summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2015-05-08 10:46:07 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2015-05-08 10:46:07 +0200
commit6ac8db9dbabd83152612c65a9cd505390a1915d1 (patch)
tree2eab090a7209a06fc91e540cf4c07f051768a070
parent4980a9dbb8ff1690abb54066da0827e1c37378c8 (diff)
downloadorg-mode-6ac8db9dbabd83152612c65a9cd505390a1915d1.tar.gz
Fix TBLFM line handling
* lisp/org-table.el (org-table-TBLFM-begin-regexp): Take into consideration that table lines are not required to end with "|". (org-table-calc-current-TBLFM): Properly clean markers at the end of the process. (org-table-TBLFM-begin): Small refactoring. * lisp/org.el (org-at-TBLFM-p): Prevent false positives. Suggested-by: Oleg Sivokon <olegsivokon@gmail.com> <http://permalink.gmane.org/gmane.emacs.orgmode/97461>
-rw-r--r--lisp/org-table.el34
-rwxr-xr-xlisp/org.el8
2 files changed, 20 insertions, 22 deletions
diff --git a/lisp/org-table.el b/lisp/org-table.el
index a644008..89f8733 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -56,7 +56,7 @@ This can be used to add additional functionality after the table is sent
to the receiver position, otherwise, if table is not sent, the functions
are not run.")
-(defvar org-table-TBLFM-begin-regexp "|\n[ \t]*#\\+TBLFM: ")
+(defvar org-table-TBLFM-begin-regexp "^[ \t]*|.*\n[ \t]*#\\+TBLFM: ")
(defcustom orgtbl-optimized (eq org-enable-table-editor 'optimized)
"Non-nil means use the optimized table editor version for `orgtbl-mode'.
@@ -3327,33 +3327,31 @@ with the prefix ARG."
(interactive "P")
(unless (org-at-TBLFM-p) (user-error "Not at a #+TBLFM line"))
(let ((formula (buffer-substring
- (point-at-bol)
- (point-at-eol)))
- s e)
+ (line-beginning-position)
+ (line-end-position))))
(save-excursion
;; Insert a temporary formula at right after the table
(goto-char (org-table-TBLFM-begin))
- (setq s (set-marker (make-marker) (point)))
- (insert (concat formula "\n"))
- (setq e (set-marker (make-marker) (point)))
- ;; Recalculate the table
- (beginning-of-line 0) ; move to the inserted line
- (skip-chars-backward " \r\n\t")
- (if (org-at-table-p)
+ (let ((s (point-marker)))
+ (insert formula "\n")
+ (let ((e (point-marker)))
+ ;; Recalculate the table.
+ (beginning-of-line 0) ; move to the inserted line
+ (skip-chars-backward " \r\n\t")
(unwind-protect
- (org-call-with-arg 'org-table-recalculate (or arg t))
- ;; delete the formula inserted temporarily
- (delete-region s e))))))
+ (org-call-with-arg #'org-table-recalculate (or arg t))
+ ;; Delete the formula inserted temporarily.
+ (delete-region s e)
+ (set-marker s nil)
+ (set-marker e nil)))))))
(defun org-table-TBLFM-begin ()
"Find the beginning of the TBLFM lines and return its position.
Return nil when the beginning of TBLFM line was not found."
(save-excursion
(when (progn (forward-line 1)
- (re-search-backward
- org-table-TBLFM-begin-regexp
- nil t))
- (point-at-bol 2))))
+ (re-search-backward org-table-TBLFM-begin-regexp nil t))
+ (line-beginning-position 2))))
(defun org-table-expand-lhs-ranges (equations)
"Expand list of formulas.
diff --git a/lisp/org.el b/lisp/org.el
index 3f1b6c3..7dc5f6d 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -4577,12 +4577,12 @@ If TABLE-TYPE is non-nil, also check for table.el-type tables."
(&optional also-non-dangling-p prompt last-valid))
(defun org-at-TBLFM-p (&optional pos)
- "Return t when point (or POS) is in #+TBLFM line."
+ "Non-nil when point (or POS) is in #+TBLFM line."
(save-excursion
- (let ((pos pos)))
(goto-char (or pos (point)))
- (beginning-of-line 1)
- (looking-at org-TBLFM-regexp)))
+ (beginning-of-line)
+ (and (eq (org-element-type (org-element-at-point)) 'table)
+ (looking-at org-TBLFM-regexp))))
(defvar org-clock-start-time)
(defvar org-clock-marker (make-marker)