From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: font-lock-multiline for cc-awk. Date: Tue, 25 Apr 2006 16:10:33 -0400 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 1145995870 29921 80.91.229.2 (25 Apr 2006 20:11:10 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 25 Apr 2006 20:11:10 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Apr 25 22:11:08 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FYTs8-0005uo-Rb for ged-emacs-devel@m.gmane.org; Tue, 25 Apr 2006 22:10:57 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FYTs8-0005Ba-Bv for ged-emacs-devel@m.gmane.org; Tue, 25 Apr 2006 16:10:56 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FYTrv-00059n-Fb for emacs-devel@gnu.org; Tue, 25 Apr 2006 16:10:43 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FYTru-00059X-QT for emacs-devel@gnu.org; Tue, 25 Apr 2006 16:10:43 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FYTru-00059U-JO for emacs-devel@gnu.org; Tue, 25 Apr 2006 16:10:42 -0400 Original-Received: from [132.204.24.67] (helo=mercure.iro.umontreal.ca) by monty-python.gnu.org with esmtp (Exim 4.52) id 1FYTuR-0006Iy-6m for emacs-devel@gnu.org; Tue, 25 Apr 2006 16:13:19 -0400 Original-Received: from hidalgo.iro.umontreal.ca (hidalgo.iro.umontreal.ca [132.204.27.50]) by mercure.iro.umontreal.ca (Postfix) with ESMTP id 7C8652DE901; Tue, 25 Apr 2006 16:10:41 -0400 (EDT) Original-Received: from asado.iro.umontreal.ca (asado.iro.umontreal.ca [132.204.24.84]) by hidalgo.iro.umontreal.ca (Postfix) with ESMTP id 184A1445C; Tue, 25 Apr 2006 16:10:34 -0400 (EDT) Original-Received: by asado.iro.umontreal.ca (Postfix, from userid 20848) id 058C871500; Tue, 25 Apr 2006 16:10:33 -0400 (EDT) Original-To: Alan Mackenzie In-Reply-To: (Alan Mackenzie's message of "Tue, 25 Apr 2006 10:53:07 +0000 (GMT)") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) X-DIRO-MailScanner-Information: Please contact the ISP for more information X-DIRO-MailScanner: Found to be clean X-DIRO-MailScanner-SpamCheck: n'est pas un polluriel, SpamAssassin (score=-2.82, requis 5, autolearn=not spam, ALL_TRUSTED -2.82) X-DIRO-MailScanner-From: monnier@iro.umontreal.ca X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:53410 Archived-At: AFAICT the patch below converts cc-awk to use font-lock-multiline instead of an after-change-function. Stefan --- cc-awk.el 06 Mar 2006 14:26:48 -0500 1.9 +++ cc-awk.el 25 Apr 2006 16:08:37 -0400 @@ -677,7 +677,13 @@ (goto-char (1+ beg)) (or (eobp) (while (search-forward "\"" end t) - (c-put-char-property (1- (point)) 'syntax-table '(1)))))) + (c-put-char-property (1- (point)) 'syntax-table '(1))))) + ;; Make sure that this element will be properly refontified next time + ;; around even if it spans several lines. + (save-excursion + (goto-char beg) + (if (search-forward "\n" end t) + (put-text-property beg end 'font-lock-multiline t)))) (defun c-awk-syntax-tablify-string () ;; Point is at the opening " or _" of a string. Set the syntax-table @@ -759,10 +765,12 @@ ;; (iv) Inside a comment, all syntax-table properties are cleared. ;; ;; This function does hidden buffer changes. - (let (anchor - (anchor-state-/div nil)) ; t means a following / would be a div sign. (c-awk-beginning-of-logical-line) ; ACM 2002/7/21. This is probably redundant. + ;; Redundant if called from font-lock. --Stef (c-clear-char-properties (point) lim 'syntax-table) + (let (anchor + (anchor-state-/div nil) + (linebeg (point))) ; t means a following / would be a div sign. ;; Once round the next loop for each string, regexp, or div sign (while (progn ;; Skip any "harmless" lines before the next tricky one. @@ -776,83 +784,19 @@ (setq anchor-state-/div (if (looking-at "_?\"") (c-awk-syntax-tablify-string) + (if (save-excursion (re-search-backward "\n" linebeg t)) + ;; Whether / is interpreted as a div or not depends on all + ;; the text between linebeg and point, so if something is + ;; changed there, even if it's on another line, we need to + ;; refontify this piece of text. + ;; Note that jit-lock-contextually also takes care of + ;; that, so this is only necessary if we want it to work + ;; without jit-lock-contextually or if we want to avoid + ;; the jit-lock-context-time delay. + (put-text-property linebeg (point) 'font-lock-multiline t)) (c-awk-syntax-tablify-/ anchor anchor-state-/div)))) nil)) - -;; ACM, 2002/07/21: Thoughts: We need an AWK Mode after-change function to set -;; the syntax-table properties even when font-lock isn't enabled, for the -;; subsequent use of movement functions, etc. However, it seems that if font -;; lock _is_ enabled, we can always leave it to do the job. -(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, whichever 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))) - -(defun c-awk-after-change (beg end old-len) -;; This function is called exclusively as an after-change function in -;; AWK Mode. It ensures that the syntax-table properties get set in the -;; changed region. However, if font-lock is enabled, this function does -;; nothing, since an enabled font-lock after-change function will always do -;; this. -;; -;; This function might do hidden buffer changes. - (unless (and (boundp 'font-lock-mode) font-lock-mode) - (save-restriction - (save-excursion - (save-match-data - (setq end (c-awk-end-of-change-region beg end old-len)) - (c-awk-beginning-of-logical-line beg) - (c-save-buffer-state nil ; So that read-only status isn't affected. - ; (e.g. when first loading the buffer) - (c-awk-set-syntax-table-properties 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) - - ;; ACM 2002/9/29. Movement functions, e.g. for C-M-a and C-M-e ;; The following three regexps differ from those earlier on in cc-awk.el in @@ -1011,5 +955,5 @@ (cc-provide 'cc-awk) ; Changed from 'awk-mode, ACM 2002/5/21 -;;; arch-tag: c4836289-3aa4-4a59-9934-9ccc2bacccf3 +;; arch-tag: c4836289-3aa4-4a59-9934-9ccc2bacccf3 ;;; awk-mode.el ends here