emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/dirvish 2f06964137: refactor: remove data fetcher of sudo


From: ELPA Syncer
Subject: [nongnu] elpa/dirvish 2f06964137: refactor: remove data fetcher of sudo directory
Date: Sat, 22 Mar 2025 04:00:25 -0400 (EDT)

branch: elpa/dirvish
commit 2f06964137872c32ac716b6fe2df700f971854f8
Author: Alex Lu <hellosimon1103@hotmail.com>
Commit: Alex Lu <hellosimon1103@hotmail.com>

    refactor: remove data fetcher of sudo directory
    
    Regard sudo directory as regular directory, merge its data-for-dir handler 
to core.
---
 dirvish-tramp.el   | 35 ++---------------------------------
 dirvish-widgets.el |  6 +++---
 dirvish.el         | 30 +++++++++++++++---------------
 3 files changed, 20 insertions(+), 51 deletions(-)

diff --git a/dirvish-tramp.el b/dirvish-tramp.el
index 627f325d19..ab4c8f94db 100644
--- a/dirvish-tramp.el
+++ b/dirvish-tramp.el
@@ -44,7 +44,7 @@ FN is the original `dired-noselect' closure."
     (with-current-buffer buffer
       (dirvish-prop :gnuls gnuls)
       (cond ((eq async-type 'local)
-             (dirvish-prop :local-sudo 1)
+             (dirvish-prop :sudo 1)
              (dirvish-prop :preview-dps local-dispatchers))
             ((eq async-type 'async)
              (dirvish-prop :remote-async 1)
@@ -91,36 +91,6 @@ FN is the original `dired-noselect' closure."
             (dirvish--redisplay))))
     (dirvish--kill-buffer (process-buffer proc))))
 
