(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))
(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))
(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)))
lpr-switches))
(command (dired-mark-read-string
"Print %s with: "
- (mapconcat 'identity
+ (mapconcat #'identity
(cons lpr-command
(if (stringp lpr-switches)
(list lpr-switches)
(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)
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.
(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"))
;; 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
(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.
;; 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
(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)))))
\f
;;; Copy, move/rename, making hard and symbolic links
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))
(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
(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)))))
\f
;;;###autoload
;;; 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)
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))
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)
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
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
(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)))
(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
(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."
(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"))
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)))
(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)
(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)
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)))
(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))
\f
;; Idiosyncratic dired commands that don't deal with marks.
(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)
'remove-from-invisibility-spec)
'dired-hide-details-link))
\f
+;;; 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
;; 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:
(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
(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
(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)
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)
;; 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)))))
\f
;;; Commands to mark or flag files based on their characteristics or names.
(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))
(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))
"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")))
"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
"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.
(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.
(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))