1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-03 18:41:25 -08:00

Support dired-movement-style in dired-next-dirline and dired-prev-dirline

* lisp/dired.el (dired-movement-style): Mention dired-next-dirline
and dired-prev-dirline in the docstring (bug#67303).
(dired-next-line): Refactor most code to dired--move-to-next-line.
(dired--move-to-next-line): New function with code from dired-next-line.
(dired--trivial-next-dirline): Rename from dired-next-dirline.
(dired-next-dirline): New function body that uses dired-movement-style,
dired--move-to-next-line and dired--trivial-next-dirline.
(dired-prev-dirline): Mention dired-movement-style in the docstring.
This commit is contained in:
Juri Linkov 2023-11-23 20:12:40 +02:00
parent 51222153df
commit 29d42d9158
2 changed files with 59 additions and 47 deletions

View file

@ -490,10 +490,11 @@ that shows as diffs replacements in the marked files in Dired.
---
*** New user option 'dired-movement-style'.
When non-nil, make 'dired-next-line' and 'dired-previous-line' skip
empty lines. It also controls how to move point when encountering a
boundary (e.g., if every line is visible, invoking 'dired-next-line'
at the last line will move to the first line). The default is nil.
When non-nil, make 'dired-next-line', 'dired-previous-line',
'dired-next-dirline', 'dired-prev-dirline' skip empty lines.
It also controls how to move point when encountering a boundary
(e.g., if every line is visible, invoking 'dired-next-line' at
the last line will move to the first line). The default is nil.
** Ediff

View file

@ -499,7 +499,8 @@ to nil: a pipe using `zcat' or `gunzip -c' will be used."
(defcustom dired-movement-style nil
"Non-nil means point skips empty lines when moving in Dired buffers.
This affects only `dired-next-line' and `dired-previous-line'.
This affects only `dired-next-line', `dired-previous-line',
`dired-next-dirline', `dired-prev-dirline'.
Possible non-nil values:
* `cycle': when moving from the last/first visible line, cycle back
@ -2705,6 +2706,10 @@ Whether to skip empty lines and how to move from last line
is controlled by `dired-movement-style'."
(interactive "^p" dired-mode)
(if dired-movement-style
(dired--move-to-next-line arg #'dired--trivial-next-line)
(dired--trivial-next-line arg)))
(defun dired--move-to-next-line (arg jumpfun)
(let ((old-position (progn
;; It's always true that we should move
;; to the filename when possible.
@ -2716,7 +2721,7 @@ is controlled by `dired-movement-style'."
-1))) ; means Up.
;; Line by line in case we forget to skip empty lines.
(while (not (zerop arg))
(dired--trivial-next-line moving-down)
(funcall jumpfun moving-down)
(when (= old-position (point))
;; Now point is at beginning/end of movable area,
;; but it still wants to move farther.
@ -2726,22 +2731,15 @@ is controlled by `dired-movement-style'."
(point-min)
(point-max)))
;; `bounded': go back to the last non-empty line.
(while (string-match-p "\\`[[:blank:]]*\\'"
(buffer-substring-no-properties
(line-beginning-position)
(line-end-position)))
(dired--trivial-next-line (- moving-down)))
(while (dired-between-files)
(funcall jumpfun (- moving-down)))
;; Encountered a boundary, so let's stop movement.
(setq arg moving-down)))
(when (not (string-match-p "\\`[[:blank:]]*\\'"
(buffer-substring-no-properties
(line-beginning-position)
(line-end-position))))
(unless (dired-between-files)
;; Has moved to a non-empty line. This movement does
;; make sense.
(cl-decf arg moving-down))
(setq old-position (point))))
(dired--trivial-next-line arg)))
(setq old-position (point)))))
(defun dired-previous-line (arg)
"Move up ARG lines, then position at filename.
@ -2753,9 +2751,8 @@ is controlled by `dired-movement-style'."
(interactive "^p" dired-mode)
(dired-next-line (- (or arg 1))))
(defun dired-next-dirline (arg &optional opoint)
(defun dired--trivial-next-dirline (arg &optional opoint)
"Goto ARGth next directory file line."
(interactive "p" dired-mode)
(or opoint (setq opoint (point)))
(if (if (> arg 0)
(re-search-forward dired-re-dir nil t arg)
@ -2763,10 +2760,24 @@ is controlled by `dired-movement-style'."
(re-search-backward dired-re-dir nil t (- arg)))
(dired-move-to-filename) ; user may type `i' or `f'
(goto-char opoint)
(error "No more subdirectories")))
(unless dired-movement-style
(error "No more subdirectories"))))
(defun dired-next-dirline (arg &optional _opoint)
"Goto ARGth next directory file line.
Whether to skip empty lines and how to move from last line
is controlled by `dired-movement-style'."
(interactive "p" dired-mode)
(if dired-movement-style
(dired--move-to-next-line arg #'dired--trivial-next-dirline)
(dired--trivial-next-dirline arg)))
(defun dired-prev-dirline (arg)
"Goto ARGth previous directory file line."
"Goto ARGth previous directory file line.
Whether to skip empty lines and how to move from last line
is controlled by `dired-movement-style'."
(interactive "p" dired-mode)
(dired-next-dirline (- arg)))