diff --git a/init.el b/init.el index b95ba8c..5c12514 100644 --- a/init.el +++ b/init.el @@ -488,10 +488,8 @@ directory. Otherwise, run `find-file' on that file." (advice-add #'map-y-or-n-p :around #'my/-kkp-fix-map-y-or-n-p)) -;; mozc -(require 'mozc nil t) -(setq default-input-method "japanese-mozc") -(defun my/-cmdline-for-pid (pid) +;; some eww (status bar) stuff +(defun my/cmdline-for-pid (pid) "Return the command line arguments passed to PID. PID can be a string or a number." (butlast (string-split @@ -501,7 +499,7 @@ PID can be a string or a number." (buffer-substring-no-properties (point-min) (point-max))) "\0"))) -(defun my/-current-eww-config-dir () +(defun my/eww-current-config-dir () "Return the configuration directory for a currently running eww process." ;; This probably only works on Linux (catch 'found @@ -515,14 +513,30 @@ PID can be a string or a number." (cl-maplist (lambda (tail) (when (equal (car tail) "-c") (throw 'found (cl-second tail)))) - (my/-cmdline-for-pid subdir))))))))) -(defun my/-set-eww-fcitx-state (enabled) - "Set the fcitx state for eww to ENABLED." - (let ((args (list "update" (format "fcitx5-state=%s" (if enabled 2 1)))) - (cfg-dir (my/-current-eww-config-dir))) + (my/cmdline-for-pid subdir))))))))) +(defun my/eww-update-variables (&rest vars) + "Update the key value pairs in VARS. +Each key should be either a symbol or a string. Each value will have its +printed representation (via `princ') set as the new value for the key." + (let* ((mappings (map-apply + #'(lambda (key val) + (when (symbolp key) (setq key (symbol-name key))) + (when (cl-find ?= key) + (error "Key cannot contain an equal sign (=): %s" key)) + (format "%s=%s" key val)) + vars)) + (args (cons "update" mappings)) + (cfg-dir (my/eww-current-config-dir))) (when cfg-dir (setq args (nconc (list "-c" cfg-dir) args))) (apply 'call-process "eww" nil 0 nil args))) + +;; mozc +(require 'mozc nil t) +(setq default-input-method "japanese-mozc") +(defun my/-set-eww-fcitx-state (enabled) + "Set the fcitx state for eww to ENABLED." + (my/eww-update-variables "fcitx5-state" (if enabled 2 1))) (defun my/global-toggle-mozc (&optional no-eww) "Toggle mozc for all buffers. With NO-EWW, don't update eww's state."