From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.cc-mode.general,gmane.emacs.devel 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) Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: sea.gmane.org 1110496554 18165 80.91.229.2 (10 Mar 2005 23:15:54 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 10 Mar 2005 23:15:54 +0000 (UTC) Cc: emacs-devel@gnu.org, bug-cc-mode@gnu.org Original-X-From: cc-mode-help-admin@lists.sourceforge.net Fri Mar 11 00:15:51 2005 Original-Received: from lists-outbound.sourceforge.net ([66.35.250.225]) by ciao.gmane.org with esmtp (Exim 4.43) id 1D9WmB-0004dg-Qo for sf-cc-mode-help@m.gmane.org; Fri, 11 Mar 2005 00:09:09 +0100 Original-Received: from projects.sourceforge.net (sc8-sf-list1-b.sourceforge.net [10.3.1.7]) by sc8-sf-spam1.sourceforge.net (Postfix) with ESMTP id 4AE3489DB7; Thu, 10 Mar 2005 15:09:05 -0800 (PST) Original-Received: from sc8-sf-mx1-b.sourceforge.net ([10.3.1.11] helo=sc8-sf-mx1.sourceforge.net) by sc8-sf-list1.sourceforge.net with esmtp (Exim 4.30) id 1D9Wm2-0002qb-Hi for cc-mode-help@lists.sourceforge.net; Thu, 10 Mar 2005 15:08:58 -0800 Original-Received: from fencepost.gnu.org ([199.232.76.164]) by sc8-sf-mx1.sourceforge.net with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.41) id 1D9Wm1-0005IQ-7Q for cc-mode-help@lists.sourceforge.net; Thu, 10 Mar 2005 15:08:58 -0800 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by fencepost.gnu.org with esmtp (Exim 4.34) id 1D9Wlv-0007qO-JR for bug-cc-mode@gnu.org; Thu, 10 Mar 2005 18:08:51 -0500 Original-Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.34) id 1D9Wlq-0006m8-TJ for bug-cc-mode@gnu.org; Thu, 10 Mar 2005 18:08:48 -0500 Original-Received: from [193.149.49.134] (helo=acm.acm) by monty-python.gnu.org with esmtp (Exim 4.34) id 1D9Wln-0006ke-4X; Thu, 10 Mar 2005 18:08:46 -0500 Original-Received: from localhost (root@localhost) by acm.acm (8.8.8/8.8.8) with SMTP id WAA00522; Thu, 10 Mar 2005 22:42:54 GMT X-Sender: root@acm.acm Original-To: Stefan Monnier In-Reply-To: X-Spam-Status: No, hits=-1.5 required=5.0 tests=EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT,RCVD_IN_ORBS, REPLY_WITH_QUOTES,USER_AGENT_PINE version=2.55 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp) X-Spam-Score: 1.0 (+) X-Spam-Report: Spam Filtering performed by sourceforge.net. See http://spamassassin.org/tag/ for more details. Report problems to http://sf.net/tracker/?func=add&group_id=1&atid=200001 1.0 FORGED_RCVD_HELO Received: contains a forged HELO Original-Sender: cc-mode-help-admin@lists.sourceforge.net Errors-To: cc-mode-help-admin@lists.sourceforge.net X-BeenThere: cc-mode-help@lists.sourceforge.net X-Mailman-Version: 2.0.9-sf.net Precedence: bulk List-Unsubscribe: , List-Id: Bug reports, feature requests, and general talk about CC Mode. List-Post: List-Help: List-Subscribe: , List-Archive: X-Original-Date: Thu, 10 Mar 2005 22:42:53 +0000 (GMT) X-MailScanner-From: cc-mode-help-admin@lists.sourceforge.net X-MailScanner-To: sf-cc-mode-help@m.gmane.org Xref: news.gmane.org gmane.emacs.cc-mode.general:2280 gmane.emacs.devel:34439 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:34439 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