From: Zhang Haijun <ccsmile2008@outlook.com>
To: Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: "35316@debbugs.gnu.org" <35316@debbugs.gnu.org>
Subject: bug#35316: 26.2; Emacs lags in c++-mode buffer when editing with iedit-mode on
Date: Thu, 9 May 2019 13:23:42 +0000 [thread overview]
Message-ID: <PS1PR06MB2759800EBE7BE0A65BF95F2DA8330@PS1PR06MB2759.apcprd06.prod.outlook.com> (raw)
In-Reply-To: <PS1PR06MB2759F95E6DC6F6E5DED1AE05A8200@PS1PR06MB2759.apcprd06.prod.outlook.com>
I find that I had too little time editing c/c++ source files recently. Because our project switched to golang.
So I didn’t test this patch too much. I just applied the patch and tested iedit with some c++ files and the lag disappeared.
> 在 2019年4月20日,上午10:44,张海君 <ccsmile2008@outlook.com> 写道:
>
> I will try it for some days and give feedback.
>
>> 在 2019年4月20日,上午12:20,Stefan Monnier <monnier@IRO.UMontreal.CA> 写道:
>>
>>> Reproducing steps:
>>> 1. emacs -Q
>>> 2. Eval code: (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/“))
>>> 3. install the package iedit (version from melpa)
>>> 4. open the attachment c++ file, and goto line 262 and column 17. cursor
>>> will be on word “subsession"
>>> 5. M-x narrow-to-defun
>>> 6. M-x iedit-mode
>>> 7. M-x widen
>>> 8. You will see the lag when inputting chars.
>>
>> This seems to be a good use case for my syntax-propertize patch.
>> I just tried it on your test case and while there is still a slight slow
>> down, it seemed to be much less problematic.
>>
>> BEWARE: it likely introduces bugs.
>>
>>
>> Stefan
>>
>>
>> diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
>> index 49268c4482..31f5ecdfdb 100644
>> --- a/lisp/progmodes/cc-mode.el
>> +++ b/lisp/progmodes/cc-mode.el
>> @@ -506,6 +506,8 @@ c-just-done-before-change
>> ;; and `after-change-functions'. Note that this variable is not set when
>> ;; `c-before-change' is invoked by a change to text properties.
>>
>> +(defvar c--use-syntax-propertize t)
>> +
>> (defun c-basic-common-init (mode default-style)
>> "Do the necessary initialization for the syntax handling routines
>> and the line breaking/filling code. Intended to be used by other
>> @@ -648,12 +650,17 @@ c-basic-common-init
>>
>> ;; Install the functions that ensure that various internal caches
>> ;; don't become invalid due to buffer changes.
>> - (when (featurep 'xemacs)
>> - (make-local-hook 'before-change-functions)
>> - (make-local-hook 'after-change-functions))
>> - (add-hook 'before-change-functions 'c-before-change nil t)
>> - (setq c-just-done-before-change nil)
>> - (add-hook 'after-change-functions 'c-after-change nil t)
>> + (if c--use-syntax-propertize
>> + (setq-local syntax-propertize-function
>> + (lambda (start end)
>> + (c-before-change start (point-max))
>> + (c-after-change start end (- end start))))
>> + (when (featurep 'xemacs)
>> + (make-local-hook 'before-change-functions)
>> + (make-local-hook 'after-change-functions))
>> + (add-hook 'before-change-functions 'c-before-change nil t)
>> + (setq c-just-done-before-change nil)
>> + (add-hook 'after-change-functions 'c-after-change nil t))
>> (when (boundp 'font-lock-extend-after-change-region-function)
>> (set (make-local-variable 'font-lock-extend-after-change-region-function)
>> 'c-extend-after-change-region))) ; Currently (2009-05) used by all
>> @@ -711,15 +718,17 @@ c-common-init
>> (widen)
>> (setq c-new-BEG (point-min))
>> (setq c-new-END (point-max))
>> - (save-excursion
>> - (let (before-change-functions after-change-functions)
>> - (mapc (lambda (fn)
>> - (funcall fn (point-min) (point-max)))
>> - c-get-state-before-change-functions)
>> - (mapc (lambda (fn)
>> - (funcall fn (point-min) (point-max)
>> - (- (point-max) (point-min))))
>> - c-before-font-lock-functions))))
>> + (unless c--use-syntax-propertize
>> + (save-excursion
>> + (let (before-change-functions after-change-functions)
>> + (mapc (lambda (fn)
>> + (funcall fn (point-min) (point-max)))
>> + c-get-state-before-change-functions)
>> + (mapc (lambda (fn)
>> + (funcall fn (point-min) (point-max)
>> + (- (point-max) (point-min))))
>> + c-before-font-lock-functions)
>> + ))))
>>
>> (set (make-local-variable 'outline-regexp) "[^#\n\^M]")
>> (set (make-local-variable 'outline-level) 'c-outline-level)
>> @@ -1954,6 +1963,12 @@ c-font-lock-fontify-region
>> ;;
>> ;; Type a space in the first blank line, and the fontification of the next
>> ;; line was fouled up by context fontification.
>> + (when c--use-syntax-propertize
>> + ;; This should also update c-new-END and c-new-BEG.
>> + (syntax-propertize end)
>> + ;; FIXME: Apparently `c-new-END' may be left unchanged to a stale value,
>> + ;; presumably when the buffer gets truncated.
>> + (if (> c-new-END (point-max)) (setq c-new-END (point-max))))
>> (let (new-beg new-end new-region case-fold-search)
>> (if (and c-in-after-change-fontification
>> (< beg c-new-END) (> end c-new-BEG))
>> @@ -1992,7 +2007,8 @@ c-font-lock-fontify-region
>> (defun c-after-font-lock-init ()
>> ;; Put on `font-lock-mode-hook'. This function ensures our after-change
>> ;; function will get executed before the font-lock one.
>> - (when (memq #'c-after-change after-change-functions)
>> + (when (and c--use-syntax-propertize
>> + (memq #'c-after-change after-change-functions))
>> (remove-hook 'after-change-functions #'c-after-change t)
>> (add-hook 'after-change-functions #'c-after-change nil t)))
>>
>> @@ -2046,11 +2062,14 @@ c-extend-after-change-region
>> (when (eq font-lock-support-mode 'jit-lock-mode)
>> (save-restriction
>> (widen)
>> + ;; FIXME: This presumes that c-new-BEG and c-new-END have been set
>> + ;; I guess from the before-change-function.
>> (c-save-buffer-state () ; Protect the undo-list from put-text-property.
>> (if (< c-new-BEG beg)
>> (put-text-property c-new-BEG beg 'fontified nil))
>> (if (> c-new-END end)
>> - (put-text-property end c-new-END 'fontified nil)))))
>> + (put-text-property end (min c-new-END (point-max))
>> + 'fontified nil)))))
>> (cons c-new-BEG c-new-END))
>>
>> ;; Emacs < 22 and XEmacs
>
next prev parent reply other threads:[~2019-05-09 13:23 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <5A24EADA-D920-4E1D-8CAE-511A6A74588C@outlook.com>
2019-04-19 0:22 ` bug#35316: 26.2; Emacs lags in c++-mode buffer when editing with iedit-mode on Zhang Haijun
2019-04-19 0:32 ` Zhang Haijun
2019-04-19 16:20 ` Stefan Monnier
2019-04-20 2:44 ` Zhang Haijun
2019-05-09 13:23 ` Zhang Haijun [this message]
2019-05-16 15:04 ` Alan Mackenzie
2019-05-16 15:46 ` Zhang Haijun
2019-05-16 16:17 ` Alan Mackenzie
2019-05-17 0:48 ` Zhang Haijun
2019-05-17 1:19 ` Amos Bird
2019-05-17 10:01 ` Alan Mackenzie
[not found] ` <20190517100118.GB5011@ACM>
2019-05-17 17:35 ` Amos Bird
2019-05-19 11:40 ` Alan Mackenzie
2019-05-19 13:20 ` Noam Postavsky
2019-05-19 14:26 ` Alan Mackenzie
2019-05-19 17:41 ` Noam Postavsky
2019-05-19 13:51 ` Zhang Haijun
2019-11-04 3:16 ` Zhang Haijun
2020-09-20 17:59 ` Lars Ingebrigtsen
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=PS1PR06MB2759800EBE7BE0A65BF95F2DA8330@PS1PR06MB2759.apcprd06.prod.outlook.com \
--to=ccsmile2008@outlook.com \
--cc=35316@debbugs.gnu.org \
--cc=monnier@IRO.UMontreal.CA \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).