From 4f8ac0a7a3d5575fedf5ea311bd34ea09c2a0d99 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Thu, 10 Dec 2020 00:40:05 -0500 Subject: [PATCH 1/2] org.el: Fix cycling hang when %p is in frame-title-format * lisp/org.el (org-optimize-window-after-visibility-change): Guard against calling set-window-start with a nil POS argument. org-optimize-window-after-visibility-change calls set-window-start with org-scroll-position-to-restore when it is a repeat call (i.e. last-command and this-command match). However, org-scroll-position-to-restore may not have yet been set yet (e.g. if org-startup-folded is at its default value of showeverything). Calling set-window-start appears to generally be a noop, but, for a reason that I don't understand, it triggers a hang when %p is in frame-title-format. Reported-by: Massimo Lauria Ref: https://orgmode.org/list/CAJCFsEEHJXP4nKZpWdzheMM5O0Dq-tT+v0u0FsT+3Q0mi4v10A@mail.gmail.com --- lisp/org.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/org.el b/lisp/org.el index 500e9659a..0c1d36a4e 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -6618,7 +6618,8 @@ This function is the default value of the hook `org-cycle-hook'." (cond ((eq state 'content) nil) ((eq state 'all) nil) - ((and (eq state 'folded) (eq last-command this-command)) + ((and org-scroll-position-to-restore + (eq state 'folded) (eq last-command this-command)) (set-window-start nil org-scroll-position-to-restore)) ((eq state 'folded) nil) ((eq state 'children) From cf02219e727536ce4f3d580efa444c2b5a96c53a Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Thu, 10 Dec 2020 00:40:05 -0500 Subject: [PATCH 2/2] org: Reset saved scroll position on new cycling sequence * lisp/org.el (org-optimize-window-after-visibility-change): Reset org-scroll-position-to-restore if it is not a repeated call. The org-scroll-position-to-restore variable is used to save the position, but the position may be from a cycling sequence other than the current one. Reset it at the start of a sequence. --- lisp/org.el | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 0c1d36a4e..b0c2f2e89 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -6615,20 +6615,23 @@ With numerical argument N, show content up to level N." "Adjust the window after a change in outline visibility. This function is the default value of the hook `org-cycle-hook'." (when (get-buffer-window (current-buffer)) - (cond - ((eq state 'content) nil) - ((eq state 'all) nil) - ((and org-scroll-position-to-restore - (eq state 'folded) (eq last-command this-command)) - (set-window-start nil org-scroll-position-to-restore)) - ((eq state 'folded) nil) - ((eq state 'children) - (setq org-scroll-position-to-restore (window-start)) - (or (org-subtree-end-visible-p) (recenter 1))) - ((eq state 'subtree) - (when (not (eq last-command this-command)) - (setq org-scroll-position-to-restore (window-start))) - (or (org-subtree-end-visible-p) (recenter 1)))))) + (let ((repeat (eq last-command this-command))) + (unless repeat + (setq org-scroll-position-to-restore nil)) + (cond + ((eq state 'content) nil) + ((eq state 'all) nil) + ((and org-scroll-position-to-restore repeat + (eq state 'folded)) + (set-window-start nil org-scroll-position-to-restore)) + ((eq state 'folded) nil) + ((eq state 'children) + (setq org-scroll-position-to-restore (window-start)) + (or (org-subtree-end-visible-p) (recenter 1))) + ((eq state 'subtree) + (unless repeat + (setq org-scroll-position-to-restore (window-start))) + (or (org-subtree-end-visible-p) (recenter 1))))))) (defun org-clean-visibility-after-subtree-move () "Fix visibility issues after moving a subtree."