changeset 43246:c187056ac630

2002-02-11 Per Abrahamsen <abraham@dina.kvl.dk> * toolbar/tool-bar.el (tool-bar-mode): Removed standard value. * menu-bar.el (menu-bar-mode): Ditto. * cus-edit.el (customize-mark-to-save): Always save variables without a standard value. * menu-bar.el (menu-bar-make-toggle): Made it aware of customize. (menu-bar-options-save): Ditto. (menu-bar-showhide-menu): Ditto. (menu-bar-options-menu): Ditto. (menu-bar-scroll-bar-right, menu-bar-scroll-bar-left, menu-bar-scroll-bar-none): Removed. (menu-bar-showhide-scroll-bar-menu): Use customize aware lambda expressions instead. * cus-edit.el (customize-set-value): Return value. (customize-set-variable): Ditto. (customize-save-variable): Ditto. (customize-set-variable): Load dependencies before setting value. (custom-load-symbol): Autoload it. (customize-mark-as-set): New function.
author Per Abrahamsen <abraham@dina.kvl.dk>
date Mon, 11 Feb 2002 16:47:55 +0000
parents 6a3915789e36
children 4c5a2e2ddf43
files lisp/ChangeLog lisp/cus-edit.el lisp/menu-bar.el lisp/toolbar/tool-bar.el
diffstat 4 files changed, 173 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Mon Feb 11 15:00:13 2002 +0000
+++ b/lisp/ChangeLog	Mon Feb 11 16:47:55 2002 +0000
@@ -1,3 +1,26 @@
+2002-02-11  Per Abrahamsen  <abraham@dina.kvl.dk>
+
+	* toolbar/tool-bar.el (tool-bar-mode): Removed standard value.
+	* menu-bar.el (menu-bar-mode): Ditto.
+	* cus-edit.el (customize-mark-to-save): Always save variables
+	without a standard value.
+
+	* menu-bar.el (menu-bar-make-toggle): Made it aware of customize.
+	(menu-bar-options-save): Ditto.
+	(menu-bar-showhide-menu): Ditto.
+	(menu-bar-options-menu): Ditto.
+	(menu-bar-scroll-bar-right, menu-bar-scroll-bar-left,
+	menu-bar-scroll-bar-none): Removed. 
+	(menu-bar-showhide-scroll-bar-menu): Use customize aware lambda
+	expressions instead.
+
+	* cus-edit.el (customize-set-value): Return value.
+	(customize-set-variable): Ditto.
+	(customize-save-variable): Ditto.
+	(customize-set-variable): Load dependencies before setting value. 
+        (custom-load-symbol): Autoload it.
+	(customize-mark-as-set): New function.
+
 2002-02-11  Eli Zaretskii  <eliz@is.elta.co.il>
 
 	* cus-start.el: Don't warn about "x-*" symbols when building a
--- a/lisp/cus-edit.el	Mon Feb 11 15:00:13 2002 +0000
+++ b/lisp/cus-edit.el	Mon Feb 11 16:47:55 2002 +0000
@@ -748,7 +748,7 @@
 
 ;;;###autoload
 (defun customize-set-value (var val &optional comment)
-  "Set VARIABLE to VALUE.  VALUE is a Lisp object.
+  "Set VARIABLE to VALUE, and return VALUE.  VALUE is a Lisp object.
 
 If VARIABLE has a `variable-interactive' property, that is used as if
 it were the arg to `interactive' (which see) to interactively read the value.
@@ -761,15 +761,16 @@
 				       "Set %s to value: "
 				       current-prefix-arg))
    
