From 39db5de5709a0e4a3b1a88bfd58d7d0075b2d728 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 13 Mar 2024 00:07:01 -0400 Subject: [PATCH] fix(org): only reveal point on save-place-after-find-file-hook Prior to this change, whenever you enter an org-mode buffer, any invisible regions around the cursor (which had been moved by save-place) would be unfolded unconditionally. There may be cases where moving the cursor immediately after visiting the file could cause errors (e.g. when yasnippet tries to wrestle control over the cursor, org-agenda-switch-to moves the cursor before switching to the buffer, etc). This change ensures the expansion *only* happens when save-place does its thing (and successfully). --- modules/lang/org/config.el | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/lang/org/config.el b/modules/lang/org/config.el index 549f38c10..ffbfbb19b 100644 --- a/modules/lang/org/config.el +++ b/modules/lang/org/config.el @@ -1368,7 +1368,7 @@ between the two." #'doom-disable-show-trailing-whitespace-h ;; #'+org-enable-auto-reformat-tables-h ;; #'+org-enable-auto-update-cookies-h - #'+org-make-last-point-visible-h) + ) (add-hook! 'org-load-hook #'+org-init-org-directory-h @@ -1435,15 +1435,20 @@ between the two." :references #'+org-lookup-references-handler :documentation #'+org-lookup-documentation-handler) - ;; HACK: Somehow, users/packages still find a way to modify tab-width in - ;; org-mode. Since org-mode treats a non-standerd tab-width as an error - ;; state, I use this hook to makes it much harder to change by accident. (add-hook! 'org-mode-hook + ;; HACK: Somehow, users/packages still find a way to modify tab-width in + ;; org-mode. Since org-mode treats a non-standerd tab-width as an error + ;; state, I use this hook to makes it much harder to change by accident. (add-hook! 'after-change-major-mode-hook :local ;; The second check is necessary, in case of `org-edit-src-code' which ;; clones a buffer and changes its major-mode. (when (derived-mode-p 'org-mode) - (setq tab-width 8)))) + (setq tab-width 8))) + + ;; HACK: `save-place' can position the cursor in an invisible region. This + ;; makes it visible unless `org-inhibit-startup' or + ;; `org-inhibit-startup-visibility-stuff' is non-nil. + (add-hook 'save-place-after-find-file-hook #'+org-make-last-point-visible-h nil t)) ;; Save target buffer after archiving a node. (setq org-archive-subtree-save-file-p t)