* perl-mode "::" as word character [patch]
@ 2005-04-30 6:47 Pandora
2005-05-01 16:44 ` Stefan Monnier
0 siblings, 1 reply; 4+ messages in thread
From: Pandora @ 2005-04-30 6:47 UTC (permalink / raw)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Just dropping in for a teeny bit. I was studying font-lock innards the
other day and noticed that the perl-mode font lock does a lot of
wrangling around the '::' sequence. That's what's used in perl to
divide package names from package members. But instead of sticking
\\(::\\sw\\)*s in after every \\sw, I noticed it'd be much simpler just
to consider the double colon (NOT the single colon) to be a \\sw
character. Seems pretty cut and dried, since :: was only introduced to
perl as a namespace separator, and can be wholly considered as if it
were a word character.
Also since my experience has been that print/printf are used like
keywords, but act like functions; they could use some special
highlighting. As for functions in general, both &\\(\\sw+\\) and
\\(\\sw+\\)( match a function name in perl, but perl-mode only
highlights the first expression as a function.
So... I went and made a patch against CVS, in case anyone else wants to
use these three quick little hacks.
Index: lisp/progmodes/perl-mode.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/perl-mode.el,v
retrieving revision 1.56
diff -r1.56 perl-mode.el
207a208
> ;; Fontify print and printf as functions, typically w/o ()
208a210,211
> '("\\<\\(print\\|printf\\)\\>" 1 font-lock-function-name-face)
>
210c213,214
< '("&\\(\\sw+\\(::\\sw+\\)*\\)" 1 font-lock-function-name-face)
- ---
> '("&\\(\\sw+\\)" 1 font-lock-function-name-face)
> '("\\(\\sw+\\)\\s *(" 1 font-lock-function-name-face)
213,214c217,218
< '("[$*]{?\\(\\sw+\\(::\\sw+\\)*\\)" 1 font-lock-variable-name-face)
< '("\\([@%]\\|\\$#\\)\\(\\sw+\\(::\\sw+\\)*\\)"
- ---
> '("[$*]{?\\(\\sw+\\)" 1 font-lock-variable-name-face)
< '("\\([@%]\\|\\$#\\)\\(\\sw+\\(::\\sw+\\)*\\)"
- ---
> '("[$*]{?\\(\\sw+\\)" 1 font-lock-variable-name-face)
> '("\\([@%]\\|\\$#\\)\\(\\sw+\\)"
258a263,264
> ;; Or $PKG::member :: is a word character, really. c.c
> ("\\(::\\)" (1 "w"))
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCcyn2B/meY5RuPPQRAlJeAKCruu9fvqzETQhQQTE9TV70WSTLqgCdHsDL
R1rwSw/KRWeOvYaGIzb9+iM=
=dJBg
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: perl-mode "::" as word character [patch]
2005-04-30 6:47 perl-mode "::" as word character [patch] Pandora
@ 2005-05-01 16:44 ` Stefan Monnier
2005-05-06 1:19 ` Pandora
0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2005-05-01 16:44 UTC (permalink / raw)
Cc: emacs-devel
> Just dropping in for a teeny bit. I was studying font-lock innards the
> other day and noticed that the perl-mode font lock does a lot of
> wrangling around the '::' sequence. That's what's used in perl to
> divide package names from package members. But instead of sticking
> \\(::\\sw\\)*s in after every \\sw, I noticed it'd be much simpler just
> to consider the double colon (NOT the single colon) to be a \\sw
> character. Seems pretty cut and dried, since :: was only introduced to
> perl as a namespace separator, and can be wholly considered as if it
> were a word character.
Word syntax is clearly wrong. Symbol syntax (i.e. "_") OTOH sounds right.
> Also since my experience has been that print/printf are used like
> keywords, but act like functions; they could use some special
> highlighting. As for functions in general, both &\\(\\sw+\\) and
> \\(\\sw+\\)( match a function name in perl, but perl-mode only
> highlights the first expression as a function.
I don't think function calls should be highlighted, only function definitions.
But that's just me.
Could you (re)send a context diff rather than plain diff?
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: perl-mode "::" as word character [patch]
2005-05-01 16:44 ` Stefan Monnier
@ 2005-05-06 1:19 ` Pandora
2005-05-06 3:02 ` Stefan Monnier
0 siblings, 1 reply; 4+ messages in thread
From: Pandora @ 2005-05-06 1:19 UTC (permalink / raw)
Stefan Monnier wrote:
> Word syntax is clearly wrong. Symbol syntax (i.e. "_") OTOH sounds right.
I would be happy to agree. But \\s_ doens't seem to match anything, and
\\sw doesn't match anything designated as ("\\(::\\)" (1 "_")). It only
matches "w". Word syntax may be "wrong" for English, but in perl ':' is
equivalent to A or q or whatever.
> I don't think function calls should be highlighted, only function definitions.
> But that's just me.
I'll go with the precedent, but if it's better without, you can remove
both the 'starting-with-&' and the 'followed-by-a-(' expressions.
They're both pretty equivocably defined as function calls, not function
definitions, in perl.
A more serious concern though, is the foreach construct:
foreach my $var (@list) {...}
That assigns the members of list to variable var one after the other.
My attempt to match 'followed-by-a-(' considers everything left of
(@list) to be a function call. I'm not good enough with emacs regexps
and font-lock to make this exception, so I'll leave my ...( function
highlighting commented out.
"\\(?:\\<foreach\\>\\|\\<for\\>\\)\\s *\\(\\sw+\\)\\s *(" and... then
how to make that /not/ highlighted, while every other
"\\(\\sw+\\)\\s *(" gets highlighted as a function call?
> Could you (re)send a context diff rather than plain diff?
Um, sure.
Index: lisp/progmodes/perl-mode.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/perl-mode.el,v
retrieving revision 1.56
diff -a -u -r1.56 perl-mode.el
--- lisp/progmodes/perl-mode.el 22 Mar 2005 19:43:13 -0000 1.56
+++ lisp/progmodes/perl-mode.el 6 May 2005 01:07:38 -0000
@@ -205,13 +205,18 @@
;;
;; Fontify local and my keywords as types.
'("\\<\\(local\\|my\\)\\>" . font-lock-type-face)
+ ;; Fontify print and printf as functions, typically w/o ()
;;
+ '("\\<\\(print\\|printf\\)\\>" 1 font-lock-function-name-face)
+
;; Fontify function, variable and file name references.
- '("&\\(\\sw+\\(::\\sw+\\)*\\)" 1 font-lock-function-name-face)
+ '("&\\(\\sw+\\)" 1 font-lock-function-name-face)
+;; How to handle foreach $var (...) {} ?
+;; '("\\(\\sw+\\)\\s *(" 1 font-lock-function-name-face)
;; Additionally underline non-scalar variables. Maybe this is a
bad idea.
;;'("[$@%*][#{]?\\(\\sw+\\)" 1 font-lock-variable-name-face)
- '("[$*]{?\\(\\sw+\\(::\\sw+\\)*\\)" 1 font-lock-variable-name-face)
- '("\\([@%]\\|\\$#\\)\\(\\sw+\\(::\\sw+\\)*\\)"
+ '("[$*]{?\\(\\sw+\\)" 1 font-lock-variable-name-face)
+ '("\\([@%]\\|\\$#\\)\\(\\sw+\\)"
(2 (cons font-lock-variable-name-face '(underline))))
'("<\\(\\sw+\\)>" 1 font-lock-constant-face)
;;
@@ -256,6 +261,8 @@
("\\(\\$\\)[{']" (1 ". p"))
;; Handle funny names like $DB'stop.
("\\$ ?{?^?[_a-zA-Z][_a-zA-Z0-9]*\\('\\)[_a-zA-Z]" (1 "_"))
+ ;; Or $PKG::member :: is a word character, really. c.c
+ ("\\(::\\)" (1 "w"))
;; format statements
("^[ \t]*format.*=[ \t]*\\(\n\\)" (1 '(7)))
;; Funny things in sub arg specifications like `sub myfunc ($$)'
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: perl-mode "::" as word character [patch]
2005-05-06 1:19 ` Pandora
@ 2005-05-06 3:02 ` Stefan Monnier
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2005-05-06 3:02 UTC (permalink / raw)
Cc: emacs-devel
>> Word syntax is clearly wrong. Symbol syntax (i.e. "_") OTOH sounds right.
> I would be happy to agree. But \\s_ doesn't seem to match anything, and
It matches any char marked with the _ syntax, which is the syntax to use for
chars which are not word-chars but are allowed as part of symbols.
> \\sw doesn't match anything designated as ("\\(::\\)" (1 "_")).
Of course not. To match a symbol try "\\(\\sw\\|\\s_)+".
> It only matches "w". Word syntax may be "wrong" for English, but in perl
> ':' is equivalent to A or q or whatever.
No, it's not the same thing. Emacs distinguishes words from symbols and
it's quite handy sometimes.
> I'll go with the precedent, but if it's better without, you can remove
> both the 'starting-with-&' and the 'followed-by-a-(' expressions.
> They're both pretty equivocably defined as function calls, not function
> definitions, in perl.
Agreed.
> "\\(?:\\<foreach\\>\\|\\<for\\>\\)\\s *\\(\\sw+\\)\\s *(" and... then
> how to make that /not/ highlighted, while every other
> "\\(\\sw+\\)\\s *(" gets highlighted as a function call?
Aren't there more cases? like
print HANDLE (arg1, arg2) ?
>> Could you (re)send a context diff rather than plain diff?
> Um, sure.
Thank you.
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-05-06 3:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-30 6:47 perl-mode "::" as word character [patch] Pandora
2005-05-01 16:44 ` Stefan Monnier
2005-05-06 1:19 ` Pandora
2005-05-06 3:02 ` Stefan Monnier
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.