-  (set var val)
   (cond ((string= comment "")
  	 (put var 'variable-comment nil))
  	(comment
- 	 (put var 'variable-comment comment))))
+ 	 (put var 'variable-comment comment)))
+  (set var val))
 
 ;;;###autoload
 (defun customize-set-variable (variable value &optional comment)
-  "Set the default for VARIABLE to VALUE.  VALUE is a Lisp object.
+  "Set the default for VARIABLE to VALUE, and return VALUE.
+VALUE is a Lisp object.
 
 If VARIABLE has a `custom-set' property, that is used for setting
 VARIABLE, otherwise `set-default' is used.
@@ -787,6 +788,7 @@
   (interactive (custom-prompt-variable "Set variable: "
 				       "Set customized value for %s to: "
 				       current-prefix-arg))
+  (custom-load-symbol variable)
   (funcall (or (get variable 'custom-set) 'set-default) variable value)
   (put variable 'customized-value (list (custom-quote value)))
   (cond ((string= comment "")
@@ -794,11 +796,14 @@
  	 (put variable 'customized-variable-comment nil))
  	(comment
  	 (put variable 'variable-comment comment)
- 	 (put variable 'customized-variable-comment comment))))
+ 	 (put variable 'customized-variable-comment comment)))
+  value)
 
 ;;;###autoload
 (defun customize-save-variable (var value &optional comment)
   "Set the default for VARIABLE to VALUE, and save it for future sessions.
+Return VALUE.
+
 If VARIABLE has a `custom-set' property, that is used for setting
 VARIABLE, otherwise `set-default' is used.
 
@@ -823,7 +828,8 @@
  	(comment
  	 (put var 'variable-comment comment)
  	 (put var 'saved-variable-comment comment)))
-  (custom-save-all))
+  (custom-save-all)
+  value)
 
 ;;;###autoload
 (defun customize ()
@@ -1815,6 +1821,7 @@
 (defvar custom-load-recursion nil
   "Hack to avoid recursive dependencies.")
 
+;;;###autoload
 (defun custom-load-symbol (symbol)
   "Load all dependencies for SYMBOL."
   (unless custom-load-recursion
@@ -3750,22 +3757,22 @@
   "Mark SYMBOL for later saving.
 
 If the default value of SYMBOL is different from the standard value, 
-set the 'saved-value' property to a list whose car evaluates to the
+set the `saved-value' property to a list whose car evaluates to the
 default value. Otherwise, set it til nil.
 
-To actually save the value, call 'custom-save-all'.
-
-Return non-nil iff the 'saved-value' property actually changed."
+To actually save the value, call `custom-save-all'.
+
+Return non-nil iff the `saved-value' property actually changed."
   (let* ((get (or (get symbol 'custom-get) 'default-value))
 	 (value (funcall get symbol))
 	 (saved (get symbol 'saved-value))
 	 (standard (get symbol 'standard-value))
 	 (comment (get symbol 'customized-variable-comment)))
     ;; Save default value iff different from standard value.
-    (if (and standard 
-	     (not (condition-case nil
-		      (equal value (eval (car standard)))
-		    (error nil))))
+    (if (or (null standard)
+	    (not (equal value (condition-case nil
+				  (eval (car standard))
+				(error nil)))))
 	(put symbol 'saved-value (list (custom-quote value)))
       (put symbol 'saved-value nil))
     ;; Clear customized information (set, but not saved).
@@ -3775,6 +3782,30 @@
       (put symbol 'saved-variable-comment comment))
     (not (equal saved (get symbol 'saved-value)))))
 
+;;;###autoload
+(defun customize-mark-as-set (symbol)
+  "Mark current value of SYMBOL as being set from customize.
+
+If the default value of SYMBOL is different from the saved value if any, 
+or else if it is different from the standard value, set the
+`customized-value' property to a list whose car evaluates to the 
+default value. Otherwise, set it til nil.
+
+Return non-nil iff the `customized-value' property actually changed."
+  (let* ((get (or (get symbol 'custom-get) 'default-value))
+	 (value (funcall get symbol))
+	 (customized (get symbol 'customized-value))
+	 (old (or (get symbol 'saved-value) (get symbol 'standard-value))))
+    ;; Mark default value as set iff different from old value.
+    (if (or (null old)
+	    (not (equal value (condition-case nil 
+				  (eval (car old))
+				(error nil)))))
+	(put symbol 'customized-value (list (custom-quote value)))
+      (put symbol 'customized-value nil))
+    ;; Changed?
+    (not (equal customized (get symbol 'customized-value)))))
+
 ;;; The Customize Menu.
 
 ;;; Menu support
--- a/lisp/menu-bar.el	Mon Feb 11 15:00:13 2002 +0000
+++ b/lisp/menu-bar.el	Mon Feb 11 16:47:55 2002 +0000
@@ -530,12 +530,28 @@
 		(substring help 1) ".")
        (interactive)
        (if ,(if body `(progn . ,body)
-	      `(setq ,variable (not ,variable)))
-  	   (message ,message "enabled")
+	      `(progn 
+		 (custom-load-symbol ',variable)
+		 (let ((set (or (get ',variable 'custom-set) 'set-default))
+		       (get (or (get ',variable 'custom-get) 'default-value)))
+		   (funcall set ',variable (not (funcall get ',variable))))))
+	   (message ,message "enabled")
   	 (message ,message "disabled")))
-     '(menu-item ,doc ,name
+     ;; The function `customize-mark-as-set' must only be called when
+     ;; a variable is set interactively, as the purpose is to mark it
+     ;; as a candidate for "Save Options", and we do not want to save
+     ;; options the user have already set explicitly in his init
+     ;; file.  Unfortunately, he could very likely call the function
+     ;; defined above there.  So we put `customize-mark-as-set' in a
+     ;; lambda expression. 
+     ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
+     '(menu-item ,doc (lambda ()
+			(interactive)
+			(,name)
+			(customize-mark-as-set ',variable))
 		 :help ,help
-                 :button (:toggle . (and (boundp ',variable) ,variable)))))
+                 :button (:toggle . (and (default-boundp ',variable)
+					 (default-value ',variable))))))
 
 ;;; Assemble all the top-level items of the "Options" menu
 (define-key menu-bar-options-menu [customize]
@@ -546,27 +562,27 @@
   "Save current values of Options menu items using Custom."
   (interactive)
   (let ((need-save nil))
-    (dolist (elt '(debug-on-quit debug-on-error auto-compression-mode
+    ;; These are set with `customize-set-variable'.
+    (dolist (elt '(line-number-mode column-number-mode scroll-bar-mode
+		   debug-on-quit debug-on-error menu-bar-mode tool-bar-mode
+		   save-place uniquify-buffer-name-style
 		   case-fold-search truncate-lines show-paren-mode
 		   transient-mark-mode global-font-lock-mode
-		   current-language-environment default-input-method
-		   default-frame-alist display-time-mode
-		   line-number-mode column-number-mode))
+		   display-time-mode auto-compression-mode
+		   ;; Saving `text-mode-hook' is somewhat questionable,
+		   ;; as we might get more than we bargain for, if
+		   ;; other code may has added hooks as well.
+		   ;; Nonetheless, not saving it would like be confuse
+		   ;; more often.
+		   ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
+		   text-mode-hook))
+      (and (get elt 'customized-value)
+	   (customize-mark-to-save elt)
+	   (setq need-save t)))
+    ;; These are set with other functions.
+    (dolist (elt '(current-language-environment default-input-method))
       (when (customize-mark-to-save elt)
 	(setq need-save t)))
-    ;; We only want to save text-mode-hook after adding or removing auto fill.
-    (and (or (memq 'turn-on-auto-fill text-mode-hook) ;Added.
-	     ;; If it is already saved, it is safe to save.
-	     (get 'text-mode-hook 'saved-value)) ;Maybe removed.
-	 (customize-mark-to-save 'text-mode-hook)
-	 (setq need-save t))
-    ;; Avoid loading extra libraries.
-    (and (featurep 'saveplace)
-	 (customize-mark-to-save 'save-place)
-	 (setq need-save t))
-    (and (featurep 'uniquify)
-	 (customize-mark-to-save 'uniquify-buffer-name-style)
-	 (setq need-save t))
     ;; Save if we changed anything.
     (when need-save
       (custom-save-all))))
@@ -603,7 +619,10 @@
     (message "Display-time mode disabled.")))
 
 (define-key menu-bar-showhide-menu [showhide-date-time]
-  '(menu-item "Date and time" showhide-date-time
+  '(menu-item "Date and time" (lambda ()
+				(interactive)
+				(showhide-date-time)
+				(customize-mark-as-set 'display-time-mode))
 	      :help "Display date and time in the mode-line"
 	      :button (:toggle . display-time-mode)))
 
@@ -612,38 +631,35 @@
 
 (defvar menu-bar-showhide-scroll-bar-menu (make-sparse-keymap "Scroll-bar"))
 
-(defun menu-bar-scroll-bar-right ()
-  "Turn on the scroll-bar on the right side."
-  (interactive)
-  (set-scroll-bar-mode 'right))
-
-(defun menu-bar-scroll-bar-left ()
-  "Turn on the scroll-bar on the left side."
-  (interactive)
-  (set-scroll-bar-mode 'left))
-
-(defun menu-bar-scroll-bar-none ()
-  "Turn off the scroll-bar."
-  (interactive)
-  (set-scroll-bar-mode nil))
-
 (define-key menu-bar-showhide-scroll-bar-menu [right]
-  '(menu-item "On the Right" menu-bar-scroll-bar-right
+  '(menu-item "On the Right" 
+	      (lambda ()
+		(interactive)
+		(customize-set-variable 'scroll-bar-mode 'right))
 	      :help "Scroll-bar on the right side"
 	      :visible window-system
-	      :button (:radio . (eq (cdr (assq 'vertical-scroll-bars (frame-parameters))) 'right))))
+	      :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
+					       (frame-parameters))) 'right))))
 
 (define-key menu-bar-showhide-scroll-bar-menu [left]
-  '(menu-item "On the Left" menu-bar-scroll-bar-left
+  '(menu-item "On the Left" 	   
+	      (lambda ()
+		(interactive)
+		(customize-set-variable 'scroll-bar-mode 'left))
 	      :help "Scroll-bar on the left side"
 	      :visible window-system
-	      :button (:radio . (eq (cdr (assq 'vertical-scroll-bars (frame-parameters))) 'left))))
+	      :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
+					       (frame-parameters))) 'left))))
 
 (define-key menu-bar-showhide-scroll-bar-menu [none]
-  '(menu-item "None" menu-bar-scroll-bar-none
+  '(menu-item "None" 
+	      (lambda ()
+		(interactive)
+		(customize-set-variable 'scroll-bar-mode nil))
 	      :help "Turn off scroll-bar"
 	      :visible window-system
-	      :button (:radio . (eq (cdr (assq 'vertical-scroll-bars (frame-parameters))) nil))))
+	      :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
+					       (frame-parameters))) nil))))
 
 (define-key menu-bar-showhide-menu [showhide-scroll-bar]
   (list 'menu-item "Scroll-Bar" menu-bar-showhide-scroll-bar-menu
@@ -659,7 +675,11 @@
     (message "Menu-bar mode disabled.  Use M-x menu-bar-mode to make the menu bar appear.")))
 
 (define-key menu-bar-showhide-menu [showhide-menu-bar]
-  '(menu-item "Menu-bar" showhide-menu-bar
+  '(menu-item "Menu-bar" 
+	      (lambda ()
+		(interactive)
+		(showhide-menu-bar)
+		(customize-mark-as-set 'menu-bar-mode))
 	      :help "Toggle menu-bar on/off"
 	      :button (:toggle . menu-bar-mode)))
 
@@ -671,7 +691,11 @@
     (message "Tool-bar mode disabled.")))
 
 (define-key menu-bar-showhide-menu [showhide-tool-bar]
-  '(menu-item "Tool-bar" showhide-tool-bar
+  '(menu-item "Tool-bar" 
+	      (lambda ()
+		(interactive)
+		(showhide-tool-bar)
+		(customize-mark-as-set 'tool-bar-mode))
 	      :help "Turn tool-bar on/off"
 	      :visible window-system
 	      :button (:toggle . tool-bar-mode)))
@@ -712,18 +736,19 @@
   '("--"))
 (define-key menu-bar-options-menu [toggle-auto-compression]
   '(menu-item "Automatic File De/compression"
-             auto-compression-mode
-	     :help "Transparently decompress compressed files"
-             :button (:toggle . (rassq 'jka-compr-handler
-				       file-name-handler-alist))))
+	      (lambda ()
+		(interactive)
+		(auto-compression-mode)
+		(customize-mark-as-set 'auto-compression-mode))
+	      :help "Transparently decompress compressed files"
+	      :button (:toggle . (rassq 'jka-compr-handler
+					file-name-handler-alist))))
 (define-key menu-bar-options-menu [save-place]
   (menu-bar-make-toggle toggle-save-place-globally save-place
 			"Save Place in Files between Sessions"
 			"Saving place in files %s"
-			"Save Emacs state for next session"
-                        (require 'saveplace)
-			(setq-default save-place
-				      (not (default-value save-place)))))
+			"Save Emacs state for next session"))
+
 (define-key menu-bar-options-menu [uniquify]
   (menu-bar-make-toggle toggle-uniquify-buffer-names uniquify-buffer-name-style
 			"Use Directory Names in Buffer Names"
@@ -733,6 +758,7 @@
 			(setq uniquify-buffer-name-style
 			      (if (not uniquify-buffer-name-style)
 				  'forward))))
+
 (define-key menu-bar-options-menu [edit-options-separator]
   '("--"))
 (define-key menu-bar-options-menu [case-fold-search]
@@ -742,7 +768,13 @@
 			"Ignore letter-case in search"))
 (define-key menu-bar-options-menu [auto-fill-mode]
   '(menu-item "Word Wrap in Text Modes (Auto Fill)"
-              toggle-text-mode-auto-fill
+              (lambda ()
+		(interactive)
+		(toggle-text-mode-auto-fill)
+		;; This is somewhat questionable, as `text-mode-hook'
+		;; might have changed outside customize.  
+		;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
+		(customize-mark-as-set 'text-mode-hook))
 	      :help "Automatically fill text between left and right margins"
               :button (:toggle . (member 'turn-on-auto-fill text-mode-hook))))
 (define-key menu-bar-options-menu [truncate-lines]
@@ -750,7 +782,10 @@
    toggle-truncate-lines truncate-lines
    "Truncate Long Lines in this Buffer" "Long Line Truncation %s"
    "Truncate long lines on the screen"
-   (prog1 (setq truncate-lines (not truncate-lines))
+   ;; FIXME: We should define a :set method for `truncate-lines' to do
+   ;; the `buffer-modified-p' stuff.
+   ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
+   (prog1 (setq-default truncate-lines (not truncate-lines))
      (set-buffer-modified-p (buffer-modified-p)))))
 (define-key menu-bar-options-menu [highlight-separator]
   '("--"))
@@ -758,8 +793,7 @@
   (menu-bar-make-toggle toggle-highlight-paren-mode show-paren-mode
 			"Paren Match Highlighting (Show Paren mode)"
 			"Show Paren mode %s"
-			"Highlight matching/mismatched parentheses at cursor"
-			(show-paren-mode)))
+			"Highlight matching/mismatched parentheses at cursor"))
 (define-key menu-bar-options-menu [transient-mark-mode]
   (menu-bar-make-toggle toggle-transient-mark-mode transient-mark-mode
 			"Active Region Highlighting (Transient Mark mode)"
@@ -769,8 +803,7 @@
   (menu-bar-make-toggle toggle-global-lazy-font-lock-mode global-font-lock-mode
 			"Syntax Highlighting (Global Font Lock mode)"
 			"Global Font Lock mode %s"
-			"Colorize text based on language syntax"
-			(global-font-lock-mode)))
+			"Colorize text based on language syntax"))
 
 
 ;; The "Tools" menu items
@@ -1403,6 +1436,12 @@
   :type 'boolean
   :group 'frames)
 
+;;; `menu-bar-mode' doesn't really have a standard value, as it depend
+;;; on where and how Emacs was started.  By removing the standard
+;;; value, we ensure that customize will always save it.
+;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
+(put 'menu-bar-mode 'standard-value nil)
+
 (defun menu-bar-mode (&optional flag)
   "Toggle display of a menu bar on each frame.
 This command applies to all frames that exist and frames to be
--- a/lisp/toolbar/tool-bar.el	Mon Feb 11 15:00:13 2002 +0000
+++ b/lisp/toolbar/tool-bar.el	Mon Feb 11 16:47:55 2002 +0000
@@ -1,6 +1,6 @@
 ;;; tool-bar.el --- setting up the tool bar
 ;;
-;; Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+;; Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
 ;;
 ;; Author: Dave Love <fx@gnu.org>
 ;; Keywords: mouse frames
@@ -67,6 +67,12 @@
 		(= 1 (length (default-value 'tool-bar-map)))) ; not yet setup
 	   (tool-bar-setup))))
 
+;;; `tool-bar-mode' doesn't really have a standard value, as it depend
+;;; on where and how Emacs was started.  By removing the standard
+;;; value, we ensure that customize will always save it.
+;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
+(put 'tool-bar-mode 'standard-value nil)
+
 (defvar tool-bar-map (make-sparse-keymap)
   "Keymap for the tool bar.
 Define this locally to override the global tool bar.")