From a4b634cf9cc82cb1c0f85281471b5f9d120f814e Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 26 Dec 2021 13:02:43 -0600 Subject: Customize 'customize' --- init.el | 18 ++++++++++++++ lisp/+cus-edit.el | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 lisp/+cus-edit.el diff --git a/init.el b/init.el index 45133df..835af08 100644 --- a/init.el +++ b/init.el @@ -136,6 +136,24 @@ calendar-latitude _location-latitude calendar-longitude _location-longitude)) +(setup cus-edit + ;; I don't use Custom to actually /make/ any customizations, but it's handy to + ;; (A) see what options are available and (B) persist some changes across + ;; restarts, for example, `safe-local-variables'. + (:also-load +cus-edit) + (:option custom-file (private/ "custom.el") + custom-magic-show nil + custom-magic-show-button t + custom-raised-buttons nil + custom-unlispify-tag-names nil + custom-variable-default-form 'lisp + +custom-variable-allowlist '(safe-local-variable-values)) + (when (file-exists-p custom-file) + (+custom-load-ignoring-most-customizations t)) + (advice-add 'custom-buffer-create-internal :after '+cus-edit-expand-widgets) + (:with-mode Custom-mode + (:local-set imenu-generic-expression +cus-edit-imenu-generic-expression))) + (setup dired (:also-load dired-x) (:also-straight dired-subtree diff --git a/lisp/+cus-edit.el b/lisp/+cus-edit.el new file mode 100644 index 0000000..2f9769d --- /dev/null +++ b/lisp/+cus-edit.el @@ -0,0 +1,72 @@ +;;; +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.") + +(defun +custom-load-ignoring-most-customizations (&optional + noerror + nomessage + nosuffix + must-suffix) + "Load `custom-file', ignoring most customizations. +Ignore all faces, and only load variables in +`+customize-variable-allowlist'. All the optional +variables---NOERROR, NOMESSAGE, NOSUFFIX, MUST-SUFFIX---are +passed on to `load'." + (cl-letf (((symbol-function 'custom-set-faces) 'ignore) + ((symbol-function 'custom-set-variables) + (lambda (&rest args) + (apply 'custom-theme-set-variables 'user + (seq-filter (lambda (el) + (memq (car el) + +customize-variable-allowlist)) + args))))) + (load custom-file noerror nomessage nosuffix must-suffix))) + +(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 -- cgit 1.4.1-21-gabe81