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

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

[elpa] externals/valign 0fe9416 06/11: Add valign-max-table-size


From: Stefan Monnier
Subject: [elpa] externals/valign 0fe9416 06/11: Add valign-max-table-size
Date: Thu, 28 Jan 2021 00:10:24 -0500 (EST)

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

    Add valign-max-table-size
    
    * README.org: Add explanation.
    * valign.el (Commentary): Add customization section.
    (valign-not-align-after-list): Change to custom option.
    (valign-max-table-size): New custom option.
    (valign-table-fallback): New face.
    (valign-table-maybe): Don't align table if size exceeds
    'valign-max-table-size', instead, put 'valign-table-fallback' face on.
---
 README.org |  6 +++++-
 valign.el  | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++-----------
 2 files changed, 56 insertions(+), 12 deletions(-)

diff --git a/README.org b/README.org
index 98280f8..53e4963 100644
--- a/README.org
+++ b/README.org
@@ -14,6 +14,7 @@ To use this package, load it and add ~valign-mode~ to 
~org-mode-hook~ or ~markdo
 *Know problems:*
 - 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.
+- ~org-indent-mode~ plus ~display-line-numbers-mode~ causes alignment problems.
 
 *Note:*
 
@@ -26,7 +27,6 @@ You can obtain valign.el from GNU ELPA by typing:
 M-x package-install RET valign RET
 #+end_src
 
-
 * Customization
 Set ~valign-fancy-bar~ to ~non-nil~:
 
@@ -34,5 +34,9 @@ Set ~valign-fancy-bar~ to ~non-nil~:
 
 This only affects Org Mode and Markdown tables.
 
+By default, valign doesn’t re-align the table after normal edit commands like 
~self-insert-command~ and ~backward-kill-word~. If you want valign to not 
re-align the table after a certain command, add that command to 
~valign-not-align-after-list~.
+
+Because valign isn’t particularly efficient, it doesn’t align tables larger 
than 4000 characters in size. If you want to change that behavior, customize 
~valign-max-table-size~. Valign puts ~valign-table-fallback~ face on those 
large tables.
+
 * If function advice makes you itch
 ~valign-mode~ adds advice and doesn’t remove them even if you close 
~valign-mode~ because function advice is global and ~valign-mode~ is local. If 
you want to remove the advice, use ~valign-remove-advice~. If you run this 
while some buffer still has ~valign-mode~ on, they break.
diff --git a/valign.el b/valign.el
index d56aaed..9b83371 100644
--- a/valign.el
+++ b/valign.el
@@ -45,6 +45,22 @@
 ;;
 ;; - Hidden links in markdown still occupy the full length of the link
 ;;   because it uses character composition, which we don’t support.
+;;
+;; Customization
+;;
+;; valign-fancy-bar               If non-nil, use pretty vertical bars.
+;; valign-not-align-after-list    Valign doesn't align after these
+;;                                commands.
+;; valign-signal-parse-error      If non-nil, emit parse errors.
+;; valign-max-table-size          Valign doesn't align tables of size
+;;                                larger than this value.
+;; valign-table-fallback          Face for tables that are not aligned
+;;                                because of their size.
+;;
+;; Uninteresting variables
+;;
+;; valign-lighter
+;; valign-box-charset-alist
 
 ;;; Developer:
 ;;
@@ -672,18 +688,32 @@ COLUMN-WIDTH-LIST is returned by 
`valign--calculate-cell-width'."
 
 ;;; Align
 
-(defvar valign-not-align-after-list '(self-insert-command
-                                      org-self-insert-command
-                                      markdown-outdent-or-delete
-                                      org-delete-backward-char
-                                      backward-kill-word
-                                      delete-char
-                                      kill-word)
-  "Valign doesn’t align table after these commands.")
+(defcustom valign-not-align-after-list '(self-insert-command
+                                         org-self-insert-command
+                                         markdown-outdent-or-delete
+                                         org-delete-backward-char
+                                         backward-kill-word
+                                         delete-char
+                                         kill-word)
+  "Valign doesn’t align table after these commands."
+  :type '(list symbol)
+  :group 'valign)
 
 (defvar valign-signal-parse-error nil
   "When non-nil, signal parse error.")
 
+(defcustom valign-max-table-size 4000
+  "Valign doesn't align tables of size larger than this value.
+Valign puts `valign-table-fallback' face onto these tables.  If the
+value is zero, valign doesn't check for table sizes."
+  :type 'integer
+  :group 'valign)
+
+(defface valign-table-fallback
+  '((t . (:inherit fixed-pitch)))
+  "Fallback face for tables whose size exceeds `valign-max-table-size'."
+  :group 'valign)
+
 (defun valign-table-maybe (&optional force go-to-end)
   "Visually align the table at point.
 If FORCE non-nil, force align.  If GO-TO-END non-nil, leave point
@@ -697,9 +727,19 @@ at the end of the table."
                                 valign-not-align-after-list))))
         (save-excursion
           (valign--beginning-of-table)
-          (if (valign--guess-charset)
-              (valign--table-2)
-            (valign-table-1)))
+          (let ((table-beg (point))
+                (table-end (save-excursion
+                             (valign--end-of-table)
+                             (point))))
+            (if (or (eq valign-max-table-size 0)
+                    (<= (- table-end table-beg) valign-max-table-size))
+                (if (valign--guess-charset)
+                    (valign--table-2)
+                  (valign-table-1))
+              ;; Can't align the table, put fallback-face on.
+              (valign--clean-text-property table-beg table-end)
+              (valign--put-overlay table-beg table-end
+                                   'face 'valign-table-fallback))))
         (when go-to-end (valign--end-of-table)))
 
     ((debug valign-parse-error error)



reply via email to

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