aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2010-04-23 12:26:11 -0400
committerStefan Monnier2010-04-23 12:26:11 -0400
commit9ae0c31028f246f77a16f4989d5c63bfbbee4832 (patch)
tree4eec67ea6b8cbfb6c3a9f7eef29239608b09404c
parentbd486b039f9478afaff25e358b9e2c615e39f5c6 (diff)
downloademacs-9ae0c31028f246f77a16f4989d5c63bfbbee4832.tar.gz
emacs-9ae0c31028f246f77a16f4989d5c63bfbbee4832.zip
Provide byte-compiler warnings when set-default a read-only var.
* emacs-lisp/bytecomp.el (byte-compile-set-default): New function. (byte-compile-setq-default): Optimize for the single-var case and don't call byte-compile-form in this case to avoid inf-loop with byte-compile-set-default.
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/emacs-lisp/bytecomp.el40
-rw-r--r--lisp/tool-bar.el31
3 files changed, 46 insertions, 30 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 5b1396a9198..834f8486ea6 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,10 @@
12010-04-23 Stefan Monnier <monnier@iro.umontreal.ca> 12010-04-23 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * emacs-lisp/bytecomp.el (byte-compile-set-default): New function.
4 (byte-compile-setq-default): Optimize for the
5 single-var case and don't call byte-compile-form in this case to avoid
6 inf-loop with byte-compile-set-default.
7
3 * progmodes/compile.el (compilation-start): Abbreviate default directory. 8 * progmodes/compile.el (compilation-start): Abbreviate default directory.
4 9
52010-04-23 Michael Albinus <michael.albinus@gmx.de> 102010-04-23 Michael Albinus <michael.albinus@gmx.de>
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index b593596a526..0c3a7b69798 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -3333,21 +3333,31 @@ If it is nil, then the handler is \"byte-compile-SYMBOL.\""
3333 (setq for-effect nil))) 3333 (setq for-effect nil)))
3334 3334
3335(defun byte-compile-setq-default (form) 3335(defun byte-compile-setq-default (form)
3336 (let ((bytecomp-args (cdr form)) 3336 (setq form (cdr form))
3337 setters) 3337 (if (> (length form) 2)
3338 (while bytecomp-args 3338 (let ((setters ()))
3339 (let ((var (car bytecomp-args))) 3339 (while (consp form)
3340 (and (or (not (symbolp var)) 3340 (push `(setq-default ,(pop form) ,(pop form)) setters))
3341 (byte-compile-const-symbol-p var t)) 3341 (byte-compile-form (cons 'progn (nreverse setters))))
3342 (byte-compile-warning-enabled-p 'constants) 3342 (let ((var (car form)))
3343 (byte-compile-warn 3343 (and (or (not (symbolp var))
3344 "variable assignment to %s `%s'" 3344 (byte-compile-const-symbol-p var t))
3345 (if (symbolp var) "constant" "nonvariable") 3345 (byte-compile-warning-enabled-p 'constants)
3346 (prin1-to-string var))) 3346 (byte-compile-warn
3347 (push (list 'set-default (list 'quote var) (car (cdr bytecomp-args))) 3347 "variable assignment to %s `%s'"
3348 setters)) 3348 (if (symbolp var) "constant" "nonvariable")
3349 (setq bytecomp-args (cdr (cdr bytecomp-args)))) 3349 (prin1-to-string var)))
3350 (byte-compile-form (cons 'progn (nreverse setters))))) 3350 (byte-compile-normal-call `(set-default ',var ,@(cdr form))))))
3351
3352(byte-defop-compiler-1 set-default)
3353(defun byte-compile-set-default (form)
3354 (let ((varexp (car-safe (cdr-safe form))))
3355 (if (eq (car-safe varexp) 'quote)
3356 ;; If the varexp is constant, compile it as a setq-default
3357 ;; so we get more warnings.
3358 (byte-compile-setq-default `(setq-default ,(car-safe (cdr varexp))
3359 ,@(cddr form)))
3360 (byte-compile-normal-call form))))
3351 3361
3352(defun byte-compile-quote (form) 3362(defun byte-compile-quote (form)
3353 (byte-compile-constant (car (cdr form)))) 3363 (byte-compile-constant (car (cdr form))))
diff --git a/lisp/tool-bar.el b/lisp/tool-bar.el
index 18a75437f97..c1fcd530d60 100644
--- a/lisp/tool-bar.el
+++ b/lisp/tool-bar.el
@@ -232,6 +232,7 @@ holds a keymap."
232 submap key) 232 submap key)
233 ;; We'll pick up the last valid entry in the list of keys if 233 ;; We'll pick up the last valid entry in the list of keys if
234 ;; there's more than one. 234 ;; there's more than one.
235 ;; FIXME: Aren't they *all* "valid"?? --Stef
235 (dolist (k keys) 236 (dolist (k keys)
236 ;; We're looking for a binding of the command in a submap of 237 ;; We're looking for a binding of the command in a submap of
237 ;; the menu bar map, so the key sequence must be two or more 238 ;; the menu bar map, so the key sequence must be two or more
@@ -242,24 +243,24 @@ holds a keymap."
242 ;; Last element in the bound key sequence: 243 ;; Last element in the bound key sequence:
243 (kk (aref k (1- (length k))))) 244 (kk (aref k (1- (length k)))))
244 (if (and (keymapp m) 245 (if (and (keymapp m)
245 (symbolp kk)) 246 (symbolp kk)) ;FIXME: Why? --Stef
246 (setq submap m 247 (setq submap m
247 key kk))))) 248 key kk)))))
248 (when (and (symbolp submap) (boundp submap)) 249 (when submap
249 (setq submap (eval submap))) 250 (let ((defn nil))
250 (let ((defn (assq key (cdr submap)))) 251 ;; Here, we're essentially doing a "lookup-key without get_keyelt".
251 (if (eq (cadr defn) 'menu-item) 252 (map-keymap (lambda (k b) (if (eq k key) (setq defn b)))
252 (define-key-after in-map (vector key) 253 submap)
253 (append (cdr defn) (list :image image-exp) props))
254 (setq defn (cdr defn))
255 (define-key-after in-map (vector key) 254 (define-key-after in-map (vector key)
256 (let ((rest (cdr defn))) 255 (if (eq (car defn) 'menu-item)
257 ;; If the rest of the definition starts 256 (append (cdr defn) (list :image image-exp) props)
258 ;; with a list of menu cache info, get rid of that. 257 (let ((rest (cdr defn)))
259 (if (and (consp rest) (consp (car rest))) 258 ;; If the rest of the definition starts
260 (setq rest (cdr rest))) 259 ;; with a list of menu cache info, get rid of that.
261 (append `(menu-item ,(car defn) ,rest) 260 (if (and (consp rest) (consp (car rest)))
262 (list :image image-exp) props))))))) 261 (setq rest (cdr rest)))
262 (append `(menu-item ,(car defn) ,rest)
263 (list :image image-exp) props))))))))
263 264
264;;; Set up some global items. Additions/deletions up for grabs. 265;;; Set up some global items. Additions/deletions up for grabs.
265 266