diff options
author | Nicolas Goaziou <n.goaziou@gmail.com> | 2011-07-27 23:18:50 +0200 |
---|---|---|
committer | Nicolas Goaziou <n.goaziou@gmail.com> | 2011-08-18 15:45:02 +0200 |
commit | 84faa05c1b906cee06bc4f5b18b0b9668e1d83c4 (patch) | |
tree | 23f8478b0b0138a45a50ab9da49e613c99f4728c | |
parent | b9962b78296c5160ba628661816ac2aebdd92f9f (diff) | |
download | org-mode-84faa05c1b906cee06bc4f5b18b0b9668e1d83c4.tar.gz |
org-indent: add breaks during asynchronous indentation
* lisp/org-indent.el (org-indent-initial-resume-timer): new variable.
(org-indent-initialize-buffer): also resume after a small break.
(org-indent-add-properties): when in asynchronous mode, proceed for
2 seconds, then take a break.
-rw-r--r-- | lisp/org-indent.el | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/lisp/org-indent.el b/lisp/org-indent.el index c12e483..e36c068 100644 --- a/lisp/org-indent.el +++ b/lisp/org-indent.el @@ -73,6 +73,12 @@ It will be set in `org-indent-initialize'.") "Position of initialization before interrupt.") (defvar org-indent-initial-timer nil "Timer used for initialization.") +(defvar org-indent-initial-resume-timer nil + "Timer used to reschedule initialization process.") +(defvar org-indent-initial-process-duration '(0 2 0) + "How long before initialization gives hand to other idle processes.") +(defvar org-indent-initial-resume-delay '(0 0 200000) + "How long before resuming initialization process.") (defvar org-indent-initial-lock nil "Lock used of initialization.") (defvar org-hide-leading-stars-before-indent-mode nil @@ -224,6 +230,9 @@ useful to make it ever so slightly different." (defun org-indent-initialize-buffer () "Set virtual indentation for the whole buffer asynchronously." (when (and org-indent-mode (not org-indent-initial-lock)) + ;; Clean reschedule timer (cf `org-indent-add-properties'). + (when org-indent-initial-resume-timer + (cancel-timer org-indent-initial-resume-timer)) (org-with-wide-buffer (setq org-indent-initial-lock t) (let ((interruptp @@ -291,7 +300,9 @@ you want to use this feature." (pf-inline (and (featurep 'org-inlinetask) (org-inlinetask-in-task-p) (+ (* org-indent-indentation-per-level - (1- (org-inlinetask-get-task-level))) 2)))) + (1- (org-inlinetask-get-task-level))) 2))) + (time-limit (time-add (current-time) + org-indent-initial-process-duration))) ;; 2. For each line, set `line-prefix' and `wrap-prefix' ;; properties depending on the type of line (headline, ;; inline task, item or other). @@ -300,6 +311,17 @@ you want to use this feature." (cond ;; When in async mode, check if interrupt is required. ((and async (input-pending-p)) (throw 'interrupt (point))) + ;; In async mode, take a break of + ;; `org-indent-initial-resume-delay' every + ;; `org-indent-initial-process-duration' to avoid blocking + ;; any other idle timer or process output. + ((and async (time-less-p time-limit (current-time))) + (setq org-indent-initial-resume-timer + (run-with-idle-timer + (time-add (current-idle-time) + org-indent-initial-resume-delay) + nil #'org-indent-initialize-buffer)) + (throw 'interrupt (point))) ;; Empty line: do nothing. ((eolp) (forward-line 1)) ;; Headline or inline task. |