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: Wed, 25 May 2022 08:05:22 +0300
User-agent: Mutt/+ () (2022-05-21)

* Emanuel Berg <incal@dataswamp.org> [2022-05-24 05:15]:
> Michael Heerdegen wrote:
> 
> >> (defun dired-find-link-target (link)
> >>   (let*((target (file-truename link))
> >>         (name   (file-name-nondirectory target)) )
> >>     (find-file (file-name-directory target))
> >>     (goto-char (point-min))
> >>     (cl-loop
> >>      while (re-search-forward name (point-max) t)
> >>      do (when (get-text-property (point) 'dired-filename)
> >>           (cl-return) ))
> >>     (goto-char (match-beginning 0)) ))
> >
> > Not wrong - but reinventing wheels: see `dired-jump' and
> > `dired-goto-file'.
> 
> None of these work ...
> 
> (dired-goto-file "~/test/dired/target-link.txt")
> (dired-jump "~/test/dired/target-link.txt")

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

-- 
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]