unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* More font-lock keywords for tcl.el
@ 2005-03-30 15:24 Glenn Morris
  2005-03-30 16:20 ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Glenn Morris @ 2005-03-30 15:24 UTC (permalink / raw)




OK to install this extra font-locking in lisp/progmodes/tcl.el?


*** tcl.el	27 Nov 2004 00:07:14 -0000	1.80
--- tcl.el	30 Mar 2005 15:22:11 -0000
***************
*** 371,376 ****
--- 373,393 ----
  Default list includes some TclX keywords.
  Call `tcl-set-font-lock-keywords' after changing this list.")
  
+ (defvar tcl-builtin-list
+   '("after" "append" "array" "bgerror" "binary" "catch" "cd" "clock"
+     "close" "concat" "console" "dde" "encoding" "eof" "exec" "expr"
+     "fblocked" "fconfigure" "fcopy" "file" "fileevent" "flush"
+     "format" "gets" "glob" "history" "incr" "info" "interp" "join"
+     "lappend" "lindex" "linsert" "list" "llength" "load" "lrange"
+     "lreplace" "lsort" "namespace" "open" "package" "pid" "puts" "pwd"
+     "read" "regexp" "registry" "regsub" "rename" "scan" "seek" "set"
+     "socket" "source" "split" "string" "subst" "tell" "time" "trace"
+     "unknown" "unset" "vwait")
+   "List of Tcl commands.  Used only for highlighting.
+ Call `tcl-set-font-lock-keywords' after changing this list.
+ This list excludes those commands already found in `tcl-proc-list' and
+ `tcl-keyword-list'.")
+ 
  (defvar tcl-font-lock-keywords nil
    "Keywords to highlight for Tcl.  See variable `font-lock-keywords'.
  This variable is generally set from `tcl-proc-regexp',
***************
*** 466,471 ****
--- 483,509 ----
  		       "\\(\\s-\\|$\\)")
  	       2 'font-lock-type-face)
  
+          (list (concat "\\(\\s-\\|^\\|\\[\\)"
+ 		       (regexp-opt tcl-builtin-list t)
+ 		       "\\(\\s-\\|$\\|\\]\\)")
+ 	       2 'font-lock-builtin-face)
+ 
+          ;; When variable names are enclosed in {} braces, any
+          ;; character can be used. Otherwise just letters, digits,
+          ;; underscores.  Variable names can be prefixed with any
+          ;; number of "namespace::" qualifiers.  A leading "::" refers
+          ;; to the global namespace.
+          '("\\${\\([^}]+\\)}" 1 font-lock-variable-name-face)
+          '("\\$\\(\\(?:::\\)?\\(?:[[:alnum:]_]+::\\)*[[:alnum:]_]+\\)"
+            1 font-lock-variable-name-face)
+          '("\\(?:\\s-\\|^\\|\\[\\)set\\s-+{\\([^}]+\\)}"
+            1 font-lock-variable-name-face keep)
+          '("\\(?:\\s-\\|^\\|\\[\\)set\\s-+\\(\\(?:::\\)?\
+ \\(?:[[:alnum:]_]+::\\)*[[:alnum:]_]+\\)"
+            1 font-lock-variable-name-face keep)
+ 
+          '("\\\\$" 0 font-lock-warning-face) ; escaped EOL
+ 
  	 ;; Keywords.  Only recognized if surrounded by whitespace.
  	 ;; FIXME consider using "not word or symbol", not
  	 ;; "whitespace".

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

* Re: More font-lock keywords for tcl.el
  2005-03-30 15:24 More font-lock keywords for tcl.el Glenn Morris
@ 2005-03-30 16:20 ` Stefan Monnier
  2005-03-30 17:33   ` Glenn Morris
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2005-03-30 16:20 UTC (permalink / raw)


> OK to install this extra font-locking in lisp/progmodes/tcl.el?

Go for it.  AFAIK there's no maintainer for tcl-mode and I've been the most
"active" maintainer for it in the last few years, but my last use of Tcl
goes back many years.

> + (defvar tcl-builtin-list
> +   '("after" "append" "array" "bgerror" "binary" "catch" "cd" "clock"
> +     "close" "concat" "console" "dde" "encoding" "eof" "exec" "expr"
> +     "fblocked" "fconfigure" "fcopy" "file" "fileevent" "flush"
> +     "format" "gets" "glob" "history" "incr" "info" "interp" "join"
> +     "lappend" "lindex" "linsert" "list" "llength" "load" "lrange"
> +     "lreplace" "lsort" "namespace" "open" "package" "pid" "puts" "pwd"
> +     "read" "regexp" "registry" "regsub" "rename" "scan" "seek" "set"
> +     "socket" "source" "split" "string" "subst" "tell" "time" "trace"
> +     "unknown" "unset" "vwait")

Just skimming through it, I notice "namespace".  Is it really a builtin?
I would've expected it to be a keyword.

> +          (list (concat "\\(\\s-\\|^\\|\\[\\)"
> + 		       (regexp-opt tcl-builtin-list t)
> + 		       "\\(\\s-\\|$\\|\\]\\)")

How 'bout (concat "\\_<" (regexp-opt tcl-builtin-list t) "\\_>") ?

> +          '("\\\\$" 0 font-lock-warning-face) ; escaped EOL

Why warning?  Is it dangerous?  I don't think so.
Also the regexp matched more than escaped EOL, it also matches an escaped
backslash at the end of the line.
I'd rather put a warning face on things like "\\\\[ \t]+$" (although it
should also check to see if the backslash is not escaped).


        Stefan

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

* Re: More font-lock keywords for tcl.el
  2005-03-30 16:20 ` Stefan Monnier
@ 2005-03-30 17:33   ` Glenn Morris
  2005-03-30 22:18     ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Glenn Morris @ 2005-03-30 17:33 UTC (permalink / raw)
  Cc: emacs-devel

Stefan Monnier wrote:

> Just skimming through it, I notice "namespace". Is it really a
> builtin? I would've expected it to be a keyword.

It's a command, if that's what you're asking. (I got this list from
Some-Frighteningly-Thick-Tcl-Book.)

>> +          (list (concat "\\(\\s-\\|^\\|\\[\\)"
>> + 		       (regexp-opt tcl-builtin-list t)
>> + 		       "\\(\\s-\\|$\\|\\]\\)")
>
> How 'bout (concat "\\_<" (regexp-opt tcl-builtin-list t) "\\_>") ?

OK. I used the format I did because it's the same as the existing
stuff in tcl.el.

>> +          '("\\\\$" 0 font-lock-warning-face) ; escaped EOL
>
> Why warning?  Is it dangerous?  I don't think so.

Personally, I like it to stand out (that's no argument, of course!).
I think I was trying to be consistent with sh-script.el.
There, escaped EOLs used to be highlighted in string-face. But that
confused sh-get-indent-info, so I changed it to warning-face.

<http://lists.gnu.org/archive/html/emacs-pretest-bug/2003-09/msg00028.html>

> Also the regexp matched more than escaped EOL, it also matches an
> escaped backslash at the end of the line.

The regexp is also the same as the sh-script.el one.

What's a regexp for "/ at the end of a line, not preceded by an odd
number of other /"?

I tried this monstrosity:

"\\(?:[^\\\\]\\|\\(?:\\\\\\\\\\)+\\)\\(\\\\\\)$"

but it also matches \\\\ (I don't see why).

I can just leave this part out, I'm not especially bothered.
But sh-script should at least be corrected, I guess.

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

* Re: More font-lock keywords for tcl.el
  2005-03-30 17:33   ` Glenn Morris
@ 2005-03-30 22:18     ` Stefan Monnier
  2005-03-31 19:32       ` Glenn Morris
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2005-03-30 22:18 UTC (permalink / raw)


>> Just skimming through it, I notice "namespace".  Is it really a
>> builtin? I would've expected it to be a keyword.

> It's a command, if that's what you're asking. (I got this list from
> Some-Frighteningly-Thick-Tcl-Book.)

