unofficial mirror of emacs-orgmode@gnu.org
 help / color / mirror / code / Atom feed
* [PATCH 0/1] Add option to delay fontification of source blocks
@ 2021-03-25 17:19 Leo Okawa Ericson
  2021-03-25 17:19 ` [PATCH 1/1] org-src.el: " Leo Okawa Ericson
  2021-03-29  5:03 ` [PATCH 0/1] " Kyle Meyer
  0 siblings, 2 replies; 6+ messages in thread
From: Leo Okawa Ericson @ 2021-03-25 17:19 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Leo Okawa Ericson

Fontification of long code blocks can be very slow. The patch, which should be
in another other email, mitigates this by
adding an option to delay the fontification after the user has become idle by
using idle timers. This seems to be faster from my limited testing, but I'm not
sure if something will go horribly wrong because of the timers.

There is a trade-off in that there will be no syntax highlightinting when the
user is typing. I don't know how to keep existing fontification so it would be
great if somebody could share a solution to that.

I have signed the copyright papers so that shouldn't be a problem. This is my
first patch submission so any suggestions for improvement are welcome.

Leo Okawa Ericson (1):
  org-src.el: Add option to delay fontification of source blocks

 lisp/org-src.el | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

-- 
2.25.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/1] org-src.el: Add option to delay fontification of source blocks
  2021-03-25 17:19 [PATCH 0/1] Add option to delay fontification of source blocks Leo Okawa Ericson
@ 2021-03-25 17:19 ` Leo Okawa Ericson
  2021-03-29  5:03 ` [PATCH 0/1] " Kyle Meyer
  1 sibling, 0 replies; 6+ messages in thread
From: Leo Okawa Ericson @ 2021-03-25 17:19 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Leo Okawa Ericson

* lisp/org-src.el (org-src-font-lock-fontify-block): Add option to delay
fontification of source blocks.  If
`org-src-font-lock-fontify-idle-delay' is non-nil fontification of
code blocks is delayed until the user has become
idle.

Fontification of source blocks can be very slow. This will add an option
for users to delay the fontification until they have become idle so that
the typing delay is kept low. The trade-off is that there will be no
syntax highlighting when the user is typing.
---
 lisp/org-src.el | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/lisp/org-src.el b/lisp/org-src.el
index 20acee4e6..b1446e105 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -584,11 +584,40 @@ (defun org-src--edit-element
 
 \f
 ;;; Fontification of source blocks
+(defvar org-src-font-lock-fontify-idle-timer nil
+  "Idle timer to use for when fontifying with a timer.")
+
+
+(defvar org-src-font-lock-fontify-idle-delay nil
+  "Duration of the delay until fontification of source blocks.
+If non-nil, source blocks are fontified when the user has been
+idle for `org-src-font-lock-fontify-idle-delay' seconds. This
+means that instead of applying syntax highlighting when you type
+it is delayed until you become idle. Not that when typing there
+will be no fontification.
+")
 
 (defun org-src-font-lock-fontify-block (lang start end)
   "Fontify code block.
 This function is called by emacs automatic fontification, as long
 as `org-src-fontify-natively' is non-nil."
+  (if org-src-font-lock-fontify-idle-delay
+      (progn
+        (when org-src-font-lock-fontify-idle-timer
+          (cancel-timer org-src-font-lock-fontify-idle-timer))
+        (setq org-src-font-lock-fontify-idle-timer
+              (let ((buf (current-buffer)))
+                (run-with-idle-timer
+                 org-src-font-lock-fontify-idle-delay
+                 nil
+                 (lambda ()
+                   (with-current-buffer buf
+                     (org-src-font-lock-fontify-block-1 lang start end)
+                     (when org-src-font-lock-fontify-idle-timer
+                       (cancel-timer org-src-font-lock-fontify-idle-timer)) ))))))
+    (org-src-font-lock-fontify-block-1 lang start end)))
+
+(defun org-src-font-lock-fontify-block-1 (lang start end)
   (let ((lang-mode (org-src-get-lang-mode lang)))
     (when (fboundp lang-mode)
       (let ((string (buffer-substring-no-properties start end))
-- 
2.25.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/1] Add option to delay fontification of source blocks
  2021-03-25 17:19 [PATCH 0/1] Add option to delay fontification of source blocks Leo Okawa Ericson
  2021-03-25 17:19 ` [PATCH 1/1] org-src.el: " Leo Okawa Ericson
@ 2021-03-29  5:03 ` Kyle Meyer
  2021-04-02 12:44   ` Leo Okawa Ericson
  1 sibling, 1 reply; 6+ messages in thread
From: Kyle Meyer @ 2021-03-29  5:03 UTC (permalink / raw)
  To: Leo Okawa Ericson; +Cc: emacs-orgmode

Leo Okawa Ericson writes:

> Fontification of long code blocks can be very slow. The patch, which should be
> in another other email, mitigates this by
> adding an option to delay the fontification after the user has become idle by
> using idle timers. This seems to be faster from my limited testing, but I'm not
> sure if something will go horribly wrong because of the timers.

Thanks for the patch.  My initial reaction is that I'm not sure about
adding an idle timer for a particular aspect of fontification.  If we do
go this route, I think the case needs to be made why this spot is
special, and why we don't expect or would reject follow-up patches for
this and that other area.

Have you explored whether jit-lock (e.g., jit-lock-defer-time) helps for
your use case?


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/1] Add option to delay fontification of source blocks
  2021-03-29  5:03 ` [PATCH 0/1] " Kyle Meyer
@ 2021-04-02 12:44   ` Leo Okawa Ericson
  0 siblings, 0 replies; 6+ messages in thread
