[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#35316: 26.2; Emacs lags in c++-mode buffer when editing with iedit-m
From: |
Zhang Haijun |
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 |
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
>
- bug#35316: 26.2; Emacs lags in c++-mode buffer when editing with iedit-mode on,
Zhang Haijun <=
- bug#35316: 26.2; Emacs lags in c++-mode buffer when editing with iedit-mode on, Alan Mackenzie, 2019/05/16
- bug#35316: 26.2; Emacs lags in c++-mode buffer when editing with iedit-mode on, Zhang Haijun, 2019/05/16
- bug#35316: 26.2; Emacs lags in c++-mode buffer when editing with iedit-mode on, Alan Mackenzie, 2019/05/16
- bug#35316: 26.2; Emacs lags in c++-mode buffer when editing with iedit-mode on, Zhang Haijun, 2019/05/16
- bug#35316: 26.2; Emacs lags in c++-mode buffer when editing with iedit-mode on, Amos Bird, 2019/05/16
- bug#35316: 26.2; Emacs lags in c++-mode buffer when editing with iedit-mode on, Alan Mackenzie, 2019/05/17
- bug#35316: 26.2; Emacs lags in c++-mode buffer when editing with iedit-mode on, Amos Bird, 2019/05/17
- bug#35316: 26.2; Emacs lags in c++-mode buffer when editing with iedit-mode on, Alan Mackenzie, 2019/05/19
- bug#35316: 26.2; Emacs lags in c++-mode buffer when editing with iedit-mode on, Noam Postavsky, 2019/05/19
- bug#35316: 26.2; Emacs lags in c++-mode buffer when editing with iedit-mode on, Alan Mackenzie, 2019/05/19