help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Function to find symlink target


From: Emanuel Berg
Subject: Re: Function to find symlink target
Date: Thu, 26 May 2022 00:33:49 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Jean Louis wrote:

> Thank you for `dired-jump' as that is what I needed, it
> works well now, I can find target of a symlink easily.
>
> (defun rcd-dired-show-symlink-target ()
>   "Show target of a symlink."
>   (interactive)
>   (let ((file (car (dired-get-marked-files))))
>     (if (and file (file-symlink-p file))
>       (let* ((target (file-truename file))
>            (target-exists (file-exists-p target))
>            (directory (file-name-directory target)))
>       (if target-exists
>           (progn
>             (find-file directory)
>             (dired-jump nil target))
>         (message "Target does not exist: %s" target)))
>       (message "Not a symlink: %s" file))))

Yes, that works. You can add an optional FILE argument and
only when that's not provided look for the first marked file
or even the file at point which is perhaps more intuitive
since it's only one file ...

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]