From: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: font-lock-multiline for cc-awk.
Date: Tue, 25 Apr 2006 16:10:33 -0400 [thread overview]
Message-ID: <jwvhd4hbeo9.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <Pine.LNX.3.96.1060425104630.675F-100000@acm.acm> (Alan Mackenzie's message of "Tue, 25 Apr 2006 10:53:07 +0000 (GMT)")
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)
-
-\f
;; 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 @@
\f
(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
next prev parent reply other threads:[~2006-04-25 20:10 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-04-17 0:56 Last steps for pretesting Richard Stallman
2006-04-17 8:01 ` Ramprasad B
2006-04-17 8:37 ` Eli Zaretskii
2006-04-18 1:42 ` Richard Stallman
2006-04-19 3:54 ` Ramprasad B
2006-04-19 15:40 ` Richard Stallman
2006-04-20 5:23 ` Ramprasad B
2006-04-18 17:31 ` Bill Wohler
2006-04-19 17:02 ` Alan Mackenzie
2006-04-19 21:23 ` Stefan Monnier
2006-04-19 21:30 ` David Kastrup
2006-04-20 21:35 ` Stefan Monnier
2006-04-20 21:37 ` David Kastrup
2006-04-20 21:44 ` Stefan Monnier
2006-04-20 21:46 ` David Kastrup
2006-04-20 22:50 ` Alan Mackenzie
2006-04-19 22:43 ` Last steps for pretesting (font-lock-extend-region-function) Alan Mackenzie
2006-04-20 9:13 ` Alan Mackenzie
2006-04-20 17:46 ` Stefan Monnier
2006-04-20 18:12 ` Alan Mackenzie
2006-04-20 20:58 ` Stefan Monnier
2006-04-20 22:40 ` Alan Mackenzie
2006-04-20 23:34 ` Stefan Monnier
2006-04-21 7:58 ` Alan Mackenzie
2006-04-21 12:18 ` Stefan Monnier
2006-04-21 19:51 ` Alan Mackenzie
2006-04-21 22:28 ` Stefan Monnier
2006-04-24 19:28 ` Alan Mackenzie
2006-04-24 21:06 ` Stefan Monnier
2006-04-25 6:21 ` Ralf Angeli
2006-04-25 10:53 ` Alan Mackenzie
2006-04-25 18:37 ` Ralf Angeli
2006-04-25 22:00 ` Alan Mackenzie
2006-04-26 6:14 ` Ralf Angeli
2006-04-25 19:26 ` Stefan Monnier
2006-04-25 20:10 ` Stefan Monnier [this message]
2006-04-26 7:37 ` font-lock-multiline for cc-awk Alan Mackenzie
2006-04-26 13:55 ` Stefan Monnier
2006-04-25 19:23 ` Last steps for pretesting (font-lock-extend-region-function) Stefan Monnier
2006-04-25 20:18 ` Stefan Monnier
2006-04-25 11:33 ` Alan Mackenzie
2006-04-25 11:59 ` David Kastrup
2006-04-25 12:33 ` Stefan Monnier
2006-04-25 14:07 ` Alan Mackenzie
2006-04-25 16:05 ` Stefan Monnier
2006-04-25 16:09 ` Stefan Monnier
2006-04-25 21:52 ` Alan Mackenzie
2006-04-25 21:49 ` Alan Mackenzie
2006-04-26 4:50 ` Stefan Monnier
2006-04-24 21:20 ` Stefan Monnier
2006-04-25 7:45 ` Alan Mackenzie
2006-04-25 12:12 ` Stefan Monnier
2006-04-25 21:15 ` Alan Mackenzie
2006-04-26 4:33 ` Stefan Monnier
2006-04-26 8:30 ` Alan Mackenzie
2006-04-26 13:36 ` Stefan Monnier
2006-04-24 21:33 ` Stefan Monnier
2006-04-25 7:27 ` Alan Mackenzie
2006-04-25 12:03 ` Stefan Monnier
2006-04-25 13:14 ` Alan Mackenzie
2006-04-26 0:22 ` Miles Bader
2006-04-25 4:39 ` Tomas Zerolo
2006-04-25 19:02 ` Ralf Angeli
2006-04-25 19:30 ` Stefan Monnier
2006-04-25 20:12 ` Ralf Angeli
2006-04-25 20:26 ` Stefan Monnier
2006-04-25 20:58 ` Ralf Angeli
2006-04-25 21:11 ` Stefan Monnier
2006-04-25 22:30 ` Alan Mackenzie
2006-04-26 4:25 ` Stefan Monnier
2006-04-26 7:44 ` Alan Mackenzie
2006-04-25 22:16 ` Alan Mackenzie
2006-04-26 4:36 ` Stefan Monnier
2006-04-21 23:14 ` Drew Adams
2006-04-19 22:53 ` Last steps for pretesting (true file names in load-history?) Alan Mackenzie
2006-04-20 1:14 ` Last steps for pretesting Richard Stallman
2006-04-24 17:52 ` Richard Stallman
2006-04-20 10:54 ` Reiner Steib
2006-04-21 0:10 ` Richard Stallman
2006-04-21 5:46 ` David Kastrup
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=jwvhd4hbeo9.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--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.