aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2021-07-19 19:03:28 +0200
committerLars Ingebrigtsen2021-07-19 19:03:28 +0200
commit6ebe8b03d80038d0c79ee0119efcd8272bb6a551 (patch)
treef882f75bfe4dcb445adb2198ff4e6758a2787517
parentf7f2024b86bdcf028ce942e59d1cfdba89747d0b (diff)
downloademacs-6ebe8b03d80038d0c79ee0119efcd8272bb6a551.tar.gz
emacs-6ebe8b03d80038d0c79ee0119efcd8272bb6a551.zip
Make wdired work better in narrowed-to buffers
* lisp/wdired.el (wdired--before-change-fn): (wdired--restore-properties): Widen before doing anything so that we get all the changed bits (bug#49124).
-rw-r--r--lisp/wdired.el122
1 files changed, 63 insertions, 59 deletions
diff --git a/lisp/wdired.el b/lisp/wdired.el
index 22c1cebe13c..fd549bac322 100644
--- a/lisp/wdired.el
+++ b/lisp/wdired.el
@@ -297,26 +297,28 @@ or \\[wdired-abort-changes] to abort changes")))
297(defun wdired--before-change-fn (beg end) 297(defun wdired--before-change-fn (beg end)
298 (save-match-data 298 (save-match-data
299 (save-excursion 299 (save-excursion
300 ;; Make sure to process entire lines. 300 (save-restriction
301 (goto-char end) 301 (widen)
302 (setq end (line-end-position)) 302 ;; Make sure to process entire lines.
303 (goto-char beg) 303 (goto-char end)
304 (forward-line 0) 304 (setq end (line-end-position))
305 305 (goto-char beg)
306 (while (< (point) end) 306 (forward-line 0)
307 (unless (wdired--line-preprocessed-p) 307
308 (while (< (point) end)
309 (unless (wdired--line-preprocessed-p)
310 (with-silent-modifications
311 (put-text-property (point) (1+ (point)) 'front-sticky t)
312 (wdired--preprocess-files)
313 (when wdired-allow-to-change-permissions
314 (wdired--preprocess-perms))
315 (when (fboundp 'make-symbolic-link)
316 (wdired--preprocess-symlinks))))
317 (forward-line))
318 (when (eobp)
308 (with-silent-modifications 319 (with-silent-modifications
309 (put-text-property (point) (1+ (point)) 'front-sticky t) 320 ;; Is this good enough? Assumes no extra white lines from dired.
310 (wdired--preprocess-files) 321 (put-text-property (1- (point-max)) (point-max) 'read-only t)))))))
311 (when wdired-allow-to-change-permissions
312 (wdired--preprocess-perms))
313 (when (fboundp 'make-symbolic-link)
314 (wdired--preprocess-symlinks))))
315 (forward-line))
316 (when (eobp)
317 (with-silent-modifications
318 ;; Is this good enough? Assumes no extra white lines from dired.
319 (put-text-property (1- (point-max)) (point-max) 'read-only t))))))
320 322
321(defun wdired-isearch-filter-read-only (beg end) 323(defun wdired-isearch-filter-read-only (beg end)
322 "Skip matches that have a read-only property." 324 "Skip matches that have a read-only property."
@@ -700,47 +702,49 @@ Optional arguments are ignored."
700(defun wdired--restore-properties (beg end _len) 702(defun wdired--restore-properties (beg end _len)
701 (save-match-data 703 (save-match-data
702 (save-excursion 704 (save-excursion
703 (let ((lep (line-end-position)) 705 (save-restriction
704 (used-F (dired-check-switches 706 (widen)
705 dired-actual-switches 707 (let ((lep (line-end-position))
706 "F" "classify"))) 708 (used-F (dired-check-switches
707 ;; Deleting the space between the link name and the arrow (a 709 dired-actual-switches
708 ;; noop) also deletes the end-name property, so restore it. 710 "F" "classify")))
709 (when (and (save-excursion 711 ;; Deleting the space between the link name and the arrow (a
710 (re-search-backward dired-permission-flags-regexp nil t) 712 ;; noop) also deletes the end-name property, so restore it.
711 (looking-at "l")) 713 (when (and (save-excursion
712 (get-text-property (1- (point)) 'dired-filename) 714 (re-search-backward dired-permission-flags-regexp nil t)
713 (not (get-text-property (point) 'dired-filename)) 715 (looking-at "l"))
714 (not (get-text-property (point) 'end-name))) 716 (get-text-property (1- (point)) 'dired-filename)
717 (not (get-text-property (point) 'dired-filename))
718 (not (get-text-property (point) 'end-name)))
715 (put-text-property (point) (1+ (point)) 'end-name t)) 719 (put-text-property (point) (1+ (point)) 'end-name t))
716 (beginning-of-line) 720 (beginning-of-line)
717 (when (re-search-forward 721 (when (re-search-forward
718 directory-listing-before-filename-regexp lep t) 722 directory-listing-before-filename-regexp lep t)
719 (setq beg (point) 723 (setq beg (point)
720 end (if (or 724 end (if (or
721 ;; If the file is a symlink, put the 725 ;; If the file is a symlink, put the
722 ;; dired-filename property only on the link 726 ;; dired-filename property only on the link
723 ;; name. (Using (file-symlink-p 727 ;; name. (Using (file-symlink-p
724 ;; (dired-get-filename)) fails in 728 ;; (dired-get-filename)) fails in
725 ;; wdired-mode, bug#32673.) 729 ;; wdired-mode, bug#32673.)
726 (and (re-search-backward 730 (and (re-search-backward
727 dired-permission-flags-regexp nil t) 731 dired-permission-flags-regexp nil t)
728 (looking-at "l") 732 (looking-at "l")
729 ;; macOS and Ultrix adds "@" to the end 733 ;; macOS and Ultrix adds "@" to the end
730 ;; of symlinks when using -F. 734 ;; of symlinks when using -F.
731 (if (and used-F 735 (if (and used-F
732 dired-ls-F-marks-symlinks) 736 dired-ls-F-marks-symlinks)
733 (re-search-forward "@? -> " lep t) 737 (re-search-forward "@? -> " lep t)
734 (search-forward " -> " lep t))) 738 (search-forward " -> " lep t)))
735 ;; When dired-listing-switches includes "F" 739 ;; When dired-listing-switches includes "F"
736 ;; or "classify", don't treat appended 740 ;; or "classify", don't treat appended
737 ;; indicator characters as part of the file 741 ;; indicator characters as part of the file
738 ;; name (bug#34915). 742 ;; name (bug#34915).
739 (and used-F 743 (and used-F
740 (re-search-forward "[*/@|=>]$" lep t))) 744 (re-search-forward "[*/@|=>]$" lep t)))
741 (goto-char (match-beginning 0)) 745 (goto-char (match-beginning 0))
742 lep)) 746 lep))
743 (put-text-property beg end 'dired-filename t)))))) 747 (put-text-property beg end 'dired-filename t)))))))
744 748
745(defun wdired-next-line (arg) 749(defun wdired-next-line (arg)
746 "Move down lines then position at filename or the current column. 750 "Move down lines then position at filename or the current column.