Function: custom-buffer-create-internal

custom-buffer-create-internal is a byte-compiled function defined in cus-edit.el.gz.

Signature

(custom-buffer-create-internal OPTIONS &optional DESCRIPTION)

Source Code

;; Defined in /usr/src/emacs/lisp/cus-edit.el.gz
(defun custom-buffer-create-internal (options &optional _description)
  (Custom-mode)
  (setq custom--invocation-options options)
  (let ((init-file (or custom-file user-init-file)))
    ;; Insert verbose help at the top of the custom buffer.
    (when custom-buffer-verbose-help
      (unless init-file
	(widget-insert
         (format-message
          "Custom settings cannot be saved; maybe you started Emacs with `-q'.\n")))
      (widget-insert "For help using this buffer, see ")
      (widget-create 'custom-manual
		     :tag "Easy Customization"
		     "(emacs)Easy Customization")
      (widget-insert " in the ")
      (widget-create 'custom-manual
		     :tag "Emacs manual"
		     :help-echo "Read the Emacs manual."
		     "(emacs)Top")
      (widget-insert "."))
    (widget-insert "\n")

    ;; Insert the search field.
    (when custom-search-field
      (widget-insert "\n")
      (let* ((echo "Search for custom items.
You can enter one or more words separated by spaces,
or a regular expression.")
	     (search-widget
	      (widget-create
	       'editable-field
	       :size 40 :help-echo echo
	       :action (lambda (widget &optional _event)
                         (let ((value (widget-value widget)))
                           (if (string= value "")
                               (message "Empty search field")
                             (customize-apropos (split-string value))))))))
	(widget-insert " ")
	(widget-create-child-and-convert
	 search-widget 'push-button
	 :tag " Search "
	 :help-echo echo :action
	 (lambda (widget &optional _event)
           (widget-apply (widget-get widget :parent) :action)))
	(widget-insert "\n")))

    ;; The custom command buttons are also in the toolbar, so for a
    ;; time they were not inserted in the buffer if the toolbar was in use.
    ;; But it can be a little confusing for the buffer layout to
    ;; change according to whether or nor the toolbar is on, not to
    ;; mention that a custom buffer can in theory be created in a
    ;; frame with a toolbar, then later viewed in one without.
    ;; So now the buttons are always inserted in the buffer.  (Bug#1326)
    (if custom-buffer-verbose-help
	(widget-insert "
Operate on all settings in this buffer:\n"))
    (let ((button (lambda (tag action visible help _icon _label active)
		    (widget-insert " ")
                    (if (eval visible)
                        (push (widget-create
                               'push-button :tag tag
                               :help-echo help :action action
                               :notify
                               (lambda (widget)
                                 (when (listp active)
                                   (if (seq-some
                                        (lambda (widget)
                                          (memq
                                           (widget-get widget :custom-state)
                                           active))
                                        custom-options)
                                       (widget-apply widget :activate)
                                     (widget-apply widget :deactivate)))))
                              custom-command-buttons))))
	  (commands custom-commands))
      (if custom-reset-button-menu
	  (progn
	    (widget-create 'push-button
			   :tag " Revert... "
			   :help-echo "Show a menu with reset operations."
			   :mouse-down-action 'ignore
			   :action 'custom-reset)
	    (apply button (pop commands))  ; Apply
	    (apply button (pop commands))) ; Apply and Save
	(apply button (pop commands))   ; Apply
	(apply button (pop commands))   ; Apply and Save
	(widget-insert "\n")
	(apply button (pop commands))   ; Undo
	(apply button (pop commands))   ; Reset
	(apply button (pop commands))   ; Erase
	(widget-insert "  ")
	(pop commands)                  ; Help (omitted)
	(apply button (pop commands)))) ; Exit
    (widget-insert "\n\n"))

  ;; Now populate the custom buffer.
  (message "Creating customization items...")
  (buffer-disable-undo)
  (setq custom-options
	(if (= (length options) 1)
	    (mapcar (lambda (entry)
		      (widget-create (nth 1 entry)
				     :documentation-shown t
				     :custom-state 'unknown
				     :tag (custom-unlispify-tag-name
					   (nth 0 entry))
				     :value (nth 0 entry)))
		    options)
	  (let ((count 0)
		(length (length options)))
	    (mapcar (lambda (entry)
		      (prog2
			  (message "Creating customization items ...%2d%%"
				   (floor (* 100.0 count) length))
			  (widget-create (nth 1 entry)
					 :tag (custom-unlispify-tag-name
					       (nth 0 entry))
					 :value (nth 0 entry))
			(setq count (1+ count))
			(unless (eq (preceding-char) ?\n)
			  (widget-insert "\n"))
			(widget-insert "\n")))
		    options))))
  (unless (eq (preceding-char) ?\n)
    (widget-insert "\n"))
  (message "Creating customization items ...done")
  (unless (eq custom-buffer-style 'tree)
    (mapc 'custom-magic-reset custom-options))
  (message "Creating customization setup...")
  (widget-setup)
  (buffer-enable-undo)
  (goto-char (point-min))
  (message "Creating customization setup...done"))