unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Emilio Lopes <eclig@gmx.net>
Subject: Support for "special" file local variables
Date: Tue, 02 Aug 2005 21:53:47 +0200	[thread overview]
Message-ID: <864uot8s4.fsf@tiscali.de> (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)

             reply	other threads:[~2005-08-02 19:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-02 19:53 Emilio Lopes [this message]
2005-08-04 20:46 ` Support for "special" file local variables Richard M. Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=864uot8s4.fsf@tiscali.de \
    --to=eclig@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).