[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/valign 7afe578 182/198: Improve documentation
From: |
Stefan Monnier |
Subject: |
[elpa] externals/valign 7afe578 182/198: Improve documentation |
Date: |
Tue, 1 Dec 2020 18:19:44 -0500 (EST) |
branch: externals/valign
commit 7afe57833bf56808490370262614596487f6c323
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Improve documentation
* valign.el (valign--cell): Change docstring.
(Developer): Add detail.
---
valign.el | 46 ++++++++++++++++++++++++++++++++++++++--------
1 file changed, 38 insertions(+), 8 deletions(-)
diff --git a/valign.el b/valign.el
index 383aedd..1700a73 100644
--- a/valign.el
+++ b/valign.el
@@ -16,9 +16,10 @@
;; meantime, the text-based alignment generated by Org mode (or
;; Markdown mode) is left untouched.
;;
-;; To use this package, add `valign-mode' to `org-mode-hook'. If you
-;; want to align a table manually, run M-x valign-table RET on a
-;; table.
+;; To use this package, type M-x valign-mode RET. If you want to
+;; align a table manually, run M-x valign-table RET on a table. If
+;; you want to automatically enable this mode, add `valign-mode' to a
+;; major mode hook like `org-mode-hook'.
;;
;; TODO:
;;
@@ -27,14 +28,41 @@
;;; Developer:
;;
-;; We decide to re-align in jit-lock hook, that means any change that
-;; causes refontification will trigger re-align. This may seem
+;; The trigger condition:
+;;
+;; We decide to re-align in the jit-lock hook, that means any change
+;; that causes refontification will trigger a re-align. This may seem
;; inefficient and unnecessary, but there are just too many things
;; that can mess up a table’s alignment. Therefore it is the most
;; reliable to re-align every time there is a refontification.
;; However, we do have a small optimization for typing in a table: if
;; the last command is 'self-insert-command', we don’t realign. That
;; should improve the typing experience in large tables.
+;;
+;; How does valign align tables:
+;;
+;; The core mechanism used is a text property 'display. Emacs can
+;; display a stretch of space that aligns to a pixel position.
+;; The following snippet
+;;
+;; (put-text-property (point) (1+ (point))
+;; 'display '(space :align-to (500)))
+;;
+;; creates a space that stretches to pixel position 500. You can look
+;; at Info node (elisp) “Display Property” for more detail.
+;;
+;; To align a table, we first look through all its cells to calculate
+;; the appropriate column width, this is done by
+;; `valign--calculate-cell-width'. Then we calculate the alignment of
+;; each column (left/right-aligned) in `valign--calculate-alignment'.
+;; Finally we align each cell by adding text property (or overlay) to
+;; the spaces in the cell which “pushes” the bars to the appropriate
+;; positions.
+;;
+;; Some important auxiliary functions:
+;;
+;; - valign--pixel-width-from-to
+;; - valign--cell-content-config
;;; Code:
;;
@@ -668,13 +696,15 @@ COL-WIDTH (6) Pixel width of the column
ALIGNMENT 'left or 'right
CELL-WIDTH (5) Pixel width of the cell content
CELL-BEG (1) Beginning of the cell
-CONTENT-BEG (2) Beginning of the cell content
-CONTENT-END (3) End of the cell content
+CONTENT-BEG (2) Beginning of the cell content[1]
+CONTENT-END (3) End of the cell content[1]
CELL-END (4) End of the cell
COLUMN-START (1) Pixel x-position of the beginning of the cell
SPACE-WIDTH Pixel width of a space character
-Assumes point is at (2)."
+Assumes point is at (2).
+
+[1] This is not completely true, see `valign--cell-content-config'."
(cl-labels ((valign--put-ov
(beg end xpos)
(valign--put-overlay beg end 'display
- [elpa] externals/valign e91abf2 112/198: Extract out boilerplate from valign-table, (continued)
- [elpa] externals/valign e91abf2 112/198: Extract out boilerplate from valign-table, Stefan Monnier, 2020/12/01
- [elpa] externals/valign d799e31 181/198: ; * valign.el (valign--cell-content-config): Fix typo., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 9fc0c11 149/198: Use new function to calculate space and bar width, Stefan Monnier, 2020/12/01
- [elpa] externals/valign d18aea8 183/198: Improve error handling, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 62766e7 184/198: Add custom group, Stefan Monnier, 2020/12/01
- [elpa] externals/valign bf68d39 171/198: Remove single-column style, Stefan Monnier, 2020/12/01
- [elpa] externals/valign ce1a53c 188/198: ; * test.org: Update., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 82be45d 198/198: Bug fix, Stefan Monnier, 2020/12/01
- [elpa] externals/valign cf3a794 099/198: Fix: cursor disappears on bars when fancy-bar is t, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 0e77a02 164/198: Add some commands that suppresses auto alignment, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 7afe578 182/198: Improve documentation,
Stefan Monnier <=
- [elpa] externals/valign e0362c0 156/198: * valign.el (valign-region): Report to jit-lock the actual end of fontified region., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 841925f 189/198: Remove all advice when they are not needed, Stefan Monnier, 2020/12/01
- [elpa] externals/valign e438083 103/198: Change text property to overlay, Stefan Monnier, 2020/12/01
- [elpa] externals/valign cd2b563 191/198: * valign.el: Bump version to 3.0.0., Stefan Monnier, 2020/12/01