[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ftable 1ea20be 11/14: Allow non-table lines before and
From: |
Stefan Monnier |
Subject: |
[elpa] externals/ftable 1ea20be 11/14: Allow non-table lines before and after table |
Date: |
Mon, 2 Aug 2021 18:27:32 -0400 (EDT) |
branch: externals/ftable
commit 1ea20be274f278df3953cea4720f776adad43616
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Allow non-table lines before and after table
* ftable.el (ftable--at-table-p, ftable--beginning-of-table,
ftable--end-of-table): New functions.
(ftable--table-info): Use new functions.
---
ftable.el | 54 ++++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 46 insertions(+), 8 deletions(-)
diff --git a/ftable.el b/ftable.el
index e0f8136..27178dc 100644
--- a/ftable.el
+++ b/ftable.el
@@ -575,6 +575,46 @@ STYLE can be ’ascii or ’unicode."
(when cell-p
#'table-recognize-region)))))
+(defun ftable--at-table-p ()
+ "Return non-nil if point is in a table."
+ (save-excursion
+ (beginning-of-line)
+ (skip-chars-forward " \t")
+ (member (char-to-string (char-after))
+ (append
+ (cl-loop for elt in ftable-box-charset-alist
+ for charset = (cdr elt)
+ collect (valign-box-char 1 charset)
+ collect (valign-box-char 4 charset)
+ collect (valign-box-char 7 charset)
+ collect (valign-box-char 'v charset))))))
+
+(defun ftable--beginning-of-table ()
+ "Go backward to the beginning of the table at point.
+Assumes point is on a table."
+ ;; This implementation allows non-table lines before a table, e.g.,
+ ;; #+latex: xxx
+ ;; |------+----|
+ (beginning-of-line)
+ (while (and (< (point-min) (point))
+ (ftable--at-table-p))
+ (forward-line -1))
+ (unless (valign--at-table-p)
+ (forward-line 1)))
+
+(defun ftable--end-of-table ()
+ "Go forward to the end of the table at point.
+Assumes point is on a table."
+ (let ((start (point)))
+ (beginning-of-line)
+ (while (and (< (point) (point-max))
+ (ftable--at-table-p))
+ (forward-line 1))
+ (unless (<= (point) start)
+ (skip-chars-backward "\n"))
+ (when (< (point) start)
+ (error "End of table goes backwards"))))
+
(defun ftable--table-info ()
"Return (TEXT BEG END TABLE-CELL-P TABLEP CHARSET).
TEXT is the table’s text. BEG and END are the beginning and end
@@ -583,14 +623,12 @@ is t if the table is managed by table.el. TABLEP is t if
point is
on a table, nil if not. CHARSET is the box drawing charset used
by the table (if there is a table). \(See
`ftable-box-charset-alist'.)"
- (let* ((beg (save-excursion (if (not (search-backward "\n\n" nil t))
- (point-min))
- (skip-chars-forward "\n")
- (point)))
- (end (save-excursion (if (not (search-forward "\n\n" nil t))
- (point-max)
- (skip-chars-backward "\n")
- (point))))
+ (let* ((beg (save-excursion
+ (ftable--beginning-of-table)
+ (point)))
+ (end (save-excursion
+ (ftable--end-of-table)
+ (point)))
(text (buffer-substring-no-properties beg end))
(table-cell-p (text-property-any beg end 'table-cell t)))
(append (list text beg end table-cell-p)
- [elpa] branch externals/ftable created (now 96a0475), Stefan Monnier, 2021/08/02
- [elpa] externals/ftable ec019c2 06/14: Add customization, Stefan Monnier, 2021/08/02
- [elpa] externals/ftable 2b08dc9 01/14: Init, Stefan Monnier, 2021/08/02
- [elpa] externals/ftable 63fb0ac 04/14: Add checks for parsing, Stefan Monnier, 2021/08/02
- [elpa] externals/ftable 9c13bfc 07/14: Add table.el intergration, Stefan Monnier, 2021/08/02
- [elpa] externals/ftable 71dcbd0 12/14: Fix beginning- and end-of-table function, Stefan Monnier, 2021/08/02
- [elpa] externals/ftable 939cc1b 13/14: Fix typo, Stefan Monnier, 2021/08/02
- [elpa] externals/ftable 1ea20be 11/14: Allow non-table lines before and after table,
Stefan Monnier <=
- [elpa] externals/ftable 96a0475 14/14: Prepare for ELPA, Stefan Monnier, 2021/08/02
- [elpa] externals/ftable a647832 03/14: xx, Stefan Monnier, 2021/08/02
- [elpa] externals/ftable 8ff305b 02/14: Not use forward-paragraph, Stefan Monnier, 2021/08/02
- [elpa] externals/ftable e029b2f 10/14: * ftable.el: Add a workaround., Stefan Monnier, 2021/08/02
- [elpa] externals/ftable d2385e3 05/14: * ftable.el (ftable-misc-test): Fix test., Stefan Monnier, 2021/08/02
- [elpa] externals/ftable 9f75340 08/14: Make ftable work with CJK characters, Stefan Monnier, 2021/08/02
- [elpa] externals/ftable 33b32ba 09/14: * ftable.el (ftable-edit-cell): Fix typos., Stefan Monnier, 2021/08/02