branch: elpa/dirvish commit 5e503cbcd4e2f8a74a644320a8cd9ca77e63e3a5 Author: Alex Lu <hellosimon1...@hotmail.com> Commit: Alex Lu <hellosimon1...@hotmail.com>
feat(core): add `dirvish-preview-dired-sync-omit` user option (#225) closes #225: I'm still undecided on introducing dired-omit-mode in parent buffers, because they are not regular dired buffers, support and sync `dired-omit-mode` there can be rather complex. --- dirvish.el | 82 ++++++++++++++++++++++++++++++++-------------------- docs/CUSTOMIZING.org | 31 ++++++++++++-------- 2 files changed, 69 insertions(+), 44 deletions(-) diff --git a/dirvish.el b/dirvish.el index 1d8c3bfc4d..a2b9af7cb3 100644 --- a/dirvish.el +++ b/dirvish.el @@ -48,7 +48,8 @@ Dirvish ships with these attributes: - `file-time': Show file modification time before the `file-size'." :group 'dirvish :type '(repeat (symbol :tag "Dirvish attribute"))) -(defcustom dirvish-preview-dispatchers '(image gif video audio epub archive pdf) +(defcustom dirvish-preview-dispatchers + '(image gif video audio epub archive pdf dired) "List of preview dispatchers. Each dispatcher in this list handles the validation and preview content generation for the corresponding filetype. @@ -61,7 +62,8 @@ The default value contains: - audio: preview audio files with metadata, requires `mediainfo'. - epub: preview epub documents, requires `epub-thumbnailer'. - pdf: preview pdf documents via `pdf-tools'. -- archive: preview archive files such as .tar, .zip, requires `tar' / `unzip'." +- archive: preview archive files such as .tar, .zip, requires `tar' / `unzip'. +- dired: preview directories using `emacs --batch'." :group 'dirvish :type '(repeat (symbol :tag "Dirvish preview methods"))) (defcustom dirvish-preview-disabled-exts '("iso" "bin" "exe" "gpg" "elc" "eln") @@ -161,11 +163,11 @@ Set it to nil to use the default `mode-line-format'." :group 'dirvish :type 'plist) (defcustom dirvish-hide-details t - "Whether to hide detailed information in Dirvish buffers. -When sets to t, it hide detailed listing info for all Dirvish buffers. + "Whether to enable `dired-hide-details-mode' in Dirvish buffers. +When sets to t, it is enabled for all Dirvish buffers. Alternatively, the value can be a list of symbols to instruct Dirvish in -what contexts they should be hided. The accepted values are: +what contexts it should be enabled. The accepted values are: - `dired': when opening a directory using `dired-*' commands. - `dirvish': when opening full-frame Dirvish. - `dirvish-fd': when the buffer is create by `dirvish-fd*' commands. @@ -181,6 +183,11 @@ Works all the same as `dirvish-hide-details' but for cursor." :type '(choice (boolean :tag "Apply to all Dirvish buffers") (repeat :tag "Apply to a list of buffer types: 'dired, 'dirvish, 'dirvish-fd or 'dirvish-side" symbol))) +(defcustom dirvish-preview-dired-sync-omit nil + "If non-nil, `dired' preview buffers sync `dired-omit-mode' from root window. +Notice that it only take effects on the built-in `dired' preview dispatcher." + :group 'dirvish :type 'boolean) + (defcustom dirvish-window-fringe 1 "Window fringe for dirvish windows." :group 'dirvish :type 'integer) @@ -488,7 +495,7 @@ If INHIBIT-HIDING is non-nil, do not hide the buffer." (defun dirvish--make-proc (form sentinel buffer-or-name &rest puts) "Make process for shell or batch FORM in BUFFER-OR-NAME. -Set process's SENTINEL had PUTS accordingly." +Set process's SENTINEL and PUTS accordingly." (let* ((buf (or buffer-or-name (make-temp-name "*dirvish-batch*"))) (print-length nil) (print-level nil) (cmd (if (stringp (car form)) form @@ -572,7 +579,7 @@ ARGS is a list of keyword arguments for `dirvish' struct." (cl-loop with dps = (or dps dirvish-preview-dispatchers) with res = (prog1 '() (require 'recentf) (require 'ansi-color)) with fmt = "[Dirvish]: install '%s' executable to preview %s files." - for dp in (append '(disable) dps '(default)) + for dp in (append '(disable) dps '(fallback)) for info = (alist-get dp dirvish--available-preview-dispatchers) for requirements = (plist-get info :require) for met = t @@ -861,16 +868,6 @@ When FORCE, ensure the preview get refreshed." ;;;; Preview -(dirvish-define-preview disable (file ext) - "Disable preview in some cases." - (cond - ((not (file-exists-p file)) - `(info . ,(format "%s does not exist" file))) - ((not (file-readable-p file)) - `(info . ,(format "%s is not readable" file))) - ((member ext dirvish-preview-disabled-exts) - `(info . ,(format "Preview for %s has been disabled" file))))) - (defun dirvish--find-file-temporarily (name) "Open file NAME temporarily for preview." (cl-letf (((symbol-function 'recentf-track-opened-file) #'ignore) @@ -887,24 +884,45 @@ When FORCE, ensure the preview get refreshed." (set-default k d) (set k v))))) (cond ((ignore-errors (buffer-local-value 'so-long-detected-p buf)) (kill-buffer buf) - `(info . ,(format "File `%s' with long lines not previewed" name))) + `(info . ,(format "File [ %s ] contains very long lines" name))) (t `(buffer . ,buf)))))) -(dirvish-define-preview default (file ext) - "Default preview dispatcher for FILE." - (when-let* ((attrs (ignore-errors (file-attributes file))) - (size (file-attribute-size attrs))) - (cond ((file-directory-p file) ; default directory previewer - (let ((script - `(let ,(mapcar (lambda (env) `(,(car env) ,(cdr env))) - (remove (cons 'inhibit-message t) - dirvish-preview-environment)) - (setq insert-directory-program ,insert-directory-program) - (with-current-buffer (dired-noselect ,file "-AlGh") - (message "\n%s" (buffer-string)))))) - `(dired . ,script))) +(dirvish-define-preview disable (file ext) + "Disable preview in some cases." + (cond + ((not (file-exists-p file)) + `(info . ,(format "[ %s ] does not exist" file))) + ((not (file-readable-p file)) + `(info . ,(format "[ %s ] is not readable" file))) + ((member ext dirvish-preview-disabled-exts) + `(info . ,(format "Preview for filetype [ %s ] has been disabled" ext))))) + +(dirvish-define-preview dired (file) + "Preview dispatcher for directory FILE." + (when (file-directory-p file) + `(dired . (let ,(mapcar (lambda (env) `(,(car env) ,(cdr env))) + (remove (cons 'inhibit-message t) + dirvish-preview-environment)) + (setq insert-directory-program ,insert-directory-program) + (setq dired-listing-switches ,dired-listing-switches) + (setq dired-omit-verbose ,(bound-and-true-p dired-omit-verbose)) + (setq dired-omit-files ,(bound-and-true-p dired-omit-files)) + (with-current-buffer (dired-noselect ,file) + ,(and dirvish-preview-dired-sync-omit + (bound-and-true-p dired-omit-mode) + `(dired-omit-mode)) + (message "\n%s" (buffer-string))))))) + +(dirvish-define-preview fallback (file ext) + "Fallback preview dispatcher for FILE." + (let* ((attrs (ignore-errors (file-attributes file))) + (size (file-attribute-size attrs))) + (cond ((not attrs) + `(info . ,(format "Can not get attributes of [ %s ]." file))) + ((not size) + `(info . ,(format "Can not get file size of [ %s ]." file))) ((> size (or large-file-warning-threshold 10000000)) - `(info . ,(format "File %s is too big for literal preview." file))) + `(info . ,(format "File [ %s ] is too big for literal preview." file))) ((member ext dirvish-media-exts) `(info . "Preview disabled for media files")) (t (dirvish--find-file-temporarily file))))) diff --git a/docs/CUSTOMIZING.org b/docs/CUSTOMIZING.org index fd6aeec3f0..67b83c4d03 100644 --- a/docs/CUSTOMIZING.org +++ b/docs/CUSTOMIZING.org @@ -165,7 +165,7 @@ conditions. The variable ~dirvish-preview-dispatchers~, which holds all the acti dispatchers, has the default value looks like: #+begin_src emacs-lisp -(image gif video audio epub pdf archive) +(image gif video audio epub pdf archive dired) #+end_src + ~image~: preview image files, requires =imagemagick= @@ -175,6 +175,7 @@ dispatchers, has the default value looks like: + ~epub~: preview epub documents, requires [[https://github.com/alexluigit/dirvish/issues/85][epub-thumbnail]] + ~pdf~: preview pdf documents via =pdf-tools= + ~archive~: preview archive files such as =.tar=, =.zip=, requires =tar= / =unzip= ++ ~dired~: preview directories using =dired= (asynchronously) Each dispatcher in this list handles the validation and preview content generation for the corresponding filetype. To enable/disable certain preview @@ -188,6 +189,10 @@ want to display preview for epub files via packages like =nov=, just remove the (setq dirvish-preview-dispatchers (remove 'epub dirvish-preview-dispatchers)) #+end_src +The =dirvish-preview-dired-sync-omit= option allows ~dired~ preview buffers to sync +your =dired-omit-mode= and its settings from the root window, it is turned off by +default. + Some of preview dispatchers, such as ~image~, generate cache images to improve the preview experience. Every time you enter a directory, Dirvish scans the the content of that directory and computes the fileset of the directory that @@ -220,25 +225,27 @@ Note: this dispatcher requires the =pdftoppm= executable. (cl-substitute 'pdf-preface 'pdf dirvish-preview-dispatchers)) #+end_src -** Preview directory using ~exa~ command +** Preview directory using ~eza~ command Let's assume you don't like the default directory preview results provided by -Dired, you can create a directory previewer that utilizes the ~exa~ command: +Dired, you can create a directory previewer that utilizes the ~eza~ command: #+begin_src emacs-lisp - (dirvish-define-preview exa (file) - "Use `exa' to generate directory preview." - :require ("exa") ; tell Dirvish to check if we have the executable - (when (file-directory-p file) ; we only interest in directories here - `(shell . ("exa" "-al" "--color=always" "--icons" - "--group-directories-first" ,file)))) - - (add-to-list 'dirvish-preview-dispatchers 'exa) +(dirvish-define-preview eza (file) + "Use `exa' to generate directory preview." + :require ("eza") ; tell Dirvish to check if we have the executable + (when (file-directory-p file) ; we only interest in directories here + `(shell . ("eza" "-al" "--color=always" "--icons=always" + "--group-directories-first" ,file)))) + +(setq dirvish-preview-dispatchers + (cl-substitute 'dired 'exa dirvish-preview-dispatchers)) #+end_src This makes Dirvish use the output from ~exa~ shell command as your preview content for a directory entry. On a side note, you can customize the corresponding -=ansi-color= faces to change the coloring in the preview window. +=ansi-color= faces to change the coloring in the preview window if your theme +doesn't have good integration with the =ansi-color= package. #+begin_src emacs-lisp (set-face-attribute 'ansi-color-blue nil :foreground "#FFFFFF")