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

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

[elpa] externals/valign 7315f4b 148/198: Add support for org-indent


From: Stefan Monnier
Subject: [elpa] externals/valign 7315f4b 148/198: Add support for org-indent
Date: Tue, 1 Dec 2020 18:19:36 -0500 (EST)

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

    Add support for org-indent
    
    * README.org: Remove org-indent.
    * valign.el (Commentary): Remove org-indent.
    (valign--pixel-width-from-to): Add argument 'with-prefix'.  Subtract
    line-prefix if 'with-prefix' non-nil.
    (valign--align-separator-row, valign-table-1): Don't subtract prefix
    for the beginning position.
---
 README.org |  2 --
 valign.el  | 35 ++++++++++++++++++++---------------
 2 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/README.org b/README.org
index 78c2209..a93e0d5 100644
--- a/README.org
+++ b/README.org
@@ -10,8 +10,6 @@ To use this package, load it and add ~valign-mode~ to 
~org-mode-hook~ or ~markdo
 [[./default.png]]
 
 *Know problems:*
-- Customizing ~org-table~ face seems to mess up the separator (it will 
disappear).
-- ~org-indent~ breaks the alignment. It uses line-prefix, and we don’t support 
it right now.
 - Hidden links in markdown still occupy the full length of the link, because 
it uses character composition which we don’t support now.
 - Rendering large tables (≥100 lines) is laggy.
 
diff --git a/valign.el b/valign.el
index cf6f517..8b1714b 100644
--- a/valign.el
+++ b/valign.el
@@ -24,8 +24,8 @@
 ;; |           |.  Customize ‘valign-separator-row-style’ to set a
 ;; style.
 ;;
-;; TODO
-;; - Support org-indent.  It uses line-prefix, and we don’t support it.
+;; TODO:
+;;
 ;; - Hidden links in markdown still occupy the full length of the link
 ;;   because it uses character composition, which we don’t support.
 
@@ -134,18 +134,23 @@ Return nil if not in a cell."
 ;; has some limitations, including not working right with face remapping.
 ;; With this function we can avoid some of them.  However we still can’t
 ;; get the true tab width, see comment in ‘valgn--tab-width’ for more.
-(defun valign--pixel-width-from-to (from to)
+(defun valign--pixel-width-from-to (from to &optional with-prefix)
   "Return the width of the glyphs from FROM (inclusive) to TO (exclusive).
-The buffer has to be in a live window.  FROM has to be less than TO.
-Unlike ‘valign--glyph-width-at-point’, this function can properly
-calculate images pixel width.  Valign display properties must be
-cleaned before using this."
-  (- (car (window-text-pixel-size
-           (get-buffer-window (current-buffer)) from to))
-     ;; FIXME: Workaround.
-     (if (bound-and-true-p display-line-numbers-mode)
-         (line-number-display-width 'pixel)
-       0)))
+The buffer has to be in a live window.  FROM has to be less than
+TO and they should be on the same line.  Valign display
+properties must be cleaned before using this.
+
+If WITH-PREFIX is non-nil, don’t subtract the width of line
+prefix."
+  (let ((window (get-buffer-window)))
+    (- (car (window-text-pixel-size window from to))
+       ;; This computes the prefix width.  This trick doesn’t seem work
+       ;; if the point is at the beginning of a line.
+       (if with-prefix 0 (car (window-text-pixel-size window to to)))
+       ;; FIXME: Workaround.
+       (if (bound-and-true-p display-line-numbers-mode)
+           (line-number-display-width 'pixel)
+         0))))
 
 (defun valign--separator-p ()
   "If the current cell is actually a separator.
@@ -424,7 +429,7 @@ COLUMN-WIDTH-LIST is returned from 
`valign--calculate-cell-width'."
         (column-start (point))
         (col-idx 0)
         (pos (valign--pixel-width-from-to
-              (line-beginning-position) (point))))
+              (line-beginning-position) (point) t)))
     (while (re-search-forward "[+|]" (line-end-position) t)
       (let ((column-width (nth col-idx column-width-list)))
         (valign--separator-row-add-overlay
@@ -518,7 +523,7 @@ You need to restart valign mode for this setting to take 
effect."
         ;; pixel position of the current point, i.e., after the left
         ;; bar.
         (setq column-start (valign--pixel-width-from-to
-                            (line-beginning-position) (point)))
+                            (line-beginning-position) (point) t))
         (valign--maybe-render-bar (1- (point)))
         (valign--do-column column-idx
           (save-excursion



reply via email to

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