unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* File local variable name containing ':'
@ 2010-09-02 23:56 Dan Davison
  2010-09-03  7:57 ` Andreas Schwab
  2010-09-03 10:53 ` Stefan Monnier
  0 siblings, 2 replies; 5+ messages in thread
From: Dan Davison @ 2010-09-02 23:56 UTC (permalink / raw)
  To: emacs-devel

I think it isn't possible to use a Local Variables line to set the value
of a variable whose name contains a colon . E.g. something like

# Local Variables:
# var:name: value
# End:

doesn't work because of the colon in var:name.

Assuming I'm not overlooking an easy workaround, it seems that one
possible fix would be to recognise the separator character on-the-fly as
the character following the word "Variables". For what it's worth, I did
have a go at making that change (below). Could this behaviour be changed
or is this a limitation that's here to stay?

Dan

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/files.el b/lisp/files.el
index 3d9dd90..68ba1f0 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -3053,7 +3053,7 @@ If MODE-ONLY is non-nil, all we do is check whether the major mode
 is specified, returning t if it is specified."
   (let ((enable-local-variables
 	 (and local-enable-local-variables enable-local-variables))
-	result)
+	result separator)
     (unless mode-only
       (setq file-local-variables-alist nil)
       (report-errors "Directory-local variables error: %s"
@@ -3066,10 +3066,11 @@ is specified, returning t if it is specified."
 	(search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
 			 'move)
 	(when (let ((case-fold-search t))
-		(search-forward "Local Variables:" nil t))
+		(re-search-forward "Local Variables\\([^ \t\n]\\)" nil t))
+	  (setq separator (match-string 1))
 	  (skip-chars-forward " \t")
-	  ;; suffix is what comes after "local variables:" in its line.
-	  ;; prefix is what comes before "local variables:" in its line.
+	  ;; suffix is what comes after "local variables<SEPARATOR>" in its line.
+	  ;; prefix is what comes before "local variables<SEPARATOR>" in its line.
 	  (let ((suffix
 		 (concat
 		  (regexp-quote (buffer-substring (point)
@@ -3088,7 +3089,7 @@ is specified, returning t if it is specified."
 	      (save-excursion
 		(unless (let ((case-fold-search t))
 			  (re-search-forward
-			   (concat prefix "[ \t]*End:[ \t]*" suffix)
+			   (concat prefix "[ \t]*End" separator "[ \t]*" suffix)
 			   nil t))
                   ;; This used to be an error, but really all it means is
                   ;; that this may simply not be a local-variables section,
@@ -3118,15 +3119,15 @@ is specified, returning t if it is specified."
 		  ;; Find the variable name; strip whitespace.
 		  (skip-chars-forward " \t")
 		  (setq beg (point))
-		  (skip-chars-forward "^:\n")
-		  (if (eolp) (error "Missing colon in local variables entry"))
+		  (skip-chars-forward (concat "^\n" separator))
+		  (if (eolp) (error "Missing separator character in local variables entry"))
 		  (skip-chars-backward " \t")
 		  (let* ((str (buffer-substring beg (point)))
 			 (var (let ((read-circle nil))
 				(read str)))
 			 val)
 		    ;; Read the variable value.
-		    (skip-chars-forward "^:")
+		    (skip-chars-forward (concat "^" separator))
 		    (forward-char 1)
 		    (let ((read-circle nil))
 		      (setq val (read (current-buffer))))
--8<---------------cut here---------------end--------------->8---



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

* Re: File local variable name containing ':'
  2010-09-02 23:56 File local variable name containing ':' Dan Davison
@ 2010-09-03  7:57 ` Andreas Schwab
  2010-09-03 10:53 ` Stefan Monnier
  1 sibling, 0 replies; 5+ messages in thread
From: Andreas Schwab @ 2010-09-03  7:57 UTC (permalink / raw)
  To: Dan Davison; +Cc: emacs-devel

Dan Davison <davison@stats.ox.ac.uk> writes:

> @@ -3088,7 +3089,7 @@ is specified, returning t if it is specified."
>  	      (save-excursion
>  		(unless (let ((case-fold-search t))
>  			  (re-search-forward
> -			   (concat prefix "[ \t]*End:[ \t]*" suffix)
> +			   (concat prefix "[ \t]*End" separator "[ \t]*" suffix)
                                               (regexp-quote separator)

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



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

* Re: File local variable name containing ':'
  2010-09-02 23:56 File local variable name containing ':' Dan Davison
  2010-09-03  7:57 ` Andreas Schwab
@ 2010-09-03 10:53 ` Stefan Monnier
  2010-09-03 14:35   ` Dan Davison
  1 sibling, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2010-09-03 10:53 UTC (permalink / raw)
  To: Dan Davison; +Cc: emacs-devel

> I think it isn't possible to use a Local Variables line to set the value
> of a variable whose name contains a colon . E.g. something like

Indeed, it looks like you're right.

> Assuming I'm not overlooking an easy workaround, it seems that one
> possible fix would be to recognise the separator character on-the-fly as
> the character following the word "Variables".

That makes the check for the presence of file-local variables even
more loose.  I.e. a file that contained "Local Variables" but not "Local
Variables:" will now be considered as containing file-local variables
and will likely generate an error about missing "End" when you try and
open the file.

The current "Local Variables:" pattern is already much too loose in my
opinion, so I'm definitely not going to let it become even more permissive.


        Stefan



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

* Re: File local variable name containing ':'
  2010-09-03 10:53 ` Stefan Monnier
@ 2010-09-03 14:35   ` Dan Davison
  2010-09-03 21:27     ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Davison @ 2010-09-03 14:35 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@IRO.UMontreal.CA> writes:

>> I think it isn't possible to use a Local Variables line to set the value
>> of a variable whose name contains a colon . E.g. something like
>
> Indeed, it looks like you're right.
>
>> Assuming I'm not overlooking an easy workaround, it seems that one
>> possible fix would be to recognise the separator character on-the-fly as
>> the character following the word "Variables".
>
> That makes the check for the presence of file-local variables even
> more loose.  I.e. a file that contained "Local Variables" but not "Local
> Variables:" will now be considered as containing file-local variables
> and will likely generate an error about missing "End" when you try and
> open the file.
>
> The current "Local Variables:" pattern is already much too loose in my
> opinion, so I'm definitely not going to let it become even more permissive.

Fair enough. What about requiring that the separating colon is followed
by whitespace. Is the backwards incompatibility cost too high there? Or
could colons in the variable name be escaped with a backslash?

Dan

>
>
>         Stefan



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

* Re: File local variable name containing ':'
  2010-09-03 14:35   ` Dan Davison
@ 2010-09-03 21:27     ` Stefan Monnier
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2010-09-03 21:27 UTC (permalink / raw)
  To: Dan Davison; +Cc: emacs-devel

> Fair enough. What about requiring that the separating colon is followed
> by whitespace. Is the backwards incompatibility cost too high there?

We could do that.  E.g. if there's only 1 colon, we know what to do, and
if there's more than 1 we can force the separating one to be followed by
something like [[ "(].

> Or could colons in the variable name be escaped with a backslash?

That would be a good simple and reliable option, indeed, since a\:b
already represents the same symbol as a:b in Elisp.


        Stefan



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

end of thread, other threads:[~2010-09-03 21:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-02 23:56 File local variable name containing ':' Dan Davison
2010-09-03  7:57 ` Andreas Schwab
2010-09-03 10:53 ` Stefan Monnier
2010-09-03 14:35   ` Dan Davison
2010-09-03 21:27     ` Stefan Monnier

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