emacs-devel
[Top][All Lists]
Advanced

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

Support for "special" file local variables


From: Emilio Lopes
Subject: Support for "special" file local variables
Date: Tue, 02 Aug 2005 21:53:47 +0200
User-agent: Emacs Gnus

The following patch implements support for "special" file local variables,
in the vein of the already existent `Mode' and `Coding'.

These special variables can be a short alias for a "real" file local.  They
can also trigger some special action when the variable is set in the local
variable specifications.

My motivation was to support (for historical reasons) file variable
specifications like

   ; -*- Mode: Scheme; Syntax: Scheme; Package: vm; -*-

without polluting the name space with short-named variables like `syntax'
or `package'.

It's such a simple change that I see no obvious reason why this could not
be added to Emacs.  I'm sure others will find nice applications for this
too.

Do you find this useful?


2005-08-02  Emilio C. Lopes  <address@hidden>

        * files.el (hack-one-local-variable): support "special" file
        local variables.
        (special-local-variables-alist): new user option.


*** orig/lisp/files.el
--- mod/lisp/files.el
***************
*** 473,478 ****
--- 473,494 ----
                 (other :tag "Query" other))
    :group 'find-file)
  
+ (defcustom special-local-variables-alist nil
+   "Alist of local variable names to be handled specially.
+ Each element looks like (VAR-NAME . NEW-VAR).
+ 
+ Whenever VAR-NAME is set to some value in the local variable
+ specifications that value is actually assigned to NEW-VAR.
+ 
+ As a special case, NEW-VAR can be a function.  In this case it
+ will be called with two arguments, the name of the variable and
+ the corresponding value, and should do whatever is necessary to
+ actually accomplish the assignment."
+   :type '(repeat (cons (symbol :tag "Original variable name")
+                      (choice (symbol :tag "New variable name")
+                              (function :tag "Function called to accomplish 
the assignment"))))
+   :group 'find-file)
+ 
  ;; Avoid losing in versions where CLASH_DETECTION is disabled.
  (or (fboundp 'lock-buffer)
      (defalias 'lock-buffer 'ignore))
***************
*** 2469,2475 ****
    "\"Set\" one variable in a local variables spec.
  A few patterns are specified so that any name which matches one
  is considered risky."
!   (cond ((eq var 'mode)
         (funcall (intern (concat (downcase (symbol-name val))
                                  "-mode"))))
        ((eq var 'coding)
--- 2485,2498 ----
    "\"Set\" one variable in a local variables spec.
  A few patterns are specified so that any name which matches one
  is considered risky."
!   (cond ((assq var special-local-variables-alist)
!          (let ((new-var (cdr (assq var special-local-variables-alist))))
!            (if (functionp new-var)
!                (funcall new-var var val)
!              ;; note that there's no check for recursive entries in
!              ;; `special-local-variables-alist'
!              (hack-one-local-variable new-var val))))
!         ((eq var 'mode)
         (funcall (intern (concat (downcase (symbol-name val))
                                  "-mode"))))
        ((eq var 'coding)







reply via email to

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