Function: custom--sort-vars

custom--sort-vars is a byte-compiled function defined in custom.el.gz.

Signature

(custom--sort-vars VARS)

Documentation

Sort VARS based on custom dependencies.

VARS is a list whose elements have the same form as the ARGS arguments to custom-theme-set-variables. Return the sorted list, in which A occurs before B if B was defined with a
:set-after keyword specifying A (see defcustom).

Source Code

;; Defined in /usr/src/emacs/lisp/custom.el.gz
(defun custom--sort-vars (vars)
  "Sort VARS based on custom dependencies.
VARS is a list whose elements have the same form as the ARGS
arguments to `custom-theme-set-variables'.  Return the sorted
list, in which A occurs before B if B was defined with a
`:set-after' keyword specifying A (see `defcustom')."
  (let ((custom--sort-vars-table (make-hash-table))
	(dependants (make-hash-table))
	(custom--sort-vars-result nil)
	last)
    ;; Construct a pair of tables keyed with the symbols of VARS.
    (dolist (var vars)
      (puthash (car var) (cons t var) custom--sort-vars-table)
      (puthash (car var) var dependants))
    ;; From the second table, remove symbols that are depended-on.
    (dolist (var vars)
      (dolist (dep (get (car var) 'custom-dependencies))
	(remhash dep dependants)))
    ;; If a variable is "stand-alone", put it last if it's a minor
    ;; mode or has a :require flag.  This is not really necessary, but
    ;; putting minor modes last helps ensure that the mode function
    ;; sees other customized values rather than default values.
    (maphash (lambda (sym var)
	       (when (and (null (get sym 'custom-dependencies))
			  (or (nth 3 var)
			      (eq (get sym 'custom-set)
				  'custom-set-minor-mode)))
		 (remhash sym dependants)
		 (push var last)))
	     dependants)
    ;; The remaining symbols depend on others but are not
    ;; depended-upon.  Do a depth-first topological sort.
    (maphash #'custom--sort-vars-1 dependants)
    (nreverse (append last custom--sort-vars-result))))