From 56eb09046e00ac7ee6d3d3d752cb1ee664b7e062 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sun, 2 May 2010 22:29:46 -0400 Subject: [PATCH] Use define-minor-mode where applicable. * mh-show.el (mh-showing-mode): Move function to mh-e.el. * mh-e.el (mh-showing-mode): * url-dired.el (url-dired-minor-mode): * org-table.el (orgtbl-mode): * view.el (view-mode): * type-break.el (type-break-query-mode) (type-break-mode-line-message-mode): * textmodes/reftex.el (reftex-mode): * term/vt100.el (vt100-wide-mode): * tar-mode.el (tar-subfile-mode): * savehist.el (savehist-mode): * ibuf-ext.el (ibuffer-auto-mode): * composite.el (auto-composition-mode): * progmodes/vhdl-mode.el (vhdl-electric-mode, vhdl-stutter-mode): Use define-minor-mode. (vhdl-mode): Use static mode-line format. (vhdl-mode-line-update): Delete. (vhdl-create-mode-menu, vhdl-activate-customizations) (vhdl-hs-minor-mode): Don't bother calling it. --- lisp/ChangeLog | 19 ++++++++ lisp/composite.el | 10 +--- lisp/ibuf-ext.el | 29 ++++-------- lisp/mh-e/ChangeLog | 5 ++ lisp/mh-e/mh-e.el | 6 ++- lisp/mh-e/mh-show.el | 10 ---- lisp/org/ChangeLog | 9 ++-- lisp/org/org-table.el | 92 +++++++++++++++++-------------------- lisp/progmodes/vhdl-mode.el | 56 +++++----------------- lisp/savehist.el | 25 ++-------- lisp/tar-mode.el | 19 ++------ lisp/term/vt100.el | 14 ++---- lisp/textmodes/reftex.el | 40 ++++------------ lisp/type-break.el | 39 ++-------------- lisp/url/ChangeLog | 4 ++ lisp/url/url-dired.el | 39 +--------------- lisp/view.el | 21 ++------- 17 files changed, 136 insertions(+), 301 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a7414aa2586..eb42484950f 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,22 @@ +2010-05-03 Stefan Monnier + + Use define-minor-mode where applicable. + * view.el (view-mode): + * type-break.el (type-break-query-mode) + (type-break-mode-line-message-mode): + * textmodes/reftex.el (reftex-mode): + * term/vt100.el (vt100-wide-mode): + * tar-mode.el (tar-subfile-mode): + * savehist.el (savehist-mode): + * ibuf-ext.el (ibuffer-auto-mode): + * composite.el (auto-composition-mode): + * progmodes/vhdl-mode.el (vhdl-electric-mode, vhdl-stutter-mode): + Use define-minor-mode. + (vhdl-mode): Use static mode-line format. + (vhdl-mode-line-update): Delete. + (vhdl-create-mode-menu, vhdl-activate-customizations) + (vhdl-hs-minor-mode): Don't bother calling it. + 2010-05-02 Stefan Monnier * simple.el (with-wrapper-hook): Move. diff --git a/lisp/composite.el b/lisp/composite.el index 5b01718fc71..2b65839b93f 100644 --- a/lisp/composite.el +++ b/lisp/composite.el @@ -745,14 +745,13 @@ This function is the default value of `auto-composition-function' (which see)." (setq func 'compose-gstring-for-terminal)) (funcall func gstring)))) -(make-variable-buffer-local 'auto-composition-mode) (put 'auto-composition-mode 'permanent-local t) (make-variable-buffer-local 'auto-composition-function) (setq-default auto-composition-function 'auto-compose-chars) ;;;###autoload -(defun auto-composition-mode (&optional arg) +(define-minor-mode auto-composition-mode "Toggle Auto Composition mode. With ARG, turn Auto Composition mode off if and only if ARG is a non-positive number; if ARG is nil, toggle Auto Composition mode; anything else turns Auto @@ -762,12 +761,7 @@ When Auto Composition is enabled, text characters are automatically composed by functions registered in `composition-function-table' (which see). You can use `global-auto-composition-mode' to turn on -Auto Composition mode in all buffers (this is the default)." - (interactive "P") - (setq auto-composition-mode - (if arg - (or (not (integerp arg)) (> arg 0)) - (not auto-composition-mode)))) +Auto Composition mode in all buffers (this is the default).") ;;;###autoload (defun global-auto-composition-mode (&optional arg) diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el index 69eb3188862..dcea1e57472 100644 --- a/lisp/ibuf-ext.el +++ b/lisp/ibuf-ext.el @@ -91,11 +91,6 @@ regardless of any active filters in this buffer." (defvar ibuffer-tmp-show-regexps nil "A list of regexps which should match buffer names to always show.") -(defvar ibuffer-auto-mode nil - "If non-nil, Ibuffer auto-mode should be enabled for this buffer. -Do not set this variable directly! Use the function -`ibuffer-auto-mode' instead.") - (defvar ibuffer-auto-buffers-changed nil) (defcustom ibuffer-saved-filters '(("gnus" @@ -220,6 +215,16 @@ Currently, this only applies to `ibuffer-saved-filters' and (ibuffer-included-in-filters-p buf ibuffer-filtering-qualifiers) (ibuffer-buf-matches-predicates buf ibuffer-always-show-predicates))))) +;;;###autoload +(define-minor-mode ibuffer-auto-mode + "Toggle use of Ibuffer's auto-update facility. +With numeric ARG, enable auto-update if and only if ARG is positive." + nil nil nil + (unless (derived-mode-p 'ibuffer-mode) + (error "This buffer is not in Ibuffer mode")) + (frame-or-buffer-changed-p 'ibuffer-auto-buffers-changed) ; Initialize state vector + (add-hook 'post-command-hook 'ibuffer-auto-update-changed)) + (defun ibuffer-auto-update-changed () (when (frame-or-buffer-changed-p 'ibuffer-auto-buffers-changed) (dolist (buf (buffer-list)) @@ -229,20 +234,6 @@ Currently, this only applies to `ibuffer-saved-filters' and (derived-mode-p 'ibuffer-mode)) (ibuffer-update nil t))))))) -;;;###autoload -(defun ibuffer-auto-mode (&optional arg) - "Toggle use of Ibuffer's auto-update facility. -With numeric ARG, enable auto-update if and only if ARG is positive." - (interactive) - (unless (derived-mode-p 'ibuffer-mode) - (error "This buffer is not in Ibuffer mode")) - (set (make-local-variable 'ibuffer-auto-mode) - (if arg - (plusp arg) - (not ibuffer-auto-mode))) - (frame-or-buffer-changed-p 'ibuffer-auto-buffers-changed) ; Initialize state vector - (add-hook 'post-command-hook 'ibuffer-auto-update-changed)) - ;;;###autoload (defun ibuffer-mouse-filter-by-mode (event) "Enable or disable filtering by the major mode chosen via mouse." diff --git a/lisp/mh-e/ChangeLog b/lisp/mh-e/ChangeLog index 4584aa0bbd7..8ed4279721e 100644 --- a/lisp/mh-e/ChangeLog +++ b/lisp/mh-e/ChangeLog @@ -1,3 +1,8 @@ +2010-05-03 Stefan Monnier + + * mh-show.el (mh-showing-mode): Move function to mh-e.el. + * mh-e.el (mh-showing-mode): Use define-minor-mode. + 2010-03-24 Juanma Barranquero * mh-scan.el (mh-scan-cmd-note-width): Doc fix. diff --git a/lisp/mh-e/mh-e.el b/lisp/mh-e/mh-e.el index 3639920f514..9a2bccbc967 100644 --- a/lisp/mh-e/mh-e.el +++ b/lisp/mh-e/mh-e.el @@ -287,8 +287,10 @@ Elements have the form (SEQUENCE . MESSAGES).") (defvar mh-show-buffer nil "Buffer that displays message for this folder.") -(defvar mh-showing-mode nil - "If non-nil, show the message in a separate window.") +(define-minor-mode mh-showing-mode + "Minor mode to show the message in a separate window." + ;; FIXME: maybe this should be moved to mh-show.el. + :lighter " Show") (defvar mh-view-ops nil "Stack of operations that change the folder view. diff --git a/lisp/mh-e/mh-show.el b/lisp/mh-e/mh-show.el index 766b6982d98..58d52205079 100644 --- a/lisp/mh-e/mh-show.el +++ b/lisp/mh-e/mh-show.el @@ -169,16 +169,6 @@ displayed." (apply #'mh-speed-flists t folders))) (run-hooks 'mh-show-hook))) -;;;###mh-autoload -(defun mh-showing-mode (&optional arg) - "Change whether messages should be displayed. - -With ARG, display messages if ARG is positive, otherwise don't display them." - (setq mh-showing-mode - (if (null arg) - (not mh-showing-mode) - (> (prefix-numeric-value arg) 0)))) - ;;;###mh-autoload (defun mh-start-of-uncleaned-message () "Position uninteresting headers off the top of the window." diff --git a/lisp/org/ChangeLog b/lisp/org/ChangeLog index 770fd883e2c..b4675723096 100644 --- a/lisp/org/ChangeLog +++ b/lisp/org/ChangeLog @@ -1,8 +1,11 @@ +2010-05-03 Stefan Monnier + + * org-table.el (orgtbl-mode): Use define-minor-mode. + 2010-04-10 Carsten Dominik - * org.el (org-insert-link): Find the link buffer on visible - frames. - (org-export-latex-default-packages-alist): hyperref must be loaded + * org.el (org-insert-link): Find the link buffer on visible frames. + (org-export-latex-default-packages-alist): Hyperref must be loaded late. (org-open-file): More care with the new matching for file links. diff --git a/lisp/org/org-table.el b/lisp/org/org-table.el index 24c02a658ba..98c48baf52c 100644 --- a/lisp/org/org-table.el +++ b/lisp/org/org-table.el @@ -3401,11 +3401,6 @@ Use COMMAND to do the motion, repeat if necessary to end up in a data line." ;; active, this binding is ignored inside tables and replaced with a ;; modified self-insert. -(defvar orgtbl-mode nil - "Variable controlling `orgtbl-mode', a minor mode enabling the `org-mode' -table editor in arbitrary modes.") -(make-variable-buffer-local 'orgtbl-mode) - (defvar orgtbl-mode-map (make-keymap) "Keymap for `orgtbl-mode'.") @@ -3426,49 +3421,51 @@ table editor in arbitrary modes.") 0 (quote 'org-table) 'prepend)) "Extra font-lock-keywords to be added when orgtbl-mode is active.") +;; Install it as a minor mode. +(put 'orgtbl-mode :included t) +(put 'orgtbl-mode :menu-tag "Org Table Mode") ;;;###autoload -(defun orgtbl-mode (&optional arg) +(define-minor-mode orgtbl-mode "The `org-mode' table editor as a minor mode for use in other modes." - (interactive) + :lighter " OrgTbl" :keymap orgtbl-mode-map (org-load-modules-maybe) - (if (org-mode-p) - ;; Exit without error, in case some hook functions calls this - ;; by accident in org-mode. - (message "Orgtbl-mode is not useful in org-mode, command ignored") - (setq orgtbl-mode - (if arg (> (prefix-numeric-value arg) 0) (not orgtbl-mode))) - (if orgtbl-mode - (progn - (and (orgtbl-setup) (defun orgtbl-setup () nil)) - ;; Make sure we are first in minor-mode-map-alist - (let ((c (assq 'orgtbl-mode minor-mode-map-alist))) - (and c (setq minor-mode-map-alist - (cons c (delq c minor-mode-map-alist))))) - (org-set-local (quote org-table-may-need-update) t) - (org-add-hook 'before-change-functions 'org-before-change-function - nil 'local) - (org-set-local 'org-old-auto-fill-inhibit-regexp - auto-fill-inhibit-regexp) - (org-set-local 'auto-fill-inhibit-regexp - (if auto-fill-inhibit-regexp - (concat orgtbl-line-start-regexp "\\|" - auto-fill-inhibit-regexp) - orgtbl-line-start-regexp)) - (org-add-to-invisibility-spec '(org-cwidth)) - (when (fboundp 'font-lock-add-keywords) - (font-lock-add-keywords nil orgtbl-extra-font-lock-keywords) - (org-restart-font-lock)) - (easy-menu-add orgtbl-mode-menu) - (run-hooks 'orgtbl-mode-hook)) - (setq auto-fill-inhibit-regexp org-old-auto-fill-inhibit-regexp) - (org-table-cleanup-narrow-column-properties) - (org-remove-from-invisibility-spec '(org-cwidth)) - (remove-hook 'before-change-functions 'org-before-change-function t) - (when (fboundp 'font-lock-remove-keywords) - (font-lock-remove-keywords nil orgtbl-extra-font-lock-keywords) - (org-restart-font-lock)) - (easy-menu-remove orgtbl-mode-menu) - (force-mode-line-update 'all)))) + (cond + ((org-mode-p) + ;; Exit without error, in case some hook functions calls this + ;; by accident in org-mode. + (message "Orgtbl-mode is not useful in org-mode, command ignored")) + (orgtbl-mode + (and (orgtbl-setup) (defun orgtbl-setup () nil)) ;; FIXME: Yuck!?! + ;; Make sure we are first in minor-mode-map-alist + (let ((c (assq 'orgtbl-mode minor-mode-map-alist))) + ;; FIXME: maybe it should use emulation-mode-map-alists? + (and c (setq minor-mode-map-alist + (cons c (delq c minor-mode-map-alist))))) + (org-set-local (quote org-table-may-need-update) t) + (org-add-hook 'before-change-functions 'org-before-change-function + nil 'local) + (org-set-local 'org-old-auto-fill-inhibit-regexp + auto-fill-inhibit-regexp) + (org-set-local 'auto-fill-inhibit-regexp + (if auto-fill-inhibit-regexp + (concat orgtbl-line-start-regexp "\\|" + auto-fill-inhibit-regexp) + orgtbl-line-start-regexp)) + (org-add-to-invisibility-spec '(org-cwidth)) + (when (fboundp 'font-lock-add-keywords) + (font-lock-add-keywords nil orgtbl-extra-font-lock-keywords) + (org-restart-font-lock)) + (easy-menu-add orgtbl-mode-menu)) + (t + (setq auto-fill-inhibit-regexp org-old-auto-fill-inhibit-regexp) + (org-table-cleanup-narrow-column-properties) + (org-remove-from-invisibility-spec '(org-cwidth)) + (remove-hook 'before-change-functions 'org-before-change-function t) + (when (fboundp 'font-lock-remove-keywords) + (font-lock-remove-keywords nil orgtbl-extra-font-lock-keywords) + (org-restart-font-lock)) + (easy-menu-remove orgtbl-mode-menu) + (force-mode-line-update 'all)))) (defun org-table-cleanup-narrow-column-properties () "Remove all properties related to narrow-column invisibility." @@ -3483,11 +3480,6 @@ table editor in arbitrary modes.") (while (setq s (text-property-any s (point-max) 'invisible 'org-cwidth)) (remove-text-properties s (1+ s) '(invisible t))))) -;; Install it as a minor mode. -(put 'orgtbl-mode :included t) -(put 'orgtbl-mode :menu-tag "Org Table Mode") -(add-minor-mode 'orgtbl-mode " OrgTbl" orgtbl-mode-map) - (defun orgtbl-make-binding (fun n &rest keys) "Create a function for binding in the table minor mode. FUN is the command to call inside a table. N is used to create a unique diff --git a/lisp/progmodes/vhdl-mode.el b/lisp/progmodes/vhdl-mode.el index 1210592af18..e0c8ee404a6 100644 --- a/lisp/progmodes/vhdl-mode.el +++ b/lisp/progmodes/vhdl-mode.el @@ -199,21 +199,6 @@ Examples: "Customizations for modes." :group 'vhdl) -(defcustom vhdl-electric-mode t - "*Non-nil enables electrification (automatic template generation). -If nil, template generators can still be invoked through key bindings and -menu. Is indicated in the modeline by \"/e\" after the mode name and can be -toggled by `\\[vhdl-electric-mode]'." - :type 'boolean - :group 'vhdl-mode) - -(defcustom vhdl-stutter-mode t - "*Non-nil enables stuttering. -Is indicated in the modeline by \"/s\" after the mode name and can be toggled -by `\\[vhdl-stutter-mode]'." - :type 'boolean - :group 'vhdl-mode) - (defcustom vhdl-indent-tabs-mode nil "*Non-nil means indentation can insert tabs. Overrides local variable `indent-tabs-mode'." @@ -3466,13 +3451,11 @@ STRING are replaced by `-' and substrings are converted to lower case." ("Mode" ["Electric Mode" (progn (customize-set-variable 'vhdl-electric-mode - (not vhdl-electric-mode)) - (vhdl-mode-line-update)) + (not vhdl-electric-mode))) :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"] ["Stutter Mode" (progn (customize-set-variable 'vhdl-stutter-mode - (not vhdl-stutter-mode)) - (vhdl-mode-line-update)) + (not vhdl-stutter-mode))) :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"] ["Indent Tabs Mode" (progn (customize-set-variable 'vhdl-indent-tabs-mode @@ -4670,7 +4653,10 @@ Key bindings: (interactive) (kill-all-local-variables) (setq major-mode 'vhdl-mode) - (setq mode-name "VHDL") + (setq mode-name '("VHDL" + (vhdl-electric-mode "/" (vhdl-stutter-mode "/")) + (vhdl-electric-mode "e") + (vhdl-stutter-mode "s"))) ;; set maps and tables (use-local-map vhdl-mode-map) @@ -4737,7 +4723,6 @@ Key bindings: ;; miscellaneous (vhdl-ps-print-init) (vhdl-write-file-hooks-init) - (vhdl-mode-line-update) (message "VHDL Mode %s.%s" vhdl-version (if noninteractive "" " See menu for documentation and release notes.")) @@ -4757,8 +4742,7 @@ Key bindings: (vhdl-write-file-hooks-init) (vhdl-update-mode-menu) (vhdl-hideshow-init) - (run-hooks 'menu-bar-update-hook) - (vhdl-mode-line-update)) + (run-hooks 'menu-bar-update-hook)) (defun vhdl-write-file-hooks-init () "Add/remove hooks when buffer is saved." @@ -8055,31 +8039,15 @@ project is defined." ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Enabling/disabling -(defun vhdl-mode-line-update () - "Update the modeline string for VHDL major mode." - (setq mode-name (concat "VHDL" - (and (or vhdl-electric-mode vhdl-stutter-mode) "/") - (and vhdl-electric-mode "e") - (and vhdl-stutter-mode "s"))) - (force-mode-line-update t)) - -(defun vhdl-electric-mode (arg) +(define-minor-mode vhdl-electric-mode "Toggle VHDL electric mode. Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil." - (interactive "P") - (setq vhdl-electric-mode - (cond ((or (not arg) (zerop arg)) (not vhdl-electric-mode)) - ((> arg 0) t) (t nil))) - (vhdl-mode-line-update)) + :global t) -(defun vhdl-stutter-mode (arg) +(define-minor-mode vhdl-stutter-mode "Toggle VHDL stuttering mode. Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil." - (interactive "P") - (setq vhdl-stutter-mode - (cond ((or (not arg) (zerop arg)) (not vhdl-stutter-mode)) - ((> arg 0) t) (t nil))) - (vhdl-mode-line-update)) + :global t) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Stuttering @@ -12533,7 +12501,7 @@ File statistics: \"%s\"\n\ (add-hook 'hs-minor-mode-hook 'hs-hide-all) (remove-hook 'hs-minor-mode-hook 'hs-hide-all)) (hs-minor-mode arg) - (vhdl-mode-line-update))) ; hack to update menu bar + (force-mode-line-update))) ; hack to update menu bar ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/lisp/savehist.el b/lisp/savehist.el index eebc5ec942b..15c841ac9c7 100644 --- a/lisp/savehist.el +++ b/lisp/savehist.el @@ -59,17 +59,6 @@ :version "22.1" :group 'minibuffer) -;;;###autoload -(defcustom savehist-mode nil - "Mode for automatic saving of minibuffer history. -Set this by calling the `savehist-mode' function or using the customize -interface." - :type 'boolean - :set (lambda (symbol value) (savehist-mode (or value 0))) - :initialize 'custom-initialize-default - :require 'savehist - :group 'savehist) - (defcustom savehist-save-minibuffer-history t "If non-nil, save all recorded minibuffer histories. If you want to save only specific histories, use `savehist-save-hook' to @@ -181,7 +170,7 @@ minibuffer history.") ;; Functions. ;;;###autoload -(defun savehist-mode (arg) +(define-minor-mode savehist-mode "Toggle savehist-mode. Positive ARG turns on `savehist-mode'. When on, savehist-mode causes minibuffer history to be saved periodically and when exiting Emacs. @@ -191,11 +180,7 @@ previous minibuffer history to be loaded from `savehist-file'. This mode should normally be turned on from your Emacs init file. Calling it at any other time replaces your current minibuffer histories, which is probably undesirable." - (interactive "P") - (setq savehist-mode - (if (null arg) - (not savehist-mode) - (> (prefix-numeric-value arg) 0))) + :global t (if (not savehist-mode) (savehist-uninstall) (when (and (not savehist-loaded) @@ -214,11 +199,7 @@ which is probably undesirable." (setq savehist-mode nil) (savehist-uninstall) (signal (car errvar) (cdr errvar))))) - (savehist-install) - (run-hooks 'savehist-mode-hook)) - ;; Return the new setting. - savehist-mode) -(add-minor-mode 'savehist-mode "") + (savehist-install))) (defun savehist-load () "Load the variables stored in `savehist-file' and turn on `savehist-mode'. diff --git a/lisp/tar-mode.el b/lisp/tar-mode.el index f8925706337..f8b9cf09fba 100644 --- a/lisp/tar-mode.el +++ b/lisp/tar-mode.el @@ -137,7 +137,6 @@ This information is useful, but it takes screen space away from file names." (defvar tar-parse-info nil) (defvar tar-superior-buffer nil) (defvar tar-superior-descriptor nil) -(defvar tar-subfile-mode nil) (defvar tar-file-name-coding-system nil) (put 'tar-superior-buffer 'permanent-local t) @@ -672,29 +671,21 @@ See also: variables `tar-update-datestamp' and `tar-anal-blocksize'. (signal (car err) (cdr err))))) -(defun tar-subfile-mode (p) +(define-minor-mode tar-subfile-mode "Minor mode for editing an element of a tar-file. This mode arranges for \"saving\" this buffer to write the data into the tar-file buffer that it came from. The changes will actually appear on disk when you save the tar-file's buffer." - (interactive "P") + ;; Don't do this, because it is redundant and wastes mode line space. + ;; :lighter " TarFile" + nil nil nil (or (and (boundp 'tar-superior-buffer) tar-superior-buffer) (error "This buffer is not an element of a tar file")) - ;; Don't do this, because it is redundant and wastes mode line space. - ;; (or (assq 'tar-subfile-mode minor-mode-alist) - ;; (setq minor-mode-alist (append minor-mode-alist - ;; (list '(tar-subfile-mode " TarFile"))))) - (make-local-variable 'tar-subfile-mode) - (setq tar-subfile-mode - (if (null p) - (not tar-subfile-mode) - (> (prefix-numeric-value p) 0))) (cond (tar-subfile-mode (add-hook 'write-file-functions 'tar-subfile-save-buffer nil t) ;; turn off auto-save. (auto-save-mode -1) - (setq buffer-auto-save-file-name nil) - (run-hooks 'tar-subfile-mode-hook)) + (setq buffer-auto-save-file-name nil)) (t (remove-hook 'write-file-functions 'tar-subfile-save-buffer t)))) diff --git a/lisp/term/vt100.el b/lisp/term/vt100.el index d0560702ac0..017c976ed51 100644 --- a/lisp/term/vt100.el +++ b/lisp/term/vt100.el @@ -41,19 +41,13 @@ (tty-run-terminal-initialization (selected-frame) "lk201")) ;;; Controlling the screen width. -(defvar vt100-wide-mode (= (frame-width) 132) - "t if vt100 is in 132-column mode.") - -(defun vt100-wide-mode (&optional arg) +(define-minor-mode vt100-wide-mode "Toggle 132/80 column mode for vt100s. With positive argument, switch to 132-column mode. With negative argument, switch to 80-column mode." - (interactive "P") - (setq vt100-wide-mode - (if (null arg) (not vt100-wide-mode) - (> (prefix-numeric-value arg) 0))) - (send-string-to-terminal (if vt100-wide-mode "\e[?3h" "\e[?3l")) - (set-frame-width terminal-frame (if vt100-wide-mode 132 80))) + :global t :initial-value (= (frame-width) 132) + (send-string-to-terminal (if vt100-wide-mode "\e[?3h" "\e[?3l")) + (set-frame-width terminal-frame (if vt100-wide-mode 132 80))) ;; arch-tag: 9ff41f24-a7c9-4dee-9cf2-fbaa951eb840 ;;; vt100.el ends here diff --git a/lisp/textmodes/reftex.el b/lisp/textmodes/reftex.el index 66dec462b83..b4b0a281ca6 100644 --- a/lisp/textmodes/reftex.el +++ b/lisp/textmodes/reftex.el @@ -305,10 +305,6 @@ (defconst reftex-version "RefTeX version 4.31" "Version string for RefTeX.") -(defvar reftex-mode nil - "Determines if RefTeX mode is active.") -(make-variable-buffer-local 'reftex-mode) - (defvar reftex-mode-map (make-sparse-keymap) "Keymap for RefTeX mode.") @@ -504,8 +500,10 @@ "Turn on RefTeX mode." (reftex-mode t)) +(put 'reftex-mode :included '(memq major-mode '(latex-mode tex-mode))) +(put 'reftex-mode :menu-tag "RefTeX Mode") ;;;###autoload -(defun reftex-mode (&optional arg) +(define-minor-mode reftex-mode "Minor mode with distinct support for \\label, \\ref and \\cite in LaTeX. \\A Table of Contents of the entire (multifile) document with browsing @@ -535,11 +533,7 @@ Under X, these and other functions will also be available as `Ref' menu on the menu bar. ------------------------------------------------------------------------------" - - (interactive "P") - (setq reftex-mode (not (or (and (null arg) reftex-mode) - (<= (prefix-numeric-value arg) 0)))) - + :lighter " Ref" :keymap reftex-mode-map (if reftex-mode (progn ;; Mode was turned on @@ -565,24 +559,10 @@ on the menu bar. (modify-syntax-entry ?\' "." reftex-syntax-table-for-bib) (modify-syntax-entry ?\" "." reftex-syntax-table-for-bib) (modify-syntax-entry ?\[ "." reftex-syntax-table-for-bib) - (modify-syntax-entry ?\] "." reftex-syntax-table-for-bib) - - (run-hooks 'reftex-mode-hook)) + (modify-syntax-entry ?\] "." reftex-syntax-table-for-bib)) ;; Mode was turned off (easy-menu-remove reftex-mode-menu))) -(if (fboundp 'add-minor-mode) - ;; Use it so that we get the extras - (progn - (put 'reftex-mode :included '(memq major-mode '(latex-mode tex-mode))) - (put 'reftex-mode :menu-tag "RefTeX Mode") - (add-minor-mode 'reftex-mode " Ref" reftex-mode-map)) - ;; The standard way - (unless (assoc 'reftex-mode minor-mode-alist) - (push '(reftex-mode " Ref") minor-mode-alist)) - (unless (assoc 'reftex-mode minor-mode-map-alist) - (push (cons 'reftex-mode reftex-mode-map) minor-mode-map-alist))) - (defvar reftex-docstruct-symbol) (defun reftex-kill-buffer-hook () "Save RefTeX's parse file for this buffer if the information has changed." @@ -625,11 +605,11 @@ on the menu bar. ;;; ;;; Multibuffer Variables ;;; -;;; Technical notes: These work as follows: We keep just one list -;;; of labels for each master file - this can save a lot of memory. -;;; `reftex-master-index-list' is an alist which connects the true file name -;;; of each master file with the symbols holding the information on that -;;; document. Each buffer has local variables which point to these symbols. +;; Technical notes: These work as follows: We keep just one list +;; of labels for each master file - this can save a lot of memory. +;; `reftex-master-index-list' is an alist which connects the true file name +;; of each master file with the symbols holding the information on that +;; document. Each buffer has local variables which point to these symbols. ;; List of variables which handle the multifile stuff. ;; This list is used to tie, untie, and reset these symbols. diff --git a/lisp/type-break.el b/lisp/type-break.el index 46523c22995..641215be8cf 100644 --- a/lisp/type-break.el +++ b/lisp/type-break.el @@ -152,13 +152,6 @@ guess a reasonably good pair of values for this variable." :type 'sexp :group 'type-break) -(defcustom type-break-query-mode t - "Non-nil means ask whether or not to prompt user for breaks. -If so, call the function specified in the value of the variable -`type-break-query-function' to do the asking." - :type 'boolean - :group 'type-break) - (defcustom type-break-query-function 'yes-or-no-p "Function to use for making query for a typing break. It should take a string as an argument, the prompt. @@ -245,14 +238,6 @@ remove themselves after running.") ;; Mode line frobs -(defcustom type-break-mode-line-message-mode nil - "Non-nil means put type-break related messages in the mode line. -Otherwise, messages typically go in the echo area. - -See also `type-break-mode-line-format' and its members." - :type 'boolean - :group 'type-break) - (defvar type-break-mode-line-format '(type-break-mode-line-message-mode ("" @@ -447,7 +432,7 @@ problems." (message "Type Break mode is disabled"))))) type-break-mode) -(defun type-break-mode-line-message-mode (&optional prefix) +(define-minor-mode type-break-mode-line-message-mode "Enable or disable warnings in the mode line about typing breaks. A negative PREFIX argument disables this mode. @@ -462,16 +447,9 @@ Variables controlling the display of messages in the mode line include: `global-mode-string' `type-break-mode-line-break-message' `type-break-mode-line-warning'" - (interactive "P") - (setq type-break-mode-line-message-mode - (>= (prefix-numeric-value prefix) 0)) - (and (called-interactively-p 'interactive) - (if type-break-mode-line-message-mode - (message "type-break-mode-line-message-mode is enabled") - (message "type-break-mode-line-message-mode is disabled"))) - type-break-mode-line-message-mode) - -(defun type-break-query-mode (&optional prefix) + :global t) + +(define-minor-mode type-break-query-mode "Enable or disable warnings in the mode line about typing breaks. When enabled, the user is periodically queried about whether to take a @@ -483,14 +461,7 @@ No argument or any non-negative argument enables it. The user may also enable or disable this mode simply by setting the variable of the same name." - (interactive "P") - (setq type-break-query-mode - (>= (prefix-numeric-value prefix) 0)) - (and (called-interactively-p 'interactive) - (if type-break-query-mode - (message "type-break-query-mode is enabled") - (message "type-break-query-mode is disabled"))) - type-break-query-mode) + :global t) ;;; session file functions diff --git a/lisp/url/ChangeLog b/lisp/url/ChangeLog index d3231672dd2..5a79712dfae 100644 --- a/lisp/url/ChangeLog +++ b/lisp/url/ChangeLog @@ -1,3 +1,7 @@ +2010-05-03 Stefan Monnier + + * url-dired.el (url-dired-minor-mode): Use define-minor-mode. + 2010-03-24 Teodor Zlatanov * url-http.el (url-http-parse-headers): Fix wrong variable name. diff --git a/lisp/url/url-dired.el b/lisp/url/url-dired.el index af2f4b202d9..143c5721b34 100644 --- a/lisp/url/url-dired.el +++ b/lisp/url/url-dired.el @@ -31,11 +31,6 @@ map) "Keymap used when browsing directories.") -(defvar url-dired-minor-mode nil - "Whether we are in url-dired-minor-mode.") - -(make-variable-buffer-local 'url-dired-minor-mode) - (defun url-dired-find-file () "In dired, visit the file or directory named on this line." (interactive) @@ -48,39 +43,9 @@ (mouse-set-point event) (url-dired-find-file)) -(defun url-dired-minor-mode (&optional arg) +(define-minor-mode url-dired-minor-mode "Minor mode for directory browsing." - (interactive "P") - (cond - ((null arg) - (setq url-dired-minor-mode (not url-dired-minor-mode))) - ((equal 0 arg) - (setq url-dired-minor-mode nil)) - (t - (setq url-dired-minor-mode t)))) - -(if (not (fboundp 'add-minor-mode)) - (defun add-minor-mode (toggle name &optional keymap after toggle-fun) - "Add a minor mode to `minor-mode-alist' and `minor-mode-map-alist'. -TOGGLE is a symbol which is used as the variable which toggle the minor mode, -NAME is the name that should appear in the modeline (it should be a string -beginning with a space), KEYMAP is a keymap to make active when the minor -mode is active, and AFTER is the toggling symbol used for another minor -mode. If AFTER is non-nil, then it is used to position the new mode in the -minor-mode alists. TOGGLE-FUN specifies an interactive function that -is called to toggle the mode on and off; this affects what appens when -button2 is pressed on the mode, and when button3 is pressed somewhere -in the list of modes. If TOGGLE-FUN is nil and TOGGLE names an -interactive function, TOGGLE is used as the toggle function. - -Example: (add-minor-mode 'view-minor-mode \" View\" view-mode-map)" - (if (not (assq toggle minor-mode-alist)) - (setq minor-mode-alist (cons (list toggle name) minor-mode-alist))) - (if (and keymap (not (assq toggle minor-mode-map-alist))) - (setq minor-mode-map-alist (cons (cons toggle keymap) - minor-mode-map-alist))))) - -(add-minor-mode 'url-dired-minor-mode " URL" url-dired-minor-mode-map) + :lighter " URL" :keymap url-dired-minor-mode-map) (defun url-find-file-dired (dir) "\"Edit\" directory DIR, but with additional URL-friendly bindings." diff --git a/lisp/view.el b/lisp/view.el index 7493f641b6c..f6698ae5a9f 100644 --- a/lisp/view.el +++ b/lisp/view.el @@ -161,14 +161,6 @@ that use View mode automatically.") "Overlay used to display where a search operation found its match. This is local in each buffer, once it is used.") (make-variable-buffer-local 'view-overlay) - -(unless (assq 'view-mode minor-mode-alist) - (setq minor-mode-alist - (cons (list 'view-mode - (propertize " View" - 'local-map mode-line-minor-mode-keymap - 'help-echo "mouse-3: minor mode menu")) - minor-mode-alist))) ;; Define keymap inside defvar to make it easier to load changes. ;; Some redundant "less"-like key bindings below have been commented out. @@ -230,10 +222,6 @@ This is local in each buffer, once it is used.") (define-key map "?" 'describe-mode) ; Maybe do as less instead? See above. (define-key map "h" 'describe-mode) map)) - -(or (assq 'view-mode minor-mode-map-alist) - (setq minor-mode-map-alist - (cons (cons 'view-mode view-mode-map) minor-mode-map-alist))) ;;; Commands that enter or exit view mode. @@ -393,7 +381,7 @@ this argument instead of explicitly setting `view-exit-action'." exit-action))) ;;;###autoload -(defun view-mode (&optional arg) +(define-minor-mode view-mode ;; In the following documentation string we have to use some explicit key ;; bindings instead of using the \\[] construction. The reason for this ;; is that most commands have more than one key binding. @@ -473,11 +461,8 @@ If view-mode was entered from another buffer, by \\[view-buffer], then \\[View-leave], \\[View-quit] and \\[View-kill-and-leave] will return to that buffer. Entry to view-mode runs the normal hook `view-mode-hook'." - (interactive "P") - (unless (and arg ; Do nothing if already OK. - (if (> (prefix-numeric-value arg) 0) view-mode (not view-mode))) - (if view-mode (view-mode-disable) - (view-mode-enable)))) + :lighter " View" :keymap view-mode-map + (if view-mode (view-mode-enable) (view-mode-disable))) (defun view-mode-enable () "Turn on View mode." -- 2.39.2