1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-06 11:55:48 +00:00

Add new command to toggle hiding all widgets in a Customize buffer

* lisp/cus-edit.el (custom-commands): Add menu entry.
(custom-toggle-hide-all-variables): New command (bug#15748).
This commit is contained in:
Lars Ingebrigtsen 2022-05-10 17:46:55 +02:00
parent 2f3cf7ffe3
commit fd49e3c62b
2 changed files with 36 additions and 1 deletions

View File

@ -780,6 +780,13 @@ so automatically.
* Changes in Specialized Modes and Packages in Emacs 29.1
** Customize
---
*** New command 'custom-toggle-hide-all-variables'.
This is bound to 'H' and toggles whether to hide or show the widget
contents.
** ispell
---

View File

@ -441,6 +441,7 @@ Use group `text' for this instead. This group is deprecated."
(define-key map "u" 'Custom-goto-parent)
(define-key map "n" 'widget-forward)
(define-key map "p" 'widget-backward)
(define-key map "H" 'custom-toggle-hide-all-variables)
map)
"Keymap for `Custom-mode'.")
@ -745,6 +746,9 @@ groups after non-groups, if nil do not order groups at all."
(or custom-file user-init-file)
"Un-customize settings in this and future sessions." "delete" "Uncustomize"
(modified set changed rogue saved))
(" Toggle hiding all values " custom-toggle-hide-all-variables
t "Toggle hiding all values."
"hide" "Hide" t)
(" Help for Customize " Custom-help t "Get help for using Customize."
"help" "Help" t)
(" Exit " Custom-buffer-done t "Exit Customize." "exit" "Exit" t))
@ -2834,6 +2838,29 @@ try matching its doc string against `custom-guess-doc-alist'."
(custom-add-parent-links widget))
(custom-add-see-also widget)))))
(defvar custom--hidden-state)
(defun custom-toggle-hide-all-variables ()
"Toggle whether to show contents of the widgets in the current buffer."
(interactive)
(save-excursion
(goto-char (point-min))
;; Surely there's a better way to find all the "top level" widgets
;; in a buffer, but I couldn't find it.
(while (not (eobp))
(when-let* ((widget (widget-at (point)))
(parent (widget-get widget :parent))
(state (widget-get parent :custom-state)))
(when (eq state custom--hidden-state)
(custom-toggle-hide-variable widget)))
(forward-line 1)))
(setq custom--hidden-state (if (eq custom--hidden-state 'hidden)
'standard
'hidden))
(if (eq custom--hidden-state 'hidden)
(message "All variables hidden")
(message "All variables shown")))
(defun custom-toggle-hide-variable (visibility-widget &rest _ignore)
"Toggle the visibility of a `custom-variable' parent widget.
By default, this signals an error if the parent has unsaved
@ -5230,7 +5257,8 @@ if that value is non-nil."
:label (nth 5 arg)))
custom-commands)
(setq custom-tool-bar-map map))))
(setq-local custom--invocation-options nil)
(setq-local custom--invocation-options nil
custom--hidden-state 'hidden)
(setq-local revert-buffer-function #'custom--revert-buffer)
(make-local-variable 'custom-options)
(make-local-variable 'custom-local-buffer)