From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#35316: 26.2; Emacs lags in c++-mode buffer when editing with iedit-mode on Date: Fri, 19 Apr 2019 12:20:14 -0400 Message-ID: References: <5A24EADA-D920-4E1D-8CAE-511A6A74588C@outlook.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="152517"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: "35316@debbugs.gnu.org" <35316@debbugs.gnu.org> To: Zhang Haijun Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Apr 19 18:35:35 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hHWU8-000dWA-Dq for geb-bug-gnu-emacs@m.gmane.org; Fri, 19 Apr 2019 18:35:32 +0200 Original-Received: from localhost ([127.0.0.1]:58815 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hHWU7-0002tg-CZ for geb-bug-gnu-emacs@m.gmane.org; Fri, 19 Apr 2019 12:35:31 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:54838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hHWTq-0002kC-LQ for bug-gnu-emacs@gnu.org; Fri, 19 Apr 2019 12:35:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hHWG6-0006RT-DP for bug-gnu-emacs@gnu.org; Fri, 19 Apr 2019 12:21:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:59229) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hHWG6-0006RJ-AO for bug-gnu-emacs@gnu.org; Fri, 19 Apr 2019 12:21:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hHWG6-00063u-00 for bug-gnu-emacs@gnu.org; Fri, 19 Apr 2019 12:21:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 19 Apr 2019 16:21:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35316 X-GNU-PR-Package: emacs Original-Received: via spool by 35316-submit@debbugs.gnu.org id=B35316.155569082023233 (code B ref 35316); Fri, 19 Apr 2019 16:21:01 +0000 Original-Received: (at 35316) by debbugs.gnu.org; 19 Apr 2019 16:20:20 +0000 Original-Received: from localhost ([127.0.0.1]:44540 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hHWFQ-00062f-6Z for submit@debbugs.gnu.org; Fri, 19 Apr 2019 12:20:20 -0400 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:43996) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hHWFN-00062V-9F for 35316@debbugs.gnu.org; Fri, 19 Apr 2019 12:20:18 -0400 Original-Received: from pastel.home (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id x3JGKFLv007908; Fri, 19 Apr 2019 12:20:15 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id D8ECD6AE31; Fri, 19 Apr 2019 12:20:14 -0400 (EDT) In-Reply-To: (Zhang Haijun's message of "Fri, 19 Apr 2019 00:32:34 +0000") X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0.1 X-NAI-Spam-Rules: 3 Rules triggered TRK_NCM1=0.1, EDT_SA_DN_PASS=0, RV6529=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6529> : inlines <7058> : streams <1819126> : uri <2834599> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:157852 Archived-At: > Reproducing steps: > 1. emacs -Q > 2. Eval code: (add-to-list 'package-archives '("melpa" . "https://melpa.o= rg/packages/=E2=80=9C)) > 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 =E2=80=9Csubsession" > 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. =20 +(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 =20 ;; 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-functi= on) '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) + )))) =20 (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 ne= xt ;; 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 valu= e, + ;; 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))) =20 @@ -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-proper= ty. (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)) =20 ;; Emacs < 22 and XEmacs