summaryrefslogtreecommitdiff
path: root/lisp/progmodes/cc-awk.el
diff options
context:
space:
mode:
authorAlan Mackenzie <acm@muc.de>2022-05-22 16:55:05 +0000
committerAlan Mackenzie <acm@muc.de>2022-05-22 17:00:34 +0000
commit2f68673a712508f70de20f485422c7e01b8ab21b (patch)
tree1cbe449cc8659307fa1149be1e1b6ddb0ed298da /lisp/progmodes/cc-awk.el
parent45694a25948146e860738cb4e01de7e7e9aa91b0 (diff)
downloademacs-2f68673a712508f70de20f485422c7e01b8ab21b.tar.gz
CC Mode: Restore string fence properties at each relevant external entry point
This fixes bug #55230. * lisp/progmodes/cc-defs.el (c-string-fences-set-flag, c-with-string-fences): New variable and macro. * lisp/progmodes/cc-mode.el (c-called-from-text-property-change-p): Add remove-text-properties to the list of accepted functions. (c-clear-string-fences, c-restore-string-fences): Surround the functions' innards with c-save-buffer-state to prevent text property changes causing change functions to be called. (c-before-change, c-after-change, c-font-lock-fontify-region): Replace the explicit calls to c-restore-string-fences and c-clear-string-fences with invocations of the new macro c-with-string-fences. * lisp/progmodes/cc-awk.el (c-awk-extend-and-syntax-tablify-region) (c-awk-end-of-defun) * lisp/progmodes/cc-cmds.el (c-show-syntactic-information) (c-electric-backspace, c-hungry-delete-backwards, c-electric-delete-forward) (c-hungry-delete-forward, c-electric-pound, c-electric-brace) (c-electric-slash, c-electric-star, c-electric-semi&comma, c-electric-colon) (c-electric-lt-gt, c-electric-paren, c-beginning-of-defun, c-end-of-defun) (c-display-defun-name, c-mark-function, c-beginning-of-statement) (c-end-of-statement, c-indent-command, c-indent-exp, c-indent-defun) (c-indent-line-or-region, c-fill-paragraph, c-indent-new-comment-line) (c-context-line-break) * lisp/progmodes/cc-guess.el (c-guess-region-no-install): These are all "boundary" functions to CC Mode. Surround each by c-with-string-fences.
Diffstat (limited to 'lisp/progmodes/cc-awk.el')
-rw-r--r--lisp/progmodes/cc-awk.el118
1 files changed, 61 insertions, 57 deletions
diff --git a/lisp/progmodes/cc-awk.el b/lisp/progmodes/cc-awk.el
index 188d5a8a837..9ea1557391b 100644
--- a/lisp/progmodes/cc-awk.el
+++ b/lisp/progmodes/cc-awk.el
@@ -56,6 +56,8 @@
;; Silence the byte compiler.
(cc-bytecomp-defvar c-new-BEG)
(cc-bytecomp-defvar c-new-END)
+(cc-bytecomp-defun c-restore-string-fences)
+(cc-bytecomp-defun c-clear-string-fences)
;; Some functions in cc-engine that are used below. There's a cyclic
;; dependency so it can't be required here. (Perhaps some functions
@@ -934,7 +936,7 @@
;; It prepares the buffer for font
;; locking, hence must get called before `font-lock-after-change-function'.
;;
- ;; This function is the AWK value of `c-before-font-lock-function'.
+ ;; This function is the AWK value of `c-before-font-lock-functions'.
;; It does hidden buffer changes.
(c-save-buffer-state ()
(setq c-new-END (c-awk-end-of-change-region beg end old-len))
@@ -1109,29 +1111,30 @@ nor helpful.
Note that this function might do hidden buffer changes. See the
comment at the start of cc-engine.el for more info."
(interactive "p")
- (or arg (setq arg 1))
- (save-match-data
- (c-save-buffer-state ; ensures the buffer is writable.
- nil
- (let ((found t)) ; Has the most recent regexp search found b-of-defun?
- (if (>= arg 0)
- ;; Go back one defun each time round the following loop. (For +ve arg)
- (while (and found (> arg 0) (not (eq (point) (point-min))))
- ;; Go back one "candidate" each time round the next loop until one
- ;; is genuinely a beginning-of-defun.
- (while (and (setq found (search-backward-regexp
- "^[^#} \t\n\r]" (point-min) 'stop-at-limit))
- (not (memq (c-awk-get-NL-prop-prev-line) '(?\$ ?\} ?\#)))))
- (setq arg (1- arg)))
- ;; The same for a -ve arg.
- (if (not (eq (point) (point-max))) (forward-char 1))
- (while (and found (< arg 0) (not (eq (point) (point-max)))) ; The same for -ve arg.
- (while (and (setq found (search-forward-regexp
- "^[^#} \t\n\r]" (point-max) 'stop-at-limit))
- (not (memq (c-awk-get-NL-prop-prev-line) '(?\$ ?\} ?\#)))))
- (setq arg (1+ arg)))
- (if found (goto-char (match-beginning 0))))
- (eq arg 0)))))
+ (c-with-string-fences
+ (or arg (setq arg 1))
+ (save-match-data
+ (c-save-buffer-state ; ensures the buffer is writable.
+ nil
+ (let ((found t)) ; Has the most recent regexp search found b-of-defun?
+ (if (>= arg 0)
+ ;; Go back one defun each time round the following loop. (For +ve arg)
+ (while (and found (> arg 0) (not (eq (point) (point-min))))
+ ;; Go back one "candidate" each time round the next loop until one
+ ;; is genuinely a beginning-of-defun.
+ (while (and (setq found (search-backward-regexp
+ "^[^#} \t\n\r]" (point-min) 'stop-at-limit))
+ (not (memq (c-awk-get-NL-prop-prev-line) '(?\$ ?\} ?\#)))))
+ (setq arg (1- arg)))
+ ;; The same for a -ve arg.
+ (if (not (eq (point) (point-max))) (forward-char 1))
+ (while (and found (< arg 0) (not (eq (point) (point-max)))) ; The same for -ve arg.
+ (while (and (setq found (search-forward-regexp
+ "^[^#} \t\n\r]" (point-max) 'stop-at-limit))
+ (not (memq (c-awk-get-NL-prop-prev-line) '(?\$ ?\} ?\#)))))
+ (setq arg (1+ arg)))
+ (if found (goto-char (match-beginning 0))))
+ (eq arg 0))))))
(defun c-awk-forward-awk-pattern ()
;; Point is at the start of an AWK pattern (which may be null) or function
@@ -1187,39 +1190,40 @@ no explicit action; see function `c-awk-beginning-of-defun'.
Note that this function might do hidden buffer changes. See the
comment at the start of cc-engine.el for more info."
(interactive "p")
- (or arg (setq arg 1))
- (save-match-data
- (c-save-buffer-state
- nil
- (let ((start-point (point)) end-point)
- ;; Strategy: (For +ve ARG): If we're not already at a beginning-of-defun,
- ;; move backwards to one.
- ;; Repeat [(i) move forward to end-of-current-defun (see below);
- ;; (ii) If this isn't it, move forward to beginning-of-defun].
- ;; We start counting ARG only when step (i) has passed the original point.
- (when (> arg 0)
- ;; Try to move back to a beginning-of-defun, if not already at one.
- (if (not (c-awk-beginning-of-defun-p))
- (when (not (c-awk-beginning-of-defun 1)) ; No bo-defun before point.
- (goto-char start-point)
- (c-awk-beginning-of-defun -1))) ; if this fails, we're at EOB, tough!
- ;; Now count forward, one defun at a time
- (while (and (not (eobp))
- (c-awk-end-of-defun1)
- (if (> (point) start-point) (setq arg (1- arg)) t)
- (> arg 0)
- (c-awk-beginning-of-defun -1))))
-
- (when (< arg 0)
- (setq end-point start-point)
- (while (and (not (bobp))
- (c-awk-beginning-of-defun 1)
- (if (< (setq end-point (if (bobp) (point)
- (save-excursion (c-awk-end-of-defun1))))
- start-point)
- (setq arg (1+ arg)) t)
- (< arg 0)))
- (goto-char (min start-point end-point)))))))
+ (c-with-string-fences
+ (or arg (setq arg 1))
+ (save-match-data
+ (c-save-buffer-state
+ nil
+ (let ((start-point (point)) end-point)
+ ;; Strategy: (For +ve ARG): If we're not already at a beginning-of-defun,
+ ;; move backwards to one.
+ ;; Repeat [(i) move forward to end-of-current-defun (see below);
+ ;; (ii) If this isn't it, move forward to beginning-of-defun].
+ ;; We start counting ARG only when step (i) has passed the original point.
+ (when (> arg 0)
+ ;; Try to move back to a beginning-of-defun, if not already at one.
+ (if (not (c-awk-beginning-of-defun-p))
+ (when (not (c-awk-beginning-of-defun 1)) ; No bo-defun before point.
+ (goto-char start-point)
+ (c-awk-beginning-of-defun -1))) ; if this fails, we're at EOB, tough!
+ ;; Now count forward, one defun at a time
+ (while (and (not (eobp))
+ (c-awk-end-of-defun1)
+ (if (> (point) start-point) (setq arg (1- arg)) t)
+ (> arg 0)
+ (c-awk-beginning-of-defun -1))))
+
+ (when (< arg 0)
+ (setq end-point start-point)
+ (while (and (not (bobp))
+ (c-awk-beginning-of-defun 1)
+ (if (< (setq end-point (if (bobp) (point)
+ (save-excursion (c-awk-end-of-defun1))))
+ start-point)
+ (setq arg (1+ arg)) t)
+ (< arg 0)))
+ (goto-char (min start-point end-point))))))))
(cc-provide 'cc-awk) ; Changed from 'awk-mode, ACM 2002/5/21