aboutsummaryrefslogtreecommitdiff
path: root/modules/dirvish-config.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-10 13:44:40 -0500
committerCraig Jennings <c@cjennings.net>2026-05-10 13:44:40 -0500
commit2b19eb175d0664908f76bf7cc8dcc1eb5c140ce1 (patch)
tree9beb7545eb65385b13246e561e764844ba49eb70 /modules/dirvish-config.el
parentcffdf3b92a97b1af3aedec624a9fb43db1c60ef8 (diff)
downloaddotemacs-2b19eb175d0664908f76bf7cc8dcc1eb5c140ce1.tar.gz
dotemacs-2b19eb175d0664908f76bf7cc8dcc1eb5c140ce1.zip
refactor(dirvish): extract cj/--dired-line-is-directory-p
`cj/dired-mark-all-visible-files' classified the current line as a directory via `(looking-at "^. d")' inline. Lift the classification into `cj/--dired-line-is-directory-p', a string predicate that takes a line and returns non-nil when it's a directory listing. The wrapper still walks the dired buffer line by line and calls `dired-mark' -- that iteration is dired-coupled and stays untested -- but the format-aware predicate is now isolated and verified. Six Normal/Boundary tests cover unmarked directories, marked directories (`*' prefix), regular files (`-' instead of `d'), symlinks (`l'), empty lines, and dired header lines (` /path:' and ` total N').
Diffstat (limited to 'modules/dirvish-config.el')
-rw-r--r--modules/dirvish-config.el17
1 files changed, 15 insertions, 2 deletions
diff --git a/modules/dirvish-config.el b/modules/dirvish-config.el
index ad2227e8..f032b1a0 100644
--- a/modules/dirvish-config.el
+++ b/modules/dirvish-config.el
@@ -180,14 +180,27 @@ used by `cj/dirvish-open-html-in-eww'."
;;; ------------------------ Dired Mark All Visible Files -----------------------
+(defun cj/--dired-line-is-directory-p (line)
+ "Return non-nil when LINE is a Dired listing of a directory.
+
+Dired prefixes each file line with a one-character mark column followed
+by `ls -l' output, so a directory line reads as `<mark> drwx...' (mark,
+space, `d'). Header lines (` /path/to:'), `total N' lines, and empty
+lines all fail this match.
+
+Pure helper used by `cj/dired-mark-all-visible-files'."
+ (and line (string-match-p "\\`. d" line)))
+
(defun cj/dired-mark-all-visible-files ()
"Mark all visible files in Dired mode."
(interactive)
(save-excursion
(goto-char (point-min))
(while (not (eobp))
- (if (not (looking-at "^. d"))
- (dired-mark 1))
+ (let ((line (buffer-substring-no-properties
+ (line-beginning-position) (line-end-position))))
+ (unless (cj/--dired-line-is-directory-p line)
+ (dired-mark 1)))
(forward-line 1))))
;;; ------------------------ Dirvish Duplicate File Copy ------------------------