emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/valign 6905c5d 030/198: Better handling for invisible t


From: Stefan Monnier
Subject: [elpa] externals/valign 6905c5d 030/198: Better handling for invisible text
Date: Tue, 1 Dec 2020 18:19:10 -0500 (EST)

branch: externals/valign
commit 6905c5dc115cdbc11266d9514d6238b878bacd58
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    Better handling for invisible text
    
    * valign.el (valign--pixel-width-from-to): consider outline fold as
    non-invisible.
    (valign--org-flag-region-advice): New function.
    (valign-mode): Add new advice.
---
 valign.el | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/valign.el b/valign.el
index 53e5c86..9e04932 100644
--- a/valign.el
+++ b/valign.el
@@ -122,8 +122,9 @@ calculate images pixel width."
                    (setq width (+ width (car (image-size display t))))
                    (goto-char
                     (next-single-property-change (point) 'display nil to))))
-                ;; 2) Invisible text.
-                ((invisible-p (point))
+                ;; 2) Invisible text.  If text is hidden under ellipses,
+                ;; (outline fold) treat it as non-invisible.
+                ((eq (invisible-p (point)) t)
                  (goto-char
                   (next-single-property-change (point) 'invisible nil to)))
                 ;; 3) This is a normal character, add glyph width.
@@ -462,6 +463,13 @@ for the former, and 'multi-column for the latter."
   "Forcefully realign every table in the buffer."
   (valign-initial-alignment (point-min) (point-max) t))
 
+;; When an org link is in an outline fold, it’s full length
+;; is used, when the subtree is unveiled, org link only shows
+;; part of it’s text, so we need to re-align.
+(defun valign--org-flag-region-advice (beg end _ _1)
+  "Valign hook, realign table between BEG and END."
+  (valign-initial-alignment beg end t))
+
 (define-minor-mode valign-mode
   "valign minor mode."
   :global t
@@ -478,14 +486,16 @@ for the former, and 'multi-column for the latter."
                     :after #'valign--force-align-buffer)
         (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-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)
     (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-table-previous-field #'valign-table)
+    (advice-remove 'org-flag-region #'valign--org-flag-region-advice)))
 
 (provide 'valign)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]