From: Leo Okawa Ericson @ 2021-04-02 12:44 UTC (permalink / raw)
  To: Kyle Meyer; +Cc: emacs-orgmode

Kyle Meyer <kyle@kyleam.com> writes:

> Have you explored whether jit-lock (e.g., jit-lock-defer-time) helps for
> your use case?

No I didn't know about it. I have tried it now and it seems to solve
the same problem as my patch. 

> If we do go this route, I think the case needs to be made why this
> spot is special, and why we don't expect or would reject follow-up
> patches for this and that other area.
>

I can't think of a reason either (now that I know that jit-lock exists)
so I will retract my patch. 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 0/1] Add option to delay fontification of source blocks
@ 2021-03-25 18:25 leo
  0 siblings, 0 replies; 6+ messages in thread
From: leo @ 2021-03-25 18:25 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Leo Okawa Ericson

From: Leo Okawa Ericson <leo@relevant-information.com>

I tried sending this patch once before, but I think it got caught as spam so I'm
trying this again.

Fontification of long code blocks can be very slow. The patch (in the reply to
this email) mitigates this by adding an option to delay the fontification after
the user has become idle by using idle timers. This seems to be faster from my
limited testing, but I'm not sure if something will go horribly wrong because of
the timers.

There is a trade-off in that there will be no syntax highlightinting when the
user is typing. I don't know how to keep existing fontification so it would be
great if somebody could share a solution to that.

I have signed the copyright papers so that shouldn't be a problem. This is my
first patch submission so any suggestions for improvement are welcome.

Leo Okawa Ericson (1):
  org-src.el: Add option to delay fontification of source blocks

 lisp/org-src.el | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

-- 
2.25.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 0/1] Add option to delay fontification of source blocks
@ 2021-03-25 17:43 Leo Okawa Ericson
  0 siblings, 0 replies; 6+ messages in thread
From: Leo Okawa Ericson @ 2021-03-25 17:43 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Leo Okawa Ericson

From: Leo Okawa Ericson <leo@relevant-information.com>

I tried sending this patch once before, but I think it got caught as spam so I'm
trying this again.

Fontification of long code blocks can be very slow. The patch (in the reply to
this email) mitigates this by adding an option to delay the fontification after
the user has become idle by using idle timers. This seems to be faster from my
limited testing, but I'm not sure if something will go horribly wrong because of
the timers.

There is a trade-off in that there will be no syntax highlightinting when the
user is typing. I don't know how to keep existing fontification so it would be
great if somebody could share a solution to that.

I have signed the copyright papers so that shouldn't be a problem. This is my
first patch submission so any suggestions for improvement are welcome.

Leo Okawa Ericson (1):
  org-src.el: Add option to delay fontification of source blocks

 lisp/org-src.el | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

-- 
2.25.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-04-02 12:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-25 17:19 [PATCH 0/1] Add option to delay fontification of source blocks Leo Okawa Ericson
2021-03-25 17:19 ` [PATCH 1/1] org-src.el: " Leo Okawa Ericson
2021-03-29  5:03 ` [PATCH 0/1] " Kyle Meyer
2021-04-02 12:44   ` Leo Okawa Ericson
2021-03-25 17:43 Leo Okawa Ericson
2021-03-25 18:25 leo

unofficial mirror of emacs-orgmode@gnu.org

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/orgmode/0 orgmode/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 orgmode orgmode/ https://yhetil.org/orgmode \
		emacs-orgmode@gnu.org
	public-inbox-index orgmode

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


code repositories for project(s) associated with this inbox:

	orgmode.git.git (no URL configured)

AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git