summaryrefslogtreecommitdiff
path: root/modules/system-utils.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-06-28 12:40:39 -0500
committerCraig Jennings <c@cjennings.net>2025-06-28 12:40:39 -0500
commit8ba784883c049d5a7b9764612874b75ee7779220 (patch)
tree444220788017396401037696c9fa8d6713f7be31 /modules/system-utils.el
parentf6aef4673ee17af2a66f155253518a9d0f27f9ae (diff)
downloaddotemacs-8ba784883c049d5a7b9764612874b75ee7779220.tar.gz
dotemacs-8ba784883c049d5a7b9764612874b75ee7779220.zip
Add code in system-utils.el to open specific extensions via xdg-open
Diffstat (limited to 'modules/system-utils.el')
-rw-r--r--modules/system-utils.el56
1 files changed, 50 insertions, 6 deletions
diff --git a/modules/system-utils.el b/modules/system-utils.el
index 605a2a1ca..33ad679a8 100644
--- a/modules/system-utils.el
+++ b/modules/system-utils.el
@@ -1,17 +1,61 @@
;;; system-utils --- System-Wide Utilities -*- lexical-binding: t; -*-
+;; -------------------------------- Use Xdg-Open -------------------------------
;; author Craig Jennings <c@cjennings.net>
-
;;; Commentary:
;;; Code:
;; ------------------------------- Disable Mouse -------------------------------
-;; prevents accidental mouse moves resulting in modifying unwanted text
+;; prevents accidental mouse moves resulting in accidentally modifying text
(use-package disable-mouse
:config
(global-disable-mouse-mode))
+;; ---------------------------------- Xdg-Open ---------------------------------
+;; open specific file extensions with the system's default mime-type handler
+
+(defun cj/xdg-open (&optional filename)
+ (interactive)
+ (let ((command (cond ((eq system-type 'gnu/linux) "xdg-open")
+ ((eq system-type 'darwin) "open")
+ ((eq system-type 'windows-nt) "start")
+ (t ""))))
+ (with-current-buffer (get-buffer-create "xdg-open.log")
+ (goto-char (point-max))
+ (insert (format "Running command %s\n" command))
+ (let ((exit-code (call-process command nil t t (expand-file-name
+ (or filename (dired-file-name-at-point))))))
+ (insert (format "Exit code: %s\n" exit-code))))))
+
+(defun cj/find-file-auto (orig-fun &rest args)
+ (let ((filename (car args)))
+ (if (cl-find-if
+ (lambda (regexp) (string-match regexp filename))
+ '("\\.avi\\'"
+ "\\.mp4\\'"
+ "\\.divx\\'"
+ "\\.flv\\'"
+ "\\.mkv\\'"
+ "\\.mpeg\\'"
+ "\\.mov\\'"
+ "\\.wav\\'"
+ "\\.webm\\'"
+ "\\.mp3\\'"
+ "\\.opus\\'"
+ "\\.ogg\\'"
+ "\\.flac\\'"
+ "\\.docx?\\'"
+ "\\.pptx?\\'"
+ "\\.xlsx?\\'"
+ ))
+ (progn
+ (cj/xdg-open filename))
+ (progn
+ (apply orig-fun args)))))
+
+(advice-add 'find-file :around 'cj/find-file-auto)
+
;; ---------------------------------- Ibuffer ----------------------------------
(global-set-key [remap list-buffers] 'ibuffer) ;; use ibuffer, not list-buffers
@@ -328,10 +372,10 @@ with a prefix argument."
:defer .5
:bind ("M-t" . tmr-prefix-map)
:config
- (setq tmr-sound-file
- "/usr/share/sounds/freedesktop/stereo/alarm-clock-elapsed.oga")
- (setq tmr-notification-urgency 'normal)
- (setq tmr-descriptions-list 'tmr-description-history))
+ (setq tmr-sound-file
+ "/usr/share/sounds/freedesktop/stereo/alarm-clock-elapsed.oga")
+ (setq tmr-notification-urgency 'normal)
+ (setq tmr-descriptions-list 'tmr-description-history))
;; ------------------------------- Who Called Me? ------------------------------
;; convenience function to display which function called a message