-(cl-defmethod dirvish-data-for-dir
-  (dir buffer inhibit-setup &context ((dirvish-prop :local-sudo) number))
-  "Fetch data for DIR in BUFFER.
-It is called when DIRVISH-PROP :local-sudo is a number, which means DIR
-is opened using `sudo-edit'.  Run `dirvish-setup-hook' after data
-parsing unless INHIBIT-SETUP is non-nil."
-  (dirvish--make-proc
-   `(prin1
-     (let ((hs (make-hash-table)))
-       (dolist (file (directory-files ,(file-local-name dir) t nil t))
-         (let* ((attrs (ignore-errors (file-attributes file)))
-                (tp (nth 0 attrs)))
-           (cond ((eq t tp) (setq tp '(dir . nil)))
-                 (tp (setq tp `(,(if (file-directory-p tp) 'dir 'file) . ,tp)))
-                 (t (setq tp '(file . nil))))
-           (puthash (secure-hash 'md5 file) `(:builtin ,attrs :type ,tp) hs)))
-       hs))
-   (lambda (p _)
-     (pcase-let ((`(,buf . ,inhibit-setup) (process-get p 'meta))
-                 (data (with-current-buffer (process-buffer p)
-                         (read (buffer-string)))))
-       (when (buffer-live-p buf)
-         (with-current-buffer buf
-           (maphash (lambda (k v) (puthash k v dirvish--dir-data)) data)
-           (unless inhibit-setup (run-hooks 'dirvish-setup-hook))
-           (dirvish--redisplay))))
-     (delete-process p)
-     (dirvish--kill-buffer (process-buffer p)))
-   nil 'meta (cons buffer inhibit-setup)))
-
 (cl-defmethod dirvish-data-for-dir
   (dir buffer inhibit-setup
        &context ((dirvish-prop :remote-async) number)
@@ -158,12 +128,11 @@ which means DIR is opened over a remote host that supports
 (dirvish-define-preview tramp (file _ dv)
   "Preview files with `ls' or `head' for tramp files."
   (let ((process-connection-type nil)
-        (localname (file-remote-p file 'localname))
         (buf (dirvish--special-buffer 'preview dv t)) proc)
     (when-let* ((proc (get-buffer-process buf))) (delete-process proc))
     (setq proc (start-file-process-shell-command
                 (buffer-name buf) buf
-                (format dirvish-tramp-preview-cmd localname localname)))
+                (format dirvish-tramp-preview-cmd file file)))
     (set-process-sentinel
      proc (lambda (proc _sig)
             (when (memq (process-status proc) '(exit signal))
diff --git a/dirvish-widgets.el b/dirvish-widgets.el
index 5cf48e004b..71489b2bde 100644
--- a/dirvish-widgets.el
+++ b/dirvish-widgets.el
@@ -206,7 +206,7 @@ Audio;(Audio-codec . \"\"%CodecID%\"\")(Audio-bitrate . 
\"\"%BitRate/String%\"\"
 
 (defun dirvish--file-attr-size (name attrs)
   "Get file size of file NAME from ATTRS."
-  (cond ((and (dirvish-prop :remote) (not (dirvish-prop :local-sudo)))
+  (cond ((and (dirvish-prop :remote) (not (dirvish-prop :sudo)))
          (substring (format "      %s%s"
                             (or (file-attribute-size attrs) "?")
                             (if (dirvish-prop :gui) " " ""))
@@ -236,7 +236,7 @@ Audio;(Audio-codec . \"\"%CodecID%\"\")(Audio-bitrate . 
\"\"%BitRate/String%\"\"
 
 (defun dirvish--file-attr-time (name attrs)
   "File NAME's modified time from ATTRS."
-  (if (and (dirvish-prop :remote) (not (dirvish-prop :local-sudo)))
+  (if (and (dirvish-prop :remote) (not (dirvish-prop :sudo)))
       (format " %s " (or (file-attribute-modification-time attrs) "?"))
     (format " %s " (dirvish-attribute-cache name :f-time
                       (format-time-string
@@ -465,7 +465,7 @@ GROUP-TITLES is a list of group titles."
   "Last modification time of file."
   (pcase-let ((`(,time . ,face)
                (dirvish--format-file-attr 'modification-time 'time)))
-    (unless (and (dirvish-prop :remote) (not (dirvish-prop :local-sudo)))
+    (unless (and (dirvish-prop :remote) (not (dirvish-prop :sudo)))
       (setq time (format-time-string dirvish-time-format-string time)))
     (propertize (format "%s" time) 'face face)))
 
diff --git a/dirvish.el b/dirvish.el
index 515e857dbd..2a3df05e81 100644
--- a/dirvish.el
+++ b/dirvish.el
@@ -675,7 +675,7 @@ A dirvish preview dispatcher is a function consumed by
                 (setq dired-omit-verbose ,(bound-and-true-p 
dired-omit-verbose))
                 (setq dired-omit-files ,(bound-and-true-p dired-omit-files))
                 ;; for `sudo-edit' compat
-                (with-current-buffer (dired-noselect (file-local-name ,file))
+                (with-current-buffer (dired-noselect ,file)
                   ,(and dirvish-preview-dired-sync-omit
                         (bound-and-true-p dired-omit-mode)
                         `(dired-omit-mode))
@@ -758,18 +758,17 @@ When PROC finishes, fill preview buffer with process 
result."
 
 (defun dirvish--preview-update (dv index)
   "Update preview content of INDEX for DV."
-  (when-let* ((window (dv-preview-window dv))
-              ((window-live-p window))
+  (when-let* ((pwin (dv-preview-window dv)) ((window-live-p pwin))
+              (root (cdr (dv-index dv))) ((buffer-live-p root))
               (ext (downcase (or (file-name-extension index) "")))
-              (fns (with-current-buffer (window-buffer (dv-root-window dv))
-                     (dirvish-prop :preview-dps)))
+              (fns (with-current-buffer root (dirvish-prop :preview-dps)))
               (buf (cl-loop for fn in fns
-                            for rcp = (funcall fn index ext window dv) thereis
+                            for rcp = (funcall fn index ext pwin dv) thereis
                             (and rcp (dirvish-preview-dispatch rcp dv)))))
     (setq-local other-window-scroll-buffer buf)
     (unless (memq buf (dv-special-buffers dv))
       (cl-pushnew buf (dv-preview-buffers dv)))
-    (set-window-buffer window buf)))
+    (set-window-buffer pwin buf)))
 
 ;;;; Attributes
 
@@ -908,7 +907,7 @@ When the attribute does not exist, set it with BODY."
   (with-selected-window window
     (cl-loop with attrs = (dirvish-prop :attrs) unless attrs do (cl-return)
              with remote = (and (dirvish-prop :remote)
-                                (not (dirvish-prop :local-sudo)))
+                                (not (dirvish-prop :sudo)))
              with gui = (dirvish-prop :gui)
              with fns = () with height = (frame-height)
              with hl = (and (dirvish--apply-hiding-p dirvish-hide-cursor)
@@ -1106,7 +1105,7 @@ Optionally, use CURSOR as the enabled cursor type."
         ;; don't grab focus when peeking or preview window is selected
         (when (and (dirvish--selected-p dv)
                    (not (dirvish--get-session 'type 'peek)))
-          (dirvish--preview-update dv filename))))))
+          (dirvish--preview-update dv (file-local-name filename)))))))
 
 (defun dirvish-kill-buffer-h ()
   "Remove buffer from session's roots, clear session when roots is empty."
@@ -1168,8 +1167,8 @@ LEVEL is the depth of current window."
       (dirvish-directory-view-mode)
       (dirvish-prop :dv (dv-id dv))
       (dirvish-prop :remote (file-remote-p dir))
-      (dirvish-prop :local-sudo ; copy this from root avoids requiring tramp
-        (with-current-buffer (cdr (dv-index dv)) (dirvish-prop :local-sudo)))
+      (dirvish-prop :sudo ; copy this from root avoids requiring tramp
+        (with-current-buffer (cdr (dv-index dv)) (dirvish-prop :sudo)))
       (puthash dir str (dv-parent-hash dv))
       (let (buffer-read-only) (erase-buffer) (save-excursion (insert str)))
       (setq-local dired-subdir-alist (list (cons dir (point-min-marker))))
@@ -1203,12 +1202,13 @@ INHIBIT-SETUP is passed to `dirvish-data-for-dir'."
   (dirvish--make-proc
    `(prin1
      (let* ((hs (make-hash-table))
-            (remote? (file-remote-p ,dir))
+            (rmt? ,(with-current-buffer buffer
+                     (and (not (dirvish-prop :sudo)) (dirvish-prop :remote))))
+            (dir (if rmt? ,dir ,(file-local-name dir)))
             (i-bk ',(with-current-buffer buffer (dirvish-prop :vc-backend)))
             ;; inherit from cached backend, avoid unneeded vc info in subtrees
-            (bk (or i-bk (unless remote? (vc-responsible-backend ,dir t))))
-            (files (ignore-errors (directory-files ,dir t nil t))))
-       (dolist (file (unless remote? files))
+            (bk (or i-bk (unless rmt? (vc-responsible-backend dir t)))))
+       (dolist (file (unless rmt? (ignore-errors (directory-files dir t nil 
t))))
          (let* ((attrs (ignore-errors (file-attributes file)))
                 (tp (nth 0 attrs)))
            (cond ((eq t tp) (setq tp '(dir . nil)))



reply via email to

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