Function: custom-save-all

custom-save-all is an autoloaded and byte-compiled function defined in cus-edit.el.gz.

Signature

(custom-save-all)

Documentation

Save all customizations in custom-file(var)/custom-file(fun).

Source Code

;; Defined in /usr/src/emacs/lisp/cus-edit.el.gz
;;;###autoload
(defun custom-save-all ()
  "Save all customizations in `custom-file'."
  (when (and (null custom-file) init-file-had-error)
    (error "Cannot save customizations; init file was not fully loaded"))
  (let* ((filename (custom-file))
	 (recentf-exclude
	  (if recentf-mode
	      (cons (concat "\\`"
			    (regexp-quote
			     (recentf-expand-file-name (custom-file)))
			    "\\'")
		    recentf-exclude)))
	 (old-buffer (find-buffer-visiting filename))
	 old-buffer-name)

    (with-current-buffer (let ((find-file-visit-truename t))
			   (or old-buffer
                               (let ((delay-mode-hooks t))
                                 (find-file-noselect filename))))
      ;; We'll save using file-precious-flag, so avoid destroying
      ;; symlinks.  (If we're not already visiting the buffer, this is
      ;; handled by find-file-visit-truename, above.)
      (when old-buffer
	(setq old-buffer-name (buffer-file-name))
	(set-visited-file-name (file-chase-links filename)))

      (unless (eq major-mode 'emacs-lisp-mode)
        (delay-mode-hooks (emacs-lisp-mode)))
      (let ((inhibit-read-only t)
	    (print-length nil)
	    (print-level nil)
            ;; We might be saving byte-code with embedded NULs, which
            ;; can cause problems when read back, so print them
            ;; readably.  (Bug#52554)
            (print-escape-control-characters t))
        ;; Insert lexical cookie, but only if the buffer is empty.
        (save-restriction
          (widen)
          (atomic-change-group
            (when (eq (point-min) (point-max))
              (save-excursion
                (goto-char (point-min))
                (insert ";;; -*- lexical-binding: t -*-\n")))
	    (custom-save-variables)
	    (custom-save-faces)
            (custom-save-icons))))
      (let ((file-precious-flag t))
	(save-buffer))
      (if old-buffer
	  (progn
	    (set-visited-file-name old-buffer-name)
	    (set-buffer-modified-p nil))
	(kill-buffer (current-buffer))))))