comparison lisp/textmodes/org.el @ 90072:cb67264d6096

Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-2 Merge from emacs--cvs-trunk--0 Patches applied: * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-83 - miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-84 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-3 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-4 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-5 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-6 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-11 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-12 Remove "-face" suffix from lazy-highlight face name * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-13 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-16 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-17 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-18 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-21 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-22 <no summary provided> * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-23 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-39 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-40 Fix regressions from latest reftex update * miles@gnu.org--gnu-2005/gnus--rel--5.10--base-0 tag of miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-82 * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-1 Merge from emacs--cvs-trunk--0 * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-2 Merge from miles@gnu.org--gnu-2004 * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-3 Merge from emacs--cvs-trunk--0
author Miles Bader <miles@gnu.org>
date Sun, 16 Jan 2005 03:40:12 +0000
parents e4029991605f dbd07a2c89d3
children 6d92d69fae33
comparison
equal deleted inserted replaced
90071:f6b4d0ebf147 90072:cb67264d6096
1 ;; org.el --- Outline-based notes management and organizer 1 ;; org.el --- Outline-based notes management and organizer
2 2 ;; Carstens outline-mode for keeping track of everything.
3 ;; Copyright (c) 2003, 2004 Free Software Foundation 3 ;; Copyright (c) 2003, 2004 Free Software Foundation
4 4
5 ;; Author: Carsten Dominik <dominik at science dot uva dot nl> 5 ;; Author: Carsten Dominik <dominik at science dot uva dot nl>
6 ;; Keywords: outlines, hypermedia, calendar 6 ;; Keywords: outlines, hypermedia, calendar
7 ;; Homepage: http://www.astro.uva.nl/~dominik/Tools/org/ 7 ;; Homepage: http://www.astro.uva.nl/~dominik/Tools/org/
8 ;; Version: 3.03 8 ;; Version: 3.04
9 9
10 ;; This file is part of GNU Emacs. 10 ;; This file is part of GNU Emacs.
11 11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify 12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by 13 ;; it under the terms of the GNU General Public License as published by
21 21
22 ;; You should have received a copy of the GNU General Public License 22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA. 25 ;; Boston, MA 02111-1307, USA.
26
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;; Carsten's outline-mode for keeping track of everything.
29 ;; 27 ;;
30 ;;; Commentary: 28 ;;; Commentary:
31 ;; 29 ;;
32 ;; Org-mode is a mode for keeping notes, maintaining ToDo lists, and doing 30 ;; Org-mode is a mode for keeping notes, maintaining ToDo lists, and doing
33 ;; project planning with a fast and effective plain-text system. 31 ;; project planning with a fast and effective plain-text system.
57 ;; 55 ;;
58 ;; (autoload 'org-mode "org" "Org mode" t) 56 ;; (autoload 'org-mode "org" "Org mode" t)
59 ;; (autoload 'org-diary "org" "Diary entries from Org mode") 57 ;; (autoload 'org-diary "org" "Diary entries from Org mode")
60 ;; (autoload 'org-agenda "org" "Multi-file agenda from Org mode" t) 58 ;; (autoload 'org-agenda "org" "Multi-file agenda from Org mode" t)
61 ;; (autoload 'org-store-link "org" "Store a link to the current location" t) 59 ;; (autoload 'org-store-link "org" "Store a link to the current location" t)
60 ;; (autoload 'orgtbl-mode "org" "Org tables as a minor mode" t)
61 ;; (autoload 'turn-on-orgtbl "org" "Org tables as a minor mode")
62 ;; (add-to-list 'auto-mode-alist '("\\.org$" . org-mode)) 62 ;; (add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
63 ;; (define-key global-map "\C-cl" 'org-store-link) 63 ;; (define-key global-map "\C-cl" 'org-store-link)
64 ;; (define-key global-map "\C-ca" 'org-agenda) 64 ;; (define-key global-map "\C-ca" 'org-agenda)
65 ;; 65 ;;
66 ;; This will put all files with extension ".org" into Org-mode. As an 66 ;; This will put all files with extension ".org" into Org-mode. As an
77 ;; This distribution also contains a PDF version of it. At the homepage 77 ;; This distribution also contains a PDF version of it. At the homepage
78 ;; of Org-mode, you can find and read online the same text as HTML. 78 ;; of Org-mode, you can find and read online the same text as HTML.
79 ;; 79 ;;
80 ;; Changes: 80 ;; Changes:
81 ;; ------- 81 ;; -------
82 ;; Version 3.04
83 ;; - Table editor optimized to need fewer realignments, and to keep
84 ;; table shape when typing in fields.
85 ;; - A new minor mode, orgtbl-mode, introduces the Org-mode table editor
86 ;; into arbitrary major modes.
87 ;; - Fixed bug with realignment in XEmacs.
88 ;; - Startup options can be set with special #+STARTUP line.
89 ;; - Heading following a match in org-occur can be suppressed.
90 ;;
82 ;; Version 3.03 91 ;; Version 3.03
83 ;; - Copyright transfer to the FSF. 92 ;; - Copyright transfer to the FSF.
84 ;; - Effect of C-u and C-u C-u in org-timeline interchanged. 93 ;; - Effect of C-u and C-u C-u in org-timeline swapped.
85 ;; - Timeline now always contains today, and `.' jumps to it. 94 ;; - Timeline now always contains today, and `.' jumps to it.
86 ;; - Table editor: 95 ;; - Table editor:
87 ;; - cut and paste of regtangular regions in tables 96 ;; - cut and paste of regtangular regions in tables
88 ;; - command to convert org-mode table to table.el table and back 97 ;; - command to convert org-mode table to table.el table and back
89 ;; - command to treat several cells like a paragraph and fill it 98 ;; - command to treat several cells like a paragraph and fill it
202 (require 'time-date) 211 (require 'time-date)
203 (require 'easymenu) 212 (require 'easymenu)
204 213
205 ;;; Customization variables 214 ;;; Customization variables
206 215
207 (defvar org-version "3.03" 216 (defvar org-version "3.04"
208 "The version number of the file org.el.") 217 "The version number of the file org.el.")
209 (defun org-version (arg) 218 (defun org-version (arg)
210 (interactive "P") 219 (interactive "P")
211 (message "Org-mode version %s" org-version)) 220 (message "Org-mode version %s" org-version))
212 221
400 (make-variable-buffer-local 'org-scheduled-regexp) 409 (make-variable-buffer-local 'org-scheduled-regexp)
401 (defvar org-scheduled-time-regexp nil 410 (defvar org-scheduled-time-regexp nil
402 "Matches the SCHEDULED keyword together with a time stamp.") 411 "Matches the SCHEDULED keyword together with a time stamp.")
403 (make-variable-buffer-local 'org-scheduled-time-regexp) 412 (make-variable-buffer-local 'org-scheduled-time-regexp)
404 413
405 (defun org-set-regexps () 414 (defun org-set-regexps-and-options ()
406 "Precompute regular expressions for current buffer." 415 "Precompute regular expressions for current buffer."
407 (when (eq major-mode 'org-mode) 416 (when (eq major-mode 'org-mode)
408 (let ((re (org-make-options-regexp 417 (let ((re (org-make-options-regexp
409 '("CATEGORY" "SEQ_TODO" "PRI_TODO" "TYP_TODO"))) 418 '("CATEGORY" "SEQ_TODO" "PRI_TODO" "TYP_TODO" "STARTUP")))
410 (splitre "[ \t]+") 419 (splitre "[ \t]+")
411 kwds int key value cat) 420 kwds int key value cat)
412 (save-restriction 421 (save-restriction
413 (save-excursion 422 (save-excursion
414 (widen) 423 (widen)
424 ((equal key "PRI_TODO") 433 ((equal key "PRI_TODO")
425 (setq int 'priority 434 (setq int 'priority
426 kwds (append kwds (org-split-string value splitre)))) 435 kwds (append kwds (org-split-string value splitre))))
427 ((equal key "TYP_TODO") 436 ((equal key "TYP_TODO")
428 (setq int 'type 437 (setq int 'type
429 kwds (append kwds (org-split-string value splitre))))) 438 kwds (append kwds (org-split-string value splitre))))
439 ((equal key "STARTUP")
440 (let ((opts (org-split-string value splitre))
441 (set '(("fold" org-startup-folded t)
442 ("nofold" org-startup-folded nil)
443 ("dlcheck" org-startup-with-deadline-check t)
444 ("nodlcheck" org-startup-with-deadline-check nil)))
445 l var val)
446 (while (setq l (assoc (pop opts) set))
447 (setq var (nth 1 l) val (nth 2 l))
448 (set (make-local-variable var) val)))))
430 ))) 449 )))
431 (and cat (set (make-local-variable 'org-category) cat)) 450 (and cat (set (make-local-variable 'org-category) cat))
432 (and kwds (set (make-local-variable 'org-todo-keywords) kwds)) 451 (and kwds (set (make-local-variable 'org-todo-keywords) kwds))
433 (and int (set (make-local-variable 'org-todo-interpretation) int))) 452 (and int (set (make-local-variable 'org-todo-interpretation) int)))
434 ;; Compute the regular expressions and other local variables 453 ;; Compute the regular expressions and other local variables
463 (concat "\\<" org-scheduled-string) 482 (concat "\\<" org-scheduled-string)
464 org-scheduled-time-regexp 483 org-scheduled-time-regexp
465 (concat "\\<" org-scheduled-string " *<\\([^>]+\\)>")) 484 (concat "\\<" org-scheduled-string " *<\\([^>]+\\)>"))
466 (org-set-font-lock-defaults))) 485 (org-set-font-lock-defaults)))
467 486
468 ;(add-hook 'hack-local-variables-hook 'org-set-regexps)
469
470 (defgroup org-time nil 487 (defgroup org-time nil
471 "Options concerning time stamps and deadlines in Org-mode." 488 "Options concerning time stamps and deadlines in Org-mode."
472 :tag "Org Time" 489 :tag "Org Time"
473 :group 'org) 490 :group 'org)
474 491
538 "Number of days to include in overview display." 555 "Number of days to include in overview display."
539 :group 'org-agenda 556 :group 'org-agenda
540 :type 'number) 557 :type 'number)
541 558
542 (defcustom org-agenda-include-all-todo t 559 (defcustom org-agenda-include-all-todo t
543 "Non-nil means, the multifile agenda will always contain alm TODO entries. 560 "Non-nil means, the multifile agenda will always contain all TODO entries.
544 When nil, date-less entries will only be shown if `org-agenda' is called 561 When nil, date-less entries will only be shown if `org-agenda' is called
545 with a prefix argument. 562 with a prefix argument.
546 When non-nil, the TODO entries will be listed at the top of the agenda, before 563 When non-nil, the TODO entries will be listed at the top of the agenda, before
547 the entries for specific days." 564 the entries for specific days."
548 :group 'org-agenda 565 :group 'org-agenda
636 )) 653 ))
637 654
638 (defconst org-time-stamp-formats '("<%Y-%m-%d %a>" . "<%Y-%m-%d %a %H:%M>") 655 (defconst org-time-stamp-formats '("<%Y-%m-%d %a>" . "<%Y-%m-%d %a %H:%M>")
639 "Formats for `format-time-string' which are used for time stamps. 656 "Formats for `format-time-string' which are used for time stamps.
640 It is not recommended to change this constant.") 657 It is not recommended to change this constant.")
658
659 (defcustom org-show-following-heading t
660 "Non-nil means, show heading following match in `org-occur'.
661 When doing an `org-occur' it is useful to show the headline which
662 follows the match, even if they do not match the regexp. This makes it
663 easier to edit directly inside the sparse tree. However, if you use
664 org-occur mainly as an overview, the following headlines are
665 unnecessary clutter."
666 :group 'org-structure
667 :type 'boolean)
668
669
641 670
642 (defgroup org-link nil 671 (defgroup org-link nil
643 "Options concerning links in Org-mode." 672 "Options concerning links in Org-mode."
644 :tag "Org Link" 673 :tag "Org Link"
645 :group 'org) 674 :group 'org)
843 (defgroup org-table nil 872 (defgroup org-table nil
844 "Options concerning tables in Org-mode." 873 "Options concerning tables in Org-mode."
845 :tag "Org Table" 874 :tag "Org Table"
846 :group 'org) 875 :group 'org)
847 876
848 (defcustom org-enable-table-editor t 877 (defcustom org-enable-table-editor 'optimized
849 "Non-nil means, lines starting with \"|\" are handled by the table editor. 878 "Non-nil means, lines starting with \"|\" are handled by the table editor.
850 When nil, such lines will be treated like ordinary lines." 879 When nil, such lines will be treated like ordinary lines.
880
881 When equal to the symbol `optimized', the table editor will be optimized to
882 do the following
883 - Use automatic overwrite mode in front of whitespace in table fields.
884 This make the structure of the table stay in tact as long as the edited
885 field does not exceed the column width.
886 - Minimize the number of realigns. Normally, the table is aligned each time
887 TAB or RET are pressed to move to another field. With optimization this
888 happens only if changes to a field might have changed the column width.
889 Optimization requires replacing the functions `self-insert-command',
890 `delete-char', and `backward-delete-char' in Org-mode buffers, with a
891 slight (in fact: unnoticable) speed impact for normal typing. Org-mode is
892 very good at guessing when a re-align will be necessary, but you can always
893 force one with `C-c C-c'.
894
895 I you would like to use the optimized version in Org-mode, but the un-optimized
896 version in OrgTbl-mode, see the variable `orgtbl-optimized'.
897
898 This variable can be used to turn on and off the table editor during a session,
899 but in order to toggle optimization, a restart is required."
851 :group 'org-table 900 :group 'org-table
852 :type 'boolean) 901 :type '(choice
902 (const :tag "off" nil)
903 (const :tag "on" t)
904 (const :tag "on, optimized" optimized)))
853 905
854 (defcustom org-table-default-size "5x2" 906 (defcustom org-table-default-size "5x2"
855 "The default size for newly created tables, Columns x Rows." 907 "The default size for newly created tables, Columns x Rows."
856 :group 'org-table 908 :group 'org-table
857 :type 'string) 909 :type 'string)
1293 ;; Tell the compiler about dynamically scoped variables, 1345 ;; Tell the compiler about dynamically scoped variables,
1294 ;; and variables from other packages 1346 ;; and variables from other packages
1295 (eval-when-compile 1347 (eval-when-compile
1296 (defvar zmacs-regions) 1348 (defvar zmacs-regions)
1297 (defvar org-transient-mark-mode) 1349 (defvar org-transient-mark-mode)
1350 (defvar org-old-auto-fill-inhibit-regexp)
1351 (defvar orgtbl-mode-menu)
1298 (defvar org-html-entities) 1352 (defvar org-html-entities)
1299 (defvar org-goto-start-pos) 1353 (defvar org-goto-start-pos)
1300 (defvar org-cursor-color) 1354 (defvar org-cursor-color)
1301 (defvar org-time-was-given) 1355 (defvar org-time-was-given)
1302 (defvar org-ts-what) 1356 (defvar org-ts-what)
1349 Plain text URL-like links connect to websites, emails (VM), Usenet 1403 Plain text URL-like links connect to websites, emails (VM), Usenet
1350 messages (Gnus), BBDB entries, and any files related to the project. 1404 messages (Gnus), BBDB entries, and any files related to the project.
1351 For printing and sharing of notes, an Org-mode file (or a part of it) 1405 For printing and sharing of notes, an Org-mode file (or a part of it)
1352 can be exported as a well-structured ASCII or HTML file. 1406 can be exported as a well-structured ASCII or HTML file.
1353 1407
1354 + The following commands are available: 1408 The following commands are available:
1355 1409
1356 \\{org-mode-map}" 1410 \\{org-mode-map}"
1357 (interactive "P") 1411 (interactive "P")
1358 (outline-mode) 1412 (outline-mode)
1359 (setq major-mode 'org-mode) 1413 (setq major-mode 'org-mode)
1361 (use-local-map org-mode-map) 1415 (use-local-map org-mode-map)
1362 (easy-menu-add org-org-menu) 1416 (easy-menu-add org-org-menu)
1363 (org-install-agenda-files-menu) 1417 (org-install-agenda-files-menu)
1364 (setq outline-regexp "\\*+") 1418 (setq outline-regexp "\\*+")
1365 (if org-startup-truncated (setq truncate-lines t)) 1419 (if org-startup-truncated (setq truncate-lines t))
1366 (org-set-regexps) 1420 (org-set-regexps-and-options)
1367 (set (make-local-variable 'font-lock-unfontify-region-function) 1421 (set (make-local-variable 'font-lock-unfontify-region-function)
1368 'org-unfontify-region) 1422 'org-unfontify-region)
1369 ;; Activate before-change-function 1423 ;; Activate before-change-function
1424 (set (make-local-variable 'org-table-may-need-update) t)
1425 (make-local-hook 'before-change-functions) ;; needed for XEmacs
1370 (add-hook 'before-change-functions 'org-before-change-function nil 1426 (add-hook 'before-change-functions 'org-before-change-function nil
1371 'local) 1427 'local)
1372 ;; Inhibit auto-fill for headers, tables and fixed-width lines. 1428 ;; Inhibit auto-fill for headers, tables and fixed-width lines.
1373 (set (make-local-variable 'auto-fill-inhibit-regexp) 1429 (set (make-local-variable 'auto-fill-inhibit-regexp)
1374 (concat "\\*" 1430 (concat "\\*"
1505 ;;; Visibility cycling 1561 ;;; Visibility cycling
1506 1562
1507 (defvar org-cycle-global-status nil) 1563 (defvar org-cycle-global-status nil)
1508 (defvar org-cycle-subtree-status nil) 1564 (defvar org-cycle-subtree-status nil)
1509 (defun org-cycle (&optional arg) 1565 (defun org-cycle (&optional arg)
1510 "Visibility cycling for outline(-minor)-mode. 1566 "Visibility cycling for org-mode.
1511 1567
1512 - When this function is called with a prefix argument, rotate the entire 1568 - When this function is called with a prefix argument, rotate the entire
1513 buffer through 3 states (global cycling) 1569 buffer through 3 states (global cycling)
1514 1. OVERVIEW: Show only top-level headlines. 1570 1. OVERVIEW: Show only top-level headlines.
1515 2. CONTENTS: Show all headlines of all levels, but no body text. 1571 2. CONTENTS: Show all headlines of all levels, but no body text.
1538 (cond 1594 (cond
1539 1595
1540 ((org-at-table-p 'any) 1596 ((org-at-table-p 'any)
1541 ;; Enter the table or move to the next field in the table 1597 ;; Enter the table or move to the next field in the table
1542 (or (org-table-recognize-table.el) 1598 (or (org-table-recognize-table.el)
1543 (org-table-next-field))) 1599 (progn
1600 (org-table-justify-field-maybe)
1601 (org-table-next-field))))
1544 1602
1545 (arg ;; Global cycling 1603 (arg ;; Global cycling
1546 1604
1547 (cond 1605 (cond
1548 ((and (eq last-command this-command) 1606 ((and (eq last-command this-command)
1763 ;;; Promotion, Demotion, Inserting new headlines 1821 ;;; Promotion, Demotion, Inserting new headlines
1764 1822
1765 (defvar org-ignore-region nil 1823 (defvar org-ignore-region nil
1766 "To temporary disable the active region.") 1824 "To temporary disable the active region.")
1767 1825
1768 (defun org-insert-heading () 1826 (defun org-insert-heading (arg)
1769 "Insert a new heading with same depth at point." 1827 "Insert a new heading with same depth at point."
1770 (interactive) 1828 (interactive "P")
1771 (let* ((head (save-excursion 1829 (let* ((head (save-excursion
1772 (condition-case nil 1830 (condition-case nil
1773 (org-back-to-heading) 1831 (org-back-to-heading)
1774 (error (outline-next-heading))) 1832 (error (outline-next-heading)))
1775 (prog1 (match-string 0) 1833 (prog1 (match-string 0)
2269 (org-show-hierarchy-above)))) 2327 (org-show-hierarchy-above))))
2270 (if (interactive-p) 2328 (if (interactive-p)
2271 (message "%d match(es) for regexp %s" cnt regexp)) 2329 (message "%d match(es) for regexp %s" cnt regexp))
2272 cnt)) 2330 cnt))
2273 2331
2274
2275 (defun org-show-hierarchy-above () 2332 (defun org-show-hierarchy-above ()
2276 "Make sure point and the headings hierarchy above is visible." 2333 "Make sure point and the headings hierarchy above is visible."
2277 (if (org-on-heading-p t) 2334 (if (org-on-heading-p t)
2278 (org-flag-heading nil) ; only show the heading 2335 (org-flag-heading nil) ; only show the heading
2279 (org-show-hidden-entry)) ; show entire entry 2336 (org-show-hidden-entry)) ; show entire entry
2280 (save-excursion 2337 (save-excursion
2281 (and (outline-next-heading) 2338 (and org-show-following-heading
2339 (outline-next-heading)
2282 (org-flag-heading nil))) ; show the next heading 2340 (org-flag-heading nil))) ; show the next heading
2283 (save-excursion ; show all higher headings 2341 (save-excursion ; show all higher headings
2284 (while (condition-case nil 2342 (while (condition-case nil
2285 (progn (org-up-heading-all 1) t) 2343 (progn (org-up-heading-all 1) t)
2286 (error nil)) 2344 (error nil))
2359 with a prefix argument, the time stamp will contain date and time. 2417 with a prefix argument, the time stamp will contain date and time.
2360 Otherwise, only the date will be included. All parts of a date not 2418 Otherwise, only the date will be included. All parts of a date not
2361 specified by the user will be filled in from the current date/time. 2419 specified by the user will be filled in from the current date/time.
2362 So if you press just return without typing anything, the time stamp 2420 So if you press just return without typing anything, the time stamp
2363 will represent the current date/time. If there is already a timestamp 2421 will represent the current date/time. If there is already a timestamp
2364 at the cursoe, it will be modified." 2422 at the cursor, it will be modified."
2365 (interactive "P") 2423 (interactive "P")
2366 (let ((fmt (if arg (cdr org-time-stamp-formats) 2424 (let ((fmt (if arg (cdr org-time-stamp-formats)
2367 (car org-time-stamp-formats))) 2425 (car org-time-stamp-formats)))
2368 (org-time-was-given nil) 2426 (org-time-was-given nil)
2369 time) 2427 time)
2796 (defvar org-agenda-buffer-name "*Org Agenda*") 2854 (defvar org-agenda-buffer-name "*Org Agenda*")
2797 (defvar org-agenda-redo-command nil) 2855 (defvar org-agenda-redo-command nil)
2798 2856
2799 ;;;###autoload 2857 ;;;###autoload
2800 (defun org-agenda-mode () 2858 (defun org-agenda-mode ()
2801 "Mode for time-sorted view on action items in Org-mode files." 2859 "Mode for time-sorted view on action items in Org-mode files.
2860
2861 The following commands are available:
2862
2863 \\{org-agenda-mode-map}"
2802 (interactive) 2864 (interactive)
2803 (kill-all-local-variables) 2865 (kill-all-local-variables)
2804 (setq major-mode 'org-agenda-mode) 2866 (setq major-mode 'org-agenda-mode)
2805 (setq mode-name "Org-Agenda") 2867 (setq mode-name "Org-Agenda")
2806 (use-local-map org-agenda-mode-map) 2868 (use-local-map org-agenda-mode-map)
3116 (message ""))) 3178 (message "")))
3117 3179
3118 (defun org-check-agenda-file (file) 3180 (defun org-check-agenda-file (file)
3119 "Make sure FILE exists. If not, ask user what to do." 3181 "Make sure FILE exists. If not, ask user what to do."
3120 ;; FIXME: this does not correctly change the menus 3182 ;; FIXME: this does not correctly change the menus
3121 ;; Could be fixed by explicitly going to the buffer, maybe. 3183 ;; Could probably be fixed by explicitly going to the buffer.
3122 (when (not (file-exists-p file)) 3184 (when (not (file-exists-p file))
3123 (message "non-existent file %s. [R]emove from agenda-files or [A]bort?" 3185 (message "non-existent file %s. [R]emove from agenda-files or [A]bort?"
3124 file) 3186 file)
3125 (let ((r (downcase (read-char-exclusive)))) 3187 (let ((r (downcase (read-char-exclusive))))
3126 (cond 3188 (cond
4505 UP/DOWN=headline TAB=cycle visibility [Q]uit RET/<left>/<right>=Store 4567 UP/DOWN=headline TAB=cycle visibility [Q]uit RET/<left>/<right>=Store
4506 RET at beg-of-buf -> Append to file as level 2 headline 4568 RET at beg-of-buf -> Append to file as level 2 headline
4507 RET on headline -> Store as sublevel entry to current headline 4569 RET on headline -> Store as sublevel entry to current headline
4508 <left>/<right> -> before/after current headline, same headings level") 4570 <left>/<right> -> before/after current headline, same headings level")
4509 4571
4510 ;; FIXME: Document C-u C-c C-c
4511 ;;;###autoload 4572 ;;;###autoload
4512 (defun org-remember-handler () 4573 (defun org-remember-handler ()
4513 "Store stuff from remember.el into an org file. 4574 "Store stuff from remember.el into an org file.
4514 First prompts for an org file. If the user just presses return, the value 4575 First prompts for an org file. If the user just presses return, the value
4515 of `org-default-notes-file' is used. 4576 of `org-default-notes-file' is used.
4793 (goto-char (point-min)) 4854 (goto-char (point-min))
4794 (while (re-search-forward "[ \t]*|[ \t]*" nil t) 4855 (while (re-search-forward "[ \t]*|[ \t]*" nil t)
4795 (replace-match "\t" t t)) 4856 (replace-match "\t" t t))
4796 (save-buffer)) 4857 (save-buffer))
4797 (kill-buffer buf))) 4858 (kill-buffer buf)))
4859
4860 (defvar org-table-aligned-begin-marker (make-marker)
4861 "Marker at the beginning of the table last aligned.
4862 Used to check if cursor still is in that table, to minimize realignment.")
4863 (defvar org-table-aligned-end-marker (make-marker)
4864 "Marker at the end of the table last aligned.
4865 Used to check if cursor still is in that table, to minimize realignment.")
4866 (defvar org-table-last-alignment nil
4867 "List of flags for flushright alignment, from the last re-algnment.
4868 This is being used to correctly align a single field after TAB or RET.")
4869 ;; FIXME: The following is currently not used.
4870 (defvar org-table-last-column-widths nil
4871 "List of max width of ffields in each column.
4872 This is being used to correctly align a single field after TAB or RET.")
4873
4798 4874
4799 (defun org-table-align (&optional arg) 4875 (defun org-table-align (&optional arg)
4800 "Align the table at point by aligning all vertical bars." 4876 "Align the table at point by aligning all vertical bars."
4801 (interactive "P") 4877 (interactive "P")
4802 (let* ( 4878 (let* (
4864 (setq cnt (1+ cnt)))))) 4940 (setq cnt (1+ cnt))))))
4865 column) 4941 column)
4866 (push (>= frac org-table-number-fraction) typenums)) 4942 (push (>= frac org-table-number-fraction) typenums))
4867 (setq lengths (nreverse lengths) 4943 (setq lengths (nreverse lengths)
4868 typenums (nreverse typenums)) 4944 typenums (nreverse typenums))
4945 (setq org-table-last-alignment typenums
4946 org-table-last-column-widths lengths)
4869 ;; Compute the formats needed for output of the table 4947 ;; Compute the formats needed for output of the table
4870 (setq rfmt (concat indent "|") hfmt (concat indent "|")) 4948 (setq rfmt (concat indent "|") hfmt (concat indent "|"))
4871 (while (setq l (pop lengths)) 4949 (while (setq l (pop lengths))
4872 (setq ty (if (pop typenums) "" "-")) ; number types flushright 4950 (setq ty (if (pop typenums) "" "-")) ; number types flushright
4873 (setq rfmt (concat rfmt (format rfmt1 ty l)) 4951 (setq rfmt (concat rfmt (format rfmt1 ty l))
4882 (append (pop fields) emptystrings)))) 4960 (append (pop fields) emptystrings))))
4883 (setq new (concat new hfmt)))) 4961 (setq new (concat new hfmt))))
4884 ;; Replace the old one 4962 ;; Replace the old one
4885 (delete-region beg end) 4963 (delete-region beg end)
4886 (move-marker end nil) 4964 (move-marker end nil)
4965 (move-marker org-table-aligned-begin-marker (point))
4887 (insert new) 4966 (insert new)
4967 (move-marker org-table-aligned-end-marker (point))
4888 ;; Try to move to the old location (approximately) 4968 ;; Try to move to the old location (approximately)
4889 (goto-line linepos) 4969 (goto-line linepos)
4890 (set-window-start (selected-window) winstart 'noforce) 4970 (set-window-start (selected-window) winstart 'noforce)
4891 (org-table-goto-column colpos) 4971 (org-table-goto-column colpos)
4892 (setq org-table-may-need-update nil) 4972 (setq org-table-may-need-update nil)
4893 ;; (message "Aligning table...done")
4894 (if (org-in-invisibility-spec-p '(org-table)) 4973 (if (org-in-invisibility-spec-p '(org-table))
4895 (org-table-add-invisible-to-vertical-lines)) 4974 (org-table-add-invisible-to-vertical-lines))
4896 )) 4975 ))
4897 4976
4898 (defun org-table-begin (&optional table-type) 4977 (defun org-table-begin (&optional table-type)
4917 org-table-border-regexp) 4996 org-table-border-regexp)
4918 nil t)) 4997 nil t))
4919 (goto-char (point-max)) 4998 (goto-char (point-max))
4920 (goto-char (match-beginning 0))) 4999 (goto-char (match-beginning 0)))
4921 (point-marker))) 5000 (point-marker)))
5001
5002 (defun org-table-justify-field-maybe ()
5003 "Justify the current field, text to left, number to right."
5004 (cond
5005 (org-table-may-need-update) ; Realignment will happen anyway, don't bother
5006 ((org-at-table-hline-p)
5007 ;; This is pretty stupid, but I don't know how to deal with hlines
5008 (setq org-table-may-need-update t))
5009 ((or (not (equal (marker-buffer org-table-aligned-begin-marker)
5010 (current-buffer)))
5011 (< (point) org-table-aligned-begin-marker)
5012 (>= (point) org-table-aligned-end-marker))
5013 ;; This is not the same table, force a full re-align
5014 (setq org-table-may-need-update t))
5015 (t ;; realign the current field, based on previous full realign
5016 (let* ((pos (point)) s org-table-may-need-update
5017 (col (org-table-current-column))
5018 (num (nth (1- col) org-table-last-alignment))
5019 l f)
5020 (when (> col 0)
5021 (skip-chars-backward "^|\n")
5022 (if (looking-at " *\\([^|\n]*?\\) *|")
5023 (progn
5024 (setq s (match-string 1)
5025 l (max 1 (- (match-end 0) (match-beginning 0) 3)))
5026 (setq f (format (if num " %%%ds |" " %%-%ds |") l))
5027 (replace-match (format f s t t)))
5028 (setq org-table-may-need-update t))
5029 (goto-char pos))))))
4922 5030
4923 (defun org-table-next-field (&optional arg) 5031 (defun org-table-next-field (&optional arg)
4924 "Go to the next field in the current table. 5032 "Go to the next field in the current table.
4925 Before doing so, re-align the table if necessary." 5033 Before doing so, re-align the table if necessary."
4926 (interactive "P") 5034 (interactive "P")
5011 (org-at-table-hline-p) 5119 (org-at-table-hline-p)
5012 (looking-at "[ \t]*$")) 5120 (looking-at "[ \t]*$"))
5013 (error "Not in table data field"))) 5121 (error "Not in table data field")))
5014 5122
5015 (defun org-table-blank-field () 5123 (defun org-table-blank-field ()
5016 "Blank the current table field." 5124 "Blank the current table field or active region."
5017 (interactive) 5125 (interactive)
5018 (org-table-check-inside-data-field) 5126 (org-table-check-inside-data-field)
5019 (skip-chars-backward "^|") 5127 (if (and (interactive-p) (org-region-active-p))
5020 (backward-char 1) 5128 (let (org-table-clip)
5021 (if (looking-at "|[^|]+") 5129 (org-table-cut-region))
5022 (let* ((pos (match-beginning 0)) 5130 (skip-chars-backward "^|")
5023 (match (match-string 0)) 5131 (backward-char 1)
5024 (len (length match))) 5132 (if (looking-at "|[^|]+")
5025 (replace-match (concat "|" (make-string (1- len) ?\ ))) 5133 (let* ((pos (match-beginning 0))
5026 (goto-char (+ 2 pos)) 5134 (match (match-string 0))
5027 (substring match 1)))) 5135 (len (length match)))
5136 (replace-match (concat "|" (make-string (1- len) ?\ )))
5137 (goto-char (+ 2 pos))
5138 (substring match 1)))))
5028 5139
5029 (defun org-table-get-field (&optional n replace) 5140 (defun org-table-get-field (&optional n replace)
5030 "Return the value of the field in column N of current row. 5141 "Return the value of the field in column N of current row.
5031 N defaults to current field. 5142 N defaults to current field.
5032 If REPLACE is a string, replace field with this value. The return value 5143 If REPLACE is a string, replace field with this value. The return value
5196 (beginning-of-line 2)) 5307 (beginning-of-line 2))
5197 (move-marker end nil) 5308 (move-marker end nil)
5198 (goto-line linepos) 5309 (goto-line linepos)
5199 (org-table-goto-column colpos)) 5310 (org-table-goto-column colpos))
5200 (org-table-align)) 5311 (org-table-align))
5312
5313 (defun org-table-move-column-right ()
5314 "Move column to the right."
5315 (interactive)
5316 (org-table-move-column nil))
5317 (defun org-table-move-column-left ()
5318 "Move column to the left."
5319 (interactive)
5320 (org-table-move-column 'left))
5201 5321
5202 (defun org-table-move-column (&optional left) 5322 (defun org-table-move-column (&optional left)
5203 "Move the current column to the right. With arg LEFT, move to the left." 5323 "Move the current column to the right. With arg LEFT, move to the left."
5204 (interactive "P") 5324 (interactive "P")
5205 (if (not (org-at-table-p)) 5325 (if (not (org-at-table-p))
5228 (move-marker end nil) 5348 (move-marker end nil)
5229 (goto-line linepos) 5349 (goto-line linepos)
5230 (org-table-goto-column colpos)) 5350 (org-table-goto-column colpos))
5231 (org-table-align)) 5351 (org-table-align))
5232 5352
5353 (defun org-table-move-row-down ()
5354 "Move table row down."
5355 (interactive)
5356 (org-table-move-row nil))
5357 (defun org-table-move-row-up ()
5358 "Move table row down."
5359 (interactive)
5360 (org-table-move-row 'up))
5361
5233 (defun org-table-move-row (&optional up) 5362 (defun org-table-move-row (&optional up)
5234 "Move the current table line down. With arg UP, move it up." 5363 "Move the current table line down. With arg UP, move it up."
5235 (interactive "P") 5364 (interactive "P")
5236 (let ((col (current-column)) 5365 (let ((col (current-column))
5237 (pos (point)) 5366 (pos (point))
5261 (let ((line (buffer-substring-no-properties (point-at-bol) (point-at-eol)))) 5390 (let ((line (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
5262 (if (string-match "^[ \t]*|-" line) 5391 (if (string-match "^[ \t]*|-" line)
5263 (setq line (mapcar (lambda (x) (if (member x '(?| ?+)) ?| ?\ )) line)) 5392 (setq line (mapcar (lambda (x) (if (member x '(?| ?+)) ?| ?\ )) line))
5264 (setq line (mapcar (lambda (x) (if (equal x ?|) ?| ?\ )) line))) 5393 (setq line (mapcar (lambda (x) (if (equal x ?|) ?| ?\ )) line)))
5265 (beginning-of-line (if arg 2 1)) 5394 (beginning-of-line (if arg 2 1))
5266 (apply 'insert line) 5395 (let (org-table-may-need-update)
5267 (insert "\n") 5396 (apply 'insert-before-markers line)
5397 (insert-before-markers "\n"))
5268 (beginning-of-line 0) 5398 (beginning-of-line 0)
5269 (re-search-forward "| ?" (point-at-eol) t) 5399 (re-search-forward "| ?" (point-at-eol) t)
5270 (org-table-align))) 5400 (and org-table-may-need-update (org-table-align))))
5271 5401
5272 (defun org-table-insert-hline (&optional arg) 5402 (defun org-table-insert-hline (&optional arg)
5273 "Insert a horizontal-line below the current line into the table. 5403 "Insert a horizontal-line below the current line into the table.
5274 With prefix ARG, insert above the current line." 5404 With prefix ARG, insert above the current line."
5275 (interactive "P") 5405 (interactive "P")
5785 (insert ev)) 5915 (insert ev))
5786 (if (and down (> ndown 0) (looking-at ".*\n[ \t]*|[^-]")) 5916 (if (and down (> ndown 0) (looking-at ".*\n[ \t]*|[^-]"))
5787 (call-interactively 'org-return) 5917 (call-interactively 'org-return)
5788 (setq ndown 0))) 5918 (setq ndown 0)))
5789 (org-table-align))) 5919 (org-table-align)))
5920
5921 ;;; The orgtbl minor mode
5922
5923 ;; Define a minor mode which can be used in other modes in order to
5924 ;; integrate the org-mode table editor.
5925
5926 ;; This is really a hack, because the org-mode table editor uses several
5927 ;; keys which normally belong to the major mode, for example the TAB and
5928 ;; RET keys. Here is how it works: The minor mode defines all the keys
5929 ;; necessary to operate the table editor, but wraps the commands into a
5930 ;; function which tests if the cursor is currently inside a table. If that
5931 ;; is the case, the table editor command is executed. However, when any of
5932 ;; those keys is used outside a table, the function uses `key-binding' to
5933 ;; look up if the key has an associated command in another currently active
5934 ;; keymap (minor modes, major mode, global), and executes that command.
5935 ;; There might be problems if any of the keys used by the table editor is
5936 ;; otherwise used as a prefix key.
5937
5938 ;; Another challenge is that the key binding for TAB can be tab or \C-i,
5939 ;; likewise the binding for RET can be return or \C-m. Orgtbl-mode
5940 ;; addresses this by checking explicitly for both bindings.
5941
5942 ;; The optimized version (see variable `orgtbl-optimized') takes over
5943 ;; all keys which are bound to `self-insert-command' in the *global map*.
5944 ;; Some modes bind other commands to simple characters, for example
5945 ;; AUCTeX binds the double quote to `Tex-insert-quote'. With orgtbl-mode
5946 ;; active, this binding is ignored inside tables and replaced with a
5947 ;; modified self-insert.
5948
5949 (defcustom orgtbl-optimized (eq org-enable-table-editor 'optimized)
5950 "Non-nil means, use the optimized table editor version for orgtbl-mode.
5951 In the optimized version, the table editor takes over all simple keys that
5952 normally just insert a character. In tables, the characters are inserted
5953 in a way to minimize disturbing the table structure (i.e. in overwrite mode
5954 for empty fields). Outside tables, the correct binding of the keys is
5955 restored.
5956
5957 The default for this option is t if the optimized version is also used in
5958 Org-mode. See the variable `org-enable-table-editor' for details. Changing
5959 this variable requires a restart of Emacs to become effective."
5960 :group 'org-table
5961 :type 'boolean)
5962
5963 (defvar orgtbl-mode nil
5964 "Variable controlling orgtbl-mode, a minor mode enabling the org-mode
5965 table editor iin arbitrary modes.")
5966 (make-variable-buffer-local 'orgtbl-mode)
5967
5968 (defvar orgtbl-mode-map (make-sparse-keymap)
5969 "Keymap for orgtbl-mode.")
5970
5971 ;;;###autoload
5972 (defun turn-on-orgtbl ()
5973 "Unconditionally turn on orgtbl-mode."
5974 (orgtbl-mode 1))
5975
5976 ;;;###autoload
5977 (defun orgtbl-mode (&optional arg)
5978 "The org-mode table editor as a minor mode for use in other modes."
5979 (interactive)
5980 (setq orgtbl-mode
5981 (if arg (> (prefix-numeric-value arg) 0) (not orgtbl-mode)))
5982 (if orgtbl-mode
5983 (progn
5984 (set (make-local-variable (quote org-table-may-need-update)) t)
5985 (make-local-hook (quote before-change-functions))
5986 (add-hook 'before-change-functions 'org-before-change-function
5987 nil 'local)
5988 (set (make-local-variable 'org-old-auto-fill-inhibit-regexp)
5989 auto-fill-inhibit-regexp)
5990 (set (make-local-variable 'auto-fill-inhibit-regexp)
5991 (if auto-fill-inhibit-regexp
5992 (concat "\\([ \t]*|\\|" auto-fill-inhibit-regexp)
5993 "[ \t]*|"))
5994 (easy-menu-add orgtbl-mode-menu)
5995 (run-hooks (quote orgtbl-mode-hook)))
5996 (setq auto-fill-inhibit-regexp org-old-auto-fill-inhibit-regexp)
5997 (remove-hook 'before-change-functions 'org-before-change-function t)
5998 (easy-menu-remove orgtbl-mode-menu)
5999 (force-mode-line-update 'all)))
6000
6001 ;; Install it as a minor mode.
6002 (put 'orgtbl-mode :included t)
6003 (put 'orgtbl-mode :menu-tag "Org Table Mode")
6004 (add-minor-mode 'orgtbl-mode " OrgTbl" orgtbl-mode-map)
6005
6006 (defun orgtbl-make-binding (fun &rest keys)
6007 "Create a function for binding in the table minor mode."
6008 (list 'lambda '(arg) '(interactive "p")
6009 (list 'if
6010 '(org-at-table-p)
6011 (list 'call-interactively (list 'quote fun))
6012 (list 'let '(orgtbl-mode)
6013 (list 'call-interactively
6014 (append '(or)
6015 (mapcar (lambda (k)
6016 (list 'key-binding k))
6017 keys)
6018 '('orgtbl-error)))))))
6019
6020 (defun orgtbl-error ()
6021 "Error when there is no default binding for a table key."
6022 (interactive)
6023 (error "This key is has no function outside tables"))
6024
6025 ;; Keybindings for the minor mode
6026 (let ((bindings
6027 '(([(meta shift left)] org-table-delete-column)
6028 ([(meta left)] org-table-move-column-left)
6029 ([(meta right)] org-table-move-column-right)
6030 ([(meta shift right)] org-table-insert-column)
6031 ([(meta shift up)] org-table-kill-row)
6032 ([(meta shift down)] org-table-insert-row)
6033 ([(meta up)] org-table-move-row-up)
6034 ([(meta down)] org-table-move-row-down)
6035 ("\C-c\C-w" org-table-cut-region)
6036 ("\C-c\M-w" org-table-copy-region)
6037 ("\C-c\C-y" org-table-paste-rectangle)
6038 ("\C-c-" org-table-insert-hline)
6039 ([(shift tab)] org-table-previous-field)
6040 ("\C-c\C-c" org-table-align)
6041 ([(return)] org-table-next-row)
6042 ([(shift return)] org-table-copy-from-above)
6043 ([(meta return)] org-table-wrap-region)
6044 ("\C-c\C-q" org-table-wrap-region)
6045 ("\C-c?" org-table-current-column)
6046 ("\C-c " org-table-blank-field)
6047 ("\C-c+" org-table-sum)
6048 ("\C-c|" org-table-toggle-vline-visibility)
6049 ("\C-c=" org-table-eval-formula)))
6050 elt key fun cmd)
6051 (while (setq elt (pop bindings))
6052 (setq key (car elt)
6053 fun (nth 1 elt)
6054 cmd (orgtbl-make-binding fun key))
6055 (define-key orgtbl-mode-map key cmd)))
6056
6057 ;; Special treatment needed for TAB and RET
6058 ;(define-key orgtbl-mode-map [(return)]
6059 ; (orgtbl-make-binding 'org-table-next-row [(return)] "\C-m"))
6060 ;(define-key orgtbl-mode-map "\C-m"
6061 ; (orgtbl-make-binding 'org-table-next-row "\C-m" [(return)]))
6062 ;(define-key orgtbl-mode-map [(tab)]
6063 ; (orgtbl-make-binding 'org-table-next-field [(tab)] "\C-i"))
6064 ;(define-key orgtbl-mode-map "\C-i"
6065 ; (orgtbl-make-binding 'org-table-next-field "\C-i" [(tab)]))
6066
6067 (define-key orgtbl-mode-map [(return)]
6068 (orgtbl-make-binding 'orgtbl-ret [(return)] "\C-m"))
6069 (define-key orgtbl-mode-map "\C-m"
6070 (orgtbl-make-binding 'orgtbl-ret "\C-m" [(return)]))
6071 (define-key orgtbl-mode-map [(tab)]
6072 (orgtbl-make-binding 'orgtbl-tab [(tab)] "\C-i"))
6073 (define-key orgtbl-mode-map "\C-i"
6074 (orgtbl-make-binding 'orgtbl-tab "\C-i" [(tab)]))
6075
6076 (when orgtbl-optimized
6077 ;; If the user wants maximum table support, we need to hijack
6078 ;; some standard editing functions
6079 (substitute-key-definition 'self-insert-command 'orgtbl-self-insert-command
6080 orgtbl-mode-map global-map)
6081 (substitute-key-definition 'delete-char 'orgtbl-delete-char
6082 orgtbl-mode-map global-map)
6083 (substitute-key-definition 'delete-backward-char 'orgtbl-delete-backward-char
6084 orgtbl-mode-map global-map)
6085 (define-key org-mode-map "|" 'self-insert-command))
6086
6087 (defun orgtbl-tab ()
6088 "Justification and field motion for orgtbl-mode."
6089 (interactive)
6090 (org-table-justify-field-maybe)
6091 (org-table-next-field))
6092
6093 (defun orgtbl-ret ()
6094 "Justification and field motion for orgtbl-mode."
6095 (interactive)
6096 (org-table-justify-field-maybe)
6097 (org-table-next-row))
6098
6099 (defun orgtbl-self-insert-command (N)
6100 "Like `self-insert-command', use overwrite-mode for whitespace in tables.
6101 If the cursor is in a table looking at whitespace, the whitespace is
6102 overwritten, and the table is not marked as requiring realignment."
6103 (interactive "p")
6104 (if (and (org-at-table-p)
6105 (eq N 1)
6106 (looking-at "[^|\n]* +|"))
6107 (let (org-table-may-need-update (pos (point)))
6108 (goto-char (1- (match-end 0)))
6109 (delete-backward-char 1)
6110 (goto-char (match-beginning 0))
6111 (self-insert-command N))
6112 (setq org-table-may-need-update t)
6113 (let (orgtbl-mode)
6114 (call-interactively (key-binding (vector last-input-event))))))
6115
6116 (defun orgtbl-delete-backward-char (N)
6117 "Like `delete-backward-char', insert whitespace at field end in tables.
6118 When deleting backwards, in tables this function will insert whitespace in
6119 front of the next \"|\" separator, to keep the table aligned. The table will
6120 still be marked for re-alignment, because a narrow field may lead to a
6121 reduced column width."
6122 (interactive "p")
6123 (if (and (org-at-table-p)
6124 (eq N 1)
6125 (looking-at ".*?|"))
6126 (let ((pos (point)))
6127 (backward-delete-char N)
6128 (skip-chars-forward "^|")
6129 (insert " ")
6130 (goto-char (1- pos)))
6131 (message "%s" last-input-event) (sit-for 1)
6132 (delete-backward-char N)))
6133
6134 (defun orgtbl-delete-char (N)
6135 "Like `delete-char', but insert whitespace at field end in tables.
6136 When deleting characters, in tables this function will insert whitespace in
6137 front of the next \"|\" separator, to keep the table aligned. The table
6138 will still be marked for re-alignment, because a narrow field may lead to
6139 a reduced column width."
6140 (interactive "p")
6141 (if (and (org-at-table-p)
6142 (eq N 1))
6143 (if (looking-at ".*?|")
6144 (let ((pos (point)))
6145 (replace-match (concat
6146 (substring (match-string 0) 1 -1)
6147 " |"))
6148 (goto-char pos)))
6149 (delete-char N)))
6150
6151 (easy-menu-define orgtbl-mode-menu orgtbl-mode-map "OrgTbl menu"
6152 '("Tbl"
6153 ["Align" org-ctrl-c-ctrl-c :active (org-at-table-p) :keys "C-c C-c"]
6154 ["Next field" org-cycle :active (org-at-table-p) :keys "TAB"]
6155 ["Previous Field" org-shifttab :active (org-at-table-p) :keys "S-TAB"]
6156 ["Next row" org-return :active (org-at-table-p) :keys "RET"]
6157 "--"
6158 ["Blank field" org-table-blank-field :active (org-at-table-p) :keys "C-c SPC"]
6159 ["Copy field from above"
6160 org-table-copy-from-above :active (org-at-table-p) :keys "S-RET"]
6161 "--"
6162 ("Column"
6163 ["Move column left" org-metaleft :active (org-at-table-p) :keys "M-<left>"]
6164 ["Move column right" org-metaright :active (org-at-table-p) :keys "M-<right>"]
6165 ["Delete column" org-shiftmetaleft :active (org-at-table-p) :keys "M-S-<left>"]
6166 ["Insert column" org-shiftmetaright :active (org-at-table-p) :keys "M-S-<right>"])
6167 ("Row"
6168 ["Move row up" org-metaup :active (org-at-table-p) :keys "M-<up>"]
6169 ["Move row down" org-metadown :active (org-at-table-p) :keys "M-<down>"]
6170 ["Delete row" org-shiftmetaup :active (org-at-table-p) :keys "M-S-<up>"]
6171 ["Insert row" org-shiftmetadown :active (org-at-table-p) :keys "M-S-<down>"]
6172 "--"
6173 ["Insert hline" org-table-insert-hline :active (org-at-table-p) :keys "C-c -"])
6174 ("Rectangle"
6175 ["Copy rectangle" org-copy-special :active (org-at-table-p) :keys "C-c M-w"]
6176 ["Cut rectangle" org-cut-special :active (org-at-table-p) :keys "C-c C-w"]
6177 ["Paste rectangle" org-paste-special :active (org-at-table-p) :keys "C-c C-y"]
6178 ["Fill rectangle" org-table-wrap-region :active (org-at-table-p) :keys "C-c C-q"])
6179 "--"
6180 ["Which column?" org-table-current-column :active (org-at-table-p) :keys "C-c ?"]
6181 ["Sum column/rectangle" org-table-sum
6182 :active (or (org-at-table-p) (org-region-active-p)) :keys "C-c +"]
6183 ["Eval formula" org-table-eval-formula :active (org-at-table-p) :keys "C-c ="]
6184 ))
5790 6185
5791 ;;; Exporting 6186 ;;; Exporting
5792 6187
5793 (defconst org-level-max 20) 6188 (defconst org-level-max 20)
5794 6189
6298 #+TEXT: Some descriptive text to be emitted. Several lines OK. 6693 #+TEXT: Some descriptive text to be emitted. Several lines OK.
6299 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s *:%s TeX:%s 6694 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s *:%s TeX:%s
6300 #+CATEGORY: %s 6695 #+CATEGORY: %s
6301 #+SEQ_TODO: %s 6696 #+SEQ_TODO: %s
6302 #+TYP_TODO: %s 6697 #+TYP_TODO: %s
6698 #+STARTUP: %s %s
6303 " 6699 "
6304 (buffer-name) (user-full-name) user-mail-address org-export-default-language 6700 (buffer-name) (user-full-name) user-mail-address org-export-default-language
6305 org-export-headline-levels 6701 org-export-headline-levels
6306 org-export-with-section-numbers 6702 org-export-with-section-numbers
6307 org-export-with-toc 6703 org-export-with-toc
6316 (if (equal org-todo-interpretation 'sequence) 6712 (if (equal org-todo-interpretation 'sequence)
6317 (mapconcat 'identity org-todo-keywords " ") 6713 (mapconcat 'identity org-todo-keywords " ")
6318 "TODO FEEDBACK VERIFY DONE") 6714 "TODO FEEDBACK VERIFY DONE")
6319 (if (equal org-todo-interpretation 'type) 6715 (if (equal org-todo-interpretation 'type)
6320 (mapconcat 'identity org-todo-keywords " ") 6716 (mapconcat 'identity org-todo-keywords " ")
6321 "Me Jason Marie DONE"))) 6717 "Me Jason Marie DONE")
6718 (if org-startup-folded "fold" "nofold")
6719 (if org-startup-with-deadline-check "dlcheck" "nodlcheck")
6720 ))
6322 6721
6323 (defun org-insert-export-options-template () 6722 (defun org-insert-export-options-template ()
6324 "Insert into the buffer a template with information for exporting." 6723 "Insert into the buffer a template with information for exporting."
6325 (interactive) 6724 (interactive)
6326 (if (not (bolp)) (newline)) 6725 (if (not (bolp)) (newline))
7023 (define-key org-mode-map [S-iso-lefttab] 'org-shifttab)) 7422 (define-key org-mode-map [S-iso-lefttab] 'org-shifttab))
7024 (define-key org-mode-map [(shift tab)] 'org-shifttab) 7423 (define-key org-mode-map [(shift tab)] 'org-shifttab)
7025 (define-key org-mode-map "\C-c\C-c" 'org-ctrl-c-ctrl-c) 7424 (define-key org-mode-map "\C-c\C-c" 'org-ctrl-c-ctrl-c)
7026 (define-key org-mode-map [(return)] 'org-return) 7425 (define-key org-mode-map [(return)] 'org-return)
7027 (define-key org-mode-map [(shift return)] 'org-table-copy-from-above) 7426 (define-key org-mode-map [(shift return)] 'org-table-copy-from-above)
7427 (define-key org-mode-map [(meta return)] 'org-meta-return)
7028 (define-key org-mode-map [(control up)] 'org-move-line-up) 7428 (define-key org-mode-map [(control up)] 'org-move-line-up)
7029 (define-key org-mode-map [(control down)] 'org-move-line-down) 7429 (define-key org-mode-map [(control down)] 'org-move-line-down)
7030 (define-key org-mode-map "\C-c?" 'org-table-current-column) 7430 (define-key org-mode-map "\C-c?" 'org-table-current-column)
7031 (define-key org-mode-map "\C-c " 'org-table-blank-field) 7431 (define-key org-mode-map "\C-c " 'org-table-blank-field)
7032 (define-key org-mode-map "\C-c+" 'org-table-sum) 7432 (define-key org-mode-map "\C-c+" 'org-table-sum)
7038 (define-key org-mode-map "\C-c\C-x\C-a" 'org-export-as-ascii) 7438 (define-key org-mode-map "\C-c\C-x\C-a" 'org-export-as-ascii)
7039 (define-key org-mode-map "\C-c\C-xt" 'org-insert-export-options-template) 7439 (define-key org-mode-map "\C-c\C-xt" 'org-insert-export-options-template)
7040 (define-key org-mode-map "\C-c:" 'org-toggle-fixed-width-section) 7440 (define-key org-mode-map "\C-c:" 'org-toggle-fixed-width-section)
7041 (define-key org-mode-map "\C-c\C-xh" 'org-export-as-html) 7441 (define-key org-mode-map "\C-c\C-xh" 'org-export-as-html)
7042 (define-key org-mode-map "\C-c\C-x\C-h" 'org-export-as-html-and-open) 7442 (define-key org-mode-map "\C-c\C-x\C-h" 'org-export-as-html-and-open)
7443
7444
7445 ;; FIXME: Do we really need to save match data in these commands?
7446 ;; I would like to remove it in order to minimize impact.
7447 ;; Self-insert already does not preserve it. How much resources does this take???
7448
7449 (defsubst org-table-p ()
7450 (if (and (eq major-mode 'org-mode) font-lock-mode)
7451 (eq (get-text-property (point) 'face) 'org-table-face)
7452 (save-match-data (org-at-table-p))))
7453
7454 (defun org-self-insert-command (N)
7455 "Like `self-insert-command', use overwrite-mode for whitespace in tables.
7456 If the cursor is in a table looking at whitespace, the whitespace is
7457 overwritten, and the table is not marked as requiring realignment."
7458 (interactive "p")
7459 (if (and (org-table-p)
7460 (eq N 1)
7461 (looking-at "[^|\n]* +|"))
7462 (let (org-table-may-need-update (pos (point)))
7463 (goto-char (1- (match-end 0)))
7464 (delete-backward-char 1)
7465 (goto-char (match-beginning 0))
7466 (self-insert-command N))
7467 (setq org-table-may-need-update t)
7468 (self-insert-command N)))
7469
7470 ;; FIXME:
7471 ;; The following two functions might still be optimized to trigger
7472 ;; re-alignment less frequently. Right now they raise the flag each time
7473 ;; (through before-change-functions). Here is how this could be minimized:
7474 ;; Basically, check if the non-white field width before deletion is
7475 ;; equal to the column width. If yes, the delete should trigger a
7476 ;; re-align. I have not implemented this so far because it is not so
7477 ;; easy, requires grabbing the field etc. So it may finally have some
7478 ;; impact on typing performance which we don't want.
7479
7480 ;; The defsubst is only a draft, untested...
7481
7482 ;; Maybe it is not so important to get rid of realigns - maybe the most
7483 ;; important aspect is to keep the table look noce as long as possible,
7484 ;; which is already achieved...
7485
7486 ;(defsubst org-check-delete-triggers-realign ()
7487 ; (let ((pos (point)))
7488 ; (skip-chars-backward "^|\n")
7489 ; (and (looking-at " *\\(.*?\\) *|")
7490 ; (= (nth (1- (org-table-current-column))
7491 ; org-table-last-column-widths)
7492 ; (- (match-end 1) (match-beginning 1)))
7493 ; (setq org-table-may-need-update t))))
7494
7495 (defun org-delete-backward-char (N)
7496 "Like `delete-backward-char', insert whitespace at field end in tables.
7497 When deleting backwards, in tables this function will insert whitespace in
7498 front of the next \"|\" separator, to keep the table aligned. The table will
7499 still be marked for re-alignment, because a narrow field may lead to a
7500 reduced column width."
7501 (interactive "p")
7502 (if (and (org-table-p)
7503 (eq N 1)
7504 (looking-at ".*?|"))
7505 (let ((pos (point)))
7506 (backward-delete-char N)
7507 (skip-chars-forward "^|")
7508 (insert " ")
7509 (goto-char (1- pos)))
7510 (backward-delete-char N)))
7511
7512 (defun org-delete-char (N)
7513 "Like `delete-char', but insert whitespace at field end in tables.
7514 When deleting characters, in tables this function will insert whitespace in
7515 front of the next \"|\" separator, to keep the table aligned. The table
7516 will still be marked for re-alignment, because a narrow field may lead to
7517 a reduced column width."
7518 (interactive "p")
7519 (if (and (org-table-p)
7520 (eq N 1))
7521 (if (looking-at ".*?|")
7522 (let ((pos (point)))
7523 (replace-match (concat
7524 (substring (match-string 0) 1 -1)
7525 " |"))
7526 (goto-char pos)))
7527 (delete-char N)))
7528
7529 ;; How to do this: Measure non-white length of current string
7530 ;; If equal to column width, we should realign.
7531
7532 (when (eq org-enable-table-editor 'optimized)
7533 ;; If the user wants maximum table support, we need to hijack
7534 ;; some standard editing functions
7535 (substitute-key-definition 'self-insert-command 'org-self-insert-command
7536 org-mode-map global-map)
7537 (substitute-key-definition 'delete-char 'org-delete-char
7538 org-mode-map global-map)
7539 (substitute-key-definition 'delete-backward-char 'org-delete-backward-char
7540 org-mode-map global-map)
7541 (define-key org-mode-map "|" 'self-insert-command))
7043 7542
7044 (defun org-shiftcursor-error () 7543 (defun org-shiftcursor-error ()
7045 "Throw an error because Shift-Cursor command was applied in wrong context." 7544 "Throw an error because Shift-Cursor command was applied in wrong context."
7046 (error "This command is only active in tables and on headlines.")) 7545 (error "This command is only active in tables and on headlines."))
7047 7546
7171 7670
7172 (defun org-return (&optional arg) 7671 (defun org-return (&optional arg)
7173 "Call `org-table-next-row' or `newline'." 7672 "Call `org-table-next-row' or `newline'."
7174 (interactive "P") 7673 (interactive "P")
7175 (cond 7674 (cond
7176 ((org-at-table-p) (org-table-next-row)) 7675 ((org-at-table-p)
7676 (org-table-justify-field-maybe)
7677 (org-table-next-row))
7177 (t (newline)))) 7678 (t (newline))))
7178 7679
7680 (defun org-meta-return (&optional arg)
7681 "Call `org-insert-heading' or `org-table-wrap-region'."
7682 (interactive "P")
7683 (cond
7684 ((org-at-table-p)
7685 (org-table-wrap-region arg))
7686 (t (org-insert-heading arg))))
7179 7687
7180 ;;; Menu entries 7688 ;;; Menu entries
7181 7689
7182 ;; First, remove the outline menus. 7690 ;; First, remove the outline menus.
7183 (if org-xemacs-p 7691 (if org-xemacs-p
7243 ("Timeline/Agenda" 7751 ("Timeline/Agenda"
7244 ["Show TODO Tree this file" org-show-todo-tree t] 7752 ["Show TODO Tree this file" org-show-todo-tree t]
7245 ["Check Deadlines this file" org-check-deadlines t] 7753 ["Check Deadlines this file" org-check-deadlines t]
7246 ["Timeline current file" org-timeline t] 7754 ["Timeline current file" org-timeline t]
7247 "--" 7755 "--"
7248 ["Adenda (multifile)" org-agenda-overview t]) 7756 ["Adenda (multifile)" org-agenda t])
7249 ("File List for Agenda") 7757 ("File List for Agenda")
7250 "--" 7758 "--"
7251 ("Hyperlinks" 7759 ("Hyperlinks"
7252 ["Store Link (global)" org-store-link t] 7760 ["Store Link (global)" org-store-link t]
7253 ["Insert Link" org-insert-link t] 7761 ["Insert Link" org-insert-link t]
7584 8092
7585 (provide 'org) 8093 (provide 'org)
7586 8094
7587 (run-hooks 'org-load-hook) 8095 (run-hooks 'org-load-hook)
7588 8096
8097 ;; arch-tag: e77da1a7-acc7-4336-b19e-efa25af3f9fd
8098
7589 ;;; org.el ends here 8099 ;;; org.el ends here
7590 8100
7591 ;; arch-tag: e77da1a7-acc7-4336-b19e-efa25af3f9fd