[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/valign bdb56ce 032/198: Sync all org mode alignment sta
From: |
Stefan Monnier |
Subject: |
[elpa] externals/valign bdb56ce 032/198: Sync all org mode alignment state automatically |
Date: |
Tue, 1 Dec 2020 18:19:11 -0500 (EST) |
branch: externals/valign
commit bdb56cee1a2d7c0741d1db4a8e5c435042f565f8
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Sync all org mode alignment state automatically
Now when you enable or disable avalign-mode, you don’t need to revert
existing Org buffers, they are aligned or unaligned automatically.
* valign.el (valign-window-buffer-change-hook, valign-reset-buffer):
New functions.
(valign-mode): Add a hook window-buffer-change-functions. Reset all
Org buffers when disabling valign-mode.
---
valign.el | 46 ++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 42 insertions(+), 4 deletions(-)
diff --git a/valign.el b/valign.el
index 652c116..28b9bc2 100644
--- a/valign.el
+++ b/valign.el
@@ -470,6 +470,33 @@ for the former, and 'multi-column for the latter."
"Valign hook, realign table between BEG and END."
(valign-initial-alignment beg end t))
+(defun valign-window-buffer-change-hook (frame)
+ "Makes sure all visible buffers in FRAME are aligned."
+ (dolist (window (window-list frame 'no-minibuf))
+ (with-current-buffer (window-buffer window)
+ (when (and (derived-mode-p 'org-mode)
+ valign-mode
+ (text-property-any (point-min) (point-max)
+ 'valign-init nil))
+ (valign-initial-alignment (point-min) (point-max))))))
+
+(defun valign-reset-buffer ()
+ "Remove alignment in the buffer."
+ ;; TODO Use the new Emacs 27 function.
+ ;; Remove text properties
+ (with-silent-modifications
+ (let ((p (point-min)) (pp (point-min)) display)
+ (while (< p (point-max))
+ (setq display (plist-get (text-properties-at p) 'display))
+ (setq p (next-single-char-property-change p 'display))
+ (when (and (consp display)
+ (eq (car display) 'space))
+ (put-text-property pp p 'display nil))))
+ ;; Remove overlays.
+ (dolist (ov (overlays-in (point-min) (point-max)))
+ (when (overlay-get ov 'valign)
+ (delete-overlay ov)))))
+
(define-minor-mode valign-mode
"Visually align Org tables."
:global t
@@ -478,7 +505,10 @@ for the former, and 'multi-column for the latter."
:lighter valign-lighter
(if (and valign-mode window-system)
(progn
- (add-hook 'org-mode-hook #'valign--org-mode-hook)
+ (if (boundp 'window-buffer-change-functions)
+ (add-hook 'window-buffer-change-functions
+ #'valign-window-buffer-change-hook)
+ (add-hook 'org-mode-hook #'valign--org-mode-hook))
(add-hook 'org-agenda-finalize-hook #'valign--force-align-buffer)
(advice-add 'org-toggle-inline-images
:after #'valign--force-align-buffer)
@@ -487,15 +517,23 @@ for the former, and 'multi-column for the latter."
(advice-add 'visible-mode :after #'valign--force-align-buffer)
(advice-add 'org-table-next-field :after #'valign-table)
(advice-add 'org-table-previous-field :after #'valign-table)
- (advice-add 'org-flag-region :after #'valign--org-flag-region-advice))
- (remove-hook 'org-mode-hook #'valign--org-mode-hook)
+ (advice-add 'org-flag-region :after #'valign--org-flag-region-advice)
+ (valign-initial-alignment (point-min) (point-max)))
+ (if (boundp 'window-buffer-change-functions)
+ (remove-hook 'window-buffer-change-functions
+ #'valign-window-buffer-change-hook)
+ (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)
(advice-remove 'org-restart-font-lock #'valign--force-align-buffer)
(advice-remove 'visible-mode #'valign--force-align-buffer)
(advice-remove 'org-table-next-field #'valign-table)
(advice-remove 'org-table-previous-field #'valign-table)
- (advice-remove 'org-flag-region #'valign--org-flag-region-advice)))
+ (advice-remove 'org-flag-region #'valign--org-flag-region-advice)
+ (dolist (buf (buffer-list))
+ (with-current-buffer buf
+ (when (derived-mode-p 'org-mode)
+ (valign-reset-buffer))))))
(provide 'valign)
- [elpa] externals/valign 15b1bff 031/198: * valign.el (valign-mode): Change docstring., (continued)
- [elpa] externals/valign 15b1bff 031/198: * valign.el (valign-mode): Change docstring., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 62bfe1a 026/198: Minor change, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 22c6b7c 033/198: Update doc, Stefan Monnier, 2020/12/01
- [elpa] externals/valign fc4c812 044/198: * valign.el (valign-mode): Advice org-table-align instead., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 1e9e16b 045/198: * valign.el (valign--align-separator-row): New implementation for gfm-mode., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 03da172 011/198: Various fixes, Stefan Monnier, 2020/12/01
- [elpa] externals/valign b0cea9f 012/198: Make point appear in the middle for empty cells, Stefan Monnier, 2020/12/01
- [elpa] externals/valign eea08cc 023/198: Re add org-agenda support., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 2a60a4d 025/198: Remove valign-setup, Stefan Monnier, 2020/12/01
- [elpa] externals/valign e555277 029/198: Add with-silent-modification, Stefan Monnier, 2020/12/01
- [elpa] externals/valign bdb56ce 032/198: Sync all org mode alignment state automatically,
Stefan Monnier <=
- [elpa] externals/valign 3c70c15 034/198: * valign.el (valign-mode): Fix., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 3752d53 036/198: Solve a bunch of edge cases, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 5b9a086 038/198: Fix edge case, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 8cfe0ca 039/198: * valign.el (valign-separator-row-style): Add choice definition., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 927d82d 041/198: Support indented tables, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 81de913 042/198: Property support tabs, Stefan Monnier, 2020/12/01
- [elpa] externals/valign db0c4d8 043/198: Add support for markdown tables, Stefan Monnier, 2020/12/01
- [elpa] externals/valign da56833 047/198: Always realign markdown tables, Stefan Monnier, 2020/12/01
- [elpa] externals/valign e885f67 048/198: Merge branch 'markdown', Stefan Monnier, 2020/12/01
- [elpa] externals/valign cd7c17f 052/198: Fix infinite loop, Stefan Monnier, 2020/12/01