branch: externals/valign
commit 5b9a0864351e0fd7c2c7a0edfa059dd78c0fddeb
Author: Yuan Fu <[email protected]>
Commit: Yuan Fu <[email protected]>
Fix edge case
When we enable valign-mode when a org buffer is in another window.
* valign.el (valign-mode): Add check for visibility.
---
valign.el | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/valign.el b/valign.el
index 09451dd..9d0faeb 100644
--- a/valign.el
+++ b/valign.el
@@ -533,13 +533,18 @@ When they are fontified next time."
(advice-add 'org-flag-region :before #'valign--org-flag-region-advice)
;; Force jit-lock to refontify (and thus realign) the buffer.
(dolist (buf (buffer-list))
+ ;; If the buffer is visible, realign immediately, if not,
+ ;; realign when it becomes visible.
(with-current-buffer buf
(when (derived-mode-p 'org-mode)
- (with-silent-modifications
- (put-text-property
- (point-min) (point-max) 'fontified nil)
- (put-text-property
- (point-min) (point-max) 'valign-init nil))))))
+ (if (get-buffer-window buf t)
+ (with-selected-window (get-buffer-window buf t)
+ (valign-initial-alignment (point-min) (point-max) t))
+ (with-silent-modifications
+ (put-text-property
+ (point-min) (point-max) 'fontified nil)
+ (put-text-property
+ (point-min) (point-max) 'valign-init nil)))))))
(remove-hook 'org-mode-hook #'valign--org-mode-hook)
(remove-hook 'org-agenda-finalize-hook #'valign--force-align-buffer)
(advice-remove 'org-toggle-inline-images #'valign--force-align-buffer)