branch: elpa/dirvish
commit 8bd4ad811ab7dd9bd06616fcfcc9f3bc9e9366cc
Author: Alex Lu <hellosimon1...@hotmail.com>
Commit: Alex Lu <hellosimon1...@hotmail.com>

    BREAKING: replace `magick` with `vipsthumbnail` (#218)
    
    Compare to `magick`, this commands runs so fast, even the "Generating 
image..."
    info text becomes distracting since it flashes so quickly.  That's why we
    removed this info text as well.  I have not tested it on Windows but I 
guess it
    should work fine.
---
 README.org           | 31 ++++++++-----------
 dirvish-widgets.el   | 87 ++++++++--------------------------------------------
 dirvish.el           |  2 +-
 docs/CUSTOMIZING.org | 14 +--------
 4 files changed, 27 insertions(+), 107 deletions(-)

diff --git a/README.org b/README.org
index a305443fa1..3b2a98024b 100644
--- a/README.org
+++ b/README.org
@@ -34,44 +34,42 @@ file manager.
 
 This package requires =GNU ls= (~gls~ on macOS), and /optionally/:
 
-+ =fd= as a faster alternative to =find=
-+ =imagemagick= for image preview
-+ =poppler= | =pdf-tools= for pdf preview
-+ =ffmpegthumbnailer= (Linux/macOS) | =mtn= (Windows) for video preview
-+ =mediainfo= for audio/video metadata generation
-+ =tar= and =unzip= for archive files preview
++ [[https://github.com/sharkdp/fd][fd]] as a faster alternative to =find=
++ [[https://github.com/libvips][vipsthumbnail]] for image preview
++ [[https://poppler.freedesktop.org/][poppler]] | 
[[https://github.com/vedang/pdf-tools][pdf-tools]] for pdf preview
++ [[https://github.com/dirkvdb/ffmpegthumbnailer][ffmpegthumbnailer]] 
(Linux/macOS) | [[https://gitlab.com/movie_thumbnailer/mtn][mtn]] (Windows) for 
video preview
++ [[https://github.com/MediaArea/MediaInfo][mediainfo]] for audio/video 
metadata generation
++ [[https://www.gnu.org/software/tar/][tar]] and 
[[https://infozip.sourceforge.net/UnZip.html][unzip]] for archive files preview
 
 @@html:<details>@@
 @@html:<summary>@@ @@html:<b>@@Toggle install instructions@@html:</b>@@ 
@@html:</summary>@@
 
 @@html:<h2>@@macOS@@html:</h2>@@
 #+begin_src bash
-  brew install coreutils fd poppler ffmpegthumbnailer mediainfo imagemagick
+  brew install coreutils fd poppler ffmpegthumbnailer mediainfo vips
 #+end_src
 
 @@html:<h2>@@Debian-based@@html:</h2>@@
 #+begin_src bash
-  apt install fd-find poppler-utils ffmpegthumbnailer mediainfo imagemagick 
tar unzip
+  apt install fd-find poppler-utils ffmpegthumbnailer mediainfo libvips-tools 
tar unzip
 #+end_src
 
 @@html:<h2>@@Arch-based@@html:</h2>@@
 #+begin_src bash
-  pacman -S fd poppler ffmpegthumbnailer mediainfo imagemagick tar unzip
+  pacman -S fd poppler ffmpegthumbnailer mediainfo libvips tar unzip
 #+end_src
 
 @@html:<h2>@@FreeBSD@@html:</h2>@@
 #+begin_src bash
-  pkg install gnuls fd-find poppler ffmpegthumbnailer ImageMagick7 gtar
+  pkg install gnuls fd-find poppler ffmpegthumbnailer vips gtar
 #+end_src
 
 @@html:<h2>@@Windows@@html:</h2>@@
 #+begin_src bash
   # install via Scoop: https://scoop.sh/
-  scoop install coreutils fd poppler imagemagick unzip
+  scoop install coreutils fd poppler mtn libvips unzip
 #+end_src
 
-You might also want to install 
[[https://gitlab.com/movie_thumbnailer/mtn][mtn]] for video preview.
-
 @@html:</details>@@
 
 * Installation
@@ -86,13 +84,10 @@ activate Dirvish globally with =M-x 
dirvish-override-dired-mode RET=.
 
   Welcome to Dirvish!  Use your favorite dired commands here!
 
-+ =M-x dired= | =dired-jump= | ... =RET=
-
-  Dirvish takes care all of your Dired entries.
-
 + =M-x dirvish-dwim RET=
 
-  If the selected window is the only window, open Dirvish, otherwise open 
Dired.
+  Works the same as `dirvish` when the selected window is the only window;
+  otherwise, it avoids occupying the entire frame.
 
 + =M-x dirvish-dispatch RET=
 
diff --git a/dirvish-widgets.el b/dirvish-widgets.el
index 3ded3d3b7a..bfb6de6753 100644
--- a/dirvish-widgets.el
+++ b/dirvish-widgets.el
@@ -23,7 +23,7 @@
 ;;
 ;; Preview dispatchers:
 ;;
-;; - `image':       preview image files, requires `imagemagick'
+;; - `image':       preview image files, requires `vipsthumbnail'
 ;; - `gif':         preview GIF image files with animation
 ;; - `video':       preview videos files with thumbnail image
 ;;                    - requires `ffmpegthumbnailer' on Linux/macOS
@@ -53,8 +53,8 @@ The value is a list with 3 elements:
 - icon for path separators [/]"
   :group 'dirvish :type '(repeat (string :tag "path separator")))
 
-(defcustom dirvish-magick-program "magick"
-  "Absolute or reletive name of the `magick' program.
+(defcustom dirvish-vipsthumbnail-program "vipsthumbnail"
+  "Absolute or reletive name of the `vipsthumbnail' program.
 This is used to generate image thumbnails."
   :group 'dirvish :type 'string)
 
@@ -103,26 +103,6 @@ This is used to list files and their attributes for .tar, 
.gz etc. archives."
   "Show media properties automatically in preview window."
   :group 'dirvish :type 'boolean)
 
-(defvar dirvish-media--cache-pool '())
-(defvar dirvish-media--auto-cache-timer nil)
-(defcustom dirvish-media-auto-cache-threshold '(500 . 4)
-  "Generate cache images automatically.
-The value should be a cons cell (FILE-COUNT . PROC-COUNT) where
-both FILE-COUNT and PROC-COUNT should be a integer.  Directories
-with file count less than FILE-COUNT are cached automatically,
-PROC-COUNT is the max number of cache processes.  If this
-variable is nil, the auto caching is disabled."
-  :group 'dirvish
-  :type '(cons (integer :tag "Max number of directory files")
-               (integer :tag "Max number of cache process"))
-  :set (lambda (k v)
-         (set k v)
-         (and (timerp dirvish-media--auto-cache-timer)
-              (cancel-timer dirvish-media--auto-cache-timer))
-         (unless v
-           (setq dirvish-media--auto-cache-timer
-                 (run-with-timer 0 0.25 #'dirvish-media--autocache)))))
-
 (defconst dirvish-media--img-max-width 2400)
 (defconst dirvish-media--img-scale-h 0.75)
 (defconst dirvish-media--img-scale-w 0.92)
@@ -274,20 +254,6 @@ A new directory is created unless NO-MKDIR."
     (and (equal path (process-get proc 'path))
          (dirvish-debounce nil (dirvish--preview-update dv path)))))
 
-(defun dirvish-media--autocache ()
-  "Pop and run the cache tasks in `dirvish-media--cache-pool'."
-  (when (and dirvish-media--cache-pool
-             (< (length (process-list))
-                (or (cdr dirvish-media-auto-cache-threshold) 0)))
-    (let (process-connection-type proc)
-      (pcase-let* ((`(,procname . (,path ,_width ,cmd ,args))
-                    (pop dirvish-media--cache-pool)))
-        (when path
-          (setq proc (apply #'start-process procname
-                            (get-buffer-create "*img-cache*") cmd args))
-          (process-put proc 'path path)
-          (set-process-sentinel proc #'dirvish-media--cache-sentinel))))))
-
 (defun dirvish-media--group-heading (group-titles)
   "Format media group heading in Dirvish preview buffer.
 GROUP-TITLES is a list of group titles."
@@ -501,27 +467,6 @@ GROUP-TITLES is a list of group titles."
 
 ;;;; Preview dispatchers
 
-(cl-defmethod dirvish-build-cache (&context ((display-graphic-p) (eql t)))
-  "Cache image/video-thumbnail when `DISPLAY-GRAPHIC-P'."
-  (when-let* ((dv (dirvish-curr))
-              ((not (dirvish-prop :remote)))
-              ((dv-curr-layout dv))
-              (win (dv-preview-window dv))
-              ((window-live-p win))
-              (width (window-width win))
-              ((< (hash-table-count dirvish--attrs-hash)
-                  (or (car dirvish-media-auto-cache-threshold) 0))))
-    (cl-loop
-     with fns = '(dirvish-image-dp dirvish-video-dp dirvish-epub-dp)
-     for file in (directory-files default-directory t)
-     for ext = (downcase (or (file-name-extension file) ""))
-     for (cmd . args) = (cl-loop for fn in fns
-                                 for (k . v) = (funcall fn file ext win dv)
-                                 thereis (and (eq k 'cache) v))
-     when cmd do (push (cons (format "%s-%s-img-cache" file width)
-                             (list file width cmd args))
-                       dirvish-media--cache-pool))))
-
 (cl-defmethod dirvish-clean-cache (&context ((display-graphic-p) (eql t)))
   "Clean cache images for marked files when `DISPLAY-GRAPHIC-P'."
   (when-let* ((win (dv-preview-window (dirvish-curr)))
@@ -605,17 +550,13 @@ GROUP-TITLES is a list of group titles."
          (name (format "%s-%s-img-cache" path
                        (window-width (dv-preview-window dv)))))
     (unless (get-process name)
-      (setq dirvish-media--cache-pool
-            (delete (assoc name dirvish-media--cache-pool) 
dirvish-media--cache-pool))
       (let ((proc (apply #'start-process
                          name (get-buffer-create "*img-cache*")
                          (cadr recipe) (cddr recipe))))
         (process-put proc 'path path)
         (set-process-sentinel proc #'dirvish-media--cache-sentinel)))
     (with-current-buffer buf
-      (let (buffer-read-only)
-        (erase-buffer) (remove-overlays) (insert "\n Generating image..."))
-      buf)))
+      (let (buffer-read-only) (erase-buffer) (remove-overlays)) buf)))
 
 (defun dirvish-media--img-size (window &optional height)
   "Get corresponding image width or HEIGHT in WINDOW."
@@ -633,21 +574,17 @@ Require: `mediainfo' (executable)"
 
 (dirvish-define-preview image (file ext preview-window)
   "Preview image files.
-Require: `magick' (executable from `imagemagick' suite)"
-  :require (dirvish-magick-program)
+Require: `vipsthumbnail'"
+  :require (dirvish-vipsthumbnail-program)
   (when (member ext dirvish-image-exts)
     (let* ((w (dirvish-media--img-size preview-window))
            (h (dirvish-media--img-size preview-window 'height))
-           (cache (dirvish-media--cache-path
-                   file (format "images/%s" w) ".jpg")))
-      (cond ((file-exists-p cache)
-             `(img . ,(create-image cache nil nil :max-width w :max-height h)))
-            ((and (< (file-attribute-size (file-attributes file)) 250000)
-                  (member ext '("jpg" "jpeg" "png" "ico" "icns" "bmp" "svg")))
-             `(img . ,(create-image file nil nil :max-width w :max-height h)))
-            (t `(cache . (,dirvish-magick-program
-                          ,file "-define" "jpeg:extent=300kb" "-resize"
-                          ,(number-to-string w) ,cache)))))))
+           (cache (dirvish-media--cache-path file (format "images/%s" w) 
".jpg")))
+      (cond
+       ((file-exists-p cache)
+        `(img . ,(create-image cache nil nil :max-width w :max-height h)))
+       (t `(cache . ("vipsthumbnail",file "--size" ,(format "%sx" w)
+                     "--output" ,cache)))))))
 
 (dirvish-define-preview gif (file ext)
   "Preview gif images with animations."
diff --git a/dirvish.el b/dirvish.el
index 3c4b393faa..46889a5479 100644
--- a/dirvish.el
+++ b/dirvish.el
@@ -56,7 +56,7 @@ content generation for the corresponding filetype.
 
 The default value contains:
 
-- image: preview image files, requires `imagemagick'.
+- image: preview image files, requires `vipsthumbnail'.
 - gif: preview GIF image files with animation.
 - video: preview videos files with thumbnail.
     requires `ffmpegthumbnailer' on Linux/macOS | `mtn' on Windows
diff --git a/docs/CUSTOMIZING.org b/docs/CUSTOMIZING.org
index efff09b117..30ce68d510 100644
--- a/docs/CUSTOMIZING.org
+++ b/docs/CUSTOMIZING.org
@@ -207,7 +207,7 @@ dispatchers, has the default value looks like:
 (image gif video audio epub pdf archive dired)
 #+end_src
 
-+ ~image~: preview image files, requires =imagemagick=
++ ~image~: preview image files, requires =vipsthumbnail=
 + ~gif~: preview GIF image files with animation
 + ~video~: preview videos files with thumbnail,
     requires =ffmpegthumbnailer= on Linux/macOS
@@ -230,17 +230,6 @@ 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
 
-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
-requires cache image generation, the corresponding caches are generated later
-when Emacs is idle.
-
-You can tweak the behavior of auto caching or turn off this feature completely
-by customizing the ~dirvish-media-auto-cache-threshold~ option.  If you don't 
want
-the media properties displayed in the preview buffer, you can turn off
-~dirvish-show-media-properties~.
-
 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.
@@ -249,7 +238,6 @@ Dirvish also offers these user options to customize its 
preview behavior. Refer
 to the docstrings of these options for detailed information.
 
  * ~dirvish-preview-buffers-max-count~
- * ~dirvish-preview-disabled-exts~
  * ~dirvish-preview-environment~
  * ~dirvish-preview-large-file-threshold~
 

Reply via email to