emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r100145: Use define-minor-mode for le


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r100145: Use define-minor-mode for less obvious cases.
Date: Tue, 04 May 2010 22:08:25 -0400
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 100145
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Tue 2010-05-04 22:08:25 -0400
message:
  Use define-minor-mode for less obvious cases.
  * emacs-lisp/easy-mmode.el (define-minor-mode): Add :variable keyword.
  * emacs-lisp/cl-macs.el (terminal-parameter, eq): Add setf method.
  * international/iso-ascii.el (iso-ascii-mode):
  * frame.el (auto-raise-mode, auto-lower-mode):
  * composite.el (global-auto-composition-mode): Use define-minor-mode.
modified:
  etc/NEWS
  lisp/ChangeLog
  lisp/composite.el
  lisp/emacs-lisp/cl-macs.el
  lisp/emacs-lisp/easy-mmode.el
  lisp/frame.el
  lisp/international/iso-ascii.el
  lisp/progmodes/idlwave.el
=== modified file 'etc/NEWS'
--- a/etc/NEWS  2010-05-03 15:01:21 +0000
+++ b/etc/NEWS  2010-05-05 02:08:25 +0000
@@ -186,6 +186,8 @@
 
 * Lisp changes in Emacs 24.1
 
+** define-minor-mode accepts a new keyword :variable.
+
 ** delete-file now accepts an optional second arg, FORCE, which says
 to always delete and ignore the value of delete-by-moving-to-trash.
 

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2010-05-04 08:44:47 +0000
+++ b/lisp/ChangeLog    2010-05-05 02:08:25 +0000
@@ -1,3 +1,11 @@
+2010-05-05  Stefan Monnier  <address@hidden>
+
+       * emacs-lisp/easy-mmode.el (define-minor-mode): Add :variable keyword.
+       * emacs-lisp/cl-macs.el (terminal-parameter, eq): Add setf method.
+       * international/iso-ascii.el (iso-ascii-mode):
+       * frame.el (auto-raise-mode, auto-lower-mode):
+       * composite.el (global-auto-composition-mode): Use define-minor-mode.
+
 2010-05-04  Michael Albinus  <address@hidden>
 
        * net/tramp.el (tramp-methods): Remove "-q" from `tramp-login-args'

=== modified file 'lisp/composite.el'
--- a/lisp/composite.el 2010-05-03 02:29:46 +0000
+++ b/lisp/composite.el 2010-05-05 02:08:25 +0000
@@ -764,16 +764,13 @@
 Auto Composition mode in all buffers (this is the default).")
 
 ;;;###autoload
-(defun global-auto-composition-mode (&optional arg)
+(define-minor-mode global-auto-composition-mode
   "Toggle Auto-Composition mode in every possible buffer.
 With prefix arg, turn Global-Auto-Composition mode on if and only if arg
 is positive.
 See `auto-composition-mode' for more information on Auto-Composition mode."
