]> code.delx.au - gnu-emacs/blobdiff - lisp/cus-edit.el
Make `buffer-offer-save' permanently local
[gnu-emacs] / lisp / cus-edit.el
index f14c055d7a8c39a9c4fb79b670fc6b587c871391..d443d6c160c041589c51ae5b5b15c0325eb6e693 100644 (file)
@@ -594,7 +594,7 @@ WIDGET is the widget to apply the filter entries of MENU on."
     ("-function\\'" function)
     ("-functions\\'" (repeat function))
     ("-list\\'" (repeat sexp))
-    ("-alist\\'" (repeat (cons sexp sexp))))
+    ("-alist\\'" (alist :key-type sexp :value-type sexp)))
   "Alist of (MATCH TYPE).
 
 MATCH should be a regexp matching the name of a symbol, and TYPE should
@@ -1033,9 +1033,36 @@ If given a prefix (or a COMMENT argument), also prompt for a comment."
         (put variable 'saved-variable-comment comment)))
   (put variable 'customized-value nil)
   (put variable 'customized-variable-comment nil)
-  (custom-save-all)
+  (if (custom-file t)
+      (custom-save-all)
+    (message "Setting `%s' temporarily since \"emacs -q\" would overwrite customizations"
+            variable)
+    (set variable value))
   value)
 
+;; Some parts of Emacs might prompt the user to save customizations,
+;; during startup before customizations are loaded.  This function
+;; handles this corner case by avoiding calling `custom-save-variable'
+;; too early, which could wipe out existing customizations.
+
+;;;###autoload
+(defun customize-push-and-save (list-var elts)
+  "Add ELTS to LIST-VAR and save for future sessions, safely.
+ELTS should be a list.  This function adds each entry to the
+value of LIST-VAR using `add-to-list'.
+
+If Emacs is initialized, call `customize-save-variable' to save
+the resulting list value now.  Otherwise, add an entry to
+`after-init-hook' to save it after initialization."
+  (dolist (entry elts)
+    (add-to-list list-var entry))
+  (if after-init-time
+      (let ((coding-system-for-read nil))
+       (customize-save-variable list-var (eval list-var)))
+    (add-hook 'after-init-hook
+             `(lambda ()
+                (customize-push-and-save ',list-var ',elts)))))
+
 ;;;###autoload
 (defun customize ()
   "Select a customization buffer which you can use to set user options.
@@ -1806,6 +1833,7 @@ item in another window.\n\n"))
 ;; We want simple widgets to be displayed by default, but complex
 ;; widgets to be hidden.
 
+;; This widget type is obsolete as of Emacs 24.1.
 (widget-put (get 'item 'widget-type) :custom-show t)
 (widget-put (get 'editable-field 'widget-type)
            :custom-show (lambda (_widget value)
@@ -2234,6 +2262,7 @@ and `face'."
             (setq widget nil)))))
   (widget-setup))
 
+(make-obsolete 'custom-show "this widget type is no longer supported." "24.1")
 (defun custom-show (widget value)
   "Non-nil if WIDGET should be shown with VALUE by default."
   (let ((show (widget-get widget :custom-show)))
@@ -3830,9 +3859,8 @@ restoring it to the state of a face that has never been customized."
   :sample-face-get 'widget-face-sample-face-get
   :notify 'widget-face-notify
   :match (lambda (_widget value) (facep value))
-  :complete-function (lambda ()
-                      (interactive)
-                      (lisp-complete-symbol 'facep))
+  :completions (apply-partially #'completion-table-with-predicate
+                                obarray #'facep 'strict)
   :prompt-match 'facep
   :prompt-history 'widget-face-prompt-value-history
   :validate (lambda (widget)
@@ -4379,23 +4407,27 @@ Click on \"More\" \(or position point there and press RETURN)
 if only the first line of the docstring is shown."))
   :group 'customize)
 
-(defun custom-file ()
+(defun custom-file (&optional no-error)
   "Return the file name for saving customizations."
-  (file-chase-links
-   (or custom-file
-       (let ((user-init-file user-init-file)
-            (default-init-file
-              (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
-        (when (null user-init-file)
-          (if (or (file-exists-p default-init-file)
-                  (and (eq system-type 'windows-nt)
-                       (file-exists-p "~/_emacs")))
-              ;; Started with -q, i.e. the file containing
-              ;; Custom settings hasn't been read.  Saving
-              ;; settings there would overwrite other settings.
-              (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
-          (setq user-init-file default-init-file))
-        user-init-file))))
+  (let ((file
+        (or custom-file
+            (let ((user-init-file user-init-file)
+                  (default-init-file
+                    (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
+              (when (null user-init-file)
+                (if (or (file-exists-p default-init-file)
+                        (and (eq system-type 'windows-nt)
+                             (file-exists-p "~/_emacs")))
+                    ;; Started with -q, i.e. the file containing
+                    ;; Custom settings hasn't been read.  Saving
+                    ;; settings there would overwrite other settings.
+                    (if no-error
+                        nil
+                      (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
+                  (setq user-init-file default-init-file)))
+              user-init-file))))
+    (and file
+        (file-chase-links file))))
 
 ;; If recentf-mode is non-nil, this is defined.
 (declare-function recentf-expand-file-name "recentf" (name))