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: Tue, 24 May 2022 02:59:17 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/geh.el

(require 'cl-lib)

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

;; /home/incal/test/dired:
;; lrwxrwxrwx 1 incal 10 May 23 22:41 target-link.txt -> target.txt
;; -rw-r--r-- 1 incal  0 May 23 22:41 target.txt

(dired-find-link-target "~/test/dired/target-link.txt")

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




reply via email to

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