emacs/lisp/+cus-edit.el

81 lines
2.9 KiB
EmacsLisp
Raw Normal View History

2021-12-26 19:02:43 +00:00
;;; +cus-edit.el -*- lexical-binding: t; -*-
;;; Commentary:
;; The naming convention for this library, called "cus-edit.el" on the
;; filesystem, is all over the damn place. Whatever.
;;; Code:
(require 'cl-lib)
(require 'seq)
(defgroup +customize nil
"Extra customize customizations."
:prefix "+customize-"
:group 'customize)
(defcustom +cus-edit-imenu-generic-expression ; thanks u/oantolin!
`(("Faces" ,(rx (seq bol
(or "Show" "Hide") " "
(group (zero-or-more nonl))
" face: [sample]"))
1)
("Variables" ,(rx (seq bol
(or "Show Value" "Hide") " "
(group (zero-or-more
(not (any "\n:"))))))
1))
"Show faces and variables in `imenu' in a `customize' buffer."
:type 'sexp ; This is .. over-simplified.
)
(defcustom +custom-variable-allowlist nil
"Variables to allow changing while loading the Custom file.")
2022-06-09 14:16:50 +00:00
(defcustom +custom-after-load-hook nil
"Functions to run after loading the custom file.")
2021-12-26 19:02:43 +00:00
(defun +custom-load-ignoring-most-customizations (&optional
2022-01-03 05:32:06 +00:00
error
2021-12-26 19:02:43 +00:00
nomessage
nosuffix
must-suffix)
"Load `custom-file', ignoring most customizations.
Ignore all faces, and only load variables in
`+customize-variable-allowlist'. All the optional
2022-01-03 05:32:06 +00:00
variables---ERROR, NOMESSAGE, NOSUFFIX, MUST-SUFFIX---are
passed on to `load'.
NOTE: ERROR is the opposite of its value in `load' -- meaning
that this function by default does /not/ error, but will if you
pass t to it."
2021-12-26 19:02:43 +00:00
(cl-letf (((symbol-function 'custom-set-faces) 'ignore)
((symbol-function 'custom-set-variables)
(lambda (&rest args)
2022-06-08 22:59:53 +00:00
(apply #'custom-theme-set-variables 'user
2021-12-26 19:02:43 +00:00
(seq-filter (lambda (el)
(memq (car el)
2021-12-27 04:50:00 +00:00
+custom-variable-allowlist))
2021-12-26 19:02:43 +00:00
args)))))
2022-06-09 14:16:50 +00:00
(load custom-file (not error) nomessage nosuffix must-suffix))
(run-hooks '+custom-after-load-hook))
2021-12-26 19:02:43 +00:00
(defun +cus-edit-expand-widgets (&rest _)
"Expand descriptions in `Custom-mode' buffers."
(interactive)
;; "More/Hide" widgets (thanks alphapapa!)
(widget-map-buttons (lambda (widget _)
(pcase (widget-get widget :off)
("More" (widget-apply-action widget)))
nil))
;; "Show Value" widgets (the little triangles)
(widget-map-buttons (lambda (widget _)
(pcase (widget-get widget :off)
("Show Value"
(widget-apply-action widget)))
nil)))
(provide '+cus-edit)
;;; +cus-edit.el ends here