emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 29d42d9158a: Support dired-movement-style in dired-next-dirline a


From: Juri Linkov
Subject: master 29d42d9158a: Support dired-movement-style in dired-next-dirline and dired-prev-dirline
Date: Thu, 23 Nov 2023 13:14:01 -0500 (EST)

branch: master
commit 29d42d9158ae836fc30d72dbdf4a8236a01de87f
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>

    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.
---
 etc/NEWS      |  9 +++---
 lisp/dired.el | 97 +++++++++++++++++++++++++++++++++--------------------------
 2 files changed, 59 insertions(+), 47 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index c0f76ed052b..259af667c03 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -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
 
diff --git a/lisp/dired.el b/lisp/dired.el
index c212e3094f8..a3d7c636d29 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -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
@@ -2688,11 +2689,11 @@ Otherwise, toggle `read-only-mode'."
 (defun dired--trivial-next-line (arg)
   "Move down ARG lines, then position at filename."
   (let ((line-move-visual)
-    (goal-column))
+        (goal-column))
     (line-move arg t))
   ;; We never want to move point into an invisible line.
   (while (and (invisible-p (point))
-          (not (if (and arg (< arg 0)) (bobp) (eobp))))
+              (not (if (and arg (< arg 0)) (bobp) (eobp))))
     (forward-char (if (and arg (< arg 0)) -1 1)))
   (dired-move-to-filename))
 
@@ -2705,44 +2706,41 @@ 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
-      (let ((old-position (progn
-                            ;; It's always true that we should move
-                            ;; to the filename when possible.
-                            (dired-move-to-filename)
-                            (point)))
-            ;; Up/Down indicates the direction.
-            (moving-down (if (cl-plusp arg)
-                             1    ; means Down.
-                           -1)))  ; means Up.
-        ;; Line by line in case we forget to skip empty lines.
-        (while (not (zerop arg))
-          (dired--trivial-next-line moving-down)
-          (when (= old-position (point))
-            ;; Now point is at beginning/end of movable area,
-            ;; but it still wants to move farther.
-            (if (eq dired-movement-style 'cycle)
-                ;; `cycle': go to the other end.
-                (goto-char (if (cl-plusp moving-down)
-                               (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)))
-              ;; 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))))
-            ;; Has moved to a non-empty line.  This movement does
-            ;; make sense.
-            (cl-decf arg moving-down))
-          (setq old-position (point))))
+      (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.
+                        (dired-move-to-filename)
+                        (point)))
+        ;; Up/Down indicates the direction.
+        (moving-down (if (cl-plusp arg)
+                         1              ; means Down.
+                       -1)))            ; means Up.
+    ;; Line by line in case we forget to skip empty lines.
+    (while (not (zerop arg))
+      (funcall jumpfun moving-down)
+      (when (= old-position (point))
+        ;; Now point is at beginning/end of movable area,
+        ;; but it still wants to move farther.
+        (if (eq dired-movement-style 'cycle)
+            ;; `cycle': go to the other end.
+            (goto-char (if (cl-plusp moving-down)
+                           (point-min)
+                         (point-max)))
+          ;; `bounded': go back to the last non-empty line.
+          (while (dired-between-files)
+            (funcall jumpfun (- moving-down)))
+          ;; Encountered a boundary, so let's stop movement.
+          (setq arg moving-down)))
+      (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)))))
+
 (defun dired-previous-line (arg)
   "Move up ARG lines, then position at filename.
 The argument ARG (interactively, prefix argument) says how many lines
@@ -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)))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]