diff options
author | bd <bdunahu@operationnull.com> | 2024-10-23 23:05:50 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2024-10-23 23:05:50 -0400 |
commit | 0a8bb339c6b698b8d833feaba9485454be9b6fc9 (patch) | |
tree | d4939a5fccbd9d13935576848f06d01ac48c1f67 /.config | |
parent | 2fdb56a981ac4779e3fa26c8e4996b61c5d6ec63 (diff) |
use a macro to simplify creating find-file wrappers
Diffstat (limited to '.config')
-rw-r--r-- | .config/emacs/modules/bd--files.el | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/.config/emacs/modules/bd--files.el b/.config/emacs/modules/bd--files.el index bef4f07..b55dd4a 100644 --- a/.config/emacs/modules/bd--files.el +++ b/.config/emacs/modules/bd--files.el @@ -3,10 +3,20 @@ ;;; Code: -(defun bd/file-has-extension? (file lst) +(defun bd/file-has-extension? (file types) "Returns t if file has an extension in LST, nil otherwise." (string-match (regexp-opt lst) (or (file-name-extension file) ""))) +(defmacro bd/defun-find-file-wrapper (name types open-f) + `(defun ,name (f &rest args) + "Wrapper around F (find-file), passing ARGS." + (if (bd/file-has-extension? (car args) ,types) + (progn + (,(eval open-f) (car args)) + (recentf-add-file (car args)) + nil) + (apply f args)))) + ;;;; dired (require 'dired) (keymap-global-set "C-c d" 'dired-jump) @@ -33,14 +43,7 @@ (interactive) (start-process (concat "zathura (" (file-name-base file) ")") nil "zathura" (expand-file-name file))) -(defun bd/pdf-find-file-wrapper (f &rest args) - "Wrapper around F (find-file), passing ARGS." - (if (bd/file-has-extension? (car args) '("epub" "pdf")) - (progn - (bd/zathura (car args)) - (recentf-add-file (car args)) - nil) - (apply f args))) +(bd/defun-find-file-wrapper bd/pdf-find-file-wrapper '("epub" "pdf") #'bd/zathura) (advice-add 'find-file :around #'bd/pdf-find-file-wrapper) ;; video @@ -48,14 +51,10 @@ "Open FILE with mpv" (start-process (concat "mpv (" (file-name-base file) ")") nil "mpv" "--force-window=yes" (expand-file-name file))) -(defun bd/video-find-file-wrapper (f &rest args) - "Wrapper around F (find-file), passing ARGS." - (if (bd/file-has-extension? (car args) '("mkv" "mov" "mp4" "webm" "m4v" "wav" "mp3" "opus" "ogv" "flac")) - (progn - (bd/mpv (car args)) - (recentf-add-file (car args)) - nil) - (apply f args))) + +(bd/defun-find-file-wrapper bd/video-find-file-wrapper + '("mkv" "mov" "mp4" "webm" "m4v" "wav" "mp3" "opus" "ogv" "flac") + #'bd/mpv) (advice-add 'find-file :around 'bd/video-find-file-wrapper) ;;;; transmission |