Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

bug#14089: 24.3; file local variables can't have a colon in their name

0 views
Skip to first unread message

schult...@gmail.com

unread,
Mar 29, 2013, 3:01:45 PM3/29/13
to 14...@debbugs.gnu.org
To reproduce this bug, try to open a file like the attached Org-mode
file. The phrase "Malformed mode-line" will be echoed in the
mini-buffer even though this file uses legal file local variable syntax.

bug-example.org
temporary-file-variables-w-colons.txt

Bastien

unread,
Apr 3, 2013, 8:14:08 AM4/3/13
to schult...@gmail.com, 14...@debbugs.gnu.org
Hi Eric,

here is an updated patch for handling this.

The idea is to allow ":" in mode's names and variables names.
No need to use two `looking-at' in this case I think.

I'll submit the patch to emacs-devel and apply it if it's good.

Thanks,

schult...@gmail.com writes:

> === modified file 'lisp/files.el'
> --- lisp/files.el 2013-03-24 06:42:25 +0000
> +++ lisp/files.el 2013-03-28 23:09:26 +0000
> @@ -3058,7 +3058,11 @@
> (while (and (or (not mode-only)
> (not result))
> (< (point) end))
> - (unless (looking-at "[ \t]*\\([^ \t\n:]+\\)[ \t]*:[ \t]*")
> + ;; The first of these next two regexs handles the
> + ;; case when a variable name includes a ":", such as
> + ;; the `org-babel-default-header-args:R' variable.
> + (unless (or (looking-at "[ \t]*\\([^ \t\n]?+\\)[ \t]*:[ \t]*")
> + (looking-at "[ \t]*\\([^ \t\n:]+\\)[ \t]*:[ \t]*"))
> (message "Malformed mode-line")
> (throw 'malformed-line nil))
> (goto-char (match-end 0))

files.el.patch

Eric Schulte

unread,
Apr 3, 2013, 10:31:13 AM4/3/13
to Bastien, 14...@debbugs.gnu.org
Bastien <b...@altern.org> writes:

> Hi Eric,
>
> here is an updated patch for handling this.
>
> The idea is to allow ":" in mode's names and variables names.
> No need to use two `looking-at' in this case I think.
>
> I'll submit the patch to emacs-devel and apply it if it's good.
>

Fantastic, Thanks.

>
> Thanks,
>
> schult...@gmail.com writes:
>
>> === modified file 'lisp/files.el'
>> --- lisp/files.el 2013-03-24 06:42:25 +0000
>> +++ lisp/files.el 2013-03-28 23:09:26 +0000
>> @@ -3058,7 +3058,11 @@
>> (while (and (or (not mode-only)
>> (not result))
>> (< (point) end))
>> - (unless (looking-at "[ \t]*\\([^ \t\n:]+\\)[ \t]*:[ \t]*")
>> + ;; The first of these next two regexs handles the
>> + ;; case when a variable name includes a ":", such as
>> + ;; the `org-babel-default-header-args:R' variable.
>> + (unless (or (looking-at "[ \t]*\\([^ \t\n]?+\\)[ \t]*:[ \t]*")
>> + (looking-at "[ \t]*\\([^ \t\n:]+\\)[ \t]*:[ \t]*"))
>> (message "Malformed mode-line")
>> (throw 'malformed-line nil))
>> (goto-char (match-end 0))

--
Eric Schulte
http://cs.unm.edu/~eschulte



Stefan Monnier

unread,
Apr 3, 2013, 6:19:15 PM4/3/13
to Bastien, 14...@debbugs.gnu.org, schult...@gmail.com
> The idea is to allow ":" in mode's names and variables names.
> No need to use two `looking-at' in this case I think.

Agreed, except that other than SPC \t and \n e need to disallow ", (),
and ;. Also we read those names in hack-local-variables with things like
skip-chars-forward and that needs to be fixed there as well (probably
using looking-at). And we should share the regexp between the various
places where we match those names.


Stefan



Stefan Monnier

unread,
Apr 13, 2013, 9:01:21 PM4/13/13
to 14089...@debbugs.gnu.org
I installed the patch below which should make it possible to have colons
in local variables.


Stefan


=== modified file 'lisp/files.el'
--- lisp/files.el 2013-04-06 07:41:09 +0000
+++ lisp/files.el 2013-04-14 00:56:39 +0000
@@ -3029,6 +3029,9 @@
(prog1 (memq char '(?! ?\s ?y))
(quit-window t)))))))

+(defconst hack-local-variable-regexp
+ "[ \t]*\\([^][;\"'?()\\ \t\n]+\\)[ \t]*:[ \t]*")
+
(defun hack-local-variables-prop-line (&optional mode-only)
"Return local variables specified in the -*- line.
Returns an alist of elements (VAR . VAL), where VAR is a variable
@@ -3055,11 +3058,11 @@
;; (last ";" is optional).
;; If MODE-ONLY, just check for `mode'.
;; Otherwise, parse the -*- line into the RESULT alist.
- (while (and (or (not mode-only)
- (not result))
- (< (point) end))
- (unless (looking-at "[ \t]*\\([^ \t\n:]+\\)[ \t]*:[ \t]*")
- (message "Malformed mode-line")
+ (while (not (or (and mode-only result)
+ (>= (point) end)))
+ (unless (looking-at hack-local-variable-regexp)
+ (message "Malformed mode-line: %S"
+ (buffer-substring-no-properties (point) end))
(throw 'malformed-line nil))
(goto-char (match-end 0))
;; There used to be a downcase here,
@@ -3211,8 +3214,7 @@
(prefix
(concat "^" (regexp-quote
(buffer-substring (line-beginning-position)
- (match-beginning 0)))))
- beg)
+ (match-beginning 0))))))

(forward-line 1)
(let ((startpos (point))
@@ -3247,18 +3249,16 @@
(forward-line 1))
(goto-char (point-min))

- (while (and (not (eobp))
- (or (not mode-only)
- (not result)))
- ;; 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-backward " \t")
- (let* ((str (buffer-substring beg (point)))
- (var (let ((read-circle nil))
- (read str)))
+ (while (not (or (eobp)
+ (and mode-only result)))
+ ;; Find the variable name;
+ (unless (looking-at hack-local-variable-regexp)
+ (error "Malformed local variable line: %S"
+ (buffer-substring-no-properties
+ (point) (line-end-position))))
+ (goto-char (match-end 1))
+ (let* ((str (match-string 1))
+ (var (intern str))
val val2)
(and (equal (downcase (symbol-name var)) "mode")
(setq var 'mode))




Bastien

unread,
Apr 14, 2013, 2:57:56 AM4/14/13
to Stefan Monnier, 14089...@debbugs.gnu.org
Stefan Monnier <mon...@iro.umontreal.ca> writes:

> I installed the patch below which should make it possible to have colons
> in local variables.

Thanks a lot!

--
Bastien



0 new messages