unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#65621: [PATCH] `dired-next-line' go to meaningful line
@ 2023-08-30 13:02 Shynur Xie
  2023-08-30 13:36 ` Eli Zaretskii
  2023-08-30 14:54 ` Drew Adams
  0 siblings, 2 replies; 34+ messages in thread
From: Shynur Xie @ 2023-08-30 13:02 UTC (permalink / raw)
  To: 65621

[-- Attachment #1: Type: text/plain, Size: 507 bytes --]

Cursor in Dired buffer sometimes go to a line which is not an item
line.  For example, the 1st line and the last line:

   > d:/Desktop/.emacs.d/site-lisp:
       drwxrwxrwx shynur 4096 08/30 18:15 .
       drwxrwxrwx shynur 4096 08/30 18:07 ..
       -rw-rw-rw- shynur  304 08/09  3:01 subdirs.el
   > \Newline here.

Avoiding these lines may improve the experience when moving cursor.
The attaching patch implements this.

If there is no visible item line, move the cursor as Dired used to do.

[-- Attachment #2: 0001-dired-next-line-go-to-meaningful-line.patch --]
[-- Type: application/octet-stream, Size: 2625 bytes --]

From c580e0f502eaa9180a5b97bb3f57d8ee4aed51db Mon Sep 17 00:00:00 2001
From: shynur <one.last.kiss@outlook.com>
Date: Wed, 30 Aug 2023 19:47:52 +0800
Subject: [PATCH] `dired-next-line' go to meaningful line

---
 lisp/dired.el | 42 ++++++++++++++++++++++++++++++++----------
 1 file changed, 32 insertions(+), 10 deletions(-)

diff --git a/lisp/dired.el b/lisp/dired.el
index e96b85a..3b5753e 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -2666,22 +2666,44 @@ Otherwise, toggle `read-only-mode'."
       (wdired-change-to-wdired-mode)
     (read-only-mode 'toggle)))
 
+(defun dired-filename-line-p ()
+  "Return t if the current line is a filename line."
+  (save-excursion
+    (dired-move-to-filename)
+    (get-char-property (point) 'dired-filename)))
+
 (defun dired-next-line (arg)
   "Move down lines then position at filename.
-Optional prefix ARG says how many lines to move; default is one line."
+Optional prefix ARG says how many lines to move; default is one line.
+
+Point won't go to the dired-header line or the last empty line.  If
+you really want to move there, use `next-line' instead."
   (interactive "^p")
-  (let ((line-move-visual)
-	(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))))
-    (forward-char (if (and arg (< arg 0)) -1 1)))
-  (dired-move-to-filename))
+  (let ((old-line-has-filename (dired-filename-line-p)))
+    (let ((line-move-visual)
+          (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))))
+      (forward-char (if (and arg (< arg 0)) -1 1)))
+    (dired-move-to-filename)
+    ;; If there's a line (or one of its succeeding lines) that we can
+    ;; go back to,
+    (when old-line-has-filename
+      ;; and the current line doesn't contain a filename,
+      (unless (dired-filename-line-p)
+        ;; then let's move back.
+        (dired-next-line (if (natnump arg)
+                             -1
+                           1))))))
 
 (defun dired-previous-line (arg)
   "Move up lines then position at filename.
-Optional prefix ARG says how many lines to move; default is one line."
+Optional prefix ARG says how many lines to move; default is one line.
+
+Point won't go to the dired-header line or the last empty line.  If
+you really want to move there, use `previous-line' instead."
   (interactive "^p")
   (dired-next-line (- (or arg 1))))
 
-- 
2.41.0.windows.3


^ permalink raw reply related	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2023-09-10  7:45 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-30 13:02 bug#65621: [PATCH] `dired-next-line' go to meaningful line Shynur Xie
2023-08-30 13:36 ` Eli Zaretskii
2023-08-30 13:50   ` Shynur Xie
2023-08-30 14:20     ` Eli Zaretskii
2023-08-30 19:14       ` Stefan Kangas
2023-08-30 20:58         ` Drew Adams
2023-08-30 21:34           ` Stefan Kangas
2023-08-30 22:36             ` Drew Adams
2023-08-31  5:45         ` Shynur Xie
2023-08-31 15:35           ` Drew Adams
2023-08-31 15:46             ` Shynur Xie
2023-08-31 15:55               ` Drew Adams
2023-08-31 18:15                 ` Shynur Xie
2023-08-31 19:10                   ` Drew Adams
2023-08-31 19:17                     ` Drew Adams
2023-08-31 19:44                     ` Shynur Xie
2023-08-31 21:51                       ` Drew Adams
2023-08-31 21:35                   ` Stefan Kangas
2023-08-31 21:37                     ` Stefan Kangas
2023-09-01 17:29                     ` Shynur Xie
2023-09-01 18:46                       ` Drew Adams
2023-09-01 20:51                         ` Shynur Xie
2023-09-01 21:06                           ` Drew Adams
2023-09-02 12:05                             ` Shynur Xie
2023-09-02 12:13                               ` Eli Zaretskii
2023-09-02 12:18                                 ` Shynur Xie
2023-09-02 12:39                                   ` Eli Zaretskii
2023-09-02 14:40                                     ` Shynur Xie
2023-09-10  7:45                                       ` Eli Zaretskii
2023-09-03 21:47                               ` Drew Adams
2023-09-07 15:04                                 ` Shynur Xie
2023-08-30 14:54 ` Drew Adams
2023-08-30 15:39   ` Shynur Xie
2023-08-30 15:55     ` Drew Adams

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).