aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2010-05-05 22:53:56 -0400
committerStefan Monnier2010-05-05 22:53:56 -0400
commit0c495c215a149245fd00cf26f375b8cfa3977ef6 (patch)
tree4cdd3980aecfba279d62ee24133fc0481060c3d7
parent07e995905de69913667a7a1186b77497ddf820cf (diff)
downloademacs-0c495c215a149245fd00cf26f375b8cfa3977ef6.tar.gz
emacs-0c495c215a149245fd00cf26f375b8cfa3977ef6.zip
Define auto-save-mode with define-minor-mode.
* emacs-lisp/easy-mmode.el (define-minor-mode): Make :variable more flexible. * files.el (auto-save-mode): Use it to define using define-minor-mode.
-rw-r--r--lisp/ChangeLog14
-rw-r--r--lisp/emacs-lisp/easy-mmode.el34
-rw-r--r--lisp/files.el32
3 files changed, 49 insertions, 31 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index d35340beb10..88c41ea84c2 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12010-05-06 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * emacs-lisp/easy-mmode.el (define-minor-mode):
4 Make :variable more flexible.
5 * files.el (auto-save-mode): Use it to define using define-minor-mode.
6
12010-05-05 Juri Linkov <juri@jurta.org> 72010-05-05 Juri Linkov <juri@jurta.org>
2 8
3 Add `slow' and `history' tags to the desktop data. 9 Add `slow' and `history' tags to the desktop data.
@@ -20,8 +26,8 @@
20 (ange-ftp-delete-file): Add FORCE arg. 26 (ange-ftp-delete-file): Add FORCE arg.
21 (ange-ftp-rename-remote-to-remote) 27 (ange-ftp-rename-remote-to-remote)
22 (ange-ftp-rename-local-to-remote, ange-ftp-rename-remote-to-local) 28 (ange-ftp-rename-local-to-remote, ange-ftp-rename-remote-to-local)
23 (ange-ftp-load, ange-ftp-compress, ange-ftp-uncompress): Force 29 (ange-ftp-load, ange-ftp-compress, ange-ftp-uncompress):
24 file deletion. 30 Force file deletion.
25 31
26 * net/tramp-compat.el (tramp-compat-delete-file): New defun. 32 * net/tramp-compat.el (tramp-compat-delete-file): New defun.
27 33
@@ -39,8 +45,8 @@
39 (tramp-fish-handle-make-symbolic-link) 45 (tramp-fish-handle-make-symbolic-link)
40 (tramp-fish-handle-process-file): Use `tramp-compat-delete-file'. 46 (tramp-fish-handle-process-file): Use `tramp-compat-delete-file'.
41 47
42 * net/tramp-ftp.el (tramp-ftp-file-name-handler): Use 48 * net/tramp-ftp.el (tramp-ftp-file-name-handler):
43 `tramp-compat-delete-file'. 49 Use `tramp-compat-delete-file'.
44 50
45 * net/tramp-gvfs.el (tramp-gvfs-handle-delete-file): Add FORCE arg. 51 * net/tramp-gvfs.el (tramp-gvfs-handle-delete-file): Add FORCE arg.
46 (tramp-gvfs-handle-write-region): Use `tramp-compat-delete-file'. 52 (tramp-gvfs-handle-write-region): Use `tramp-compat-delete-file'.
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
index 238f2fa551a..5a21946183e 100644
--- a/lisp/emacs-lisp/easy-mmode.el
+++ b/lisp/emacs-lisp/easy-mmode.el
@@ -117,7 +117,10 @@ BODY contains code to execute each time the mode is activated or deactivated.
117:keymap MAP Same as the KEYMAP argument. 117:keymap MAP Same as the KEYMAP argument.
118:require SYM Same as in `defcustom'. 118:require SYM Same as in `defcustom'.
119:variable PLACE The location (as can be used with `setf') to use instead 119:variable PLACE The location (as can be used with `setf') to use instead
120 of the variable MODE to store the state of the mode. 120 of the variable MODE to store the state of the mode. PLACE
121 can also be of the form (GET . SET) where GET is an expression
122 that returns the current state and SET is a function that takes
123 a new state and sets it.
121 124
122For example, you could write 125For example, you could write
123 (define-minor-mode foo-mode \"If enabled, foo on you!\" 126 (define-minor-mode foo-mode \"If enabled, foo on you!\"
@@ -149,8 +152,9 @@ For example, you could write
149 (type nil) 152 (type nil)
150 (extra-args nil) 153 (extra-args nil)
151 (extra-keywords nil) 154 (extra-keywords nil)
152 (variable nil) 155 (variable nil) ;The PLACE where the state is stored.
153 (modefun mode) 156 (setter nil) ;The function (if any) to set the mode var.
157 (modefun mode) ;The minor mode function name we're defining.
154 (require t) 158 (require t)
155 (hook (intern (concat mode-name "-hook"))) 159 (hook (intern (concat mode-name "-hook")))
156 (hook-on (intern (concat mode-name "-on-hook"))) 160 (hook-on (intern (concat mode-name "-on-hook")))
@@ -171,7 +175,12 @@ For example, you could write
171 (:type (setq type (list :type (pop body)))) 175 (:type (setq type (list :type (pop body))))
172 (:require (setq require (pop body))) 176 (:require (setq require (pop body)))
173 (:keymap (setq keymap (pop body))) 177 (:keymap (setq keymap (pop body)))
174 (:variable (setq variable (setq mode (pop body)))) 178 (:variable (setq variable (pop body))
179 (if (not (functionp (cdr-safe variable)))
180 ;; PLACE is not of the form (GET . SET).
181 (setq mode variable)
182 (setq mode (car variable))
183 (setq setter (cdr variable))))
175 (t (push keyw extra-keywords) (push (pop body) extra-keywords)))) 184 (t (push keyw extra-keywords) (push (pop body) extra-keywords))))
176 185
177 (setq keymap-sym (if (and keymap (symbolp keymap)) keymap 186 (setq keymap-sym (if (and keymap (symbolp keymap)) keymap
@@ -230,7 +239,8 @@ With zero or negative ARG turn mode off.
230 ;; repeat-command still does the toggling correctly. 239 ;; repeat-command still does the toggling correctly.
231 (interactive (list (or current-prefix-arg 'toggle))) 240 (interactive (list (or current-prefix-arg 'toggle)))
232 (let ((,last-message (current-message))) 241 (let ((,last-message (current-message)))
233 (,(if (symbolp mode) 'setq 'setf) ,mode 242 (,@(if setter (list setter)
243 (list (if (symbolp mode) 'setq 'setf) mode))
234 (if (eq arg 'toggle) 244 (if (eq arg 'toggle)
235 (not ,mode) 245 (not ,mode)
236 ;; A nil argument also means ON now. 246 ;; A nil argument also means ON now.
@@ -240,7 +250,8 @@ With zero or negative ARG turn mode off.
240 (run-hooks ',hook (if ,mode ',hook-on ',hook-off)) 250 (run-hooks ',hook (if ,mode ',hook-on ',hook-off))
241 (if (called-interactively-p 'any) 251 (if (called-interactively-p 'any)
242 (progn 252 (progn
243 ,(if globalp `(customize-mark-as-set ',mode)) 253 ,(if (and globalp (symbolp mode))
254 `(customize-mark-as-set ',mode))
244 ;; Avoid overwriting a message shown by the body, 255 ;; Avoid overwriting a message shown by the body,
245 ;; but do overwrite previous messages. 256 ;; but do overwrite previous messages.
246 (unless (and (current-message) 257 (unless (and (current-message)
@@ -265,10 +276,15 @@ With zero or negative ARG turn mode off.
265 (t (error "Invalid keymap %S" ,keymap)))) 276 (t (error "Invalid keymap %S" ,keymap))))
266 ,(format "Keymap for `%s'." mode-name))) 277 ,(format "Keymap for `%s'." mode-name)))
267 278
268 ,(unless variable 279 ,(if (not (symbolp mode))
269 `(add-minor-mode ',mode ',lighter 280 (if (or lighter keymap)
281 (error ":lighter and :keymap unsupported with mode expression %s" mode))
282 `(with-no-warnings
283 (add-minor-mode ',mode ',lighter
270 ,(if keymap keymap-sym 284 ,(if keymap keymap-sym
271 `(if (boundp ',keymap-sym) ,keymap-sym))))))) 285 `(if (boundp ',keymap-sym) ,keymap-sym))
286 nil
287 ,(unless (eq mode modefun) 'modefun)))))))
272 288
273;;; 289;;;
274;;; make global minor mode 290;;; make global minor mode
diff --git a/lisp/files.el b/lisp/files.el
index 138261b64dd..9090f8afc88 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -5150,29 +5150,25 @@ The optional second argument indicates whether to kill internal buffers too."
5150 (kill-buffer-ask buffer))))) 5150 (kill-buffer-ask buffer)))))
5151 5151
5152 5152
5153(defun auto-save-mode (arg) 5153(define-minor-mode auto-save-mode
5154 "Toggle auto-saving of contents of current buffer. 5154 "Toggle auto-saving of contents of current buffer.
5155With prefix argument ARG, turn auto-saving on if positive, else off." 5155With prefix argument ARG, turn auto-saving on if positive, else off."
5156 (interactive "P") 5156 :variable ((and buffer-auto-save-file-name
5157 (setq buffer-auto-save-file-name 5157 ;; If auto-save is off because buffer has shrunk,
5158 (and (if (null arg) 5158 ;; then toggling should turn it on.
5159 (or (not buffer-auto-save-file-name) 5159 (>= buffer-saved-size 0))
5160 ;; If auto-save is off because buffer has shrunk, 5160 . (lambda (val)
5161 ;; then toggling should turn it on. 5161 (setq buffer-auto-save-file-name
5162 (< buffer-saved-size 0)) 5162 (cond
5163 (or (eq arg t) (listp arg) (and (integerp arg) (> arg 0)))) 5163 ((null val) nil)
5164 (if (and buffer-file-name auto-save-visited-file-name 5164 ((and buffer-file-name auto-save-visited-file-name
5165 (not buffer-read-only)) 5165 (not buffer-read-only))
5166 buffer-file-name 5166 buffer-file-name)
5167 (make-auto-save-file-name)))) 5167 (t (make-auto-save-file-name))))))
5168 ;; If -1 was stored here, to temporarily turn off saving, 5168 ;; If -1 was stored here, to temporarily turn off saving,
5169 ;; turn it back on. 5169 ;; turn it back on.
5170 (and (< buffer-saved-size 0) 5170 (and (< buffer-saved-size 0)
5171 (setq buffer-saved-size 0)) 5171 (setq buffer-saved-size 0)))
5172 (if (called-interactively-p 'interactive)
5173 (message "Auto-save %s (in this buffer)"
5174 (if buffer-auto-save-file-name "on" "off")))
5175 buffer-auto-save-file-name)
5176 5172
5177(defun rename-auto-save-file () 5173(defun rename-auto-save-file ()
5178 "Adjust current buffer's auto save file name for current conditions. 5174 "Adjust current buffer's auto save file name for current conditions.