summaryrefslogtreecommitdiff
path: root/lisp/dired-aux.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2019-03-17 13:35:20 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2019-03-17 13:35:20 -0400
commit5055e14dda041f4a4985d3663f19fa8ccb37cad6 (patch)
tree282e553df14bc3914a7d24fb42bd57eee31b2d2d /lisp/dired-aux.el
parent2f50a990b756a0b3477455e28abc0dbd8d33a27e (diff)
downloademacs-5055e14dda041f4a4985d3663f19fa8ccb37cad6.tar.gz
Dired: Use invisibility-spec instead of selective-display
* lisp/dired.el (dired-subdir-regexp): No need to pay attention to \r. (dired-remember-hidden): Use pcase-dolist and dired--hidden-p. (dired-mode): Set invisibility-spec instead of selective-display. (dired--hidden-p, dired--hide, dired--unhide, dired--find-hidden-pos): New functions. (dired-move-to-end-of-filename): Use dired--hidden-p. (dired-next-subdir): No need to pay attention to \r. (dired-fun-in-all-buffers): Use push. * lisp/dired-aux.el (dired-unhide-subdir, dired-hide-subdir, dired-hide-all): Use the new functions and with-silent-modifications. (dired-add-entry): Use dired--hidden-p. (dired-goto-subdir): No need to pay attention to \r. (dired-hide-check): Remove. (dired-subdir-hidden-p): Use dired--hidden-p. (dired-do-find-regexp): Use file-name-as-directory.
Diffstat (limited to 'lisp/dired-aux.el')
-rw-r--r--lisp/dired-aux.el146
1 files changed, 66 insertions, 80 deletions
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 4be93c32207..b81c0d1a4f5 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -148,7 +148,7 @@ the string of command switches used as the third argument of `diff'."
(read-string "Options for diff: "
(if (stringp diff-switches)
diff-switches
- (mapconcat 'identity diff-switches " ")))))))
+ (mapconcat #'identity diff-switches " ")))))))
(let ((current (dired-get-filename t)))
(when (or (equal (expand-file-name file)
(expand-file-name current))
@@ -173,7 +173,7 @@ With prefix arg, prompt for argument SWITCHES which is options for `diff'."
(list (read-string "Options for diff: "
(if (stringp diff-switches)
diff-switches
- (mapconcat 'identity diff-switches " "))))
+ (mapconcat #'identity diff-switches " "))))
nil))
(diff-backup (dired-get-filename) switches))
@@ -227,12 +227,12 @@ Examples of PREDICATE:
(setq file-alist2 (delq (assoc "." file-alist2) file-alist2))
(setq file-alist2 (delq (assoc ".." file-alist2) file-alist2))
(setq file-list1 (mapcar
- 'cadr
+ #'cadr
(dired-file-set-difference
file-alist1 file-alist2
predicate))
file-list2 (mapcar
- 'cadr
+ #'cadr
(dired-file-set-difference
file-alist2 file-alist1
predicate)))
@@ -491,7 +491,7 @@ Uses the shell command coming from variables `lpr-command' and
lpr-switches))
(command (dired-mark-read-string
"Print %s with: "
- (mapconcat 'identity
+ (mapconcat #'identity
(cons lpr-command
(if (stringp lpr-switches)
(list lpr-switches)
@@ -597,7 +597,7 @@ with a prefix argument."
(possibilities (file-name-all-completions
base-versions
(file-name-directory fn)))
- (versions (mapcar 'backup-extract-version possibilities)))
+ (versions (mapcar #'backup-extract-version possibilities)))
(if versions
(setq dired-file-version-alist
(cons (cons fn versions)
@@ -822,27 +822,28 @@ can be produced by `dired-get-marked-files', for example."
retval))
(lambda (x) (concat cmd-prefix command dired-mark-separator x)))))
(concat
- (cond (on-each
- (format "%s%s"
- (mapconcat stuff-it (mapcar 'shell-quote-argument file-list)
- cmd-sep)
- ;; POSIX shells running a list of commands in the background
- ;; (LIST = cmd_1 & [cmd_2 & ... cmd_i & ... cmd_N &])
- ;; return once cmd_N ends, i.e., the shell does not
- ;; wait for cmd_i to finish before executing cmd_i+1.
- ;; That means, running (shell-command LIST) may not show
- ;; the output of all the commands (Bug#23206).
- ;; Add 'wait' to force those POSIX shells to wait until
- ;; all commands finish.
- (or (and parallel-in-background (not w32-shell)
- "&wait")
- "")))
- (t
- (let ((files (mapconcat 'shell-quote-argument
- file-list dired-mark-separator)))
- (when (cdr file-list)
- (setq files (concat dired-mark-prefix files dired-mark-postfix)))
- (funcall stuff-it files))))
+ (cond
+ (on-each
+ (format "%s%s"
+ (mapconcat stuff-it (mapcar #'shell-quote-argument file-list)
+ cmd-sep)
+ ;; POSIX shells running a list of commands in the background
+ ;; (LIST = cmd_1 & [cmd_2 & ... cmd_i & ... cmd_N &])
+ ;; return once cmd_N ends, i.e., the shell does not
+ ;; wait for cmd_i to finish before executing cmd_i+1.
+ ;; That means, running (shell-command LIST) may not show
+ ;; the output of all the commands (Bug#23206).
+ ;; Add 'wait' to force those POSIX shells to wait until
+ ;; all commands finish.
+ (or (and parallel-in-background (not w32-shell)
+ "&wait")
+ "")))
+ (t
+ (let ((files (mapconcat #'shell-quote-argument
+ file-list dired-mark-separator)))
+ (when (cdr file-list)
+ (setq files (concat dired-mark-prefix files dired-mark-postfix)))
+ (funcall stuff-it files))))
(or (and in-background "&") ""))))
;; This is an extra function so that it can be redefined by ange-ftp.
@@ -872,7 +873,7 @@ Else returns nil for success."
(set-buffer err-buffer)
(erase-buffer)
(setq default-directory dir ; caller's default-directory
- err (not (eq 0 (apply 'process-file program nil t nil arguments))))
+ err (not (eq 0 (apply #'process-file program nil t nil arguments))))
(if err
(progn
(dired-log (concat program " " (prin1-to-string arguments) "\n"))
@@ -1349,7 +1350,7 @@ See Info node `(emacs)Subdir switches' for more details."
;; Replace space by old marker without moving point.
;; Faster than goto+insdel inside a save-excursion?
(when char
- (subst-char-in-region opoint (1+ opoint) ?\040 char)))))
+ (subst-char-in-region opoint (1+ opoint) ?\s char)))))
(dired-move-to-filename))
;;;###autoload
@@ -1403,8 +1404,8 @@ files matching `dired-omit-regexp'."
(catch 'not-found
(if (string= directory cur-dir)
(progn
- (skip-chars-forward "^\r\n")
- (if (eq (following-char) ?\r)
+ (end-of-line)
+ (if (dired--hidden-p)
(dired-unhide-subdir))
;; We are already where we should be, except when
;; point is before the subdir line or its total line.
@@ -1414,7 +1415,7 @@ files matching `dired-omit-regexp'."
;; else try to find correct place to insert
(if (dired-goto-subdir directory)
(progn ;; unhide if necessary
- (if (= (following-char) ?\r)
+ (if (dired--hidden-p)
;; Point is at end of subdir line.
(dired-unhide-subdir))
;; found - skip subdir and `total' line
@@ -1523,7 +1524,7 @@ files matching `dired-omit-regexp'."
(point))
(line-beginning-position 2)))
(setq file (directory-file-name file))
- (dired-add-entry file (if (eq ?\040 marker) nil marker)))))
+ (dired-add-entry file (if (eq ?\s marker) nil marker)))))
;;; Copy, move/rename, making hard and symbolic links
@@ -2562,7 +2563,7 @@ Optional third arg LIMIT (>= 1) is a limit to the length of the
resulting list.
Thus, if SEP is a regexp that only matches itself,
- (mapconcat 'identity (dired-split SEP STRING) SEP)
+ (mapconcat #'identity (dired-split SEP STRING) SEP)
is always equal to STRING."
(let* ((start (string-match pat str))
@@ -2610,7 +2611,7 @@ When called interactively and not on a subdir line, go to this subdir's line."
(defun dired-goto-subdir (dir)
"Go to end of header line of DIR in this dired buffer.
Return value of point on success, otherwise return nil.
-The next char is either \\n, or \\r if DIR is hidden."
+The next char is \\n."
(interactive
(prog1 ; let push-mark display its message
(list (expand-file-name
@@ -2625,8 +2626,8 @@ The next char is either \\n, or \\r if DIR is hidden."
(and elt
(goto-char (dired-get-subdir-min elt))
;; dired-subdir-hidden-p and dired-add-entry depend on point being
- ;; at either \r or \n after this function succeeds.
- (progn (skip-chars-forward "^\r\n")
+ ;; at \n after this function succeeds.
+ (progn (end-of-line)
(point)))))
;;;###autoload
@@ -2699,18 +2700,13 @@ Lower levels are unaffected."
;;; hiding
(defun dired-unhide-subdir ()
- (let (buffer-read-only)
- (subst-char-in-region (dired-subdir-min) (dired-subdir-max) ?\r ?\n)))
-
-(defun dired-hide-check ()
- (or selective-display
- (error "selective-display must be t for subdir hiding to work!")))
+ (with-silent-modifications
+ (dired--unhide (dired-subdir-min) (dired-subdir-max))))
(defun dired-subdir-hidden-p (dir)
- (and selective-display
- (save-excursion
- (dired-goto-subdir dir)
- (= (following-char) ?\r))))
+ (save-excursion
+ (dired-goto-subdir dir)
+ (dired--hidden-p)))
;;;###autoload
(defun dired-hide-subdir (arg)
@@ -2718,8 +2714,7 @@ Lower levels are unaffected."
Optional prefix arg is a repeat factor.
Use \\[dired-hide-all] to (un)hide all directories."
(interactive "p")
- (dired-hide-check)
- (let ((modflag (buffer-modified-p)))
+ (with-silent-modifications
(while (>= (setq arg (1- arg)) 0)
(let* ((cur-dir (dired-current-directory))
(hidden-p (dired-subdir-hidden-p cur-dir))
@@ -2728,12 +2723,11 @@ Use \\[dired-hide-all] to (un)hide all directories."
buffer-read-only)
;; keep header line visible, hide rest
(goto-char (dired-get-subdir-min elt))
- (skip-chars-forward "^\n\r")
+ (end-of-line)
(if hidden-p
- (subst-char-in-region (point) end-pos ?\r ?\n)
- (subst-char-in-region (point) end-pos ?\n ?\r)))
- (dired-next-subdir 1 t))
- (restore-buffer-modified-p modflag)))
+ (dired--unhide (point) end-pos)
+ (dired--hide (point) end-pos)))
+ (dired-next-subdir 1 t))))
;;;###autoload
(defun dired-hide-all (&optional ignored)
@@ -2741,28 +2735,20 @@ Use \\[dired-hide-all] to (un)hide all directories."
If there is already something hidden, make everything visible again.
Use \\[dired-hide-subdir] to (un)hide a particular subdirectory."
(interactive "P")
- (dired-hide-check)
- (let ((modflag (buffer-modified-p))
- buffer-read-only)
- (if (save-excursion
- (goto-char (point-min))
- (search-forward "\r" nil t))
- ;; unhide - bombs on \r in filenames
- (subst-char-in-region (point-min) (point-max) ?\r ?\n)
+ (with-silent-modifications
+ (if (text-property-any (point-min) (point-max) 'invisible 'dired)
+ (dired--unhide (point-min) (point-max))
;; hide
- (let ((pos (point-max)) ; pos of end of last directory
- (alist dired-subdir-alist))
- (while alist ; while there are dirs before pos
- (subst-char-in-region (dired-get-subdir-min (car alist)) ; pos of prev dir
- (save-excursion
- (goto-char pos) ; current dir
- ;; we're somewhere on current dir's line
- (forward-line -1)
- (point))
- ?\n ?\r)
- (setq pos (dired-get-subdir-min (car alist))) ; prev dir gets current dir
- (setq alist (cdr alist)))))
- (restore-buffer-modified-p modflag)))
+ (let ((pos (point-max))) ; pos of end of last directory
+ (dolist (subdir dired-subdir-alist)
+ (let ((start (dired-get-subdir-min subdir)) ; pos of prev dir
+ (end (save-excursion
+ (goto-char pos) ; current dir
+ ;; we're somewhere on current dir's line
+ (forward-line -1)
+ (point))))
+ (dired--hide start end))
+ (setq pos (dired-get-subdir-min subdir))))))) ; prev dir gets current dir
;;;###end dired-ins.el
@@ -2788,8 +2774,8 @@ When off, it uses the original predicate."
nil nil nil
(if dired-isearch-filenames-mode
(add-function :before-while (local 'isearch-filter-predicate)
- #'dired-isearch-filter-filenames
- '((isearch-message-prefix . "filename ")))
+ #'dired-isearch-filter-filenames
+ '((isearch-message-prefix . "filename ")))
(remove-function (local 'isearch-filter-predicate)
#'dired-isearch-filter-filenames))
(when isearch-mode
@@ -2805,13 +2791,13 @@ Intended to be added to `isearch-mode-hook'."
(get-text-property (point) 'dired-filename)))
(define-key isearch-mode-map "\M-sff" 'dired-isearch-filenames-mode)
(dired-isearch-filenames-mode 1)
- (add-hook 'isearch-mode-end-hook 'dired-isearch-filenames-end nil t)))
+ (add-hook 'isearch-mode-end-hook #'dired-isearch-filenames-end nil t)))
(defun dired-isearch-filenames-end ()
"Clean up the Dired file name search after terminating isearch."
(define-key isearch-mode-map "\M-sff" nil)
(dired-isearch-filenames-mode -1)
- (remove-hook 'isearch-mode-end-hook 'dired-isearch-filenames-end t)
+ (remove-hook 'isearch-mode-end-hook #'dired-isearch-filenames-end t)
(unless isearch-suspended
(custom-reevaluate-setting 'dired-isearch-filenames)))
@@ -2905,7 +2891,7 @@ REGEXP should use constructs supported by your local `grep' command."
(declare-function rgrep-find-ignored-directories "grep" (dir))
(let* ((files (dired-get-marked-files nil nil nil nil t))
(ignores (nconc (mapcar
- (lambda (s) (concat s "/"))
+ #'file-name-as-directory
(rgrep-find-ignored-directories default-directory))
grep-find-ignored-files))
(xrefs (mapcan