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

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

[elpa] externals/latex-table-wizard 9ce3165694 32/70: Add center and rig


From: ELPA Syncer
Subject: [elpa] externals/latex-table-wizard 9ce3165694 32/70: Add center and right alignment
Date: Sat, 13 May 2023 08:59:12 -0400 (EDT)

branch: externals/latex-table-wizard
commit 9ce3165694f84be20e6ea58cf3f62fea8f7f3643
Author: Enrico Flor <nericoflor@gmail.com>
Commit: Enrico Flor <nericoflor@gmail.com>

    Add center and right alignment
---
 latex-table-wizard.el | 40 +++++++++++++++++++++++++++++++---------
 readme.org            |  6 ++++--
 2 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/latex-table-wizard.el b/latex-table-wizard.el
index 4a8d8c4c3a..79902348a6 100644
--- a/latex-table-wizard.el
+++ b/latex-table-wizard.el
@@ -5,7 +5,7 @@
 ;; Author: Enrico Flor <enrico@eflor.net>
 ;; Maintainer: Enrico Flor <enrico@eflor.net>
 ;; URL: https://github.com/enricoflor/latex-table-wizard
-;; Version: 0.2.1
+;; Version: 0.3.0
 
 ;; Package-Requires: ((emacs "27.1") (auctex "12.1") (transient "0.3.7"))
 
@@ -403,9 +403,8 @@ Each value is an integer, S and E are markers."
                     (point-marker)))
          (hash (secure-hash 'sha256
                             (buffer-substring-no-properties env-beg env-end)))
-         (col-re
-          (latex-table-wizard--disjoin
-           latex-table-wizard--current-col-delims))
+         (col-re (latex-table-wizard--disjoin
+                  latex-table-wizard--current-col-delims))
          (row-re (latex-table-wizard--disjoin
                   latex-table-wizard--current-row-delims)))
     (if (and (equal `(,env-beg . ,env-end) (nth 0 latex-table-wizard--parse))
@@ -850,13 +849,19 @@ Don't print any message if NO-MESSAGE is non-nil."
         (goto-char x)
         (just-one-space)))))
 
+(defvar-local latex-table-wizard--align-status '(left center right))
+
 (defun latex-table-wizard-align ()
   "Align and format table at point.
 
 Have every row start on its own line and vertically align column
-delimiters."
+delimiters.
+
+Cycle through three modes of alignment for the text in the cells:
+align left, center and right."
   (interactive)
-  (let ((max-col (thread-last (latex-table-wizard--parse-table)
+  (let ((mode (car latex-table-wizard--align-status))
+        (max-col (thread-last (latex-table-wizard--parse-table)
                               (mapcar (lambda (x) (plist-get x :column)))
                               (delete-dups)
                               (apply #'max))))
@@ -879,9 +884,26 @@ delimiters."
               (dolist (cell line)
                 (goto-char (plist-get cell :end))
                 (when (< (current-column) longest)
-                  (insert (make-string (- longest (current-column))
-                                       (string-to-char " ")))))))
-          (setq count (1+ count)))))))
+                  (let* ((tot (- longest (current-column)))
+                         (pre (/ tot 2))
+                         (post (- tot pre)))
+                    (cond ((eq mode 'left)
+                           (insert (make-string tot
+                                                (string-to-char " "))))
+                          ((eq mode 'right)
+                           (goto-char (plist-get cell :start))
+                           (insert (make-string tot
+                                                (string-to-char " "))))
+                          ((eq mode 'center)
+                           (insert (make-string post
+                                                (string-to-char " ")))
+                           (goto-char (plist-get cell :start))
+                           (insert (make-string pre
+                                                (string-to-char " "))))))))))
+          (setq count (1+ count)))))
+    (setq latex-table-wizard--align-status
+          (append (cdr latex-table-wizard--align-status)
+                  (list (car latex-table-wizard--align-status))))))
 
 (defun latex-table-wizard-right (&optional n)
   "Move point N cells to the right.
diff --git a/readme.org b/readme.org
index 056f6a15ff..0060567735 100644
--- a/readme.org
+++ b/readme.org
@@ -199,8 +199,10 @@ table by removing excess white space at the edges of each 
cell, call
 ~latex-table-wizard-clean-whitespace~.
 
 Call ~latex-table-wizard-align~ if you want the columns to be vertically
-aligned too (and each row starting on its own line).  This alignment
-command tries to be smart and not be fooled by column or row
+aligned too (and each row starting on its own line).  If you call this
+command repeatedly, it will cycle through three modes of alignment of
+the text in the cells: align text left, center, and right.  This
+alignment command tries to be smart and not be fooled by column or row
 delimiters embedded in a cell.
 
 | Command                             | Default key |



reply via email to

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