Clean up eww code

This commit is contained in:
Alexander Rosenberg 2025-02-05 20:54:55 -08:00
parent 9611655fa0
commit 2af97af4dd
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730

34
init.el
View File

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