Emacs 打开dired并选择与上一个缓冲区关联的文件?

Emacs 打开dired并选择与上一个缓冲区关联的文件?,emacs,elisp,rename,dired,Emacs,Elisp,Rename,Dired,假设我正在用Emacs编辑blah.txt,我决定使用blah.txt。当我按下C-x d-RET(或C-x C-f-RET)时,一个dired缓冲区将显示包含blah.txt的目录的内容,但光标将不在blah.txt上。所以我需要先搜索我的文件(C-s blah.txt),将光标放在上面,然后我可以重命名它(R) 如何自动执行或删除步骤C-s blah.txt?您可以这样做: M-: (dired (buffer-name (current-buffer))) 然后,在dired中唯一可见的

假设我正在用Emacs编辑
blah.txt
,我决定使用blah.txt。当我按下
C-x d-RET
(或
C-x C-f-RET
)时,一个dired缓冲区将显示包含
blah.txt
的目录的内容,但光标将不在
blah.txt
上。所以我需要先搜索我的文件(
C-s blah.txt
),将光标放在上面,然后我可以重命名它(
R


如何自动执行或删除步骤
C-s blah.txt

您可以这样做:

M-: (dired (buffer-name (current-buffer)))

然后,在dired中唯一可见的文件将是您当前的文件,光标将正好位于该文件上。

您想要的
C-x C-j

是一个改进了很多的dired。默认情况下,它会满足您的需要

这条建议可以满足您的要求:

(defadvice dired (around dired-jump-to-buffer activate)
  "When running dired, move cursor to the line for the buffer we came from"
  (interactive (list nil nil)) ;; bogus values, will be overwritten below
  (let ((coming-from (buffer-file-name)))
(ad-set-args 0 (dired-read-dir-and-switches ""))
ad-do-it
(when (and coming-from
       (equal (file-truename default-directory) (file-truename (file-name-directory coming-from))))
    (goto-char (point-min))
    (search-forward (file-name-nondirectory coming-from) nil t))))

注意:适用于C-x d,但不适用于dired的C-x C-f入口点。

dired jump
正是您想要的

(autoload 'dired-jump "dired-x" "Jump to dired corresponding current buffer.")
(autoload 'dired-jump-other-window "dired-x" "jump to dired in other window.")
然后打电话:

M-x dired-jump

在.emacs中:

(require 'dired-x)

现在
C-xc-j
应该绑定到
dired jump

,什么是
C-xc-j
?它不绑定在文本缓冲区或dired缓冲区(Emacs 23.2)中。@Trey:
C-x C-j
绑定到
dired jump
,但仅在加载
dired-x
时绑定。(我认为有一个Emacs政策,
dired-x
不符合这里的规定。)谢谢,Gilles;我没有意识到默认情况下它没有绑定。如果您按照手册中的说明操作,您也会得到正确的密钥绑定:
C-h I g
(dired-x)可选安装dired Jump
RET
$ emacs --version
GNU Emacs 24.3.1
(require 'dired-x)