2008-03-22 11:52:18 -04:00
|
|
|
;;; org-table.el --- The table editor for Org-mode
|
|
|
|
|
2014-01-07 08:18:17 -05:00
|
|
|
;; Copyright (C) 2004-2014 Free Software Foundation, Inc.
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
;; Author: Carsten Dominik <carsten at orgmode dot org>
|
|
|
|
;; Keywords: outlines, hypermedia, calendar, wp
|
|
|
|
;; Homepage: http://orgmode.org
|
|
|
|
;;
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;;
|
2008-05-06 08:45:52 -04:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2008-03-22 11:52:18 -04:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 08:45:52 -04:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2008-05-06 08:45:52 -04:00
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
2008-03-22 11:52:18 -04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;
|
|
|
|
;;; Commentary:
|
|
|
|
|
2008-12-16 11:49:26 -05:00
|
|
|
;; This file contains the table editor and spreadsheet for Org-mode.
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
;; Watch out: Here we are talking about two different kind of tables.
|
|
|
|
;; Most of the code is for the tables created with the Org-mode table editor.
|
|
|
|
;; Sometimes, we talk about tables created and edited with the table.el
|
|
|
|
;; Emacs package. We call the former org-type tables, and the latter
|
|
|
|
;; table.el-type tables.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(eval-when-compile
|
|
|
|
(require 'cl))
|
|
|
|
(require 'org)
|
|
|
|
|
2013-01-27 17:44:27 -05:00
|
|
|
(declare-function org-export-string-as "ox"
|
|
|
|
(string backend &optional body-only ext-plist))
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
(declare-function org-export-create-backend "ox")
|
|
|
|
(declare-function org-export-get-backend "ox" (name))
|
|
|
|
|
2014-05-20 15:44:37 -04:00
|
|
|
(declare-function calc-eval "calc" (str &optional separator &rest args))
|
2014-08-20 08:32:47 -04:00
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
(defvar orgtbl-mode) ; defined below
|
|
|
|
(defvar orgtbl-mode-menu) ; defined when orgtbl mode get initialized
|
|
|
|
(defvar constants-unit-system)
|
2011-06-01 02:41:20 -04:00
|
|
|
(defvar org-table-follow-field-mode)
|
2008-03-22 11:52:18 -04:00
|
|
|
|
2010-11-17 07:58:52 -05:00
|
|
|
(defvar orgtbl-after-send-table-hook nil
|
|
|
|
"Hook for functions attaching to `C-c C-c', if the table is sent.
|
|
|
|
This can be used to add additional functionality after the table is sent
|
2012-01-10 05:56:15 -05:00
|
|
|
to the receiver position, otherwise, if table is not sent, the functions
|
2010-11-17 07:58:52 -05:00
|
|
|
are not run.")
|
|
|
|
|
2013-05-15 10:18:37 -04:00
|
|
|
(defvar org-table-TBLFM-begin-regexp "|\n[ \t]*#\\+TBLFM: ")
|
2013-04-02 05:09:26 -04:00
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
(defcustom orgtbl-optimized (eq org-enable-table-editor 'optimized)
|
2010-01-21 10:15:40 -05:00
|
|
|
"Non-nil means use the optimized table editor version for `orgtbl-mode'.
|
2008-03-22 11:52:18 -04:00
|
|
|
In the optimized version, the table editor takes over all simple keys that
|
|
|
|
normally just insert a character. In tables, the characters are inserted
|
|
|
|
in a way to minimize disturbing the table structure (i.e. in overwrite mode
|
|
|
|
for empty fields). Outside tables, the correct binding of the keys is
|
|
|
|
restored.
|
|
|
|
|
|
|
|
The default for this option is t if the optimized version is also used in
|
|
|
|
Org-mode. See the variable `org-enable-table-editor' for details. Changing
|
|
|
|
this variable requires a restart of Emacs to become effective."
|
|
|
|
:group 'org-table
|
|
|
|
:type 'boolean)
|
|
|
|
|
|
|
|
(defcustom orgtbl-radio-table-templates
|
|
|
|
'((latex-mode "% BEGIN RECEIVE ORGTBL %n
|
|
|
|
% END RECEIVE ORGTBL %n
|
|
|
|
\\begin{comment}
|
|
|
|
#+ORGTBL: SEND %n orgtbl-to-latex :splice nil :skip 0
|
|
|
|
| | |
|
|
|
|
\\end{comment}\n")
|
|
|
|
(texinfo-mode "@c BEGIN RECEIVE ORGTBL %n
|
|
|
|
@c END RECEIVE ORGTBL %n
|
|
|
|
@ignore
|
|
|
|
#+ORGTBL: SEND %n orgtbl-to-html :splice nil :skip 0
|
|
|
|
| | |
|
|
|
|
@end ignore\n")
|
|
|
|
(html-mode "<!-- BEGIN RECEIVE ORGTBL %n -->
|
|
|
|
<!-- END RECEIVE ORGTBL %n -->
|
|
|
|
<!--
|
|
|
|
#+ORGTBL: SEND %n orgtbl-to-html :splice nil :skip 0
|
|
|
|
| | |
|
2012-07-31 09:40:05 -04:00
|
|
|
-->\n")
|
|
|
|
(org-mode "#+ BEGIN RECEIVE ORGTBL %n
|
|
|
|
#+ END RECEIVE ORGTBL %n
|
|
|
|
|
|
|
|
#+ORGTBL: SEND %n orgtbl-to-orgtbl :splice nil :skip 0
|
|
|
|
| | |
|
|
|
|
"))
|
2008-03-22 11:52:18 -04:00
|
|
|
"Templates for radio tables in different major modes.
|
2013-09-02 05:33:54 -04:00
|
|
|
Each template must define lines that will be treated as a comment and that
|
|
|
|
must contain the \"BEGIN RECEIVE ORGTBL %n\" and \"END RECEIVE ORGTBL\"
|
|
|
|
lines where \"%n\" will be replaced with the name of the table during
|
2013-11-17 03:12:41 -05:00
|
|
|
insertion of the template. The transformed table will later be inserted
|
2013-09-02 05:33:54 -04:00
|
|
|
between these lines.
|
|
|
|
|
|
|
|
The template should also contain a minimal table in a multiline comment.
|
2013-11-17 03:12:41 -05:00
|
|
|
If multiline comments are not possible in the buffer language,
|
2013-09-02 05:33:54 -04:00
|
|
|
you can pack it into a string that will not be used when the code
|
|
|
|
is compiled or executed. Above the table will you need a line with
|
|
|
|
the fixed string \"#+ORGTBL: SEND\", followed by instruction on how to
|
|
|
|
convert the table into a data structure useful in the
|
|
|
|
language of the buffer. Check the manual for the section on
|
|
|
|
\"Translator functions\", and more generally check out
|
|
|
|
http://orgmode.org/manual/Tables-in-arbitrary-syntax.html#Tables-in-arbitrary-syntax
|
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
All occurrences of %n in a template will be replaced with the name of the
|
|
|
|
table, obtained by prompting the user."
|
|
|
|
:group 'org-table
|
|
|
|
:type '(repeat
|
|
|
|
(list (symbol :tag "Major mode")
|
|
|
|
(string :tag "Format"))))
|
|
|
|
|
|
|
|
(defgroup org-table-settings nil
|
|
|
|
"Settings for tables in Org-mode."
|
|
|
|
:tag "Org Table Settings"
|
|
|
|
:group 'org-table)
|
|
|
|
|
|
|
|
(defcustom org-table-default-size "5x2"
|
|
|
|
"The default size for newly created tables, Columns x Rows."
|
|
|
|
:group 'org-table-settings
|
2012-08-11 13:10:44 -04:00
|
|
|
:type 'string)
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defcustom org-table-number-regexp
|
2012-12-28 09:00:03 -05:00
|
|
|
"^\\([<>]?[-+^.0-9]*[0-9][-+^.0-9eEdDx()%:]*\\|[<>]?[-+]?0[xX][0-9a-fA-F.]+\\|[<>]?[-+]?[0-9]+#[0-9a-zA-Z.]+\\|nan\\|[-+u]?inf\\)$"
|
2008-03-22 11:52:18 -04:00
|
|
|
"Regular expression for recognizing numbers in table columns.
|
|
|
|
If a table column contains mostly numbers, it will be aligned to the
|
|
|
|
right. If not, it will be aligned to the left.
|
|
|
|
|
|
|
|
The default value of this option is a regular expression which allows
|
|
|
|
anything which looks remotely like a number as used in scientific
|
|
|
|
context. For example, all of the following will be considered a
|
|
|
|
number:
|
2012-08-27 11:55:05 -04:00
|
|
|
12 12.2 2.4e-08 2x10^12 4.034+-0.02 2.7(10) >3.5
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
Other options offered by the customize interface are more restrictive."
|
|
|
|
:group 'org-table-settings
|
|
|
|
:type '(choice
|
|
|
|
(const :tag "Positive Integers"
|
|
|
|
"^[0-9]+$")
|
|
|
|
(const :tag "Integers"
|
|
|
|
"^[-+]?[0-9]+$")
|
|
|
|
(const :tag "Floating Point Numbers"
|
2012-08-27 11:55:18 -04:00
|
|
|
"^[-+]?\\([0-9]*\\.[0-9]+\\|[0-9]+\\.[0-9]*\\)$")
|
2008-03-22 11:52:18 -04:00
|
|
|
(const :tag "Floating Point Number or Integer"
|
2012-08-27 11:55:18 -04:00
|
|
|
"^[-+]?\\([0-9]*\\.[0-9]+\\|[0-9]+\\.?[0-9]*\\)$")
|
2008-03-22 11:52:18 -04:00
|
|
|
(const :tag "Exponential, Floating point, Integer"
|
2012-08-27 11:55:18 -04:00
|
|
|
"^[-+]?[0-9.]+\\([eEdD][-+0-9]+\\)?$")
|
2012-12-28 09:00:03 -05:00
|
|
|
(const :tag "Very General Number-Like, including hex and Calc radix"
|
|
|
|
"^\\([<>]?[-+^.0-9]*[0-9][-+^.0-9eEdDx()%]*\\|[<>]?[-+]?0[xX][0-9a-fA-F.]+\\|[<>]?[-+]?[0-9]+#[0-9a-zA-Z.]+\\|nan\\|[-+u]?inf\\)$")
|
|
|
|
(const :tag "Very General Number-Like, including hex and Calc radix, allows comma as decimal mark"
|
|
|
|
"^\\([<>]?[-+^.,0-9]*[0-9][-+^.0-9eEdDx()%]*\\|[<>]?[-+]?0[xX][0-9a-fA-F.]+\\|[<>]?[-+]?[0-9]+#[0-9a-zA-Z.]+\\|nan\\|[-+u]?inf\\)$")
|
2012-08-27 11:55:18 -04:00
|
|
|
(string :tag "Regexp:")))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defcustom org-table-number-fraction 0.5
|
|
|
|
"Fraction of numbers in a column required to make the column align right.
|
2012-04-23 14:53:51 -04:00
|
|
|
In a column all non-white fields are considered. If at least
|
|
|
|
this fraction of fields is matched by `org-table-number-regexp',
|
2008-03-22 11:52:18 -04:00
|
|
|
alignment to the right border applies."
|
|
|
|
:group 'org-table-settings
|
|
|
|
:type 'number)
|
|
|
|
|
|
|
|
(defgroup org-table-editing nil
|
|
|
|
"Behavior of tables during editing in Org-mode."
|
|
|
|
:tag "Org Table Editing"
|
|
|
|
:group 'org-table)
|
|
|
|
|
|
|
|
(defcustom org-table-automatic-realign t
|
2010-01-21 10:15:40 -05:00
|
|
|
"Non-nil means automatically re-align table when pressing TAB or RETURN.
|
2008-03-22 11:52:18 -04:00
|
|
|
When nil, aligning is only done with \\[org-table-align], or after column
|
|
|
|
removal/insertion."
|
|
|
|
:group 'org-table-editing
|
|
|
|
:type 'boolean)
|
|
|
|
|
|
|
|
(defcustom org-table-auto-blank-field t
|
2010-01-21 10:15:40 -05:00
|
|
|
"Non-nil means automatically blank table field when starting to type into it.
|
2008-03-22 11:52:18 -04:00
|
|
|
This only happens when typing immediately after a field motion
|
|
|
|
command (TAB, S-TAB or RET).
|
|
|
|
Only relevant when `org-enable-table-editor' is equal to `optimized'."
|
|
|
|
:group 'org-table-editing
|
|
|
|
:type 'boolean)
|
|
|
|
|
2011-05-11 03:48:36 -04:00
|
|
|
(defcustom org-table-exit-follow-field-mode-when-leaving-table t
|
|
|
|
"Non-nil means automatically exit the follow mode.
|
|
|
|
When nil, the follow mode will stay on and be active in any table
|
|
|
|
the cursor enters. Since the table follow filed mode messes with the
|
|
|
|
window configuration, it is not recommended to set this variable to nil,
|
|
|
|
except maybe locally in a special file that has mostly tables with long
|
|
|
|
fields."
|
|
|
|
:group 'org-table
|
2012-03-19 16:38:12 -04:00
|
|
|
:version "24.1"
|
2011-05-11 03:48:36 -04:00
|
|
|
:type 'boolean)
|
|
|
|
|
2011-03-05 17:22:32 -05:00
|
|
|
(defcustom org-table-fix-formulas-confirm nil
|
|
|
|
"Whether the user should confirm when Org fixes formulas."
|
|
|
|
:group 'org-table-editing
|
2012-03-19 16:38:12 -04:00
|
|
|
:version "24.1"
|
2011-03-05 17:22:32 -05:00
|
|
|
:type '(choice
|
|
|
|
(const :tag "with yes-or-no" yes-or-no-p)
|
|
|
|
(const :tag "with y-or-n" y-or-n-p)
|
|
|
|
(const :tag "no confirmation" nil)))
|
|
|
|
(put 'org-table-fix-formulas-confirm
|
|
|
|
'safe-local-variable
|
2011-06-14 15:01:04 -04:00
|
|
|
#'(lambda (x) (member x '(yes-or-no-p y-or-n-p))))
|
2011-03-05 17:22:32 -05:00
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
(defcustom org-table-tab-jumps-over-hlines t
|
2010-01-21 10:15:40 -05:00
|
|
|
"Non-nil means tab in the last column of a table with jump over a hline.
|
2008-03-22 11:52:18 -04:00
|
|
|
If a horizontal separator line is following the current line,
|
|
|
|
`org-table-next-field' can either create a new row before that line, or jump
|
|
|
|
over the line. When this option is nil, a new line will be created before
|
|
|
|
this line."
|
|
|
|
:group 'org-table-editing
|
|
|
|
:type 'boolean)
|
|
|
|
|
|
|
|
(defgroup org-table-calculation nil
|
|
|
|
"Options concerning tables in Org-mode."
|
|
|
|
:tag "Org Table Calculation"
|
|
|
|
:group 'org-table)
|
|
|
|
|
2011-03-03 11:45:02 -05:00
|
|
|
(defcustom org-table-use-standard-references 'from
|
2008-12-16 11:49:26 -05:00
|
|
|
"Should org-mode work with table references like B3 instead of @3$2?
|
2008-03-22 11:52:18 -04:00
|
|
|
Possible values are:
|
|
|
|
nil never use them
|
|
|
|
from accept as input, do not present for editing
|
2011-03-03 03:30:16 -05:00
|
|
|
t accept as input and present for editing"
|
2008-03-22 11:52:18 -04:00
|
|
|
:group 'org-table-calculation
|
|
|
|
:type '(choice
|
2008-03-30 14:33:07 -04:00
|
|
|
(const :tag "Never, don't even check user input for them" nil)
|
2008-03-22 11:52:18 -04:00
|
|
|
(const :tag "Always, both as user input, and when editing" t)
|
2011-03-01 03:05:56 -05:00
|
|
|
(const :tag "Convert user input, don't offer during editing" from)))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defcustom org-table-copy-increment t
|
2010-01-21 10:15:40 -05:00
|
|
|
"Non-nil means increment when copying current field with \\[org-table-copy-down]."
|
2008-03-22 11:52:18 -04:00
|
|
|
:group 'org-table-calculation
|
2014-10-24 05:56:09 -04:00
|
|
|
:version "25.1"
|
2014-05-20 10:07:01 -04:00
|
|
|
:package-version '(Org . "8.3")
|
|
|
|
:type '(choice
|
|
|
|
(const :tag "Use the difference between the current and the above fields" t)
|
|
|
|
(integer :tag "Use a number" 1)
|
2014-05-20 12:59:29 -04:00
|
|
|
(const :tag "Don't increment the value when copying a field" nil)))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defcustom org-calc-default-modes
|
|
|
|
'(calc-internal-prec 12
|
2012-08-11 13:10:44 -04:00
|
|
|
calc-float-format (float 8)
|
|
|
|
calc-angle-mode deg
|
|
|
|
calc-prefer-frac nil
|
|
|
|
calc-symbolic-mode nil
|
|
|
|
calc-date-format (YYYY "-" MM "-" DD " " Www (" " hh ":" mm))
|
|
|
|
calc-display-working-message t
|
|
|
|
)
|
2010-07-17 14:53:36 -04:00
|
|
|
"List with Calc mode settings for use in `calc-eval' for table formulas.
|
2008-03-22 11:52:18 -04:00
|
|
|
The list must contain alternating symbols (Calc modes variables and values).
|
|
|
|
Don't remove any of the default settings, just change the values. Org-mode
|
|
|
|
relies on the variables to be present in the list."
|
|
|
|
:group 'org-table-calculation
|
|
|
|
:type 'plist)
|
|
|
|
|
2011-07-27 07:14:37 -04:00
|
|
|
(defcustom org-table-duration-custom-format 'hours
|
|
|
|
"Format for the output of calc computations like $1+$2;t.
|
|
|
|
The default value is 'hours, and will output the results as a
|
|
|
|
number of hours. Other allowed values are 'seconds, 'minutes and
|
|
|
|
'days, and the output will be a fraction of seconds, minutes or
|
|
|
|
days."
|
|
|
|
:group 'org-table-calculation
|
2012-03-19 16:38:12 -04:00
|
|
|
:version "24.1"
|
2011-07-27 07:14:37 -04:00
|
|
|
:type '(choice (symbol :tag "Seconds" 'seconds)
|
|
|
|
(symbol :tag "Minutes" 'minutes)
|
|
|
|
(symbol :tag "Hours " 'hours)
|
|
|
|
(symbol :tag "Days " 'days)))
|
|
|
|
|
2011-12-11 08:05:13 -05:00
|
|
|
(defcustom org-table-formula-field-format "%s"
|
|
|
|
"Format for fields which contain the result of a formula.
|
|
|
|
For example, using \"~%s~\" will display the result within tilde
|
|
|
|
characters. Beware that modifying the display can prevent the
|
|
|
|
field from being used in another formula."
|
|
|
|
:group 'org-table-settings
|
2012-03-19 16:38:12 -04:00
|
|
|
:version "24.1"
|
2011-12-11 08:05:13 -05:00
|
|
|
:type 'string)
|
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
(defcustom org-table-formula-evaluate-inline t
|
2010-01-21 10:15:40 -05:00
|
|
|
"Non-nil means TAB and RET evaluate a formula in current table field.
|
2008-03-22 11:52:18 -04:00
|
|
|
If the current field starts with an equal sign, it is assumed to be a formula
|
|
|
|
which should be evaluated as described in the manual and in the documentation
|
|
|
|
string of the command `org-table-eval-formula'. This feature requires the
|
|
|
|
Emacs calc package.
|
|
|
|
When this variable is nil, formula calculation is only available through
|
|
|
|
the command \\[org-table-eval-formula]."
|
|
|
|
:group 'org-table-calculation
|
|
|
|
:type 'boolean)
|
|
|
|
|
|
|
|
(defcustom org-table-formula-use-constants t
|
2010-01-21 10:15:40 -05:00
|
|
|
"Non-nil means interpret constants in formulas in tables.
|
2008-03-22 11:52:18 -04:00
|
|
|
A constant looks like `$c' or `$Grav' and will be replaced before evaluation
|
|
|
|
by the value given in `org-table-formula-constants', or by a value obtained
|
|
|
|
from the `constants.el' package."
|
|
|
|
:group 'org-table-calculation
|
|
|
|
:type 'boolean)
|
|
|
|
|
|
|
|
(defcustom org-table-formula-constants nil
|
|
|
|
"Alist with constant names and values, for use in table formulas.
|
|
|
|
The car of each element is a name of a constant, without the `$' before it.
|
|
|
|
The cdr is the value as a string. For example, if you'd like to use the
|
|
|
|
speed of light in a formula, you would configure
|
|
|
|
|
|
|
|
(setq org-table-formula-constants '((\"c\" . \"299792458.\")))
|
|
|
|
|
|
|
|
and then use it in an equation like `$1*$c'.
|
|
|
|
|
|
|
|
Constants can also be defined on a per-file basis using a line like
|
|
|
|
|
|
|
|
#+CONSTANTS: c=299792458. pi=3.14 eps=2.4e-6"
|
|
|
|
:group 'org-table-calculation
|
|
|
|
:type '(repeat
|
|
|
|
(cons (string :tag "name")
|
|
|
|
(string :tag "value"))))
|
|
|
|
|
|
|
|
(defcustom org-table-allow-automatic-line-recalculation t
|
2010-01-21 10:15:40 -05:00
|
|
|
"Non-nil means lines marked with |#| or |*| will be recomputed automatically.
|
|
|
|
Automatically means when TAB or RET or C-c C-c are pressed in the line."
|
2008-03-22 11:52:18 -04:00
|
|
|
:group 'org-table-calculation
|
|
|
|
:type 'boolean)
|
|
|
|
|
2008-12-05 07:07:17 -05:00
|
|
|
(defcustom org-table-error-on-row-ref-crossing-hline t
|
2009-08-01 01:56:26 -04:00
|
|
|
"OBSOLETE VARIABLE, please see `org-table-relative-ref-may-cross-hline'."
|
2008-12-05 07:07:17 -05:00
|
|
|
:group 'org-table
|
|
|
|
:type 'boolean)
|
|
|
|
|
2009-08-01 01:56:26 -04:00
|
|
|
(defcustom org-table-relative-ref-may-cross-hline t
|
2010-01-21 10:15:40 -05:00
|
|
|
"Non-nil means relative formula references may cross hlines.
|
2009-08-01 01:56:26 -04:00
|
|
|
Here are the allowed values:
|
|
|
|
|
|
|
|
nil Relative references may not cross hlines. They will reference the
|
|
|
|
field next to the hline instead. Coming from below, the reference
|
|
|
|
will be to the field below the hline. Coming from above, it will be
|
|
|
|
to the field above.
|
2009-11-12 07:39:29 -05:00
|
|
|
t Relative references may cross hlines.
|
2009-08-01 01:56:26 -04:00
|
|
|
error An attempt to cross a hline will throw an error.
|
|
|
|
|
|
|
|
It is probably good to never set this variable to nil, for the sake of
|
|
|
|
portability of tables."
|
|
|
|
:group 'org-table-calculation
|
|
|
|
:type '(choice
|
|
|
|
(const :tag "Allow to cross" t)
|
|
|
|
(const :tag "Stick to hline" nil)
|
|
|
|
(const :tag "Error on attempt to cross" error)))
|
|
|
|
|
2014-10-01 01:36:21 -04:00
|
|
|
(defcustom org-table-formula-create-columns nil
|
|
|
|
"Non-nil means that evaluation of a field formula can add new
|
|
|
|
columns if an out-of-bounds field is being set."
|
|
|
|
:group 'org-table-calculation
|
2014-10-24 05:56:09 -04:00
|
|
|
:version "25.1"
|
2014-10-01 01:36:21 -04:00
|
|
|
:package-version '(Org . "8.3")
|
|
|
|
:type '(choice
|
|
|
|
(const :tag "Setting an out-of-bounds field generates an error (default)" nil)
|
|
|
|
(const :tag "Setting an out-of-bounds field silently adds columns as needed" t)
|
|
|
|
(const :tag "Setting an out-of-bounds field adds columns as needed, but issues a warning message" warn)
|
|
|
|
(const :tag "When setting an out-of-bounds field, the user is prompted" prompt)))
|
|
|
|
|
2008-04-10 02:27:56 -04:00
|
|
|
(defgroup org-table-import-export nil
|
|
|
|
"Options concerning table import and export in Org-mode."
|
|
|
|
:tag "Org Table Import Export"
|
|
|
|
:group 'org-table)
|
2008-03-22 11:52:18 -04:00
|
|
|
|
2008-05-12 01:31:21 -04:00
|
|
|
(defcustom org-table-export-default-format "orgtbl-to-tsv"
|
2010-07-17 14:53:36 -04:00
|
|
|
"Default export parameters for `org-table-export'.
|
|
|
|
These can be overridden for a specific table by setting the
|
|
|
|
TABLE_EXPORT_FORMAT property. See the manual section on orgtbl
|
|
|
|
radio tables for the different export transformations and
|
|
|
|
available parameters."
|
2008-04-10 02:27:56 -04:00
|
|
|
:group 'org-table-import-export
|
|
|
|
:type 'string)
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defconst org-table-auto-recalculate-regexp "^[ \t]*| *# *\\(|\\|$\\)"
|
|
|
|
"Detects a table line marked for automatic recalculation.")
|
|
|
|
(defconst org-table-recalculate-regexp "^[ \t]*| *[#*] *\\(|\\|$\\)"
|
|
|
|
"Detects a table line marked for automatic recalculation.")
|
|
|
|
(defconst org-table-calculate-mark-regexp "^[ \t]*| *[!$^_#*] *\\(|\\|$\\)"
|
|
|
|
"Detects a table line marked for automatic recalculation.")
|
|
|
|
(defconst org-table-border-regexp "^[ \t]*[^| \t]"
|
2010-07-17 14:53:36 -04:00
|
|
|
"Searching from within a table (any type) this finds the first line outside the table.")
|
2008-03-22 11:52:18 -04:00
|
|
|
(defvar org-table-last-highlighted-reference nil)
|
|
|
|
(defvar org-table-formula-history nil)
|
|
|
|
|
|
|
|
(defvar org-table-column-names nil
|
|
|
|
"Alist with column names, derived from the `!' line.")
|
|
|
|
(defvar org-table-column-name-regexp nil
|
|
|
|
"Regular expression matching the current column names.")
|
|
|
|
(defvar org-table-local-parameters nil
|
|
|
|
"Alist with parameter names, derived from the `$' line.")
|
|
|
|
(defvar org-table-named-field-locations nil
|
|
|
|
"Alist with locations of named fields.")
|
|
|
|
|
|
|
|
(defvar org-table-current-line-types nil
|
2010-07-17 14:53:36 -04:00
|
|
|
"Table row types, non-nil only for the duration of a command.")
|
2008-03-22 11:52:18 -04:00
|
|
|
(defvar org-table-current-begin-line nil
|
2010-07-17 14:53:36 -04:00
|
|
|
"Table begin line, non-nil only for the duration of a command.")
|
2008-03-22 11:52:18 -04:00
|
|
|
(defvar org-table-current-begin-pos nil
|
2010-07-17 14:53:36 -04:00
|
|
|
"Table begin position, non-nil only for the duration of a command.")
|
2011-03-01 03:05:56 -05:00
|
|
|
(defvar org-table-current-ncol nil
|
|
|
|
"Number of columns in table, non-nil only for the duration of a command.")
|
2008-03-22 11:52:18 -04:00
|
|
|
(defvar org-table-dlines nil
|
|
|
|
"Vector of data line line numbers in the current table.")
|
|
|
|
(defvar org-table-hlines nil
|
|
|
|
"Vector of hline line numbers in the current table.")
|
|
|
|
|
|
|
|
(defconst org-table-range-regexp
|
2012-08-11 13:10:44 -04:00
|
|
|
"@\\([-+]?I*[-+]?[0-9]*\\)?\\(\\$[-+]?[0-9]+\\)?\\(\\.\\.@?\\([-+]?I*[-+]?[0-9]*\\)?\\(\\$[-+]?[0-9]+\\)?\\)?"
|
|
|
|
;; 1 2 3 4 5
|
2008-03-22 11:52:18 -04:00
|
|
|
"Regular expression for matching ranges in formulas.")
|
|
|
|
|
|
|
|
(defconst org-table-range-regexp2
|
|
|
|
(concat
|
|
|
|
"\\(" "@[-0-9I$&]+" "\\|" "[a-zA-Z]\\{1,2\\}\\([0-9]+\\|&\\)" "\\|" "\\$[a-zA-Z0-9]+" "\\)"
|
|
|
|
"\\.\\."
|
|
|
|
"\\(" "@?[-0-9I$&]+" "\\|" "[a-zA-Z]\\{1,2\\}\\([0-9]+\\|&\\)" "\\|" "\\$[a-zA-Z0-9]+" "\\)")
|
|
|
|
"Match a range for reference display.")
|
|
|
|
|
2010-04-27 06:13:27 -04:00
|
|
|
(defun org-table-colgroup-line-p (line)
|
|
|
|
"Is this a table line colgroup information?"
|
|
|
|
(save-match-data
|
|
|
|
(and (string-match "[<>]\\|&[lg]t;" line)
|
|
|
|
(string-match "\\`[ \t]*|[ \t]*/[ \t]*\\(|[ \t<>0-9|lgt&;]+\\)\\'"
|
|
|
|
line)
|
|
|
|
(not (delq
|
|
|
|
nil
|
|
|
|
(mapcar
|
|
|
|
(lambda (s)
|
|
|
|
(not (member s '("" "<" ">" "<>" "<" ">" "<>"))))
|
|
|
|
(org-split-string (match-string 1 line) "[ \t]*|[ \t]*")))))))
|
|
|
|
|
|
|
|
(defun org-table-cookie-line-p (line)
|
|
|
|
"Is this a table line with only alignment/width cookies?"
|
|
|
|
(save-match-data
|
|
|
|
(and (string-match "[<>]\\|&[lg]t;" line)
|
2010-10-21 10:28:06 -04:00
|
|
|
(or (string-match
|
2010-10-22 03:19:04 -04:00
|
|
|
"\\`[ \t]*|[ \t]*/[ \t]*\\(|[ \t<>0-9|lrcgt&;]+\\)\\'" line)
|
|
|
|
(string-match "\\(\\`[ \t<>lrc0-9|gt&;]+\\'\\)" line))
|
2010-04-27 06:13:27 -04:00
|
|
|
(not (delq nil (mapcar
|
|
|
|
(lambda (s)
|
|
|
|
(not (or (equal s "")
|
2010-10-21 10:28:06 -04:00
|
|
|
(string-match
|
2010-10-22 03:19:04 -04:00
|
|
|
"\\`<\\([lrc]?[0-9]+\\|[lrc]\\)>\\'" s)
|
2010-10-21 10:28:06 -04:00
|
|
|
(string-match
|
2010-10-22 03:19:04 -04:00
|
|
|
"\\`<\\([lrc]?[0-9]+\\|[lrc]\\)>\\'"
|
2010-10-21 10:28:06 -04:00
|
|
|
s))))
|
|
|
|
(org-split-string (match-string 1 line)
|
|
|
|
"[ \t]*|[ \t]*")))))))
|
2010-04-27 06:13:27 -04:00
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
(defconst org-table-translate-regexp
|
|
|
|
(concat "\\(" "@[-0-9I$]+" "\\|" "[a-zA-Z]\\{1,2\\}\\([0-9]+\\|&\\)" "\\)")
|
|
|
|
"Match a reference that needs translation, for reference display.")
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-create-with-table.el ()
|
|
|
|
"Use the table.el package to insert a new table.
|
|
|
|
If there is already a table at point, convert between Org-mode tables
|
|
|
|
and table.el tables."
|
|
|
|
(interactive)
|
|
|
|
(require 'table)
|
|
|
|
(cond
|
|
|
|
((org-at-table.el-p)
|
|
|
|
(if (y-or-n-p "Convert table to Org-mode table? ")
|
|
|
|
(org-table-convert)))
|
|
|
|
((org-at-table-p)
|
2010-08-18 02:35:15 -04:00
|
|
|
(when (y-or-n-p "Convert table to table.el table? ")
|
|
|
|
(org-table-align)
|
|
|
|
(org-table-convert)))
|
2008-03-22 11:52:18 -04:00
|
|
|
(t (call-interactively 'table-insert))))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-create-or-convert-from-region (arg)
|
|
|
|
"Convert region to table, or create an empty table.
|
|
|
|
If there is an active region, convert it to a table, using the function
|
|
|
|
`org-table-convert-region'. See the documentation of that function
|
|
|
|
to learn how the prefix argument is interpreted to determine the field
|
|
|
|
separator.
|
|
|
|
If there is no such region, create an empty table with `org-table-create'."
|
|
|
|
(interactive "P")
|
|
|
|
(if (org-region-active-p)
|
|
|
|
(org-table-convert-region (region-beginning) (region-end) arg)
|
|
|
|
(org-table-create arg)))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-create (&optional size)
|
|
|
|
"Query for a size and insert a table skeleton.
|
|
|
|
SIZE is a string Columns x Rows like for example \"3x2\"."
|
|
|
|
(interactive "P")
|
|
|
|
(unless size
|
|
|
|
(setq size (read-string
|
|
|
|
(concat "Table size Columns x Rows [e.g. "
|
|
|
|
org-table-default-size "]: ")
|
|
|
|
"" nil org-table-default-size)))
|
|
|
|
|
|
|
|
(let* ((pos (point))
|
|
|
|
(indent (make-string (current-column) ?\ ))
|
|
|
|
(split (org-split-string size " *x *"))
|
|
|
|
(rows (string-to-number (nth 1 split)))
|
|
|
|
(columns (string-to-number (car split)))
|
|
|
|
(line (concat (apply 'concat indent "|" (make-list columns " |"))
|
|
|
|
"\n")))
|
|
|
|
(if (string-match "^[ \t]*$" (buffer-substring-no-properties
|
|
|
|
(point-at-bol) (point)))
|
|
|
|
(beginning-of-line 1)
|
|
|
|
(newline))
|
|
|
|
;; (mapcar (lambda (x) (insert line)) (make-list rows t))
|
|
|
|
(dotimes (i rows) (insert line))
|
|
|
|
(goto-char pos)
|
|
|
|
(if (> rows 1)
|
|
|
|
;; Insert a hline after the first row.
|
|
|
|
(progn
|
|
|
|
(end-of-line 1)
|
|
|
|
(insert "\n|-")
|
|
|
|
(goto-char pos)))
|
|
|
|
(org-table-align)))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-convert-region (beg0 end0 &optional separator)
|
|
|
|
"Convert region to a table.
|
|
|
|
The region goes from BEG0 to END0, but these borders will be moved
|
|
|
|
slightly, to make sure a beginning of line in the first line is included.
|
|
|
|
|
|
|
|
SEPARATOR specifies the field separator in the lines. It can have the
|
|
|
|
following values:
|
|
|
|
|
|
|
|
'(4) Use the comma as a field separator
|
|
|
|
'(16) Use a TAB as field separator
|
2013-09-29 06:27:09 -04:00
|
|
|
'(64) Prompt for a regular expression as field separator
|
2008-03-22 11:52:18 -04:00
|
|
|
integer When a number, use that many spaces as field separator
|
2013-09-29 06:27:09 -04:00
|
|
|
regexp When a regular expression, use it to match the separator
|
2008-03-22 11:52:18 -04:00
|
|
|
nil When nil, the command tries to be smart and figure out the
|
|
|
|
separator in the following way:
|
|
|
|
- when each line contains a TAB, assume TAB-separated material
|
2008-12-16 11:49:26 -05:00
|
|
|
- when each line contains a comma, assume CSV material
|
2008-11-08 16:00:03 -05:00
|
|
|
- else, assume one or more SPACE characters as separator."
|
2013-06-01 01:46:08 -04:00
|
|
|
(interactive "r\nP")
|
2008-03-22 11:52:18 -04:00
|
|
|
(let* ((beg (min beg0 end0))
|
|
|
|
(end (max beg0 end0))
|
|
|
|
re)
|
2013-09-29 06:27:09 -04:00
|
|
|
(if (equal separator '(64))
|
|
|
|
(setq separator (read-regexp "Regexp for field separator")))
|
2008-03-22 11:52:18 -04:00
|
|
|
(goto-char beg)
|
|
|
|
(beginning-of-line 1)
|
2012-12-19 23:46:41 -05:00
|
|
|
(setq beg (point-marker))
|
2008-03-22 11:52:18 -04:00
|
|
|
(goto-char end)
|
|
|
|
(if (bolp) (backward-char 1) (end-of-line 1))
|
2012-12-19 23:46:41 -05:00
|
|
|
(setq end (point-marker))
|
2008-03-22 11:52:18 -04:00
|
|
|
;; Get the right field separator
|
|
|
|
(unless separator
|
|
|
|
(goto-char beg)
|
|
|
|
(setq separator
|
|
|
|
(cond
|
|
|
|
((not (re-search-forward "^[^\n\t]+$" end t)) '(16))
|
|
|
|
((not (re-search-forward "^[^\n,]+$" end t)) '(4))
|
|
|
|
(t 1))))
|
|
|
|
(goto-char beg)
|
2009-10-26 07:31:16 -04:00
|
|
|
(if (equal separator '(4))
|
fix infinite loop in csv table import
* lisp/org-table.el (org-table-convert-region): don't continue csv
importation which the point catches the end, this fixes an infinite
loop which was caused by the (point) never catching up with the
"end" marker
Hi,
I've just noticed that I get an infinite loop when importing csv tables
into Org-mode tables. For example calling
(org-table-convert-region (point-min) (point-max) '(4))
from inside of a simple text file containing the following
--8<---------------cut here---------------start------------->8---
1,2,3
1
2
3
5
--8<---------------cut here---------------end--------------->8---
results in an infinite loop. The attached patch fixes this issue [1],
however it seems weird that this would just surface now, given that the
code in question has been in the repo since last fall
,----
| commit 59c9c4cdd4ae974dfb92ab441462b3fee48ab5af
| Author: Carsten Dominik <carsten.dominik@gmail.com>
| Date: Mon Oct 26 12:31:16 2009 +0100
|
| Correctly interpret CVS tables with quoted fields
|
| The csv parser was very primitive, ignoring quoted fields. This is
| now fixed.
`----
Has anyone else noticed this problem? Should I go ahead and apply this
patch?
Best -- Eric
Footnotes:
[1]
>From 3c3f4ca9a34dca23051ca2f4e4518b416338d4f4 Mon Sep 17 00:00:00 2001
From: Eric Schulte <schulte.eric@gmail.com>
Date: Mon, 19 Jul 2010 13:45:25 -0700
Subject: [PATCH] org-table: fix infinite loop in table importation
* lisp/org-table.el (org-table-convert-region): don't continue csv
importation which the point catches the end, this fixes an infinite
loop which was caused by the (point) never catching up with the
"end" marker
2010-07-19 21:53:30 -04:00
|
|
|
(while (< (point) end)
|
2009-10-26 07:31:16 -04:00
|
|
|
;; parse the csv stuff
|
|
|
|
(cond
|
2009-10-31 04:24:32 -04:00
|
|
|
((looking-at "^") (insert "| "))
|
|
|
|
((looking-at "[ \t]*$") (replace-match " |") (beginning-of-line 2))
|
2009-10-26 07:31:16 -04:00
|
|
|
((looking-at "[ \t]*\"\\([^\"\n]*\\)\"")
|
|
|
|
(replace-match "\\1")
|
|
|
|
(if (looking-at "\"") (insert "\"")))
|
|
|
|
((looking-at "[^,\n]+") (goto-char (match-end 0)))
|
|
|
|
((looking-at "[ \t]*,") (replace-match " | "))
|
2009-10-31 04:24:32 -04:00
|
|
|
(t (beginning-of-line 2))))
|
2009-10-26 07:31:16 -04:00
|
|
|
(setq re (cond
|
|
|
|
((equal separator '(4)) "^\\|\"?[ \t]*,[ \t]*\"?")
|
|
|
|
((equal separator '(16)) "^\\|\t")
|
|
|
|
((integerp separator)
|
2011-03-19 02:42:13 -04:00
|
|
|
(if (< separator 1)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Number of spaces in separator must be >= 1")
|
2011-03-19 02:42:13 -04:00
|
|
|
(format "^ *\\| *\t *\\| \\{%d,\\}" separator)))
|
2013-09-29 06:27:09 -04:00
|
|
|
((stringp separator)
|
|
|
|
(format "^ *\\|%s" separator))
|
2009-10-26 07:31:16 -04:00
|
|
|
(t (error "This should not happen"))))
|
|
|
|
(while (re-search-forward re end t)
|
|
|
|
(replace-match "| " t t)))
|
2008-03-22 11:52:18 -04:00
|
|
|
(goto-char beg)
|
|
|
|
(org-table-align)))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-import (file arg)
|
|
|
|
"Import FILE as a table.
|
|
|
|
The file is assumed to be tab-separated. Such files can be produced by most
|
|
|
|
spreadsheet and database applications. If no tabs (at least one per line)
|
|
|
|
are found, lines will be split on whitespace into fields."
|
|
|
|
(interactive "f\nP")
|
|
|
|
(or (bolp) (newline))
|
|
|
|
(let ((beg (point))
|
|
|
|
(pm (point-max)))
|
|
|
|
(insert-file-contents file)
|
|
|
|
(org-table-convert-region beg (+ (point) (- (point-max) pm)) arg)))
|
|
|
|
|
2008-04-10 02:27:56 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-04-10 02:27:56 -04:00
|
|
|
(defun org-table-export (&optional file format)
|
2008-05-10 01:54:45 -04:00
|
|
|
"Export table to a file, with configurable format.
|
2012-07-06 14:13:34 -04:00
|
|
|
Such a file can be imported into usual spreadsheet programs.
|
|
|
|
|
|
|
|
FILE can be the output file name. If not given, it will be taken
|
|
|
|
from a TABLE_EXPORT_FILE property in the current entry or higher
|
|
|
|
up in the hierarchy, or the user will be prompted for a file
|
|
|
|
name. FORMAT can be an export format, of the same kind as it
|
|
|
|
used when `orgtbl-mode' sends a table in a different format.
|
|
|
|
|
|
|
|
The command suggests a format depending on TABLE_EXPORT_FORMAT,
|
|
|
|
whether it is set locally or up in the hierarchy, then on the
|
|
|
|
extension of the given file name, and finally on the variable
|
|
|
|
`org-table-export-default-format'."
|
2008-03-22 11:52:18 -04:00
|
|
|
(interactive)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(unless (org-at-table-p) (user-error "No table at point"))
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
(org-table-align) ; Make sure we have everything we need.
|
|
|
|
(let ((file (or file (org-entry-get (point) "TABLE_EXPORT_FILE" t))))
|
2008-05-10 01:54:45 -04:00
|
|
|
(unless file
|
|
|
|
(setq file (read-file-name "Export table to: "))
|
|
|
|
(unless (or (not (file-exists-p file))
|
|
|
|
(y-or-n-p (format "Overwrite file %s? " file)))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "File not written")))
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
(when (file-directory-p file)
|
|
|
|
(user-error "This is a directory path, not a file"))
|
|
|
|
(when (and (buffer-file-name (buffer-base-buffer))
|
2014-09-19 04:05:15 -04:00
|
|
|
(org-file-equal-p
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
(file-truename file)
|
|
|
|
(file-truename (buffer-file-name (buffer-base-buffer)))))
|
|
|
|
(user-error "Please specify a file name that is different from current"))
|
|
|
|
(let ((fileext (concat (file-name-extension file) "$"))
|
|
|
|
(format (or format (org-entry-get (point) "TABLE_EXPORT_FORMAT" t))))
|
|
|
|
(unless format
|
|
|
|
(let* ((formats '("orgtbl-to-tsv" "orgtbl-to-csv" "orgtbl-to-latex"
|
|
|
|
"orgtbl-to-html" "orgtbl-to-generic"
|
|
|
|
"orgtbl-to-texinfo" "orgtbl-to-orgtbl"
|
|
|
|
"orgtbl-to-unicode"))
|
|
|
|
(deffmt-readable
|
|
|
|
(replace-regexp-in-string
|
|
|
|
"\t" "\\t"
|
|
|
|
(replace-regexp-in-string
|
|
|
|
"\n" "\\n"
|
|
|
|
(or (car (delq nil
|
|
|
|
(mapcar
|
|
|
|
(lambda (f)
|
|
|
|
(and (org-string-match-p fileext f) f))
|
|
|
|
formats)))
|
|
|
|
org-table-export-default-format)
|
|
|
|
t t) t t)))
|
|
|
|
(setq format
|
|
|
|
(org-completing-read
|
|
|
|
"Format: " formats nil nil deffmt-readable))))
|
|
|
|
(if (string-match "\\([^ \t\r\n]+\\)\\( +.*\\)?" format)
|
|
|
|
(let ((transform (intern (match-string 1 format)))
|
|
|
|
(params (and (match-end 2)
|
|
|
|
(read (concat "(" (match-string 2 format) ")"))))
|
|
|
|
(table (org-table-to-lisp
|
|
|
|
(buffer-substring-no-properties
|
|
|
|
(org-table-begin) (org-table-end)))))
|
|
|
|
(unless (fboundp transform)
|
|
|
|
(user-error "No such transformation function %s" transform))
|
|
|
|
(let (buf)
|
|
|
|
(with-current-buffer (find-file-noselect file)
|
|
|
|
(setq buf (current-buffer))
|
|
|
|
(erase-buffer)
|
|
|
|
(fundamental-mode)
|
|
|
|
(insert (funcall transform table params) "\n")
|
|
|
|
(save-buffer))
|
|
|
|
(kill-buffer buf))
|
|
|
|
(message "Export done."))
|
|
|
|
(user-error "TABLE_EXPORT_FORMAT invalid")))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defvar org-table-aligned-begin-marker (make-marker)
|
|
|
|
"Marker at the beginning of the table last aligned.
|
|
|
|
Used to check if cursor still is in that table, to minimize realignment.")
|
|
|
|
(defvar org-table-aligned-end-marker (make-marker)
|
|
|
|
"Marker at the end of the table last aligned.
|
|
|
|
Used to check if cursor still is in that table, to minimize realignment.")
|
|
|
|
(defvar org-table-last-alignment nil
|
|
|
|
"List of flags for flushright alignment, from the last re-alignment.
|
|
|
|
This is being used to correctly align a single field after TAB or RET.")
|
|
|
|
(defvar org-table-last-column-widths nil
|
|
|
|
"List of max width of fields in each column.
|
|
|
|
This is being used to correctly align a single field after TAB or RET.")
|
2008-04-15 02:49:26 -04:00
|
|
|
(defvar org-table-formula-debug nil
|
2010-01-21 10:15:40 -05:00
|
|
|
"Non-nil means debug table formulas.
|
2008-04-15 02:49:26 -04:00
|
|
|
When nil, simply write \"#ERROR\" in corrupted fields.")
|
|
|
|
(make-variable-buffer-local 'org-table-formula-debug)
|
2008-03-22 11:52:18 -04:00
|
|
|
(defvar org-table-overlay-coordinates nil
|
|
|
|
"Overlay coordinates after each align of a table.")
|
|
|
|
(make-variable-buffer-local 'org-table-overlay-coordinates)
|
|
|
|
|
|
|
|
(defvar org-last-recalc-line nil)
|
2010-02-12 12:48:16 -05:00
|
|
|
(defvar org-table-do-narrow t) ; for dynamic scoping
|
2008-03-22 11:52:18 -04:00
|
|
|
(defconst org-narrow-column-arrow "=>"
|
|
|
|
"Used as display property in narrowed table columns.")
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-align ()
|
|
|
|
"Align the table at point by aligning all vertical bars."
|
|
|
|
(interactive)
|
|
|
|
(let* (
|
|
|
|
;; Limits of table
|
|
|
|
(beg (org-table-begin))
|
|
|
|
(end (org-table-end))
|
|
|
|
;; Current cursor position
|
|
|
|
(linepos (org-current-line))
|
|
|
|
(colpos (org-table-current-column))
|
|
|
|
(winstart (window-start))
|
|
|
|
(winstartline (org-current-line (min winstart (1- (point-max)))))
|
|
|
|
lines (new "") lengths l typenums ty fields maxfields i
|
|
|
|
column
|
|
|
|
(indent "") cnt frac
|
|
|
|
rfmt hfmt
|
|
|
|
(spaces '(1 . 1))
|
|
|
|
(sp1 (car spaces))
|
|
|
|
(sp2 (cdr spaces))
|
|
|
|
(rfmt1 (concat
|
|
|
|
(make-string sp2 ?\ ) "%%%s%ds" (make-string sp1 ?\ ) "|"))
|
|
|
|
(hfmt1 (concat
|
|
|
|
(make-string sp2 ?-) "%s" (make-string sp1 ?-) "+"))
|
2010-06-03 04:24:04 -04:00
|
|
|
emptystrings links dates emph raise narrow
|
2013-02-13 03:46:33 -05:00
|
|
|
falign falign1 fmax f1 f2 len c e space)
|
2008-03-22 11:52:18 -04:00
|
|
|
(untabify beg end)
|
|
|
|
(remove-text-properties beg end '(org-cwidth t org-dwidth t display t))
|
|
|
|
;; Check if we have links or dates
|
|
|
|
(goto-char beg)
|
|
|
|
(setq links (re-search-forward org-bracket-link-regexp end t))
|
|
|
|
(goto-char beg)
|
|
|
|
(setq emph (and org-hide-emphasis-markers
|
|
|
|
(re-search-forward org-emph-re end t)))
|
|
|
|
(goto-char beg)
|
2010-06-03 04:24:04 -04:00
|
|
|
(setq raise (and org-use-sub-superscripts
|
2012-08-11 13:10:44 -04:00
|
|
|
(re-search-forward org-match-substring-regexp end t)))
|
2010-06-03 04:24:04 -04:00
|
|
|
(goto-char beg)
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq dates (and org-display-custom-times
|
|
|
|
(re-search-forward org-ts-regexp-both end t)))
|
|
|
|
;; Make sure the link properties are right
|
|
|
|
(when links (goto-char beg) (while (org-activate-bracket-links end)))
|
|
|
|
;; Make sure the date properties are right
|
|
|
|
(when dates (goto-char beg) (while (org-activate-dates end)))
|
|
|
|
(when emph (goto-char beg) (while (org-do-emphasis-faces end)))
|
2010-06-03 04:24:04 -04:00
|
|
|
(when raise (goto-char beg) (while (org-raise-scripts end)))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
;; Check if we are narrowing any columns
|
|
|
|
(goto-char beg)
|
2010-02-12 12:48:16 -05:00
|
|
|
(setq narrow (and org-table-do-narrow
|
|
|
|
org-format-transports-properties-p
|
2010-10-22 03:19:04 -04:00
|
|
|
(re-search-forward "<[lrc]?[0-9]+>" end t)))
|
2009-06-21 16:40:45 -04:00
|
|
|
(goto-char beg)
|
2010-10-22 03:19:04 -04:00
|
|
|
(setq falign (re-search-forward "<[lrc][0-9]*>" end t))
|
2009-09-10 13:54:44 -04:00
|
|
|
(goto-char beg)
|
2008-03-22 11:52:18 -04:00
|
|
|
;; Get the rows
|
|
|
|
(setq lines (org-split-string
|
|
|
|
(buffer-substring beg end) "\n"))
|
|
|
|
;; Store the indentation of the first line
|
|
|
|
(if (string-match "^ *" (car lines))
|
|
|
|
(setq indent (make-string (- (match-end 0) (match-beginning 0)) ?\ )))
|
|
|
|
;; Mark the hlines by setting the corresponding element to nil
|
|
|
|
;; At the same time, we remove trailing space.
|
|
|
|
(setq lines (mapcar (lambda (l)
|
|
|
|
(if (string-match "^ *|-" l)
|
|
|
|
nil
|
|
|
|
(if (string-match "[ \t]+$" l)
|
|
|
|
(substring l 0 (match-beginning 0))
|
|
|
|
l)))
|
|
|
|
lines))
|
|
|
|
;; Get the data fields by splitting the lines.
|
|
|
|
(setq fields (mapcar
|
|
|
|
(lambda (l)
|
2012-08-11 13:10:44 -04:00
|
|
|
(org-split-string l " *| *"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(delq nil (copy-sequence lines))))
|
|
|
|
;; How many fields in the longest line?
|
|
|
|
(condition-case nil
|
|
|
|
(setq maxfields (apply 'max (mapcar 'length fields)))
|
|
|
|
(error
|
|
|
|
(kill-region beg end)
|
|
|
|
(org-table-create org-table-default-size)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Empty table - created default table")))
|
2008-03-22 11:52:18 -04:00
|
|
|
;; A list of empty strings to fill any short rows on output
|
|
|
|
(setq emptystrings (make-list maxfields ""))
|
|
|
|
;; Check for special formatting.
|
|
|
|
(setq i -1)
|
|
|
|
(while (< (setq i (1+ i)) maxfields) ;; Loop over all columns
|
|
|
|
(setq column (mapcar (lambda (x) (or (nth i x) "")) fields))
|
|
|
|
;; Check if there is an explicit width specified
|
2010-03-27 11:13:45 -04:00
|
|
|
(setq fmax nil)
|
2009-06-21 16:40:45 -04:00
|
|
|
(when (or narrow falign)
|
|
|
|
(setq c column fmax nil falign1 nil)
|
2008-03-22 11:52:18 -04:00
|
|
|
(while c
|
|
|
|
(setq e (pop c))
|
2010-10-22 03:19:04 -04:00
|
|
|
(when (and (stringp e) (string-match "^<\\([lrc]\\)?\\([0-9]+\\)?>$" e))
|
2009-06-21 16:40:45 -04:00
|
|
|
(if (match-end 1) (setq falign1 (match-string 1 e)))
|
2010-02-12 12:48:16 -05:00
|
|
|
(if (and org-table-do-narrow (match-end 2))
|
2009-06-21 16:40:45 -04:00
|
|
|
(setq fmax (string-to-number (match-string 2 e)) c nil))))
|
2008-03-22 11:52:18 -04:00
|
|
|
;; Find fields that are wider than fmax, and shorten them
|
|
|
|
(when fmax
|
|
|
|
(loop for xx in column do
|
|
|
|
(when (and (stringp xx)
|
|
|
|
(> (org-string-width xx) fmax))
|
|
|
|
(org-add-props xx nil
|
|
|
|
'help-echo
|
2014-05-24 05:52:36 -04:00
|
|
|
(concat "Clipped table field, use C-c ` to edit. Full value is:\n"
|
|
|
|
(org-no-properties (copy-sequence xx))))
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq f1 (min fmax (or (string-match org-bracket-link-regexp xx) fmax)))
|
|
|
|
(unless (> f1 1)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Cannot narrow field starting with wide link \"%s\""
|
2008-03-22 11:52:18 -04:00
|
|
|
(match-string 0 xx)))
|
2013-02-13 03:46:33 -05:00
|
|
|
(setq f2 (length xx))
|
|
|
|
(if (= (org-string-width xx)
|
|
|
|
f2)
|
|
|
|
(setq f2 f1)
|
|
|
|
(setq f2 1)
|
|
|
|
(while (< (org-string-width (substring xx 0 f2))
|
|
|
|
f1)
|
|
|
|
(setq f2 (1+ f2))))
|
|
|
|
(add-text-properties f2 (length xx) (list 'org-cwidth t) xx)
|
|
|
|
(add-text-properties (if (>= (string-width (substring xx (1- f2) f2)) 2)
|
|
|
|
(1- f2) (- f2 2)) f2
|
|
|
|
(list 'display org-narrow-column-arrow)
|
|
|
|
xx)))))
|
2008-03-22 11:52:18 -04:00
|
|
|
;; Get the maximum width for each column
|
2010-03-27 11:13:45 -04:00
|
|
|
(push (apply 'max (or fmax 1) 1 (mapcar 'org-string-width column))
|
|
|
|
lengths)
|
2008-03-22 11:52:18 -04:00
|
|
|
;; Get the fraction of numbers, to decide about alignment of the column
|
2009-06-21 16:40:45 -04:00
|
|
|
(if falign1
|
|
|
|
(push (equal (downcase falign1) "r") typenums)
|
|
|
|
(setq cnt 0 frac 0.0)
|
|
|
|
(loop for x in column do
|
|
|
|
(if (equal x "")
|
|
|
|
nil
|
|
|
|
(setq frac ( / (+ (* frac cnt)
|
|
|
|
(if (string-match org-table-number-regexp x) 1 0))
|
|
|
|
(setq cnt (1+ cnt))))))
|
|
|
|
(push (>= frac org-table-number-fraction) typenums)))
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq lengths (nreverse lengths) typenums (nreverse typenums))
|
|
|
|
|
|
|
|
;; Store the alignment of this table, for later editing of single fields
|
|
|
|
(setq org-table-last-alignment typenums
|
|
|
|
org-table-last-column-widths lengths)
|
|
|
|
|
|
|
|
;; With invisible characters, `format' does not get the field width right
|
|
|
|
;; So we need to make these fields wide by hand.
|
2010-06-03 04:24:04 -04:00
|
|
|
(when (or links emph raise)
|
2008-03-22 11:52:18 -04:00
|
|
|
(loop for i from 0 upto (1- maxfields) do
|
|
|
|
(setq len (nth i lengths))
|
|
|
|
(loop for j from 0 upto (1- (length fields)) do
|
|
|
|
(setq c (nthcdr i (car (nthcdr j fields))))
|
|
|
|
(if (and (stringp (car c))
|
2010-06-03 04:24:04 -04:00
|
|
|
(or (text-property-any 0 (length (car c))
|
|
|
|
'invisible 'org-link (car c))
|
|
|
|
(text-property-any 0 (length (car c))
|
|
|
|
'org-dwidth t (car c)))
|
2008-03-22 11:52:18 -04:00
|
|
|
(< (org-string-width (car c)) len))
|
2010-05-19 05:34:23 -04:00
|
|
|
(progn
|
|
|
|
(setq space (make-string (- len (org-string-width (car c))) ?\ ))
|
|
|
|
(setcar c (if (nth i typenums)
|
|
|
|
(concat space (car c))
|
|
|
|
(concat (car c) space))))))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
;; Compute the formats needed for output of the table
|
|
|
|
(setq rfmt (concat indent "|") hfmt (concat indent "|"))
|
|
|
|
(while (setq l (pop lengths))
|
|
|
|
(setq ty (if (pop typenums) "" "-")) ; number types flushright
|
|
|
|
(setq rfmt (concat rfmt (format rfmt1 ty l))
|
|
|
|
hfmt (concat hfmt (format hfmt1 (make-string l ?-)))))
|
|
|
|
(setq rfmt (concat rfmt "\n")
|
|
|
|
hfmt (concat (substring hfmt 0 -1) "|\n"))
|
|
|
|
|
|
|
|
(setq new (mapconcat
|
|
|
|
(lambda (l)
|
|
|
|
(if l (apply 'format rfmt
|
|
|
|
(append (pop fields) emptystrings))
|
|
|
|
hfmt))
|
|
|
|
lines ""))
|
|
|
|
(move-marker org-table-aligned-begin-marker (point))
|
|
|
|
(insert new)
|
2009-08-27 06:50:36 -04:00
|
|
|
;; Replace the old one
|
|
|
|
(delete-region (point) end)
|
|
|
|
(move-marker end nil)
|
2008-03-22 11:52:18 -04:00
|
|
|
(move-marker org-table-aligned-end-marker (point))
|
Use (derived-mode-p 'org-mode) instead of (eq major-mode 'org-mode).
* org.el (org-show-hierarchy-above, org-cycle)
(org-global-cycle, org-files-list, org-store-link)
(org-link-search, org-open-file, org-display-outline-path)
(org-refile-get-location, org-update-all-dblocks)
(org-change-tag-in-region, org-entry-properties)
(org-save-all-org-buffers, org-revert-all-org-buffers)
(org-buffer-list, org-cdlatex-mode)
(org-install-agenda-files-menu, org-end-of-subtree)
(org-speedbar-set-agenda-restriction): Use (derived-mode-p
'org-mode) instead of (eq major-mode 'org-mode).
* org-timer.el (org-timer-set-timer): Ditto.
* org-table.el (orgtbl-mode, org-table-align, orgtbl-mode): Ditto.
* org-src.el (org-edit-src-exit, org-edit-src-code)
(org-edit-fixed-width-region, org-edit-src-exit): Ditto.
* org-remember.el (org-remember-handler): Ditto.
* org-mouse.el (dnd-open-file, org-mouse-insert-item): Ditto.
* org-macs.el (org-get-limited-outline-regexp): Ditto.
* org-lparse.el (org-replace-region-by): Ditto.
* org-latex.el (org-latex-to-pdf-process)
(org-replace-region-by-latex): Ditto.
* org-indent.el (org-indent-indent-buffer): Ditto.
* org-id.el (org-id-store-link, org-id-update-id-locations)
(org-id-store-link): Ditto.
* org-html.el (org-export-html-preprocess)
(org-replace-region-by-html): Ditto.
* org-footnote.el (org-footnote-normalize)
(org-footnote-goto-definition)
(org-footnote-create-definition, org-footnote-normalize): Ditto.
* org-docbook.el (org-replace-region-by-docbook): Ditto.
* org-ctags.el (find-tag): Ditto.
* org-colview.el (org-columns-redo)
(org-columns-display-here, org-columns-edit-value)
(org-columns-redo): Ditto.
* org-colview-xemacs.el (org-columns-redo)
(org-columns-display-here, org-columns-edit-value)
(org-columns-redo): Ditto.
* org-capture.el (org-capture-insert-template-here)
(org-capture, org-capture-finalize)
(org-capture-set-target-location)
(org-capture-insert-template-here): Ditto.
* org-ascii.el (org-replace-region-by-ascii): Ditto.
* org-archive.el (org-archive-subtree): Ditto.
* org-agenda.el (org-agenda)
(org-agenda-get-restriction-and-command)
(org-agenda-get-some-entry-text, org-search-view)
(org-tags-view, org-agenda-get-day-entries)
(org-agenda-format-item, org-agenda-goto, org-agenda-kill)
(org-agenda-archive-with, org-agenda-switch-to): Ditto.
2012-04-20 14:03:45 -04:00
|
|
|
(when (and orgtbl-mode (not (derived-mode-p 'org-mode)))
|
2008-03-22 11:52:18 -04:00
|
|
|
(goto-char org-table-aligned-begin-marker)
|
|
|
|
(while (org-hide-wide-columns org-table-aligned-end-marker)))
|
|
|
|
;; Try to move to the old location
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line winstartline)
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq winstart (point-at-bol))
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line linepos)
|
2013-02-16 08:08:47 -05:00
|
|
|
(when (eq (window-buffer (selected-window)) (current-buffer))
|
|
|
|
(set-window-start (selected-window) winstart 'noforce))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-goto-column colpos)
|
|
|
|
(and org-table-overlay-coordinates (org-table-overlay-coordinates))
|
|
|
|
(setq org-table-may-need-update nil)
|
|
|
|
))
|
|
|
|
|
2013-11-15 00:53:59 -05:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-begin (&optional table-type)
|
|
|
|
"Find the beginning of the table and return its position.
|
|
|
|
With argument TABLE-TYPE, go to the beginning of a table.el-type table."
|
|
|
|
(save-excursion
|
|
|
|
(if (not (re-search-backward
|
|
|
|
(if table-type org-table-any-border-regexp
|
|
|
|
org-table-border-regexp)
|
|
|
|
nil t))
|
|
|
|
(progn (goto-char (point-min)) (point))
|
|
|
|
(goto-char (match-beginning 0))
|
|
|
|
(beginning-of-line 2)
|
|
|
|
(point))))
|
|
|
|
|
2013-11-15 00:53:59 -05:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-end (&optional table-type)
|
|
|
|
"Find the end of the table and return its position.
|
|
|
|
With argument TABLE-TYPE, go to the end of a table.el-type table."
|
|
|
|
(save-excursion
|
|
|
|
(if (not (re-search-forward
|
|
|
|
(if table-type org-table-any-border-regexp
|
|
|
|
org-table-border-regexp)
|
|
|
|
nil t))
|
|
|
|
(goto-char (point-max))
|
|
|
|
(goto-char (match-beginning 0)))
|
|
|
|
(point-marker)))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-justify-field-maybe (&optional new)
|
|
|
|
"Justify the current field, text to left, number to right.
|
|
|
|
Optional argument NEW may specify text to replace the current field content."
|
|
|
|
(cond
|
|
|
|
((and (not new) org-table-may-need-update)) ; Realignment will happen anyway
|
|
|
|
((org-at-table-hline-p))
|
|
|
|
((and (not new)
|
|
|
|
(or (not (equal (marker-buffer org-table-aligned-begin-marker)
|
|
|
|
(current-buffer)))
|
|
|
|
(< (point) org-table-aligned-begin-marker)
|
|
|
|
(>= (point) org-table-aligned-end-marker)))
|
|
|
|
;; This is not the same table, force a full re-align
|
|
|
|
(setq org-table-may-need-update t))
|
|
|
|
(t ;; realign the current field, based on previous full realign
|
|
|
|
(let* ((pos (point)) s
|
|
|
|
(col (org-table-current-column))
|
|
|
|
(num (if (> col 0) (nth (1- col) org-table-last-alignment)))
|
|
|
|
l f n o e)
|
|
|
|
(when (> col 0)
|
|
|
|
(skip-chars-backward "^|\n")
|
|
|
|
(if (looking-at " *\\([^|\n]*?\\) *\\(|\\|$\\)")
|
|
|
|
(progn
|
|
|
|
(setq s (match-string 1)
|
|
|
|
o (match-string 0)
|
2013-02-12 22:56:18 -05:00
|
|
|
l (max 1
|
|
|
|
(- (org-string-width
|
|
|
|
(buffer-substring-no-properties
|
|
|
|
(match-end 0) (match-beginning 0))) 3))
|
2008-03-22 11:52:18 -04:00
|
|
|
e (not (= (match-beginning 2) (match-end 2))))
|
|
|
|
(setq f (format (if num " %%%ds %s" " %%-%ds %s")
|
|
|
|
l (if e "|" (setq org-table-may-need-update t) ""))
|
|
|
|
n (format f s))
|
|
|
|
(if new
|
2013-02-12 22:56:18 -05:00
|
|
|
(if (<= (org-string-width new) l)
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq n (format f new))
|
|
|
|
(setq n (concat new "|") org-table-may-need-update t)))
|
2010-04-24 04:22:49 -04:00
|
|
|
(if (equal (string-to-char n) ?-) (setq n (concat " " n)))
|
2008-03-22 11:52:18 -04:00
|
|
|
(or (equal n o)
|
|
|
|
(let (org-table-may-need-update)
|
|
|
|
(replace-match n t t))))
|
|
|
|
(setq org-table-may-need-update t))
|
|
|
|
(goto-char pos))))))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-next-field ()
|
|
|
|
"Go to the next field in the current table, creating new lines as needed.
|
|
|
|
Before doing so, re-align the table if necessary."
|
|
|
|
(interactive)
|
|
|
|
(org-table-maybe-eval-formula)
|
|
|
|
(org-table-maybe-recalculate-line)
|
|
|
|
(if (and org-table-automatic-realign
|
|
|
|
org-table-may-need-update)
|
|
|
|
(org-table-align))
|
|
|
|
(let ((end (org-table-end)))
|
|
|
|
(if (org-at-table-hline-p)
|
|
|
|
(end-of-line 1))
|
|
|
|
(condition-case nil
|
|
|
|
(progn
|
|
|
|
(re-search-forward "|" end)
|
|
|
|
(if (looking-at "[ \t]*$")
|
|
|
|
(re-search-forward "|" end))
|
|
|
|
(if (and (looking-at "-")
|
|
|
|
org-table-tab-jumps-over-hlines
|
|
|
|
(re-search-forward "^[ \t]*|\\([^-]\\)" end t))
|
|
|
|
(goto-char (match-beginning 1)))
|
|
|
|
(if (looking-at "-")
|
|
|
|
(progn
|
|
|
|
(beginning-of-line 0)
|
|
|
|
(org-table-insert-row 'below))
|
|
|
|
(if (looking-at " ") (forward-char 1))))
|
|
|
|
(error
|
|
|
|
(org-table-insert-row 'below)))))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-previous-field ()
|
|
|
|
"Go to the previous field in the table.
|
|
|
|
Before doing so, re-align the table if necessary."
|
|
|
|
(interactive)
|
|
|
|
(org-table-justify-field-maybe)
|
|
|
|
(org-table-maybe-recalculate-line)
|
|
|
|
(if (and org-table-automatic-realign
|
|
|
|
org-table-may-need-update)
|
|
|
|
(org-table-align))
|
|
|
|
(if (org-at-table-hline-p)
|
|
|
|
(end-of-line 1))
|
2009-03-21 13:16:11 -04:00
|
|
|
(condition-case nil
|
|
|
|
(progn
|
|
|
|
(re-search-backward "|" (org-table-begin))
|
|
|
|
(re-search-backward "|" (org-table-begin)))
|
2013-02-22 04:31:35 -05:00
|
|
|
(error (user-error "Cannot move to previous table field")))
|
2008-03-22 11:52:18 -04:00
|
|
|
(while (looking-at "|\\(-\\|[ \t]*$\\)")
|
|
|
|
(re-search-backward "|" (org-table-begin)))
|
|
|
|
(if (looking-at "| ?")
|
|
|
|
(goto-char (match-end 0))))
|
|
|
|
|
2009-03-21 13:16:11 -04:00
|
|
|
(defun org-table-beginning-of-field (&optional n)
|
|
|
|
"Move to the end of the current table field.
|
|
|
|
If already at or after the end, move to the end of the next table field.
|
|
|
|
With numeric argument N, move N-1 fields forward first."
|
|
|
|
(interactive "p")
|
|
|
|
(let ((pos (point)))
|
|
|
|
(while (> n 1)
|
|
|
|
(setq n (1- n))
|
|
|
|
(org-table-previous-field))
|
|
|
|
(if (not (re-search-backward "|" (point-at-bol 0) t))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "No more table fields before the current")
|
2009-03-21 13:16:11 -04:00
|
|
|
(goto-char (match-end 0))
|
|
|
|
(and (looking-at " ") (forward-char 1)))
|
|
|
|
(if (>= (point) pos) (org-table-beginning-of-field 2))))
|
|
|
|
|
|
|
|
(defun org-table-end-of-field (&optional n)
|
|
|
|
"Move to the beginning of the current table field.
|
|
|
|
If already at or before the beginning, move to the beginning of the
|
|
|
|
previous field.
|
|
|
|
With numeric argument N, move N-1 fields backward first."
|
|
|
|
(interactive "p")
|
|
|
|
(let ((pos (point)))
|
|
|
|
(while (> n 1)
|
|
|
|
(setq n (1- n))
|
|
|
|
(org-table-next-field))
|
|
|
|
(when (re-search-forward "|" (point-at-eol 1) t)
|
|
|
|
(backward-char 1)
|
|
|
|
(skip-chars-backward " ")
|
|
|
|
(if (and (equal (char-before (point)) ?|) (looking-at " "))
|
|
|
|
(forward-char 1)))
|
|
|
|
(if (<= (point) pos) (org-table-end-of-field 2))))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-next-row ()
|
|
|
|
"Go to the next row (same column) in the current table.
|
|
|
|
Before doing so, re-align the table if necessary."
|
|
|
|
(interactive)
|
|
|
|
(org-table-maybe-eval-formula)
|
|
|
|
(org-table-maybe-recalculate-line)
|
|
|
|
(if (or (looking-at "[ \t]*$")
|
|
|
|
(save-excursion (skip-chars-backward " \t") (bolp)))
|
|
|
|
(newline)
|
|
|
|
(if (and org-table-automatic-realign
|
|
|
|
org-table-may-need-update)
|
|
|
|
(org-table-align))
|
|
|
|
(let ((col (org-table-current-column)))
|
|
|
|
(beginning-of-line 2)
|
|
|
|
(if (or (not (org-at-table-p))
|
|
|
|
(org-at-table-hline-p))
|
|
|
|
(progn
|
|
|
|
(beginning-of-line 0)
|
|
|
|
(org-table-insert-row 'below)))
|
|
|
|
(org-table-goto-column col)
|
|
|
|
(skip-chars-backward "^|\n\r")
|
|
|
|
(if (looking-at " ") (forward-char 1)))))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-copy-down (n)
|
2014-05-20 10:07:01 -04:00
|
|
|
"Copy the value of the current field one row below.
|
|
|
|
|
|
|
|
If the field at the cursor is empty, copy the content of the
|
|
|
|
nearest non-empty field above. With argument N, use the Nth
|
|
|
|
non-empty field.
|
|
|
|
|
|
|
|
If the current field is not empty, it is copied down to the next
|
|
|
|
row, and the cursor is moved with it. Therefore, repeating this
|
|
|
|
command causes the column to be filled row-by-row.
|
|
|
|
|
2011-02-26 11:16:41 -05:00
|
|
|
If the variable `org-table-copy-increment' is non-nil and the
|
|
|
|
field is an integer or a timestamp, it will be incremented while
|
2014-05-20 10:07:01 -04:00
|
|
|
copying. By default, increment by the difference between the
|
|
|
|
value in the current field and the one in the field above. To
|
|
|
|
increment using a fixed integer, set `org-table-copy-increment'
|
|
|
|
to a number. In the case of a timestamp, increment by days."
|
2008-03-22 11:52:18 -04:00
|
|
|
(interactive "p")
|
|
|
|
(let* ((colpos (org-table-current-column))
|
|
|
|
(col (current-column))
|
2013-04-10 18:32:33 -04:00
|
|
|
(field (save-excursion (org-table-get-field)))
|
2014-05-20 10:07:01 -04:00
|
|
|
(field-up (or (save-excursion
|
|
|
|
(org-table-get (1- (org-table-current-line))
|
|
|
|
(org-table-current-column))) ""))
|
2008-03-22 11:52:18 -04:00
|
|
|
(non-empty (string-match "[^ \t]" field))
|
2014-05-20 10:07:01 -04:00
|
|
|
(non-empty-up (string-match "[^ \t]" field-up))
|
2008-03-22 11:52:18 -04:00
|
|
|
(beg (org-table-begin))
|
2008-09-08 14:18:18 -04:00
|
|
|
(orig-n n)
|
2014-05-20 10:07:01 -04:00
|
|
|
txt txt-up inc)
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-check-inside-data-field)
|
2014-05-21 11:48:29 -04:00
|
|
|
(if (not non-empty)
|
2008-03-22 11:52:18 -04:00
|
|
|
(save-excursion
|
|
|
|
(setq txt
|
|
|
|
(catch 'exit
|
|
|
|
(while (progn (beginning-of-line 1)
|
|
|
|
(re-search-backward org-table-dataline-regexp
|
|
|
|
beg t))
|
|
|
|
(org-table-goto-column colpos t)
|
|
|
|
(if (and (looking-at
|
|
|
|
"|[ \t]*\\([^| \t][^|]*?\\)[ \t]*|")
|
2008-09-08 14:18:18 -04:00
|
|
|
(<= (setq n (1- n)) 0))
|
2014-05-21 11:48:29 -04:00
|
|
|
(throw 'exit (match-string 1))))))
|
|
|
|
(setq field-up
|
|
|
|
(catch 'exit
|
|
|
|
(while (progn (beginning-of-line 1)
|
|
|
|
(re-search-backward org-table-dataline-regexp
|
|
|
|
beg t))
|
|
|
|
(org-table-goto-column colpos t)
|
|
|
|
(if (and (looking-at
|
|
|
|
"|[ \t]*\\([^| \t][^|]*?\\)[ \t]*|")
|
|
|
|
(<= (setq n (1- n)) 0))
|
|
|
|
(throw 'exit (match-string 1))))))
|
2014-05-21 12:37:53 -04:00
|
|
|
(setq non-empty-up (and field-up (string-match "[^ \t]" field-up))))
|
2014-05-21 11:48:29 -04:00
|
|
|
;; Above field was not empty, go down to the next row
|
|
|
|
(setq txt (org-trim field))
|
2014-05-20 10:07:01 -04:00
|
|
|
(org-table-next-row)
|
|
|
|
(org-table-blank-field))
|
2014-05-21 11:48:29 -04:00
|
|
|
(if non-empty-up (setq txt-up (org-trim field-up)))
|
2014-05-20 10:07:01 -04:00
|
|
|
(setq inc (cond
|
|
|
|
((numberp org-table-copy-increment) org-table-copy-increment)
|
2014-05-20 15:44:37 -04:00
|
|
|
(txt-up (cond ((and (string-match org-ts-regexp3 txt-up)
|
|
|
|
(string-match org-ts-regexp3 txt))
|
|
|
|
(- (org-time-string-to-absolute txt)
|
|
|
|
(org-time-string-to-absolute txt-up)))
|
2014-05-21 12:37:53 -04:00
|
|
|
((string-match org-ts-regexp3 txt) 1)
|
2014-05-31 04:47:55 -04:00
|
|
|
((string-match "^[0-9]+\\(\.[0-9]+\\)?" txt-up)
|
|
|
|
(- (string-to-number txt)
|
|
|
|
(string-to-number (match-string 0 txt-up))))
|
|
|
|
(t 1)))
|
2014-05-20 10:07:01 -04:00
|
|
|
(t 1)))
|
2014-05-20 15:44:37 -04:00
|
|
|
(if (not txt)
|
|
|
|
(user-error "No non-empty field found")
|
|
|
|
(if (and org-table-copy-increment
|
|
|
|
(not (equal orig-n 0))
|
|
|
|
(string-match "^[-+^/*0-9eE.]+$" txt)
|
|
|
|
(< (string-to-number txt) 100000000))
|
|
|
|
(setq txt (calc-eval (concat txt "+" (number-to-string inc)))))
|
|
|
|
(insert txt)
|
|
|
|
(org-move-to-column col)
|
|
|
|
(if (and org-table-copy-increment (org-at-timestamp-p t))
|
|
|
|
(org-timestamp-up-day inc)
|
|
|
|
(org-table-maybe-recalculate-line))
|
|
|
|
(org-table-align)
|
|
|
|
(org-move-to-column col))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
2011-05-11 03:48:36 -04:00
|
|
|
(defun org-table-check-inside-data-field (&optional noerror)
|
2008-03-22 11:52:18 -04:00
|
|
|
"Is point inside a table data field?
|
|
|
|
I.e. not on a hline or before the first or after the last column?
|
|
|
|
This actually throws an error, so it aborts the current command."
|
|
|
|
(if (or (not (org-at-table-p))
|
|
|
|
(= (org-table-current-column) 0)
|
|
|
|
(org-at-table-hline-p)
|
|
|
|
(looking-at "[ \t]*$"))
|
2011-05-11 03:48:36 -04:00
|
|
|
(if noerror
|
|
|
|
nil
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Not in table data field"))
|
2011-05-11 03:48:36 -04:00
|
|
|
t))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defvar org-table-clip nil
|
|
|
|
"Clipboard for table regions.")
|
|
|
|
|
2010-03-21 15:08:01 -04:00
|
|
|
(defun org-table-get (line column)
|
|
|
|
"Get the field in table line LINE, column COLUMN.
|
|
|
|
If LINE is larger than the number of data lines in the table, the function
|
|
|
|
returns nil. However, if COLUMN is too large, we will simply return an
|
|
|
|
empty string.
|
|
|
|
If LINE is nil, use the current line.
|
2014-09-19 14:37:46 -04:00
|
|
|
If COLUMN is nil, use the current column."
|
2010-03-21 15:08:01 -04:00
|
|
|
(setq column (or column (org-table-current-column)))
|
|
|
|
(save-excursion
|
|
|
|
(and (or (not line) (org-table-goto-line line))
|
|
|
|
(org-trim (org-table-get-field column)))))
|
|
|
|
|
|
|
|
(defun org-table-put (line column value &optional align)
|
|
|
|
"Put VALUE into line LINE, column COLUMN.
|
2010-07-17 14:53:36 -04:00
|
|
|
When ALIGN is set, also realign the table."
|
2010-03-21 15:08:01 -04:00
|
|
|
(setq column (or column (org-table-current-column)))
|
|
|
|
(prog1 (save-excursion
|
|
|
|
(and (or (not line) (org-table-goto-line line))
|
|
|
|
(progn (org-table-goto-column column nil 'force) t)
|
|
|
|
(org-table-get-field column value)))
|
|
|
|
(and align (org-table-align))))
|
2010-04-01 07:11:54 -04:00
|
|
|
|
2010-03-21 15:08:01 -04:00
|
|
|
(defun org-table-current-line ()
|
|
|
|
"Return the index of the current data line."
|
2010-04-01 07:11:54 -04:00
|
|
|
(let ((pos (point)) (end (org-table-end)) (cnt 0))
|
2010-03-21 15:08:01 -04:00
|
|
|
(save-excursion
|
|
|
|
(goto-char (org-table-begin))
|
|
|
|
(while (and (re-search-forward org-table-dataline-regexp end t)
|
|
|
|
(setq cnt (1+ cnt))
|
|
|
|
(< (point-at-eol) pos))))
|
|
|
|
cnt))
|
|
|
|
|
|
|
|
(defun org-table-goto-line (N)
|
|
|
|
"Go to the Nth data line in the current table.
|
|
|
|
Return t when the line exists, nil if it does not exist."
|
|
|
|
(goto-char (org-table-begin))
|
|
|
|
(let ((end (org-table-end)) (cnt 0))
|
|
|
|
(while (and (re-search-forward org-table-dataline-regexp end t)
|
2010-03-25 07:47:48 -04:00
|
|
|
(< (setq cnt (1+ cnt)) N)))
|
2010-03-26 06:22:56 -04:00
|
|
|
(= cnt N)))
|
2010-03-21 15:08:01 -04:00
|
|
|
|
2013-11-15 00:53:59 -05:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-blank-field ()
|
|
|
|
"Blank the current table field or active region."
|
|
|
|
(interactive)
|
|
|
|
(org-table-check-inside-data-field)
|
2011-06-29 18:25:09 -04:00
|
|
|
(if (and (org-called-interactively-p 'any) (org-region-active-p))
|
2008-03-22 11:52:18 -04:00
|
|
|
(let (org-table-clip)
|
|
|
|
(org-table-cut-region (region-beginning) (region-end)))
|
|
|
|
(skip-chars-backward "^|")
|
|
|
|
(backward-char 1)
|
|
|
|
(if (looking-at "|[^|\n]+")
|
|
|
|
(let* ((pos (match-beginning 0))
|
|
|
|
(match (match-string 0))
|
|
|
|
(len (org-string-width match)))
|
|
|
|
(replace-match (concat "|" (make-string (1- len) ?\ )))
|
|
|
|
(goto-char (+ 2 pos))
|
|
|
|
(substring match 1)))))
|
|
|
|
|
|
|
|
(defun org-table-get-field (&optional n replace)
|
|
|
|
"Return the value of the field in column N of current row.
|
|
|
|
N defaults to current field.
|
|
|
|
If REPLACE is a string, replace field with this value. The return value
|
|
|
|
is always the old value."
|
|
|
|
(and n (org-table-goto-column n))
|
|
|
|
(skip-chars-backward "^|\n")
|
|
|
|
(backward-char 1)
|
|
|
|
(if (looking-at "|[^|\r\n]*")
|
|
|
|
(let* ((pos (match-beginning 0))
|
|
|
|
(val (buffer-substring (1+ pos) (match-end 0))))
|
|
|
|
(if replace
|
2011-05-26 02:39:46 -04:00
|
|
|
(replace-match (concat "|" (if (equal replace "") " " replace))
|
|
|
|
t t))
|
2008-03-22 11:52:18 -04:00
|
|
|
(goto-char (min (point-at-eol) (+ 2 pos)))
|
|
|
|
val)
|
|
|
|
(forward-char 1) ""))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-field-info (arg)
|
|
|
|
"Show info about the current field, and highlight any reference at point."
|
|
|
|
(interactive "P")
|
2014-01-30 05:58:28 -05:00
|
|
|
(unless (org-at-table-p) (user-error "Not at a table"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-get-specials)
|
|
|
|
(save-excursion
|
|
|
|
(let* ((pos (point))
|
|
|
|
(col (org-table-current-column))
|
|
|
|
(cname (car (rassoc (int-to-string col) org-table-column-names)))
|
|
|
|
(name (car (rassoc (list (org-current-line) col)
|
|
|
|
org-table-named-field-locations)))
|
2011-03-01 03:05:56 -05:00
|
|
|
(eql (org-table-expand-lhs-ranges
|
|
|
|
(mapcar
|
|
|
|
(lambda (e)
|
2011-03-08 08:49:53 -05:00
|
|
|
(cons (org-table-formula-handle-first/last-rc
|
|
|
|
(car e)) (cdr e)))
|
2011-03-01 03:05:56 -05:00
|
|
|
(org-table-get-stored-formulas))))
|
2008-03-22 11:52:18 -04:00
|
|
|
(dline (org-table-current-dline))
|
|
|
|
(ref (format "@%d$%d" dline col))
|
|
|
|
(ref1 (org-table-convert-refs-to-an ref))
|
|
|
|
(fequation (or (assoc name eql) (assoc ref eql)))
|
|
|
|
(cequation (assoc (int-to-string col) eql))
|
|
|
|
(eqn (or fequation cequation)))
|
2011-03-01 03:05:56 -05:00
|
|
|
(if (and eqn (get-text-property 0 :orig-eqn (car eqn)))
|
|
|
|
(setq eqn (get-text-property 0 :orig-eqn (car eqn))))
|
2008-03-22 11:52:18 -04:00
|
|
|
(goto-char pos)
|
|
|
|
(condition-case nil
|
|
|
|
(org-table-show-reference 'local)
|
|
|
|
(error nil))
|
|
|
|
(message "line @%d, col $%s%s, ref @%d$%d or %s%s%s"
|
|
|
|
dline col
|
|
|
|
(if cname (concat " or $" cname) "")
|
|
|
|
dline col ref1
|
|
|
|
(if name (concat " or $" name) "")
|
|
|
|
;; FIXME: formula info not correct if special table line
|
|
|
|
(if eqn
|
|
|
|
(concat ", formula: "
|
|
|
|
(org-table-formula-to-user
|
|
|
|
(concat
|
|
|
|
(if (string-match "^[$@]"(car eqn)) "" "$")
|
|
|
|
(car eqn) "=" (cdr eqn))))
|
|
|
|
"")))))
|
|
|
|
|
|
|
|
(defun org-table-current-column ()
|
|
|
|
"Find out which column we are in."
|
2010-09-30 02:29:37 -04:00
|
|
|
(interactive)
|
2011-06-29 18:25:09 -04:00
|
|
|
(if (org-called-interactively-p 'any) (org-table-check-inside-data-field))
|
2008-03-22 11:52:18 -04:00
|
|
|
(save-excursion
|
|
|
|
(let ((cnt 0) (pos (point)))
|
|
|
|
(beginning-of-line 1)
|
|
|
|
(while (search-forward "|" pos t)
|
|
|
|
(setq cnt (1+ cnt)))
|
2011-06-29 18:25:09 -04:00
|
|
|
(when (org-called-interactively-p 'interactive)
|
|
|
|
(message "In table column %d" cnt))
|
2008-03-22 11:52:18 -04:00
|
|
|
cnt)))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-current-dline ()
|
|
|
|
"Find out what table data line we are in.
|
2010-07-17 14:53:36 -04:00
|
|
|
Only data lines count for this."
|
2008-03-22 11:52:18 -04:00
|
|
|
(interactive)
|
2011-06-29 18:25:09 -04:00
|
|
|
(when (org-called-interactively-p 'any)
|
|
|
|
(org-table-check-inside-data-field))
|
2008-03-22 11:52:18 -04:00
|
|
|
(save-excursion
|
|
|
|
(let ((cnt 0) (pos (point)))
|
|
|
|
(goto-char (org-table-begin))
|
|
|
|
(while (<= (point) pos)
|
|
|
|
(if (looking-at org-table-dataline-regexp) (setq cnt (1+ cnt)))
|
|
|
|
(beginning-of-line 2))
|
2011-06-29 18:25:09 -04:00
|
|
|
(when (org-called-interactively-p 'any)
|
|
|
|
(message "This is table line %d" cnt))
|
2008-03-22 11:52:18 -04:00
|
|
|
cnt)))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-goto-column (n &optional on-delim force)
|
|
|
|
"Move the cursor to the Nth column in the current table line.
|
|
|
|
With optional argument ON-DELIM, stop with point before the left delimiter
|
|
|
|
of the field.
|
|
|
|
If there are less than N fields, just go to after the last delimiter.
|
|
|
|
However, when FORCE is non-nil, create new columns if necessary."
|
|
|
|
(interactive "p")
|
2010-03-21 15:08:01 -04:00
|
|
|
(beginning-of-line 1)
|
|
|
|
(when (> n 0)
|
|
|
|
(while (and (> (setq n (1- n)) -1)
|
|
|
|
(or (search-forward "|" (point-at-eol) t)
|
|
|
|
(and force
|
|
|
|
(progn (end-of-line 1)
|
|
|
|
(skip-chars-backward "^|")
|
|
|
|
(insert " | ")
|
|
|
|
t)))))
|
|
|
|
(when (and force (not (looking-at ".*|")))
|
|
|
|
(save-excursion (end-of-line 1) (insert " | ")))
|
|
|
|
(if on-delim
|
|
|
|
(backward-char 1)
|
|
|
|
(if (looking-at " ") (forward-char 1)))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-insert-column ()
|
|
|
|
"Insert a new column into the table."
|
|
|
|
(interactive)
|
|
|
|
(if (not (org-at-table-p))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Not at a table"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-find-dataline)
|
|
|
|
(let* ((col (max 1 (org-table-current-column)))
|
|
|
|
(beg (org-table-begin))
|
|
|
|
(end (org-table-end))
|
|
|
|
;; Current cursor position
|
|
|
|
(linepos (org-current-line))
|
|
|
|
(colpos col))
|
|
|
|
(goto-char beg)
|
|
|
|
(while (< (point) end)
|
|
|
|
(if (org-at-table-hline-p)
|
|
|
|
nil
|
|
|
|
(org-table-goto-column col t)
|
|
|
|
(insert "| "))
|
|
|
|
(beginning-of-line 2))
|
|
|
|
(move-marker end nil)
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line linepos)
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-goto-column colpos)
|
|
|
|
(org-table-align)
|
2011-03-05 17:22:32 -05:00
|
|
|
(when (or (not org-table-fix-formulas-confirm)
|
|
|
|
(funcall org-table-fix-formulas-confirm "Fix formulas? "))
|
|
|
|
(org-table-fix-formulas "$" nil (1- col) 1)
|
|
|
|
(org-table-fix-formulas "$LR" nil (1- col) 1))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defun org-table-find-dataline ()
|
2010-07-17 14:53:36 -04:00
|
|
|
"Find a data line in the current table, which is needed for column commands."
|
2008-03-22 11:52:18 -04:00
|
|
|
(if (and (org-at-table-p)
|
|
|
|
(not (org-at-table-hline-p)))
|
|
|
|
t
|
|
|
|
(let ((col (current-column))
|
|
|
|
(end (org-table-end)))
|
2014-03-20 10:04:49 -04:00
|
|
|
(org-move-to-column col)
|
2008-03-22 11:52:18 -04:00
|
|
|
(while (and (< (point) end)
|
|
|
|
(or (not (= (current-column) col))
|
|
|
|
(org-at-table-hline-p)))
|
|
|
|
(beginning-of-line 2)
|
2014-03-20 10:04:49 -04:00
|
|
|
(org-move-to-column col))
|
2008-03-22 11:52:18 -04:00
|
|
|
(if (and (org-at-table-p)
|
|
|
|
(not (org-at-table-hline-p)))
|
|
|
|
t
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error
|
2008-03-22 11:52:18 -04:00
|
|
|
"Please position cursor in a data line for column operations")))))
|
|
|
|
|
2011-03-01 03:05:56 -05:00
|
|
|
(defun org-table-line-to-dline (line &optional above)
|
|
|
|
"Turn a buffer line number into a data line number.
|
|
|
|
If there is no data line in this line, return nil.
|
2012-01-10 05:56:15 -05:00
|
|
|
If there is no matching dline (most likely te reference was a hline), the
|
2011-03-01 03:05:56 -05:00
|
|
|
first dline below it is used. When ABOVE is non-nil, the one above is used."
|
|
|
|
(catch 'exit
|
|
|
|
(let ((ll (length org-table-dlines))
|
|
|
|
i)
|
|
|
|
(if above
|
|
|
|
(progn
|
|
|
|
(setq i (1- ll))
|
|
|
|
(while (> i 0)
|
|
|
|
(if (<= (aref org-table-dlines i) line)
|
|
|
|
(throw 'exit i))
|
|
|
|
(setq i (1- i))))
|
|
|
|
(setq i 1)
|
|
|
|
(while (< i ll)
|
|
|
|
(if (>= (aref org-table-dlines i) line)
|
|
|
|
(throw 'exit i))
|
2012-08-11 13:10:44 -04:00
|
|
|
(setq i (1+ i)))))
|
|
|
|
nil))
|
2011-03-01 03:05:56 -05:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-delete-column ()
|
|
|
|
"Delete a column from the table."
|
|
|
|
(interactive)
|
|
|
|
(if (not (org-at-table-p))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Not at a table"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-find-dataline)
|
|
|
|
(org-table-check-inside-data-field)
|
|
|
|
(let* ((col (org-table-current-column))
|
|
|
|
(beg (org-table-begin))
|
|
|
|
(end (org-table-end))
|
|
|
|
;; Current cursor position
|
|
|
|
(linepos (org-current-line))
|
|
|
|
(colpos col))
|
|
|
|
(goto-char beg)
|
|
|
|
(while (< (point) end)
|
|
|
|
(if (org-at-table-hline-p)
|
|
|
|
nil
|
|
|
|
(org-table-goto-column col t)
|
|
|
|
(and (looking-at "|[^|\n]+|")
|
|
|
|
(replace-match "|")))
|
|
|
|
(beginning-of-line 2))
|
|
|
|
(move-marker end nil)
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line linepos)
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-goto-column colpos)
|
|
|
|
(org-table-align)
|
2011-03-05 17:22:32 -05:00
|
|
|
(when (or (not org-table-fix-formulas-confirm)
|
|
|
|
(funcall org-table-fix-formulas-confirm "Fix formulas? "))
|
|
|
|
(org-table-fix-formulas "$" (list (cons (number-to-string col) "INVALID"))
|
|
|
|
col -1 col)
|
|
|
|
(org-table-fix-formulas "$LR" (list (cons (number-to-string col) "INVALID"))
|
|
|
|
col -1 col))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-move-column-right ()
|
|
|
|
"Move column to the right."
|
|
|
|
(interactive)
|
|
|
|
(org-table-move-column nil))
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-move-column-left ()
|
|
|
|
"Move column to the left."
|
|
|
|
(interactive)
|
|
|
|
(org-table-move-column 'left))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-move-column (&optional left)
|
|
|
|
"Move the current column to the right. With arg LEFT, move to the left."
|
|
|
|
(interactive "P")
|
|
|
|
(if (not (org-at-table-p))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Not at a table"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-find-dataline)
|
|
|
|
(org-table-check-inside-data-field)
|
|
|
|
(let* ((col (org-table-current-column))
|
|
|
|
(col1 (if left (1- col) col))
|
|
|
|
(beg (org-table-begin))
|
|
|
|
(end (org-table-end))
|
|
|
|
;; Current cursor position
|
|
|
|
(linepos (org-current-line))
|
|
|
|
(colpos (if left (1- col) (1+ col))))
|
|
|
|
(if (and left (= col 1))
|
2013-02-22 04:31:35 -05:00
|
|
|
(user-error "Cannot move column further left"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(if (and (not left) (looking-at "[^|\n]*|[^|\n]*$"))
|
2013-02-22 04:31:35 -05:00
|
|
|
(user-error "Cannot move column further right"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(goto-char beg)
|
|
|
|
(while (< (point) end)
|
|
|
|
(if (org-at-table-hline-p)
|
|
|
|
nil
|
|
|
|
(org-table-goto-column col1 t)
|
|
|
|
(and (looking-at "|\\([^|\n]+\\)|\\([^|\n]+\\)|")
|
|
|
|
(replace-match "|\\2|\\1|")))
|
|
|
|
(beginning-of-line 2))
|
|
|
|
(move-marker end nil)
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line linepos)
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-goto-column colpos)
|
|
|
|
(org-table-align)
|
2011-03-05 17:22:32 -05:00
|
|
|
(when (or (not org-table-fix-formulas-confirm)
|
|
|
|
(funcall org-table-fix-formulas-confirm "Fix formulas? "))
|
|
|
|
(org-table-fix-formulas
|
|
|
|
"$" (list (cons (number-to-string col) (number-to-string colpos))
|
|
|
|
(cons (number-to-string colpos) (number-to-string col))))
|
|
|
|
(org-table-fix-formulas
|
|
|
|
"$LR" (list (cons (number-to-string col) (number-to-string colpos))
|
|
|
|
(cons (number-to-string colpos) (number-to-string col)))))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-move-row-down ()
|
|
|
|
"Move table row down."
|
|
|
|
(interactive)
|
|
|
|
(org-table-move-row nil))
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-move-row-up ()
|
|
|
|
"Move table row up."
|
|
|
|
(interactive)
|
|
|
|
(org-table-move-row 'up))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-move-row (&optional up)
|
|
|
|
"Move the current table line down. With arg UP, move it up."
|
|
|
|
(interactive "P")
|
|
|
|
(let* ((col (current-column))
|
|
|
|
(pos (point))
|
|
|
|
(hline1p (save-excursion (beginning-of-line 1)
|
|
|
|
(looking-at org-table-hline-regexp)))
|
|
|
|
(dline1 (org-table-current-dline))
|
|
|
|
(dline2 (+ dline1 (if up -1 1)))
|
|
|
|
(tonew (if up 0 2))
|
|
|
|
txt hline2p)
|
|
|
|
(beginning-of-line tonew)
|
|
|
|
(unless (org-at-table-p)
|
|
|
|
(goto-char pos)
|
2013-02-22 04:31:35 -05:00
|
|
|
(user-error "Cannot move row further"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq hline2p (looking-at org-table-hline-regexp))
|
|
|
|
(goto-char pos)
|
|
|
|
(beginning-of-line 1)
|
|
|
|
(setq pos (point))
|
|
|
|
(setq txt (buffer-substring (point) (1+ (point-at-eol))))
|
|
|
|
(delete-region (point) (1+ (point-at-eol)))
|
|
|
|
(beginning-of-line tonew)
|
|
|
|
(insert txt)
|
|
|
|
(beginning-of-line 0)
|
2014-03-20 10:04:49 -04:00
|
|
|
(org-move-to-column col)
|
2011-03-05 17:22:32 -05:00
|
|
|
(unless (or hline1p hline2p
|
|
|
|
(not (or (not org-table-fix-formulas-confirm)
|
2011-07-23 11:23:19 -04:00
|
|
|
(funcall org-table-fix-formulas-confirm
|
2011-03-05 17:22:32 -05:00
|
|
|
"Fix formulas? "))))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-fix-formulas
|
|
|
|
"@" (list (cons (number-to-string dline1) (number-to-string dline2))
|
|
|
|
(cons (number-to-string dline2) (number-to-string dline1)))))))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-insert-row (&optional arg)
|
|
|
|
"Insert a new row above the current line into the table.
|
|
|
|
With prefix ARG, insert below the current line."
|
|
|
|
(interactive "P")
|
|
|
|
(if (not (org-at-table-p))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Not at a table"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(let* ((line (buffer-substring (point-at-bol) (point-at-eol)))
|
|
|
|
(new (org-table-clean-line line)))
|
|
|
|
;; Fix the first field if necessary
|
|
|
|
(if (string-match "^[ \t]*| *[#$] *|" line)
|
|
|
|
(setq new (replace-match (match-string 0 line) t t new)))
|
|
|
|
(beginning-of-line (if arg 2 1))
|
|
|
|
(let (org-table-may-need-update) (insert-before-markers new "\n"))
|
|
|
|
(beginning-of-line 0)
|
|
|
|
(re-search-forward "| ?" (point-at-eol) t)
|
|
|
|
(and (or org-table-may-need-update org-table-overlay-coordinates)
|
|
|
|
(org-table-align))
|
2011-03-05 17:22:32 -05:00
|
|
|
(when (or (not org-table-fix-formulas-confirm)
|
|
|
|
(funcall org-table-fix-formulas-confirm "Fix formulas? "))
|
|
|
|
(org-table-fix-formulas "@" nil (1- (org-table-current-dline)) 1))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-insert-hline (&optional above)
|
|
|
|
"Insert a horizontal-line below the current line into the table.
|
|
|
|
With prefix ABOVE, insert above the current line."
|
|
|
|
(interactive "P")
|
|
|
|
(if (not (org-at-table-p))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Not at a table"))
|
2009-01-25 07:07:23 -05:00
|
|
|
(when (eobp) (insert "\n") (backward-char 1))
|
2009-01-21 07:14:07 -05:00
|
|
|
(if (not (string-match "|[ \t]*$" (org-current-line-string)))
|
2009-01-24 04:51:21 -05:00
|
|
|
(org-table-align))
|
2008-03-22 11:52:18 -04:00
|
|
|
(let ((line (org-table-clean-line
|
|
|
|
(buffer-substring (point-at-bol) (point-at-eol))))
|
|
|
|
(col (current-column)))
|
|
|
|
(while (string-match "|\\( +\\)|" line)
|
|
|
|
(setq line (replace-match
|
|
|
|
(concat "+" (make-string (- (match-end 1) (match-beginning 1))
|
|
|
|
?-) "|") t t line)))
|
|
|
|
(and (string-match "\\+" line) (setq line (replace-match "|" t t line)))
|
|
|
|
(beginning-of-line (if above 1 2))
|
|
|
|
(insert line "\n")
|
|
|
|
(beginning-of-line (if above 1 -1))
|
2014-03-20 10:04:49 -04:00
|
|
|
(org-move-to-column col)
|
2008-03-22 11:52:18 -04:00
|
|
|
(and org-table-overlay-coordinates (org-table-align))))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-hline-and-move (&optional same-column)
|
|
|
|
"Insert a hline and move to the row below that line."
|
|
|
|
(interactive "P")
|
|
|
|
(let ((col (org-table-current-column)))
|
|
|
|
(org-table-maybe-eval-formula)
|
|
|
|
(org-table-maybe-recalculate-line)
|
|
|
|
(org-table-insert-hline)
|
|
|
|
(end-of-line 2)
|
|
|
|
(if (looking-at "\n[ \t]*|-")
|
|
|
|
(progn (insert "\n|") (org-table-align))
|
|
|
|
(org-table-next-field))
|
|
|
|
(if same-column (org-table-goto-column col))))
|
|
|
|
|
|
|
|
(defun org-table-clean-line (s)
|
|
|
|
"Convert a table line S into a string with only \"|\" and space.
|
|
|
|
In particular, this does handle wide and invisible characters."
|
|
|
|
(if (string-match "^[ \t]*|-" s)
|
|
|
|
;; It's a hline, just map the characters
|
|
|
|
(setq s (mapconcat (lambda (x) (if (member x '(?| ?+)) "|" " ")) s ""))
|
|
|
|
(while (string-match "|\\([ \t]*?[^ \t\r\n|][^\r\n|]*\\)|" s)
|
|
|
|
(setq s (replace-match
|
|
|
|
(concat "|" (make-string (org-string-width (match-string 1 s))
|
|
|
|
?\ ) "|")
|
|
|
|
t t s)))
|
|
|
|
s))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-kill-row ()
|
|
|
|
"Delete the current row or horizontal line from the table."
|
|
|
|
(interactive)
|
|
|
|
(if (not (org-at-table-p))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Not at a table"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(let ((col (current-column))
|
|
|
|
(dline (org-table-current-dline)))
|
|
|
|
(kill-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))
|
|
|
|
(if (not (org-at-table-p)) (beginning-of-line 0))
|
2014-03-20 10:04:49 -04:00
|
|
|
(org-move-to-column col)
|
2011-03-05 17:22:32 -05:00
|
|
|
(when (or (not org-table-fix-formulas-confirm)
|
|
|
|
(funcall org-table-fix-formulas-confirm "Fix formulas? "))
|
|
|
|
(org-table-fix-formulas "@" (list (cons (number-to-string dline) "INVALID"))
|
|
|
|
dline -1 dline))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-sort-lines (with-case &optional sorting-type)
|
|
|
|
"Sort table lines according to the column at point.
|
|
|
|
|
|
|
|
The position of point indicates the column to be used for
|
|
|
|
sorting, and the range of lines is the range between the nearest
|
|
|
|
horizontal separator lines, or the entire table of no such lines
|
|
|
|
exist. If point is before the first column, you will be prompted
|
|
|
|
for the sorting column. If there is an active region, the mark
|
|
|
|
specifies the first line and the sorting column, while point
|
|
|
|
should be in the last line to be included into the sorting.
|
|
|
|
|
|
|
|
The command then prompts for the sorting type which can be
|
|
|
|
alphabetically, numerically, or by time (as given in a time stamp
|
2014-04-16 12:23:47 -04:00
|
|
|
in the field, or as a HH:MM value). Sorting in reverse order is
|
|
|
|
also possible.
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
With prefix argument WITH-CASE, alphabetic sorting will be case-sensitive.
|
|
|
|
|
|
|
|
If SORTING-TYPE is specified when this function is called from a Lisp
|
|
|
|
program, no prompting will take place. SORTING-TYPE must be a character,
|
|
|
|
any of (?a ?A ?n ?N ?t ?T) where the capital letter indicate that sorting
|
|
|
|
should be done in reverse order."
|
|
|
|
(interactive "P")
|
|
|
|
(let* ((thisline (org-current-line))
|
|
|
|
(thiscol (org-table-current-column))
|
2012-12-11 11:29:38 -05:00
|
|
|
(otc org-table-overlay-coordinates)
|
2008-03-22 11:52:18 -04:00
|
|
|
beg end bcol ecol tend tbeg column lns pos)
|
|
|
|
(when (equal thiscol 0)
|
2011-06-29 18:25:09 -04:00
|
|
|
(if (org-called-interactively-p 'any)
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq thiscol
|
|
|
|
(string-to-number
|
|
|
|
(read-string "Use column N for sorting: ")))
|
|
|
|
(setq thiscol 1))
|
|
|
|
(org-table-goto-column thiscol))
|
|
|
|
(org-table-check-inside-data-field)
|
|
|
|
(if (org-region-active-p)
|
|
|
|
(progn
|
|
|
|
(setq beg (region-beginning) end (region-end))
|
|
|
|
(goto-char beg)
|
|
|
|
(setq column (org-table-current-column)
|
|
|
|
beg (point-at-bol))
|
|
|
|
(goto-char end)
|
|
|
|
(setq end (point-at-bol 2)))
|
|
|
|
(setq column (org-table-current-column)
|
|
|
|
pos (point)
|
|
|
|
tbeg (org-table-begin)
|
|
|
|
tend (org-table-end))
|
|
|
|
(if (re-search-backward org-table-hline-regexp tbeg t)
|
|
|
|
(setq beg (point-at-bol 2))
|
|
|
|
(goto-char tbeg)
|
|
|
|
(setq beg (point-at-bol 1)))
|
|
|
|
(goto-char pos)
|
|
|
|
(if (re-search-forward org-table-hline-regexp tend t)
|
|
|
|
(setq end (point-at-bol 1))
|
|
|
|
(goto-char tend)
|
|
|
|
(setq end (point-at-bol))))
|
|
|
|
(setq beg (move-marker (make-marker) beg)
|
|
|
|
end (move-marker (make-marker) end))
|
|
|
|
(untabify beg end)
|
|
|
|
(goto-char beg)
|
|
|
|
(org-table-goto-column column)
|
|
|
|
(skip-chars-backward "^|")
|
|
|
|
(setq bcol (current-column))
|
|
|
|
(org-table-goto-column (1+ column))
|
|
|
|
(skip-chars-backward "^|")
|
|
|
|
(setq ecol (1- (current-column)))
|
|
|
|
(org-table-goto-column column)
|
|
|
|
(setq lns (mapcar (lambda(x) (cons
|
|
|
|
(org-sort-remove-invisible
|
|
|
|
(nth (1- column)
|
|
|
|
(org-split-string x "[ \t]*|[ \t]*")))
|
|
|
|
x))
|
|
|
|
(org-split-string (buffer-substring beg end) "\n")))
|
|
|
|
(setq lns (org-do-sort lns "Table" with-case sorting-type))
|
2012-12-11 11:29:38 -05:00
|
|
|
(when org-table-overlay-coordinates
|
|
|
|
(org-table-toggle-coordinate-overlays))
|
2008-03-22 11:52:18 -04:00
|
|
|
(delete-region beg end)
|
|
|
|
(move-marker beg nil)
|
|
|
|
(move-marker end nil)
|
|
|
|
(insert (mapconcat 'cdr lns "\n") "\n")
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line thisline)
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-goto-column thiscol)
|
2012-12-11 11:29:38 -05:00
|
|
|
(when otc (org-table-toggle-coordinate-overlays))
|
2008-03-22 11:52:18 -04:00
|
|
|
(message "%d lines sorted, based on column %d" (length lns) column)))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-cut-region (beg end)
|
2009-07-31 01:35:02 -04:00
|
|
|
"Copy region in table to the clipboard and blank all relevant fields.
|
|
|
|
If there is no active region, use just the field at point."
|
|
|
|
(interactive (list
|
|
|
|
(if (org-region-active-p) (region-beginning) (point))
|
|
|
|
(if (org-region-active-p) (region-end) (point))))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-copy-region beg end 'cut))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-copy-region (beg end &optional cut)
|
|
|
|
"Copy rectangular region in table to clipboard.
|
|
|
|
A special clipboard is used which can only be accessed
|
|
|
|
with `org-table-paste-rectangle'."
|
2009-07-31 01:35:02 -04:00
|
|
|
(interactive (list
|
|
|
|
(if (org-region-active-p) (region-beginning) (point))
|
|
|
|
(if (org-region-active-p) (region-end) (point))
|
|
|
|
current-prefix-arg))
|
2008-03-22 11:52:18 -04:00
|
|
|
(let* (l01 c01 l02 c02 l1 c1 l2 c2 ic1 ic2
|
2012-08-11 13:10:44 -04:00
|
|
|
region cols
|
|
|
|
(rpl (if cut " " nil)))
|
2008-03-22 11:52:18 -04:00
|
|
|
(goto-char beg)
|
|
|
|
(org-table-check-inside-data-field)
|
|
|
|
(setq l01 (org-current-line)
|
|
|
|
c01 (org-table-current-column))
|
|
|
|
(goto-char end)
|
|
|
|
(org-table-check-inside-data-field)
|
|
|
|
(setq l02 (org-current-line)
|
|
|
|
c02 (org-table-current-column))
|
|
|
|
(setq l1 (min l01 l02) l2 (max l01 l02)
|
|
|
|
c1 (min c01 c02) c2 (max c01 c02))
|
|
|
|
(catch 'exit
|
|
|
|
(while t
|
|
|
|
(catch 'nextline
|
|
|
|
(if (> l1 l2) (throw 'exit t))
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line l1)
|
2008-03-22 11:52:18 -04:00
|
|
|
(if (org-at-table-hline-p) (throw 'nextline (setq l1 (1+ l1))))
|
|
|
|
(setq cols nil ic1 c1 ic2 c2)
|
|
|
|
(while (< ic1 (1+ ic2))
|
|
|
|
(push (org-table-get-field ic1 rpl) cols)
|
|
|
|
(setq ic1 (1+ ic1)))
|
|
|
|
(push (nreverse cols) region)
|
|
|
|
(setq l1 (1+ l1)))))
|
|
|
|
(setq org-table-clip (nreverse region))
|
|
|
|
(if cut (org-table-align))
|
|
|
|
org-table-clip))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-paste-rectangle ()
|
|
|
|
"Paste a rectangular region into a table.
|
|
|
|
The upper right corner ends up in the current field. All involved fields
|
|
|
|
will be overwritten. If the rectangle does not fit into the present table,
|
|
|
|
the table is enlarged as needed. The process ignores horizontal separator
|
|
|
|
lines."
|
|
|
|
(interactive)
|
|
|
|
(unless (and org-table-clip (listp org-table-clip))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "First cut/copy a region to paste!"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-check-inside-data-field)
|
|
|
|
(let* ((clip org-table-clip)
|
|
|
|
(line (org-current-line))
|
|
|
|
(col (org-table-current-column))
|
|
|
|
(org-enable-table-editor t)
|
|
|
|
(org-table-automatic-realign nil)
|
|
|
|
c cols field)
|
|
|
|
(while (setq cols (pop clip))
|
|
|
|
(while (org-at-table-hline-p) (beginning-of-line 2))
|
|
|
|
(if (not (org-at-table-p))
|
|
|
|
(progn (end-of-line 0) (org-table-next-field)))
|
|
|
|
(setq c col)
|
|
|
|
(while (setq field (pop cols))
|
|
|
|
(org-table-goto-column c nil 'force)
|
|
|
|
(org-table-get-field nil field)
|
|
|
|
(setq c (1+ c)))
|
|
|
|
(beginning-of-line 2))
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line line)
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-goto-column col)
|
|
|
|
(org-table-align)))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-convert ()
|
|
|
|
"Convert from `org-mode' table to table.el and back.
|
|
|
|
Obviously, this only works within limits. When an Org-mode table is
|
|
|
|
converted to table.el, all horizontal separator lines get lost, because
|
|
|
|
table.el uses these as cell boundaries and has no notion of horizontal lines.
|
|
|
|
A table.el table can be converted to an Org-mode table only if it does not
|
|
|
|
do row or column spanning. Multiline cells will become multiple cells.
|
|
|
|
Beware, Org-mode does not test if the table can be successfully converted - it
|
|
|
|
blindly applies a recipe that works for simple tables."
|
|
|
|
(interactive)
|
|
|
|
(require 'table)
|
|
|
|
(if (org-at-table.el-p)
|
|
|
|
;; convert to Org-mode table
|
|
|
|
(let ((beg (move-marker (make-marker) (org-table-begin t)))
|
|
|
|
(end (move-marker (make-marker) (org-table-end t))))
|
|
|
|
(table-unrecognize-region beg end)
|
|
|
|
(goto-char beg)
|
|
|
|
(while (re-search-forward "^\\([ \t]*\\)\\+-.*\n" end t)
|
|
|
|
(replace-match ""))
|
|
|
|
(goto-char beg))
|
|
|
|
(if (org-at-table-p)
|
|
|
|
;; convert to table.el table
|
|
|
|
(let ((beg (move-marker (make-marker) (org-table-begin)))
|
|
|
|
(end (move-marker (make-marker) (org-table-end))))
|
|
|
|
;; first, get rid of all horizontal lines
|
|
|
|
(goto-char beg)
|
|
|
|
(while (re-search-forward "^\\([ \t]*\\)|-.*\n" end t)
|
|
|
|
(replace-match ""))
|
|
|
|
;; insert a hline before first
|
|
|
|
(goto-char beg)
|
|
|
|
(org-table-insert-hline 'above)
|
|
|
|
(beginning-of-line -1)
|
|
|
|
;; insert a hline after each line
|
|
|
|
(while (progn (beginning-of-line 3) (< (point) end))
|
|
|
|
(org-table-insert-hline))
|
|
|
|
(goto-char beg)
|
|
|
|
(setq end (move-marker end (org-table-end)))
|
|
|
|
;; replace "+" at beginning and ending of hlines
|
|
|
|
(while (re-search-forward "^\\([ \t]*\\)|-" end t)
|
|
|
|
(replace-match "\\1+-"))
|
|
|
|
(goto-char beg)
|
|
|
|
(while (re-search-forward "-|[ \t]*$" end t)
|
|
|
|
(replace-match "-+"))
|
|
|
|
(goto-char beg)))))
|
|
|
|
|
2011-12-11 11:34:37 -05:00
|
|
|
(defun org-table-transpose-table-at-point ()
|
2013-09-30 14:32:29 -04:00
|
|
|
"Transpose Org table at point and eliminate hlines.
|
2011-12-11 11:34:37 -05:00
|
|
|
So a table like
|
|
|
|
|
|
|
|
| 1 | 2 | 4 | 5 |
|
|
|
|
|---+---+---+---|
|
|
|
|
| a | b | c | d |
|
|
|
|
| e | f | g | h |
|
|
|
|
|
|
|
|
will be transposed as
|
|
|
|
|
|
|
|
| 1 | a | e |
|
|
|
|
| 2 | b | f |
|
|
|
|
| 4 | c | g |
|
|
|
|
| 5 | d | h |
|
|
|
|
|
2013-09-30 14:32:29 -04:00
|
|
|
Note that horizontal lines disappear."
|
2011-12-11 11:34:37 -05:00
|
|
|
(interactive)
|
2013-06-21 16:37:51 -04:00
|
|
|
(let* ((table (delete 'hline (org-table-to-lisp)))
|
2013-09-30 14:32:29 -04:00
|
|
|
(dline_old (org-table-current-line))
|
|
|
|
(col_old (org-table-current-column))
|
2013-06-21 16:37:51 -04:00
|
|
|
(contents (mapcar (lambda (p)
|
|
|
|
(let ((tp table))
|
|
|
|
(mapcar
|
|
|
|
(lambda (rown)
|
|
|
|
(prog1
|
|
|
|
(pop (car tp))
|
|
|
|
(setq tp (cdr tp))))
|
|
|
|
table)))
|
|
|
|
(car table))))
|
2013-09-30 14:32:29 -04:00
|
|
|
(goto-char (org-table-begin))
|
|
|
|
(re-search-forward "|")
|
|
|
|
(backward-char)
|
|
|
|
(delete-region (point) (org-table-end))
|
|
|
|
(insert (mapconcat
|
|
|
|
(lambda(x)
|
|
|
|
(concat "| " (mapconcat 'identity x " | " ) " |\n" ))
|
|
|
|
contents ""))
|
|
|
|
(org-table-goto-line col_old)
|
|
|
|
(org-table-goto-column dline_old))
|
|
|
|
(org-table-align))
|
2011-12-11 11:34:37 -05:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-wrap-region (arg)
|
|
|
|
"Wrap several fields in a column like a paragraph.
|
|
|
|
This is useful if you'd like to spread the contents of a field over several
|
|
|
|
lines, in order to keep the table compact.
|
|
|
|
|
|
|
|
If there is an active region, and both point and mark are in the same column,
|
|
|
|
the text in the column is wrapped to minimum width for the given number of
|
|
|
|
lines. Generally, this makes the table more compact. A prefix ARG may be
|
|
|
|
used to change the number of desired lines. For example, `C-2 \\[org-table-wrap]'
|
|
|
|
formats the selected text to two lines. If the region was longer than two
|
|
|
|
lines, the remaining lines remain empty. A negative prefix argument reduces
|
|
|
|
the current number of lines by that amount. The wrapped text is pasted back
|
|
|
|
into the table. If you formatted it to more lines than it was before, fields
|
|
|
|
further down in the table get overwritten - so you might need to make space in
|
|
|
|
the table first.
|
|
|
|
|
|
|
|
If there is no region, the current field is split at the cursor position and
|
|
|
|
the text fragment to the right of the cursor is prepended to the field one
|
|
|
|
line down.
|
|
|
|
|
|
|
|
If there is no region, but you specify a prefix ARG, the current field gets
|
|
|
|
blank, and the content is appended to the field above."
|
|
|
|
(interactive "P")
|
|
|
|
(org-table-check-inside-data-field)
|
|
|
|
(if (org-region-active-p)
|
|
|
|
;; There is a region: fill as a paragraph
|
|
|
|
(let* ((beg (region-beginning))
|
|
|
|
(cline (save-excursion (goto-char beg) (org-current-line)))
|
|
|
|
(ccol (save-excursion (goto-char beg) (org-table-current-column)))
|
|
|
|
nlines)
|
|
|
|
(org-table-cut-region (region-beginning) (region-end))
|
|
|
|
(if (> (length (car org-table-clip)) 1)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Region must be limited to single column"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq nlines (if arg
|
|
|
|
(if (< arg 1)
|
|
|
|
(+ (length org-table-clip) arg)
|
|
|
|
arg)
|
|
|
|
(length org-table-clip)))
|
|
|
|
(setq org-table-clip
|
|
|
|
(mapcar 'list (org-wrap (mapconcat 'car org-table-clip " ")
|
|
|
|
nil nlines)))
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line cline)
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-goto-column ccol)
|
|
|
|
(org-table-paste-rectangle))
|
|
|
|
;; No region, split the current field at point
|
|
|
|
(unless (org-get-alist-option org-M-RET-may-split-line 'table)
|
|
|
|
(skip-chars-forward "^\r\n|"))
|
|
|
|
(if arg
|
|
|
|
;; combine with field above
|
|
|
|
(let ((s (org-table-blank-field))
|
|
|
|
(col (org-table-current-column)))
|
|
|
|
(beginning-of-line 0)
|
|
|
|
(while (org-at-table-hline-p) (beginning-of-line 0))
|
|
|
|
(org-table-goto-column col)
|
|
|
|
(skip-chars-forward "^|")
|
|
|
|
(skip-chars-backward " ")
|
|
|
|
(insert " " (org-trim s))
|
|
|
|
(org-table-align))
|
|
|
|
;; split field
|
|
|
|
(if (looking-at "\\([^|]+\\)+|")
|
|
|
|
(let ((s (match-string 1)))
|
|
|
|
(replace-match " |")
|
|
|
|
(goto-char (match-beginning 0))
|
|
|
|
(org-table-next-row)
|
|
|
|
(insert (org-trim s) " ")
|
|
|
|
(org-table-align))
|
|
|
|
(org-table-next-row)))))
|
|
|
|
|
|
|
|
(defvar org-field-marker nil)
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-edit-field (arg)
|
|
|
|
"Edit table field in a different window.
|
|
|
|
This is mainly useful for fields that contain hidden parts.
|
|
|
|
When called with a \\[universal-argument] prefix, just make the full field visible so that
|
|
|
|
it can be edited in place."
|
|
|
|
(interactive "P")
|
2011-05-11 03:48:36 -04:00
|
|
|
(cond
|
|
|
|
((equal arg '(16))
|
|
|
|
(org-table-follow-field-mode (if org-table-follow-field-mode -1 1)))
|
|
|
|
(arg
|
|
|
|
(let ((b (save-excursion (skip-chars-backward "^|") (point)))
|
|
|
|
(e (save-excursion (skip-chars-forward "^|\r\n") (point))))
|
|
|
|
(remove-text-properties b e '(org-cwidth t invisible t
|
|
|
|
display t intangible t))
|
|
|
|
(if (and (boundp 'font-lock-mode) font-lock-mode)
|
|
|
|
(font-lock-fontify-block))))
|
|
|
|
(t
|
2012-12-19 23:46:41 -05:00
|
|
|
(let ((pos (point-marker))
|
2011-07-23 12:48:52 -04:00
|
|
|
(coord
|
|
|
|
(if (eq org-table-use-standard-references t)
|
|
|
|
(concat (org-number-to-letters (org-table-current-column))
|
|
|
|
(int-to-string (org-table-current-dline)))
|
|
|
|
(concat "@" (int-to-string (org-table-current-dline))
|
|
|
|
"$" (int-to-string (org-table-current-column)))))
|
2008-03-22 11:52:18 -04:00
|
|
|
(field (org-table-get-field))
|
|
|
|
(cw (current-window-configuration))
|
|
|
|
p)
|
2011-05-11 03:48:36 -04:00
|
|
|
(goto-char pos)
|
|
|
|
(org-switch-to-buffer-other-window "*Org Table Edit Field*")
|
|
|
|
(when (and (local-variable-p 'org-field-marker)
|
|
|
|
(markerp org-field-marker))
|
|
|
|
(move-marker org-field-marker nil))
|
2008-03-22 11:52:18 -04:00
|
|
|
(erase-buffer)
|
2011-07-23 12:48:52 -04:00
|
|
|
(insert "#\n# Edit field " coord " and finish with C-c C-c\n#\n")
|
2008-03-22 11:52:18 -04:00
|
|
|
(let ((org-inhibit-startup t)) (org-mode))
|
2011-05-11 03:48:36 -04:00
|
|
|
(auto-fill-mode -1)
|
|
|
|
(setq truncate-lines nil)
|
|
|
|
(setq word-wrap t)
|
2008-03-22 11:52:18 -04:00
|
|
|
(goto-char (setq p (point-max)))
|
|
|
|
(insert (org-trim field))
|
|
|
|
(remove-text-properties p (point-max)
|
|
|
|
'(invisible t org-cwidth t display t
|
|
|
|
intangible t))
|
|
|
|
(goto-char p)
|
|
|
|
(org-set-local 'org-finish-function 'org-table-finish-edit-field)
|
|
|
|
(org-set-local 'org-window-configuration cw)
|
|
|
|
(org-set-local 'org-field-marker pos)
|
2011-05-11 03:48:36 -04:00
|
|
|
(message "Edit and finish with C-c C-c")))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defun org-table-finish-edit-field ()
|
|
|
|
"Finish editing a table data field.
|
|
|
|
Remove all newline characters, insert the result into the table, realign
|
|
|
|
the table and kill the editing buffer."
|
|
|
|
(let ((pos org-field-marker)
|
|
|
|
(cw org-window-configuration)
|
|
|
|
(cb (current-buffer))
|
|
|
|
text)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (re-search-forward "^#.*\n?" nil t) (replace-match ""))
|
|
|
|
(while (re-search-forward "\\([ \t]*\n[ \t]*\\)+" nil t)
|
|
|
|
(replace-match " "))
|
|
|
|
(setq text (org-trim (buffer-string)))
|
|
|
|
(set-window-configuration cw)
|
|
|
|
(kill-buffer cb)
|
|
|
|
(select-window (get-buffer-window (marker-buffer pos)))
|
|
|
|
(goto-char pos)
|
|
|
|
(move-marker pos nil)
|
|
|
|
(org-table-check-inside-data-field)
|
|
|
|
(org-table-get-field nil text)
|
|
|
|
(org-table-align)
|
|
|
|
(message "New field value inserted")))
|
|
|
|
|
2011-05-11 03:48:36 -04:00
|
|
|
(define-minor-mode org-table-follow-field-mode
|
|
|
|
"Minor mode to make the table field editor window follow the cursor.
|
|
|
|
When this mode is active, the field editor window will always show the
|
|
|
|
current field. The mode exits automatically when the cursor leaves the
|
|
|
|
table (but see `org-table-exit-follow-field-mode-when-leaving-table')."
|
|
|
|
nil " TblFollow" nil
|
|
|
|
(if org-table-follow-field-mode
|
|
|
|
(org-add-hook 'post-command-hook 'org-table-follow-fields-with-editor
|
|
|
|
'append 'local)
|
|
|
|
(remove-hook 'post-command-hook 'org-table-follow-fields-with-editor 'local)
|
|
|
|
(let* ((buf (get-buffer "*Org Table Edit Field*"))
|
|
|
|
(win (and buf (get-buffer-window buf))))
|
|
|
|
(when win (delete-window win))
|
|
|
|
(when buf
|
|
|
|
(with-current-buffer buf
|
|
|
|
(move-marker org-field-marker nil))
|
|
|
|
(kill-buffer buf)))))
|
|
|
|
|
|
|
|
(defun org-table-follow-fields-with-editor ()
|
|
|
|
(if (and org-table-exit-follow-field-mode-when-leaving-table
|
|
|
|
(not (org-at-table-p)))
|
|
|
|
;; We have left the table, exit the follow mode
|
|
|
|
(org-table-follow-field-mode -1)
|
|
|
|
(when (org-table-check-inside-data-field 'noerror)
|
|
|
|
(let ((win (selected-window)))
|
|
|
|
(org-table-edit-field nil)
|
|
|
|
(org-fit-window-to-buffer)
|
|
|
|
(select-window win)))))
|
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
(defvar org-timecnt) ; dynamically scoped parameter
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-sum (&optional beg end nlast)
|
|
|
|
"Sum numbers in region of current table column.
|
|
|
|
The result will be displayed in the echo area, and will be available
|
|
|
|
as kill to be inserted with \\[yank].
|
|
|
|
|
|
|
|
If there is an active region, it is interpreted as a rectangle and all
|
|
|
|
numbers in that rectangle will be summed. If there is no active
|
|
|
|
region and point is located in a table column, sum all numbers in that
|
|
|
|
column.
|
|
|
|
|
|
|
|
If at least one number looks like a time HH:MM or HH:MM:SS, all other
|
|
|
|
numbers are assumed to be times as well (in decimal hours) and the
|
|
|
|
numbers are added as such.
|
|
|
|
|
|
|
|
If NLAST is a number, only the NLAST fields will actually be summed."
|
|
|
|
(interactive)
|
|
|
|
(save-excursion
|
|
|
|
(let (col (org-timecnt 0) diff h m s org-table-clip)
|
|
|
|
(cond
|
|
|
|
((and beg end)) ; beg and end given explicitly
|
|
|
|
((org-region-active-p)
|
|
|
|
(setq beg (region-beginning) end (region-end)))
|
|
|
|
(t
|
|
|
|
(setq col (org-table-current-column))
|
|
|
|
(goto-char (org-table-begin))
|
|
|
|
(unless (re-search-forward "^[ \t]*|[^-]" nil t)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "No table data"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-goto-column col)
|
|
|
|
(setq beg (point))
|
|
|
|
(goto-char (org-table-end))
|
|
|
|
(unless (re-search-backward "^[ \t]*|[^-]" nil t)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "No table data"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-goto-column col)
|
|
|
|
(setq end (point))))
|
|
|
|
(let* ((items (apply 'append (org-table-copy-region beg end)))
|
|
|
|
(items1 (cond ((not nlast) items)
|
|
|
|
((>= nlast (length items)) items)
|
|
|
|
(t (setq items (reverse items))
|
|
|
|
(setcdr (nthcdr (1- nlast) items) nil)
|
|
|
|
(nreverse items))))
|
|
|
|
(numbers (delq nil (mapcar 'org-table-get-number-for-summing
|
|
|
|
items1)))
|
|
|
|
(res (apply '+ numbers))
|
|
|
|
(sres (if (= org-timecnt 0)
|
2008-09-24 11:33:10 -04:00
|
|
|
(number-to-string res)
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq diff (* 3600 res)
|
|
|
|
h (floor (/ diff 3600)) diff (mod diff 3600)
|
|
|
|
m (floor (/ diff 60)) diff (mod diff 60)
|
|
|
|
s diff)
|
2013-07-03 04:18:22 -04:00
|
|
|
(format "%.0f:%02.0f:%02.0f" h m s))))
|
2008-03-22 11:52:18 -04:00
|
|
|
(kill-new sres)
|
2011-06-29 18:25:09 -04:00
|
|
|
(if (org-called-interactively-p 'interactive)
|
2008-03-22 11:52:18 -04:00
|
|
|
(message "%s"
|
|
|
|
(substitute-command-keys
|
|
|
|
(format "Sum of %d items: %-20s (\\[yank] will insert result into buffer)"
|
|
|
|
(length numbers) sres))))
|
|
|
|
sres))))
|
|
|
|
|
|
|
|
(defun org-table-get-number-for-summing (s)
|
|
|
|
(let (n)
|
|
|
|
(if (string-match "^ *|? *" s)
|
|
|
|
(setq s (replace-match "" nil nil s)))
|
|
|
|
(if (string-match " *|? *$" s)
|
|
|
|
(setq s (replace-match "" nil nil s)))
|
|
|
|
(setq n (string-to-number s))
|
|
|
|
(cond
|
|
|
|
((and (string-match "0" s)
|
|
|
|
(string-match "\\`[-+ \t0.edED]+\\'" s)) 0)
|
2008-12-16 11:48:54 -05:00
|
|
|
((string-match "\\`[ \t]+\\'" s) nil)
|
2008-03-22 11:52:18 -04:00
|
|
|
((string-match "\\`\\([0-9]+\\):\\([0-9]+\\)\\(:\\([0-9]+\\)\\)?\\'" s)
|
|
|
|
(let ((h (string-to-number (or (match-string 1 s) "0")))
|
|
|
|
(m (string-to-number (or (match-string 2 s) "0")))
|
|
|
|
(s (string-to-number (or (match-string 4 s) "0"))))
|
|
|
|
(if (boundp 'org-timecnt) (setq org-timecnt (1+ org-timecnt)))
|
|
|
|
(* 1.0 (+ h (/ m 60.0) (/ s 3600.0)))))
|
2008-12-16 11:48:54 -05:00
|
|
|
((equal n 0) nil)
|
2008-03-22 11:52:18 -04:00
|
|
|
(t n))))
|
|
|
|
|
|
|
|
(defun org-table-current-field-formula (&optional key noerror)
|
|
|
|
"Return the formula active for the current field.
|
|
|
|
Assumes that specials are in place.
|
|
|
|
If KEY is given, return the key to this formula.
|
2010-07-17 14:53:36 -04:00
|
|
|
Otherwise return the formula preceded with \"=\" or \":=\"."
|
2008-03-22 11:52:18 -04:00
|
|
|
(let* ((name (car (rassoc (list (org-current-line)
|
|
|
|
(org-table-current-column))
|
|
|
|
org-table-named-field-locations)))
|
|
|
|
(col (org-table-current-column))
|
|
|
|
(scol (int-to-string col))
|
|
|
|
(ref (format "@%d$%d" (org-table-current-dline) col))
|
|
|
|
(stored-list (org-table-get-stored-formulas noerror))
|
|
|
|
(ass (or (assoc name stored-list)
|
|
|
|
(assoc ref stored-list)
|
|
|
|
(assoc scol stored-list))))
|
|
|
|
(if key
|
|
|
|
(car ass)
|
|
|
|
(if ass (concat (if (string-match "^[0-9]+$" (car ass)) "=" ":=")
|
|
|
|
(cdr ass))))))
|
|
|
|
|
|
|
|
(defun org-table-get-formula (&optional equation named)
|
|
|
|
"Read a formula from the minibuffer, offer stored formula as default.
|
|
|
|
When NAMED is non-nil, look for a named equation."
|
|
|
|
(let* ((stored-list (org-table-get-stored-formulas))
|
|
|
|
(name (car (rassoc (list (org-current-line)
|
|
|
|
(org-table-current-column))
|
|
|
|
org-table-named-field-locations)))
|
|
|
|
(ref (format "@%d$%d" (org-table-current-dline)
|
|
|
|
(org-table-current-column)))
|
|
|
|
(refass (assoc ref stored-list))
|
2008-12-22 17:10:32 -05:00
|
|
|
(nameass (assoc name stored-list))
|
2008-03-22 11:52:18 -04:00
|
|
|
(scol (if named
|
2008-12-19 12:28:58 -05:00
|
|
|
(if (and name (not (string-match "^LR[0-9]+$" name)))
|
|
|
|
name
|
|
|
|
ref)
|
2008-03-22 11:52:18 -04:00
|
|
|
(int-to-string (org-table-current-column))))
|
2008-12-22 17:10:32 -05:00
|
|
|
(dummy (and (or nameass refass) (not named)
|
|
|
|
(not (y-or-n-p "Replace existing field formula with column formula? " ))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(message "Formula not replaced")))
|
2008-03-22 11:52:18 -04:00
|
|
|
(name (or name ref))
|
|
|
|
(org-table-may-need-update nil)
|
|
|
|
(stored (cdr (assoc scol stored-list)))
|
|
|
|
(eq (cond
|
|
|
|
((and stored equation (string-match "^ *=? *$" equation))
|
|
|
|
stored)
|
|
|
|
((stringp equation)
|
|
|
|
equation)
|
|
|
|
(t (org-table-formula-from-user
|
|
|
|
(read-string
|
|
|
|
(org-table-formula-to-user
|
|
|
|
(format "%s formula %s%s="
|
|
|
|
(if named "Field" "Column")
|
|
|
|
(if (member (string-to-char scol) '(?$ ?@)) "" "$")
|
|
|
|
scol))
|
|
|
|
(if stored (org-table-formula-to-user stored) "")
|
|
|
|
'org-table-formula-history
|
|
|
|
)))))
|
|
|
|
mustsave)
|
|
|
|
(when (not (string-match "\\S-" eq))
|
|
|
|
;; remove formula
|
|
|
|
(setq stored-list (delq (assoc scol stored-list) stored-list))
|
|
|
|
(org-table-store-formulas stored-list)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Formula removed"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(if (string-match "^ *=?" eq) (setq eq (replace-match "" t t eq)))
|
|
|
|
(if (string-match " *$" eq) (setq eq (replace-match "" t t eq)))
|
|
|
|
(if (and name (not named))
|
|
|
|
;; We set the column equation, delete the named one.
|
|
|
|
(setq stored-list (delq (assoc name stored-list) stored-list)
|
|
|
|
mustsave t))
|
|
|
|
(if stored
|
|
|
|
(setcdr (assoc scol stored-list) eq)
|
|
|
|
(setq stored-list (cons (cons scol eq) stored-list)))
|
|
|
|
(if (or mustsave (not (equal stored eq)))
|
|
|
|
(org-table-store-formulas stored-list))
|
|
|
|
eq))
|
|
|
|
|
|
|
|
(defun org-table-store-formulas (alist)
|
|
|
|
"Store the list of formulas below the current table."
|
|
|
|
(setq alist (sort alist 'org-table-formula-less-p))
|
2012-04-28 17:34:51 -04:00
|
|
|
(let ((case-fold-search t))
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (org-table-end))
|
|
|
|
(if (looking-at "\\([ \t]*\n\\)*[ \t]*\\(#\\+tblfm:\\)\\(.*\n?\\)")
|
|
|
|
(progn
|
|
|
|
;; don't overwrite TBLFM, we might use text properties to store stuff
|
|
|
|
(goto-char (match-beginning 3))
|
|
|
|
(delete-region (match-beginning 3) (match-end 0)))
|
2012-07-11 13:11:26 -04:00
|
|
|
(org-indent-line)
|
2012-04-30 20:03:12 -04:00
|
|
|
(insert (or (match-string 2) "#+TBLFM:")))
|
2012-04-28 17:34:51 -04:00
|
|
|
(insert " "
|
|
|
|
(mapconcat (lambda (x)
|
|
|
|
(concat
|
|
|
|
(if (equal (string-to-char (car x)) ?@) "" "$")
|
|
|
|
(car x) "=" (cdr x)))
|
|
|
|
alist "::")
|
|
|
|
"\n"))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defsubst org-table-formula-make-cmp-string (a)
|
2011-03-08 08:49:53 -05:00
|
|
|
(when (string-match "\\`$[<>]" a)
|
|
|
|
(let ((arrow (string-to-char (substring a 1))))
|
|
|
|
;; Fake a high number to make sure this is sorted at the end.
|
|
|
|
(setq a (org-table-formula-handle-first/last-rc a))
|
|
|
|
(setq a (format "$%d" (+ 10000
|
|
|
|
(if (= arrow ?<) -1000 0)
|
|
|
|
(string-to-number (substring a 1)))))))
|
|
|
|
(when (string-match
|
|
|
|
"^\\(@\\([0-9]+\\)\\)?\\(\\$?\\([0-9]+\\)\\)?\\(\\$?[a-zA-Z0-9]+\\)?"
|
|
|
|
a)
|
2008-03-22 11:52:18 -04:00
|
|
|
(concat
|
2011-03-08 08:49:53 -05:00
|
|
|
(if (match-end 2)
|
|
|
|
(format "@%05d" (string-to-number (match-string 2 a))) "")
|
|
|
|
(if (match-end 4)
|
|
|
|
(format "$%05d" (string-to-number (match-string 4 a))) "")
|
|
|
|
(if (match-end 5)
|
|
|
|
(concat "@@" (match-string 5 a))))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defun org-table-formula-less-p (a b)
|
|
|
|
"Compare two formulas for sorting."
|
|
|
|
(let ((as (org-table-formula-make-cmp-string (car a)))
|
|
|
|
(bs (org-table-formula-make-cmp-string (car b))))
|
|
|
|
(and as bs (string< as bs))))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-get-stored-formulas (&optional noerror)
|
|
|
|
"Return an alist with the stored formulas directly after current table."
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
(interactive) ;; FIXME interactive?
|
2012-04-21 09:36:04 -04:00
|
|
|
(let ((case-fold-search t) scol eq eq-alist strings string seen)
|
2008-03-22 11:52:18 -04:00
|
|
|
(save-excursion
|
|
|
|
(goto-char (org-table-end))
|
2012-04-21 09:36:04 -04:00
|
|
|
(when (looking-at "\\([ \t]*\n\\)*[ \t]*#\\+tblfm: *\\(.*\\)")
|
2011-03-03 11:44:13 -05:00
|
|
|
(setq strings (org-split-string (org-match-string-no-properties 2)
|
|
|
|
" *:: *"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(while (setq string (pop strings))
|
2011-03-08 08:49:53 -05:00
|
|
|
(when (string-match "\\`\\(@[-+I<>0-9.$@]+\\|@?[0-9]+\\|\\$\\([a-zA-Z0-9]+\\|[<>]+\\)\\) *= *\\(.*[^ \t]\\)" string)
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq scol (if (match-end 2)
|
|
|
|
(match-string 2 string)
|
|
|
|
(match-string 1 string))
|
2011-03-08 08:49:53 -05:00
|
|
|
scol (if (member (string-to-char scol) '(?< ?>))
|
|
|
|
(concat "$" scol) scol)
|
2008-03-22 11:52:18 -04:00
|
|
|
eq (match-string 3 string)
|
|
|
|
eq-alist (cons (cons scol eq) eq-alist))
|
|
|
|
(if (member scol seen)
|
2008-12-16 11:48:54 -05:00
|
|
|
(if noerror
|
|
|
|
(progn
|
|
|
|
(message "Double definition `$%s=' in TBLFM line, please fix by hand" scol)
|
|
|
|
(ding)
|
|
|
|
(sit-for 2))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Double definition `$%s=' in TBLFM line, please fix by hand" scol))
|
2008-03-22 11:52:18 -04:00
|
|
|
(push scol seen))))))
|
|
|
|
(nreverse eq-alist)))
|
|
|
|
|
|
|
|
(defun org-table-fix-formulas (key replace &optional limit delta remove)
|
|
|
|
"Modify the equations after the table structure has been edited.
|
|
|
|
KEY is \"@\" or \"$\". REPLACE is an alist of numbers to replace.
|
|
|
|
For all numbers larger than LIMIT, shift them by DELTA."
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (org-table-end))
|
2014-01-09 14:10:19 -05:00
|
|
|
(while (let ((case-fold-search t)) (looking-at "[ \t]*#\\+tblfm:"))
|
|
|
|
(let ((msg "The formulas in #+TBLFM have been updated")
|
|
|
|
(re (concat key "\\([0-9]+\\)"))
|
|
|
|
(re2
|
|
|
|
(when remove
|
|
|
|
(if (or (equal key "$") (equal key "$LR"))
|
|
|
|
(format "\\(@[0-9]+\\)?%s%d=.*?\\(::\\|$\\)"
|
|
|
|
(regexp-quote key) remove)
|
|
|
|
(format "@%d\\$[0-9]+=.*?\\(::\\|$\\)" remove))))
|
|
|
|
s n a)
|
|
|
|
(when remove
|
|
|
|
(while (re-search-forward re2 (point-at-eol) t)
|
2009-04-15 09:06:07 -04:00
|
|
|
(unless (save-match-data (org-in-regexp "remote([^)]+?)"))
|
2014-01-09 14:10:19 -05:00
|
|
|
(if (equal (char-before (match-beginning 0)) ?.)
|
|
|
|
(user-error
|
|
|
|
"Change makes TBLFM term %s invalid, use undo to recover"
|
|
|
|
(match-string 0))
|
|
|
|
(replace-match "")))))
|
|
|
|
(while (re-search-forward re (point-at-eol) t)
|
|
|
|
(unless (save-match-data (org-in-regexp "remote([^)]+?)"))
|
|
|
|
(setq s (match-string 1) n (string-to-number s))
|
|
|
|
(cond
|
|
|
|
((setq a (assoc s replace))
|
|
|
|
(replace-match (concat key (cdr a)) t t)
|
|
|
|
(message msg))
|
|
|
|
((and limit (> n limit))
|
|
|
|
(replace-match (concat key (int-to-string (+ n delta))) t t)
|
|
|
|
(message msg))))))
|
|
|
|
(forward-line))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defun org-table-get-specials ()
|
|
|
|
"Get the column names and local parameters for this table."
|
|
|
|
(save-excursion
|
|
|
|
(let ((beg (org-table-begin)) (end (org-table-end))
|
|
|
|
names name fields fields1 field cnt
|
2008-12-19 12:28:58 -05:00
|
|
|
c v l line col types dlines hlines last-dline)
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq org-table-column-names nil
|
|
|
|
org-table-local-parameters nil
|
|
|
|
org-table-named-field-locations nil
|
|
|
|
org-table-current-begin-line nil
|
|
|
|
org-table-current-begin-pos nil
|
2011-03-01 03:05:56 -05:00
|
|
|
org-table-current-line-types nil
|
|
|
|
org-table-current-ncol 0)
|
2008-03-22 11:52:18 -04:00
|
|
|
(goto-char beg)
|
|
|
|
(when (re-search-forward "^[ \t]*| *! *\\(|.*\\)" end t)
|
|
|
|
(setq names (org-split-string (match-string 1) " *| *")
|
|
|
|
cnt 1)
|
|
|
|
(while (setq name (pop names))
|
|
|
|
(setq cnt (1+ cnt))
|
2011-08-23 10:27:56 -04:00
|
|
|
(if (string-match "^[a-zA-Z][_a-zA-Z0-9]*$" name)
|
2008-03-22 11:52:18 -04:00
|
|
|
(push (cons name (int-to-string cnt)) org-table-column-names))))
|
|
|
|
(setq org-table-column-names (nreverse org-table-column-names))
|
|
|
|
(setq org-table-column-name-regexp
|
|
|
|
(concat "\\$\\(" (mapconcat 'car org-table-column-names "\\|") "\\)\\>"))
|
|
|
|
(goto-char beg)
|
|
|
|
(while (re-search-forward "^[ \t]*| *\\$ *\\(|.*\\)" end t)
|
|
|
|
(setq fields (org-split-string (match-string 1) " *| *"))
|
|
|
|
(while (setq field (pop fields))
|
|
|
|
(if (string-match "^\\([a-zA-Z][_a-zA-Z0-9]*\\|%\\) *= *\\(.*\\)" field)
|
|
|
|
(push (cons (match-string 1 field) (match-string 2 field))
|
|
|
|
org-table-local-parameters))))
|
|
|
|
(goto-char beg)
|
|
|
|
(while (re-search-forward "^[ \t]*| *\\([_^]\\) *\\(|.*\\)" end t)
|
|
|
|
(setq c (match-string 1)
|
|
|
|
fields (org-split-string (match-string 2) " *| *"))
|
|
|
|
(save-excursion
|
|
|
|
(beginning-of-line (if (equal c "_") 2 0))
|
|
|
|
(setq line (org-current-line) col 1)
|
|
|
|
(and (looking-at "^[ \t]*|[^|]*\\(|.*\\)")
|
|
|
|
(setq fields1 (org-split-string (match-string 1) " *| *"))))
|
|
|
|
(while (and fields1 (setq field (pop fields)))
|
|
|
|
(setq v (pop fields1) col (1+ col))
|
|
|
|
(when (and (stringp field) (stringp v)
|
2011-08-23 10:27:56 -04:00
|
|
|
(string-match "^[a-zA-Z][_a-zA-Z0-9]*$" field))
|
2012-08-11 13:10:44 -04:00
|
|
|
(push (cons field v) org-table-local-parameters)
|
|
|
|
(push (list field line col) org-table-named-field-locations))))
|
2008-03-22 11:52:18 -04:00
|
|
|
;; Analyse the line types
|
|
|
|
(goto-char beg)
|
|
|
|
(setq org-table-current-begin-line (org-current-line)
|
|
|
|
org-table-current-begin-pos (point)
|
|
|
|
l org-table-current-begin-line)
|
|
|
|
(while (looking-at "[ \t]*|\\(-\\)?")
|
|
|
|
(push (if (match-end 1) 'hline 'dline) types)
|
|
|
|
(if (match-end 1) (push l hlines) (push l dlines))
|
|
|
|
(beginning-of-line 2)
|
|
|
|
(setq l (1+ l)))
|
2009-01-24 04:51:21 -05:00
|
|
|
(push 'hline types) ;; add an imaginary extra hline to the end
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq org-table-current-line-types (apply 'vector (nreverse types))
|
2008-12-19 12:28:58 -05:00
|
|
|
last-dline (car dlines)
|
2008-12-18 17:05:21 -05:00
|
|
|
org-table-dlines (apply 'vector (cons nil (nreverse dlines)))
|
2008-12-19 12:28:58 -05:00
|
|
|
org-table-hlines (apply 'vector (cons nil (nreverse hlines))))
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line last-dline)
|
2008-12-19 12:28:58 -05:00
|
|
|
(let* ((l last-dline)
|
|
|
|
(fields (org-split-string
|
|
|
|
(buffer-substring (point-at-bol) (point-at-eol))
|
2009-01-24 04:51:21 -05:00
|
|
|
"[ \t]*|[ \t]*"))
|
2008-12-19 12:28:58 -05:00
|
|
|
(nfields (length fields))
|
|
|
|
al al2)
|
2011-03-01 03:05:56 -05:00
|
|
|
(setq org-table-current-ncol nfields)
|
2008-12-19 12:28:58 -05:00
|
|
|
(loop for i from 1 to nfields do
|
|
|
|
(push (list (format "LR%d" i) l i) al)
|
|
|
|
(push (cons (format "LR%d" i) (nth (1- i) fields)) al2))
|
|
|
|
(setq org-table-named-field-locations
|
|
|
|
(append org-table-named-field-locations al))
|
|
|
|
(setq org-table-local-parameters
|
|
|
|
(append org-table-local-parameters al2))))))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-maybe-eval-formula ()
|
|
|
|
"Check if the current field starts with \"=\" or \":=\".
|
|
|
|
If yes, store the formula and apply it."
|
|
|
|
;; We already know we are in a table. Get field will only return a formula
|
|
|
|
;; when appropriate. It might return a separator line, but no problem.
|
|
|
|
(when org-table-formula-evaluate-inline
|
|
|
|
(let* ((field (org-trim (or (org-table-get-field) "")))
|
|
|
|
named eq)
|
2012-04-30 20:03:12 -04:00
|
|
|
(when (string-match "^:?=\\(.*[^=]\\)$" field)
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq named (equal (string-to-char field) ?:)
|
|
|
|
eq (match-string 1 field))
|
|
|
|
(if (or (fboundp 'calc-eval)
|
|
|
|
(equal (substring eq 0 (min 2 (length eq))) "'("))
|
|
|
|
(org-table-eval-formula (if named '(4) nil)
|
|
|
|
(org-table-formula-from-user eq))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Calc does not seem to be installed, and is needed to evaluate the formula"))))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defvar org-recalc-commands nil
|
|
|
|
"List of commands triggering the recalculation of a line.
|
|
|
|
Will be filled automatically during use.")
|
|
|
|
|
|
|
|
(defvar org-recalc-marks
|
|
|
|
'((" " . "Unmarked: no special line, no automatic recalculation")
|
|
|
|
("#" . "Automatically recalculate this line upon TAB, RET, and C-c C-c in the line")
|
|
|
|
("*" . "Recalculate only when entire table is recalculated with `C-u C-c *'")
|
2012-08-11 13:10:44 -04:00
|
|
|
("!" . "Column name definition line. Reference in formula as $name.")
|
|
|
|
("$" . "Parameter definition line name=value. Reference in formula as $name.")
|
2008-03-22 11:52:18 -04:00
|
|
|
("_" . "Names for values in row below this one.")
|
|
|
|
("^" . "Names for values in row above this one.")))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-rotate-recalc-marks (&optional newchar)
|
|
|
|
"Rotate the recalculation mark in the first column.
|
|
|
|
If in any row, the first field is not consistent with a mark,
|
|
|
|
insert a new column for the markers.
|
|
|
|
When there is an active region, change all the lines in the region,
|
|
|
|
after prompting for the marking character.
|
|
|
|
After each change, a message will be displayed indicating the meaning
|
|
|
|
of the new mark."
|
|
|
|
(interactive)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(unless (org-at-table-p) (user-error "Not at a table"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(let* ((marks (append (mapcar 'car org-recalc-marks) '(" ")))
|
|
|
|
(beg (org-table-begin))
|
|
|
|
(end (org-table-end))
|
|
|
|
(l (org-current-line))
|
|
|
|
(l1 (if (org-region-active-p) (org-current-line (region-beginning))))
|
|
|
|
(l2 (if (org-region-active-p) (org-current-line (region-end))))
|
|
|
|
(have-col
|
|
|
|
(save-excursion
|
|
|
|
(goto-char beg)
|
|
|
|
(not (re-search-forward "^[ \t]*|[^-|][^|]*[^#!$*_^| \t][^|]*|" end t))))
|
|
|
|
(col (org-table-current-column))
|
|
|
|
(forcenew (car (assoc newchar org-recalc-marks)))
|
|
|
|
epos new)
|
|
|
|
(when l1
|
|
|
|
(message "Change region to what mark? Type # * ! $ or SPC: ")
|
|
|
|
(setq newchar (char-to-string (read-char-exclusive))
|
|
|
|
forcenew (car (assoc newchar org-recalc-marks))))
|
|
|
|
(if (and newchar (not forcenew))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Invalid NEWCHAR `%s' in `org-table-rotate-recalc-marks'"
|
2008-03-22 11:52:18 -04:00
|
|
|
newchar))
|
2009-08-27 04:24:09 -04:00
|
|
|
(if l1 (org-goto-line l1))
|
2008-03-22 11:52:18 -04:00
|
|
|
(save-excursion
|
|
|
|
(beginning-of-line 1)
|
|
|
|
(unless (looking-at org-table-dataline-regexp)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Not at a table data line")))
|
2008-03-22 11:52:18 -04:00
|
|
|
(unless have-col
|
|
|
|
(org-table-goto-column 1)
|
|
|
|
(org-table-insert-column)
|
|
|
|
(org-table-goto-column (1+ col)))
|
|
|
|
(setq epos (point-at-eol))
|
|
|
|
(save-excursion
|
|
|
|
(beginning-of-line 1)
|
|
|
|
(org-table-get-field
|
|
|
|
1 (if (looking-at "^[ \t]*| *\\([#!$*^_ ]\\) *|")
|
|
|
|
(concat " "
|
|
|
|
(setq new (or forcenew
|
|
|
|
(cadr (member (match-string 1) marks))))
|
|
|
|
" ")
|
|
|
|
" # ")))
|
|
|
|
(if (and l1 l2)
|
|
|
|
(progn
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line l1)
|
2008-03-22 11:52:18 -04:00
|
|
|
(while (progn (beginning-of-line 2) (not (= (org-current-line) l2)))
|
|
|
|
(and (looking-at org-table-dataline-regexp)
|
|
|
|
(org-table-get-field 1 (concat " " new " "))))
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line l1)))
|
2008-03-22 11:52:18 -04:00
|
|
|
(if (not (= epos (point-at-eol))) (org-table-align))
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line l)
|
2011-06-29 18:25:09 -04:00
|
|
|
(and (org-called-interactively-p 'interactive)
|
|
|
|
(message "%s" (cdr (assoc new org-recalc-marks))))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-maybe-recalculate-line ()
|
|
|
|
"Recompute the current line if marked for it, and if we haven't just done it."
|
|
|
|
(interactive)
|
|
|
|
(and org-table-allow-automatic-line-recalculation
|
|
|
|
(not (and (memq last-command org-recalc-commands)
|
|
|
|
(equal org-last-recalc-line (org-current-line))))
|
|
|
|
(save-excursion (beginning-of-line 1)
|
|
|
|
(looking-at org-table-auto-recalculate-regexp))
|
|
|
|
(org-table-recalculate) t))
|
|
|
|
|
2012-04-30 19:41:50 -04:00
|
|
|
(defvar org-tbl-calc-modes) ;; Dynamically bound in `org-table-eval-formula'
|
2008-03-22 11:52:18 -04:00
|
|
|
(defsubst org-set-calc-mode (var &optional value)
|
|
|
|
(if (stringp var)
|
|
|
|
(setq var (assoc var '(("D" calc-angle-mode deg)
|
|
|
|
("R" calc-angle-mode rad)
|
|
|
|
("F" calc-prefer-frac t)
|
|
|
|
("S" calc-symbolic-mode t)))
|
|
|
|
value (nth 2 var) var (nth 1 var)))
|
2012-04-30 19:41:50 -04:00
|
|
|
(if (memq var org-tbl-calc-modes)
|
|
|
|
(setcar (cdr (memq var org-tbl-calc-modes)) value)
|
|
|
|
(cons var (cons value org-tbl-calc-modes)))
|
|
|
|
org-tbl-calc-modes)
|
2008-03-22 11:52:18 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-eval-formula (&optional arg equation
|
|
|
|
suppress-align suppress-const
|
|
|
|
suppress-store suppress-analysis)
|
|
|
|
"Replace the table field value at the cursor by the result of a calculation.
|
|
|
|
|
|
|
|
This function makes use of Dave Gillespie's Calc package, in my view the
|
|
|
|
most exciting program ever written for GNU Emacs. So you need to have Calc
|
|
|
|
installed in order to use this function.
|
|
|
|
|
|
|
|
In a table, this command replaces the value in the current field with the
|
|
|
|
result of a formula. It also installs the formula as the \"current\" column
|
|
|
|
formula, by storing it in a special line below the table. When called
|
2009-11-12 07:39:29 -05:00
|
|
|
with a `C-u' prefix, the current field must be a named field, and the
|
2008-03-22 11:52:18 -04:00
|
|
|
formula is installed as valid in only this specific field.
|
|
|
|
|
|
|
|
When called with two `C-u' prefixes, insert the active equation
|
|
|
|
for the field back into the current field, so that it can be
|
|
|
|
edited there. This is useful in order to use \\[org-table-show-reference]
|
|
|
|
to check the referenced fields.
|
|
|
|
|
|
|
|
When called, the command first prompts for a formula, which is read in
|
|
|
|
the minibuffer. Previously entered formulas are available through the
|
|
|
|
history list, and the last used formula is offered as a default.
|
|
|
|
These stored formulas are adapted correctly when moving, inserting, or
|
|
|
|
deleting columns with the corresponding commands.
|
|
|
|
|
|
|
|
The formula can be any algebraic expression understood by the Calc package.
|
|
|
|
For details, see the Org-mode manual.
|
|
|
|
|
|
|
|
This function can also be called from Lisp programs and offers
|
|
|
|
additional arguments: EQUATION can be the formula to apply. If this
|
|
|
|
argument is given, the user will not be prompted. SUPPRESS-ALIGN is
|
|
|
|
used to speed-up recursive calls by by-passing unnecessary aligns.
|
|
|
|
SUPPRESS-CONST suppresses the interpretation of constants in the
|
|
|
|
formula, assuming that this has been done already outside the function.
|
|
|
|
SUPPRESS-STORE means the formula should not be stored, either because
|
|
|
|
it is already stored, or because it is a modified equation that should
|
|
|
|
not overwrite the stored one."
|
|
|
|
(interactive "P")
|
|
|
|
(org-table-check-inside-data-field)
|
|
|
|
(or suppress-analysis (org-table-get-specials))
|
|
|
|
(if (equal arg '(16))
|
|
|
|
(let ((eq (org-table-current-field-formula)))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(or eq (user-error "No equation active for current field"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-get-field nil eq)
|
|
|
|
(org-table-align)
|
|
|
|
(setq org-table-may-need-update t))
|
|
|
|
(let* (fields
|
|
|
|
(ndown (if (integerp arg) arg 1))
|
|
|
|
(org-table-automatic-realign nil)
|
|
|
|
(case-fold-search nil)
|
|
|
|
(down (> ndown 1))
|
|
|
|
(formula (if (and equation suppress-store)
|
|
|
|
equation
|
|
|
|
(org-table-get-formula equation (equal arg '(4)))))
|
|
|
|
(n0 (org-table-current-column))
|
2012-04-30 19:41:50 -04:00
|
|
|
(org-tbl-calc-modes (copy-sequence org-calc-default-modes))
|
2008-03-22 11:52:18 -04:00
|
|
|
(numbers nil) ; was a variable, now fixed default
|
|
|
|
(keep-empty nil)
|
2012-03-19 16:38:12 -04:00
|
|
|
n form form0 formrpl formrg bw fmt x ev orig c lispp literal
|
2011-08-14 14:24:43 -04:00
|
|
|
duration duration-output-format)
|
2008-03-22 11:52:18 -04:00
|
|
|
;; Parse the format string. Since we have a lot of modes, this is
|
|
|
|
;; a lot of work. However, I think calc still uses most of the time.
|
|
|
|
(if (string-match ";" formula)
|
|
|
|
(let ((tmp (org-split-string formula ";")))
|
|
|
|
(setq formula (car tmp)
|
|
|
|
fmt (concat (cdr (assoc "%" org-table-local-parameters))
|
|
|
|
(nth 1 tmp)))
|
|
|
|
(while (string-match "\\([pnfse]\\)\\(-?[0-9]+\\)" fmt)
|
|
|
|
(setq c (string-to-char (match-string 1 fmt))
|
|
|
|
n (string-to-number (match-string 2 fmt)))
|
|
|
|
(if (= c ?p)
|
2012-04-30 19:41:50 -04:00
|
|
|
(setq org-tbl-calc-modes (org-set-calc-mode 'calc-internal-prec n))
|
|
|
|
(setq org-tbl-calc-modes
|
|
|
|
(org-set-calc-mode
|
|
|
|
'calc-float-format
|
|
|
|
(list (cdr (assoc c '((?n . float) (?f . fix)
|
|
|
|
(?s . sci) (?e . eng))))
|
|
|
|
n))))
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq fmt (replace-match "" t t fmt)))
|
2011-07-02 07:08:54 -04:00
|
|
|
(if (string-match "T" fmt)
|
|
|
|
(setq duration t numbers t
|
2011-07-27 07:14:37 -04:00
|
|
|
duration-output-format nil
|
|
|
|
fmt (replace-match "" t t fmt)))
|
|
|
|
(if (string-match "t" fmt)
|
2012-03-19 16:38:12 -04:00
|
|
|
(setq duration t
|
2011-07-27 07:14:37 -04:00
|
|
|
duration-output-format org-table-duration-custom-format
|
|
|
|
numbers t
|
2011-07-02 07:08:54 -04:00
|
|
|
fmt (replace-match "" t t fmt)))
|
|
|
|
(if (string-match "N" fmt)
|
|
|
|
(setq numbers t
|
2008-03-22 11:52:18 -04:00
|
|
|
fmt (replace-match "" t t fmt)))
|
|
|
|
(if (string-match "L" fmt)
|
|
|
|
(setq literal t
|
|
|
|
fmt (replace-match "" t t fmt)))
|
|
|
|
(if (string-match "E" fmt)
|
|
|
|
(setq keep-empty t
|
|
|
|
fmt (replace-match "" t t fmt)))
|
|
|
|
(while (string-match "[DRFS]" fmt)
|
2012-04-30 19:41:50 -04:00
|
|
|
(setq org-tbl-calc-modes (org-set-calc-mode (match-string 0 fmt)))
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq fmt (replace-match "" t t fmt)))
|
|
|
|
(unless (string-match "\\S-" fmt)
|
|
|
|
(setq fmt nil))))
|
|
|
|
(if (and (not suppress-const) org-table-formula-use-constants)
|
|
|
|
(setq formula (org-table-formula-substitute-names formula)))
|
|
|
|
(setq orig (or (get-text-property 1 :orig-formula formula) "?"))
|
|
|
|
(while (> ndown 0)
|
2011-07-24 14:31:38 -04:00
|
|
|
(setq fields (org-split-string
|
2012-08-15 03:22:51 -04:00
|
|
|
(buffer-substring-no-properties (point-at-bol) (point-at-eol))
|
2011-07-24 14:31:38 -04:00
|
|
|
" *| *"))
|
|
|
|
;; replace fields with duration values if relevant
|
|
|
|
(if duration
|
|
|
|
(setq fields
|
|
|
|
(mapcar (lambda (x) (org-table-time-string-to-seconds x))
|
|
|
|
fields)))
|
2008-03-22 11:52:18 -04:00
|
|
|
(if (eq numbers t)
|
|
|
|
(setq fields (mapcar
|
2012-12-28 09:02:01 -05:00
|
|
|
(lambda (x)
|
|
|
|
(if (string-match "\\S-" x)
|
|
|
|
(number-to-string (string-to-number x))
|
|
|
|
x))
|
2008-03-22 11:52:18 -04:00
|
|
|
fields)))
|
|
|
|
(setq ndown (1- ndown))
|
|
|
|
(setq form (copy-sequence formula)
|
2011-07-24 14:31:38 -04:00
|
|
|
lispp (and (> (length form) 2) (equal (substring form 0 2) "'(")))
|
2008-03-22 11:52:18 -04:00
|
|
|
(if (and lispp literal) (setq lispp 'literal))
|
2010-03-14 08:11:17 -04:00
|
|
|
|
|
|
|
;; Insert row and column number of formula result field
|
|
|
|
(while (string-match "[@$]#" form)
|
|
|
|
(setq form
|
|
|
|
(replace-match
|
|
|
|
(format "%d"
|
|
|
|
(save-match-data
|
|
|
|
(if (equal (substring form (match-beginning 0)
|
|
|
|
(1+ (match-beginning 0)))
|
|
|
|
"@")
|
|
|
|
(org-table-current-dline)
|
|
|
|
(org-table-current-column))))
|
|
|
|
t t form)))
|
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
;; Check for old vertical references
|
2008-12-05 07:19:36 -05:00
|
|
|
(setq form (org-table-rewrite-old-row-references form))
|
2009-01-24 04:51:21 -05:00
|
|
|
;; Insert remote references
|
2014-01-12 04:53:06 -05:00
|
|
|
(setq form (org-table-remote-reference-indirection form))
|
2009-01-24 04:51:21 -05:00
|
|
|
(while (string-match "\\<remote([ \t]*\\([-_a-zA-Z0-9]+\\)[ \t]*,[ \t]*\\([^\n)]+\\))" form)
|
|
|
|
(setq form
|
|
|
|
(replace-match
|
|
|
|
(save-match-data
|
|
|
|
(org-table-make-reference
|
2012-04-10 18:43:05 -04:00
|
|
|
(let ((rmtrng (org-table-get-remote-range
|
|
|
|
(match-string 1 form) (match-string 2 form))))
|
|
|
|
(if duration
|
|
|
|
(if (listp rmtrng)
|
|
|
|
(mapcar (lambda(x) (org-table-time-string-to-seconds x)) rmtrng)
|
|
|
|
(org-table-time-string-to-seconds rmtrng))
|
|
|
|
rmtrng))
|
2009-01-24 04:51:21 -05:00
|
|
|
keep-empty numbers lispp))
|
|
|
|
t t form)))
|
2008-03-22 11:52:18 -04:00
|
|
|
;; Insert complex ranges
|
2008-10-15 07:11:48 -04:00
|
|
|
(while (and (string-match org-table-range-regexp form)
|
|
|
|
(> (length (match-string 0 form)) 1))
|
2012-03-19 16:38:12 -04:00
|
|
|
(setq formrg (save-match-data
|
2011-07-24 18:55:04 -04:00
|
|
|
(org-table-get-range (match-string 0 form) nil n0)))
|
2011-07-23 11:23:19 -04:00
|
|
|
(setq formrpl
|
|
|
|
(save-match-data
|
|
|
|
(org-table-make-reference
|
2011-07-24 14:31:38 -04:00
|
|
|
;; possibly handle durations
|
|
|
|
(if duration
|
2011-07-24 18:55:04 -04:00
|
|
|
(if (listp formrg)
|
|
|
|
(mapcar (lambda(x) (org-table-time-string-to-seconds x)) formrg)
|
|
|
|
(org-table-time-string-to-seconds formrg))
|
|
|
|
formrg)
|
2011-07-23 11:23:19 -04:00
|
|
|
keep-empty numbers lispp)))
|
|
|
|
(if (not (save-match-data
|
|
|
|
(string-match (regexp-quote form) formrpl)))
|
|
|
|
(setq form (replace-match formrpl t t form))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Spreadsheet error: invalid reference \"%s\"" form)))
|
2008-03-22 11:52:18 -04:00
|
|
|
;; Insert simple ranges
|
|
|
|
(while (string-match "\\$\\([0-9]+\\)\\.\\.\\$\\([0-9]+\\)" form)
|
|
|
|
(setq form
|
|
|
|
(replace-match
|
|
|
|
(save-match-data
|
|
|
|
(org-table-make-reference
|
|
|
|
(org-sublist
|
|
|
|
fields (string-to-number (match-string 1 form))
|
|
|
|
(string-to-number (match-string 2 form)))
|
|
|
|
keep-empty numbers lispp))
|
|
|
|
t t form)))
|
|
|
|
(setq form0 form)
|
|
|
|
;; Insert the references to fields in same row
|
2011-03-03 16:06:08 -05:00
|
|
|
(while (string-match "\\$\\(\\([-+]\\)?[0-9]+\\)" form)
|
2011-03-03 11:46:24 -05:00
|
|
|
(setq n (+ (string-to-number (match-string 1 form))
|
2011-03-03 16:06:08 -05:00
|
|
|
(if (match-end 2) n0 0))
|
2014-07-27 09:05:48 -04:00
|
|
|
x (nth (1- (if (= n 0) n0 (max n 1))) fields)
|
|
|
|
formrpl (save-match-data
|
|
|
|
(org-table-make-reference
|
|
|
|
x keep-empty numbers lispp)))
|
|
|
|
(when (or (not x)
|
|
|
|
(save-match-data
|
|
|
|
(string-match (regexp-quote formula) formrpl)))
|
|
|
|
(user-error "Invalid field specifier \"%s\""
|
|
|
|
(match-string 0 form)))
|
2014-07-29 11:36:39 -04:00
|
|
|
(setq form (replace-match formrpl t t form)))
|
2014-08-20 08:32:47 -04:00
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
(if lispp
|
|
|
|
(setq ev (condition-case nil
|
|
|
|
(eval (eval (read form)))
|
2013-03-03 14:29:58 -05:00
|
|
|
(error "#ERROR"))
|
2011-07-02 07:08:54 -04:00
|
|
|
ev (if (numberp ev) (number-to-string ev) ev)
|
2011-07-23 11:23:19 -04:00
|
|
|
ev (if duration (org-table-time-seconds-to-string
|
2011-07-27 07:14:37 -04:00
|
|
|
(string-to-number ev)
|
|
|
|
duration-output-format) ev))
|
2008-03-22 11:52:18 -04:00
|
|
|
(or (fboundp 'calc-eval)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Calc does not seem to be installed, and is needed to evaluate the formula"))
|
2012-12-19 19:36:05 -05:00
|
|
|
;; Use <...> time-stamps so that Calc can handle them
|
2014-05-20 16:03:30 -04:00
|
|
|
(while (string-match (concat "\\[" org-ts-regexp1 "\\]") form)
|
|
|
|
(setq form (replace-match "<\\1>" nil nil form)))
|
2012-12-19 19:36:05 -05:00
|
|
|
;; I18n-ize local time-stamps by setting (system-time-locale "C")
|
|
|
|
(when (string-match org-ts-regexp2 form)
|
|
|
|
(let* ((ts (match-string 0 form))
|
|
|
|
(tsp (apply 'encode-time (save-match-data (org-parse-time-string ts))))
|
|
|
|
(system-time-locale "C")
|
|
|
|
(tf (or (and (save-match-data (string-match "[0-9]\\{1,2\\}:[0-9]\\{2\\}" ts))
|
|
|
|
(cdr org-time-stamp-formats))
|
|
|
|
(car org-time-stamp-formats))))
|
|
|
|
(setq form (replace-match (format-time-string tf tsp) t t form))))
|
|
|
|
|
2012-05-05 10:14:33 -04:00
|
|
|
(setq ev (if (and duration (string-match "^[0-9]+:[0-9]+\\(?::[0-9]+\\)?$" form))
|
|
|
|
form
|
2012-12-28 09:03:10 -05:00
|
|
|
(calc-eval (cons form org-tbl-calc-modes)
|
|
|
|
(when (and (not keep-empty) numbers) 'num)))
|
2011-07-23 11:23:19 -04:00
|
|
|
ev (if duration (org-table-time-seconds-to-string
|
2012-05-05 10:14:33 -04:00
|
|
|
(if (string-match "^[0-9]+:[0-9]+\\(?::[0-9]+\\)?$" ev)
|
|
|
|
(string-to-number (org-table-time-string-to-seconds ev))
|
|
|
|
(string-to-number ev))
|
|
|
|
duration-output-format)
|
|
|
|
ev)))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(when org-table-formula-debug
|
|
|
|
(with-output-to-temp-buffer "*Substitution History*"
|
|
|
|
(princ (format "Substitution history of formula
|
|
|
|
Orig: %s
|
|
|
|
$xyz-> %s
|
|
|
|
@r$c-> %s
|
|
|
|
$1-> %s\n" orig formula form0 form))
|
2014-09-14 04:44:28 -04:00
|
|
|
(if (consp ev)
|
2013-09-07 04:55:14 -04:00
|
|
|
(princ (format " %s^\nError: %s"
|
2008-03-22 11:52:18 -04:00
|
|
|
(make-string (car ev) ?\-) (nth 1 ev)))
|
|
|
|
(princ (format "Result: %s\nFormat: %s\nFinal: %s"
|
|
|
|
ev (or fmt "NONE")
|
|
|
|
(if fmt (format fmt (string-to-number ev)) ev)))))
|
|
|
|
(setq bw (get-buffer-window "*Substitution History*"))
|
2008-11-03 07:38:25 -05:00
|
|
|
(org-fit-window-to-buffer bw)
|
2011-06-29 18:25:09 -04:00
|
|
|
(unless (and (org-called-interactively-p 'any) (not ndown))
|
2008-03-22 11:52:18 -04:00
|
|
|
(unless (let (inhibit-redisplay)
|
2010-07-17 14:53:36 -04:00
|
|
|
(y-or-n-p "Debugging Formula. Continue to next? "))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-align)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Abort"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(delete-window bw)
|
|
|
|
(message "")))
|
2014-09-14 04:44:28 -04:00
|
|
|
(when (consp ev) (setq fmt nil ev "#ERROR"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-justify-field-maybe
|
2011-12-11 08:05:13 -05:00
|
|
|
(format org-table-formula-field-format
|
|
|
|
(if fmt (format fmt (string-to-number ev)) ev)))
|
2008-03-22 11:52:18 -04:00
|
|
|
(if (and down (> ndown 0) (looking-at ".*\n[ \t]*|[^-]"))
|
|
|
|
(call-interactively 'org-return)
|
|
|
|
(setq ndown 0)))
|
|
|
|
(and down (org-table-maybe-recalculate-line))
|
|
|
|
(or suppress-align (and org-table-may-need-update
|
|
|
|
(org-table-align))))))
|
|
|
|
|
|
|
|
(defun org-table-put-field-property (prop value)
|
|
|
|
(save-excursion
|
|
|
|
(put-text-property (progn (skip-chars-backward "^|") (point))
|
|
|
|
(progn (skip-chars-forward "^|") (point))
|
|
|
|
prop value)))
|
|
|
|
|
2011-03-01 03:05:56 -05:00
|
|
|
(defun org-table-get-range (desc &optional tbeg col highlight corners-only)
|
2008-12-16 11:49:26 -05:00
|
|
|
"Get a calc vector from a column, according to descriptor DESC.
|
2008-03-22 11:52:18 -04:00
|
|
|
Optional arguments TBEG and COL can give the beginning of the table and
|
|
|
|
the current column, to avoid unnecessary parsing.
|
2011-03-01 03:05:56 -05:00
|
|
|
|
|
|
|
HIGHLIGHT means just highlight the range.
|
|
|
|
|
|
|
|
When CORNERS-ONLY is set, only return the corners of the range as
|
|
|
|
a list (line1 column1 line2 column2) where line1 and line2 are line numbers
|
|
|
|
in the buffer and column1 and column2 are table column numbers."
|
2008-03-22 11:52:18 -04:00
|
|
|
(if (not (equal (string-to-char desc) ?@))
|
|
|
|
(setq desc (concat "@" desc)))
|
|
|
|
(save-excursion
|
|
|
|
(or tbeg (setq tbeg (org-table-begin)))
|
|
|
|
(or col (setq col (org-table-current-column)))
|
|
|
|
(let ((thisline (org-current-line))
|
|
|
|
beg end c1 c2 r1 r2 rangep tmp)
|
|
|
|
(unless (string-match org-table-range-regexp desc)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Invalid table range specifier `%s'" desc))
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq rangep (match-end 3)
|
|
|
|
r1 (and (match-end 1) (match-string 1 desc))
|
|
|
|
r2 (and (match-end 4) (match-string 4 desc))
|
|
|
|
c1 (and (match-end 2) (substring (match-string 2 desc) 1))
|
|
|
|
c2 (and (match-end 5) (substring (match-string 5 desc) 1)))
|
|
|
|
|
|
|
|
(and c1 (setq c1 (+ (string-to-number c1)
|
|
|
|
(if (memq (string-to-char c1) '(?- ?+)) col 0))))
|
|
|
|
(and c2 (setq c2 (+ (string-to-number c2)
|
|
|
|
(if (memq (string-to-char c2) '(?- ?+)) col 0))))
|
|
|
|
(if (equal r1 "") (setq r1 nil))
|
|
|
|
(if (equal r2 "") (setq r2 nil))
|
|
|
|
(if r1 (setq r1 (org-table-get-descriptor-line r1)))
|
|
|
|
(if r2 (setq r2 (org-table-get-descriptor-line r2)))
|
2012-08-11 13:10:44 -04:00
|
|
|
; (setq r2 (or r2 r1) c2 (or c2 c1))
|
2008-03-22 11:52:18 -04:00
|
|
|
(if (not r1) (setq r1 thisline))
|
|
|
|
(if (not r2) (setq r2 thisline))
|
2012-04-09 14:03:58 -04:00
|
|
|
(if (or (not c1) (= 0 c1)) (setq c1 col))
|
|
|
|
(if (or (not c2) (= 0 c2)) (setq c2 col))
|
2011-03-01 03:05:56 -05:00
|
|
|
(if (and (not corners-only)
|
|
|
|
(or (not rangep) (and (= r1 r2) (= c1 c2))))
|
2008-03-22 11:52:18 -04:00
|
|
|
;; just one field
|
|
|
|
(progn
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line r1)
|
2008-03-22 11:52:18 -04:00
|
|
|
(while (not (looking-at org-table-dataline-regexp))
|
|
|
|
(beginning-of-line 2))
|
|
|
|
(prog1 (org-trim (org-table-get-field c1))
|
|
|
|
(if highlight (org-table-highlight-rectangle (point) (point)))))
|
|
|
|
;; A range, return a vector
|
2012-01-10 05:56:15 -05:00
|
|
|
;; First sort the numbers to get a regular rectangle
|
2008-03-22 11:52:18 -04:00
|
|
|
(if (< r2 r1) (setq tmp r1 r1 r2 r2 tmp))
|
|
|
|
(if (< c2 c1) (setq tmp c1 c1 c2 c2 tmp))
|
2011-03-01 03:05:56 -05:00
|
|
|
(if corners-only
|
|
|
|
;; Only return the corners of the range
|
|
|
|
(list r1 c1 r2 c2)
|
|
|
|
;; Copy the range values into a list
|
|
|
|
(org-goto-line r1)
|
|
|
|
(while (not (looking-at org-table-dataline-regexp))
|
|
|
|
(beginning-of-line 2))
|
|
|
|
(org-table-goto-column c1)
|
|
|
|
(setq beg (point))
|
|
|
|
(org-goto-line r2)
|
|
|
|
(while (not (looking-at org-table-dataline-regexp))
|
|
|
|
(beginning-of-line 0))
|
|
|
|
(org-table-goto-column c2)
|
|
|
|
(setq end (point))
|
|
|
|
(if highlight
|
|
|
|
(org-table-highlight-rectangle
|
|
|
|
beg (progn (skip-chars-forward "^|\n") (point))))
|
|
|
|
;; return string representation of calc vector
|
|
|
|
(mapcar 'org-trim
|
|
|
|
(apply 'append (org-table-copy-region beg end))))))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defun org-table-get-descriptor-line (desc &optional cline bline table)
|
|
|
|
"Analyze descriptor DESC and retrieve the corresponding line number.
|
|
|
|
The cursor is currently in line CLINE, the table begins in line BLINE,
|
|
|
|
and TABLE is a vector with line types."
|
|
|
|
(if (string-match "^[0-9]+$" desc)
|
|
|
|
(aref org-table-dlines (string-to-number desc))
|
|
|
|
(setq cline (or cline (org-current-line))
|
|
|
|
bline (or bline org-table-current-begin-line)
|
|
|
|
table (or table org-table-current-line-types))
|
|
|
|
(if (or
|
|
|
|
(not (string-match "^\\(\\([-+]\\)?\\(I+\\)\\)?\\(\\([-+]\\)?\\([0-9]+\\)\\)?" desc))
|
|
|
|
;; 1 2 3 4 5 6
|
|
|
|
(and (not (match-end 3)) (not (match-end 6)))
|
|
|
|
(and (match-end 3) (match-end 6) (not (match-end 5))))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Invalid row descriptor `%s'" desc))
|
2008-03-22 11:52:18 -04:00
|
|
|
(let* ((hdir (and (match-end 2) (match-string 2 desc)))
|
|
|
|
(hn (if (match-end 3) (- (match-end 3) (match-beginning 3)) nil))
|
|
|
|
(odir (and (match-end 5) (match-string 5 desc)))
|
|
|
|
(on (if (match-end 6) (string-to-number (match-string 6 desc))))
|
|
|
|
(i (- cline bline))
|
|
|
|
(rel (and (match-end 6)
|
|
|
|
(or (and (match-end 1) (not (match-end 3)))
|
|
|
|
(match-end 5)))))
|
|
|
|
(if (and hn (not hdir))
|
|
|
|
(progn
|
|
|
|
(setq i 0 hdir "+")
|
|
|
|
(if (eq (aref table 0) 'hline) (setq hn (1- hn)))))
|
|
|
|
(if (and (not hn) on (not odir))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Should never happen");;(aref org-table-dlines on)
|
2008-03-22 11:52:18 -04:00
|
|
|
(if (and hn (> hn 0))
|
2008-12-05 07:19:36 -05:00
|
|
|
(setq i (org-table-find-row-type table i 'hline (equal hdir "-")
|
|
|
|
nil hn cline desc)))
|
2008-03-22 11:52:18 -04:00
|
|
|
(if on
|
2008-12-05 07:19:36 -05:00
|
|
|
(setq i (org-table-find-row-type table i 'dline (equal odir "-")
|
|
|
|
rel on cline desc)))
|
2008-03-22 11:52:18 -04:00
|
|
|
(+ bline i)))))
|
|
|
|
|
2008-12-05 07:19:36 -05:00
|
|
|
(defun org-table-find-row-type (table i type backwards relative n cline desc)
|
2008-12-05 07:07:17 -05:00
|
|
|
"FIXME: Needs more documentation."
|
2008-03-22 11:52:18 -04:00
|
|
|
(let ((l (length table)))
|
|
|
|
(while (> n 0)
|
|
|
|
(while (and (setq i (+ i (if backwards -1 1)))
|
|
|
|
(>= i 0) (< i l)
|
|
|
|
(not (eq (aref table i) type))
|
|
|
|
(if (and relative (eq (aref table i) 'hline))
|
2009-08-01 01:56:26 -04:00
|
|
|
(cond
|
|
|
|
((eq org-table-relative-ref-may-cross-hline t) t)
|
|
|
|
((eq org-table-relative-ref-may-cross-hline 'error)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Row descriptor %s used in line %d crosses hline" desc cline))
|
2009-08-01 01:56:26 -04:00
|
|
|
(t (setq i (- i (if backwards -1 1))
|
|
|
|
n 1)
|
|
|
|
nil))
|
2008-03-22 11:52:18 -04:00
|
|
|
t)))
|
|
|
|
(setq n (1- n)))
|
|
|
|
(if (or (< i 0) (>= i l))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Row descriptor %s used in line %d leads outside table"
|
2008-12-05 07:07:17 -05:00
|
|
|
desc cline)
|
2008-03-22 11:52:18 -04:00
|
|
|
i)))
|
|
|
|
|
2008-12-05 07:19:36 -05:00
|
|
|
(defun org-table-rewrite-old-row-references (s)
|
2008-03-22 11:52:18 -04:00
|
|
|
(if (string-match "&[-+0-9I]" s)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Formula contains old &row reference, please rewrite using @-syntax")
|
2008-03-22 11:52:18 -04:00
|
|
|
s))
|
|
|
|
|
|
|
|
(defun org-table-make-reference (elements keep-empty numbers lispp)
|
|
|
|
"Convert list ELEMENTS to something appropriate to insert into formula.
|
|
|
|
KEEP-EMPTY indicated to keep empty fields, default is to skip them.
|
|
|
|
NUMBERS indicates that everything should be converted to numbers.
|
2012-12-28 09:03:10 -05:00
|
|
|
LISPP non-nil means to return something appropriate for a Lisp
|
|
|
|
list, 'literal is for the format specifier L."
|
|
|
|
;; Calc nan (not a number) is used for the conversion of the empty
|
|
|
|
;; field to a reference for several reasons: (i) It is accepted in a
|
|
|
|
;; Calc formula (e. g. "" or "()" would result in a Calc error).
|
|
|
|
;; (ii) In a single field (not in range) it can be distinguished
|
|
|
|
;; from "(nan)" which is the reference made from a single field
|
|
|
|
;; containing "nan".
|
|
|
|
(if (stringp elements)
|
|
|
|
;; field reference
|
2008-03-22 11:52:18 -04:00
|
|
|
(if lispp
|
|
|
|
(if (eq lispp 'literal)
|
|
|
|
elements
|
2013-04-09 08:35:21 -04:00
|
|
|
(if (and (eq elements "") (not keep-empty))
|
|
|
|
""
|
|
|
|
(prin1-to-string
|
|
|
|
(if numbers (string-to-number elements) elements))))
|
2012-12-28 09:03:10 -05:00
|
|
|
(if (string-match "\\S-" elements)
|
|
|
|
(progn
|
|
|
|
(when numbers (setq elements (number-to-string
|
|
|
|
(string-to-number elements))))
|
|
|
|
(concat "(" elements ")"))
|
|
|
|
(if (or (not keep-empty) numbers) "(0)" "nan")))
|
|
|
|
;; range reference
|
2008-03-22 11:52:18 -04:00
|
|
|
(unless keep-empty
|
|
|
|
(setq elements
|
|
|
|
(delq nil
|
|
|
|
(mapcar (lambda (x) (if (string-match "\\S-" x) x nil))
|
|
|
|
elements))))
|
2013-04-09 08:35:21 -04:00
|
|
|
(setq elements (or elements '())) ; if delq returns nil then we need '()
|
2008-03-22 11:52:18 -04:00
|
|
|
(if lispp
|
|
|
|
(mapconcat
|
|
|
|
(lambda (x)
|
|
|
|
(if (eq lispp 'literal)
|
|
|
|
x
|
|
|
|
(prin1-to-string (if numbers (string-to-number x) x))))
|
|
|
|
elements " ")
|
|
|
|
(concat "[" (mapconcat
|
|
|
|
(lambda (x)
|
2012-12-28 09:02:01 -05:00
|
|
|
(if (string-match "\\S-" x)
|
|
|
|
(if numbers
|
|
|
|
(number-to-string (string-to-number x))
|
|
|
|
x)
|
2012-12-28 09:03:10 -05:00
|
|
|
(if (or (not keep-empty) numbers) "0" "nan")))
|
2008-03-22 11:52:18 -04:00
|
|
|
elements
|
|
|
|
",") "]"))))
|
|
|
|
|
2013-03-19 10:25:14 -04:00
|
|
|
;;;###autoload
|
|
|
|
(defun org-table-set-constants ()
|
|
|
|
"Set `org-table-formula-constants-local' in the current buffer."
|
|
|
|
(let (cst consts const-str)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (re-search-forward "^[ \t]*#\\+CONSTANTS: \\(.*\\)" nil t)
|
|
|
|
(setq const-str (substring-no-properties (match-string 1)))
|
|
|
|
(setq consts (append consts (org-split-string const-str "[ \t]+")))
|
|
|
|
(when consts
|
|
|
|
(let (e)
|
|
|
|
(while (setq e (pop consts))
|
|
|
|
(when (string-match "^\\([a-zA-Z0][_a-zA-Z0-9]*\\)=\\(.*\\)" e)
|
|
|
|
(if (assoc-string (match-string 1 e) cst)
|
|
|
|
(setq cst (delete (assoc-string (match-string 1 e) cst) cst)))
|
|
|
|
(push (cons (match-string 1 e) (match-string 2 e)) cst)))
|
|
|
|
(setq org-table-formula-constants-local cst)))))))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-recalculate (&optional all noalign)
|
|
|
|
"Recalculate the current table line by applying all stored formulas.
|
2008-12-12 08:50:43 -05:00
|
|
|
With prefix arg ALL, do this for all lines in the table.
|
2010-07-17 14:53:36 -04:00
|
|
|
With the prefix argument ALL is `(16)' \
|
|
|
|
\(a double \\[universal-prefix] \\[universal-prefix] prefix), or if
|
2008-12-12 08:50:43 -05:00
|
|
|
it is the symbol `iterate', recompute the table until it no longer changes.
|
|
|
|
If NOALIGN is not nil, do not re-align the table after the computations
|
|
|
|
are done. This is typically used internally to save time, if it is
|
|
|
|
known that the table will be realigned a little later anyway."
|
2008-03-22 11:52:18 -04:00
|
|
|
(interactive "P")
|
|
|
|
(or (memq this-command org-recalc-commands)
|
|
|
|
(setq org-recalc-commands (cons this-command org-recalc-commands)))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(unless (org-at-table-p) (user-error "Not at a table"))
|
2008-12-12 08:50:43 -05:00
|
|
|
(if (or (eq all 'iterate) (equal all '(16)))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-iterate)
|
|
|
|
(org-table-get-specials)
|
|
|
|
(let* ((eqlist (sort (org-table-get-stored-formulas)
|
|
|
|
(lambda (a b) (string< (car a) (car b)))))
|
2011-03-03 11:44:13 -05:00
|
|
|
(eqlist1 (copy-sequence eqlist))
|
2008-03-22 11:52:18 -04:00
|
|
|
(inhibit-redisplay (not debug-on-error))
|
|
|
|
(line-re org-table-dataline-regexp)
|
|
|
|
(thisline (org-current-line))
|
|
|
|
(thiscol (org-table-current-column))
|
2011-03-03 11:44:13 -05:00
|
|
|
seen-fields lhs1
|
2011-03-01 03:05:56 -05:00
|
|
|
beg end entry eqlnum eqlname eqlname1 eql (cnt 0) eq a name name1)
|
2008-03-22 11:52:18 -04:00
|
|
|
;; Insert constants in all formulas
|
|
|
|
(setq eqlist
|
|
|
|
(mapcar (lambda (x)
|
2013-11-05 06:07:41 -05:00
|
|
|
(if (string-match "^@-?I+" (car x))
|
|
|
|
(user-error "Can't assign to hline relative reference"))
|
2011-03-08 08:49:53 -05:00
|
|
|
(when (string-match "\\`$[<>]" (car x))
|
2011-03-03 11:44:13 -05:00
|
|
|
(setq lhs1 (car x))
|
|
|
|
(setq x (cons (substring
|
2011-03-08 08:49:53 -05:00
|
|
|
(org-table-formula-handle-first/last-rc
|
2011-03-03 11:44:13 -05:00
|
|
|
(car x)) 1)
|
|
|
|
(cdr x)))
|
|
|
|
(if (assoc (car x) eqlist1)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "\"%s=\" formula tries to overwrite existing formula for column %s"
|
2011-03-03 11:44:13 -05:00
|
|
|
lhs1 (car x))))
|
2011-03-01 03:05:56 -05:00
|
|
|
(cons
|
2011-03-08 08:49:53 -05:00
|
|
|
(org-table-formula-handle-first/last-rc (car x))
|
2011-03-01 03:05:56 -05:00
|
|
|
(org-table-formula-substitute-names
|
2011-03-08 08:49:53 -05:00
|
|
|
(org-table-formula-handle-first/last-rc (cdr x)))))
|
2008-03-22 11:52:18 -04:00
|
|
|
eqlist))
|
|
|
|
;; Split the equation list
|
|
|
|
(while (setq eq (pop eqlist))
|
2011-03-03 16:13:26 -05:00
|
|
|
(if (<= (string-to-char (car eq)) ?9)
|
|
|
|
(push eq eqlnum)
|
|
|
|
(push eq eqlname)))
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq eqlnum (nreverse eqlnum) eqlname (nreverse eqlname))
|
2011-03-01 03:05:56 -05:00
|
|
|
;; Expand ranges in lhs of formulas
|
|
|
|
(setq eqlname (org-table-expand-lhs-ranges eqlname))
|
2011-07-23 11:23:19 -04:00
|
|
|
|
2011-03-01 03:05:56 -05:00
|
|
|
;; Get the correct line range to process
|
2008-03-22 11:52:18 -04:00
|
|
|
(if all
|
|
|
|
(progn
|
|
|
|
(setq end (move-marker (make-marker) (1+ (org-table-end))))
|
|
|
|
(goto-char (setq beg (org-table-begin)))
|
|
|
|
(if (re-search-forward org-table-calculate-mark-regexp end t)
|
|
|
|
;; This is a table with marked lines, compute selected lines
|
|
|
|
(setq line-re org-table-recalculate-regexp)
|
|
|
|
;; Move forward to the first non-header line
|
|
|
|
(if (and (re-search-forward org-table-dataline-regexp end t)
|
|
|
|
(re-search-forward org-table-hline-regexp end t)
|
|
|
|
(re-search-forward org-table-dataline-regexp end t))
|
|
|
|
(setq beg (match-beginning 0))
|
|
|
|
nil))) ;; just leave beg where it is
|
|
|
|
(setq beg (point-at-bol)
|
|
|
|
end (move-marker (make-marker) (1+ (point-at-eol)))))
|
|
|
|
(goto-char beg)
|
|
|
|
(and all (message "Re-applying formulas to full table..."))
|
|
|
|
|
2011-03-01 03:05:56 -05:00
|
|
|
;; First find the named fields, and mark them untouchable.
|
|
|
|
;; Also check if several field/range formulas try to set the same field.
|
2008-03-22 11:52:18 -04:00
|
|
|
(remove-text-properties beg end '(org-untouchable t))
|
|
|
|
(while (setq eq (pop eqlname))
|
|
|
|
(setq name (car eq)
|
|
|
|
a (assoc name org-table-named-field-locations))
|
2011-03-01 03:05:56 -05:00
|
|
|
(setq name1 name)
|
|
|
|
(if a (setq name1 (format "@%d$%d" (org-table-line-to-dline (nth 1 a))
|
|
|
|
(nth 2 a))))
|
|
|
|
(when (member name1 seen-fields)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Several field/range formulas try to set %s" name1))
|
2011-03-01 03:05:56 -05:00
|
|
|
(push name1 seen-fields)
|
2011-07-23 11:23:19 -04:00
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
(and (not a)
|
|
|
|
(string-match "@\\([0-9]+\\)\\$\\([0-9]+\\)" name)
|
|
|
|
(setq a (list name
|
2008-05-28 08:11:33 -04:00
|
|
|
(condition-case nil
|
|
|
|
(aref org-table-dlines
|
|
|
|
(string-to-number (match-string 1 name)))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(error (user-error "Invalid row number in %s"
|
2008-05-28 08:11:33 -04:00
|
|
|
name)))
|
2008-03-22 11:52:18 -04:00
|
|
|
(string-to-number (match-string 2 name)))))
|
|
|
|
(when (and a (or all (equal (nth 1 a) thisline)))
|
|
|
|
(message "Re-applying formula to field: %s" name)
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line (nth 1 a))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-goto-column (nth 2 a))
|
|
|
|
(push (append a (list (cdr eq))) eqlname1)
|
|
|
|
(org-table-put-field-property :org-untouchable t)))
|
2011-03-03 11:44:13 -05:00
|
|
|
(setq eqlname1 (nreverse eqlname1))
|
2011-07-23 11:23:19 -04:00
|
|
|
|
2009-11-12 07:39:29 -05:00
|
|
|
;; Now evaluate the column formulas, but skip fields covered by
|
2008-03-22 11:52:18 -04:00
|
|
|
;; field formulas
|
|
|
|
(goto-char beg)
|
|
|
|
(while (re-search-forward line-re end t)
|
|
|
|
(unless (string-match "^ *[_^!$/] *$" (org-table-get-field 1))
|
|
|
|
;; Unprotected line, recalculate
|
|
|
|
(and all (message "Re-applying formulas to full table...(line %d)"
|
|
|
|
(setq cnt (1+ cnt))))
|
|
|
|
(setq org-last-recalc-line (org-current-line))
|
|
|
|
(setq eql eqlnum)
|
|
|
|
(while (setq entry (pop eql))
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line org-last-recalc-line)
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-goto-column (string-to-number (car entry)) nil 'force)
|
|
|
|
(unless (get-text-property (point) :org-untouchable)
|
|
|
|
(org-table-eval-formula nil (cdr entry)
|
|
|
|
'noalign 'nocst 'nostore 'noanalysis)))))
|
|
|
|
|
|
|
|
;; Now evaluate the field formulas
|
|
|
|
(while (setq eq (pop eqlname1))
|
|
|
|
(message "Re-applying formula to field: %s" (car eq))
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line (nth 1 eq))
|
2014-10-01 01:36:21 -04:00
|
|
|
(let ((column-target (nth 2 eq)))
|
|
|
|
(when (> column-target 1000)
|
|
|
|
(user-error "Formula column target too large"))
|
|
|
|
(let* ((column-count (progn (end-of-line)
|
|
|
|
(1- (org-table-current-column))))
|
|
|
|
(create-new-column
|
|
|
|
(and (> column-target column-count)
|
|
|
|
(or (eq org-table-formula-create-columns t)
|
|
|
|
(and
|
|
|
|
(eq org-table-formula-create-columns 'warn)
|
|
|
|
(progn
|
|
|
|
(org-display-warning "Out-of-bounds formula added columns")
|
|
|
|
t))
|
|
|
|
(and
|
|
|
|
(eq org-table-formula-create-columns 'prompt)
|
|
|
|
(yes-or-no-p "Out-of-bounds formula. Add columns?"))))))
|
|
|
|
(org-table-goto-column column-target nil create-new-column))
|
|
|
|
|
|
|
|
(org-table-eval-formula nil (nth 3 eq) 'noalign 'nocst
|
|
|
|
'nostore 'noanalysis)))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line thisline)
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-goto-column thiscol)
|
|
|
|
(remove-text-properties (point-min) (point-max) '(org-untouchable t))
|
|
|
|
(or noalign (and org-table-may-need-update (org-table-align))
|
|
|
|
(and all (message "Re-applying formulas to %d lines...done" cnt)))
|
|
|
|
|
|
|
|
;; back to initial position
|
|
|
|
(message "Re-applying formulas...done")
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line thisline)
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-goto-column thiscol)
|
|
|
|
(or noalign (and org-table-may-need-update (org-table-align))
|
|
|
|
(and all (message "Re-applying formulas...done"))))))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-iterate (&optional arg)
|
2011-03-03 11:44:13 -05:00
|
|
|
"Recalculate the table until it does not change anymore.
|
2012-04-02 01:51:52 -04:00
|
|
|
The maximum number of iterations is 10, but you can choose a different value
|
2011-03-03 11:44:13 -05:00
|
|
|
with the prefix ARG."
|
2008-03-22 11:52:18 -04:00
|
|
|
(interactive "P")
|
|
|
|
(let ((imax (if arg (prefix-numeric-value arg) 10))
|
|
|
|
(i 0)
|
|
|
|
(lasttbl (buffer-substring (org-table-begin) (org-table-end)))
|
|
|
|
thistbl)
|
|
|
|
(catch 'exit
|
|
|
|
(while (< i imax)
|
|
|
|
(setq i (1+ i))
|
|
|
|
(org-table-recalculate 'all)
|
|
|
|
(setq thistbl (buffer-substring (org-table-begin) (org-table-end)))
|
|
|
|
(if (not (string= lasttbl thistbl))
|
|
|
|
(setq lasttbl thistbl)
|
|
|
|
(if (> i 1)
|
|
|
|
(message "Convergence after %d iterations" i)
|
|
|
|
(message "Table was already stable"))
|
|
|
|
(throw 'exit t)))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "No convergence after %d iterations" i))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
2012-04-09 11:32:18 -04:00
|
|
|
;;;###autoload
|
2010-05-07 03:45:34 -04:00
|
|
|
(defun org-table-recalculate-buffer-tables ()
|
|
|
|
"Recalculate all tables in the current buffer."
|
|
|
|
(interactive)
|
|
|
|
(save-excursion
|
|
|
|
(save-restriction
|
|
|
|
(widen)
|
|
|
|
(org-table-map-tables (lambda () (org-table-recalculate t)) t))))
|
|
|
|
|
2012-04-09 11:32:18 -04:00
|
|
|
;;;###autoload
|
2010-05-07 03:45:34 -04:00
|
|
|
(defun org-table-iterate-buffer-tables ()
|
|
|
|
"Iterate all tables in the buffer, to converge inter-table dependencies."
|
2012-08-11 13:10:44 -04:00
|
|
|
(interactive)
|
|
|
|
(let* ((imax 10)
|
2012-10-02 04:03:15 -04:00
|
|
|
(i imax)
|
2012-08-11 13:10:44 -04:00
|
|
|
(checksum (md5 (buffer-string)))
|
2012-10-02 04:03:15 -04:00
|
|
|
c1)
|
2012-08-11 13:10:44 -04:00
|
|
|
(save-excursion
|
|
|
|
(save-restriction
|
|
|
|
(widen)
|
|
|
|
(catch 'exit
|
|
|
|
(while (> i 0)
|
|
|
|
(setq i (1- i))
|
|
|
|
(org-table-map-tables (lambda () (org-table-recalculate t)) t)
|
|
|
|
(if (equal checksum (setq c1 (md5 (buffer-string))))
|
|
|
|
(progn
|
|
|
|
(message "Convergence after %d iterations" (- imax i))
|
|
|
|
(throw 'exit t))
|
|
|
|
(setq checksum c1)))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "No convergence after %d iterations" imax))))))
|
2010-05-07 03:45:34 -04:00
|
|
|
|
2013-05-15 10:18:37 -04:00
|
|
|
(defun org-table-calc-current-TBLFM (&optional arg)
|
|
|
|
"Apply the #+TBLFM in the line at point to the table."
|
2013-04-02 05:11:26 -04:00
|
|
|
(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)
|
|
|
|
(save-excursion
|
|
|
|
;; Insert a temporary formula at right after the table
|
2013-05-15 10:18:37 -04:00
|
|
|
(goto-char (org-table-TBLFM-begin))
|
2013-04-02 05:11:26 -04:00
|
|
|
(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)
|
2013-04-05 03:07:00 -04:00
|
|
|
(unwind-protect
|
|
|
|
(org-call-with-arg 'org-table-recalculate (or arg t))
|
|
|
|
;; delete the formula inserted temporarily
|
|
|
|
(delete-region s e))))))
|
2013-04-02 05:11:26 -04:00
|
|
|
|
2013-05-15 10:18:37 -04:00
|
|
|
(defun org-table-TBLFM-begin ()
|
2013-04-02 05:09:26 -04:00
|
|
|
"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
|
2013-05-15 10:18:37 -04:00
|
|
|
org-table-TBLFM-begin-regexp
|
2013-04-02 05:09:26 -04:00
|
|
|
nil t))
|
|
|
|
(point-at-bol 2))))
|
|
|
|
|
2011-03-01 03:05:56 -05:00
|
|
|
(defun org-table-expand-lhs-ranges (equations)
|
|
|
|
"Expand list of formulas.
|
|
|
|
If some of the RHS in the formulas are ranges or a row reference, expand
|
|
|
|
them to individual field equations for each field."
|
|
|
|
(let (e res lhs rhs range r1 r2 c1 c2)
|
|
|
|
(while (setq e (pop equations))
|
|
|
|
(setq lhs (car e) rhs (cdr e))
|
|
|
|
(cond
|
2012-05-10 06:17:51 -04:00
|
|
|
((string-match "^@-?[-+0-9]+\\$-?[0-9]+$" lhs)
|
2011-03-01 03:05:56 -05:00
|
|
|
;; This just refers to one fixed field
|
|
|
|
(push e res))
|
2011-08-23 10:27:56 -04:00
|
|
|
((string-match "^[a-zA-Z][_a-zA-Z0-9]*$" lhs)
|
2011-03-01 03:05:56 -05:00
|
|
|
;; This just refers to one fixed named field
|
|
|
|
(push e res))
|
|
|
|
((string-match "^@[0-9]+$" lhs)
|
|
|
|
(loop for ic from 1 to org-table-current-ncol do
|
|
|
|
(push (cons (format "%s$%d" lhs ic) rhs) res)
|
|
|
|
(put-text-property 0 (length (caar res))
|
|
|
|
:orig-eqn e (caar res))))
|
|
|
|
(t
|
|
|
|
(setq range (org-table-get-range lhs org-table-current-begin-pos
|
|
|
|
1 nil 'corners))
|
|
|
|
(setq r1 (nth 0 range) c1 (nth 1 range)
|
|
|
|
r2 (nth 2 range) c2 (nth 3 range))
|
|
|
|
(setq r1 (org-table-line-to-dline r1))
|
|
|
|
(setq r2 (org-table-line-to-dline r2 'above))
|
|
|
|
(loop for ir from r1 to r2 do
|
|
|
|
(loop for ic from c1 to c2 do
|
|
|
|
(push (cons (format "@%d$%d" ir ic) rhs) res)
|
|
|
|
(put-text-property 0 (length (caar res))
|
|
|
|
:orig-eqn e (caar res)))))))
|
|
|
|
(nreverse res)))
|
|
|
|
|
2011-03-08 08:49:53 -05:00
|
|
|
(defun org-table-formula-handle-first/last-rc (s)
|
|
|
|
"Replace @<, @>, $<, $> with first/last row/column of the table.
|
|
|
|
So @< and $< will always be replaced with @1 and $1, respectively.
|
|
|
|
The advantage of these special markers are that structure editing of
|
|
|
|
the table will not change them, while @1 and $1 will be modified
|
2011-12-31 02:59:49 -05:00
|
|
|
when a line/row is swapped out of that privileged position. So for
|
2011-03-08 08:49:53 -05:00
|
|
|
formulas that use a range of rows or columns, it may often be better
|
|
|
|
to anchor the formula with \"I\" row markers, or to offset from the
|
|
|
|
borders of the table using the @< @> $< $> makers."
|
Fix remote references that contain pointers to first/last rows/columns
* lisp/org-table.el (org-table-formula-handle-first/last-rc): Do not
expand pointers to first/last row/column that are inside a call
to `remote'.
(org-table-get-remote-range): Expand pointers to first/last
row/column.
Wu Feng writes:
> Hello,
>
> First, please check below simple example, I defined two tables (T1 and
> T2). In table-2, I remotely refer to the @>$1 (last row, column 1) and
> $LR2 (last row, column 2) of T1.
>
> #+TBLNAME: T1
> | 11 | 12 |
> | 21 | 22 |
> | 31 | 32 |
>
> #+TBLNAME: T2
> | xxx | xxx | xxx | xxx |
> | # | 21 | 32 | |
> #+TBLFM: @>$3=remote(T1,$LR2)::@>$2=remote(T1,@>$1)
>
> Obviously, the expected results are:
>
> - remote(T1,@>$1) is replaced by 31
> - remote(T1,$LR2) is replaced by 32
>
> But I got 21 for remote(T1,@>$1). The $LR version works perfectly
> (though the manual says $LR is out-dated)
>
> Below are debug info when evaluating remote(T1,@>$1). Looks like @> in
> the remote reference is mapped to the last row of the current table, not
> of the remote table.
>
> Substitution history of formula
> Orig: remote(T1,@2$1)
> $xyz-> remote(T1,@2$1)
> @r$c-> (21)
> $1-> (21)
> Result: 21
> Format: NONE
> Final: 21
>
> Emacs : GNU Emacs 23.3.1 (i686-pc-linux-gnu, GTK+ Version 2.24.6)
> of 2011-09-13 on shirley
> Package: Org-mode version 7.7
2011-10-27 11:30:47 -04:00
|
|
|
(let (n nmax len char (start 0))
|
|
|
|
(while (string-match "\\([@$]\\)\\(<+\\|>+\\)\\|\\(remote([^\)]+)\\)"
|
|
|
|
s start)
|
|
|
|
(if (match-end 3)
|
|
|
|
(setq start (match-end 3))
|
|
|
|
(setq nmax (if (equal (match-string 1 s) "@")
|
|
|
|
(1- (length org-table-dlines))
|
|
|
|
org-table-current-ncol)
|
|
|
|
len (- (match-end 2) (match-beginning 2))
|
|
|
|
char (string-to-char (match-string 2 s))
|
|
|
|
n (if (= char ?<)
|
|
|
|
len
|
|
|
|
(- nmax len -1)))
|
|
|
|
(if (or (< n 1) (> n nmax))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Reference \"%s\" in expression \"%s\" points outside table"
|
Fix remote references that contain pointers to first/last rows/columns
* lisp/org-table.el (org-table-formula-handle-first/last-rc): Do not
expand pointers to first/last row/column that are inside a call
to `remote'.
(org-table-get-remote-range): Expand pointers to first/last
row/column.
Wu Feng writes:
> Hello,
>
> First, please check below simple example, I defined two tables (T1 and
> T2). In table-2, I remotely refer to the @>$1 (last row, column 1) and
> $LR2 (last row, column 2) of T1.
>
> #+TBLNAME: T1
> | 11 | 12 |
> | 21 | 22 |
> | 31 | 32 |
>
> #+TBLNAME: T2
> | xxx | xxx | xxx | xxx |
> | # | 21 | 32 | |
> #+TBLFM: @>$3=remote(T1,$LR2)::@>$2=remote(T1,@>$1)
>
> Obviously, the expected results are:
>
> - remote(T1,@>$1) is replaced by 31
> - remote(T1,$LR2) is replaced by 32
>
> But I got 21 for remote(T1,@>$1). The $LR version works perfectly
> (though the manual says $LR is out-dated)
>
> Below are debug info when evaluating remote(T1,@>$1). Looks like @> in
> the remote reference is mapped to the last row of the current table, not
> of the remote table.
>
> Substitution history of formula
> Orig: remote(T1,@2$1)
> $xyz-> remote(T1,@2$1)
> @r$c-> (21)
> $1-> (21)
> Result: 21
> Format: NONE
> Final: 21
>
> Emacs : GNU Emacs 23.3.1 (i686-pc-linux-gnu, GTK+ Version 2.24.6)
> of 2011-09-13 on shirley
> Package: Org-mode version 7.7
2011-10-27 11:30:47 -04:00
|
|
|
(match-string 0 s) s))
|
|
|
|
(setq start (match-beginning 0))
|
|
|
|
(setq s (replace-match (format "%s%d" (match-string 1 s) n) t t s)))))
|
2011-03-01 03:05:56 -05:00
|
|
|
s)
|
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-formula-substitute-names (f)
|
|
|
|
"Replace $const with values in string F."
|
|
|
|
(let ((start 0) a (f1 f) (pp (/= (string-to-char f) ?')))
|
|
|
|
;; First, check for column names
|
|
|
|
(while (setq start (string-match org-table-column-name-regexp f start))
|
|
|
|
(setq start (1+ start))
|
|
|
|
(setq a (assoc (match-string 1 f) org-table-column-names))
|
|
|
|
(setq f (replace-match (concat "$" (cdr a)) t t f)))
|
|
|
|
;; Parameters and constants
|
|
|
|
(setq start 0)
|
2009-01-24 04:51:21 -05:00
|
|
|
(while (setq start (string-match "\\$\\([a-zA-Z][_a-zA-Z0-9]*\\)\\|\\(\\<remote([^)]*)\\)" f start))
|
|
|
|
(if (match-end 2)
|
|
|
|
(setq start (match-end 2))
|
|
|
|
(setq start (1+ start))
|
|
|
|
(if (setq a (save-match-data
|
|
|
|
(org-table-get-constant (match-string 1 f))))
|
|
|
|
(setq f (replace-match
|
|
|
|
(concat (if pp "(") a (if pp ")")) t t f)))))
|
2008-03-22 11:52:18 -04:00
|
|
|
(if org-table-formula-debug
|
|
|
|
(put-text-property 0 (length f) :orig-formula f1 f))
|
|
|
|
f))
|
|
|
|
|
|
|
|
(defun org-table-get-constant (const)
|
|
|
|
"Find the value for a parameter or constant in a formula.
|
|
|
|
Parameters get priority."
|
|
|
|
(or (cdr (assoc const org-table-local-parameters))
|
|
|
|
(cdr (assoc const org-table-formula-constants-local))
|
|
|
|
(cdr (assoc const org-table-formula-constants))
|
|
|
|
(and (fboundp 'constants-get) (constants-get const))
|
|
|
|
(and (string= (substring const 0 (min 5 (length const))) "PROP_")
|
|
|
|
(org-entry-get nil (substring const 5) 'inherit))
|
|
|
|
"#UNDEFINED_NAME"))
|
|
|
|
|
|
|
|
(defvar org-table-fedit-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(org-defkey map "\C-x\C-s" 'org-table-fedit-finish)
|
|
|
|
(org-defkey map "\C-c\C-s" 'org-table-fedit-finish)
|
|
|
|
(org-defkey map "\C-c\C-c" 'org-table-fedit-finish)
|
2010-06-06 06:50:44 -04:00
|
|
|
(org-defkey map "\C-c'" 'org-table-fedit-finish)
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-defkey map "\C-c\C-q" 'org-table-fedit-abort)
|
2008-12-16 11:48:54 -05:00
|
|
|
(org-defkey map "\C-c?" 'org-table-show-reference)
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-defkey map [(meta shift up)] 'org-table-fedit-line-up)
|
|
|
|
(org-defkey map [(meta shift down)] 'org-table-fedit-line-down)
|
|
|
|
(org-defkey map [(shift up)] 'org-table-fedit-ref-up)
|
|
|
|
(org-defkey map [(shift down)] 'org-table-fedit-ref-down)
|
|
|
|
(org-defkey map [(shift left)] 'org-table-fedit-ref-left)
|
|
|
|
(org-defkey map [(shift right)] 'org-table-fedit-ref-right)
|
|
|
|
(org-defkey map [(meta up)] 'org-table-fedit-scroll-down)
|
|
|
|
(org-defkey map [(meta down)] 'org-table-fedit-scroll)
|
|
|
|
(org-defkey map [(meta tab)] 'lisp-complete-symbol)
|
|
|
|
(org-defkey map "\M-\C-i" 'lisp-complete-symbol)
|
2008-12-16 11:48:54 -05:00
|
|
|
(org-defkey map [(tab)] 'org-table-fedit-lisp-indent)
|
|
|
|
(org-defkey map "\C-i" 'org-table-fedit-lisp-indent)
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-defkey map "\C-c\C-r" 'org-table-fedit-toggle-ref-type)
|
|
|
|
(org-defkey map "\C-c}" 'org-table-fedit-toggle-coordinates)
|
|
|
|
map))
|
|
|
|
|
|
|
|
(easy-menu-define org-table-fedit-menu org-table-fedit-map "Org Edit Formulas Menu"
|
|
|
|
'("Edit-Formulas"
|
|
|
|
["Finish and Install" org-table-fedit-finish t]
|
|
|
|
["Finish, Install, and Apply" (org-table-fedit-finish t) :keys "C-u C-c C-c"]
|
|
|
|
["Abort" org-table-fedit-abort t]
|
|
|
|
"--"
|
|
|
|
["Pretty-Print Lisp Formula" org-table-fedit-lisp-indent t]
|
|
|
|
["Complete Lisp Symbol" lisp-complete-symbol t]
|
|
|
|
"--"
|
|
|
|
"Shift Reference at Point"
|
|
|
|
["Up" org-table-fedit-ref-up t]
|
|
|
|
["Down" org-table-fedit-ref-down t]
|
|
|
|
["Left" org-table-fedit-ref-left t]
|
|
|
|
["Right" org-table-fedit-ref-right t]
|
|
|
|
"-"
|
|
|
|
"Change Test Row for Column Formulas"
|
|
|
|
["Up" org-table-fedit-line-up t]
|
|
|
|
["Down" org-table-fedit-line-down t]
|
|
|
|
"--"
|
|
|
|
["Scroll Table Window" org-table-fedit-scroll t]
|
|
|
|
["Scroll Table Window down" org-table-fedit-scroll-down t]
|
|
|
|
["Show Table Grid" org-table-fedit-toggle-coordinates
|
|
|
|
:style toggle :selected (with-current-buffer (marker-buffer org-pos)
|
|
|
|
org-table-overlay-coordinates)]
|
|
|
|
"--"
|
|
|
|
["Standard Refs (B3 instead of @3$2)" org-table-fedit-toggle-ref-type
|
|
|
|
:style toggle :selected org-table-buffer-is-an]))
|
|
|
|
|
|
|
|
(defvar org-pos)
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-edit-formulas ()
|
|
|
|
"Edit the formulas of the current table in a separate buffer."
|
|
|
|
(interactive)
|
2012-04-21 09:36:04 -04:00
|
|
|
(when (save-excursion (beginning-of-line 1) (let ((case-fold-search t)) (looking-at "[ \t]*#\\+TBLFM")))
|
2008-03-22 11:52:18 -04:00
|
|
|
(beginning-of-line 0))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(unless (org-at-table-p) (user-error "Not at a table"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-get-specials)
|
|
|
|
(let ((key (org-table-current-field-formula 'key 'noerror))
|
|
|
|
(eql (sort (org-table-get-stored-formulas 'noerror)
|
2008-12-16 11:48:54 -05:00
|
|
|
'org-table-formula-less-p))
|
2012-12-19 23:46:41 -05:00
|
|
|
(pos (point-marker))
|
2008-03-22 11:52:18 -04:00
|
|
|
(startline 1)
|
|
|
|
(wc (current-window-configuration))
|
2009-09-03 02:07:58 -04:00
|
|
|
(sel-win (selected-window))
|
2008-03-22 11:52:18 -04:00
|
|
|
(titles '((column . "# Column Formulas\n")
|
2011-03-01 03:05:56 -05:00
|
|
|
(field . "# Field and Range Formulas\n")
|
2008-03-22 11:52:18 -04:00
|
|
|
(named . "# Named Field Formulas\n")))
|
|
|
|
entry s type title)
|
|
|
|
(org-switch-to-buffer-other-window "*Edit Formulas*")
|
|
|
|
(erase-buffer)
|
|
|
|
;; Keep global-font-lock-mode from turning on font-lock-mode
|
|
|
|
(let ((font-lock-global-modes '(not fundamental-mode)))
|
|
|
|
(fundamental-mode))
|
|
|
|
(org-set-local 'font-lock-global-modes (list 'not major-mode))
|
|
|
|
(org-set-local 'org-pos pos)
|
|
|
|
(org-set-local 'org-window-configuration wc)
|
2009-09-03 02:07:58 -04:00
|
|
|
(org-set-local 'org-selected-window sel-win)
|
2008-03-22 11:52:18 -04:00
|
|
|
(use-local-map org-table-fedit-map)
|
|
|
|
(org-add-hook 'post-command-hook 'org-table-fedit-post-command t t)
|
|
|
|
(easy-menu-add org-table-fedit-menu)
|
|
|
|
(setq startline (org-current-line))
|
|
|
|
(while (setq entry (pop eql))
|
|
|
|
(setq type (cond
|
2011-03-08 08:49:53 -05:00
|
|
|
((string-match "\\`$[<>]" (car entry)) 'column)
|
2008-03-22 11:52:18 -04:00
|
|
|
((equal (string-to-char (car entry)) ?@) 'field)
|
|
|
|
((string-match "^[0-9]" (car entry)) 'column)
|
|
|
|
(t 'named)))
|
|
|
|
(when (setq title (assq type titles))
|
|
|
|
(or (bobp) (insert "\n"))
|
|
|
|
(insert (org-add-props (cdr title) nil 'face font-lock-comment-face))
|
2011-03-01 03:05:56 -05:00
|
|
|
(setq titles (remove title titles)))
|
2008-03-22 11:52:18 -04:00
|
|
|
(if (equal key (car entry)) (setq startline (org-current-line)))
|
2011-03-03 11:44:13 -05:00
|
|
|
(setq s (concat (if (member (string-to-char (car entry)) '(?@ ?$)) "" "$")
|
2008-03-22 11:52:18 -04:00
|
|
|
(car entry) " = " (cdr entry) "\n"))
|
|
|
|
(remove-text-properties 0 (length s) '(face nil) s)
|
|
|
|
(insert s))
|
|
|
|
(if (eq org-table-use-standard-references t)
|
|
|
|
(org-table-fedit-toggle-ref-type))
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line startline)
|
2010-06-06 06:50:44 -04:00
|
|
|
(message "Edit formulas, finish with `C-c C-c' or `C-c ' '. See menu for more commands.")))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defun org-table-fedit-post-command ()
|
|
|
|
(when (not (memq this-command '(lisp-complete-symbol)))
|
|
|
|
(let ((win (selected-window)))
|
|
|
|
(save-excursion
|
|
|
|
(condition-case nil
|
|
|
|
(org-table-show-reference)
|
|
|
|
(error nil))
|
|
|
|
(select-window win)))))
|
|
|
|
|
|
|
|
(defun org-table-formula-to-user (s)
|
|
|
|
"Convert a formula from internal to user representation."
|
|
|
|
(if (eq org-table-use-standard-references t)
|
|
|
|
(org-table-convert-refs-to-an s)
|
|
|
|
s))
|
|
|
|
|
|
|
|
(defun org-table-formula-from-user (s)
|
|
|
|
"Convert a formula from user to internal representation."
|
|
|
|
(if org-table-use-standard-references
|
|
|
|
(org-table-convert-refs-to-rc s)
|
|
|
|
s))
|
|
|
|
|
|
|
|
(defun org-table-convert-refs-to-rc (s)
|
2011-03-03 03:34:34 -05:00
|
|
|
"Convert spreadsheet references from A7 to @7$28.
|
2008-03-22 11:52:18 -04:00
|
|
|
Works for single references, but also for entire formulas and even the
|
|
|
|
full TBLFM line."
|
|
|
|
(let ((start 0))
|
2012-08-10 05:00:15 -04:00
|
|
|
(while (string-match "\\<\\([a-zA-Z]+\\)\\([0-9]+\\>\\|&\\)\\|\\(;[^\r\n:]+\\|\\<remote([^,)]*)\\)" s start)
|
2008-03-22 11:52:18 -04:00
|
|
|
(cond
|
|
|
|
((match-end 3)
|
|
|
|
;; format match, just advance
|
|
|
|
(setq start (match-end 0)))
|
|
|
|
((and (> (match-beginning 0) 0)
|
|
|
|
(equal ?. (aref s (max (1- (match-beginning 0)) 0)))
|
|
|
|
(not (equal ?. (aref s (max (- (match-beginning 0) 2) 0)))))
|
|
|
|
;; 3.e5 or something like this.
|
|
|
|
(setq start (match-end 0)))
|
2010-03-08 02:40:06 -05:00
|
|
|
((or (> (- (match-end 1) (match-beginning 1)) 2)
|
|
|
|
;; (member (match-string 1 s)
|
|
|
|
;; '("arctan" "exp" "expm" "lnp" "log" "stir"))
|
|
|
|
)
|
2010-03-07 10:20:04 -05:00
|
|
|
;; function name, just advance
|
|
|
|
(setq start (match-end 0)))
|
2008-03-22 11:52:18 -04:00
|
|
|
(t
|
|
|
|
(setq start (match-beginning 0)
|
|
|
|
s (replace-match
|
|
|
|
(if (equal (match-string 2 s) "&")
|
|
|
|
(format "$%d" (org-letters-to-number (match-string 1 s)))
|
|
|
|
(format "@%d$%d"
|
|
|
|
(string-to-number (match-string 2 s))
|
|
|
|
(org-letters-to-number (match-string 1 s))))
|
|
|
|
t t s)))))
|
|
|
|
s))
|
|
|
|
|
|
|
|
(defun org-table-convert-refs-to-an (s)
|
|
|
|
"Convert spreadsheet references from to @7$28 to AB7.
|
|
|
|
Works for single references, but also for entire formulas and even the
|
|
|
|
full TBLFM line."
|
|
|
|
(while (string-match "@\\([0-9]+\\)\\$\\([0-9]+\\)" s)
|
|
|
|
(setq s (replace-match
|
|
|
|
(format "%s%d"
|
|
|
|
(org-number-to-letters
|
|
|
|
(string-to-number (match-string 2 s)))
|
|
|
|
(string-to-number (match-string 1 s)))
|
|
|
|
t t s)))
|
|
|
|
(while (string-match "\\(^\\|[^0-9a-zA-Z]\\)\\$\\([0-9]+\\)" s)
|
|
|
|
(setq s (replace-match (concat "\\1"
|
|
|
|
(org-number-to-letters
|
|
|
|
(string-to-number (match-string 2 s))) "&")
|
|
|
|
t nil s)))
|
|
|
|
s)
|
|
|
|
|
|
|
|
(defun org-letters-to-number (s)
|
|
|
|
"Convert a base 26 number represented by letters into an integer.
|
|
|
|
For example: AB -> 28."
|
|
|
|
(let ((n 0))
|
|
|
|
(setq s (upcase s))
|
|
|
|
(while (> (length s) 0)
|
2012-08-11 13:10:44 -04:00
|
|
|
(setq n (+ (* n 26) (string-to-char s) (- ?A) 1)
|
|
|
|
s (substring s 1)))
|
2008-03-22 11:52:18 -04:00
|
|
|
n))
|
|
|
|
|
|
|
|
(defun org-number-to-letters (n)
|
|
|
|
"Convert an integer into a base 26 number represented by letters.
|
|
|
|
For example: 28 -> AB."
|
|
|
|
(let ((s ""))
|
|
|
|
(while (> n 0)
|
|
|
|
(setq s (concat (char-to-string (+ (mod (1- n) 26) ?A)) s)
|
|
|
|
n (/ (1- n) 26)))
|
|
|
|
s))
|
|
|
|
|
2011-07-02 07:08:54 -04:00
|
|
|
(defun org-table-time-string-to-seconds (s)
|
2011-07-24 12:19:17 -04:00
|
|
|
"Convert a time string into numerical duration in seconds.
|
2011-07-24 18:55:04 -04:00
|
|
|
S can be a string matching either -?HH:MM:SS or -?HH:MM.
|
|
|
|
If S is a string representing a number, keep this number."
|
2012-05-05 10:14:33 -04:00
|
|
|
(if (equal s "")
|
|
|
|
s
|
|
|
|
(let (hour minus min sec res)
|
|
|
|
(cond
|
2012-08-11 13:10:44 -04:00
|
|
|
((and (string-match "\\(-?\\)\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\)" s))
|
|
|
|
(setq minus (< 0 (length (match-string 1 s)))
|
|
|
|
hour (string-to-number (match-string 2 s))
|
|
|
|
min (string-to-number (match-string 3 s))
|
|
|
|
sec (string-to-number (match-string 4 s)))
|
|
|
|
(if minus
|
|
|
|
(setq res (- (+ (* hour 3600) (* min 60) sec)))
|
|
|
|
(setq res (+ (* hour 3600) (* min 60) sec))))
|
|
|
|
((and (not (string-match org-ts-regexp-both s))
|
|
|
|
(string-match "\\(-?\\)\\([0-9]+\\):\\([0-9]+\\)" s))
|
|
|
|
(setq minus (< 0 (length (match-string 1 s)))
|
|
|
|
hour (string-to-number (match-string 2 s))
|
|
|
|
min (string-to-number (match-string 3 s)))
|
|
|
|
(if minus
|
|
|
|
(setq res (- (+ (* hour 3600) (* min 60))))
|
|
|
|
(setq res (+ (* hour 3600) (* min 60)))))
|
|
|
|
(t (setq res (string-to-number s))))
|
2012-05-05 10:14:33 -04:00
|
|
|
(number-to-string res))))
|
2011-07-02 07:08:54 -04:00
|
|
|
|
2011-07-27 07:14:37 -04:00
|
|
|
(defun org-table-time-seconds-to-string (secs &optional output-format)
|
|
|
|
"Convert a number of seconds to a time string.
|
|
|
|
If OUTPUT-FORMAT is non-nil, return a number of days, hours,
|
|
|
|
minutes or seconds."
|
2012-05-01 13:19:06 -04:00
|
|
|
(let* ((secs0 (abs secs))
|
|
|
|
(res
|
|
|
|
(cond ((eq output-format 'days)
|
|
|
|
(format "%.3f" (/ (float secs0) 86400)))
|
|
|
|
((eq output-format 'hours)
|
|
|
|
(format "%.2f" (/ (float secs0) 3600)))
|
|
|
|
((eq output-format 'minutes)
|
|
|
|
(format "%.1f" (/ (float secs0) 60)))
|
|
|
|
((eq output-format 'seconds)
|
|
|
|
(format "%d" secs0))
|
|
|
|
(t (org-format-seconds "%.2h:%.2m:%.2s" secs0)))))
|
|
|
|
(if (< secs 0) (concat "-" res) res)))
|
2011-07-02 07:08:54 -04:00
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-fedit-convert-buffer (function)
|
2008-12-16 11:49:26 -05:00
|
|
|
"Convert all references in this buffer, using FUNCTION."
|
2008-03-22 11:52:18 -04:00
|
|
|
(let ((line (org-current-line)))
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (not (eobp))
|
|
|
|
(insert (funcall function (buffer-substring (point) (point-at-eol))))
|
|
|
|
(delete-region (point) (point-at-eol))
|
|
|
|
(or (eobp) (forward-char 1)))
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line line)))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defun org-table-fedit-toggle-ref-type ()
|
|
|
|
"Convert all references in the buffer from B3 to @3$2 and back."
|
|
|
|
(interactive)
|
|
|
|
(org-set-local 'org-table-buffer-is-an (not org-table-buffer-is-an))
|
|
|
|
(org-table-fedit-convert-buffer
|
|
|
|
(if org-table-buffer-is-an
|
|
|
|
'org-table-convert-refs-to-an 'org-table-convert-refs-to-rc))
|
|
|
|
(message "Reference type switched to %s"
|
|
|
|
(if org-table-buffer-is-an "A1 etc" "@row$column")))
|
|
|
|
|
|
|
|
(defun org-table-fedit-ref-up ()
|
|
|
|
"Shift the reference at point one row/hline up."
|
|
|
|
(interactive)
|
|
|
|
(org-table-fedit-shift-reference 'up))
|
|
|
|
(defun org-table-fedit-ref-down ()
|
|
|
|
"Shift the reference at point one row/hline down."
|
|
|
|
(interactive)
|
|
|
|
(org-table-fedit-shift-reference 'down))
|
|
|
|
(defun org-table-fedit-ref-left ()
|
|
|
|
"Shift the reference at point one field to the left."
|
|
|
|
(interactive)
|
|
|
|
(org-table-fedit-shift-reference 'left))
|
|
|
|
(defun org-table-fedit-ref-right ()
|
|
|
|
"Shift the reference at point one field to the right."
|
|
|
|
(interactive)
|
|
|
|
(org-table-fedit-shift-reference 'right))
|
|
|
|
|
|
|
|
(defun org-table-fedit-shift-reference (dir)
|
|
|
|
(cond
|
|
|
|
((org-at-regexp-p "\\(\\<[a-zA-Z]\\)&")
|
|
|
|
(if (memq dir '(left right))
|
|
|
|
(org-rematch-and-replace 1 (eq dir 'left))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Cannot shift reference in this direction")))
|
2008-03-22 11:52:18 -04:00
|
|
|
((org-at-regexp-p "\\(\\<[a-zA-Z]\\{1,2\\}\\)\\([0-9]+\\)")
|
|
|
|
;; A B3-like reference
|
|
|
|
(if (memq dir '(up down))
|
|
|
|
(org-rematch-and-replace 2 (eq dir 'up))
|
|
|
|
(org-rematch-and-replace 1 (eq dir 'left))))
|
|
|
|
((org-at-regexp-p
|
|
|
|
"\\(@\\|\\.\\.\\)\\([-+]?\\(I+\\>\\|[0-9]+\\)\\)\\(\\$\\([-+]?[0-9]+\\)\\)?")
|
|
|
|
;; An internal reference
|
|
|
|
(if (memq dir '(up down))
|
|
|
|
(org-rematch-and-replace 2 (eq dir 'up) (match-end 3))
|
|
|
|
(org-rematch-and-replace 5 (eq dir 'left))))))
|
|
|
|
|
|
|
|
(defun org-rematch-and-replace (n &optional decr hline)
|
2010-07-17 14:53:36 -04:00
|
|
|
"Re-match the group N, and replace it with the shifted reference."
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(or (match-end n) (user-error "Cannot shift reference in this direction"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(goto-char (match-beginning n))
|
|
|
|
(and (looking-at (regexp-quote (match-string n)))
|
2008-12-05 07:19:36 -05:00
|
|
|
(replace-match (org-table-shift-refpart (match-string 0) decr hline)
|
2008-03-22 11:52:18 -04:00
|
|
|
t t)))
|
|
|
|
|
2008-12-05 07:19:36 -05:00
|
|
|
(defun org-table-shift-refpart (ref &optional decr hline)
|
2010-07-17 14:53:36 -04:00
|
|
|
"Shift a reference part REF.
|
2008-03-22 11:52:18 -04:00
|
|
|
If DECR is set, decrease the references row/column, else increase.
|
|
|
|
If HLINE is set, this may be a hline reference, it certainly is not
|
|
|
|
a translation reference."
|
|
|
|
(save-match-data
|
|
|
|
(let* ((sign (string-match "^[-+]" ref)) n)
|
|
|
|
|
|
|
|
(if sign (setq sign (substring ref 0 1) ref (substring ref 1)))
|
|
|
|
(cond
|
|
|
|
((and hline (string-match "^I+" ref))
|
|
|
|
(setq n (string-to-number (concat sign (number-to-string (length ref)))))
|
|
|
|
(setq n (+ n (if decr -1 1)))
|
|
|
|
(if (= n 0) (setq n (+ n (if decr -1 1))))
|
|
|
|
(if sign
|
|
|
|
(setq sign (if (< n 0) "-" "+") n (abs n))
|
|
|
|
(setq n (max 1 n)))
|
|
|
|
(concat sign (make-string n ?I)))
|
|
|
|
|
|
|
|
((string-match "^[0-9]+" ref)
|
|
|
|
(setq n (string-to-number (concat sign ref)))
|
|
|
|
(setq n (+ n (if decr -1 1)))
|
|
|
|
(if sign
|
|
|
|
(concat (if (< n 0) "-" "+") (number-to-string (abs n)))
|
|
|
|
(number-to-string (max 1 n))))
|
|
|
|
|
|
|
|
((string-match "^[a-zA-Z]+" ref)
|
|
|
|
(org-number-to-letters
|
|
|
|
(max 1 (+ (org-letters-to-number ref) (if decr -1 1)))))
|
|
|
|
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(t (user-error "Cannot shift reference"))))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defun org-table-fedit-toggle-coordinates ()
|
2008-12-16 11:49:26 -05:00
|
|
|
"Toggle the display of coordinates in the referenced table."
|
2008-03-22 11:52:18 -04:00
|
|
|
(interactive)
|
|
|
|
(let ((pos (marker-position org-pos)))
|
|
|
|
(with-current-buffer (marker-buffer org-pos)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char pos)
|
|
|
|
(org-table-toggle-coordinate-overlays)))))
|
|
|
|
|
|
|
|
(defun org-table-fedit-finish (&optional arg)
|
|
|
|
"Parse the buffer for formula definitions and install them.
|
|
|
|
With prefix ARG, apply the new formulas to the table."
|
|
|
|
(interactive "P")
|
|
|
|
(org-table-remove-rectangle-highlight)
|
|
|
|
(if org-table-use-standard-references
|
|
|
|
(progn
|
|
|
|
(org-table-fedit-convert-buffer 'org-table-convert-refs-to-rc)
|
|
|
|
(setq org-table-buffer-is-an nil)))
|
2009-09-03 02:07:58 -04:00
|
|
|
(let ((pos org-pos) (sel-win org-selected-window) eql var form)
|
2008-03-22 11:52:18 -04:00
|
|
|
(goto-char (point-min))
|
|
|
|
(while (re-search-forward
|
2011-03-08 08:49:53 -05:00
|
|
|
"^\\(@[-+I<>0-9.$@]+\\|@?[0-9]+\\|\\$\\([a-zA-Z0-9]+\\|[<>]+\\)\\) *= *\\(.*\\(\n[ \t]+.*$\\)*\\)"
|
2008-03-22 11:52:18 -04:00
|
|
|
nil t)
|
|
|
|
(setq var (if (match-end 2) (match-string 2) (match-string 1))
|
|
|
|
form (match-string 3))
|
|
|
|
(setq form (org-trim form))
|
|
|
|
(when (not (equal form ""))
|
|
|
|
(while (string-match "[ \t]*\n[ \t]*" form)
|
|
|
|
(setq form (replace-match " " t t form)))
|
|
|
|
(when (assoc var eql)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Double formulas for %s" var))
|
2008-03-22 11:52:18 -04:00
|
|
|
(push (cons var form) eql)))
|
|
|
|
(setq org-pos nil)
|
|
|
|
(set-window-configuration org-window-configuration)
|
2009-09-03 02:07:58 -04:00
|
|
|
(select-window sel-win)
|
2008-03-22 11:52:18 -04:00
|
|
|
(goto-char pos)
|
|
|
|
(unless (org-at-table-p)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Lost table position - cannot install formulas"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-store-formulas eql)
|
|
|
|
(move-marker pos nil)
|
|
|
|
(kill-buffer "*Edit Formulas*")
|
|
|
|
(if arg
|
|
|
|
(org-table-recalculate 'all)
|
|
|
|
(message "New formulas installed - press C-u C-c C-c to apply."))))
|
|
|
|
|
|
|
|
(defun org-table-fedit-abort ()
|
|
|
|
"Abort editing formulas, without installing the changes."
|
|
|
|
(interactive)
|
|
|
|
(org-table-remove-rectangle-highlight)
|
2009-09-03 02:07:58 -04:00
|
|
|
(let ((pos org-pos) (sel-win org-selected-window))
|
2008-03-22 11:52:18 -04:00
|
|
|
(set-window-configuration org-window-configuration)
|
2009-09-03 02:07:58 -04:00
|
|
|
(select-window sel-win)
|
2008-03-22 11:52:18 -04:00
|
|
|
(goto-char pos)
|
|
|
|
(move-marker pos nil)
|
|
|
|
(message "Formula editing aborted without installing changes")))
|
|
|
|
|
|
|
|
(defun org-table-fedit-lisp-indent ()
|
|
|
|
"Pretty-print and re-indent Lisp expressions in the Formula Editor."
|
|
|
|
(interactive)
|
|
|
|
(let ((pos (point)) beg end ind)
|
|
|
|
(beginning-of-line 1)
|
|
|
|
(cond
|
|
|
|
((looking-at "[ \t]")
|
|
|
|
(goto-char pos)
|
|
|
|
(call-interactively 'lisp-indent-line))
|
|
|
|
((looking-at "[$&@0-9a-zA-Z]+ *= *[^ \t\n']") (goto-char pos))
|
|
|
|
((not (fboundp 'pp-buffer))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Cannot pretty-print. Command `pp-buffer' is not available"))
|
2008-03-22 11:52:18 -04:00
|
|
|
((looking-at "[$&@0-9a-zA-Z]+ *= *'(")
|
|
|
|
(goto-char (- (match-end 0) 2))
|
|
|
|
(setq beg (point))
|
|
|
|
(setq ind (make-string (current-column) ?\ ))
|
|
|
|
(condition-case nil (forward-sexp 1)
|
|
|
|
(error
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Cannot pretty-print Lisp expression: Unbalanced parenthesis")))
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq end (point))
|
|
|
|
(save-restriction
|
|
|
|
(narrow-to-region beg end)
|
|
|
|
(if (eq last-command this-command)
|
|
|
|
(progn
|
|
|
|
(goto-char (point-min))
|
|
|
|
(setq this-command nil)
|
|
|
|
(while (re-search-forward "[ \t]*\n[ \t]*" nil t)
|
|
|
|
(replace-match " ")))
|
|
|
|
(pp-buffer)
|
|
|
|
(untabify (point-min) (point-max))
|
|
|
|
(goto-char (1+ (point-min)))
|
|
|
|
(while (re-search-forward "^." nil t)
|
|
|
|
(beginning-of-line 1)
|
|
|
|
(insert ind))
|
|
|
|
(goto-char (point-max))
|
2012-12-23 11:31:41 -05:00
|
|
|
(org-delete-backward-char 1)))
|
2008-03-22 11:52:18 -04:00
|
|
|
(goto-char beg))
|
|
|
|
(t nil))))
|
|
|
|
|
|
|
|
(defvar org-show-positions nil)
|
|
|
|
|
|
|
|
(defun org-table-show-reference (&optional local)
|
|
|
|
"Show the location/value of the $ expression at point."
|
|
|
|
(interactive)
|
|
|
|
(org-table-remove-rectangle-highlight)
|
|
|
|
(catch 'exit
|
|
|
|
(let ((pos (if local (point) org-pos))
|
2008-12-16 11:48:54 -05:00
|
|
|
(face2 'highlight)
|
|
|
|
(org-inhibit-highlight-removal t)
|
2008-03-22 11:52:18 -04:00
|
|
|
(win (selected-window))
|
|
|
|
(org-show-positions nil)
|
|
|
|
var name e what match dest)
|
|
|
|
(if local (org-table-get-specials))
|
|
|
|
(setq what (cond
|
2011-03-01 03:05:56 -05:00
|
|
|
((org-at-regexp-p "^@[0-9]+[ \t=]")
|
|
|
|
(setq match (concat (substring (match-string 0) 0 -1)
|
|
|
|
"$1.."
|
|
|
|
(substring (match-string 0) 0 -1)
|
|
|
|
"$100"))
|
|
|
|
'range)
|
2008-03-22 11:52:18 -04:00
|
|
|
((or (org-at-regexp-p org-table-range-regexp2)
|
|
|
|
(org-at-regexp-p org-table-translate-regexp)
|
|
|
|
(org-at-regexp-p org-table-range-regexp))
|
|
|
|
(setq match
|
|
|
|
(save-match-data
|
|
|
|
(org-table-convert-refs-to-rc (match-string 0))))
|
|
|
|
'range)
|
|
|
|
((org-at-regexp-p "\\$[a-zA-Z][a-zA-Z0-9]*") 'name)
|
|
|
|
((org-at-regexp-p "\\$[0-9]+") 'column)
|
|
|
|
((not local) nil)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(t (user-error "No reference at point")))
|
2008-03-22 11:52:18 -04:00
|
|
|
match (and what (or match (match-string 0))))
|
|
|
|
(when (and match (not (equal (match-beginning 0) (point-at-bol))))
|
|
|
|
(org-table-add-rectangle-overlay (match-beginning 0) (match-end 0)
|
|
|
|
'secondary-selection))
|
|
|
|
(org-add-hook 'before-change-functions
|
|
|
|
'org-table-remove-rectangle-highlight)
|
|
|
|
(if (eq what 'name) (setq var (substring match 1)))
|
|
|
|
(when (eq what 'range)
|
|
|
|
(or (equal (string-to-char match) ?@) (setq match (concat "@" match)))
|
|
|
|
(setq match (org-table-formula-substitute-names match)))
|
|
|
|
(unless local
|
|
|
|
(save-excursion
|
|
|
|
(end-of-line 1)
|
|
|
|
(re-search-backward "^\\S-" nil t)
|
|
|
|
(beginning-of-line 1)
|
|
|
|
(when (looking-at "\\(\\$[0-9a-zA-Z]+\\|@[0-9]+\\$[0-9]+\\|[a-zA-Z]+\\([0-9]+\\|&\\)\\) *=")
|
|
|
|
(setq dest
|
|
|
|
(save-match-data
|
|
|
|
(org-table-convert-refs-to-rc (match-string 1))))
|
|
|
|
(org-table-add-rectangle-overlay
|
|
|
|
(match-beginning 1) (match-end 1) face2))))
|
|
|
|
(if (and (markerp pos) (marker-buffer pos))
|
|
|
|
(if (get-buffer-window (marker-buffer pos))
|
|
|
|
(select-window (get-buffer-window (marker-buffer pos)))
|
|
|
|
(org-switch-to-buffer-other-window (get-buffer-window
|
2012-08-11 13:10:44 -04:00
|
|
|
(marker-buffer pos)))))
|
2008-03-22 11:52:18 -04:00
|
|
|
(goto-char pos)
|
|
|
|
(org-table-force-dataline)
|
|
|
|
(when dest
|
|
|
|
(setq name (substring dest 1))
|
|
|
|
(cond
|
|
|
|
((string-match "^\\$[a-zA-Z][a-zA-Z0-9]*" dest)
|
|
|
|
(setq e (assoc name org-table-named-field-locations))
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line (nth 1 e))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-goto-column (nth 2 e)))
|
|
|
|
((string-match "^@\\([0-9]+\\)\\$\\([0-9]+\\)" dest)
|
|
|
|
(let ((l (string-to-number (match-string 1 dest)))
|
|
|
|
(c (string-to-number (match-string 2 dest))))
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line (aref org-table-dlines l))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-goto-column c)))
|
|
|
|
(t (org-table-goto-column (string-to-number name))))
|
|
|
|
(move-marker pos (point))
|
|
|
|
(org-table-highlight-rectangle nil nil face2))
|
|
|
|
(cond
|
|
|
|
((equal dest match))
|
|
|
|
((not match))
|
|
|
|
((eq what 'range)
|
|
|
|
(condition-case nil
|
|
|
|
(save-excursion
|
|
|
|
(org-table-get-range match nil nil 'highlight))
|
|
|
|
(error nil)))
|
|
|
|
((setq e (assoc var org-table-named-field-locations))
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line (nth 1 e))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-goto-column (nth 2 e))
|
|
|
|
(org-table-highlight-rectangle (point) (point))
|
|
|
|
(message "Named field, column %d of line %d" (nth 2 e) (nth 1 e)))
|
|
|
|
((setq e (assoc var org-table-column-names))
|
|
|
|
(org-table-goto-column (string-to-number (cdr e)))
|
|
|
|
(org-table-highlight-rectangle (point) (point))
|
|
|
|
(goto-char (org-table-begin))
|
|
|
|
(if (re-search-forward (concat "^[ \t]*| *! *.*?| *\\(" var "\\) *|")
|
|
|
|
(org-table-end) t)
|
|
|
|
(progn
|
|
|
|
(goto-char (match-beginning 1))
|
|
|
|
(org-table-highlight-rectangle)
|
|
|
|
(message "Named column (column %s)" (cdr e)))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Column name not found")))
|
2008-03-22 11:52:18 -04:00
|
|
|
((eq what 'column)
|
|
|
|
;; column number
|
|
|
|
(org-table-goto-column (string-to-number (substring match 1)))
|
|
|
|
(org-table-highlight-rectangle (point) (point))
|
|
|
|
(message "Column %s" (substring match 1)))
|
|
|
|
((setq e (assoc var org-table-local-parameters))
|
|
|
|
(goto-char (org-table-begin))
|
|
|
|
(if (re-search-forward (concat "^[ \t]*| *\\$ *.*?| *\\(" var "=\\)") nil t)
|
|
|
|
(progn
|
|
|
|
(goto-char (match-beginning 1))
|
|
|
|
(org-table-highlight-rectangle)
|
|
|
|
(message "Local parameter."))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Parameter not found")))
|
2008-03-22 11:52:18 -04:00
|
|
|
(t
|
|
|
|
(cond
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
((not var) (user-error "No reference at point"))
|
2008-03-22 11:52:18 -04:00
|
|
|
((setq e (assoc var org-table-formula-constants-local))
|
|
|
|
(message "Local Constant: $%s=%s in #+CONSTANTS line."
|
|
|
|
var (cdr e)))
|
|
|
|
((setq e (assoc var org-table-formula-constants))
|
|
|
|
(message "Constant: $%s=%s in `org-table-formula-constants'."
|
|
|
|
var (cdr e)))
|
|
|
|
((setq e (and (fboundp 'constants-get) (constants-get var)))
|
|
|
|
(message "Constant: $%s=%s, from `constants.el'%s."
|
|
|
|
var e (format " (%s units)" constants-unit-system)))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(t (user-error "Undefined name $%s" var)))))
|
2008-03-22 11:52:18 -04:00
|
|
|
(goto-char pos)
|
|
|
|
(when (and org-show-positions
|
2008-12-16 11:48:54 -05:00
|
|
|
(not (memq this-command '(org-table-fedit-scroll
|
|
|
|
org-table-fedit-scroll-down))))
|
2008-03-22 11:52:18 -04:00
|
|
|
(push pos org-show-positions)
|
|
|
|
(push org-table-current-begin-pos org-show-positions)
|
|
|
|
(let ((min (apply 'min org-show-positions))
|
|
|
|
(max (apply 'max org-show-positions)))
|
2014-07-22 17:11:36 -04:00
|
|
|
(set-window-start (selected-window) min)
|
2008-12-16 11:48:54 -05:00
|
|
|
(goto-char max)
|
2014-06-12 06:04:24 -04:00
|
|
|
(or (pos-visible-in-window-p max)
|
2014-07-22 17:11:36 -04:00
|
|
|
(set-window-start (selected-window) max))))
|
2008-03-22 11:52:18 -04:00
|
|
|
(select-window win))))
|
|
|
|
|
|
|
|
(defun org-table-force-dataline ()
|
|
|
|
"Make sure the cursor is in a dataline in a table."
|
|
|
|
(unless (save-excursion
|
|
|
|
(beginning-of-line 1)
|
|
|
|
(looking-at org-table-dataline-regexp))
|
|
|
|
(let* ((re org-table-dataline-regexp)
|
|
|
|
(p1 (save-excursion (re-search-forward re nil 'move)))
|
|
|
|
(p2 (save-excursion (re-search-backward re nil 'move))))
|
|
|
|
(cond ((and p1 p2)
|
|
|
|
(goto-char (if (< (abs (- p1 (point))) (abs (- p2 (point))))
|
|
|
|
p1 p2)))
|
|
|
|
((or p1 p2) (goto-char (or p1 p2)))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(t (user-error "No table dataline around here"))))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defun org-table-fedit-line-up ()
|
|
|
|
"Move cursor one line up in the window showing the table."
|
|
|
|
(interactive)
|
|
|
|
(org-table-fedit-move 'previous-line))
|
|
|
|
|
|
|
|
(defun org-table-fedit-line-down ()
|
|
|
|
"Move cursor one line down in the window showing the table."
|
|
|
|
(interactive)
|
|
|
|
(org-table-fedit-move 'next-line))
|
|
|
|
|
|
|
|
(defun org-table-fedit-move (command)
|
2008-12-16 11:49:26 -05:00
|
|
|
"Move the cursor in the window showing the table.
|
2008-03-22 11:52:18 -04:00
|
|
|
Use COMMAND to do the motion, repeat if necessary to end up in a data line."
|
|
|
|
(let ((org-table-allow-automatic-line-recalculation nil)
|
|
|
|
(pos org-pos) (win (selected-window)) p)
|
|
|
|
(select-window (get-buffer-window (marker-buffer org-pos)))
|
|
|
|
(setq p (point))
|
|
|
|
(call-interactively command)
|
|
|
|
(while (and (org-at-table-p)
|
|
|
|
(org-at-table-hline-p))
|
|
|
|
(call-interactively command))
|
|
|
|
(or (org-at-table-p) (goto-char p))
|
|
|
|
(move-marker pos (point))
|
|
|
|
(select-window win)))
|
|
|
|
|
|
|
|
(defun org-table-fedit-scroll (N)
|
|
|
|
(interactive "p")
|
|
|
|
(let ((other-window-scroll-buffer (marker-buffer org-pos)))
|
|
|
|
(scroll-other-window N)))
|
|
|
|
|
|
|
|
(defun org-table-fedit-scroll-down (N)
|
|
|
|
(interactive "p")
|
|
|
|
(org-table-fedit-scroll (- N)))
|
|
|
|
|
|
|
|
(defvar org-table-rectangle-overlays nil)
|
|
|
|
|
|
|
|
(defun org-table-add-rectangle-overlay (beg end &optional face)
|
|
|
|
"Add a new overlay."
|
2010-04-18 10:37:42 -04:00
|
|
|
(let ((ov (make-overlay beg end)))
|
|
|
|
(overlay-put ov 'face (or face 'secondary-selection))
|
2008-03-22 11:52:18 -04:00
|
|
|
(push ov org-table-rectangle-overlays)))
|
|
|
|
|
|
|
|
(defun org-table-highlight-rectangle (&optional beg end face)
|
|
|
|
"Highlight rectangular region in a table."
|
|
|
|
(setq beg (or beg (point)) end (or end (point)))
|
|
|
|
(let ((b (min beg end))
|
|
|
|
(e (max beg end))
|
|
|
|
l1 c1 l2 c2 tmp)
|
|
|
|
(and (boundp 'org-show-positions)
|
|
|
|
(setq org-show-positions (cons b (cons e org-show-positions))))
|
|
|
|
(goto-char (min beg end))
|
|
|
|
(setq l1 (org-current-line)
|
|
|
|
c1 (org-table-current-column))
|
|
|
|
(goto-char (max beg end))
|
|
|
|
(setq l2 (org-current-line)
|
|
|
|
c2 (org-table-current-column))
|
|
|
|
(if (> c1 c2) (setq tmp c1 c1 c2 c2 tmp))
|
2009-08-27 04:24:09 -04:00
|
|
|
(org-goto-line l1)
|
2008-03-22 11:52:18 -04:00
|
|
|
(beginning-of-line 1)
|
|
|
|
(loop for line from l1 to l2 do
|
|
|
|
(when (looking-at org-table-dataline-regexp)
|
|
|
|
(org-table-goto-column c1)
|
|
|
|
(skip-chars-backward "^|\n") (setq beg (point))
|
|
|
|
(org-table-goto-column c2)
|
|
|
|
(skip-chars-forward "^|\n") (setq end (point))
|
|
|
|
(org-table-add-rectangle-overlay beg end face))
|
|
|
|
(beginning-of-line 2))
|
|
|
|
(goto-char b))
|
|
|
|
(add-hook 'before-change-functions 'org-table-remove-rectangle-highlight))
|
|
|
|
|
|
|
|
(defun org-table-remove-rectangle-highlight (&rest ignore)
|
|
|
|
"Remove the rectangle overlays."
|
|
|
|
(unless org-inhibit-highlight-removal
|
|
|
|
(remove-hook 'before-change-functions 'org-table-remove-rectangle-highlight)
|
2010-04-18 10:37:42 -04:00
|
|
|
(mapc 'delete-overlay org-table-rectangle-overlays)
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq org-table-rectangle-overlays nil)))
|
|
|
|
|
|
|
|
(defvar org-table-coordinate-overlays nil
|
2008-12-16 11:49:26 -05:00
|
|
|
"Collects the coordinate grid overlays, so that they can be removed.")
|
2008-03-22 11:52:18 -04:00
|
|
|
(make-variable-buffer-local 'org-table-coordinate-overlays)
|
|
|
|
|
|
|
|
(defun org-table-overlay-coordinates ()
|
|
|
|
"Add overlays to the table at point, to show row/column coordinates."
|
|
|
|
(interactive)
|
2010-04-18 10:37:42 -04:00
|
|
|
(mapc 'delete-overlay org-table-coordinate-overlays)
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq org-table-coordinate-overlays nil)
|
|
|
|
(save-excursion
|
|
|
|
(let ((id 0) (ih 0) hline eol s1 s2 str ic ov beg)
|
|
|
|
(goto-char (org-table-begin))
|
|
|
|
(while (org-at-table-p)
|
|
|
|
(setq eol (point-at-eol))
|
2010-04-18 10:37:42 -04:00
|
|
|
(setq ov (make-overlay (point-at-bol) (1+ (point-at-bol))))
|
2008-03-22 11:52:18 -04:00
|
|
|
(push ov org-table-coordinate-overlays)
|
|
|
|
(setq hline (looking-at org-table-hline-regexp))
|
|
|
|
(setq str (if hline (format "I*%-2d" (setq ih (1+ ih)))
|
|
|
|
(format "%4d" (setq id (1+ id)))))
|
|
|
|
(org-overlay-before-string ov str 'org-special-keyword 'evaporate)
|
|
|
|
(when hline
|
|
|
|
(setq ic 0)
|
|
|
|
(while (re-search-forward "[+|]\\(-+\\)" eol t)
|
|
|
|
(setq beg (1+ (match-beginning 0))
|
|
|
|
ic (1+ ic)
|
|
|
|
s1 (concat "$" (int-to-string ic))
|
|
|
|
s2 (org-number-to-letters ic)
|
|
|
|
str (if (eq org-table-use-standard-references t) s2 s1))
|
2010-04-18 10:37:42 -04:00
|
|
|
(setq ov (make-overlay beg (+ beg (length str))))
|
2008-03-22 11:52:18 -04:00
|
|
|
(push ov org-table-coordinate-overlays)
|
|
|
|
(org-overlay-display ov str 'org-special-keyword 'evaporate)))
|
|
|
|
(beginning-of-line 2)))))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-toggle-coordinate-overlays ()
|
|
|
|
"Toggle the display of Row/Column numbers in tables."
|
|
|
|
(interactive)
|
|
|
|
(setq org-table-overlay-coordinates (not org-table-overlay-coordinates))
|
2012-08-21 14:09:25 -04:00
|
|
|
(message "Tables Row/Column numbers display turned %s"
|
2008-03-22 11:52:18 -04:00
|
|
|
(if org-table-overlay-coordinates "on" "off"))
|
|
|
|
(if (and (org-at-table-p) org-table-overlay-coordinates)
|
|
|
|
(org-table-align))
|
|
|
|
(unless org-table-overlay-coordinates
|
2010-04-18 10:37:42 -04:00
|
|
|
(mapc 'delete-overlay org-table-coordinate-overlays)
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq org-table-coordinate-overlays nil)))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun org-table-toggle-formula-debugger ()
|
|
|
|
"Toggle the formula debugger in tables."
|
|
|
|
(interactive)
|
|
|
|
(setq org-table-formula-debug (not org-table-formula-debug))
|
|
|
|
(message "Formula debugging has been turned %s"
|
|
|
|
(if org-table-formula-debug "on" "off")))
|
|
|
|
|
|
|
|
;;; The orgtbl minor mode
|
|
|
|
|
|
|
|
;; Define a minor mode which can be used in other modes in order to
|
|
|
|
;; integrate the org-mode table editor.
|
|
|
|
|
|
|
|
;; This is really a hack, because the org-mode table editor uses several
|
|
|
|
;; keys which normally belong to the major mode, for example the TAB and
|
|
|
|
;; RET keys. Here is how it works: The minor mode defines all the keys
|
|
|
|
;; necessary to operate the table editor, but wraps the commands into a
|
|
|
|
;; function which tests if the cursor is currently inside a table. If that
|
|
|
|
;; is the case, the table editor command is executed. However, when any of
|
|
|
|
;; those keys is used outside a table, the function uses `key-binding' to
|
|
|
|
;; look up if the key has an associated command in another currently active
|
|
|
|
;; keymap (minor modes, major mode, global), and executes that command.
|
|
|
|
;; There might be problems if any of the keys used by the table editor is
|
|
|
|
;; otherwise used as a prefix key.
|
|
|
|
|
|
|
|
;; Another challenge is that the key binding for TAB can be tab or \C-i,
|
|
|
|
;; likewise the binding for RET can be return or \C-m. Orgtbl-mode
|
|
|
|
;; addresses this by checking explicitly for both bindings.
|
|
|
|
|
|
|
|
;; The optimized version (see variable `orgtbl-optimized') takes over
|
|
|
|
;; all keys which are bound to `self-insert-command' in the *global map*.
|
|
|
|
;; Some modes bind other commands to simple characters, for example
|
|
|
|
;; AUCTeX binds the double quote to `Tex-insert-quote'. With orgtbl-mode
|
|
|
|
;; active, this binding is ignored inside tables and replaced with a
|
|
|
|
;; modified self-insert.
|
|
|
|
|
|
|
|
|
|
|
|
(defvar orgtbl-mode-map (make-keymap)
|
|
|
|
"Keymap for `orgtbl-mode'.")
|
|
|
|
|
|
|
|
(defvar org-old-auto-fill-inhibit-regexp nil
|
2010-07-17 14:53:36 -04:00
|
|
|
"Local variable used by `orgtbl-mode'.")
|
2008-03-22 11:52:18 -04:00
|
|
|
|
2009-09-15 09:11:21 -04:00
|
|
|
(defconst orgtbl-line-start-regexp
|
2012-04-21 09:36:04 -04:00
|
|
|
"[ \t]*\\(|\\|#\\+\\(tblfm\\|orgtbl\\|tblname\\):\\)"
|
2008-03-22 11:52:18 -04:00
|
|
|
"Matches a line belonging to an orgtbl.")
|
|
|
|
|
|
|
|
(defconst orgtbl-extra-font-lock-keywords
|
|
|
|
(list (list (concat "^" orgtbl-line-start-regexp ".*")
|
|
|
|
0 (quote 'org-table) 'prepend))
|
2010-07-17 14:53:36 -04:00
|
|
|
"Extra `font-lock-keywords' to be added when `orgtbl-mode' is active.")
|
2008-03-22 11:52:18 -04:00
|
|
|
|
2010-05-16 10:18:23 -04:00
|
|
|
;; Install it as a minor mode.
|
|
|
|
(put 'orgtbl-mode :included t)
|
|
|
|
(put 'orgtbl-mode :menu-tag "Org Table Mode")
|
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
;;;###autoload
|
2010-05-16 10:18:23 -04:00
|
|
|
(define-minor-mode orgtbl-mode
|
2008-03-22 11:52:18 -04:00
|
|
|
"The `org-mode' table editor as a minor mode for use in other modes."
|
2010-05-16 10:18:23 -04:00
|
|
|
:lighter " OrgTbl" :keymap orgtbl-mode-map
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-load-modules-maybe)
|
2010-05-16 10:18:23 -04:00
|
|
|
(cond
|
Use (derived-mode-p 'org-mode) instead of (eq major-mode 'org-mode).
* org.el (org-show-hierarchy-above, org-cycle)
(org-global-cycle, org-files-list, org-store-link)
(org-link-search, org-open-file, org-display-outline-path)
(org-refile-get-location, org-update-all-dblocks)
(org-change-tag-in-region, org-entry-properties)
(org-save-all-org-buffers, org-revert-all-org-buffers)
(org-buffer-list, org-cdlatex-mode)
(org-install-agenda-files-menu, org-end-of-subtree)
(org-speedbar-set-agenda-restriction): Use (derived-mode-p
'org-mode) instead of (eq major-mode 'org-mode).
* org-timer.el (org-timer-set-timer): Ditto.
* org-table.el (orgtbl-mode, org-table-align, orgtbl-mode): Ditto.
* org-src.el (org-edit-src-exit, org-edit-src-code)
(org-edit-fixed-width-region, org-edit-src-exit): Ditto.
* org-remember.el (org-remember-handler): Ditto.
* org-mouse.el (dnd-open-file, org-mouse-insert-item): Ditto.
* org-macs.el (org-get-limited-outline-regexp): Ditto.
* org-lparse.el (org-replace-region-by): Ditto.
* org-latex.el (org-latex-to-pdf-process)
(org-replace-region-by-latex): Ditto.
* org-indent.el (org-indent-indent-buffer): Ditto.
* org-id.el (org-id-store-link, org-id-update-id-locations)
(org-id-store-link): Ditto.
* org-html.el (org-export-html-preprocess)
(org-replace-region-by-html): Ditto.
* org-footnote.el (org-footnote-normalize)
(org-footnote-goto-definition)
(org-footnote-create-definition, org-footnote-normalize): Ditto.
* org-docbook.el (org-replace-region-by-docbook): Ditto.
* org-ctags.el (find-tag): Ditto.
* org-colview.el (org-columns-redo)
(org-columns-display-here, org-columns-edit-value)
(org-columns-redo): Ditto.
* org-colview-xemacs.el (org-columns-redo)
(org-columns-display-here, org-columns-edit-value)
(org-columns-redo): Ditto.
* org-capture.el (org-capture-insert-template-here)
(org-capture, org-capture-finalize)
(org-capture-set-target-location)
(org-capture-insert-template-here): Ditto.
* org-ascii.el (org-replace-region-by-ascii): Ditto.
* org-archive.el (org-archive-subtree): Ditto.
* org-agenda.el (org-agenda)
(org-agenda-get-restriction-and-command)
(org-agenda-get-some-entry-text, org-search-view)
(org-tags-view, org-agenda-get-day-entries)
(org-agenda-format-item, org-agenda-goto, org-agenda-kill)
(org-agenda-archive-with, org-agenda-switch-to): Ditto.
2012-04-20 14:03:45 -04:00
|
|
|
((derived-mode-p 'org-mode)
|
2010-05-16 10:18:23 -04:00
|
|
|
;; Exit without error, in case some hook functions calls this
|
|
|
|
;; by accident in org-mode.
|
|
|
|
(message "Orgtbl-mode is not useful in org-mode, command ignored"))
|
|
|
|
(orgtbl-mode
|
|
|
|
(and (orgtbl-setup) (defun orgtbl-setup () nil)) ;; FIXME: Yuck!?!
|
|
|
|
;; Make sure we are first in minor-mode-map-alist
|
|
|
|
(let ((c (assq 'orgtbl-mode minor-mode-map-alist)))
|
|
|
|
;; FIXME: maybe it should use emulation-mode-map-alists?
|
|
|
|
(and c (setq minor-mode-map-alist
|
|
|
|
(cons c (delq c minor-mode-map-alist)))))
|
|
|
|
(org-set-local (quote org-table-may-need-update) t)
|
|
|
|
(org-add-hook 'before-change-functions 'org-before-change-function
|
|
|
|
nil 'local)
|
|
|
|
(org-set-local 'org-old-auto-fill-inhibit-regexp
|
|
|
|
auto-fill-inhibit-regexp)
|
|
|
|
(org-set-local 'auto-fill-inhibit-regexp
|
|
|
|
(if auto-fill-inhibit-regexp
|
|
|
|
(concat orgtbl-line-start-regexp "\\|"
|
|
|
|
auto-fill-inhibit-regexp)
|
|
|
|
orgtbl-line-start-regexp))
|
2010-05-16 10:24:16 -04:00
|
|
|
(add-to-invisibility-spec '(org-cwidth))
|
2010-05-16 10:18:23 -04:00
|
|
|
(when (fboundp 'font-lock-add-keywords)
|
|
|
|
(font-lock-add-keywords nil orgtbl-extra-font-lock-keywords)
|
|
|
|
(org-restart-font-lock))
|
|
|
|
(easy-menu-add orgtbl-mode-menu))
|
|
|
|
(t
|
|
|
|
(setq auto-fill-inhibit-regexp org-old-auto-fill-inhibit-regexp)
|
|
|
|
(org-table-cleanup-narrow-column-properties)
|
|
|
|
(org-remove-from-invisibility-spec '(org-cwidth))
|
|
|
|
(remove-hook 'before-change-functions 'org-before-change-function t)
|
|
|
|
(when (fboundp 'font-lock-remove-keywords)
|
|
|
|
(font-lock-remove-keywords nil orgtbl-extra-font-lock-keywords)
|
|
|
|
(org-restart-font-lock))
|
|
|
|
(easy-menu-remove orgtbl-mode-menu)
|
|
|
|
(force-mode-line-update 'all))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
2008-12-05 07:19:36 -05:00
|
|
|
(defun org-table-cleanup-narrow-column-properties ()
|
2008-03-22 11:52:18 -04:00
|
|
|
"Remove all properties related to narrow-column invisibility."
|
2011-04-09 08:46:45 -04:00
|
|
|
(let ((s (point-min)))
|
2008-03-22 11:52:18 -04:00
|
|
|
(while (setq s (text-property-any s (point-max)
|
|
|
|
'display org-narrow-column-arrow))
|
|
|
|
(remove-text-properties s (1+ s) '(display t)))
|
2011-04-09 08:46:45 -04:00
|
|
|
(setq s (point-min))
|
2008-03-22 11:52:18 -04:00
|
|
|
(while (setq s (text-property-any s (point-max) 'org-cwidth 1))
|
|
|
|
(remove-text-properties s (1+ s) '(org-cwidth t)))
|
2011-04-09 08:46:45 -04:00
|
|
|
(setq s (point-min))
|
2008-03-22 11:52:18 -04:00
|
|
|
(while (setq s (text-property-any s (point-max) 'invisible 'org-cwidth))
|
|
|
|
(remove-text-properties s (1+ s) '(invisible t)))))
|
|
|
|
|
|
|
|
(defun orgtbl-make-binding (fun n &rest keys)
|
|
|
|
"Create a function for binding in the table minor mode.
|
|
|
|
FUN is the command to call inside a table. N is used to create a unique
|
|
|
|
command name. KEYS are keys that should be checked in for a command
|
|
|
|
to execute outside of tables."
|
|
|
|
(eval
|
|
|
|
(list 'defun
|
|
|
|
(intern (concat "orgtbl-hijacker-command-" (int-to-string n)))
|
|
|
|
'(arg)
|
|
|
|
(concat "In tables, run `" (symbol-name fun) "'.\n"
|
|
|
|
"Outside of tables, run the binding of `"
|
2013-11-12 03:02:23 -05:00
|
|
|
(mapconcat #'key-description keys "' or `")
|
2008-03-22 11:52:18 -04:00
|
|
|
"'.")
|
|
|
|
'(interactive "p")
|
|
|
|
(list 'if
|
|
|
|
'(org-at-table-p)
|
|
|
|
(list 'call-interactively (list 'quote fun))
|
|
|
|
(list 'let '(orgtbl-mode)
|
|
|
|
(list 'call-interactively
|
|
|
|
(append '(or)
|
|
|
|
(mapcar (lambda (k)
|
|
|
|
(list 'key-binding k))
|
|
|
|
keys)
|
|
|
|
'('orgtbl-error))))))))
|
|
|
|
|
|
|
|
(defun orgtbl-error ()
|
|
|
|
"Error when there is no default binding for a table key."
|
|
|
|
(interactive)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "This key has no function outside tables"))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defun orgtbl-setup ()
|
|
|
|
"Setup orgtbl keymaps."
|
|
|
|
(let ((nfunc 0)
|
|
|
|
(bindings
|
2010-05-16 10:18:23 -04:00
|
|
|
'(([(meta shift left)] org-table-delete-column)
|
|
|
|
([(meta left)] org-table-move-column-left)
|
|
|
|
([(meta right)] org-table-move-column-right)
|
|
|
|
([(meta shift right)] org-table-insert-column)
|
|
|
|
([(meta shift up)] org-table-kill-row)
|
|
|
|
([(meta shift down)] org-table-insert-row)
|
|
|
|
([(meta up)] org-table-move-row-up)
|
|
|
|
([(meta down)] org-table-move-row-down)
|
|
|
|
("\C-c\C-w" org-table-cut-region)
|
|
|
|
("\C-c\M-w" org-table-copy-region)
|
|
|
|
("\C-c\C-y" org-table-paste-rectangle)
|
2011-12-09 17:22:56 -05:00
|
|
|
("\C-c\C-w" org-table-wrap-region)
|
2010-05-16 10:18:23 -04:00
|
|
|
("\C-c-" org-table-insert-hline)
|
|
|
|
("\C-c}" org-table-toggle-coordinate-overlays)
|
|
|
|
("\C-c{" org-table-toggle-formula-debugger)
|
|
|
|
("\C-m" org-table-next-row)
|
|
|
|
([(shift return)] org-table-copy-down)
|
|
|
|
("\C-c?" org-table-field-info)
|
|
|
|
("\C-c " org-table-blank-field)
|
|
|
|
("\C-c+" org-table-sum)
|
|
|
|
("\C-c=" org-table-eval-formula)
|
|
|
|
("\C-c'" org-table-edit-formulas)
|
|
|
|
("\C-c`" org-table-edit-field)
|
|
|
|
("\C-c*" org-table-recalculate)
|
|
|
|
("\C-c^" org-table-sort-lines)
|
|
|
|
("\M-a" org-table-beginning-of-field)
|
|
|
|
("\M-e" org-table-end-of-field)
|
|
|
|
([(control ?#)] org-table-rotate-recalc-marks)))
|
2008-03-22 11:52:18 -04:00
|
|
|
elt key fun cmd)
|
|
|
|
(while (setq elt (pop bindings))
|
|
|
|
(setq nfunc (1+ nfunc))
|
|
|
|
(setq key (org-key (car elt))
|
|
|
|
fun (nth 1 elt)
|
|
|
|
cmd (orgtbl-make-binding fun nfunc key))
|
|
|
|
(org-defkey orgtbl-mode-map key cmd))
|
|
|
|
|
|
|
|
;; Special treatment needed for TAB and RET
|
|
|
|
(org-defkey orgtbl-mode-map [(return)]
|
2012-08-11 13:10:44 -04:00
|
|
|
(orgtbl-make-binding 'orgtbl-ret 100 [(return)] "\C-m"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-defkey orgtbl-mode-map "\C-m"
|
2012-08-11 13:10:44 -04:00
|
|
|
(orgtbl-make-binding 'orgtbl-ret 101 "\C-m" [(return)]))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(org-defkey orgtbl-mode-map [(tab)]
|
2012-08-11 13:10:44 -04:00
|
|
|
(orgtbl-make-binding 'orgtbl-tab 102 [(tab)] "\C-i"))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-defkey orgtbl-mode-map "\C-i"
|
2012-08-11 13:10:44 -04:00
|
|
|
(orgtbl-make-binding 'orgtbl-tab 103 "\C-i" [(tab)]))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(org-defkey orgtbl-mode-map [(shift tab)]
|
2012-08-11 13:10:44 -04:00
|
|
|
(orgtbl-make-binding 'org-table-previous-field 104
|
|
|
|
[(shift tab)] [(tab)] "\C-i"))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
2009-11-12 05:23:23 -05:00
|
|
|
|
|
|
|
(unless (featurep 'xemacs)
|
|
|
|
(org-defkey orgtbl-mode-map [S-iso-lefttab]
|
2012-08-11 13:10:44 -04:00
|
|
|
(orgtbl-make-binding 'org-table-previous-field 107
|
|
|
|
[S-iso-lefttab] [backtab] [(shift tab)]
|
|
|
|
[(tab)] "\C-i")))
|
2009-06-19 11:46:27 -04:00
|
|
|
|
|
|
|
(org-defkey orgtbl-mode-map [backtab]
|
2012-08-11 13:10:44 -04:00
|
|
|
(orgtbl-make-binding 'org-table-previous-field 108
|
|
|
|
[backtab] [S-iso-lefttab] [(shift tab)]
|
|
|
|
[(tab)] "\C-i"))
|
2009-06-19 11:46:27 -04:00
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-defkey orgtbl-mode-map "\M-\C-m"
|
2012-08-11 13:10:44 -04:00
|
|
|
(orgtbl-make-binding 'org-table-wrap-region 105
|
|
|
|
"\M-\C-m" [(meta return)]))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-defkey orgtbl-mode-map [(meta return)]
|
2012-08-11 13:10:44 -04:00
|
|
|
(orgtbl-make-binding 'org-table-wrap-region 106
|
|
|
|
[(meta return)] "\M-\C-m"))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(org-defkey orgtbl-mode-map "\C-c\C-c" 'orgtbl-ctrl-c-ctrl-c)
|
2008-11-26 03:14:09 -05:00
|
|
|
(org-defkey orgtbl-mode-map "\C-c|" 'orgtbl-create-or-convert-from-region)
|
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
(when orgtbl-optimized
|
|
|
|
;; If the user wants maximum table support, we need to hijack
|
|
|
|
;; some standard editing functions
|
|
|
|
(org-remap orgtbl-mode-map
|
|
|
|
'self-insert-command 'orgtbl-self-insert-command
|
|
|
|
'delete-char 'org-delete-char
|
|
|
|
'delete-backward-char 'org-delete-backward-char)
|
|
|
|
(org-defkey orgtbl-mode-map "|" 'org-force-self-insert))
|
|
|
|
(easy-menu-define orgtbl-mode-menu orgtbl-mode-map "OrgTbl menu"
|
|
|
|
'("OrgTbl"
|
2008-11-26 03:14:09 -05:00
|
|
|
["Create or convert" org-table-create-or-convert-from-region
|
|
|
|
:active (not (org-at-table-p)) :keys "C-c |" ]
|
|
|
|
"--"
|
2008-03-22 11:52:18 -04:00
|
|
|
["Align" org-ctrl-c-ctrl-c :active (org-at-table-p) :keys "C-c C-c"]
|
|
|
|
["Next Field" org-cycle :active (org-at-table-p) :keys "TAB"]
|
|
|
|
["Previous Field" org-shifttab :active (org-at-table-p) :keys "S-TAB"]
|
|
|
|
["Next Row" org-return :active (org-at-table-p) :keys "RET"]
|
|
|
|
"--"
|
|
|
|
["Blank Field" org-table-blank-field :active (org-at-table-p) :keys "C-c SPC"]
|
|
|
|
["Edit Field" org-table-edit-field :active (org-at-table-p) :keys "C-c ` "]
|
|
|
|
["Copy Field from Above"
|
|
|
|
org-table-copy-down :active (org-at-table-p) :keys "S-RET"]
|
|
|
|
"--"
|
|
|
|
("Column"
|
|
|
|
["Move Column Left" org-metaleft :active (org-at-table-p) :keys "M-<left>"]
|
|
|
|
["Move Column Right" org-metaright :active (org-at-table-p) :keys "M-<right>"]
|
|
|
|
["Delete Column" org-shiftmetaleft :active (org-at-table-p) :keys "M-S-<left>"]
|
2014-10-11 09:59:17 -04:00
|
|
|
["Insert Column" org-shiftmetaright :active (org-at-table-p) :keys "M-S-<right>"])
|
2008-03-22 11:52:18 -04:00
|
|
|
("Row"
|
|
|
|
["Move Row Up" org-metaup :active (org-at-table-p) :keys "M-<up>"]
|
|
|
|
["Move Row Down" org-metadown :active (org-at-table-p) :keys "M-<down>"]
|
|
|
|
["Delete Row" org-shiftmetaup :active (org-at-table-p) :keys "M-S-<up>"]
|
|
|
|
["Insert Row" org-shiftmetadown :active (org-at-table-p) :keys "M-S-<down>"]
|
|
|
|
["Sort lines in region" org-table-sort-lines :active (org-at-table-p) :keys "C-c ^"]
|
|
|
|
"--"
|
|
|
|
["Insert Hline" org-table-insert-hline :active (org-at-table-p) :keys "C-c -"])
|
|
|
|
("Rectangle"
|
|
|
|
["Copy Rectangle" org-copy-special :active (org-at-table-p)]
|
|
|
|
["Cut Rectangle" org-cut-special :active (org-at-table-p)]
|
|
|
|
["Paste Rectangle" org-paste-special :active (org-at-table-p)]
|
|
|
|
["Fill Rectangle" org-table-wrap-region :active (org-at-table-p)])
|
|
|
|
"--"
|
|
|
|
("Radio tables"
|
|
|
|
["Insert table template" orgtbl-insert-radio-table
|
|
|
|
(assq major-mode orgtbl-radio-table-templates)]
|
|
|
|
["Comment/uncomment table" orgtbl-toggle-comment t])
|
|
|
|
"--"
|
|
|
|
["Set Column Formula" org-table-eval-formula :active (org-at-table-p) :keys "C-c ="]
|
|
|
|
["Set Field Formula" (org-table-eval-formula '(4)) :active (org-at-table-p) :keys "C-u C-c ="]
|
|
|
|
["Edit Formulas" org-table-edit-formulas :active (org-at-table-p) :keys "C-c '"]
|
|
|
|
["Recalculate line" org-table-recalculate :active (org-at-table-p) :keys "C-c *"]
|
|
|
|
["Recalculate all" (org-table-recalculate '(4)) :active (org-at-table-p) :keys "C-u C-c *"]
|
|
|
|
["Iterate all" (org-table-recalculate '(16)) :active (org-at-table-p) :keys "C-u C-u C-c *"]
|
|
|
|
["Toggle Recalculate Mark" org-table-rotate-recalc-marks :active (org-at-table-p) :keys "C-c #"]
|
|
|
|
["Sum Column/Rectangle" org-table-sum
|
|
|
|
:active (or (org-at-table-p) (org-region-active-p)) :keys "C-c +"]
|
|
|
|
["Which Column?" org-table-current-column :active (org-at-table-p) :keys "C-c ?"]
|
|
|
|
["Debug Formulas"
|
|
|
|
org-table-toggle-formula-debugger :active (org-at-table-p)
|
|
|
|
:keys "C-c {"
|
|
|
|
:style toggle :selected org-table-formula-debug]
|
|
|
|
["Show Col/Row Numbers"
|
|
|
|
org-table-toggle-coordinate-overlays :active (org-at-table-p)
|
|
|
|
:keys "C-c }"
|
|
|
|
:style toggle :selected org-table-overlay-coordinates]
|
2014-10-11 09:59:17 -04:00
|
|
|
"--"
|
|
|
|
("Plot"
|
|
|
|
["Ascii plot" orgtbl-ascii-plot :active (org-at-table-p) :keys "C-c \" a"]
|
|
|
|
["Gnuplot" org-plot/gnuplot :active (org-at-table-p) :keys "C-c \" g"])))
|
2008-03-22 11:52:18 -04:00
|
|
|
t))
|
|
|
|
|
|
|
|
(defun orgtbl-ctrl-c-ctrl-c (arg)
|
|
|
|
"If the cursor is inside a table, realign the table.
|
2009-06-26 01:04:22 -04:00
|
|
|
If it is a table to be sent away to a receiver, do it.
|
2008-03-22 11:52:18 -04:00
|
|
|
With prefix arg, also recompute table."
|
|
|
|
(interactive "P")
|
2013-03-19 10:25:14 -04:00
|
|
|
(let ((case-fold-search t) (pos (point)) action)
|
2008-03-22 11:52:18 -04:00
|
|
|
(save-excursion
|
|
|
|
(beginning-of-line 1)
|
2010-12-12 07:22:11 -05:00
|
|
|
(setq action (cond
|
|
|
|
((looking-at "[ \t]*#\\+ORGTBL:.*\n[ \t]*|") (match-end 0))
|
|
|
|
((looking-at "[ \t]*|") pos)
|
2012-04-21 09:36:04 -04:00
|
|
|
((looking-at "[ \t]*#\\+tblfm:") 'recalc))))
|
2008-03-22 11:52:18 -04:00
|
|
|
(cond
|
|
|
|
((integerp action)
|
|
|
|
(goto-char action)
|
|
|
|
(org-table-maybe-eval-formula)
|
|
|
|
(if arg
|
|
|
|
(call-interactively 'org-table-recalculate)
|
|
|
|
(org-table-maybe-recalculate-line))
|
|
|
|
(call-interactively 'org-table-align)
|
2010-11-17 07:58:52 -05:00
|
|
|
(when (orgtbl-send-table 'maybe)
|
|
|
|
(run-hooks 'orgtbl-after-send-table-hook)))
|
2008-03-22 11:52:18 -04:00
|
|
|
((eq action 'recalc)
|
2013-03-19 10:25:14 -04:00
|
|
|
(org-table-set-constants)
|
2008-03-22 11:52:18 -04:00
|
|
|
(save-excursion
|
|
|
|
(beginning-of-line 1)
|
|
|
|
(skip-chars-backward " \r\n\t")
|
|
|
|
(if (org-at-table-p)
|
|
|
|
(org-call-with-arg 'org-table-recalculate t))))
|
|
|
|
(t (let (orgtbl-mode)
|
|
|
|
(call-interactively (key-binding "\C-c\C-c")))))))
|
|
|
|
|
2008-11-26 03:14:09 -05:00
|
|
|
(defun orgtbl-create-or-convert-from-region (arg)
|
|
|
|
"Create table or convert region to table, if no conflicting binding.
|
|
|
|
This installs the table binding `C-c |', but only if there is no
|
|
|
|
conflicting binding to this key outside orgtbl-mode."
|
|
|
|
(interactive "P")
|
|
|
|
(let* (orgtbl-mode (cmd (key-binding "\C-c|")))
|
|
|
|
(if cmd
|
|
|
|
(call-interactively cmd)
|
|
|
|
(call-interactively 'org-table-create-or-convert-from-region))))
|
2008-12-04 09:33:43 -05:00
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun orgtbl-tab (arg)
|
|
|
|
"Justification and field motion for `orgtbl-mode'."
|
|
|
|
(interactive "P")
|
|
|
|
(if arg (org-table-edit-field t)
|
|
|
|
(org-table-justify-field-maybe)
|
|
|
|
(org-table-next-field)))
|
|
|
|
|
|
|
|
(defun orgtbl-ret ()
|
|
|
|
"Justification and field motion for `orgtbl-mode'."
|
|
|
|
(interactive)
|
2008-11-24 16:45:56 -05:00
|
|
|
(if (bobp)
|
|
|
|
(newline)
|
|
|
|
(org-table-justify-field-maybe)
|
|
|
|
(org-table-next-row)))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defun orgtbl-self-insert-command (N)
|
|
|
|
"Like `self-insert-command', use overwrite-mode for whitespace in tables.
|
|
|
|
If the cursor is in a table looking at whitespace, the whitespace is
|
|
|
|
overwritten, and the table is not marked as requiring realignment."
|
|
|
|
(interactive "p")
|
|
|
|
(if (and (org-at-table-p)
|
|
|
|
(or
|
|
|
|
(and org-table-auto-blank-field
|
|
|
|
(member last-command
|
|
|
|
'(orgtbl-hijacker-command-100
|
|
|
|
orgtbl-hijacker-command-101
|
|
|
|
orgtbl-hijacker-command-102
|
|
|
|
orgtbl-hijacker-command-103
|
|
|
|
orgtbl-hijacker-command-104
|
2009-06-21 16:19:15 -04:00
|
|
|
orgtbl-hijacker-command-105
|
|
|
|
yas/expand))
|
2008-03-22 11:52:18 -04:00
|
|
|
(org-table-blank-field))
|
|
|
|
t)
|
|
|
|
(eq N 1)
|
|
|
|
(looking-at "[^|\n]* +|"))
|
|
|
|
(let (org-table-may-need-update)
|
|
|
|
(goto-char (1- (match-end 0)))
|
2012-12-23 11:31:41 -05:00
|
|
|
(org-delete-backward-char 1)
|
2008-03-22 11:52:18 -04:00
|
|
|
(goto-char (match-beginning 0))
|
|
|
|
(self-insert-command N))
|
|
|
|
(setq org-table-may-need-update t)
|
2009-02-25 06:43:24 -05:00
|
|
|
(let* (orgtbl-mode
|
|
|
|
a
|
|
|
|
(cmd (or (key-binding
|
|
|
|
(or (and (listp function-key-map)
|
|
|
|
(setq a (assoc last-input-event function-key-map))
|
|
|
|
(cdr a))
|
|
|
|
(vector last-input-event)))
|
2012-08-11 13:10:44 -04:00
|
|
|
'self-insert-command)))
|
2009-02-25 06:43:24 -05:00
|
|
|
(call-interactively cmd)
|
|
|
|
(if (and org-self-insert-cluster-for-undo
|
|
|
|
(eq cmd 'self-insert-command))
|
|
|
|
(if (not (eq last-command 'orgtbl-self-insert-command))
|
|
|
|
(setq org-self-insert-command-undo-counter 1)
|
|
|
|
(if (>= org-self-insert-command-undo-counter 20)
|
|
|
|
(setq org-self-insert-command-undo-counter 1)
|
|
|
|
(and (> org-self-insert-command-undo-counter 0)
|
|
|
|
buffer-undo-list
|
|
|
|
(not (cadr buffer-undo-list)) ; remove nil entry
|
|
|
|
(setcdr buffer-undo-list (cddr buffer-undo-list)))
|
|
|
|
(setq org-self-insert-command-undo-counter
|
|
|
|
(1+ org-self-insert-command-undo-counter))))))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defvar orgtbl-exp-regexp "^\\([-+]?[0-9][0-9.]*\\)[eE]\\([-+]?[0-9]+\\)$"
|
|
|
|
"Regular expression matching exponentials as produced by calc.")
|
|
|
|
|
2008-04-21 01:50:27 -04:00
|
|
|
(defun orgtbl-gather-send-defs ()
|
2010-07-17 14:53:36 -04:00
|
|
|
"Gather a plist of :name, :transform, :params for each destination before
|
2008-04-21 01:50:27 -04:00
|
|
|
a radio table."
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (org-table-begin))
|
|
|
|
(let (rtn)
|
|
|
|
(beginning-of-line 0)
|
2010-04-18 02:11:07 -04:00
|
|
|
(while (looking-at "[ \t]*#\\+ORGTBL[: \t][ \t]*SEND[ \t]+\\([^ \t\r\n]+\\)[ \t]+\\([^ \t\r\n]+\\)\\([ \t]+.*\\)?")
|
2008-04-21 01:50:27 -04:00
|
|
|
(let ((name (org-no-properties (match-string 1)))
|
|
|
|
(transform (intern (match-string 2)))
|
|
|
|
(params (if (match-end 3)
|
|
|
|
(read (concat "(" (match-string 3) ")")))))
|
|
|
|
(push (list :name name :transform transform :params params)
|
|
|
|
rtn)
|
|
|
|
(beginning-of-line 0)))
|
|
|
|
rtn)))
|
|
|
|
|
|
|
|
(defun orgtbl-send-replace-tbl (name txt)
|
|
|
|
"Find and replace table NAME with TXT."
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(unless (re-search-forward
|
2013-08-30 11:48:51 -04:00
|
|
|
(concat "BEGIN +RECEIVE +ORGTBL +" name "\\([ \t]\\|$\\)") nil t)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Don't know where to insert translated table"))
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
(let ((beg (line-beginning-position 2)))
|
|
|
|
(unless (re-search-forward
|
|
|
|
(concat "END +RECEIVE +ORGTBL +" name) nil t)
|
|
|
|
(user-error "Cannot find end of insertion region"))
|
|
|
|
(beginning-of-line)
|
|
|
|
(delete-region beg (point)))
|
2008-04-21 01:50:27 -04:00
|
|
|
(insert txt "\n")))
|
|
|
|
|
2008-09-03 03:10:17 -04:00
|
|
|
;;;###autoload
|
2008-07-17 13:08:53 -04:00
|
|
|
(defun org-table-to-lisp (&optional txt)
|
|
|
|
"Convert the table at point to a Lisp structure.
|
|
|
|
The structure will be a list. Each item is either the symbol `hline'
|
|
|
|
for a horizontal separator line, or a list of field values as strings.
|
|
|
|
The table is taken from the parameter TXT, or from the buffer at point."
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
(unless (or txt (org-at-table-p)) (user-error "No table at point"))
|
|
|
|
(let ((txt (or txt
|
|
|
|
(buffer-substring-no-properties (org-table-begin)
|
|
|
|
(org-table-end)))))
|
|
|
|
(mapcar (lambda (x)
|
|
|
|
(if (string-match org-table-hline-regexp x) 'hline
|
|
|
|
(org-split-string (org-trim x) "\\s-*|\\s-*")))
|
|
|
|
(org-split-string txt "[ \t]*\n[ \t]*"))))
|
2008-07-17 13:08:53 -04:00
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun orgtbl-send-table (&optional maybe)
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
"Send a transformed version of table at point to the receiver position.
|
|
|
|
With argument MAYBE, fail quietly if no transformation is defined
|
|
|
|
for this table."
|
2008-03-22 11:52:18 -04:00
|
|
|
(interactive)
|
|
|
|
(catch 'exit
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(unless (org-at-table-p) (user-error "Not at a table"))
|
2008-03-22 11:52:18 -04:00
|
|
|
;; when non-interactive, we assume align has just happened.
|
2011-06-29 18:25:09 -04:00
|
|
|
(when (org-called-interactively-p 'any) (org-table-align))
|
2008-04-21 01:50:27 -04:00
|
|
|
(let ((dests (orgtbl-gather-send-defs))
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
(table (org-table-to-lisp
|
|
|
|
(buffer-substring-no-properties (org-table-begin)
|
|
|
|
(org-table-end))))
|
2008-04-21 01:50:27 -04:00
|
|
|
(ntbl 0))
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
(unless dests
|
|
|
|
(if maybe (throw 'exit nil)
|
|
|
|
(user-error "Don't know how to transform this table")))
|
2008-04-21 01:50:27 -04:00
|
|
|
(dolist (dest dests)
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
(let ((name (plist-get dest :name))
|
|
|
|
(transform (plist-get dest :transform))
|
|
|
|
(params (plist-get dest :params)))
|
|
|
|
(unless (fboundp transform)
|
|
|
|
(user-error "No such transformation function %s" transform))
|
|
|
|
(orgtbl-send-replace-tbl name (funcall transform table params)))
|
|
|
|
(incf ntbl))
|
2008-04-21 01:50:27 -04:00
|
|
|
(message "Table converted and installed at %d receiver location%s"
|
2012-08-11 13:10:44 -04:00
|
|
|
ntbl (if (> ntbl 1) "s" ""))
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
(and (> ntbl 0) ntbl))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defun org-remove-by-index (list indices &optional i0)
|
|
|
|
"Remove the elements in LIST with indices in INDICES.
|
|
|
|
First element has index 0, or I0 if given."
|
|
|
|
(if (not indices)
|
|
|
|
list
|
|
|
|
(if (integerp indices) (setq indices (list indices)))
|
|
|
|
(setq i0 (1- (or i0 0)))
|
|
|
|
(delq :rm (mapcar (lambda (x)
|
|
|
|
(setq i0 (1+ i0))
|
|
|
|
(if (memq i0 indices) :rm x))
|
|
|
|
list))))
|
|
|
|
|
|
|
|
(defun orgtbl-toggle-comment ()
|
|
|
|
"Comment or uncomment the orgtbl at point."
|
|
|
|
(interactive)
|
2012-04-21 09:36:04 -04:00
|
|
|
(let* ((case-fold-search t)
|
|
|
|
(re1 (concat "^" (regexp-quote comment-start) orgtbl-line-start-regexp))
|
2008-03-22 11:52:18 -04:00
|
|
|
(re2 (concat "^" orgtbl-line-start-regexp))
|
|
|
|
(commented (save-excursion (beginning-of-line 1)
|
2012-08-11 13:10:44 -04:00
|
|
|
(cond ((looking-at re1) t)
|
|
|
|
((looking-at re2) nil)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(t (user-error "Not at an org table")))))
|
2008-03-22 11:52:18 -04:00
|
|
|
(re (if commented re1 re2))
|
|
|
|
beg end)
|
|
|
|
(save-excursion
|
|
|
|
(beginning-of-line 1)
|
|
|
|
(while (looking-at re) (beginning-of-line 0))
|
|
|
|
(beginning-of-line 2)
|
|
|
|
(setq beg (point))
|
|
|
|
(while (looking-at re) (beginning-of-line 2))
|
|
|
|
(setq end (point)))
|
|
|
|
(comment-region beg end (if commented '(4) nil))))
|
|
|
|
|
|
|
|
(defun orgtbl-insert-radio-table ()
|
|
|
|
"Insert a radio table template appropriate for this major mode."
|
|
|
|
(interactive)
|
|
|
|
(let* ((e (assq major-mode orgtbl-radio-table-templates))
|
|
|
|
(txt (nth 1 e))
|
|
|
|
name pos)
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(unless e (user-error "No radio table setup defined for %s" major-mode))
|
2008-03-22 11:52:18 -04:00
|
|
|
(setq name (read-string "Table name: "))
|
|
|
|
(while (string-match "%n" txt)
|
|
|
|
(setq txt (replace-match name t t txt)))
|
|
|
|
(or (bolp) (insert "\n"))
|
|
|
|
(setq pos (point))
|
|
|
|
(insert txt)
|
|
|
|
(goto-char pos)))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
(defun orgtbl-to-generic (table params)
|
2008-03-22 11:52:18 -04:00
|
|
|
"Convert the orgtbl-mode TABLE to some other format.
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
This generic routine can be used for many standard cases.
|
2013-03-19 12:32:35 -04:00
|
|
|
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
TABLE is a list, each entry either the symbol `hline' for
|
|
|
|
a horizontal separator line, or a list of fields for that
|
|
|
|
line. PARAMS is a property list of parameters that can
|
|
|
|
influence the conversion.
|
2008-03-22 11:52:18 -04:00
|
|
|
|
2012-08-09 10:17:05 -04:00
|
|
|
Valid parameters are:
|
2008-03-22 11:52:18 -04:00
|
|
|
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
:backend, :raw
|
|
|
|
|
|
|
|
Export back-end used as a basis to transcode elements of the
|
|
|
|
table, when no specific parameter applies to it. It is also
|
|
|
|
used to translate cells contents. You can prevent this by
|
|
|
|
setting :raw property to a non-nil value.
|
|
|
|
|
|
|
|
:splice
|
|
|
|
|
|
|
|
When non-nil, only convert rows, not the table itself. This is
|
|
|
|
equivalent to setting to the empty string both :tstart
|
|
|
|
and :tend, which see.
|
|
|
|
|
|
|
|
:skip
|
|
|
|
|
|
|
|
When set to an integer N, skip the first N lines of the table.
|
|
|
|
Horizontal separation lines do count for this parameter!
|
|
|
|
|
|
|
|
:skipcols
|
|
|
|
|
|
|
|
List of columns that should be skipped. If the table has
|
|
|
|
a column with calculation marks, that column is automatically
|
|
|
|
discarded beforehand.
|
|
|
|
|
|
|
|
:hline
|
|
|
|
|
|
|
|
String to be inserted on horizontal separation lines. May be
|
|
|
|
nil to ignore these lines altogether.
|
2008-03-22 11:52:18 -04:00
|
|
|
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
:sep
|
2008-03-22 11:52:18 -04:00
|
|
|
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
Separator between two fields, as a string.
|
2008-04-21 01:50:27 -04:00
|
|
|
|
2008-05-12 01:31:21 -04:00
|
|
|
Each in the following group may be either a string or a function
|
|
|
|
of no arguments returning a string:
|
2012-08-09 10:17:05 -04:00
|
|
|
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
:tstart, :tend
|
|
|
|
|
|
|
|
Strings to start and end the table. Ignored when :splice is t.
|
|
|
|
|
|
|
|
:lstart, :lend
|
|
|
|
|
|
|
|
Strings to start and end a new table line.
|
|
|
|
|
|
|
|
:llstart, :llend
|
|
|
|
|
|
|
|
Strings to start and end the last table line. Default,
|
|
|
|
respectively, to :lstart and :lend.
|
|
|
|
|
|
|
|
Each in the following group may be a string or a function of one
|
|
|
|
argument (either the cells in the current row, as a list of
|
|
|
|
strings, or the current cell) returning a string:
|
|
|
|
|
|
|
|
:lfmt
|
|
|
|
|
|
|
|
Format string for an entire row, with enough %s to capture all
|
|
|
|
fields. When non-nil, :lstart, :lend, and :sep are ignored.
|
|
|
|
|
|
|
|
:llfmt
|
|
|
|
|
|
|
|
Format for the entire last line, defaults to :lfmt.
|
|
|
|
|
|
|
|
:fmt
|
|
|
|
|
|
|
|
A format to be used to wrap the field, should contain %s for
|
|
|
|
the original field value. For example, to wrap everything in
|
|
|
|
dollars, you could use :fmt \"$%s$\". This may also be
|
|
|
|
a property list with column numbers and format strings, or
|
|
|
|
functions, e.g.,
|
|
|
|
|
|
|
|
\(:fmt (2 \"$%s$\" 4 (lambda (c) (format \"$%s$\" c))))
|
|
|
|
|
|
|
|
:hlstart :hllstart :hlend :hllend :hsep :hlfmt :hllfmt :hfmt
|
|
|
|
|
|
|
|
Same as above, specific for the header lines in the table.
|
|
|
|
All lines before the first hline are treated as header. If
|
|
|
|
any of these is not present, the data line value is used.
|
2008-03-22 11:52:18 -04:00
|
|
|
|
2008-05-12 01:31:21 -04:00
|
|
|
This may be either a string or a function of two arguments:
|
2012-08-09 10:17:05 -04:00
|
|
|
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
:efmt
|
|
|
|
|
|
|
|
Use this format to print numbers with exponential. The format
|
|
|
|
should have %s twice for inserting mantissa and exponent, for
|
|
|
|
example \"%s\\\\times10^{%s}\". This may also be a property
|
|
|
|
list with column numbers and format strings or functions.
|
|
|
|
:fmt will still be applied after :efmt."
|
|
|
|
(let ((backend (plist-get params :backend)))
|
|
|
|
(when (and backend (symbolp backend) (not (org-export-get-backend backend)))
|
|
|
|
(user-error "Unknown :backend value"))
|
|
|
|
(when (or (not backend) (plist-get params :raw)) (require 'ox-org))
|
|
|
|
(org-trim
|
|
|
|
(org-export-string-as
|
|
|
|
;; Return TABLE as Org syntax. Tolerate non-string cells.
|
|
|
|
(with-output-to-string
|
|
|
|
(dolist (e table)
|
|
|
|
(cond ((eq e 'hline) (princ "|--\n"))
|
|
|
|
((consp e)
|
|
|
|
(princ "| ") (dolist (c e) (princ c) (princ " |"))
|
|
|
|
(princ "\n")))))
|
|
|
|
;; Build a custom back-end according to PARAMS. Before defining
|
|
|
|
;; a translator, check if there is anything to do. When there
|
|
|
|
;; isn't, let BACKEND handle the element.
|
|
|
|
(org-export-create-backend
|
|
|
|
:parent (or backend 'org)
|
|
|
|
:filters
|
|
|
|
'((:filter-parse-tree
|
|
|
|
;; Handle :skip parameter.
|
|
|
|
(lambda (tree backend info)
|
|
|
|
(let ((skip (plist-get info :skip)))
|
|
|
|
(when skip
|
|
|
|
(unless (wholenump skip) (user-error "Wrong :skip value"))
|
|
|
|
(let ((n 0))
|
|
|
|
(org-element-map tree 'table-row
|
|
|
|
(lambda (row)
|
|
|
|
(if (>= n skip) t
|
|
|
|
(org-element-extract-element row)
|
|
|
|
(incf n)
|
|
|
|
nil))
|
|
|
|
info t))
|
|
|
|
tree)))
|
|
|
|
;; Handle :skipcols parameter.
|
|
|
|
(lambda (tree backend info)
|
|
|
|
(let ((skipcols (plist-get info :skipcols)))
|
|
|
|
(when skipcols
|
|
|
|
(unless (consp skipcols) (user-error "Wrong :skipcols value"))
|
|
|
|
(org-element-map tree 'table
|
|
|
|
(lambda (table)
|
|
|
|
(let ((specialp
|
|
|
|
(org-export-table-has-special-column-p table)))
|
|
|
|
(dolist (row (org-element-contents table))
|
|
|
|
(when (eq (org-element-property :type row) 'standard)
|
|
|
|
(let ((c 1))
|
|
|
|
(dolist (cell (nthcdr (if specialp 1 0)
|
|
|
|
(org-element-contents row)))
|
|
|
|
(when (memq c skipcols)
|
|
|
|
(org-element-extract-element cell))
|
|
|
|
(incf c)))))))
|
|
|
|
info)
|
|
|
|
tree)))))
|
|
|
|
:transcoders
|
|
|
|
`((table . ,(org-table--to-generic-table params))
|
|
|
|
(table-row . ,(org-table--to-generic-row params))
|
|
|
|
(table-cell . ,(org-table--to-generic-cell params))
|
|
|
|
;; Section. Return contents to avoid garbage around table.
|
|
|
|
(section . (lambda (s c i) c))))
|
|
|
|
'body-only (org-combine-plists params '(:with-tables t))))))
|
|
|
|
|
|
|
|
(defun org-table--generic-apply (value name &optional with-cons &rest args)
|
|
|
|
(cond ((null value) nil)
|
|
|
|
((functionp value) `(funcall ',value ,@args))
|
|
|
|
((stringp value)
|
|
|
|
(cond ((consp (car args)) `(apply #'format ,value ,@args))
|
|
|
|
(args `(format ,value ,@args))
|
|
|
|
(t value)))
|
|
|
|
((and with-cons (consp value))
|
|
|
|
`(let ((val (cadr (memq column ',value))))
|
|
|
|
(cond ((null val) contents)
|
|
|
|
((stringp val) (format val ,@args))
|
|
|
|
((functionp val) (funcall val ,@args))
|
|
|
|
(t (user-error "Wrong %s value" ,name)))))
|
|
|
|
(t (user-error "Wrong %s value" name))))
|
|
|
|
|
|
|
|
(defun org-table--to-generic-table (params)
|
|
|
|
"Return custom table transcoder according to PARAMS.
|
|
|
|
PARAMS is a plist. See `orgtbl-to-generic' for more
|
|
|
|
information."
|
|
|
|
(let ((backend (plist-get params :backend))
|
|
|
|
(splice (plist-get params :splice))
|
|
|
|
(tstart (plist-get params :tstart))
|
|
|
|
(tend (plist-get params :tend)))
|
|
|
|
`(lambda (table contents info)
|
|
|
|
(concat
|
|
|
|
,(and tstart (not splice)
|
|
|
|
`(concat ,(org-table--generic-apply tstart ":tstart") "\n"))
|
|
|
|
,(if (or (not backend) tstart tend splice) 'contents
|
|
|
|
`(org-export-with-backend ',backend table contents info))
|
|
|
|
,(org-table--generic-apply (and (not splice) tend) ":tend")))))
|
|
|
|
|
|
|
|
(defun org-table--to-generic-row (params)
|
|
|
|
"Return custom table row transcoder according to PARAMS.
|
|
|
|
PARAMS is a plist. See `orgtbl-to-generic' for more
|
|
|
|
information."
|
|
|
|
(let* ((backend (plist-get params :backend))
|
|
|
|
(lstart (plist-get params :lstart))
|
|
|
|
(llstart (plist-get params :llstart))
|
|
|
|
(hlstart (plist-get params :hlstart))
|
|
|
|
(hllstart (plist-get params :hllstart))
|
|
|
|
(lend (plist-get params :lend))
|
|
|
|
(llend (plist-get params :llend))
|
|
|
|
(hlend (plist-get params :hlend))
|
|
|
|
(hllend (plist-get params :hllend))
|
|
|
|
(lfmt (plist-get params :lfmt))
|
|
|
|
(llfmt (plist-get params :llfmt))
|
|
|
|
(hlfmt (plist-get params :hlfmt))
|
|
|
|
(hllfmt (plist-get params :hllfmt)))
|
|
|
|
`(lambda (row contents info)
|
|
|
|
(if (eq (org-element-property :type row) 'rule)
|
|
|
|
,(cond
|
|
|
|
((plist-member params :hline)
|
|
|
|
(org-table--generic-apply (plist-get params :hline) ":hline"))
|
|
|
|
(backend `(org-export-with-backend ',backend row nil info)))
|
|
|
|
(let ((headerp (org-export-table-row-in-header-p row info))
|
|
|
|
(lastp (not (org-export-get-next-element row info)))
|
|
|
|
(last-header-p (org-export-table-row-ends-header-p row info)))
|
|
|
|
(when contents
|
|
|
|
;; Check if we can apply `:lfmt', `:llfmt', `:hlfmt', or
|
|
|
|
;; `:hllfmt' to CONTENTS. Otherwise, fallback on
|
|
|
|
;; `:lstart', `:lend' and their relatives.
|
|
|
|
,(let ((cells
|
|
|
|
'(org-element-map row 'table-cell
|
|
|
|
(lambda (cell)
|
|
|
|
;; Export all cells, without separators.
|
|
|
|
;;
|
|
|
|
;; Use `org-export-data-with-backend'
|
|
|
|
;; instead of `org-export-data' to eschew
|
|
|
|
;; cached values, which
|
|
|
|
;; ignore :orgtbl-ignore-sep parameter.
|
|
|
|
(org-export-data-with-backend
|
|
|
|
cell
|
|
|
|
(plist-get info :back-end)
|
|
|
|
(org-combine-plists info '(:orgtbl-ignore-sep t))))
|
|
|
|
info)))
|
|
|
|
`(cond
|
|
|
|
,(and hllfmt
|
|
|
|
`(last-header-p ,(org-table--generic-apply
|
|
|
|
hllfmt ":hllfmt" nil cells)))
|
|
|
|
,(and hlfmt
|
|
|
|
`(headerp ,(org-table--generic-apply
|
|
|
|
hlfmt ":hlfmt" nil cells)))
|
|
|
|
,(and llfmt
|
|
|
|
`(lastp ,(org-table--generic-apply
|
|
|
|
llfmt ":llfmt" nil cells)))
|
|
|
|
(t
|
|
|
|
,(if lfmt (org-table--generic-apply lfmt ":lfmt" nil cells)
|
|
|
|
`(concat
|
|
|
|
(cond
|
|
|
|
,(and
|
|
|
|
(or hllstart hllend)
|
|
|
|
`(last-header-p
|
|
|
|
(concat
|
|
|
|
,(org-table--generic-apply hllstart ":hllstart")
|
|
|
|
contents
|
|
|
|
,(org-table--generic-apply hllend ":hllend"))))
|
|
|
|
,(and
|
|
|
|
(or hlstart hlend)
|
|
|
|
`(headerp
|
|
|
|
(concat
|
|
|
|
,(org-table--generic-apply hlstart ":hlstart")
|
|
|
|
contents
|
|
|
|
,(org-table--generic-apply hlend ":hlend"))))
|
|
|
|
,(and
|
|
|
|
(or llstart llend)
|
|
|
|
`(lastp
|
|
|
|
(concat
|
|
|
|
,(org-table--generic-apply llstart ":llstart")
|
|
|
|
contents
|
|
|
|
,(org-table--generic-apply llend ":llend"))))
|
|
|
|
(t
|
|
|
|
,(cond
|
|
|
|
((or lstart lend)
|
|
|
|
`(concat
|
|
|
|
,(org-table--generic-apply lstart ":lstart")
|
|
|
|
contents
|
|
|
|
,(org-table--generic-apply lend ":lend")))
|
|
|
|
(backend
|
|
|
|
`(org-export-with-backend
|
|
|
|
',backend row contents info))
|
|
|
|
(t 'contents)))))))))))))))
|
|
|
|
|
|
|
|
(defun org-table--to-generic-cell (params)
|
|
|
|
"Return custom table cell transcoder according to PARAMS.
|
|
|
|
PARAMS is a plist. See `orgtbl-to-generic' for more
|
|
|
|
information."
|
|
|
|
(let* ((backend (plist-get params :backend))
|
|
|
|
(efmt (plist-get params :efmt))
|
|
|
|
(fmt (plist-get params :fmt))
|
|
|
|
(hfmt (plist-get params :hfmt))
|
|
|
|
(sep (plist-get params :sep))
|
|
|
|
(hsep (plist-get params :hsep)))
|
|
|
|
`(lambda (cell contents info)
|
|
|
|
(let ((headerp (org-export-table-row-in-header-p
|
|
|
|
(org-export-get-parent-element cell) info))
|
|
|
|
(column (1+ (cdr (org-export-table-cell-address cell info)))))
|
|
|
|
;; Make sure that contents are exported as Org data when :raw
|
|
|
|
;; parameter is non-nil.
|
|
|
|
,(when (and backend (plist-get params :raw))
|
2014-10-11 11:01:59 -04:00
|
|
|
`(setq contents
|
|
|
|
;; Since we don't know what are the pseudo object
|
|
|
|
;; types defined in backend, we cannot pass them to
|
|
|
|
;; `org-element-interpret-data'. As a consequence,
|
|
|
|
;; they will be treated as pseudo elements, and
|
|
|
|
;; will have newlines appended instead of spaces.
|
|
|
|
;; Therefore, we must make sure :post-blank value
|
|
|
|
;; is really turned into spaces.
|
|
|
|
(replace-regexp-in-string
|
|
|
|
"\n" " "
|
|
|
|
(org-trim
|
|
|
|
(org-element-interpret-data
|
|
|
|
(org-element-contents cell))))))
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
(when contents
|
|
|
|
;; Check if we can apply `:efmt' on CONTENTS.
|
|
|
|
,(when efmt
|
|
|
|
`(when (string-match orgtbl-exp-regexp contents)
|
|
|
|
(let ((mantissa (match-string 1 contents))
|
|
|
|
(exponent (match-string 2 contents)))
|
|
|
|
(setq contents ,(org-table--generic-apply
|
|
|
|
efmt ":efmt" t 'mantissa 'exponent)))))
|
|
|
|
;; Check if we can apply FMT (or HFMT) on CONTENTS.
|
|
|
|
(cond
|
|
|
|
,(and hfmt `(headerp (setq contents ,(org-table--generic-apply
|
|
|
|
hfmt ":hfmt" t 'contents))))
|
|
|
|
,(and fmt `(t (setq contents ,(org-table--generic-apply
|
|
|
|
fmt ":hfmt" t 'contents))))))
|
|
|
|
;; If a separator is provided, use it instead of BACKEND's.
|
|
|
|
;; Separators are ignored when LFMT (or equivalent) is
|
|
|
|
;; provided.
|
|
|
|
,(cond
|
|
|
|
((or hsep sep)
|
|
|
|
`(if (or ,(and (not sep) '(not headerp))
|
|
|
|
(plist-get info :orgtbl-ignore-sep)
|
|
|
|
(not (org-export-get-next-element cell info)))
|
|
|
|
,(if (not backend) 'contents
|
|
|
|
`(org-export-with-backend ',backend cell contents info))
|
|
|
|
(concat contents
|
|
|
|
,(if (and sep hsep) `(if headerp ,hsep ,sep)
|
|
|
|
(or hsep sep)))))
|
|
|
|
(backend `(org-export-with-backend ',backend cell contents info))
|
|
|
|
(t 'contents))))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-05-10 07:40:25 -04:00
|
|
|
(defun orgtbl-to-tsv (table params)
|
|
|
|
"Convert the orgtbl-mode table to TAB separated material."
|
|
|
|
(orgtbl-to-generic table (org-combine-plists '(:sep "\t") params)))
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-05-10 07:40:25 -04:00
|
|
|
(defun orgtbl-to-csv (table params)
|
|
|
|
"Convert the orgtbl-mode table to CSV material.
|
|
|
|
This does take care of the proper quoting of fields with comma or quotes."
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
(orgtbl-to-generic table
|
|
|
|
(org-combine-plists '(:sep "," :fmt org-quote-csv-field)
|
|
|
|
params)))
|
2008-05-10 07:40:25 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun orgtbl-to-latex (table params)
|
|
|
|
"Convert the orgtbl-mode TABLE to LaTeX.
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
|
|
|
|
TABLE is a list, each entry either the symbol `hline' for
|
|
|
|
a horizontal separator line, or a list of fields for that line.
|
|
|
|
PARAMS is a property list of parameters that can influence the
|
|
|
|
conversion. All parameters from `orgtbl-to-generic' are
|
|
|
|
supported. It is also possible to use the following ones:
|
|
|
|
|
|
|
|
:booktabs
|
|
|
|
|
|
|
|
When non-nil, use formal \"booktabs\" style.
|
|
|
|
|
|
|
|
:environment
|
|
|
|
|
|
|
|
Specify environment to use, as a string. If you use
|
|
|
|
\"longtable\", you may also want to specify :language property,
|
|
|
|
as a string, to get proper continuation strings."
|
|
|
|
(require 'ox-latex)
|
|
|
|
(orgtbl-to-generic
|
|
|
|
table
|
|
|
|
(org-combine-plists
|
|
|
|
;; Provide sane default values.
|
|
|
|
(list :backend 'latex
|
|
|
|
:latex-default-table-mode 'table
|
|
|
|
:latex-tables-centered nil
|
|
|
|
:latex-tables-booktabs (plist-get params :booktabs)
|
|
|
|
:latex-table-scientific-notation nil
|
|
|
|
:latex-default-table-environment
|
|
|
|
(or (plist-get params :environment) "tabular"))
|
|
|
|
params)))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun orgtbl-to-html (table params)
|
2010-06-25 04:01:23 -04:00
|
|
|
"Convert the orgtbl-mode TABLE to HTML.
|
2008-03-22 11:52:18 -04:00
|
|
|
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
TABLE is a list, each entry either the symbol `hline' for
|
|
|
|
a horizontal separator line, or a list of fields for that line.
|
|
|
|
PARAMS is a property list of parameters that can influence the
|
|
|
|
conversion. All parameters from `orgtbl-to-generic' are
|
|
|
|
supported. It is also possible to use the following one:
|
|
|
|
|
|
|
|
:attributes
|
2008-03-22 11:52:18 -04:00
|
|
|
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
Attributes and values, as a plist, which will be used in
|
|
|
|
<table> tag."
|
2013-01-27 17:44:27 -05:00
|
|
|
(require 'ox-html)
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
(orgtbl-to-generic
|
|
|
|
table
|
|
|
|
(org-combine-plists
|
|
|
|
;; Provide sane default values.
|
|
|
|
(list :backend 'html
|
|
|
|
:html-table-data-tags '("<td%s>" . "</td>")
|
|
|
|
:html-table-use-header-tags-for-first-column nil
|
|
|
|
:html-table-align-individual-fields t
|
|
|
|
:html-table-row-tags '("<tr>" . "</tr>")
|
|
|
|
:html-table-attributes
|
|
|
|
(if (plist-member params :attributes)
|
|
|
|
(plist-get params :attributes)
|
|
|
|
'(:border "2" :cellspacing "0" :cellpadding "6" :rules "groups"
|
|
|
|
:frame "hsides")))
|
|
|
|
params)))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-03-22 11:52:18 -04:00
|
|
|
(defun orgtbl-to-texinfo (table params)
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
"Convert the orgtbl-mode TABLE to Texinfo.
|
|
|
|
|
|
|
|
TABLE is a list, each entry either the symbol `hline' for
|
|
|
|
a horizontal separator line, or a list of fields for that line.
|
|
|
|
PARAMS is a property list of parameters that can influence the
|
|
|
|
conversion. All parameters from `orgtbl-to-generic' are
|
|
|
|
supported. It is also possible to use the following one:
|
|
|
|
|
|
|
|
:columns
|
|
|
|
|
|
|
|
Column widths, as a string. When providing column fractions,
|
|
|
|
\"@columnfractions\" command can be omitted."
|
|
|
|
(require 'ox-texinfo)
|
|
|
|
(let ((output
|
|
|
|
(orgtbl-to-generic
|
|
|
|
table
|
|
|
|
(org-combine-plists
|
|
|
|
(list :backend 'texinfo
|
|
|
|
:texinfo-tables-verbatim nil
|
|
|
|
:texinfo-table-scientific-notation nil)
|
|
|
|
params)))
|
|
|
|
(columns (let ((w (plist-get params :columns)))
|
|
|
|
(cond ((not w) nil)
|
|
|
|
((org-string-match-p "{\\|@columnfractions " w) w)
|
|
|
|
(t (concat "@columnfractions " w))))))
|
|
|
|
(if (not columns) output
|
|
|
|
(replace-regexp-in-string
|
|
|
|
"@multitable \\(.*\\)" columns output t nil 1))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-05-06 08:15:45 -04:00
|
|
|
(defun orgtbl-to-orgtbl (table params)
|
|
|
|
"Convert the orgtbl-mode TABLE into another orgtbl-mode table.
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
|
|
|
|
TABLE is a list, each entry either the symbol `hline' for
|
|
|
|
a horizontal separator line, or a list of fields for that line.
|
|
|
|
PARAMS is a property list of parameters that can influence the
|
|
|
|
conversion. All parameters from `orgtbl-to-generic' are
|
|
|
|
supported.
|
|
|
|
|
2008-05-06 08:15:45 -04:00
|
|
|
Useful when slicing one table into many. The :hline, :sep,
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
:lstart, and :lend provide orgtbl framing. :tstart and :tend can
|
|
|
|
be set to provide ORGTBL directives for the generated table."
|
|
|
|
(require 'ox-org)
|
|
|
|
(orgtbl-to-generic table (org-combine-plists (list :backend 'org))))
|
2012-07-31 09:40:05 -04:00
|
|
|
|
|
|
|
(defun orgtbl-to-table.el (table params)
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
"Convert the orgtbl-mode TABLE into a table.el table.
|
|
|
|
TABLE is a list, each entry either the symbol `hline' for
|
|
|
|
a horizontal separator line, or a list of fields for that line.
|
|
|
|
PARAMS is a property list of parameters that can influence the
|
|
|
|
conversion. All parameters from `orgtbl-to-generic' are
|
|
|
|
supported."
|
2012-07-31 09:40:05 -04:00
|
|
|
(with-temp-buffer
|
|
|
|
(insert (orgtbl-to-orgtbl table params))
|
|
|
|
(org-table-align)
|
|
|
|
(replace-regexp-in-string
|
|
|
|
"-|" "-+"
|
|
|
|
(replace-regexp-in-string "|-" "+-" (buffer-substring 1 (buffer-size))))))
|
|
|
|
|
|
|
|
(defun orgtbl-to-unicode (table params)
|
|
|
|
"Convert the orgtbl-mode TABLE into a table with unicode characters.
|
org-table: Use "ox.el" internally for radio tables
* lisp/org-table.el (org-table-clean-before-export, orgtbl-get-fmt,
orgtbl-apply-fmt, orgtbl-eval-str, orgtbl-format-line,
orgtbl-format-section): Remove functions.
(org-table-clean-did-remove-column, *orgtbl-table*, *orgtbl-rtn*,
*orgtbl-hline*, *orgtbl-sep*, *orgtbl-default-fmt*, *orgtbl-fmt*,
*orgtbl-efmt*, *orgtbl-lfmt*, *orgtbl-llfmt*, *orgtbl-lstart*,
*orgtbl-llstart*, *orgtbl-lend*, *orgtbl-llend*): Remove variables.
(org-table-export, orgtbl-send-table): Apply function removal. Do not
set `org-table-last-alignment' and `org-table-last-column-widths'
anymore.
(org-table-to-lisp, orgtbl-send-replace-tbl): Small refactoring.
(org-table--to-generic-table, org-table--to-generic-row,
org-table--to-generic-cell): New functions.
(orgtbl-to-generic): Rewrite function. Handle :skip and :skipcols
parameters.
(orgtbl-to-latex, orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl,
orgtbl-to-unicode): Use new `orgtbl-to-generic' features.
* testing/lisp/test-org-table.el (test-org-table/to-generic,
test-org-table/to-latex, test-org-table/to-texinfo,
test-org-table/to-html, test-org-table/to-unicode,
test-org-table/send-region): New tests.
* doc/org.texi (Radio tables, A @LaTeX{} example, Translator
functions): Update documentation.
* etc/ORG-NEWS (argument): Document new features.
2014-08-23 19:31:56 -04:00
|
|
|
|
|
|
|
TABLE is a list, each entry either the symbol `hline' for
|
|
|
|
a horizontal separator line, or a list of fields for that line.
|
|
|
|
PARAMS is a property list of parameters that can influence the
|
|
|
|
conversion. All parameters from `orgtbl-to-generic' are
|
|
|
|
supported. It is also possible to use the following ones:
|
|
|
|
|
|
|
|
:ascii-art
|
|
|
|
|
|
|
|
When non-nil, use \"ascii-art-to-unicode\" package to translate
|
|
|
|
the table. You can download it here:
|
|
|
|
http://gnuvola.org/software/j/aa2u/ascii-art-to-unicode.el.
|
|
|
|
|
|
|
|
:narrow
|
|
|
|
|
|
|
|
When non-nil, narrow columns width than provided width cookie,
|
|
|
|
using \"=>\" as an ellipsis, just like in an Org mode buffer."
|
|
|
|
(require 'ox-ascii)
|
|
|
|
(orgtbl-to-generic
|
|
|
|
table
|
|
|
|
(org-combine-plists
|
|
|
|
(list :backend 'ascii
|
|
|
|
:ascii-charset 'utf-8
|
|
|
|
:ascii-table-keep-all-vertical-lines (plist-get params :)
|
|
|
|
:ascii-table-widen-columns (not (plist-get params :narrow))
|
|
|
|
:ascii-table-use-ascii-art (plist-get params :ascii-art))
|
|
|
|
params)))
|
2008-05-06 08:15:45 -04:00
|
|
|
|
2014-08-28 16:28:27 -04:00
|
|
|
;; Put the cursor in a column containing numerical values
|
|
|
|
;; of an Org-Mode table,
|
2014-10-11 09:59:17 -04:00
|
|
|
;; type C-c " a
|
2014-08-28 16:28:27 -04:00
|
|
|
;; A new column is added with a bar plot.
|
|
|
|
;; When the table is refreshed (C-u C-c *),
|
|
|
|
;; the plot is updated to reflect the new values.
|
|
|
|
|
|
|
|
(defun orgtbl-ascii-draw (value min max &optional width characters)
|
|
|
|
"Draw an ascii bar in a table.
|
|
|
|
VALUE is a the value to plot, the width of the bar to draw. A
|
|
|
|
value equal to MIN will be displayed as empty (zero width bar).
|
|
|
|
A value equal to MAX will draw a bar filling all the WIDTH.
|
|
|
|
WIDTH is the expected width in characters of the column.
|
|
|
|
CHARACTERS is a string that will compose the bar, with shades of
|
|
|
|
grey from pure white to pure black. It defaults to a 10
|
|
|
|
characters string of regular ascii characters."
|
|
|
|
(let* ((characters (or characters " .:;c!lhVHW"))
|
|
|
|
(width (or width 12))
|
|
|
|
(value (if (numberp value) value (string-to-number value)))
|
|
|
|
(value (* (/ (- (+ value 0.0) min) (- max min)) width)))
|
|
|
|
(cond
|
|
|
|
((< value 0) "too small")
|
|
|
|
((> value width) "too large")
|
|
|
|
(t
|
|
|
|
(let ((len (1- (length characters))))
|
|
|
|
(concat
|
|
|
|
(make-string (floor value) (elt characters len))
|
|
|
|
(string (elt characters
|
|
|
|
(floor (* (- value (floor value)) len))))))))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun orgtbl-ascii-plot (&optional ask)
|
|
|
|
"Draw an ascii bar plot in a column.
|
|
|
|
With cursor in a column containing numerical values, this
|
|
|
|
function will draw a plot in a new column.
|
|
|
|
ASK, if given, is a numeric prefix to override the default 12
|
|
|
|
characters width of the plot. ASK may also be the
|
|
|
|
\\[universal-argument] prefix, which will prompt for the width."
|
|
|
|
(interactive "P")
|
|
|
|
(let ((col (org-table-current-column))
|
|
|
|
(min 1e999) ; 1e999 will be converted to infinity
|
|
|
|
(max -1e999) ; which is the desired result
|
|
|
|
(table (org-table-to-lisp))
|
|
|
|
(length
|
|
|
|
(cond ((consp ask)
|
|
|
|
(read-number "Length of column " 12))
|
|
|
|
((numberp ask) ask)
|
|
|
|
(t 12))))
|
|
|
|
;; Skip any hline a the top of table.
|
|
|
|
(while (eq (car table) 'hline) (setq table (cdr table)))
|
|
|
|
;; Skip table header if any.
|
|
|
|
(dolist (x (or (cdr (memq 'hline table)) table))
|
|
|
|
(when (consp x)
|
|
|
|
(setq x (nth (1- col) x))
|
|
|
|
(when (string-match
|
|
|
|
"^[-+]?\\([0-9]*[.]\\)?[0-9]*\\([eE][+-]?[0-9]+\\)?$"
|
|
|
|
x)
|
|
|
|
(setq x (string-to-number x))
|
|
|
|
(when (> min x) (setq min x))
|
|
|
|
(when (< max x) (setq max x)))))
|
|
|
|
(org-table-insert-column)
|
|
|
|
(org-table-move-column-right)
|
|
|
|
(org-table-store-formulas
|
|
|
|
(cons
|
|
|
|
(cons
|
|
|
|
(number-to-string (1+ col))
|
|
|
|
(format "'(%s $%s %s %s %s)"
|
|
|
|
"orgtbl-ascii-draw" col min max length))
|
|
|
|
(org-table-get-stored-formulas)))
|
|
|
|
(org-table-recalculate t)))
|
|
|
|
|
|
|
|
;; Example of extension: unicode characters
|
|
|
|
;; Here are two examples of different styles.
|
|
|
|
|
|
|
|
;; Unicode block characters are used to give a smooth effect.
|
|
|
|
;; See http://en.wikipedia.org/wiki/Block_Elements
|
|
|
|
;; Use one of those drawing functions
|
|
|
|
;; - orgtbl-ascii-draw (the default ascii)
|
|
|
|
;; - orgtbl-uc-draw-grid (unicode with a grid effect)
|
|
|
|
;; - orgtbl-uc-draw-cont (smooth unicode)
|
|
|
|
|
|
|
|
;; This is best viewed with the "DejaVu Sans Mono" font
|
|
|
|
;; (use M-x set-default-font).
|
|
|
|
|
|
|
|
(defun orgtbl-uc-draw-grid (value min max &optional width)
|
|
|
|
"Draw a bar in a table using block unicode characters.
|
|
|
|
It is a variant of orgtbl-ascii-draw with Unicode block
|
|
|
|
characters, for a smooth display. Bars appear as grids (to the
|
|
|
|
extent the font allows)."
|
|
|
|
;; http://en.wikipedia.org/wiki/Block_Elements
|
|
|
|
;; best viewed with the "DejaVu Sans Mono" font.
|
|
|
|
(orgtbl-ascii-draw value min max width
|
|
|
|
" \u258F\u258E\u258D\u258C\u258B\u258A\u2589"))
|
|
|
|
|
|
|
|
(defun orgtbl-uc-draw-cont (value min max &optional width)
|
|
|
|
"Draw a bar in a table using block unicode characters.
|
|
|
|
It is a variant of orgtbl-ascii-draw with Unicode block
|
|
|
|
characters, for a smooth display. Bars are solid (to the extent
|
|
|
|
the font allows)."
|
|
|
|
(orgtbl-ascii-draw value min max width
|
|
|
|
" \u258F\u258E\u258D\u258C\u258B\u258A\u2589\u2588"))
|
|
|
|
|
2009-01-24 04:51:21 -05:00
|
|
|
(defun org-table-get-remote-range (name-or-id form)
|
|
|
|
"Get a field value or a list of values in a range from table at ID.
|
|
|
|
|
2013-04-09 16:09:00 -04:00
|
|
|
NAME-OR-ID may be the name of a table in the current file as set
|
|
|
|
by a \"#+NAME:\" directive. The first table following this line
|
2009-01-24 04:51:21 -05:00
|
|
|
will then be used. Alternatively, it may be an ID referring to
|
2013-04-09 16:09:00 -04:00
|
|
|
any entry, also in a different file. In this case, the first
|
|
|
|
table in that entry will be referenced.
|
2011-06-20 09:38:24 -04:00
|
|
|
FORM is a field or range descriptor like \"@2$3\" or \"B3\" or
|
2009-01-24 04:51:21 -05:00
|
|
|
\"@I$2..@II$2\". All the references must be absolute, not relative.
|
|
|
|
|
|
|
|
The return value is either a single string for a single field, or a
|
2013-04-18 09:42:31 -04:00
|
|
|
list of the fields in the rectangle."
|
2009-01-24 04:51:21 -05:00
|
|
|
(save-match-data
|
2012-04-21 09:36:04 -04:00
|
|
|
(let ((case-fold-search t) (id-loc nil)
|
Fix remote references that contain pointers to first/last rows/columns
* lisp/org-table.el (org-table-formula-handle-first/last-rc): Do not
expand pointers to first/last row/column that are inside a call
to `remote'.
(org-table-get-remote-range): Expand pointers to first/last
row/column.
Wu Feng writes:
> Hello,
>
> First, please check below simple example, I defined two tables (T1 and
> T2). In table-2, I remotely refer to the @>$1 (last row, column 1) and
> $LR2 (last row, column 2) of T1.
>
> #+TBLNAME: T1
> | 11 | 12 |
> | 21 | 22 |
> | 31 | 32 |
>
> #+TBLNAME: T2
> | xxx | xxx | xxx | xxx |
> | # | 21 | 32 | |
> #+TBLFM: @>$3=remote(T1,$LR2)::@>$2=remote(T1,@>$1)
>
> Obviously, the expected results are:
>
> - remote(T1,@>$1) is replaced by 31
> - remote(T1,$LR2) is replaced by 32
>
> But I got 21 for remote(T1,@>$1). The $LR version works perfectly
> (though the manual says $LR is out-dated)
>
> Below are debug info when evaluating remote(T1,@>$1). Looks like @> in
> the remote reference is mapped to the last row of the current table, not
> of the remote table.
>
> Substitution history of formula
> Orig: remote(T1,@2$1)
> $xyz-> remote(T1,@2$1)
> @r$c-> (21)
> $1-> (21)
> Result: 21
> Format: NONE
> Final: 21
>
> Emacs : GNU Emacs 23.3.1 (i686-pc-linux-gnu, GTK+ Version 2.24.6)
> of 2011-09-13 on shirley
> Package: Org-mode version 7.7
2011-10-27 11:30:47 -04:00
|
|
|
;; Protect a bunch of variables from being overwritten
|
|
|
|
;; by the context of the remote table
|
2009-01-24 04:51:21 -05:00
|
|
|
org-table-column-names org-table-column-name-regexp
|
|
|
|
org-table-local-parameters org-table-named-field-locations
|
|
|
|
org-table-current-line-types org-table-current-begin-line
|
|
|
|
org-table-current-begin-pos org-table-dlines
|
2011-03-01 03:05:56 -05:00
|
|
|
org-table-current-ncol
|
2009-01-24 04:51:21 -05:00
|
|
|
org-table-hlines org-table-last-alignment
|
|
|
|
org-table-last-column-widths org-table-last-alignment
|
|
|
|
org-table-last-column-widths tbeg
|
|
|
|
buffer loc)
|
2009-04-15 09:14:19 -04:00
|
|
|
(setq form (org-table-convert-refs-to-rc form))
|
2009-01-24 04:51:21 -05:00
|
|
|
(save-excursion
|
|
|
|
(save-restriction
|
|
|
|
(widen)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(if (re-search-forward
|
2013-04-26 11:07:55 -04:00
|
|
|
(concat "^[ \t]*#\\+\\(tbl\\)?name:[ \t]*"
|
|
|
|
(regexp-quote name-or-id) "[ \t]*$")
|
2009-01-24 04:51:21 -05:00
|
|
|
nil t)
|
|
|
|
(setq buffer (current-buffer) loc (match-beginning 0))
|
2009-07-02 02:42:24 -04:00
|
|
|
(setq id-loc (org-id-find name-or-id 'marker))
|
|
|
|
(unless (and id-loc (markerp id-loc))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Can't find remote table \"%s\"" name-or-id))
|
2009-07-02 02:42:24 -04:00
|
|
|
(setq buffer (marker-buffer id-loc)
|
2009-01-24 04:51:21 -05:00
|
|
|
loc (marker-position id-loc))
|
|
|
|
(move-marker id-loc nil)))
|
2010-05-12 09:04:20 -04:00
|
|
|
(with-current-buffer buffer
|
|
|
|
(save-excursion
|
|
|
|
(save-restriction
|
|
|
|
(widen)
|
|
|
|
(goto-char loc)
|
|
|
|
(forward-char 1)
|
2014-08-20 08:32:47 -04:00
|
|
|
(unless (and (re-search-forward "^\\(\\*+ \\)\\|^[ \t]*|" nil t)
|
2010-05-12 09:04:20 -04:00
|
|
|
(not (match-beginning 1)))
|
org-table.el: Use `user-error' instead of `error' for user errors
* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
2013-03-02 09:40:09 -05:00
|
|
|
(user-error "Cannot find a table at NAME or ID %s" name-or-id))
|
2010-05-12 09:04:20 -04:00
|
|
|
(setq tbeg (point-at-bol))
|
|
|
|
(org-table-get-specials)
|
Fix remote references that contain pointers to first/last rows/columns
* lisp/org-table.el (org-table-formula-handle-first/last-rc): Do not
expand pointers to first/last row/column that are inside a call
to `remote'.
(org-table-get-remote-range): Expand pointers to first/last
row/column.
Wu Feng writes:
> Hello,
>
> First, please check below simple example, I defined two tables (T1 and
> T2). In table-2, I remotely refer to the @>$1 (last row, column 1) and
> $LR2 (last row, column 2) of T1.
>
> #+TBLNAME: T1
> | 11 | 12 |
> | 21 | 22 |
> | 31 | 32 |
>
> #+TBLNAME: T2
> | xxx | xxx | xxx | xxx |
> | # | 21 | 32 | |
> #+TBLFM: @>$3=remote(T1,$LR2)::@>$2=remote(T1,@>$1)
>
> Obviously, the expected results are:
>
> - remote(T1,@>$1) is replaced by 31
> - remote(T1,$LR2) is replaced by 32
>
> But I got 21 for remote(T1,@>$1). The $LR version works perfectly
> (though the manual says $LR is out-dated)
>
> Below are debug info when evaluating remote(T1,@>$1). Looks like @> in
> the remote reference is mapped to the last row of the current table, not
> of the remote table.
>
> Substitution history of formula
> Orig: remote(T1,@2$1)
> $xyz-> remote(T1,@2$1)
> @r$c-> (21)
> $1-> (21)
> Result: 21
> Format: NONE
> Final: 21
>
> Emacs : GNU Emacs 23.3.1 (i686-pc-linux-gnu, GTK+ Version 2.24.6)
> of 2011-09-13 on shirley
> Package: Org-mode version 7.7
2011-10-27 11:30:47 -04:00
|
|
|
(setq form (org-table-formula-substitute-names
|
|
|
|
(org-table-formula-handle-first/last-rc form)))
|
2010-05-12 09:04:20 -04:00
|
|
|
(if (and (string-match org-table-range-regexp form)
|
|
|
|
(> (length (match-string 0 form)) 1))
|
|
|
|
(save-match-data
|
|
|
|
(org-table-get-range (match-string 0 form) tbeg 1))
|
|
|
|
form)))))))))
|
2009-01-24 04:51:21 -05:00
|
|
|
|
2014-01-12 04:53:06 -05:00
|
|
|
(defun org-table-remote-reference-indirection (form)
|
|
|
|
"Return formula with table remote references substituted by indirection.
|
|
|
|
For example \"remote($1, @>$2)\" => \"remote(year_2013, @>$1)\".
|
|
|
|
This indirection works only with the format @ROW$COLUMN. The
|
|
|
|
format \"B3\" is not supported because it can not be
|
|
|
|
distinguished from a plain table name or ID."
|
2014-01-12 05:52:40 -05:00
|
|
|
(let ((start 0))
|
|
|
|
(while (string-match (concat
|
|
|
|
;; Same as in `org-table-eval-formula'.
|
|
|
|
"\\<remote([ \t]*\\("
|
|
|
|
;; Allow "$1", "@<", "$-1", "@<<$1" etc.
|
2014-01-13 14:23:11 -05:00
|
|
|
"[@$][^ \t,]+"
|
2014-01-12 05:52:40 -05:00
|
|
|
;; Same as in `org-table-eval-formula'.
|
|
|
|
"\\)[ \t]*,[ \t]*\\([^\n)]+\\))")
|
|
|
|
form
|
|
|
|
start)
|
2014-01-13 14:23:11 -05:00
|
|
|
;; The position of the character as far as possible to the right
|
|
|
|
;; that will not be replaced and particularly not be shifted by
|
|
|
|
;; `replace-match'.
|
|
|
|
(setq start (match-beginning 1))
|
2014-01-12 04:53:06 -05:00
|
|
|
;; Substitute the remote reference with the value found in the
|
|
|
|
;; field.
|
|
|
|
(setq form
|
|
|
|
(replace-match
|
|
|
|
(save-match-data
|
|
|
|
(org-table-get-range (org-table-formula-handle-first/last-rc
|
|
|
|
(match-string 1 form))))
|
|
|
|
t t form 1))))
|
|
|
|
form)
|
|
|
|
|
2012-10-15 02:54:24 -04:00
|
|
|
(defmacro org-define-lookup-function (mode)
|
|
|
|
(let ((mode-str (symbol-name mode))
|
|
|
|
(first-p (equal mode 'first))
|
|
|
|
(all-p (equal mode 'all)))
|
|
|
|
(let ((plural-str (if all-p "s" "")))
|
|
|
|
`(defun ,(intern (format "org-lookup-%s" mode-str)) (val s-list r-list &optional predicate)
|
|
|
|
,(format "Find %s occurrence%s of VAL in S-LIST; return corresponding element%s of R-LIST.
|
|
|
|
If R-LIST is nil, return matching element%s of S-LIST.
|
|
|
|
If PREDICATE is not nil, use it instead of `equal' to match VAL.
|
|
|
|
Matching is done by (PREDICATE VAL S), where S is an element of S-LIST.
|
|
|
|
This function is generated by a call to the macro `org-define-lookup-function'."
|
|
|
|
mode-str plural-str plural-str plural-str)
|
|
|
|
(let ,(let ((lvars '((p (or predicate 'equal))
|
|
|
|
(sl s-list)
|
|
|
|
(rl (or r-list s-list))
|
|
|
|
(ret nil))))
|
|
|
|
(if first-p (add-to-list 'lvars '(match-p nil)))
|
|
|
|
lvars)
|
|
|
|
(while ,(if first-p '(and (not match-p) sl) 'sl)
|
|
|
|
(progn
|
|
|
|
(if (funcall p val (car sl))
|
|
|
|
(progn
|
|
|
|
,(if first-p '(setq match-p t))
|
|
|
|
(let ((rval (car rl)))
|
|
|
|
(setq ret ,(if all-p '(append ret (list rval)) 'rval)))))
|
|
|
|
(setq sl (cdr sl) rl (cdr rl))))
|
|
|
|
ret)))))
|
|
|
|
|
|
|
|
(org-define-lookup-function first)
|
|
|
|
(org-define-lookup-function last)
|
|
|
|
(org-define-lookup-function all)
|
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
(provide 'org-table)
|
|
|
|
|
2012-10-02 02:50:46 -04:00
|
|
|
;; Local variables:
|
|
|
|
;; generated-autoload-file: "org-loaddefs.el"
|
|
|
|
;; End:
|
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
;;; org-table.el ends here
|