From bdc1f193470633adcd860db4b05a9fe951bd375b Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Thu, 27 Aug 2020 11:51:30 +0200 Subject: [PATCH] dired: Show broken/circular links w/ different face * lisp/dired.el (dired-broken-symlink): New face. (dired-font-lock-keywords): Use it for broken/circular links (Bug#39145). * etc/NEWS (Changes in Specialized Modes and Packages in Emacs 28.1): Announce this change. --- etc/NEWS | 4 ++++ lisp/dired.el | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index 6e04a1cf891..8b9bd07a985 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -240,6 +240,10 @@ time zones will use a form like "+0100" instead of "CET". ** Dired +--- +*** Broken and circular links are shown with the new + 'dired-broken-symlink' face. + *** '=' ('dired-diff') will now put all backup files into the 'M-n' history. When using '=' on a file with backup files, the default file to use for diffing is the newest backup file. You can now use 'M-n' to quickly diff --git a/lisp/dired.el b/lisp/dired.el index 08d04688519..d122869a5e3 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -534,6 +534,14 @@ Subexpression 2 must end right before the \\n.") (defvar dired-symlink-face 'dired-symlink "Face name used for symbolic links.") +(defface dired-broken-symlink + '((((class color)) + :foreground "yellow1" :background "red1" :weight bold) + (t :weight bold :slant italic :underline t)) + "Face used for broken symbolic links." + :group 'dired-faces + :version "28.1") + (defface dired-special '((t (:inherit font-lock-variable-name-face))) "Face used for sockets, pipes, block devices and char devices." @@ -597,6 +605,20 @@ Subexpression 2 must end right before the \\n.") (list dired-re-dir '(".+" (dired-move-to-filename) nil (0 dired-directory-face))) ;; + ;; Broken Symbolic link. + (list dired-re-sym + (list (lambda (end) + (let* ((file (dired-file-name-at-point)) + (truename (ignore-errors (file-truename file)))) + ;; either not existent target or circular link + (and (not (and truename (file-exists-p truename))) + (search-forward-regexp "\\(.+\\) \\(->\\) ?\\(.+\\)" end t)))) + '(dired-move-to-filename) + nil + '(1 'dired-broken-symlink) + '(2 dired-symlink-face) + '(3 'dired-broken-symlink))) + ;; ;; Symbolic link to a directory. (list dired-re-sym (list (lambda (end) -- 2.39.2