all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tino Calancha <tino.calancha@gmail.com>
To: Glenn Morris <rgm@gnu.org>
Cc: uyennhi.qm@gmail.com, 39145@debbugs.gnu.org
Subject: bug#39145: 28.0.50; dired: Show broken/circular links in different font
Date: Mon, 24 Aug 2020 20:05:45 +0200	[thread overview]
Message-ID: <87364bq5qe.fsf@gmail.com> (raw)
In-Reply-To: <ximlc5p7k.fsf@fencepost.gnu.org> (Glenn Morris's message of "Wed, 15 Jan 2020 17:28:47 -0500")

Glenn Morris <rgm@gnu.org> writes:

> Tino Calancha wrote:
>
>> +(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")
>> +
>> +(defvar dired-broken-symlink-face 'dired-broken-symlink
>> +  "Face name used for broken symbolic links.")
>
> Why have a variable at all, why not just customize the face?
> (If it's just for consistency with existing dired stuff, consider
> breaking that consistency.)
It was for the consistency.
OK, I have dropped the variable.  Thank you!

I've been using this feature with joy since January.

Today I have updated the patch to match what my terminals (gnome
terminal and xterm) do: instead of
using the new font in the whole link line as I did before, that is
foo -> bar

now I only use dired-broken-symlink at 'foo' and 'bar' keeping '->' with
dired-symlink.

--8<-----------------------------cut here---------------start------------->8---
commit d250625b8f79a3b9273de6640f4840b5c8e54fe8
Author: Tino Calancha <ccalancha@suse.com>
Date:   Mon Aug 24 19:44:29 2020 +0200

    dired: Show broken/circular links w/ different face
    
    * lisp/dired.el (dired-broken-symlink): New face.
    (dired-font-lock-keywords) Use the new face for broken/circular links.
    
    * etc/NEWS (Changes in Specialized Modes and Packages in Emacs 28.1):
    Announce this change.
    
    * test/lisp/dired-tests.el (dired-test-dired-broken-symlink-face):
    Add a test.

diff --git a/etc/NEWS b/etc/NEWS
index a65852fcd0..53124b4253 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -235,6 +235,9 @@ time zones will use a form like "+0100" instead of "CET".
 
 ** Dired
 
++++
+*** Dired shows in a different color broken or circular links.
+
 +++
 *** New user option 'dired-maybe-use-globstar'.
 If set, enables globstar (recursive globbing) in shells that support
diff --git a/lisp/dired.el b/lisp/dired.el
index 94d3befda8..05f6bb0a68 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -534,6 +534,14 @@ dired-symlink
 (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 @@ dired-font-lock-keywords
    (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)
diff --git a/test/lisp/dired-tests.el b/test/lisp/dired-tests.el
index 5c6649cba4..47f8809727 100644
--- a/test/lisp/dired-tests.el
+++ b/test/lisp/dired-tests.el
@@ -440,6 +440,31 @@ dired-test-bug27940
        (should (= 6 (length (dired-get-marked-files)))) ; All empty dirs but zeta-empty-dir deleted.
      (advice-remove 'read-answer 'dired-test-bug27940-advice))))
 
+(ert-deftest dired-test-dired-broken-symlink-face ()
+  "Test Dired fontifies correctly broken/circular links."
+  (let* ((dir (make-temp-file "test-symlink" 'dir))
+         (file (make-temp-file (expand-file-name "test-file" dir)))
+         (circular-link (expand-file-name "circular-link" dir))
+         (broken-link (expand-file-name "unexistent" dir))
+         (ok-link (expand-file-name file "ok-link")))
+    (unwind-protect
+        (with-current-buffer (dired dir)
+          (make-symbolic-link circular-link "circular-link")
+          (make-symbolic-link file "ok-link")
+          (make-symbolic-link broken-link "broken-link")
+          (dired-revert)
+          (sit-for 1)
+          ;; A circular link
+          (dired-goto-file circular-link)
+          (should (eq 'dired-broken-symlink (get-text-property (point) 'face)))
+          ;; A broken link
+          (dired-goto-file broken-link)
+          (should (eq 'dired-broken-symlink (get-text-property (point) 'face)))
+          ;; A valid link
+          (dired-goto-file ok-link)
+          (should-not (eq 'dired-broken-symlink (get-text-property (point) 'face))))
+      (delete-directory dir 'recursive))))
+
 
 (provide 'dired-tests)
 ;; dired-tests.el ends here

--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 28.0.50 (build 14, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw scroll bars)
 of 2020-08-24 built on localhost.example.com
Repository revision: 88795c52ff13203dda5940ed5defc26ce2c20e5e
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12008000
System Description: openSUSE Tumbleweed





  reply	other threads:[~2020-08-24 18:05 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-15 21:06 bug#39145: 28.0.50; dired: Show broken/circular links in different font Tino Calancha
2020-01-15 22:28 ` Glenn Morris
2020-08-24 18:05   ` Tino Calancha [this message]
2020-08-25 16:34     ` Tino Calancha
2020-08-25 16:51       ` Eli Zaretskii
2020-08-25 17:05         ` Tino Calancha
2020-08-25 17:18           ` Tino Calancha
2020-08-25 18:22             ` Eli Zaretskii
2020-08-27  8:30               ` Tino Calancha
2020-08-27  9:03                 ` Eli Zaretskii
2020-08-27  9:37     ` Stefan Kangas
2020-08-27  9:58       ` Tino Calancha
2020-01-15 23:13 ` Juri Linkov
2020-08-24 17:52   ` Tino Calancha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87364bq5qe.fsf@gmail.com \
    --to=tino.calancha@gmail.com \
    --cc=39145@debbugs.gnu.org \
    --cc=rgm@gnu.org \
    --cc=uyennhi.qm@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.