Function: wdired--restore-properties

wdired--restore-properties is a byte-compiled function defined in wdired.el.gz.

Signature

(wdired--restore-properties BEG END LEN)

Source Code

;; Defined in /usr/src/emacs/lisp/wdired.el.gz
;; Added to after-change-functions in wdired-change-to-wdired-mode to
;; ensure that, on editing a file name, new characters get the
;; dired-filename text property, which allows functions that look for
;; this property (e.g. dired-isearch-filenames) to work in wdired-mode
;; and also avoids an error with non-nil wdired-use-interactive-rename
;; (bug#32173).  Also prevents editing the symlink arrow (which is a
;; noop) from corrupting the link name (see bug#18475 for elaboration).
(defun wdired--restore-properties (beg end _len)
  (save-match-data
    (save-excursion
      (save-restriction
        (widen)
        (let ((lep (line-end-position))
              (used-F (dired-check-switches
                       dired-actual-switches
                       "F" "classify")))
          ;; Deleting the space between the link name and the arrow (a
          ;; noop) also deletes the end-name property, so restore it.
          (when (and (save-excursion
                       (re-search-backward dired-permission-flags-regexp nil t)
                       (looking-at "l"))
                     (get-text-property (1- (point)) 'dired-filename)
                     (not (get-text-property (point) 'dired-filename))
                     (not (get-text-property (point) 'end-name)))
            (put-text-property (point) (1+ (point)) 'end-name t))
          (beginning-of-line)
          (when (re-search-forward
                 directory-listing-before-filename-regexp lep t)
            (setq beg (point)
                  end (if (or
                           ;; 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.)
                           (and (re-search-backward
                                 dired-permission-flags-regexp nil t)
                                (looking-at "l")
                                ;; macOS and Ultrix adds "@" to the end
                                ;; of symlinks when using -F.
                                (if (and used-F
                                         dired-ls-F-marks-symlinks)
                                    (re-search-forward "@? -> " lep t)
                                  (search-forward " -> " lep t)))
                           ;; When dired-listing-switches includes "F"
                           ;; or "classify", don't treat appended
                           ;; indicator characters as part of the file
                           ;; name (bug#34915).
                           (and used-F
                                (re-search-forward "[*/@|=>]$" lep t)))
                          (goto-char (match-beginning 0))
                        lep))
            (put-text-property beg end 'dired-filename t)))))))