unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Support for "special" file local variables
@ 2005-08-02 19:53 Emilio Lopes
  2005-08-04 20:46 ` Richard M. Stallman
  0 siblings, 1 reply; 2+ messages in thread
From: Emilio Lopes @ 2005-08-02 19:53 UTC (permalink / raw)


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  <eclig@gmx.net>

	* 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)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Support for "special" file local variables
  2005-08-02 19:53 Support for "special" file local variables Emilio Lopes
@ 2005-08-04 20:46 ` Richard M. Stallman
  0 siblings, 0 replies; 2+ messages in thread
From: Richard M. Stallman @ 2005-08-04 20:46 UTC (permalink / raw)
  Cc: emacs-devel

It seems like a good idea.  However, special-local-variables-alist
should not be customizable; it is not for users to set.
Also, it has to be marked as a risky local variable.

But this shouldn't be installed now; it should wait for after the
release.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-08-04 20:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-02 19:53 Support for "special" file local variables Emilio Lopes
2005-08-04 20:46 ` Richard M. Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).