Well, your patch distinguishes between tcl-keyword-list and
tcl-builtin-list, so is `namespace' more like `append' or more like `if'?
To me it feels more like an `if', in that it seems to be part of the syntax
rather than one of a set of builtin functions.  But I honestly have no idea
what was your intention behind the separation keyword-vs-builtin.

>>> +          (list (concat "\\(\\s-\\|^\\|\\[\\)"
>>> + 		       (regexp-opt tcl-builtin-list t)
>>> + 		       "\\(\\s-\\|$\\|\\]\\)")
>> 
>> How 'bout (concat "\\_<" (regexp-opt tcl-builtin-list t) "\\_>") ?

> OK. I used the format I did because it's the same as the existing
> stuff in tcl.el.

I know, but I think the other one should be changed as well.  Except that in
neither case do I know whether my suggestion is really the right idea.
Maybe it breaks some hilighting, so please check it.

>>> +          '("\\\\$" 0 font-lock-warning-face) ; escaped EOL
>> Why warning?  Is it dangerous?  I don't think so.
> Personally, I like it to stand out (that's no argument, of course!).

Well, you might know better than I.  I just seem to remember using such
escaped-newlines fairly often in my Tcl code.  But maybe I was just a lousy
Tcl coder.

> I think I was trying to be consistent with sh-script.el.

I'm not sure sh-script's use of warning-face is such a hot idea either.

> There, escaped EOLs used to be highlighted in string-face. But that
> confused sh-get-indent-info, so I changed it to warning-face.

Yes, I remember that.

>> Also the regexp matched more than escaped EOL, it also matches an
>> escaped backslash at the end of the line.

> What's a regexp for "/ at the end of a line, not preceded by an odd
> number of other /"?

> I tried this monstrosity:

> "\\(?:[^\\\\]\\|\\(?:\\\\\\\\\\)+\\)\\(\\\\\\)$"

> but it also matches \\\\ (I don't see why).

Because it matches just the last 3 backslashes.
You have to use something like

  "\\(^\\|[^\\]\\)\\(\\\\\\\\\\)*\\)\\(\\\\\\)$"

see for example comment-start-skip in emacs-lisp-mode.  You can also
check for escaped backslashes in the "face" part rather than in the "regexp"
part of the font-lock-keyword.

> But sh-script should at least be corrected, I guess.

Probably; patches welcome,


        Stefan

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

* Re: More font-lock keywords for tcl.el
  2005-03-30 22:18     ` Stefan Monnier
