branch: externals/valign
commit 638f9784cf7b6b2ace9d9ec8956bb1ca185eced0
Author: Yuan Fu <[email protected]>
Commit: Yuan Fu <[email protected]>
Fix infinite loop!!
* (valign--beginning-of-table, valign--end-of-table): Fix.
---
valign.el | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/valign.el b/valign.el
index 0bc50d9..79eab0c 100644
--- a/valign.el
+++ b/valign.el
@@ -303,17 +303,29 @@ Assumes point is on a table. Return nil if failed, point
otherwise."
(beginning-of-line)
(if (not (looking-at "[ \t]*|")) nil
- (while (re-search-backward "^[ \t]*|" nil t))
+ (condition-case nil
+ (while (looking-at "[ \t]*|")
+ (search-backward "\n")
+ (beginning-of-line))
+ (search-failed nil))
(point)))
(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
otherwise."
- (beginning-of-line)
- (if (not (looking-at "[ \t]*|")) nil
- (while (re-search-forward "|[^|\n]*$" nil t))
- (point)))
+ (let ((p (point)))
+ (beginning-of-line)
+ (if (not (looking-at "[ \t]*|"))
+ (progn (goto-char p) nil)
+ (condition-case nil
+ (while (looking-at "[ \t]*|")
+ ;; Each iteration the point is at BOL.
+ (search-forward "\n" nil))
+ (search-failed nil))
+ ;; Point at the line after the last line of the table.
+ (backward-char)
+ (point))))
(defun valign--put-text-property (beg end xpos)
"Put text property on text from BEG to END.