[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/valign 1d915f7 024/198: Merge pull request #1 from tuma
From: |
Stefan Monnier |
Subject: |
[elpa] externals/valign 1d915f7 024/198: Merge pull request #1 from tumashu/master |
Date: |
Tue, 1 Dec 2020 18:19:09 -0500 (EST) |
branch: externals/valign
commit 1d915f7f1dda9795cde3ed4bc4378edc991206f8
Merge: f4235e7 eea08cc
Author: Yuan Fu <casouri@gmail.com>
Commit: GitHub <noreply@github.com>
Merge pull request #1 from tumashu/master
Add valign-mode.
---
valign.el | 69 ++++++++++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 48 insertions(+), 21 deletions(-)
diff --git a/valign.el b/valign.el
index fbde10b..50d446c 100644
--- a/valign.el
+++ b/valign.el
@@ -1,6 +1,10 @@
;;; valign.el --- Visually align tables -*- lexical-binding: t; -*-
;; Author: Yuan Fu <casouri@gmail.com>
+;; URL: https://github.com/casouri/valign
+;; Version: 0.1.0
+;; Keywords: convenience
+;; Package-Requires: ((emacs "26.0"))
;;; This file is NOT part of GNU Emacs
@@ -8,15 +12,15 @@
;;
;; This package provides visual alignment for Org tables on GUI Emacs.
;; It can properly align tables containing variable-pitch font, CJK
-;; characters and images. In the meantime, the text-based alignment
+;; characters and images. In the meantime, the text-based alignment
;; generated by Org mode is left untouched.
;;
-;; To use this package, load it and run M-x valign-setup RET. And any
-;; Org tables in Org mode should be automatically aligned. If you want
+;; To use this package, load it and run M-x valign-setup RET. And any
+;; Org tables in Org mode should be automatically aligned. If you want
;; to align a table manually, run M-x valign-table RET on a Org table.
;;
;; Valign provides two styles of separator, |-----|-----|, and
-;; | |. Customize ‘valign-separator-row-style’ to set a
+;; | |. Customize ‘valign-separator-row-style’ to set a
;; style.
;;; Code:
@@ -25,6 +29,11 @@
(require 'cl-lib)
(require 'pcase)
+(defcustom valign-lighter " valign"
+ "The lighter string used by function `valign-mode'."
+ :group 'valign
+ :type 'string)
+
;;; Backstage
(define-error 'valign-bad-cell "Valign encountered a invalid table cell")
@@ -77,7 +86,7 @@ Return nil if not in a cell."
(defun valign--glyph-width-at-point (&optional point)
"Return the pixel width of the glyph at POINT.
-The buffer has to be visible. If point is at an image, this
+The buffer has to be visible. If point is at an image, this
function doens’t return the image’s width, but the underlining
character’s glyph width."
(let* ((p (or point (point))))
@@ -88,7 +97,7 @@ character’s glyph width."
(defun valign--pixel-width-from-to (from to)
"Return the width of the glyphs from FROM (inclusive) to TO (exclusive).
-The buffer has to be visible. FROM has to be less than TO. Unlike
+The buffer has to be visible. FROM has to be less than TO. Unlike
‘valign--glyph-width-at-point’, this function can properly
calculate images pixel width."
(let ((width 0))
@@ -202,7 +211,7 @@ Start from point, stop at LIMIT."
(defun valign--beginning-of-table ()
"Go backward to the beginning of the table at point.
-Assumes point is on a table. Return nil if failed, point
+Assumes point is on a table. Return nil if failed, point
otherwise."
(beginning-of-line)
(if (not (eq (char-after) ?|))
@@ -215,7 +224,7 @@ otherwise."
(defun valign--end-of-table ()
"Go forward to the end of the table at point.
-Assumes point is on a table. Return nil if failed, point
+Assumes point is on a table. Return nil if failed, point
otherwise."
(beginning-of-line)
(if (not (eq (char-after) ?|))
@@ -280,7 +289,7 @@ Force align if FORCE non-nil."
(defun valign--align-separator-row (total-width)
"Align the separator row (|---+---|) as “| |”.
-Assumes the point is after the left bar (“|”). TOTAL-WIDTH is the
+Assumes the point is after the left bar (“|”). TOTAL-WIDTH is the
pixel width counting from the left of the left bar to the left of
the right bar."
(let ((p (point)))
@@ -324,7 +333,7 @@ the position for the right bar (“|”)."
(defcustom valign-separator-row-style 'multi-column
"The style of the separator row of a table.
Valign can render it as “| |”
-or as “|-----|-----|”. Set this option to 'single-column
+or as “|-----|-----|”. Set this option to 'single-column
for the former, and 'multi-column for the latter."
:type 'symbol
:group 'valign)
@@ -437,23 +446,41 @@ for the former, and 'multi-column for the latter."
(valign--separator-row-add-overlay
p (1- (point))
(or (nth col-idx (reverse rev-list)) 0)))))))))
-
+
(valign-bad-cell (message (error-message-string err)))
(valign-werid-alignment (message (error-message-string err)))))
+(defun valign-org-mode-hook ()
+ "Valign hook function use by `org-mode'."
+ (add-hook 'jit-lock-functions
+ #'valign-initial-alignment 90 t))
+
+(defun valign-org-agenda-finalize-hook ()
+ "Valign hook function use by `org-agenda-finalize-hook'."
+ (valign-initial-alignment
+ (point-min) (point-max) t))
+
+(define-minor-mode valign-mode
+ "valign minor mode."
+ :global t
+ :require 'valign
+ :group 'valign
+ :lighter valign-lighter
+ (if (and valign-mode window-system)
+ (progn
+ (add-hook 'org-mode-hook #'valign-org-mode-hook)
+ (add-hook 'org-agenda-finalize-hook #'valign-org-agenda-finalize-hook)
+ (advice-add 'org-table-next-field :after #'valign-table)
+ (advice-add 'org-table-previous-field :after #'valign-table))
+ (remove-hook 'org-mode-hook #'valign-org-mode-hook)
+ (remove-hook 'org-agenda-finalize-hook #'valign-org-agenda-finalize-hook)
+ (advice-remove 'org-table-next-field #'valign-table)
+ (advice-remove 'org-table-previous-field #'valign-table)))
+
(defun valign-setup ()
"Enable visual table alignment."
(interactive)
- (when window-system
- (add-hook 'org-mode-hook
- (lambda ()
- (add-hook 'jit-lock-functions
- #'valign-initial-alignment 90 t)))
- (advice-add #'org-table-next-field :after #'valign-table)
- (advice-add #'org-table-previous-field :after #'valign-table)
- (add-hook 'org-agenda-finalize-hook
- (lambda () (valign-initial-alignment
- (point-min) (point-max) t)))))
+ (valign-mode 1))
(provide 'valign)
- [elpa] externals/valign 57b004d 004/198: * README.org: Move image down., (continued)
- [elpa] externals/valign 57b004d 004/198: * README.org: Move image down., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 056138e 007/198: * valign.el (valign--cell-alignment): Fix unused variable., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 6f813f3 009/198: Add images, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 4146b5d 005/198: * valign.el (valign-table): Don’t align separator row if don’t exist., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 9f2bc32 010/198: Add another separator row style., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 29bf04f 001/198: Init, Stefan Monnier, 2020/12/01
- [elpa] externals/valign a28b966 006/198: * valign.el (valign--cell-width): Fix symbol-not-found, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 8c05580 016/198: * valign.el (valign-table): Fix separator alignment., Stefan Monnier, 2020/12/01
- [elpa] externals/valign f8a4a38 013/198: Fix case for multiple separator rows, Stefan Monnier, 2020/12/01
- [elpa] externals/valign f0c030e 018/198: * valign.el (valign--pixel-width-from-to): Support invisible text., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 1d915f7 024/198: Merge pull request #1 from tumashu/master,
Stefan Monnier <=
- [elpa] externals/valign 954906d 028/198: Add more hooks, Stefan Monnier, 2020/12/01
- [elpa] externals/valign eb787e7 008/198: * table.png: Delete file., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 4af6efd 017/198: Support overlay image, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 25b75fc 015/198: Support Emacs 26, Stefan Monnier, 2020/12/01
- [elpa] externals/valign f4235e7 019/198: Add support for Org Agenda, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 586bba2 020/198: Fix package-lint and checkdoc warns, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 8618a44 021/198: Add valign-mode, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 9a9a4a1 022/198: Merge branch 'master' into master, Stefan Monnier, 2020/12/01
- [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