summaryrefslogtreecommitdiff
path: root/lisp/dired.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/dired.el')
-rw-r--r--lisp/dired.el122
1 files changed, 73 insertions, 49 deletions
diff --git a/lisp/dired.el b/lisp/dired.el
index 98f493ecc65..fc0b71238ba 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -364,12 +364,12 @@ This is an alist of the form (SUBDIR . SWITCHES).")
(defvaralias 'dired-move-to-filename-regexp
'directory-listing-before-filename-regexp)
-(defvar dired-subdir-regexp "^. \\([^\n\r]+\\)\\(:\\)[\n\r]"
+(defvar dired-subdir-regexp "^. \\(.+\\)\\(:\\)\n"
"Regexp matching a maybe hidden subdirectory line in `ls -lR' output.
Subexpression 1 is the subdirectory proper, no trailing colon.
The match starts at the beginning of the line and ends after the end
-of the line (\\n or \\r).
-Subexpression 2 must end right before the \\n or \\r.")
+of the line.
+Subexpression 2 must end right before the \\n.")
(defgroup dired-faces nil
"Faces used by Dired."
@@ -548,7 +548,7 @@ Return value is the number of files marked, or nil if none were marked."
(setq count 0)
(when ,msg
(message "%s %ss%s..."
- (cond ((eq dired-marker-char ?\040) "Unmarking")
+ (cond ((eq dired-marker-char ?\s) "Unmarking")
((eq dired-del-marker dired-marker-char)
"Flagging")
(t "Marking"))
@@ -568,7 +568,7 @@ Return value is the number of files marked, or nil if none were marked."
count
,msg
(dired-plural-s count)
- (if (eq dired-marker-char ?\040) "un" "")
+ (if (eq dired-marker-char ?\s) "un" "")
(if (eq dired-marker-char dired-del-marker)
"flagged" "marked"))))
(and (> count 0) count)))
@@ -1539,9 +1539,8 @@ change; the point does."
(defun dired-remember-marks (beg end)
"Return alist of files and their marks, from BEG to END."
- (if selective-display ; must unhide to make this work.
- (let ((inhibit-read-only t))
- (subst-char-in-region beg end ?\r ?\n)))
+ (if (dired--find-hidden-pos (point-min) (point-max))
+ (dired--unhide (point-min) (point-max))) ;Must unhide to make this work.
(let (fil chr alist)
(save-excursion
(goto-char beg)
@@ -1568,15 +1567,12 @@ Each element of ALIST looks like (FILE . MARKERCHAR)."
(defun dired-remember-hidden ()
"Return a list of names of subdirs currently hidden."
- (let ((l dired-subdir-alist) dir pos result)
- (while l
- (setq dir (car (car l))
- pos (cdr (car l))
- l (cdr l))
+ (let (result)
+ (pcase-dolist (`(,dir . ,pos) dired-subdir-alist)
(goto-char pos)
- (skip-chars-forward "^\r\n")
- (if (eq (following-char) ?\r)
- (setq result (cons dir result))))
+ (end-of-line)
+ (if (dired--hidden-p)
+ (push dir result)))
result))
(defun dired-insert-old-subdirs (old-subdir-alist)
@@ -2135,9 +2131,9 @@ Keybindings:
mode-name "Dired"
;; case-fold-search nil
buffer-read-only t
- selective-display t ; for subdirectory hiding
mode-line-buffer-identification
(propertized-buffer-identification "%17b"))
+ (add-to-invisibility-spec '(dired . t))
;; Ignore dired-hide-details-* value of invisible text property by default.
(when (eq buffer-invisibility-spec t)
(setq buffer-invisibility-spec (list t)))
@@ -2160,8 +2156,8 @@ Keybindings:
(when (featurep 'dnd)
(setq-local dnd-protocol-alist
(append dired-dnd-protocol-alist dnd-protocol-alist)))
- (add-hook 'file-name-at-point-functions 'dired-file-name-at-point nil t)
- (add-hook 'isearch-mode-hook 'dired-isearch-filenames-setup nil t)
+ (add-hook 'file-name-at-point-functions #'dired-file-name-at-point nil t)
+ (add-hook 'isearch-mode-hook #'dired-isearch-filenames-setup nil t)
(run-mode-hooks 'dired-mode-hook))
;; Idiosyncratic dired commands that don't deal with marks.
@@ -2266,7 +2262,8 @@ directory in another window."
(error "File no longer exists; type `g' to update Dired buffer")))))
;; Force C-m keybinding rather than `f' or `e' in the mode doc:
-(define-obsolete-function-alias 'dired-advertised-find-file 'dired-find-file "23.2")
+(define-obsolete-function-alias 'dired-advertised-find-file
+ #'dired-find-file "23.2")
(defun dired-find-file ()
"In Dired, visit the file or directory named on this line."
(interactive)
@@ -2514,6 +2511,34 @@ See options: `dired-hide-details-hide-symlink-targets' and
'remove-from-invisibility-spec)
'dired-hide-details-link))
+;;; Functions to hide/unhide text
+
+(defun dired--find-hidden-pos (start end)
+ (text-property-any start end 'invisible 'dired))
+
+(defun dired--hidden-p (&optional pos)
+ (eq (get-char-property (or pos (point)) 'invisible) 'dired))
+
+(defun dired--hide (start end)
+ ;; The old code used selective-display which only works at
+ ;; a line-granularity, so it used start and end positions that where
+ ;; approximate ("anywhere on the line is fine").
+ (save-excursion
+ (put-text-property (progn (goto-char start) (line-end-position))
+ (progn (goto-char end) (line-end-position))
+ 'invisible 'dired)))
+
+(defun dired--unhide (start end)
+ ;; The old code used selective-display which only works at
+ ;; a line-granularity, so it used start and end positions that where
+ ;; approximate ("anywhere on the line is fine").
+ ;; FIXME: This also removes other invisible properties!
+ (save-excursion
+ (remove-text-properties
+ (progn (goto-char start) (line-end-position))
+ (progn (goto-char end) (line-end-position))
+ '(invisible))))
+
;;; Functions for finding the file name in a dired buffer line.
(defvar dired-permission-flags-regexp
@@ -2553,12 +2578,11 @@ Return the position of the beginning of the filename, or nil if none found."
;; This is the UNIX version.
(if (get-text-property (point) 'dired-filename)
(goto-char (next-single-property-change (point) 'dired-filename))
- (let (opoint file-type executable symlink hidden used-F eol)
- (setq used-F (dired-check-switches dired-actual-switches "F" "classify")
- opoint (point)
- eol (line-end-position)
- hidden (and selective-display
- (save-excursion (search-forward "\r" eol t))))
+ (let ((opoint (point))
+ (used-F (dired-check-switches dired-actual-switches "F" "classify"))
+ (eol (line-end-position))
+ (hidden (dired--hidden-p))
+ file-type executable symlink)
(if hidden
nil
(save-excursion ;; Find out what kind of file this is:
@@ -2795,7 +2819,7 @@ You can then feed the file name(s) to other commands with \\[yank]."
(if pos
(progn
(goto-char pos)
- (or no-skip (skip-chars-forward "^\n\r"))
+ (or no-skip (end-of-line))
(point))
(if no-error-if-not-found
nil ; return nil if not found
@@ -3187,17 +3211,17 @@ non-empty directories is allowed."
(dired-move-to-filename))
(defun dired-fun-in-all-buffers (directory file fun &rest args)
- ;; In all buffers dired'ing DIRECTORY, run FUN with ARGS.
- ;; If the buffer has a wildcard pattern, check that it matches FILE.
- ;; (FILE does not include a directory component.)
- ;; FILE may be nil, in which case ignore it.
- ;; Return list of buffers where FUN succeeded (i.e., returned non-nil).
+ "In all buffers dired'ing DIRECTORY, run FUN with ARGS.
+If the buffer has a wildcard pattern, check that it matches FILE.
+(FILE does not include a directory component.)
+FILE may be nil, in which case ignore it.
+Return list of buffers where FUN succeeded (i.e., returned non-nil)."
(let (success-list)
- (dolist (buf (dired-buffers-for-dir (expand-file-name directory)
- file))
+ (dolist (buf (dired-buffers-for-dir (expand-file-name directory) file))
(with-current-buffer buf
(if (apply fun args)
- (setq success-list (cons (buffer-name buf) success-list)))))
+ (push buf success-list))))
+ ;; FIXME: AFAICT, this return value is not used by any of the callers!
success-list))
;; Delete the entry for FILE from
@@ -3430,7 +3454,7 @@ no ARGth marked file is found before this line."
(and (dired-goto-file file)
(progn
(beginning-of-line)
- (if (not (equal ?\040 (following-char)))
+ (if (not (equal ?\s (following-char)))
(following-char))))))
(defun dired-mark-files-in-region (start end)
@@ -3488,7 +3512,7 @@ If looking at a subdir, unmark all its files except `.' and `..'.
If the region is active in Transient Mark mode, unmark all files
in the active region."
(interactive (list current-prefix-arg t))
- (let ((dired-marker-char ?\040))
+ (let ((dired-marker-char ?\s))
(dired-mark arg interactive)))
(defun dired-flag-file-deletion (arg &optional interactive)
@@ -3527,11 +3551,11 @@ As always, hidden subdirs are not affected."
;; use subst instead of insdel because it does not move
;; the gap and thus should be faster and because
;; other characters are left alone automatically
- (apply 'subst-char-in-region
+ (apply #'subst-char-in-region
(point) (1+ (point))
- (if (eq ?\040 (following-char)) ; SPC
- (list ?\040 dired-marker-char)
- (list dired-marker-char ?\040))))
+ (if (eq ?\s (following-char))
+ (list ?\s dired-marker-char)
+ (list dired-marker-char ?\s))))
(forward-line 1)))))
;;; Commands to mark or flag files based on their characteristics or names.
@@ -3562,7 +3586,7 @@ object files--just `.o' will mark more than you might think."
(dired-get-filename nil t) t))
"\\'"))))
'dired-regexp-history)
- (if current-prefix-arg ?\040)))
+ (if current-prefix-arg ?\s)))
(let ((dired-marker-char (or marker-char dired-marker-char)))
(dired-mark-if
(and (not (looking-at-p dired-re-dot))
@@ -3585,7 +3609,7 @@ since it was last visited."
(list (read-regexp (concat (if current-prefix-arg "Unmark" "Mark")
" files containing (regexp): ")
nil 'dired-regexp-history)
- (if current-prefix-arg ?\040)))
+ (if current-prefix-arg ?\s)))
(let ((dired-marker-char (or marker-char dired-marker-char)))
(dired-mark-if
(and (not (looking-at-p dired-re-dot))
@@ -3622,14 +3646,14 @@ The match is against the non-directory part of the filename. Use `^'
"Mark all symbolic links.
With prefix argument, unmark or unflag all those files."
(interactive "P")
- (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
+ (let ((dired-marker-char (if unflag-p ?\s dired-marker-char)))
(dired-mark-if (looking-at-p dired-re-sym) "symbolic link")))
(defun dired-mark-directories (unflag-p)
"Mark all directory file lines except `.' and `..'.
With prefix argument, unmark or unflag all those files."
(interactive "P")
- (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
+ (let ((dired-marker-char (if unflag-p ?\s dired-marker-char)))
(dired-mark-if (and (looking-at-p dired-re-dir)
(not (looking-at-p dired-re-dot)))
"directory file")))
@@ -3638,7 +3662,7 @@ With prefix argument, unmark or unflag all those files."
"Mark all executable files.
With prefix argument, unmark or unflag all those files."
(interactive "P")
- (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
+ (let ((dired-marker-char (if unflag-p ?\s dired-marker-char)))
(dired-mark-if (looking-at-p dired-re-exe) "executable file")))
;; dired-x.el has a dired-mark-sexp interactive command: mark
@@ -3648,7 +3672,7 @@ With prefix argument, unmark or unflag all those files."
"Flag for deletion files whose names suggest they are auto save files.
A prefix argument says to unmark or unflag those files instead."
(interactive "P")
- (let ((dired-marker-char (if unflag-p ?\040 dired-del-marker)))
+ (let ((dired-marker-char (if unflag-p ?\s dired-del-marker)))
(dired-mark-if
;; It is less than general to check for # here,
;; but it's the only way this runs fast enough.
@@ -3887,7 +3911,7 @@ The idea is to set this buffer-locally in special Dired buffers.")
(force-mode-line-update)))
(define-obsolete-function-alias 'dired-sort-set-modeline
- 'dired-sort-set-mode-line "24.3")
+ #'dired-sort-set-mode-line "24.3")
(defun dired-sort-toggle-or-edit (&optional arg)
"Toggle sorting by date, and refresh the Dired buffer.
@@ -4129,7 +4153,7 @@ Ask means pop up a menu for the user to select one of copy, move or link."
(dired dired-dir)
;; The following elements of `misc-data' are the keys
;; from `dired-subdir-alist'.
- (mapc 'dired-maybe-insert-subdir (cdr misc-data))
+ (mapc #'dired-maybe-insert-subdir (cdr misc-data))
(current-buffer))
(message "Desktop: Directory %s no longer exists." dir)
(when desktop-missing-file-warning (sit-for 1))