6

On a Linux machine I symlink some directories into my home directory like this:

/home/mrdarcy:
total used in directory 231 available 520120
drwxrwxr-x  3     4k 04-30 18:16 bin
drwxr-xr-x  2     4k 2017-08-23  Desktop
lrwxrwxrwx  1     30 2017-10-10  devel -> /working/mrdarcy/devel
.
.
.

(because /working is the mount point of a much bigger disk).

When I view my home director in Dired and I am on the devel line I would like to open the symlinked directory. However the command I know of, dired-find-file, opens it as /home/mrdarcy/devel.

How can I follow the symlink with a Dired command and open /working/mrdarcy/devel?

8

You can set the value of find-file-visit-truename to t — for instance with customise via M-x customize-variable RET find-file-visit-truename or just with (setq find-file-visit-truename t).

This will result in dired-find-file and Emacs in general, always following symlinks when opening a file or directory. (See the documentation of find-file-visit-truename with C-h v find-file-visit-truename for details.)

If you'd prefer to have a separate function that opens the given directory, following symlinks, the following should do what you want:

(defun dired-find-file-following-symlinks ()
  "In Dired, visit the file or directory on the line, following symlinks"
  (interactive)
  (let ((find-file-visit-truename t))
    (dired-find-file)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.