mtn generates thumbnails with different filename than what dirvish expects. This wrapper renames mtn output to match dirvish's expected MD5-based filename.
102 lines
4.3 KiB
EmacsLisp
102 lines
4.3 KiB
EmacsLisp
;;; init-dired.el --- dired & dirvish -*-lexical-binding: t -*-
|
|
|
|
;;; Commentary:
|
|
|
|
;;; Code:
|
|
|
|
(with-eval-after-load 'dirvish
|
|
(define-key dirvish-mode-map (kbd "<down>")
|
|
(lambda () (interactive) (forward-line 1) (dired-move-to-filename)))
|
|
(define-key dirvish-mode-map (kbd "C-n")
|
|
(lambda () (interactive) (forward-line 1) (dired-move-to-filename)))
|
|
(define-key dirvish-mode-map (kbd "n")
|
|
(lambda () (interactive) (forward-line 1) (dired-move-to-filename)))
|
|
(define-key dirvish-mode-map (kbd "b") 'dired-up-directory)
|
|
(define-key dirvish-mode-map (kbd "C-b") 'dired-up-directory)
|
|
(define-key dirvish-mode-map (kbd "<left>") 'dired-up-directory)
|
|
(define-key dirvish-mode-map (kbd "<right>") 'dired-find-file)
|
|
(define-key dirvish-mode-map (kbd "C-f") 'dired-find-file)
|
|
(define-key dirvish-mode-map (kbd "<SPC>") 'dirvish-layout-toggle))
|
|
|
|
(with-eval-after-load 'dirvish
|
|
(add-hook 'dired-mode-hook #'dired-hide-details-mode))
|
|
|
|
;; dirvish
|
|
(use-package dirvish
|
|
:init
|
|
(dirvish-override-dired-mode)
|
|
:config
|
|
(setq dirvish-hide-details nil)
|
|
(setq dirvish-use-mode-line 'global)
|
|
:custom
|
|
(dirvish-quick-access-entries
|
|
(when *is-windows*
|
|
'(("h" "~/" "Home")
|
|
("e" "~/.emacs.d/")
|
|
("p" "c:/Users/gaozh/Pictures/Screenshots/" "Pictures")
|
|
("d" "f:/下载25-2-10/" "Download")
|
|
("v" "f:/luping26-1-11/" "Videos")))))
|
|
|
|
(setq dired-listing-switches
|
|
"-l --almost-all --human-readable --group-directories-first --no-group")
|
|
(put 'dired-find-alternate-file 'disabled nil)
|
|
|
|
(with-eval-after-load 'dirvish
|
|
(global-set-key (kbd "C-c d a") 'dirvish-quick-access)
|
|
(global-set-key (kbd "C-c d s") 'dirvish-side)
|
|
(global-set-key (kbd "C-c d h") 'dirvish-history-menu)
|
|
(global-set-key (kbd "C-x d") 'dired-jump)
|
|
(global-set-key (kbd "C-x C-j") 'dired)
|
|
(define-key dired-mode-map (kbd "h") 'dirvish-history-menu)
|
|
(define-key dired-mode-map (kbd "M-,") 'scroll-other-window-down)
|
|
(define-key dired-mode-map (kbd "M-.") 'scroll-other-window))
|
|
|
|
(with-eval-after-load 'dirvish
|
|
(global-set-key (kbd "C-c d a") 'dirvish-quick-access)
|
|
(global-set-key (kbd "C-c d s") 'dirvish-side)
|
|
(global-set-key (kbd "C-c d h") 'dirvish-history-menu)
|
|
(global-set-key (kbd "C-x d") 'dired-jump)
|
|
(global-set-key (kbd "C-x C-j") 'dired)
|
|
(define-key dired-mode-map (kbd "h") 'dirvish-history-menu)
|
|
(define-key dired-mode-map (kbd "M-,") 'scroll-other-window-down)
|
|
(define-key dired-mode-map (kbd "M-.") 'scroll-other-window))
|
|
|
|
;; Fix video-mtn preview issue on Windows
|
|
;; The problem: mtn generates thumbnails with filename like "video.mp4.jpg",
|
|
;; but dirvish expects MD5-based filename like "a1b2c3d4.jpg"
|
|
(with-eval-after-load 'dirvish
|
|
;; Function to find mtn output file for a given video file in cache directory
|
|
(defun my/dirvish-find-mtn-output (video-file cache-dir ext)
|
|
"Find mtn-generated thumbnail for VIDEO-FILE in CACHE-DIR with extension EXT."
|
|
(let* ((file-base (file-name-base video-file))
|
|
;; mtn generates: [filename].[ext].jpg
|
|
(mtn-pattern (format "%s.%s.jpg" (regexp-quote file-base) ext))
|
|
(files (directory-files cache-dir t mtn-pattern)))
|
|
(car files)))
|
|
|
|
;; Advice to fix the sentinel after mtn generates the thumbnail
|
|
(defun my/dirvish-media--cache-sentinel-advice (orig-fun proc exit-code)
|
|
"Advice to rename mtn output to MD5 format after generation."
|
|
(let* ((video-path (process-get proc 'path))
|
|
(ext (downcase (or (file-name-extension video-path) "")))
|
|
(dv (dirvish-curr)))
|
|
(when (and (memq system-type '(ms-dos windows-nt))
|
|
(member ext dirvish-video-exts)
|
|
dv)
|
|
;; Try to find and rename mtn output to MD5 format
|
|
(let* ((width (dirvish-media--img-size (dv-preview-window dv)))
|
|
(cache (dirvish--img-thumb-name video-path width ".jpg"))
|
|
(cache-dir (dirvish--get-parent-path cache))
|
|
(mtn-file (my/dirvish-find-mtn-output video-path cache-dir ext)))
|
|
(when (and mtn-file (file-exists-p mtn-file) (not (file-exists-p cache)))
|
|
(rename-file mtn-file cache)))))
|
|
;; Call original function
|
|
(funcall orig-fun proc exit-code))
|
|
|
|
;; Apply advice
|
|
(advice-add 'dirvish-media--cache-sentinel :around #'my/dirvish-media--cache-sentinel-advice))
|
|
|
|
(provide 'init-dired)
|
|
|
|
;;; init-dired.el ends here
|