From: Alan Mackenzie <acm@muc.de>
Cc: emacs-devel@gnu.org, bug-cc-mode@gnu.org
Subject: Re: [sigra@home.se: C++-mode: Syntax highlighting: wrong color for function identifier depending on the kind of whitespace that follows]
Date: Thu, 10 Mar 2005 22:42:53 +0000 (GMT) [thread overview]
Message-ID: <Pine.LNX.3.96.1050310215812.357E-100000@acm.acm> (raw)
In-Reply-To: <jwv8y4vp6tu.fsf-monnier+emacs@gnu.org>
On Thu, 10 Mar 2005, Stefan Monnier wrote:
>>> You may be right, but I'd like to see your code first, to see how easy and
>>> robust it is to use your hook.
>> I re-posted my tentative 2002 patch here last night.
>Read again: I said "use" not "define".
>I.e. I don't want to see the font-lock side of the code, but the awk-mode or
>c++-mode side of it. Most importantly, I'd like to see some code that would
>solve the problem at hand (see subject) using your new hook.
Sorry, I didn't quite understand what you were asking for. I hope the
following will do. I can't produce any working c-mode code for this in a
hurry. But here is the stuff from cc-awk.el. It has the functionality
to fit the hook I'd proposed, but not the same interface.
What it does is to expand the region in an AWK buffer to be
after-change-font-locked from a physical line to the containing
@dfn{logical line}, the maximal sequence of physical lines joined by
escaped newlines. It does the Right Thing when a backslash at an EOL
gets inserted or deleted.
(defun c-awk-beginning-of-logical-line (&optional pos)
;; Go back to the start of the (apparent) current line (or the start of the
;; line containing POS), returning the buffer position of that point. I.e.,
;; go back to the last line which doesn't have an escaped EOL before it.
;;
;; This is guaranteed to be "safe" for syntactic analysis, i.e. outwith any
;; comment, string or regexp. IT MAY WELL BE that this function should not be
;; executed on a narrowed buffer.
;;
;; This function might do hidden buffer changes.
(if pos (goto-char pos))
(forward-line 0)
(while (and (> (point) (point-min))
(eq (char-before (1- (point))) ?\\))
(forward-line -1))
(point))
(defun c-awk-end-of-logical-line (&optional pos)
;; Go forward to the end of the (apparent) current logical line (or the end of
;; the line containing POS), returning the buffer position of that point. I.e.,
;; go to the end of the next line which doesn't have an escaped EOL.
;;
;; This is guaranteed to be "safe" for syntactic analysis, i.e. outwith any
;; comment, string or regexp. IT MAY WELL BE that this function should not be
;; executed on a narrowed buffer.
;;
;; This function might do hidden buffer changes.
(if pos (goto-char pos))
(end-of-line)
(while (and (< (point) (point-max))
(eq (char-before) ?\\))
(end-of-line 2))
(point))
(defvar c-awk-old-EOLL 0)
(make-variable-buffer-local 'c-awk-old-EOLL)
;; End of logical line following the region which is about to be changed. Set
;; in c-awk-before-change and used in c-awk-after-change.
(defun c-awk-before-change (beg end)
;; This function is called exclusively from the before-change-functions hook.
;; It does two things: Finds the end of the (logical) line on which END lies,
;; and clears c-awk-NL-prop text properties from this point onwards.
;;
;; This function might do hidden buffer changes.
(save-restriction
(save-excursion
(setq c-awk-old-EOLL (c-awk-end-of-logical-line end))
(c-save-buffer-state nil
(c-awk-clear-NL-props end (point-max))))))
(defun c-awk-end-of-change-region (beg end old-len)
;; Find the end of the region which needs to be font-locked after a change.
;; This is the end of the logical line on which the change happened, either
;; as it was before the change, or as it is now, which ever is later.
;; N.B. point is left undefined.
;;
;; This function might do hidden buffer changes.
(max (+ (- c-awk-old-EOLL old-len) (- end beg))
(c-awk-end-of-logical-line end)))
;; ACM 2002/5/25. When font-locking is invoked by a buffer change, the region
;; specified by the font-lock after-change function must be expanded to
;; include ALL of any string or regexp within the region. The simplest way to
;; do this in practice is to use the beginning/end-of-logical-line functions.
;; Don't overlook the possibility of the buffer change being the "recapturing"
;; of a previously escaped newline.
(defmacro c-awk-advise-fl-for-awk-region (function)
`(defadvice ,function (before get-awk-region activate)
;; When font-locking an AWK Mode buffer, make sure that any string/regexp is
;; completely font-locked.
(when (eq major-mode 'awk-mode)
(save-excursion
(ad-set-arg 1 (c-awk-end-of-change-region
(ad-get-arg 0) ; beg
(ad-get-arg 1) ; end
(ad-get-arg 2))) ; old-len
(ad-set-arg 0 (c-awk-beginning-of-logical-line (ad-get-arg 0)))))))
(c-awk-advise-fl-for-awk-region font-lock-after-change-function)
(c-awk-advise-fl-for-awk-region jit-lock-after-change)
(c-awk-advise-fl-for-awk-region lazy-lock-defer-rest-after-change)
(c-awk-advise-fl-for-awk-region lazy-lock-defer-line-after-change)
>> I think this putting of warning-face on unmatched quotes would be a good
>> idea generally.
>It would help if you actually explained what you're talking about.
>Not everyone uses awk-mode.
I'll try; I'm not doing very well at explaining at the moment. Open a
new AWK mode buffer with font locking enabled: Start by entering a
string:
"string
At this point, the opening quote has font-lock-warning-face, giving the
user a constant niggling reminder to close the string at some point; the
remainder of the text has font-lock-string-face. Use escaped NLs to
continue the string thus:
"string\
on several\
lines.
The entire string still has string-face, and the opening quote still has
warning-face. Finally, type the closing quote:
"string\
on several\
lines."
This last action now causes the opening quote to be refonted with
string-face.
> Stefan
--
Alan Mackenzie (Munich, Germany)
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
next prev parent reply other threads:[~2005-03-10 22:42 UTC|newest]
Thread overview: 103+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <E1D94Wo-0006AP-W2@fencepost.gnu.org>
2005-03-09 21:18 ` [sigra@home.se: C++-mode: Syntax highlighting: wrong color for function identifier depending on the kind of whitespace that follows] Alan Mackenzie
2005-03-09 22:35 ` Stefan Monnier
2005-03-10 8:00 ` Alan Mackenzie
2005-03-10 13:01 ` Stefan Monnier
2005-03-10 15:16 ` D. R. E. Moonfire
2005-03-10 17:01 ` Stefan Monnier
2005-03-10 20:09 ` Alan Mackenzie
2005-03-10 20:53 ` Stefan Monnier
2005-03-10 22:42 ` Alan Mackenzie [this message]
2005-03-11 20:28 ` Richard Stallman
2005-03-11 1:48 ` Richard Stallman
2005-03-11 19:43 ` Alan Mackenzie
2005-03-10 22:13 ` Martin Stjernholm
2005-03-10 22:59 ` Stefan Monnier
2005-03-11 20:27 ` Richard Stallman
2005-03-13 16:19 ` Martin Stjernholm
2005-03-14 1:07 ` Stefan Monnier
2005-03-19 22:23 ` Martin Stjernholm
2005-03-19 22:30 ` Stefan Monnier
2005-03-11 1:47 ` Richard Stallman
2005-03-11 4:47 ` Stefan Monnier
2005-03-12 0:56 ` Richard Stallman
2005-03-12 1:00 ` Stefan Monnier
2005-03-13 15:30 ` Richard Stallman
2005-03-11 1:46 ` Richard Stallman
2005-03-11 1:46 ` Richard Stallman
2006-02-12 13:06 ` Ralf Angeli
2006-02-12 16:20 ` Stefan Monnier
2006-02-12 22:58 ` Ralf Angeli
2006-02-13 22:10 ` Stefan Monnier
2006-02-14 7:53 ` martin rudalics
2006-02-14 19:00 ` Stefan Monnier
2006-02-14 20:13 ` martin rudalics
2006-02-14 21:08 ` Stefan Monnier
2006-02-15 10:17 ` martin rudalics
2006-02-15 10:38 ` Ralf Angeli
2006-02-15 14:20 ` martin rudalics
2006-02-15 14:56 ` Ralf Angeli
2006-02-15 16:40 ` martin rudalics
2006-02-15 17:03 ` Ralf Angeli
2006-02-16 11:10 ` Alan Mackenzie
2006-02-16 11:54 ` Vivek Dasmohapatra
2006-02-16 15:21 ` Stefan Monnier
2006-02-16 23:28 ` David Kastrup
2006-02-17 14:19 ` Stefan Monnier
2006-02-16 17:21 ` martin rudalics
2006-02-15 20:44 ` Alan Mackenzie
2006-02-16 0:40 ` Stefan Monnier
2006-02-15 20:56 ` Alan Mackenzie
2006-02-16 8:56 ` martin rudalics
2006-02-15 20:13 ` Alan Mackenzie
2006-02-16 9:02 ` martin rudalics
2006-02-14 8:18 ` Werner LEMBERG
2006-02-14 8:49 ` Ralf Angeli
2006-02-14 19:05 ` Stefan Monnier
2006-02-14 21:12 ` Ralf Angeli
2006-02-15 13:35 ` Stefan Monnier
2006-02-15 14:05 ` Ralf Angeli
2006-02-15 14:21 ` Ralf Angeli
2006-02-15 20:33 ` Alan Mackenzie
2006-02-15 21:13 ` Stefan Monnier
2006-02-15 21:59 ` Alan Mackenzie
2006-02-16 14:59 ` Kim F. Storm
2006-02-16 16:37 ` Stefan Monnier
2006-02-15 19:07 ` Alan Mackenzie
2006-02-15 21:42 ` Ralf Angeli
2006-02-16 11:20 ` Alan Mackenzie
2006-02-16 11:54 ` Ralf Angeli
2006-02-16 15:12 ` Alan Mackenzie
2006-02-17 7:56 ` martin rudalics
2006-02-17 11:32 ` Ralf Angeli
2006-02-17 13:22 ` martin rudalics
2006-02-17 13:33 ` Ralf Angeli
2006-02-16 16:32 ` Stefan Monnier
2006-02-16 0:38 ` Stefan Monnier
2006-02-16 9:51 ` Alan Mackenzie
2006-02-16 16:27 ` Stefan Monnier
2006-02-17 7:48 ` martin rudalics
2006-02-17 14:36 ` Stefan Monnier
2006-02-16 18:46 ` martin rudalics
2006-02-16 9:09 ` martin rudalics
2006-02-13 4:40 ` Richard M. Stallman
2006-02-13 5:25 ` Stefan Monnier
2006-02-14 0:39 ` Richard M. Stallman
2006-03-14 19:23 ` Alan Mackenzie
2006-03-14 22:11 ` Stefan Monnier
2006-03-15 8:52 ` martin rudalics
2006-03-15 9:02 ` Ralf Angeli
2006-03-15 10:22 ` Stefan Monnier
2006-03-15 11:40 ` Alan Mackenzie
2006-03-15 16:16 ` Stefan Monnier
2006-03-15 20:20 ` Richard Stallman
2006-03-20 8:16 ` font-lock-extend-region (was: [sigra@home.se: C++-mode: Syntax highlighting: wrong color for function identifier depending on the kind of whitespace that follows]) Stefan Monnier
2006-03-20 13:01 ` Alan Mackenzie
2006-03-20 17:18 ` font-lock-extend-region Stefan Monnier
2006-03-21 16:05 ` font-lock-extend-region Alan Mackenzie
2006-03-21 21:32 ` font-lock-extend-region Stefan Monnier
2006-03-23 15:23 ` font-lock-extend-region Alan Mackenzie
2006-03-23 16:18 ` font-lock-extend-region Stefan Monnier
2006-02-15 19:34 ` [sigra@home.se: C++-mode: Syntax highlighting: wrong color for function identifier depending on the kind of whitespace that follows] Alan Mackenzie
2006-02-16 9:07 ` Ralf Angeli
2006-02-16 9:07 ` martin rudalics
[not found] <E1CsBPC-0004xn-8P@fencepost.gnu.org>
2005-02-19 0:03 ` Martin Stjernholm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.3.96.1050310215812.357E-100000@acm.acm \
--to=acm@muc.de \
--cc=bug-cc-mode@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.