[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
- [elpa] externals/valign d132330 120/198: Align separator row like other rows, (continued)
- [elpa] externals/valign d132330 120/198: Align separator row like other rows, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 973ddd6 138/198: * valign.el: Fix typo., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 6468741 168/198: Add better table.el table support, Stefan Monnier, 2020/12/01
- [elpa] externals/valign eea7454 173/198: * valign.el (cl-generic): Add require., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 16e3313 174/198: * valign.el (Commentary): Update., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 4005231 165/198: Fix inconsistency after enabling org-indent, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 8c28c8c 151/198: * valign.el: Bump version to 2.3.0., Stefan Monnier, 2020/12/01
- [elpa] externals/valign e82e1f0 155/198: Re-align in jit-lock-functions, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 2d7918b 195/198: Minor fixes, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 831c2a7 176/198: * valign.el (valign--do-row): Fix infinite loop., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 7315f4b 148/198: Add support for org-indent,
Stefan Monnier <=
- [elpa] externals/valign 99300eb 167/198: Add support for table.el tables, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 7b581e0 072/198: Remove valign-werid-alignment error, Stefan Monnier, 2020/12/01
- [elpa] externals/valign f6d60d2 078/198: Merge two implementations for valign--align-separator-row, Stefan Monnier, 2020/12/01
- [elpa] externals/valign e9975b7 083/198: Use new text size calculation, Stefan Monnier, 2020/12/01
- [elpa] externals/valign e32d191 079/198: Valign-table refactor, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 21a397a 092/198: Update README, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 4ecc990 093/198: * valign.el (valign--table-face): Fix markdown-mode., Stefan Monnier, 2020/12/01
- [elpa] externals/valign c4ddfb3 095/198: Fix org-flag-region advice, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 7529ddd 111/198: Revert "* valign.el (valign-table): Tuck in some long lines.", Stefan Monnier, 2020/12/01
- [elpa] externals/valign 97beef8 127/198: Remove valign-table-quiet, Stefan Monnier, 2020/12/01