* lisp/files.el (hack-one-local-variable--obsolete): New function.
authorStefan Monnier <monnier@iro.umontreal.ca>
Thu, 8 Nov 2012 19:50:08 +0000 (14:50 -0500)
committerStefan Monnier <monnier@iro.umontreal.ca>
Thu, 8 Nov 2012 19:50:08 +0000 (14:50 -0500)
(hack-one-local-variable): Use it for obsolete settings.

lisp/ChangeLog
lisp/files.el

index edd3950..b3decbd 100644 (file)
@@ -1,5 +1,8 @@
 2012-11-08  Stefan Monnier  <monnier@iro.umontreal.ca>
 
+       * files.el (hack-one-local-variable--obsolete): New function.
+       (hack-one-local-variable): Use it for obsolete settings.
+
        * subr.el (locate-user-emacs-file): If both old and new name exist, use
        the new name.
 
index 26c5c68..8e8a178 100644 (file)
@@ -3387,30 +3387,39 @@ It is dangerous if either of these conditions are met:
                                (setq ok t)))
                          ok))))))))
 
+(defun hack-one-local-variable--obsolete (var)
+  (let ((o (get var 'byte-obsolete-variable)))
+    (when o
+      (let ((instead (nth 0 o))
+            (since (nth 2 o)))
+        (message "%s is obsolete%s; %s"
+                 var (if since (format " (since %s)" since))
+                 (if (stringp instead) instead
+                   (format "use `%s' instead" instead)))))))
+
 (defun hack-one-local-variable (var val)
   "Set local variable VAR with value VAL.
 If VAR is `mode', call `VAL-mode' as a function unless it's
 already the major mode."
-  (cond ((eq var 'mode)
-        (let ((mode (intern (concat (downcase (symbol-name val))
-                                    "-mode"))))
-          (unless (eq (indirect-function mode)
-                      (indirect-function major-mode))
-            (if (memq mode minor-mode-list)
-                ;; A minor mode must be passed an argument.
-                ;; Otherwise, if the user enables the minor mode in a
-                ;; major mode hook, this would toggle it off.
-                (funcall mode 1)
-              (funcall mode)))))
-       ((eq var 'eval)
-        (save-excursion (eval val)))
-       (t
-         ;; Make sure the string has no text properties.
-         ;; Some text properties can get evaluated in various ways,
-         ;; so it is risky to put them on with a local variable list.
-         (if (stringp val)
-             (set-text-properties 0 (length val) nil val))
-         (set (make-local-variable var) val))))
+  (pcase var
+    (`mode
+     (let ((mode (intern (concat (downcase (symbol-name val))
+                                 "-mode"))))
+       (unless (eq (indirect-function mode)
+                   (indirect-function major-mode))
+         (funcall mode))))
+    (`eval
+     (pcase val
+       (`(add-hook ',hook . ,_) (hack-one-local-variable--obsolete hook)))
+     (save-excursion (eval val)))
+    (_
+     (hack-one-local-variable--obsolete var)
+     ;; Make sure the string has no text properties.
+     ;; Some text properties can get evaluated in various ways,
+     ;; so it is risky to put them on with a local variable list.
+     (if (stringp val)
+         (set-text-properties 0 (length val) nil val))
+     (set (make-local-variable var) val))))
 \f
 ;;; Handling directory-local variables, aka project settings.