branch: externals/sxhkdrc-mode
commit a9f82b55714354351dbe629f8c949d427dacd81d
Author: Jonathan Neidel <jnei...@jneidel.com>
Commit: Jonathan Neidel <jnei...@jneidel.com>

    Add daemon restart
---
 sxhkdrc-mode.el | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/sxhkdrc-mode.el b/sxhkdrc-mode.el
index d47182dfd1..5d5fe1bf84 100644
--- a/sxhkdrc-mode.el
+++ b/sxhkdrc-mode.el
@@ -39,6 +39,8 @@
 
 ;;; Code:
 
+(eval-when-compile (require 'subr-x))
+
 (defgroup sxhkdrc nil
   "Major mode for editing sxhkdrc files.
 SXHKD is the Simple X Hotkey Daemon which is commonly used in
@@ -152,6 +154,44 @@ key chord chain (demarcated by a colon or semicolon)."
           (indent-to indent))
       'no-indent)))
 
+(defun sxhkdrc-mode-restart-process ()
+  "Restart the sxhkd process."
+  (when-let* ((pid (shell-command-to-string "pidof sxhkd")))
+    (call-process "kill" nil 0 nil "-USR1" (string-trim pid))
+    t))
+
+(declare-function notifications-notify "notifications" (&rest params))
+
+(defun sxhkdrc-mode-restart-notify ()
+  "Notify that the sxhkd process has been restarted.
+Read Info node `(elisp) Desktop Notifications' for details."
+  (when (featurep 'dbusbind)
+    (unless (fboundp 'notifications-notify)
+      (require 'notifications))
+    (notifications-notify
+     :title "sxhkdrc-mode"
+     :body "Restarted the SXHKD process"
+     :app-name "Emacs"
+     :app-icon 'emacs
+     :urgency 'normal
+     :sound-file nil)))
+
+(defun sxhkdrc-mode-restart ()
+  "Restart the sxhkd process."
+  (interactive)
+  (when (sxhkdrc-mode-restart-process)
+    (sxhkdrc-mode-restart-notify)))
+
+(define-minor-mode sxhkdrc-mode-auto-restart
+  "Automatically restart sxhkd after saving its file.
+To set this minor mode up when opening a file that uses the
+`sxhkdrc-mode', use the hook `sxhkdrc-mode-hook'."
+  :global nil
+  :init-value nil
+  (if sxhkdrc-mode-auto-restart
+      (add-hook 'after-save-hook #'sxhkdrc-mode-restart nil :local-only)
+    (remove-hook 'after-save-hook #'sxhkdrc-mode-restart :local-only)))
+
 (defvar sxhkdrc-mode-map (make-sparse-keymap)
   "Local keymap for `sxhkdrc-mode' buffers.")
 

Reply via email to