From: "Sébastien Miquel" <sebastien.miquel@posteo.eu> To: "Léo Ackermann" <leo.komba@gmail.com>, "Org Mode List" <emacs-orgmode@gnu.org> Subject: Re: Large source block causes org-mode to be unusable Date: Mon, 28 Jun 2021 08:28:24 +0000 [thread overview] Message-ID: <5c82f571-f36b-0d61-b69b-e057832f7d84@posteo.eu> (raw) In-Reply-To: <CAFhsWEjdHiRT3dKxbbYSvos=QNKmy9Cq5KjFNXe06nrO1N=zzQ@mail.gmail.com> [-- Attachment #1: Type: text/plain, Size: 493 bytes --] Hi, Léo Ackermann writes: > @EricSFrada, would you mind sharing your code for your proof sections ? This functionality is now built-in: headings with an `ignore' tag do not get exported (their contents do). For very large proof, this seems like the right thing to do. In small to moderate sized blocks, the delay can still be noticeable and ought to be fixed. Attached is a patch that seems to resolve this issue. I haven't noticed any drawbacks so far. Regards, -- Sébastien Miquel [-- Attachment #2: 0001-WIP-do-not-refontify-special-blocks.patch --] [-- Type: text/x-patch, Size: 6303 bytes --] From d843bdc5887a6e50a57e349128ebbe032086dc17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Miquel?= <sebastien.miquel@posteo.eu> Date: Sun, 27 Jun 2021 16:24:22 +0200 Subject: [PATCH] WIP : do not refontify special blocks --- lisp/org.el | 99 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 35 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 1bd9e02eb..9fd3f8514 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -5265,22 +5265,32 @@ by a #." (org-fontify-meta-lines-and-blocks-1 limit) (error (message "Org mode fontification error in %S at %d" (current-buffer) - (line-number-at-pos))))) + (line-number-at-pos)))) + nil) (defun org-fontify-meta-lines-and-blocks-1 (limit) "Fontify #+ lines and blocks." - (let ((case-fold-search t)) - (when (re-search-forward - (rx bol (group (zero-or-more (any " \t")) "#" - (group (group (or (seq "+" (one-or-more (any "a-zA-Z")) (optional ":")) - (any " \t") - eol)) - (optional (group "_" (group (one-or-more (any "a-zA-Z")))))) - (zero-or-more (any " \t")) - (group (group (zero-or-more (not (any " \t\n")))) - (zero-or-more (any " \t")) - (group (zero-or-more any))))) - limit t) + (let* ((case-fold-search t) + (fl-beg (point)) + (fl-end limit) + (fbeg (when (and (> fl-beg (point-min)) + (get-text-property (1- fl-beg) 'font-lock-multiline-block)) + (or (previous-single-property-change + fl-beg 'font-lock-multiline-block) + (point-min))))) + (when fbeg (goto-char fbeg)) + (while (and (< (point) limit) + (re-search-forward + (rx bol (group (zero-or-more (any " \t")) "#" + (group (group (or (seq "+" (one-or-more (any "a-zA-Z")) (optional ":")) + (any " \t") + eol)) + (optional (group "_" (group (one-or-more (any "a-zA-Z")))))) + (zero-or-more (any " \t")) + (group (group (zero-or-more (not (any " \t\n")))) + (zero-or-more (any " \t")) + (group (zero-or-more any))))) + limit t)) (let ((beg (match-beginning 0)) (end-of-beginline (match-end 0)) ;; Including \n at end of #+begin line will include \n @@ -5318,7 +5328,7 @@ by a #." (remove-text-properties beg end-of-endline '(display t invisible t intangible t))) (add-text-properties - beg end-of-endline '(font-lock-fontified t font-lock-multiline t)) + beg end-of-endline '(font-lock-fontified t font-lock-multiline-block t)) (org-remove-flyspell-overlays-in beg bol-after-beginline) (org-remove-flyspell-overlays-in nl-before-endline end-of-endline) (cond @@ -5327,7 +5337,8 @@ by a #." (add-text-properties bol-after-beginline block-end '(src-block t))) (quoting (add-text-properties - bol-after-beginline beg-of-endline + (max bol-after-beginline (or fl-beg bol-after-beginline)) + (min beg-of-endline (or fl-end beg-of-endline)) (list 'face (list :inherit (let ((face-name @@ -5426,26 +5437,41 @@ by a #." (add-text-properties closing-start end '(invisible t))) t))))) -(defun org-fontify-extend-region (beg end _old-len) - (let ((begin-re "\\(\\\\\\[\\|\\(#\\+begin_\\|\\\\begin{\\)\\S-+\\)") - (end-re "\\(\\\\\\]\\|\\(#\\+end_\\|\\\\end{\\)\\S-+\\)") - (extend - (lambda (r1 r2 dir) - (let ((re (replace-regexp-in-string - "\\(begin\\|end\\)" r1 - (replace-regexp-in-string - "[][]" r2 - (match-string-no-properties 0))))) - (re-search-forward (regexp-quote re) nil t dir))))) - (save-match-data - (save-excursion - (goto-char beg) - (back-to-indentation) - (cond ((looking-at end-re) - (cons (or (funcall extend "begin" "[" -1) beg) end)) - ((looking-at begin-re) - (cons beg (or (funcall extend "end" "]" 1) end))) - (t (cons beg end))))))) +(defun org-fontify-extend-region (bego endo _old-len) + (let* ((beg bego) (end endo) + (bol (save-excursion (goto-char beg) (point-at-bol))) + (eol (save-excursion (goto-char end) (point-at-eol)))) + (let ((before-multi (and (> bol (point-min)) + (get-text-property (1- bol) 'font-lock-multiline-block))) + (after-multi (get-text-property eol 'font-lock-multiline-block))) + (if before-multi + (unless after-multi + (setq beg (or (previous-single-property-change + bol 'font-lock-multiline-block) + (point-min)))) + (when after-multi + (setq end (or (text-property-any eol (point-max) + 'font-lock-multiline-block nil) + (point-max)))))) + (let ((begin-re "\\(\\\\\\[\\|\\(#\\+begin_\\|\\\\begin{\\)\\S-+\\)") + (end-re "\\(\\\\\\]\\|\\(#\\+end_\\|\\\\end{\\)\\S-+\\)") + (extend + (lambda (r1 r2 dir) + (let ((re (replace-regexp-in-string + "\\(begin\\|end\\)" r1 + (replace-regexp-in-string + "[][]" r2 + (match-string-no-properties 0))))) + (re-search-forward (regexp-quote re) nil t dir))))) + (save-match-data + (save-excursion + (goto-char beg) + (back-to-indentation) + (cond ((looking-at end-re) + (cons (or (funcall extend "begin" "[" -1) beg) end)) + ((looking-at begin-re) + (cons beg (max end (or (funcall extend "end" "]" 1) end)))) + (t (cons beg end)))))))) (defun org-activate-footnote-links (limit) "Add text properties for footnotes." @@ -5772,6 +5798,9 @@ needs to be inserted at a specific position in the font-lock sequence.") '(org-font-lock-keywords t nil nil backward-paragraph)) (setq-local font-lock-extend-after-change-region-function #'org-fontify-extend-region) + (setq-local font-lock-extra-managed-props + (append font-lock-extra-managed-props + '(font-lock-multiline-block))) (kill-local-variable 'font-lock-keywords) nil)) -- 2.32.0
next prev parent reply other threads:[~2021-06-28 8:29 UTC|newest] Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-06-21 18:27 Léo Ackermann 2021-06-21 18:43 ` John Hendy 2021-06-21 18:57 ` Sébastien Miquel 2021-06-21 19:22 ` John Kitchin 2021-06-21 19:36 ` John Hendy 2021-06-21 20:41 ` Tom Gillespie 2021-06-22 4:48 ` Tim Cross 2021-06-22 7:54 ` Eric S Fraga 2021-06-22 11:20 ` Léo Ackermann 2021-06-22 12:13 ` Eric S Fraga 2021-06-22 12:32 ` Léo Ackermann 2021-06-22 13:03 ` Eric S Fraga 2021-06-22 13:32 ` Léo Ackermann 2021-06-23 16:40 ` Maxim Nikulin 2021-06-23 19:42 ` Gennady Uraltsev 2021-06-24 7:54 ` Eric S Fraga 2021-06-26 14:10 ` Léo Ackermann 2021-06-28 8:28 ` Sébastien Miquel [this message] 2021-06-28 10:42 ` Eric S Fraga 2021-06-28 10:40 ` Eric S Fraga 2021-06-22 6:10 ` Timothy
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.orgmode.org/ * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=5c82f571-f36b-0d61-b69b-e057832f7d84@posteo.eu \ --to=sebastien.miquel@posteo.eu \ --cc=emacs-orgmode@gnu.org \ --cc=leo.komba@gmail.com \ --subject='Re: Large source block causes org-mode to be unusable' \ /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
Code repositories for project(s) associated with this inbox: https://git.savannah.gnu.org/cgit/emacs/org-mode.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).