* font-lock-keywords and lines containing comments / quotes
@ 2010-02-26 1:57 Erik Iverson
2010-02-26 15:17 ` Tim Visher
[not found] ` <mailman.1939.1267197484.14305.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 4+ messages in thread
From: Erik Iverson @ 2010-02-26 1:57 UTC (permalink / raw)
To: help-gnu-emacs
Hello,
I am trying to learn things about font-lock-mode, and am needing help
understanding the following behavior. To see what I am confused about, create a
buffer in emacs-lisp mode (or just use *scratch*) and define the following:
;; syntax highlight lines that start with a "*" in the current buffer
(font-lock-add-keywords nil
'(("^\\*\\{1\\}.*" . font-lock-keyword-face)))
Now, with the above defined, paste (or type out to see the effect in action) the
following lines starting with * in the same buffer, which will demonstrate what
I would like to achieve, and what is going wrong...
* this is highlighted, great!
* so is this, until I type a ; comment
* similiar here, until I type a "quote"
As soon as I type the ; or " characters, the previous part of the line becomes
"normal" and the comment or quote appears as it should. I would like for the
initial part of the line to remain highlighted though.
Obviously I am missing something simple(?) here, but I am having a hard time
figuring out how the typical major-modes (e.g., emacs-lisp) handle this case.
Any hints?
Hopefully this was clear! I am using Emacs 23 under Linux.
Best Regards,
Erik Iverson
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: font-lock-keywords and lines containing comments / quotes
2010-02-26 1:57 font-lock-keywords and lines containing comments / quotes Erik Iverson
@ 2010-02-26 15:17 ` Tim Visher
[not found] ` <mailman.1939.1267197484.14305.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 4+ messages in thread
From: Tim Visher @ 2010-02-26 15:17 UTC (permalink / raw)
To: Erik Iverson; +Cc: help-gnu-emacs
Hi Erik,
On Thu, Feb 25, 2010 at 8:57 PM, Erik Iverson <eriki@ccbr.umn.edu> wrote:
> I am trying to learn things about font-lock-mode, and am needing help
> understanding the following behavior. To see what I am confused about,
> create a buffer in emacs-lisp mode (or just use *scratch*) and define the
> following:
>
> ;; syntax highlight lines that start with a "*" in the current buffer
> (font-lock-add-keywords nil
> '(("^\\*\\{1\\}.*" . font-lock-keyword-face)))
>
>
> Now, with the above defined, paste (or type out to see the effect in action)
> the following lines starting with * in the same buffer, which will
> demonstrate what I would like to achieve, and what is going wrong...
>
>
> * this is highlighted, great!
> * so is this, until I type a ; comment
> * similiar here, until I type a "quote"
>
>
> As soon as I type the ; or " characters, the previous part of the line
> becomes "normal" and the comment or quote appears as it should. I would
> like for the initial part of the line to remain highlighted though.
>
> Obviously I am missing something simple(?) here, but I am having a hard time
> figuring out how the typical major-modes (e.g., emacs-lisp) handle this
> case. Any hints?
>
> Hopefully this was clear! I am using Emacs 23 under Linux.
I can't say for sure but this smells pretty strongly of a regex
failure. Lots of stuff in Emacs is keyed off of regexs which can be a
pain because many languages aren't truly regular (take markdown for
instance) and the languages that are would probably be better served
by a state machine.
That being said, have you read the sections in the ELisp reference
manual on Font Lock? `C-h i m elisp RET m font lock basics RET`
should get you there if you haven't. That may shed some more light on
the matter for you.
If you have already read that manual, then I'm afraid I probably can't
be of any more service to you.
Good luck!
--
In Christ,
Timmy V.
http://burningones.com/
http://five.sentenc.es/ - Spend less time on e-mail
^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <mailman.1939.1267197484.14305.help-gnu-emacs@gnu.org>]
* Re: font-lock-keywords and lines containing comments / quotes
[not found] ` <mailman.1939.1267197484.14305.help-gnu-emacs@gnu.org>
@ 2010-02-26 18:41 ` despen
0 siblings, 0 replies; 4+ messages in thread
From: despen @ 2010-02-26 18:41 UTC (permalink / raw)
To: help-gnu-emacs
On Thu, Feb 25, 2010 at 8:57 PM, Erik Iverson <eriki@ccbr.umn.edu> wrote:
> I am trying to learn things about font-lock-mode, and am needing help
> understanding the following behavior. To see what I am confused about,
> create a buffer in emacs-lisp mode (or just use *scratch*) and define the
> following:
>
> ;; syntax highlight lines that start with a "*" in the current buffer
> (font-lock-add-keywords nil
> '(("^\\*\\{1\\}.*" . font-lock-keyword-face)))
>
>
> Now, with the above defined, paste (or type out to see the effect in action)
> the following lines starting with * in the same buffer, which will
> demonstrate what I would like to achieve, and what is going wrong...
>
>
> * this is highlighted, great!
> * so is this, until I type a ; comment
> * similiar here, until I type a "quote"
>
>
> As soon as I type the ; or " characters, the previous part of the line
> becomes "normal" and the comment or quote appears as it should. I would
> like for the initial part of the line to remain highlighted though.
>
> Obviously I am missing something simple(?) here, but I am having a hard time
> figuring out how the typical major-modes (e.g., emacs-lisp) handle this
> case. Any hints?
Look at the description of font-lock-defaults.
When you set it, you want to set KEYWORDS-ONLY to t so that
syntax tables (strings and comments) are ignored.
^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <mailman.1902.1267156792.14305.help-gnu-emacs@gnu.org>]
* Re: font-lock-keywords and lines containing comments / quotes
[not found] <mailman.1902.1267156792.14305.help-gnu-emacs@gnu.org>
@ 2010-02-26 21:51 ` Johan Bockgård
0 siblings, 0 replies; 4+ messages in thread
From: Johan Bockgård @ 2010-02-26 21:51 UTC (permalink / raw)
To: help-gnu-emacs
Erik Iverson <eriki@ccbr.umn.edu> writes:
> ;; syntax highlight lines that start with a "*" in the current buffer
> (font-lock-add-keywords nil
> '(("^\\*\\{1\\}.*" . font-lock-keyword-face)))
The \\{1\\} is not useful.
> As soon as I type the ; or " characters, the previous part of the line
> becomes "normal" and the comment or quote appears as it should. I
> would like for the initial part of the line to remain highlighted
> though.
Use the OVERRIDE element.
(font-lock-add-keywords
nil '(("^\\*.*" 0 font-lock-keyword-face keep)))
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-02-26 21:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-26 1:57 font-lock-keywords and lines containing comments / quotes Erik Iverson
2010-02-26 15:17 ` Tim Visher
[not found] ` <mailman.1939.1267197484.14305.help-gnu-emacs@gnu.org>
2010-02-26 18:41 ` despen
[not found] <mailman.1902.1267156792.14305.help-gnu-emacs@gnu.org>
2010-02-26 21:51 ` Johan Bockgård
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.