branch: elpa/dirvish commit 7011a0fbff90c09285cf86905a0ca009d43708f9 Author: Alex Lu <hellosimon1...@hotmail.com> Commit: Alex Lu <hellosimon1...@hotmail.com>
refactor: more robost attribute renderer; simplify fd proc filter --- dirvish.el | 8 ++++---- extensions/dirvish-fd.el | 21 ++++++++------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/dirvish.el b/dirvish.el index a72f3a590c..b1e70451c9 100644 --- a/dirvish.el +++ b/dirvish.el @@ -877,9 +877,9 @@ When the attribute does not exist, set it with BODY." (let ((f-beg (dired-move-to-filename)) (f-end (dired-move-to-end-of-filename t)) (l-beg (line-beginning-position)) (l-end (line-end-position)) - (f-wid 0) f-str f-name f-attrs f-type hl-face left right) + (f-wid 0) f-str f-name f-attrs f-type hl-face left right f-line?) (setq hl-face (and (eq (or f-beg l-beg) pos) hl)) - (when (and f-beg f-end) ; `f-end' is nil in a incomplete line + (when (setq f-line? (and f-beg f-end (eq (char-after l-end) 10))) (setq f-str (buffer-substring f-beg f-end) f-wid (string-width f-str) f-name (concat (if remote (dired-current-directory) @@ -889,7 +889,7 @@ When the attribute does not exist, set it with BODY." (unless remote (ignore-errors (file-attributes f-name)))) f-type (dirvish-attribute-cache f-name :type (let ((ch (progn (back-to-indentation) (char-after)))) - (cond ; ASCII: d -> 100, l -> 108 + (cond ; ASCII: d -> 100, l -> 108, LF(\n) -> 10 (remote `(,(if (eq ch 100) 'dir 'file) . nil)) ((eq ch 100) '(dir . nil)) ((eq ch 108) ; use slash for dir check is unreliable @@ -899,7 +899,7 @@ When the attribute does not exist, set it with BODY." (unless (get-text-property f-beg 'mouse-face) (dired-insert-set-properties l-beg l-end))) (cl-loop - for fn in (if (and f-beg f-end) fns '(dirvish-attribute-hl-line-rd)) + for fn in (if f-line? fns '(dirvish-attribute-hl-line-rd)) for (k . v) = (funcall fn f-beg f-end f-str f-name f-attrs f-type l-beg l-end hl-face w-width) do (pcase k ('ov (overlay-put v 'dirvish-a-ov t)) diff --git a/extensions/dirvish-fd.el b/extensions/dirvish-fd.el index 03d9f3e17c..097868a6c8 100644 --- a/extensions/dirvish-fd.el +++ b/extensions/dirvish-fd.el @@ -258,31 +258,26 @@ value 16, let the user choose the root directory of their search." (dired-jump nil full-file)))) (defun dirvish-fd-proc-filter (proc string) - "Filter for `dirvish-fd' processes PROC and output STRING." + "Filter for output STRING of `dirvish-fd''s processes PROC." (let ((buf (process-buffer proc))) (if (not (buffer-name buf)) (delete-process proc) (with-current-buffer buf (save-excursion (save-restriction (widen) - (let ((beg (point-max)) (data (dirvish-prop :fd-cache)) - buffer-read-only lb le fname) - (goto-char beg) - (insert string) + (let ((data (dirvish-prop :fd-cache)) buffer-read-only last file) + (goto-char (point-max)) (insert string) (goto-char (process-mark proc)) (or (looking-at "^") (forward-line 1)) + ;; strip " ./" prefix and collect data on complete lines (while-let ((fb (search-forward " ./" nil t)) - ((search-forward "\n" nil t))) ; skip incomplete lines + (le (line-end-position)) ((eq (char-after le) 10))) (delete-region fb (- fb 2)) - (forward-line -1) - (setq fname (buffer-substring (- fb 2) (line-end-position))) + (setq file (buffer-substring (- fb 2) (- le 2)) last le) (beginning-of-line) (insert " ") - (setq lb (line-beginning-position) le (line-end-position)) - (puthash fname (buffer-substring lb (1+ le)) data) + (puthash file (buffer-substring (- (point) 2) (1+ le)) data) (forward-line 1)) - (goto-char (point-max)) - (when (search-backward "\n" (process-mark proc) t) - (move-marker (process-mark proc) (1+ (point))))))))))) + (when last (move-marker (process-mark proc) (1+ last)))))))))) (defsubst dirvish-fd-revert (&rest _) "Revert buffer function for fd buffer."