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

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

Function to find symlink target


From: Jean Louis
Subject: Function to find symlink target
Date: Wed, 18 May 2022 23:55:26 +0300

Hello,

I have made this function to find the target of a symlink in dired, it opens
new Dired window and tries to locate the file. I have tried finding
such function in Dired and did not succeed, maybe it exists in Emacs
programs somewhere.

(defun rcd-dired-find-symlink ()
  "Find target of a symlink"
  (interactive)
  (when (dired-get-marked-files)
    (let ((file (car (dired-get-marked-files))))
      (if (file-symlink-p file)
          (let* ((file (file-truename file))
                 (directory (file-name-directory file))
                 (file (file-name-nondirectory file))
                 (back (length file)))
            (find-file directory)
            (search-forward file)
            (backward-char back))
        (message "Not a symlink: %s" file)))))


Let me know if I should improve this by any means.

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]