Open dired and select the file associated with the previous buffer?

被刻印的时光 ゝ 提交于 2019-12-05 05:42:39

dired-jump is exactly what you want.

(autoload 'dired-jump "dired-x" "Jump to dired corresponding current buffer.")
(autoload 'dired-jump-other-window "dired-x" "jump to dired in other window.")

Then call:

M-x dired-jump

or

M-x dired-jump-other-window

You want C-x C-j.

Sunrise Commander is a much improved dired. and it does what you need by default.

You can do something like that:

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

Then the only file visible in dired will be your current file and cursor will be right on it.

This piece of advice will do what you want:

(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))))

Note: Works for C-x d, but not the C-x C-f entry point to dired.

$ emacs --version
GNU Emacs 24.3.1

In .emacs:

(require 'dired-x)

Now C-x C-j should be bound to dired-jump.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!