-  (interactive "P")
-  (setq-default auto-composition-mode
-               (if arg
-                   (or (not (integerp arg)) (> arg 0))
-                 (not (default-value 'auto-composition-mode)))))
+  :variable (default-value 'auto-composition-mode))
+
 (defalias 'toggle-auto-composition 'auto-composition-mode)
 
 

=== modified file 'lisp/emacs-lisp/cl-macs.el'
--- a/lisp/emacs-lisp/cl-macs.el        2010-04-08 19:59:46 +0000
+++ b/lisp/emacs-lisp/cl-macs.el        2010-05-05 02:08:25 +0000
@@ -1769,6 +1769,7 @@
 (defsetf frame-visible-p cl-set-frame-visible-p)
 (defsetf frame-width set-screen-width t)
 (defsetf frame-parameter set-frame-parameter t)
+(defsetf terminal-parameter set-terminal-parameter)
 (defsetf getenv setenv t)
 (defsetf get-register set-register)
 (defsetf global-key-binding global-set-key)
@@ -1821,10 +1822,16 @@
 (defsetf x-get-secondary-selection x-own-secondary-selection t)
 (defsetf x-get-selection x-own-selection t)
 
+;; This is a hack that allows (setf (eq a 7) B) to mean either
+;; (setq a 7) or (setq a nil) depending on whether B is nil or not.
+;; This is useful when you have control over the PLACE but not over
+;; the VALUE, as is the case in define-minor-mode's :variable.
+(defsetf eq (a b) (v) `(setf ,a (if ,v ,b (not ,b))))
+
 ;;; More complex setf-methods.
-;;; These should take &environment arguments, but since full arglists aren't
-;;; available while compiling cl-macs, we fake it by referring to the global
-;;; variable cl-macro-environment directly.
+;; These should take &environment arguments, but since full arglists aren't
+;; available while compiling cl-macs, we fake it by referring to the global
+;; variable cl-macro-environment directly.
 
 (define-setf-method apply (func arg1 &rest rest)
   (or (and (memq (car-safe func) '(quote function function*))

=== modified file 'lisp/emacs-lisp/easy-mmode.el'
--- a/lisp/emacs-lisp/easy-mmode.el     2010-04-28 15:18:37 +0000
+++ b/lisp/emacs-lisp/easy-mmode.el     2010-05-05 02:08:25 +0000
@@ -116,6 +116,8 @@
 :lighter SPEC  Same as the LIGHTER argument.
 :keymap MAP    Same as the KEYMAP argument.
 :require SYM   Same as in `defcustom'.
+:variable PLACE        The location (as can be used with `setf') to use instead
+               of the variable MODE to store the state of the mode.
 
 For example, you could write
   (define-minor-mode foo-mode \"If enabled, foo on you!\"
@@ -147,6 +149,8 @@
         (type nil)
         (extra-args nil)
         (extra-keywords nil)
+         (variable nil)
+         (modefun mode)
         (require t)
         (hook (intern (concat mode-name "-hook")))
         (hook-on (intern (concat mode-name "-on-hook")))
@@ -167,6 +171,7 @@
        (:type (setq type (list :type (pop body))))
        (:require (setq require (pop body)))
        (:keymap (setq keymap (pop body)))
+        (:variable (setq variable (setq mode (pop body))))
        (t (push keyw extra-keywords) (push (pop body) extra-keywords))))
 
     (setq keymap-sym (if (and keymap (symbolp keymap)) keymap
@@ -187,12 +192,16 @@
 
     `(progn
        ;; Define the variable to enable or disable the mode.
-       ,(if (not globalp)
-           `(progn
-              (defvar ,mode ,init-value ,(format "Non-nil if %s is enabled.
+       ,(cond
+         ;; If :variable is specified, then the var will be
+         ;; declared elsewhere.
+         (variable nil)
+         ((not globalp)
+          `(progn
+             (defvar ,mode ,init-value ,(format "Non-nil if %s is enabled.
 Use the command `%s' to change this variable." pretty-name mode))
-              (make-variable-buffer-local ',mode))
-
+             (make-variable-buffer-local ',mode)))
+         (t
          (let ((base-doc-string
                  (concat "Non-nil if %s is enabled.
 See the command `%s' for a description of this minor mode."
@@ -207,10 +216,10 @@
               ,@group
               ,@type
               ,@(unless (eq require t) `(:require ,require))
-               ,@(nreverse extra-keywords))))
+               ,@(nreverse extra-keywords)))))
 
        ;; The actual function.
-       (defun ,mode (&optional arg ,@extra-args)
+       (defun ,modefun (&optional arg ,@extra-args)
         ,(or doc
              (format (concat "Toggle %s on or off.
 Interactively, with no prefix argument, toggle the mode.
@@ -221,11 +230,11 @@
         ;; repeat-command still does the toggling correctly.
         (interactive (list (or current-prefix-arg 'toggle)))
         (let ((,last-message (current-message)))
-           (setq ,mode
-                 (if (eq arg 'toggle)
-                     (not ,mode)
-                   ;; A nil argument also means ON now.
-                   (> (prefix-numeric-value arg) 0)))
+           (,(if (symbolp mode) 'setq 'setf) ,mode
+            (if (eq arg 'toggle)
+                (not ,mode)
+              ;; A nil argument also means ON now.
+              (> (prefix-numeric-value arg) 0)))
            ,@body
            ;; The on/off hooks are here for backward compatibility only.
            (run-hooks ',hook (if ,mode ',hook-on ',hook-off))
@@ -256,9 +265,10 @@
                     (t (error "Invalid keymap %S" ,keymap))))
             ,(format "Keymap for `%s'." mode-name)))
 
-       (add-minor-mode ',mode ',lighter
-                      ,(if keymap keymap-sym
-                         `(if (boundp ',keymap-sym) ,keymap-sym))))))
+       ,(unless variable
+          `(add-minor-mode ',mode ',lighter
+                           ,(if keymap keymap-sym
+                              `(if (boundp ',keymap-sym) ,keymap-sym)))))))
 
 ;;;
 ;;; make global minor mode

=== modified file 'lisp/frame.el'
--- a/lisp/frame.el     2010-01-14 06:13:16 +0000
+++ b/lisp/frame.el     2010-05-05 02:08:25 +0000
@@ -24,6 +24,7 @@
 ;;; Commentary:
 
 ;;; Code:
+(eval-when-compile (require 'cl))
 
 (defvar frame-creation-function-alist
   (list (cons nil
@@ -1132,37 +1133,26 @@
   (modify-frame-parameters (selected-frame)
                           (list (cons 'border-color color-name))))
 
-(defun auto-raise-mode (arg)
+(define-minor-mode auto-raise-mode
   "Toggle whether or not the selected frame should auto-raise.
 With ARG, turn auto-raise mode on if and only if ARG is positive.
 Note that this controls Emacs's own auto-raise feature.
 Some window managers allow you to enable auto-raise for certain windows.
 You can use that for Emacs windows if you wish, but if you do,
 that is beyond the control of Emacs and this command has no effect on it."
-  (interactive "P")
-  (if (null arg)
-      (setq arg
-           (if (cdr (assq 'auto-raise (frame-parameters (selected-frame))))
-               -1 1)))
-  (if (> arg 0)
-      (raise-frame (selected-frame)))
-  (modify-frame-parameters (selected-frame)
-                          (list (cons 'auto-raise (> arg 0)))))
+  :variable (frame-parameter nil 'auto-raise)
+  (if (frame-parameter nil 'auto-raise)
+      (raise-frame)))
 
-(defun auto-lower-mode (arg)
+(define-minor-mode auto-lower-mode
   "Toggle whether or not the selected frame should auto-lower.
 With ARG, turn auto-lower mode on if and only if ARG is positive.
 Note that this controls Emacs's own auto-lower feature.
 Some window managers allow you to enable auto-lower for certain windows.
 You can use that for Emacs windows if you wish, but if you do,
 that is beyond the control of Emacs and this command has no effect on it."
-  (interactive "P")
-  (if (null arg)
-      (setq arg
-           (if (cdr (assq 'auto-lower (frame-parameters (selected-frame))))
-               -1 1)))
-  (modify-frame-parameters (selected-frame)
-                          (list (cons 'auto-lower (> arg 0)))))
+  :variable (frame-parameter nil 'auto-lower))
+
 (defun set-frame-name (name)
   "Set the name of the selected frame to NAME.
 When called interactively, prompt for the name of the frame.

=== modified file 'lisp/international/iso-ascii.el'
--- a/lisp/international/iso-ascii.el   2010-01-13 08:35:10 +0000
+++ b/lisp/international/iso-ascii.el   2010-05-05 02:08:25 +0000
@@ -33,6 +33,7 @@
 ;;; Code:
 
 (require 'disp-table)
+(eval-when-compile (require 'cl))
 
 (defgroup iso-ascii nil
   "Set up char tables for ISO 8859/1 on ASCII terminals."
@@ -162,15 +163,11 @@
 (iso-ascii-display 254 "th")  ; small thorn, Icelandic
 (iso-ascii-display 255 "\"y") ; small y with diaeresis or umlaut mark
 
-(defun iso-ascii-mode (arg)
+(define-minor-mode iso-ascii-mode
   "Toggle ISO-ASCII mode."
-  (interactive "P")
-  (unless arg
-    (setq arg (eq standard-display-table iso-ascii-standard-display-table)))
-  (setq standard-display-table
-       (if arg
-           iso-ascii-display-table
-         iso-ascii-standard-display-table)))
+  :variable (eq standard-display-table iso-ascii-display-table)
+  (unless standard-display-table
+    (setq standard-display-table iso-ascii-standard-display-table)))
 
 (provide 'iso-ascii)
 

=== modified file 'lisp/progmodes/idlwave.el'
--- a/lisp/progmodes/idlwave.el 2010-01-14 18:37:23 +0000
+++ b/lisp/progmodes/idlwave.el 2010-05-05 02:08:25 +0000
@@ -1370,6 +1370,7 @@
 not possible without parsing.  Thus assignment statement become just
 the leftover unidentified statements containing an equal sign.")
 
+;; FIXME: This var seems to only ever be set, but never actually used!
 (defvar idlwave-fill-function 'auto-fill-function
   "IDL mode auto fill function.")
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]