From: Stephen Berman <stephen.berman@gmx.net>
Date: Thu, 13 Sep 2018 20:19:22 +0000 (+0200)
Subject: Fix wdired handling of symlinks when restoring filename property
X-Git-Tag: emacs-27.0.90~4423
X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=755fa346eba212b4650c8541023bb78e1658d77b;p=emacs.git

Fix wdired handling of symlinks when restoring filename property

* lisp/wdired.el (wdired--restore-dired-filename-prop): Use
dired-permission-flags-regexp instead of dired-filename to test
whether the file is a symlink, since calling file-symlink-p on the
latter may fail in wdired-mode (bug#32673).
---

diff --git a/lisp/wdired.el b/lisp/wdired.el
index be0bde290ab..3157e887d77 100644
--- a/lisp/wdired.el
+++ b/lisp/wdired.el
@@ -607,15 +607,22 @@ Optional arguments are ignored."
 (defun wdired--restore-dired-filename-prop (beg end _len)
   (save-match-data
     (save-excursion
-      (beginning-of-line)
-      (when (re-search-forward directory-listing-before-filename-regexp
-                               (line-end-position) t)
-        (setq beg (point)
-              end (if (and (file-symlink-p (dired-get-filename))
-                           (search-forward " -> " (line-end-position) t))
-                      (goto-char (match-beginning 0))
-                    (line-end-position)))
-        (put-text-property beg end 'dired-filename t)))))
+      (let ((lep (line-end-position)))
+        (beginning-of-line)
+        (when (re-search-forward
+               directory-listing-before-filename-regexp lep t)
+          (setq beg (point)
+                ;; If the file is a symlink, put the dired-filename
+                ;; property only on the link name.  (Using
+                ;; (file-symlink-p (dired-get-filename)) fails in
+                ;; wdired-mode, bug#32673.)
+                end (if (and (re-search-backward
+                              dired-permission-flags-regexp nil t)
+                             (looking-at "l")
+                             (search-forward " -> " lep t))
+                        (goto-char (match-beginning 0))
+                      lep))
+          (put-text-property beg end 'dired-filename t))))))
 
 (defun wdired-next-line (arg)
   "Move down lines then position at filename or the current column.