@ 2005-03-31 19:32       ` Glenn Morris
  2005-03-31 20:36         ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Glenn Morris @ 2005-03-31 19:32 UTC (permalink / raw)
  Cc: emacs-devel

Stefan Monnier wrote:

> Well, your patch distinguishes between tcl-keyword-list and
> tcl-builtin-list, so is `namespace' more like `append' or more like
> `if'? To me it feels more like an `if', in that it seems to be part
> of the syntax rather than one of a set of builtin functions.

It seems it can be used in a similar fashion to "proc", eg

namespace eval foo {
   ... do stuff ...
}

or like a simple command:

namespace import foo::*

so IMO it could be either a builtin or keyword. I slightly prefer the
former, but don't have an especially strong opinion.

> But I honestly have no idea what was your intention behind the
> separation keyword-vs-builtin.

No particularly deep intention (as you might guess!). Partly to keep
the new stuff separate, partly that font-lock-builtin-face is not
otherwise used in tcl.el. Just seemed to make sense to me to use
builtin for these new ones.

> I know, but I think the other one should be changed as well. Except
> that in neither case do I know whether my suggestion is really the
> right idea. Maybe it breaks some hilighting, so please check it.

OK.

>>>> +          '("\\\\$" 0 font-lock-warning-face) ; escaped EOL

With regards to this (separate from the "get the right regexp" issue),
it can either:

i)  not be highlighted
ii) be highlighted in some other face. keyword or builtin (?) seem to be
the only non-obviously-wrong faces left.

I have no strong preference as to what Emacs should do. Personally, I
like such things strongly highlighted.

AFAICS, the situation for this is exactly the same in sh-script and
tcl, so the solution ought to be the same.

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

* Re: More font-lock keywords for tcl.el
  2005-03-31 19:32       ` Glenn Morris
@ 2005-03-31 20:36         ` Stefan Monnier
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2005-03-31 20:36 UTC (permalink / raw)


>> Well, your patch distinguishes between tcl-keyword-list and
>> tcl-builtin-list, so is `namespace' more like `append' or more like
>> `if'? To me it feels more like an `if', in that it seems to be part
>> of the syntax rather than one of a set of builtin functions.
> It seems it can be used in a similar fashion to "proc", eg
>    namespace eval foo {
>       ... do stuff ...
>    }
> or like a simple command:
>    namespace import foo::*
> so IMO it could be either a builtin or keyword. I slightly prefer the
> former, but don't have an especially strong opinion.

I have no opinion at all, I was just asking because it seemed odd.
As mentioned originally, feel free to install whatever you feel is right.

> ii) be highlighted in some other face. keyword or builtin (?) seem to be
> the only non-obviously-wrong faces left.

There's no reason to restrict oneself to font-lock*-face faces.
It might be better to use `defface' to create a new face (which could just
inherit from font-lock-warning-face) so users who feel that \ shouldn't be
so "in your face" can change it without changing font-lock-warning-face.


        Stefan

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

end of thread, other threads:[~2005-03-31 20:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-30 15:24 More font-lock keywords for tcl.el Glenn Morris
2005-03-30 16:20 ` Stefan Monnier
2005-03-30 17:33   ` Glenn Morris
2005-03-30 22:18     ` Stefan Monnier
2005-03-31 19:32       ` Glenn Morris
2005-03-31 20:36         ` 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).