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: Jean Louis
Subject: Re: Function to find symlink target
Date: Fri, 27 May 2022 11:00:19 +0300
User-agent: Mutt/+ () (2022-05-21)

* Michael Heerdegen <michael_heerdegen@web.de> [2022-05-27 06:32]:
> Jean Louis <bugs@gnu.support> writes:
> 
> > How do you mean to see truename, is it by message?
> 
> Not sure I understand your question.
> 
> I meant this case:
> 
>   symlink1 -> symlink2 -> file
> 
> what would you want to get?  Both seeing FILE or SYMLINK2 could be
> useful.

Yes, there are complex conditions.

In my case I need `file', the target. I found also `file-chase-links'
function. But that one returns always something, even if file does not
exist, and is not as good as `file-truename' as it would not resolve
parent directories that are symlinks.

(defun rcd-dired-show-symlink-target (&optional file)
  "Show target of a link."
  (interactive)
  (let ((file (or file (car (dired-get-marked-files)))))
    (if (and file (file-symlink-p file))
      (let* ((target (file-chase-links file))
             (target-exists (file-exists-p target))
             (directory (file-name-directory target)))
        (if target-exists
            (progn
              (find-file directory)
              (dired-jump nil target))
          (rcd-warning-message "Target does not exist: %s" target)))
      (rcd-warning-message "Not a symlink: %s" file))))

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

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