diff options
| author | Protesilaos Stavrou <info@protesilaos.com> | 2025-08-10 08:27:00 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-10 08:27:00 +0300 |
| commit | 26db393a4e0bc6e9bc3c6a5bde0cd5dc721e00d1 (patch) | |
| tree | 66ce0336acc83eff2e96304edadbdc6087c92aa2 | |
| parent | 82816999f82a5ed5bc7c26d8ff95dbb4833dc011 (diff) | |
| parent | f4254c0ba84c80dffc35ef1240bb2faf899cc768 (diff) | |
Merge pull request #2 from jneidel/main
Add deamon restart and document usage
| -rw-r--r-- | README.md | 19 | ||||
| -rw-r--r-- | sxhkdrc-mode.el | 40 |
2 files changed, 59 insertions, 0 deletions
@@ -12,3 +12,22 @@ technicalities, read the man page `sxhkd(1)`. + GitLab: <https://gitlab.com/protesilaos/sxhkdrc-mode> + Backronym: Such Xenotropic Hot Keys Demonstrate Robustness and Configurability ... mode. + +## Usage + +Install the mode and use with any `sxhkdrc` file: + +```elisp +(use-package sxhkdrc-mode + :ensure t + :mode "sxhkdrc.*") +``` + +Restart the sxhkd daemon: +```elisp +; once +(sxhkdrc-mode-restart) + +; automatically on file write +(sxhkdrc-mode-auto-restart) +``` diff --git a/sxhkdrc-mode.el b/sxhkdrc-mode.el index d47182d..5d5fe1b 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.") |
