From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Emilio Lopes Newsgroups: gmane.emacs.devel Subject: Support for "special" file local variables Date: Tue, 02 Aug 2005 21:53:47 +0200 Organization: private Message-ID: <864uot8s4.fsf@tiscali.de> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1123012550 5059 80.91.229.2 (2 Aug 2005 19:55:50 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 2 Aug 2005 19:55:50 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Aug 02 21:55:48 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1E02px-0006Ok-1W for ged-emacs-devel@m.gmane.org; Tue, 02 Aug 2005 21:54:05 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1E02sf-0008Ir-EK for ged-emacs-devel@m.gmane.org; Tue, 02 Aug 2005 15:56:53 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1E02qp-0007F3-Ii for emacs-devel@gnu.org; Tue, 02 Aug 2005 15:55:00 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1E02qf-00079J-9s for emacs-devel@gnu.org; Tue, 02 Aug 2005 15:54:51 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1E02qd-00077q-GW for emacs-devel@gnu.org; Tue, 02 Aug 2005 15:54:47 -0400 Original-Received: from [213.165.64.20] (helo=mail.gmx.net) by monty-python.gnu.org with smtp (Exim 4.34) id 1E02vU-0007K0-Mh for emacs-devel@gnu.org; Tue, 02 Aug 2005 15:59:48 -0400 Original-Received: (qmail invoked by alias); 02 Aug 2005 19:46:53 -0000 Original-Received: from p62.246.12.147.tisdip.tiscali.de (EHLO jumeirah.tiscali.de) [62.246.12.147] by mail.gmx.net (mp031) with SMTP; 02 Aug 2005 21:46:53 +0200 X-Authenticated: #3737989 Original-To: emacs-devel@gnu.org User-Agent: Emacs Gnus X-Y-GMX-Trusted: 0 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:41440 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:41440 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 * 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)