summaryrefslogtreecommitdiff
path: root/.config/emacs
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2024-10-23 22:30:08 -0400
committerbd <bdunahu@operationnull.com>2024-10-23 22:30:08 -0400
commit613bb0b65c63340ca92fcb1bad16c902db412ae5 (patch)
treebee53817a09330c6540d33a5f9b40b89fe62a1c7 /.config/emacs
parent4df0aba0364f6a234870f0bf5e086b98609689a8 (diff)
find-file opens media in mpv
Diffstat (limited to '.config/emacs')
-rw-r--r--.config/emacs/modules/bd--files.el34
1 files changed, 26 insertions, 8 deletions
diff --git a/.config/emacs/modules/bd--files.el b/.config/emacs/modules/bd--files.el
index 4765510..712b2c8 100644
--- a/.config/emacs/modules/bd--files.el
+++ b/.config/emacs/modules/bd--files.el
@@ -3,6 +3,10 @@
;;; Code:
+(defun bd/file-has-extension? (file lst)
+ "Returns t if file has an extension in LST, nil otherwise."
+ (string-match (regexp-opt lst) (or (file-name-extension file) "")))
+
;;;; dired
(require 'dired)
(keymap-global-set "C-c d" 'dired-jump)
@@ -19,27 +23,41 @@
dired-dwim-target t
dired-guess-shell-alist-user
- `((,(regexp-opt '(".mkv" ".mov" ".mp4" ".webm" ".m4v" ".wav" ".mp3" ".opus" ".ogv" ".flac")) "mpv &")
- (,(regexp-opt '(".jpeg" ".jpg" ".png")) "feh &")
+ `((,(regexp-opt '(".jpeg" ".jpg" ".png")) "nsxiv &")
(,(regexp-opt '(".pdf")) "pdftotext -nopgbrk -enc UTF-8 -eol unix -layout")
(,(regexp-opt '(".html")) "icecat &")))
;; pdf
-(defun bd/zathura (file &rest args)
- "Launch zathura ignoring args."
+(defun bd/zathura (file)
+ "Open FILE with zathura"
(interactive)
- (ignore args)
- (start-process "zathura" nil "zathura" file))
+ (start-process (concat "zathura (" (file-name-base file) ")") nil "zathura" file))
(defun bd/pdf-find-file-wrapper (f &rest args)
"Wrapper around F (find-file), passing ARGS."
- (if (string-match "\\(?:epub\\|pdf\\)" (or (file-name-extension (car args)) ""))
+ (if (bd/file-has-extension? (car args) '("epub" "pdf"))
(progn
(bd/zathura (car args))
- (recentf-add-file (car args)))
+ (recentf-add-file (car args))
+ nil)
(apply f args)))
(advice-add 'find-file :around #'bd/pdf-find-file-wrapper)
+;; video
+(defun bd/mpv (file)
+ "Open FILE with mpv"
+ (start-process (concat "mpv (" (file-name-base file) ")") nil "mpv" "--force-window=yes" 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)))
+(advice-add 'find-file :around 'bd/video-find-file-wrapper)
+
;;;; transmission
(use-package transmission
:bind