Mercurial > emacs
comparison lisp/textmodes/org.el @ 68031:f556787bf755
(org-end-of-subtree): New function.
(org-cycle, org-subtree-end-visible-p, org-scan-tags): Use
`org-end-of-subtree'.
(org-agenda, org-agenda-convert-date): Protect calls to
`fit-window-to-buffer'.
(org-tags-view): Force matching of sublevels when doing a
todo-only search. Define the correct redo command, including the
arguments.
(org-agenda-redo): Display message.
(org-check-for-org-mode): New function.
(org-agenda-type): New variable.
(org-timeline, org-agenda-list, org-todo-list, org-tags-view): Set
`org-agenda-type'.
(org-agenda-check-type): New function.
(org-agenda-goto-today, org-agenda-later, org-agenda-earlier)
(org-agenda-week-view, org-agenda-day-view)
(org-agenda-next-date-line, org-agenda-previous-date-line)
(org-agenda-log-mode, org-agenda-toggle-diary)
(org-agenda-toggle-time-grid, org-agenda-date-later)
(org-agenda-date-prompt, org-agenda-diary-entry)
(org-agenda-execute-calendar-command, org-agenda-goto-calendar)
(org-agenda-convert-date, org-agenda-menu): Use
`org-agenda-check-type'.
(org-make-overlay, org-delete-overlay)
(org-detatch-overlay, org-move-overlay, org-overlay-put): New
compatibility functions.
(org-calendar-select-mouse): New command.
author | Carsten Dominik <dominik@science.uva.nl> |
---|---|
date | Thu, 05 Jan 2006 08:05:44 +0000 |
parents | f30b7a47672e |
children | 0164d7cc3832 |
comparison
equal
deleted
inserted
replaced
68030:fe40de091488 | 68031:f556787bf755 |
---|---|
1 ;;; org.el --- Outline-based notes management and organize | 1 ;;; org.el --- Outline-based notes management and organize |
2 ;; Carstens outline-mode for keeping track of everything. | 2 ;; Carstens outline-mode for keeping track of everything. |
3 ;; Copyright (c) 2004, 2005 Free Software Foundation | 3 ;; Copyright (c) 2004, 2005, 2006 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, wp | 6 ;; Keywords: outlines, hypermedia, calendar, wp |
7 ;; Homepage: http://www.astro.uva.nl/~dominik/Tools/org/ | 7 ;; Homepage: http://www.astro.uva.nl/~dominik/Tools/org/ |
8 ;; Version: 4.01 | 8 ;; Version: 4.02 |
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 |
77 ;; distribution also contains a PDF version of it. At the homepage of | 77 ;; distribution also contains a PDF version of it. At the homepage of |
78 ;; Org-mode, you can read the same text online as HTML. There is also an | 78 ;; Org-mode, you can read the same text online as HTML. There is also an |
79 ;; excellent reference card made by Philip Rooke. This card can be found | 79 ;; excellent reference card made by Philip Rooke. This card can be found |
80 ;; in the etc/ directory of Emacs 22. | 80 ;; in the etc/ directory of Emacs 22. |
81 ;; | 81 ;; |
82 ;; Changes: | 82 ;; Changes since version 4.00: |
83 ;; ------- | 83 ;; --------------------------- |
84 ;; Version 4.02 | |
85 ;; - Minor bug fixes and improvements around tag searches. | |
86 ;; - XEmacs compatibility fixes. | |
87 ;; | |
84 ;; Version 4.01 | 88 ;; Version 4.01 |
85 ;; - Tags can also be set remotely from agenda buffer. | 89 ;; - Tags can also be set remotely from agenda buffer. |
86 ;; - Boolean logic for tag searches. | 90 ;; - Boolean logic for tag searches. |
87 ;; - Additional agenda commands can be configured through the variable | 91 ;; - Additional agenda commands can be configured through the variable |
88 ;; `org-agenda-custom-commands'. | 92 ;; `org-agenda-custom-commands'. |
89 ;; - Minor bug fixes. | 93 ;; - Minor bug fixes. |
90 ;; | 94 ;; |
91 ;; Version 4.00 | |
92 ;; - Headlines can contain TAGS, and Org-mode can produced a list | |
93 ;; of matching headlines based on a TAG search expression. | |
94 ;; - `org-agenda' has now become a dispatcher that will produce the agenda | |
95 ;; and other views on org-mode data with an additional keypress. | |
96 ;; | |
97 ;; Version 3.24 | |
98 ;; - Switching and item to DONE records a time stamp when the variable | |
99 ;; `org-log-done' is turned on. Default is off. | |
100 ;; | |
101 ;; Version 3.23 | |
102 ;; - M-RET makes new items as well as new headings. | |
103 ;; - Various small bug fixes | |
104 ;; | |
105 ;; Version 3.22 | |
106 ;; - CamelCase words link to other locations in the same file. | |
107 ;; - File links accept search options, to link to specific locations. | |
108 ;; - Plain list items can be folded with `org-cycle'. See new option | |
109 ;; `org-cycle-include-plain-lists'. | |
110 ;; - Sparse trees for specific TODO keywords through numeric prefix | |
111 ;; argument to `C-c C-v'. | |
112 ;; - Global TODO list, also for specific keywords. | |
113 ;; - Matches in sparse trees are highlighted (highlights disappear with | |
114 ;; next buffer change due to editing). | |
115 ;; | |
116 ;; Version 3.21 | |
117 ;; - Improved CSS support for the HTML export. Thanks to Christian Egli. | |
118 ;; - Editing support for hand-formatted lists | |
119 ;; - M-S-cursor keys handle plain list items | |
120 ;; - C-c C-c renumbers ordered plain lists | |
121 ;; | |
122 ;; Version 3.20 | |
123 ;; - There is finally an option to make TAB jump over horizontal lines | |
124 ;; in tables instead of creating a new line before that line. | |
125 ;; The option is `org-table-tab-jumps-over-hlines', default nil. | |
126 ;; - New command for sorting tables, on `C-c ^'. | |
127 ;; - Changes to the HTML exporter | |
128 ;; - hand-formatted lists are exported correctly, similar to | |
129 ;; markdown lists. Nested lists are possible. See the docstring | |
130 ;; of the variable `org-export-plain-list-max-depth'. | |
131 ;; - cleaned up to produce valid HTML 4.0 (transitional). | |
132 ;; - support for cascading style sheets. | |
133 ;; - New command to cycle through all agenda files, on C-, | |
134 ;; - C-c [ can now also be used to change the sequence of agenda files. | |
135 ;; | |
136 ;; Version 3.19 | |
137 ;; - Bug fixes | |
138 ;; | |
139 ;; Version 3.18 | |
140 ;; - Export of calendar information in the standard iCalendar format. | |
141 ;; - Some bug fixes. | |
142 ;; | |
143 ;; Version 3.17 | |
144 ;; - HTML export specifies character set depending on coding-system. | |
145 ;; | |
146 ;; Version 3.16 | |
147 ;; - In tables, directly after the field motion commands like TAB and RET, | |
148 ;; typing a character will blank the field. Can be turned off with | |
149 ;; variable `org-table-auto-blank-field'. | |
150 ;; - Inactive timestamps with `C-c !'. These do not trigger the agenda | |
151 ;; and are not linked to the calendar. | |
152 ;; - Additional key bindings to allow Org-mode to function on a tty emacs. | |
153 ;; - `C-c C-h' prefix key replaced by `C-c C-x', and `C-c C-x C-h' replaced | |
154 ;; by `C-c C-x b' (b=Browser). This was necessary to recover the | |
155 ;; standard meaning of C-h after a prefix key (show prefix bindings). | |
156 ;; | |
157 ;; Version 3.15 | |
158 ;; - QUOTE keyword at the beginning of an entry causes fixed-width export | |
159 ;; of unmodified entry text. `C-c :' toggles this keyword. | |
160 ;; - New face `org-special-keyword' which is used for COMMENT, QUOTE, | |
161 ;; DEADLINE and SCHEDULED, and priority cookies. Default is only a weak | |
162 ;; color, to reduce the amount of aggressive color in the buffer. | |
163 ;; | |
164 ;; Version 3.14 | |
165 ;; - Formulas for individual fields in table. | |
166 ;; - Automatic recalculation in calculating tables. | |
167 ;; - Named fields and columns in tables. | |
168 ;; - Fixed bug with calling `org-archive' several times in a row. | |
169 ;; | |
170 ;; Version 3.13 | |
171 ;; - Efficiency improvements: Fewer table re-alignments needed. | |
172 ;; - New special lines in tables, for defining names for individual cells. | |
173 ;; | |
174 ;; Version 3.12 | |
175 ;; - Tables can store formulas (one per column) and compute fields. | |
176 ;; Not quite like a full spreadsheet, but very powerful. | |
177 ;; - table.el keybinding is now `C-c ~'. | |
178 ;; - Numeric argument to org-cycle does `show-subtree' above on level ARG. | |
179 ;; - Small changes to keys in agenda buffer. Affected keys: | |
180 ;; [w] weekly view; [d] daily view; [D] toggle diary inclusion. | |
181 ;; - Bug fixes. | |
182 ;; | |
183 ;; Version 3.11 | |
184 ;; - Links inserted with C-c C-l are now by default enclosed in angle | |
185 ;; brackets. See the new variable `org-link-format'. | |
186 ;; - ">" terminates a link, this is a way to have several links in a line. | |
187 ;; Both "<" and ">" are no longer allowed as characters in a link. | |
188 ;; - Archiving of finished tasks. | |
189 ;; - C-<up>/<down> bindings removed, to allow access to paragraph commands. | |
190 ;; - Compatibility with CUA-mode (see variable `org-CUA-compatible'). | |
191 ;; - Compatibility problems with viper-mode fixed. | |
192 ;; - Improved html export of tables. | |
193 ;; - Various clean-up changes. | |
194 ;; | |
195 ;; Version 3.10 | |
196 ;; - Using `define-derived-mode' to derive `org-mode' from `outline-mode'. | |
197 ;; | |
198 ;; Version 3.09 | |
199 ;; - Time-of-day specifications in agenda are extracted and placed | |
200 ;; into the prefix. Timed entries can be placed into a time grid for | |
201 ;; day. | |
202 ;; | |
203 ;; Version 3.08 | |
204 ;; - "|" no longer allowed as part of a link, to allow links in tables. | |
205 ;; - The prefix of items in the agenda buffer can be configured. | |
206 ;; - Cleanup. | |
207 ;; | |
208 ;; Version 3.07 | |
209 ;; - Some folding inconsistencies removed. | |
210 ;; - BBDB links to company-only entries. | |
211 ;; - Bug fixes and global cleanup. | |
212 ;; | |
213 ;; Version 3.06 | |
214 ;; - M-S-RET inserts a new TODO heading. | |
215 ;; - New startup option `content'. | |
216 ;; - Better visual response when TODO items in agenda change status. | |
217 ;; - Window positioning after visibility state changes optimized and made | |
218 ;; configurable. See `org-cycle-hook' and `org-occur-hook'. | |
219 ;; | |
220 ;; Version 3.05 | |
221 ;; - Agenda entries from the diary are linked to the diary file, so | |
222 ;; adding and editing diary entries can be done directly from the agenda. | |
223 ;; - Many calendar/diary commands available directly from agenda. | |
224 ;; - Field copying in tables with S-RET does increment. | |
225 ;; - C-c C-x C-v extracts the visible part of the buffer for printing. | |
226 ;; - Moving subtrees up and down preserves the whitespace at the tree end. | |
227 ;; | |
228 ;; Version 3.04 | |
229 ;; - Table editor optimized to need fewer realignments, and to keep | |
230 ;; table shape when typing in fields. | |
231 ;; - A new minor mode, orgtbl-mode, introduces the Org-mode table editor | |
232 ;; into arbitrary major modes. | |
233 ;; - Fixed bug with realignment in XEmacs. | |
234 ;; - Startup options can be set with special #+STARTUP line. | |
235 ;; - Heading following a match in org-occur can be suppressed. | |
236 ;; | |
237 ;; Version 3.03 | |
238 ;; - Copyright transfer to the FSF. | |
239 ;; - Effect of C-u and C-u C-u in org-timeline swapped. | |
240 ;; - Timeline now always contains today, and `.' jumps to it. | |
241 ;; - Table editor: | |
242 ;; - cut and paste of rectangular regions in tables | |
243 ;; - command to convert org-mode table to table.el table and back | |
244 ;; - command to treat several cells like a paragraph and fill it | |
245 ;; - command to convert a buffer region to a table | |
246 ;; - import/export tables as tab-separated files (exchange with Excel) | |
247 ;; - Agenda: | |
248 ;; - Sorting mechanism for agenda items rewritten from scratch. | |
249 ;; - Sorting fully configurable. | |
250 ;; - Entries specifying a time are sorted together. | |
251 ;; - Completion also covers option keywords after `#-'. | |
252 ;; - Bug fixes. | |
253 ;; | |
254 ;; Version 3.01 | |
255 ;; - New reference card, thanks to Philip Rooke for creating it. | |
256 ;; - Single file agenda renamed to "Timeline". It no longer shows | |
257 ;; warnings about upcoming deadlines/overdue scheduled items. | |
258 ;; That functionality is now limited to the (multifile) agenda. | |
259 ;; - When reading a date, the calendar can be manipulated with keys. | |
260 ;; - Link support for RMAIL and Wanderlust (from planner.el, untested). | |
261 ;; - Minor bug fixes and documentation improvements. | |
262 | |
263 ;;; Code: | 95 ;;; Code: |
264 | 96 |
265 (eval-when-compile (require 'cl) (require 'calendar)) | 97 (eval-when-compile (require 'cl) (require 'calendar)) |
266 (require 'outline) | 98 (require 'outline) |
267 (require 'time-date) | 99 (require 'time-date) |
599 Entries are added to this list with \\[org-agenda-file-to-front] and removed with | 431 Entries are added to this list with \\[org-agenda-file-to-front] and removed with |
600 \\[org-remove-file]. You can also use customize to edit the list." | 432 \\[org-remove-file]. You can also use customize to edit the list." |
601 :group 'org-agenda | 433 :group 'org-agenda |
602 :type '(repeat file)) | 434 :type '(repeat file)) |
603 | 435 |
604 (defcustom org-agenda-custom-commands | 436 (defcustom org-agenda-custom-commands '(("w" todo "WAITING")) |
605 '(("w" todo "WAITING") | |
606 ("u" tags "+WORK+URGENT-BOSS")) | |
607 "Custom commands for the agenda. | 437 "Custom commands for the agenda. |
608 These commands will be offered on the splash screen displayed by the | 438 These commands will be offered on the splash screen displayed by the |
609 agenda dispatcher \\[org-agenda]. Each entry is a list of 3 items: | 439 agenda dispatcher \\[org-agenda]. Each entry is a list of 3 items: |
610 | 440 |
611 key The key (as a string) to be associated with the command. | 441 key The key (a single char as a string) to be associated with the command. |
612 type The command type, either `todo' for a todo list with a specific | 442 type The command type, any of the following symbols: |
613 todo keyword, or `tags' for a tags search. | 443 todo Entries with a specific TODO keyword, in all agenda files. |
614 match What to search for. Either a TODO keyword, or a tags match query." | 444 tags Tags match in all agenda files. |
445 todo-tree Sparse tree of specific TODO keyword in *current* file. | |
446 tags-tree Sparse tree with all tags matches in *current* file. | |
447 occur-tree Occur sparse tree for current file. | |
448 match What to search for: | |
449 - a single keyword for TODO keyword searches | |
450 - a tags match expression for tags searches | |
451 - a regular expression for occur searches" | |
615 :group 'org-agenda | 452 :group 'org-agenda |
616 :type '(repeat | 453 :type '(repeat |
617 (list (string :tag "Key") | 454 (list (string :tag "Key") |
618 (choice :tag "Type" (const tags) (const todo)) | 455 (choice :tag "Type" |
456 (const :tag "Tags search in all agenda files" tags) | |
457 (const :tag "TODO keyword search in all agenda files" todo) | |
458 (const :tag "Tags sparse tree in current buffer" tags-tree) | |
459 (const :tag "TODO keyword tree in current buffer" todo-tree) | |
460 (const :tag "Occur tree in current buffer" occur-tree)) | |
619 (string :tag "Match")))) | 461 (string :tag "Match")))) |
620 | 462 |
621 (defcustom org-select-timeline-window t | 463 (defcustom org-select-timeline-window t |
622 "Non-nil means, after creating a timeline, move cursor into Timeline window. | 464 "Non-nil means, after creating a timeline, move cursor into Timeline window. |
623 When nil, cursor will remain in the current window." | 465 When nil, cursor will remain in the current window." |
1034 Because of tag inheritance (see variable `org-use-tag-inheritance'), | 876 Because of tag inheritance (see variable `org-use-tag-inheritance'), |
1035 the sublevels of a headline matching a tag search often also match | 877 the sublevels of a headline matching a tag search often also match |
1036 the same search. Listing all of them can create very long lists. | 878 the same search. Listing all of them can create very long lists. |
1037 Setting this variable to nil causes subtrees to be skipped. | 879 Setting this variable to nil causes subtrees to be skipped. |
1038 This option is off by default, because inheritance in on. If you turn | 880 This option is off by default, because inheritance in on. If you turn |
1039 inheritance off, you very likely want to turn this option on." | 881 inheritance off, you very likely want to turn this option on. |
882 | |
883 As a special case, if the tag search is restricted to TODO items, the | |
884 value of this variable is ignored and sublevels are always checked, to | |
885 make sure all corresponding TODO items find their way into the list." | |
1040 :group 'org-tags | 886 :group 'org-tags |
1041 :type 'boolean) | 887 :type 'boolean) |
1042 | 888 |
1043 (defvar org-tags-history nil | 889 (defvar org-tags-history nil |
1044 "History of minibuffer reads for tags.") | 890 "History of minibuffer reads for tags.") |
2135 ;; Activate before-change-function | 1981 ;; Activate before-change-function |
2136 (set (make-local-variable 'org-table-may-need-update) t) | 1982 (set (make-local-variable 'org-table-may-need-update) t) |
2137 (make-local-hook 'before-change-functions) ;; needed for XEmacs | 1983 (make-local-hook 'before-change-functions) ;; needed for XEmacs |
2138 (add-hook 'before-change-functions 'org-before-change-function nil | 1984 (add-hook 'before-change-functions 'org-before-change-function nil |
2139 'local) | 1985 'local) |
1986 ;; FIXME: The following does not work because isearch-mode-end-hook | |
1987 ;; is called *before* the visibility overlays as removed. | |
1988 ;; There should be another hook then for me to be used. | |
1989 ;; (make-local-hook 'isearch-mode-end-hook) ;; needed for XEmacs | |
1990 ;; (add-hook 'isearch-mode-end-hook 'org-show-hierarchy-above nil | |
1991 ;; 'local) | |
2140 ;; Paragraphs and auto-filling | 1992 ;; Paragraphs and auto-filling |
2141 (org-set-autofill-regexps) | 1993 (org-set-autofill-regexps) |
2142 ;; Settings for Calc embedded mode | 1994 ;; Settings for Calc embedded mode |
2143 (set (make-local-variable 'calc-embedded-open-formula) "|\\|\n") | 1995 (set (make-local-variable 'calc-embedded-open-formula) "|\\|\n") |
2144 (set (make-local-variable 'calc-embedded-close-formula) "|\\|\n") | 1996 (set (make-local-variable 'calc-embedded-close-formula) "|\\|\n") |
2170 (let ((this-command 'org-cycle) (last-command 'org-cycle)) | 2022 (let ((this-command 'org-cycle) (last-command 'org-cycle)) |
2171 (org-cycle '(4)) (org-cycle '(4)))))))) | 2023 (org-cycle '(4)) (org-cycle '(4)))))))) |
2172 | 2024 |
2173 (defsubst org-current-line (&optional pos) | 2025 (defsubst org-current-line (&optional pos) |
2174 (+ (if (bolp) 1 0) (count-lines (point-min) (or pos (point))))) | 2026 (+ (if (bolp) 1 0) (count-lines (point-min) (or pos (point))))) |
2027 | |
2028 | |
2029 ;; FIXME: Do we need to copy? | |
2030 (defun org-string-props (string &rest properties) | |
2031 "Add PROPERTIES to string." | |
2032 (add-text-properties 0 (length string) properties string) | |
2033 string) | |
2175 | 2034 |
2176 ;;; Font-Lock stuff | 2035 ;;; Font-Lock stuff |
2177 | 2036 |
2178 (defvar org-mouse-map (make-sparse-keymap)) | 2037 (defvar org-mouse-map (make-sparse-keymap)) |
2179 (define-key org-mouse-map | 2038 (define-key org-mouse-map |
2450 (beginning-of-line 2) | 2309 (beginning-of-line 2) |
2451 (while (and (not (eobp)) ;; this is like `next-line' | 2310 (while (and (not (eobp)) ;; this is like `next-line' |
2452 (get-char-property (1- (point)) 'invisible)) | 2311 (get-char-property (1- (point)) 'invisible)) |
2453 (beginning-of-line 2)) (setq eol (point))) | 2312 (beginning-of-line 2)) (setq eol (point))) |
2454 (outline-end-of-heading) (setq eoh (point)) | 2313 (outline-end-of-heading) (setq eoh (point)) |
2455 (outline-end-of-subtree) (setq eos (point)) | 2314 (org-end-of-subtree t) (setq eos (point)) |
2456 (outline-next-heading)) | 2315 (outline-next-heading)) |
2457 ;; Find out what to do next and set `this-command' | 2316 ;; Find out what to do next and set `this-command' |
2458 (cond | 2317 (cond |
2459 ((= eos eoh) | 2318 ((= eos eoh) |
2460 ;; Nothing is hidden behind this heading | 2319 ;; Nothing is hidden behind this heading |
2511 ((eq state 'subtree) (or (org-subtree-end-visible-p) (recenter 1))))) | 2370 ((eq state 'subtree) (or (org-subtree-end-visible-p) (recenter 1))))) |
2512 | 2371 |
2513 (defun org-subtree-end-visible-p () | 2372 (defun org-subtree-end-visible-p () |
2514 "Is the end of the current subtree visible?" | 2373 "Is the end of the current subtree visible?" |
2515 (pos-visible-in-window-p | 2374 (pos-visible-in-window-p |
2516 (save-excursion (outline-end-of-subtree) (point)))) | 2375 (save-excursion (org-end-of-subtree t) (point)))) |
2517 | 2376 |
2518 (defun org-first-headline-recenter (&optional N) | 2377 (defun org-first-headline-recenter (&optional N) |
2519 "Move cursor to the first headline and recenter the headline. | 2378 "Move cursor to the first headline and recenter the headline. |
2520 Optional argument N means, put the headline into the Nth line of the window." | 2379 Optional argument N means, put the headline into the Nth line of the window." |
2521 (goto-char (point-min)) | 2380 (goto-char (point-min)) |
3624 (message "%d match(es) for regexp %s" cnt regexp)) | 3483 (message "%d match(es) for regexp %s" cnt regexp)) |
3625 cnt)) | 3484 cnt)) |
3626 | 3485 |
3627 (defun org-show-hierarchy-above () | 3486 (defun org-show-hierarchy-above () |
3628 "Make sure point and the headings hierarchy above is visible." | 3487 "Make sure point and the headings hierarchy above is visible." |
3629 (if (org-on-heading-p t) | 3488 (catch 'exit |
3630 (org-flag-heading nil) ; only show the heading | 3489 (if (org-on-heading-p t) |
3631 (and (org-invisible-p) (org-show-hidden-entry))) ; show entire entry | 3490 (org-flag-heading nil) ; only show the heading |
3632 (save-excursion | 3491 (and (org-invisible-p) (org-show-hidden-entry))) ; show entire entry |
3633 (and org-show-following-heading | 3492 (save-excursion |
3634 (outline-next-heading) | 3493 (and org-show-following-heading |
3635 (org-flag-heading nil))) ; show the next heading | 3494 (outline-next-heading) |
3636 (when org-show-hierarchy-above | 3495 (org-flag-heading nil))) ; show the next heading |
3637 (save-excursion ; show all higher headings | 3496 (when org-show-hierarchy-above |
3638 (while (condition-case nil | 3497 (save-excursion ; show all higher headings |
3639 (progn (org-up-heading-all 1) t) | 3498 (while (and (condition-case nil |
3640 (error nil)) | 3499 (progn (org-up-heading-all 1) t) |
3641 (org-flag-heading nil))))) | 3500 (error nil)) |
3501 (not (bobp))) | |
3502 (org-flag-heading nil)))))) | |
3503 | |
3504 ;; Overlay compatibility functions | |
3505 (defun org-make-overlay (beg end &optional buffer) | |
3506 (if org-xemacs-p (make-extent beg end buffer) (make-overlay beg end buffer))) | |
3507 (defun org-delete-overlay (ovl) | |
3508 (if org-xemacs-p (delete-extent ovl) (delete-overlay ovl))) | |
3509 (defun org-detatch-overlay (ovl) | |
3510 (if org-xemacs-p (detach-extent ovl) (delete-overlay ovl))) | |
3511 (defun org-move-overlay (ovl beg end &optional buffer) | |
3512 (if org-xemacs-p | |
3513 (set-extent-endpoints ovl beg end buffer) | |
3514 (move-overlay ovl beg end buffer))) | |
3515 (defun org-overlay-put (ovl prop value) | |
3516 (if org-xemacs-p | |
3517 (set-extent-property ovl prop value) | |
3518 (overlay-put ovl prop value))) | |
3642 | 3519 |
3643 (defvar org-occur-highlights nil) | 3520 (defvar org-occur-highlights nil) |
3644 (defun org-highlight-new-match (beg end) | 3521 (defun org-highlight-new-match (beg end) |
3645 "Highlight from BEG to END and mark the highlight is an occur headline." | 3522 "Highlight from BEG to END and mark the highlight is an occur headline." |
3646 (let ((ov (make-overlay beg end))) | 3523 (let ((ov (org-make-overlay beg end))) |
3647 (overlay-put ov 'face 'secondary-selection) | 3524 (org-overlay-put ov 'face 'secondary-selection) |
3648 (push ov org-occur-highlights))) | 3525 (push ov org-occur-highlights))) |
3649 | 3526 |
3650 (defun org-remove-occur-highlights (&optional beg end noremove) | 3527 (defun org-remove-occur-highlights (&optional beg end noremove) |
3651 "Remove the occur highlights from the buffer. | 3528 "Remove the occur highlights from the buffer. |
3652 BEG and END are ignored. If NOREMOVE is nil, remove this function | 3529 BEG and END are ignored. If NOREMOVE is nil, remove this function |
3653 from the before-change-functions in the current buffer." | 3530 from the before-change-functions in the current buffer." |
3654 (interactive) | 3531 (interactive) |
3655 (mapc 'delete-overlay org-occur-highlights) | 3532 (mapc 'org-delete-overlay org-occur-highlights) |
3656 (setq org-occur-highlights nil) | 3533 (setq org-occur-highlights nil) |
3657 (unless noremove | 3534 (unless noremove |
3658 (remove-hook 'before-change-functions | 3535 (remove-hook 'before-change-functions |
3659 'org-remove-occur-highlights 'local))) | 3536 'org-remove-occur-highlights 'local))) |
3660 | 3537 |
3784 (setq time (org-read-date arg 'totime)) | 3661 (setq time (org-read-date arg 'totime)) |
3785 (if org-time-was-given (setq fmt (cdr org-time-stamp-formats))) | 3662 (if org-time-was-given (setq fmt (cdr org-time-stamp-formats))) |
3786 (setq fmt (concat "[" (substring fmt 1 -1) "]")) | 3663 (setq fmt (concat "[" (substring fmt 1 -1) "]")) |
3787 (insert (format-time-string fmt time)))) | 3664 (insert (format-time-string fmt time)))) |
3788 | 3665 |
3666 (defvar org-date-ovl (org-make-overlay 1 1)) | |
3667 (org-overlay-put org-date-ovl 'face 'org-warning) | |
3668 (org-detatch-overlay org-date-ovl) | |
3669 | |
3789 ;;; FIXME: Make the function take "Fri" as "next friday" | 3670 ;;; FIXME: Make the function take "Fri" as "next friday" |
3790 ;;; because these are mostly being used to record the current time. | 3671 ;;; because these are mostly being used to record the current time. |
3791 (defun org-read-date (&optional with-time to-time) | 3672 (defun org-read-date (&optional with-time to-time) |
3792 "Read a date and make things smooth for the user. | 3673 "Read a date and make things smooth for the user. |
3793 The prompt will suggest to enter an ISO date, but you can also enter anything | 3674 The prompt will suggest to enter an ISO date, but you can also enter anything |
3845 (save-window-excursion | 3726 (save-window-excursion |
3846 (calendar) | 3727 (calendar) |
3847 (calendar-forward-day (- (time-to-days default-time) | 3728 (calendar-forward-day (- (time-to-days default-time) |
3848 (calendar-absolute-from-gregorian | 3729 (calendar-absolute-from-gregorian |
3849 (calendar-current-date)))) | 3730 (calendar-current-date)))) |
3731 (org-eval-in-calendar nil) | |
3850 (let* ((old-map (current-local-map)) | 3732 (let* ((old-map (current-local-map)) |
3851 (map (copy-keymap calendar-mode-map)) | 3733 (map (copy-keymap calendar-mode-map)) |
3852 (minibuffer-local-map (copy-keymap minibuffer-local-map))) | 3734 (minibuffer-local-map (copy-keymap minibuffer-local-map))) |
3853 (define-key map (kbd "RET") 'org-calendar-select) | 3735 (define-key map (kbd "RET") 'org-calendar-select) |
3854 (define-key map (if org-xemacs-p [button1] [mouse-1]) | 3736 (define-key map (if org-xemacs-p [button1] [mouse-1]) |
3855 'org-calendar-select) | 3737 'org-calendar-select-mouse) |
3738 (define-key map (if org-xemacs-p [button2] [mouse-2]) | |
3739 'org-calendar-select-mouse) | |
3856 (define-key minibuffer-local-map [(meta shift left)] | 3740 (define-key minibuffer-local-map [(meta shift left)] |
3857 (lambda () (interactive) | 3741 (lambda () (interactive) |
3858 (org-eval-in-calendar '(calendar-backward-month 1)))) | 3742 (org-eval-in-calendar '(calendar-backward-month 1)))) |
3859 (define-key minibuffer-local-map [(meta shift right)] | 3743 (define-key minibuffer-local-map [(meta shift right)] |
3860 (lambda () (interactive) | 3744 (lambda () (interactive) |
3883 (setq ans (read-string prompt "" nil nil)) | 3767 (setq ans (read-string prompt "" nil nil)) |
3884 (setq ans (or ans1 ans2 ans))) | 3768 (setq ans (or ans1 ans2 ans))) |
3885 (use-local-map old-map))))) | 3769 (use-local-map old-map))))) |
3886 ;; Naked prompt only | 3770 ;; Naked prompt only |
3887 (setq ans (read-string prompt "" nil timestr))) | 3771 (setq ans (read-string prompt "" nil timestr))) |
3772 (org-detatch-overlay org-date-ovl) | |
3888 | 3773 |
3889 (if (string-match | 3774 (if (string-match |
3890 "^ *\\(\\([0-9]+\\)-\\)?\\([0-1]?[0-9]\\)-\\([0-3]?[0-9]\\)\\([^-0-9]\\|$\\)" ans) | 3775 "^ *\\(\\([0-9]+\\)-\\)?\\([0-1]?[0-9]\\)-\\([0-3]?[0-9]\\)\\([^-0-9]\\|$\\)" ans) |
3891 (progn | 3776 (progn |
3892 (setq year (if (match-end 2) | 3777 (setq year (if (match-end 2) |
3922 (eval form) | 3807 (eval form) |
3923 (when (calendar-cursor-to-date) | 3808 (when (calendar-cursor-to-date) |
3924 (let* ((date (calendar-cursor-to-date)) | 3809 (let* ((date (calendar-cursor-to-date)) |
3925 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date)))) | 3810 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date)))) |
3926 (setq ans2 (format-time-string "%Y-%m-%d" time)))) | 3811 (setq ans2 (format-time-string "%Y-%m-%d" time)))) |
3927 (and org-xemacs-p (sit-for .2)) | 3812 (org-move-overlay org-date-ovl (1- (point)) (1+ (point)) (current-buffer)) |
3928 (select-window sw))) | 3813 (select-window sw))) |
3929 | 3814 |
3930 (defun org-calendar-select () | 3815 (defun org-calendar-select () |
3931 "Return to `org-read-date' with the date currently selected. | 3816 "Return to `org-read-date' with the date currently selected. |
3932 This is used by `org-read-date' in a temporary keymap for the calendar buffer." | 3817 This is used by `org-read-date' in a temporary keymap for the calendar buffer." |
3933 (interactive) | 3818 (interactive) |
3819 (when (calendar-cursor-to-date) | |
3820 (let* ((date (calendar-cursor-to-date)) | |
3821 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date)))) | |
3822 (setq ans1 (format-time-string "%Y-%m-%d" time))) | |
3823 (if (active-minibuffer-window) (exit-minibuffer)))) | |
3824 | |
3825 (defun org-calendar-select-mouse (ev) | |
3826 "Return to `org-read-date' with the date currently selected. | |
3827 This is used by `org-read-date' in a temporary keymap for the calendar buffer." | |
3828 (interactive "e") | |
3829 (mouse-set-point ev) | |
3934 (when (calendar-cursor-to-date) | 3830 (when (calendar-cursor-to-date) |
3935 (let* ((date (calendar-cursor-to-date)) | 3831 (let* ((date (calendar-cursor-to-date)) |
3936 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date)))) | 3832 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date)))) |
3937 (setq ans1 (format-time-string "%Y-%m-%d" time))) | 3833 (setq ans1 (format-time-string "%Y-%m-%d" time))) |
3938 (if (active-minibuffer-window) (exit-minibuffer)))) | 3834 (if (active-minibuffer-window) (exit-minibuffer)))) |
4218 (defvar org-agenda-follow-mode nil) | 4114 (defvar org-agenda-follow-mode nil) |
4219 (defvar org-agenda-show-log nil) | 4115 (defvar org-agenda-show-log nil) |
4220 (defvar org-agenda-buffer-name "*Org Agenda*") | 4116 (defvar org-agenda-buffer-name "*Org Agenda*") |
4221 (defvar org-agenda-redo-command nil) | 4117 (defvar org-agenda-redo-command nil) |
4222 (defvar org-agenda-mode-hook nil) | 4118 (defvar org-agenda-mode-hook nil) |
4223 | 4119 (defvar org-agenda-type nil) |
4224 (defvar org-agenda-force-single-file nil) | 4120 (defvar org-agenda-force-single-file nil) |
4225 | 4121 |
4226 ;;;###autoload | 4122 ;;;###autoload |
4227 (defun org-agenda-mode () | 4123 (defun org-agenda-mode () |
4228 "Mode for time-sorted view on action items in Org-mode files. | 4124 "Mode for time-sorted view on action items in Org-mode files. |
4336 :style toggle :selected org-agenda-follow-mode :active t] | 4232 :style toggle :selected org-agenda-follow-mode :active t] |
4337 "--" | 4233 "--" |
4338 ["Cycle TODO" org-agenda-todo t] | 4234 ["Cycle TODO" org-agenda-todo t] |
4339 ["Set Tags" org-agenda-set-tags t] | 4235 ["Set Tags" org-agenda-set-tags t] |
4340 ("Reschedule" | 4236 ("Reschedule" |
4341 ["Reschedule +1 day" org-agenda-date-later t] | 4237 ["Reschedule +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)] |
4342 ["Reschedule -1 day" org-agenda-date-earlier t] | 4238 ["Reschedule -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)] |
4343 "--" | 4239 "--" |
4344 ["Reschedule to ..." org-agenda-date-prompt t]) | 4240 ["Reschedule to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)]) |
4345 ("Priority" | 4241 ("Priority" |
4346 ["Set Priority" org-agenda-priority t] | 4242 ["Set Priority" org-agenda-priority t] |
4347 ["Increase Priority" org-agenda-priority-up t] | 4243 ["Increase Priority" org-agenda-priority-up t] |
4348 ["Decrease Priority" org-agenda-priority-down t] | 4244 ["Decrease Priority" org-agenda-priority-down t] |
4349 ["Show Priority" org-agenda-show-priority t]) | 4245 ["Show Priority" org-agenda-show-priority t]) |
4350 "--" | 4246 "--" |
4247 ;; ["New agenda command" org-agenda t] | |
4351 ["Rebuild buffer" org-agenda-redo t] | 4248 ["Rebuild buffer" org-agenda-redo t] |
4352 ["Goto Today" org-agenda-goto-today t] | |
4353 ["Next Dates" org-agenda-later (local-variable-p 'starting-day (current-buffer))] | |
4354 ["Previous Dates" org-agenda-earlier (local-variable-p 'starting-day (current-buffer))] | |
4355 "--" | 4249 "--" |
4356 ["Day View" org-agenda-day-view :active (local-variable-p 'starting-day (current-buffer)) | 4250 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)] |
4251 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)] | |
4252 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)] | |
4253 "--" | |
4254 ["Day View" org-agenda-day-view :active (org-agenda-check-type nil 'agenda) | |
4357 :style radio :selected (equal org-agenda-ndays 1)] | 4255 :style radio :selected (equal org-agenda-ndays 1)] |
4358 ["Week View" org-agenda-week-view :active (local-variable-p 'starting-day (current-buffer)) | 4256 ["Week View" org-agenda-week-view :active (org-agenda-check-type nil 'agenda) |
4359 :style radio :selected (equal org-agenda-ndays 7)] | 4257 :style radio :selected (equal org-agenda-ndays 7)] |
4360 "--" | 4258 "--" |
4361 ["Show Logbook entries" org-agenda-log-mode | 4259 ["Show Logbook entries" org-agenda-log-mode |
4362 :style toggle :selected org-agenda-show-log :active t] | 4260 :style toggle :selected org-agenda-show-log :active (org-agenda-check-type nil 'agenda 'timeline)] |
4363 ["Include Diary" org-agenda-toggle-diary | 4261 ["Include Diary" org-agenda-toggle-diary |
4364 :style toggle :selected org-agenda-include-diary :active t] | 4262 :style toggle :selected org-agenda-include-diary :active (org-agenda-check-type nil 'agenda)] |
4365 ["Use Time Grid" org-agenda-toggle-time-grid | 4263 ["Use Time Grid" org-agenda-toggle-time-grid |
4366 :style toggle :selected org-agenda-use-time-grid :active t] | 4264 :style toggle :selected org-agenda-use-time-grid :active (org-agenda-check-type nil 'agenda)] |
4367 "--" | 4265 "--" |
4368 ["New Diary Entry" org-agenda-diary-entry t] | 4266 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)] |
4369 ("Calendar Commands" | 4267 ("Calendar Commands" |
4370 ["Goto Calendar" org-agenda-goto-calendar t] | 4268 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)] |
4371 ["Phases of the Moon" org-agenda-phases-of-moon t] | 4269 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)] |
4372 ["Sunrise/Sunset" org-agenda-sunrise-sunset t] | 4270 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)] |
4373 ["Holidays" org-agenda-holidays t] | 4271 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)] |
4374 ["Convert" org-agenda-convert-date t]) | 4272 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]) |
4375 ["Create iCalendar file" org-export-icalendar-combine-agenda-files t] | 4273 ["Create iCalendar file" org-export-icalendar-combine-agenda-files t] |
4376 "--" | 4274 "--" |
4377 ["Quit" org-agenda-quit t] | 4275 ["Quit" org-agenda-quit t] |
4378 ["Exit and Release Buffers" org-agenda-exit t] | 4276 ["Exit and Release Buffers" org-agenda-exit t] |
4379 )) | 4277 )) |
4384 Prompts for a character to select a command. Any prefix arg will be passed | 4282 Prompts for a character to select a command. Any prefix arg will be passed |
4385 on to the selected command. The default selections are: | 4283 on to the selected command. The default selections are: |
4386 | 4284 |
4387 a Call `org-agenda' to display the agenda for the current day or week. | 4285 a Call `org-agenda' to display the agenda for the current day or week. |
4388 t Call `org-todo-list' to display the global todo list. | 4286 t Call `org-todo-list' to display the global todo list. |
4389 T Call `org-todo-list' to display the global todo list, put | 4287 T Call `org-todo-list' to display the global todo list, select only |
4390 select only entries with a specific TODO keyword. | 4288 entries with a specific TODO keyword (the user get a prompt). |
4391 m Call `org-tags-view' to display headlines with tags matching | 4289 m Call `org-tags-view' to display headlines with tags matching |
4392 a condition. The tags condition is a list of positive and negative | 4290 a condition (the user is prompted for the condition). |
4393 selections, like `+WORK+URGENT-WITHBOSS'. | |
4394 M like `m', but select only TODO entries, no ordinary headlines. | 4291 M like `m', but select only TODO entries, no ordinary headlines. |
4395 | 4292 |
4396 More commands can be added by configuring the variable | 4293 More commands can be added by configuring the variable |
4397 `org-agenda-custom-commands'. | 4294 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword |
4295 searches can be pre-defined in this way. | |
4398 | 4296 |
4399 If the current buffer is in Org-mode and visiting a file, you can also | 4297 If the current buffer is in Org-mode and visiting a file, you can also |
4400 first press `1' to indicate that the agenda should be temporarily | 4298 first press `1' to indicate that the agenda should be temporarily (until the |
4401 restricted to the current file." | 4299 next use of \\[org-agenda]) restricted to the current file." |
4402 (interactive "P") | 4300 (interactive "P") |
4403 (catch 'exit | 4301 (catch 'exit |
4404 (let ((restrict-ok (and (buffer-file-name) (eq major-mode 'org-mode))) | 4302 (let ((restrict-ok (and (buffer-file-name) (eq major-mode 'org-mode))) |
4405 (custom org-agenda-custom-commands) | 4303 (custom org-agenda-custom-commands) |
4406 c entry key type string) | 4304 c entry key type string) |
4416 t List of all TODO entries T Entries with special TODO kwd | 4314 t List of all TODO entries T Entries with special TODO kwd |
4417 m Match a TAGS query M Like m, but only TODO entries. | 4315 m Match a TAGS query M Like m, but only TODO entries. |
4418 C Configure your own agenda commands") | 4316 C Configure your own agenda commands") |
4419 (while (setq entry (pop custom)) | 4317 (while (setq entry (pop custom)) |
4420 (setq key (car entry) type (nth 1 entry) string (nth 2 entry)) | 4318 (setq key (car entry) type (nth 1 entry) string (nth 2 entry)) |
4421 (insert (format "\n%-4s%-12s: %s" | 4319 (insert (format "\n%-4s%-14s: %s" |
4422 key | 4320 key |
4423 (if (eq type 'tags) "Tags query" "TODO keyword") | 4321 (cond |
4424 string))) | 4322 ((eq type 'tags) "Tags query") |
4323 ((eq type 'todo) "TODO keyword") | |
4324 ((eq type 'tags-tree) "Tags tree") | |
4325 ((eq type 'todo-tree) "TODO kwd tree") | |
4326 ((eq type 'occur-tree) "Occur tree") | |
4327 (t "???")) | |
4328 (org-string-props string 'face 'org-link)))) | |
4425 (goto-char (point-min)) | 4329 (goto-char (point-min)) |
4426 (fit-window-to-buffer) | 4330 (if (fboundp 'fit-window-to-buffer) (fit-window-to-buffer)) |
4427 (message "Press key for agenda command%s" | 4331 (message "Press key for agenda command%s" |
4428 (if restrict-ok ", or [1] to restrict to current file" "")) | 4332 (if restrict-ok ", or [1] to restrict to current file" "")) |
4429 (setq c (read-char-exclusive)) | 4333 (setq c (read-char-exclusive)) |
4430 (message "") | 4334 (message "") |
4431 (when (equal c ?1) | 4335 (when (equal c ?1) |
4432 (if restrict-ok | 4336 (if restrict-ok |
4433 (put 'org-agenda-files 'org-restrict (list (buffer-file-name))) | 4337 (put 'org-agenda-files 'org-restrict (list (buffer-file-name))) |
4435 (message "Press key for agenda command%s" | 4339 (message "Press key for agenda command%s" |
4436 (if restrict-ok " (restricted to current file)" "")) | 4340 (if restrict-ok " (restricted to current file)" "")) |
4437 (setq c (read-char-exclusive)) | 4341 (setq c (read-char-exclusive)) |
4438 (message ""))) | 4342 (message ""))) |
4439 (require 'calendar) ; FIXME: can we avoid this for some commands? | 4343 (require 'calendar) ; FIXME: can we avoid this for some commands? |
4344 ;; For example the todo list should not need it (but does...) | |
4440 (cond | 4345 (cond |
4441 ((equal c ?C) (customize-variable 'org-agenda-custom-commands)) | 4346 ((equal c ?C) (customize-variable 'org-agenda-custom-commands)) |
4442 ((equal c ?a) (call-interactively 'org-agenda-list)) | 4347 ((equal c ?a) (call-interactively 'org-agenda-list)) |
4443 ((equal c ?t) (call-interactively 'org-todo-list)) | 4348 ((equal c ?t) (call-interactively 'org-todo-list)) |
4444 ((equal c ?T) | 4349 ((equal c ?T) |
4453 (cond | 4358 (cond |
4454 ((eq type 'tags) | 4359 ((eq type 'tags) |
4455 (org-tags-view current-prefix-arg string)) | 4360 (org-tags-view current-prefix-arg string)) |
4456 ((eq type 'todo) | 4361 ((eq type 'todo) |
4457 (org-todo-list string)) | 4362 (org-todo-list string)) |
4363 ((eq type 'tags-tree) | |
4364 (org-check-for-org-mode) | |
4365 (org-tags-sparse-tree current-prefix-arg string)) | |
4366 ((eq type 'todo-tree) | |
4367 (org-check-for-org-mode) | |
4368 (org-occur (concat "^" outline-regexp "[ \t]*" | |
4369 (regexp-quote string) "\\>"))) | |
4370 ((eq type 'occur-tree) | |
4371 (org-check-for-org-mode) | |
4372 (org-occur string)) | |
4458 (t (error "Invalid custom agenda command type %s" type)))) | 4373 (t (error "Invalid custom agenda command type %s" type)))) |
4459 (t (error "Invalid key")))))) | 4374 (t (error "Invalid key")))))) |
4375 | |
4376 (defun org-check-for-org-mode () | |
4377 "Make sure current buffer is in org-mode. Error if not." | |
4378 (or (eq major-mode 'org-mode) | |
4379 (error "Cannot execute org-mode agenda command on buffer in %s." | |
4380 major-mode))) | |
4460 | 4381 |
4461 (defun org-fit-agenda-window () | 4382 (defun org-fit-agenda-window () |
4462 "Fit the window to the buffer size." | 4383 "Fit the window to the buffer size." |
4463 (and org-fit-agenda-window | 4384 (and org-fit-agenda-window |
4464 (fboundp 'fit-window-to-buffer) | 4385 (fboundp 'fit-window-to-buffer) |
4563 (switch-to-buffer-other-window | 4484 (switch-to-buffer-other-window |
4564 (get-buffer-create org-agenda-buffer-name)) | 4485 (get-buffer-create org-agenda-buffer-name)) |
4565 (setq buffer-read-only nil) | 4486 (setq buffer-read-only nil) |
4566 (erase-buffer) | 4487 (erase-buffer) |
4567 (org-agenda-mode) (setq buffer-read-only nil) | 4488 (org-agenda-mode) (setq buffer-read-only nil) |
4489 (set (make-local-variable 'org-agenda-type) 'timeline) | |
4568 (if doclosed (push :closed args)) | 4490 (if doclosed (push :closed args)) |
4569 (push :timestamp args) | 4491 (push :timestamp args) |
4570 (if dotodo (push :todo args)) | 4492 (if dotodo (push :todo args)) |
4571 (while (setq d (pop day-numbers)) | 4493 (while (setq d (pop day-numbers)) |
4572 (if (and (>= d today) | 4494 (if (and (>= d today) |
4651 (switch-to-buffer-other-window | 4573 (switch-to-buffer-other-window |
4652 (get-buffer-create org-agenda-buffer-name)))) | 4574 (get-buffer-create org-agenda-buffer-name)))) |
4653 (setq buffer-read-only nil) | 4575 (setq buffer-read-only nil) |
4654 (erase-buffer) | 4576 (erase-buffer) |
4655 (org-agenda-mode) (setq buffer-read-only nil) | 4577 (org-agenda-mode) (setq buffer-read-only nil) |
4578 (set (make-local-variable 'org-agenda-type) 'agenda) | |
4656 (set (make-local-variable 'starting-day) (car day-numbers)) | 4579 (set (make-local-variable 'starting-day) (car day-numbers)) |
4657 (set (make-local-variable 'include-all-loc) include-all) | 4580 (set (make-local-variable 'include-all-loc) include-all) |
4658 (when (and (or include-all org-agenda-include-all-todo) | 4581 (when (and (or include-all org-agenda-include-all-todo) |
4659 (member today day-numbers)) | 4582 (member today day-numbers)) |
4660 (setq files (org-agenda-files) | 4583 (setq files (org-agenda-files) |
4760 (switch-to-buffer-other-window | 4683 (switch-to-buffer-other-window |
4761 (get-buffer-create org-agenda-buffer-name)))) | 4684 (get-buffer-create org-agenda-buffer-name)))) |
4762 (setq buffer-read-only nil) | 4685 (setq buffer-read-only nil) |
4763 (erase-buffer) | 4686 (erase-buffer) |
4764 (org-agenda-mode) (setq buffer-read-only nil) | 4687 (org-agenda-mode) (setq buffer-read-only nil) |
4688 (set (make-local-variable 'org-agenda-type) 'todo) | |
4765 (set (make-local-variable 'last-arg) arg) | 4689 (set (make-local-variable 'last-arg) arg) |
4766 (set (make-local-variable 'org-todo-keywords) kwds) | 4690 (set (make-local-variable 'org-todo-keywords) kwds) |
4767 (set (make-local-variable 'org-agenda-redo-command) | 4691 (set (make-local-variable 'org-agenda-redo-command) |
4768 '(org-todo-list (or current-prefix-arg last-arg) t)) | 4692 '(org-todo-list (or current-prefix-arg last-arg) t)) |
4769 (setq files (org-agenda-files) | 4693 (setq files (org-agenda-files) |
4796 (if (not org-select-agenda-window) (select-window win)))) | 4720 (if (not org-select-agenda-window) (select-window win)))) |
4797 | 4721 |
4798 (defun org-check-agenda-file (file) | 4722 (defun org-check-agenda-file (file) |
4799 "Make sure FILE exists. If not, ask user what to do." | 4723 "Make sure FILE exists. If not, ask user what to do." |
4800 ;; FIXME: this does not correctly change the menus | 4724 ;; FIXME: this does not correctly change the menus |
4801 ;; Could probably be fixed by explicitly going to the buffer. | 4725 ;; Could probably be fixed by explicitly going to the buffer where |
4726 ;; the call originated. | |
4802 (when (not (file-exists-p file)) | 4727 (when (not (file-exists-p file)) |
4803 (message "non-existent file %s. [R]emove from agenda-files or [A]bort?" | 4728 (message "non-existent file %s. [R]emove from agenda-files or [A]bort?" |
4804 file) | 4729 file) |
4805 (let ((r (downcase (read-char-exclusive)))) | 4730 (let ((r (downcase (read-char-exclusive)))) |
4806 (cond | 4731 (cond |
4807 ((equal r ?r) | 4732 ((equal r ?r) |
4808 (org-remove-file file) | 4733 (org-remove-file file) |
4809 (throw 'nextfile t)) | 4734 (throw 'nextfile t)) |
4810 (t (error "Abort")))))) | 4735 (t (error "Abort")))))) |
4811 | 4736 |
4737 (defun org-agenda-check-type (error &rest types) | |
4738 "Check if agenda buffer is of allowed type. | |
4739 If ERROR is non-nil, throw an error, otherwise just return nil." | |
4740 (if (memq org-agenda-type types) | |
4741 t | |
4742 (if error | |
4743 (error "Now allowed in %s-type agenda buffers" org-agenda-type) | |
4744 nil))) | |
4745 | |
4812 (defun org-agenda-quit () | 4746 (defun org-agenda-quit () |
4813 "Exit agenda by removing the window or the buffer." | 4747 "Exit agenda by removing the window or the buffer." |
4814 (interactive) | 4748 (interactive) |
4815 (let ((buf (current-buffer))) | 4749 (let ((buf (current-buffer))) |
4816 (if (not (one-window-p)) (delete-window)) | 4750 (if (not (one-window-p)) (delete-window)) |
4828 | 4762 |
4829 (defun org-agenda-redo () | 4763 (defun org-agenda-redo () |
4830 "Rebuild Agenda. | 4764 "Rebuild Agenda. |
4831 When this is the global TODO list, a prefix argument will be interpreted." | 4765 When this is the global TODO list, a prefix argument will be interpreted." |
4832 (interactive) | 4766 (interactive) |
4833 (eval org-agenda-redo-command)) | 4767 (message "Rebuilding agenda buffer...") |
4768 (eval org-agenda-redo-command) | |
4769 (message "Rebuilding agenda buffer...done")) | |
4834 | 4770 |
4835 (defun org-agenda-goto-today () | 4771 (defun org-agenda-goto-today () |
4836 "Go to today." | 4772 "Go to today." |
4837 (interactive) | 4773 (interactive) |
4774 (org-agenda-check-type t 'timeline 'agenda) | |
4838 (if (boundp 'starting-day) | 4775 (if (boundp 'starting-day) |
4839 (let ((cmd (car org-agenda-redo-command)) | 4776 (let ((cmd (car org-agenda-redo-command)) |
4840 (iall (nth 1 org-agenda-redo-command)) | 4777 (iall (nth 1 org-agenda-redo-command)) |
4841 (nday (nth 3 org-agenda-redo-command)) | 4778 (nday (nth 3 org-agenda-redo-command)) |
4842 (keep (nth 4 org-agenda-redo-command))) | 4779 (keep (nth 4 org-agenda-redo-command))) |
4846 | 4783 |
4847 (defun org-agenda-later (arg) | 4784 (defun org-agenda-later (arg) |
4848 "Go forward in time by `org-agenda-ndays' days. | 4785 "Go forward in time by `org-agenda-ndays' days. |
4849 With prefix ARG, go forward that many times `org-agenda-ndays'." | 4786 With prefix ARG, go forward that many times `org-agenda-ndays'." |
4850 (interactive "p") | 4787 (interactive "p") |
4851 (unless (boundp 'starting-day) | 4788 (org-agenda-check-type t 'agenda) |
4852 (error "Not allowed")) | |
4853 (org-agenda-list (if (boundp 'include-all-loc) include-all-loc nil) | 4789 (org-agenda-list (if (boundp 'include-all-loc) include-all-loc nil) |
4854 (+ starting-day (* arg org-agenda-ndays)) nil t)) | 4790 (+ starting-day (* arg org-agenda-ndays)) nil t)) |
4855 | 4791 |
4856 (defun org-agenda-earlier (arg) | 4792 (defun org-agenda-earlier (arg) |
4857 "Go back in time by `org-agenda-ndays' days. | 4793 "Go back in time by `org-agenda-ndays' days. |
4858 With prefix ARG, go back that many times `org-agenda-ndays'." | 4794 With prefix ARG, go back that many times `org-agenda-ndays'." |
4859 (interactive "p") | 4795 (interactive "p") |
4860 (unless (boundp 'starting-day) | 4796 (org-agenda-check-type t 'agenda) |
4861 (error "Not allowed")) | |
4862 (org-agenda-list (if (boundp 'include-all-loc) include-all-loc nil) | 4797 (org-agenda-list (if (boundp 'include-all-loc) include-all-loc nil) |
4863 (- starting-day (* arg org-agenda-ndays)) nil t)) | 4798 (- starting-day (* arg org-agenda-ndays)) nil t)) |
4864 | 4799 |
4865 (defun org-agenda-week-view () | 4800 (defun org-agenda-week-view () |
4866 "Switch to weekly view for agenda." | 4801 "Switch to weekly view for agenda." |
4867 (interactive) | 4802 (interactive) |
4868 (unless (boundp 'starting-day) | 4803 (org-agenda-check-type t 'agenda) |
4869 (error "Not allowed")) | |
4870 (setq org-agenda-ndays 7) | 4804 (setq org-agenda-ndays 7) |
4871 (org-agenda-list include-all-loc | 4805 (org-agenda-list include-all-loc |
4872 (or (get-text-property (point) 'day) | 4806 (or (get-text-property (point) 'day) |
4873 starting-day) | 4807 starting-day) |
4874 nil t) | 4808 nil t) |
4876 (message "Switched to week view")) | 4810 (message "Switched to week view")) |
4877 | 4811 |
4878 (defun org-agenda-day-view () | 4812 (defun org-agenda-day-view () |
4879 "Switch to weekly view for agenda." | 4813 "Switch to weekly view for agenda." |
4880 (interactive) | 4814 (interactive) |
4881 (unless (boundp 'starting-day) | 4815 (org-agenda-check-type t 'agenda) |
4882 (error "Not allowed")) | |
4883 (setq org-agenda-ndays 1) | 4816 (setq org-agenda-ndays 1) |
4884 (org-agenda-list include-all-loc | 4817 (org-agenda-list include-all-loc |
4885 (or (get-text-property (point) 'day) | 4818 (or (get-text-property (point) 'day) |
4886 starting-day) | 4819 starting-day) |
4887 nil t) | 4820 nil t) |
4889 (message "Switched to day view")) | 4822 (message "Switched to day view")) |
4890 | 4823 |
4891 (defun org-agenda-next-date-line (&optional arg) | 4824 (defun org-agenda-next-date-line (&optional arg) |
4892 "Jump to the next line indicating a date in agenda buffer." | 4825 "Jump to the next line indicating a date in agenda buffer." |
4893 (interactive "p") | 4826 (interactive "p") |
4827 (org-agenda-check-type t 'agenda 'timeline) | |
4894 (beginning-of-line 1) | 4828 (beginning-of-line 1) |
4895 (if (looking-at "^\\S-") (forward-char 1)) | 4829 (if (looking-at "^\\S-") (forward-char 1)) |
4896 (if (not (re-search-forward "^\\S-" nil t arg)) | 4830 (if (not (re-search-forward "^\\S-" nil t arg)) |
4897 (progn | 4831 (progn |
4898 (backward-char 1) | 4832 (backward-char 1) |
4900 (goto-char (match-beginning 0))) | 4834 (goto-char (match-beginning 0))) |
4901 | 4835 |
4902 (defun org-agenda-previous-date-line (&optional arg) | 4836 (defun org-agenda-previous-date-line (&optional arg) |
4903 "Jump to the next line indicating a date in agenda buffer." | 4837 "Jump to the next line indicating a date in agenda buffer." |
4904 (interactive "p") | 4838 (interactive "p") |
4839 (org-agenda-check-type t 'agenda 'timeline) | |
4905 (beginning-of-line 1) | 4840 (beginning-of-line 1) |
4906 (if (not (re-search-backward "^\\S-" nil t arg)) | 4841 (if (not (re-search-backward "^\\S-" nil t arg)) |
4907 (error "No previous date before this line in this buffer"))) | 4842 (error "No previous date before this line in this buffer"))) |
4908 | 4843 |
4909 ;; Initialize the highlight | 4844 ;; Initialize the highlight |
4910 (defvar org-hl (funcall (if org-xemacs-p 'make-extent 'make-overlay) 1 1)) | 4845 (defvar org-hl (org-make-overlay 1 1)) |
4911 (funcall (if org-xemacs-p 'set-extent-property 'overlay-put) org-hl | 4846 (org-overlay-put org-hl 'face 'highlight) |
4912 'face 'highlight) | |
4913 | 4847 |
4914 (defun org-highlight (begin end &optional buffer) | 4848 (defun org-highlight (begin end &optional buffer) |
4915 "Highlight a region with overlay." | 4849 "Highlight a region with overlay." |
4916 (funcall (if org-xemacs-p 'set-extent-endpoints 'move-overlay) | 4850 (funcall (if org-xemacs-p 'set-extent-endpoints 'move-overlay) |
4917 org-hl begin end (or buffer (current-buffer)))) | 4851 org-hl begin end (or buffer (current-buffer)))) |
4930 (if org-agenda-follow-mode "on" "off"))) | 4864 (if org-agenda-follow-mode "on" "off"))) |
4931 | 4865 |
4932 (defun org-agenda-log-mode () | 4866 (defun org-agenda-log-mode () |
4933 "Toggle follow mode in an agenda buffer." | 4867 "Toggle follow mode in an agenda buffer." |
4934 (interactive) | 4868 (interactive) |
4869 (org-agenda-check-type t 'agenda 'timeline) | |
4935 (setq org-agenda-show-log (not org-agenda-show-log)) | 4870 (setq org-agenda-show-log (not org-agenda-show-log)) |
4936 (org-agenda-set-mode-name) | 4871 (org-agenda-set-mode-name) |
4937 (org-agenda-redo) | 4872 (org-agenda-redo) |
4938 (message "Log mode is %s" | 4873 (message "Log mode is %s" |
4939 (if org-agenda-show-log "on" "off"))) | 4874 (if org-agenda-show-log "on" "off"))) |
4940 | 4875 |
4941 (defun org-agenda-toggle-diary () | 4876 (defun org-agenda-toggle-diary () |
4942 "Toggle follow mode in an agenda buffer." | 4877 "Toggle follow mode in an agenda buffer." |
4943 (interactive) | 4878 (interactive) |
4879 (org-agenda-check-type t 'agenda) | |
4944 (setq org-agenda-include-diary (not org-agenda-include-diary)) | 4880 (setq org-agenda-include-diary (not org-agenda-include-diary)) |
4945 (org-agenda-redo) | 4881 (org-agenda-redo) |
4946 (org-agenda-set-mode-name) | 4882 (org-agenda-set-mode-name) |
4947 (message "Diary inclusion turned %s" | 4883 (message "Diary inclusion turned %s" |
4948 (if org-agenda-include-diary "on" "off"))) | 4884 (if org-agenda-include-diary "on" "off"))) |
4949 | 4885 |
4950 (defun org-agenda-toggle-time-grid () | 4886 (defun org-agenda-toggle-time-grid () |
4951 "Toggle follow mode in an agenda buffer." | 4887 "Toggle follow mode in an agenda buffer." |
4952 (interactive) | 4888 (interactive) |
4889 (org-agenda-check-type t 'agenda) | |
4953 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid)) | 4890 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid)) |
4954 (org-agenda-redo) | 4891 (org-agenda-redo) |
4955 (org-agenda-set-mode-name) | 4892 (org-agenda-set-mode-name) |
4956 (message "Time-grid turned %s" | 4893 (message "Time-grid turned %s" |
4957 (if org-agenda-use-time-grid "on" "off"))) | 4894 (if org-agenda-use-time-grid "on" "off"))) |
5363 marker priority category | 5300 marker priority category |
5364 ee txt) | 5301 ee txt) |
5365 (goto-char (point-min)) | 5302 (goto-char (point-min)) |
5366 (while (re-search-forward regexp nil t) | 5303 (while (re-search-forward regexp nil t) |
5367 (goto-char (match-beginning 1)) | 5304 (goto-char (match-beginning 1)) |
5368 (setq marker (org-agenda-new-marker (point-at-bol)) | 5305 (setq marker (org-agenda-new-marker (1+ (match-beginning 0))) |
5369 category (org-get-category) | 5306 category (org-get-category) |
5370 txt (org-format-agenda-item "" (match-string 1) category) | 5307 txt (org-format-agenda-item "" (match-string 1) category) |
5371 priority | 5308 priority |
5372 (+ (org-get-priority txt) | 5309 (+ (org-get-priority txt) |
5373 (if org-todo-kwd-priority-p | 5310 (if org-todo-kwd-priority-p |
5374 (- org-todo-kwd-max-priority -2 | 5311 (- org-todo-kwd-max-priority -2 |
5375 (length | 5312 (length |
5376 (member (match-string 2) org-todo-keywords))) | 5313 (member (match-string 2) org-todo-keywords))) |
5377 1))) | 5314 1))) |
5378 (add-text-properties | 5315 (add-text-properties |
5379 0 (length txt) (append (list 'org-marker marker 'org-hd-marker marker | 5316 0 (length txt) (append (list 'org-marker marker 'org-hd-marker marker |
5380 'priority priority 'category category) | 5317 'priority priority 'category category) |
5381 props) | 5318 props) |
5382 txt) | 5319 txt) |
6087 | 6024 |
6088 (defun org-agenda-set-tags () | 6025 (defun org-agenda-set-tags () |
6089 "Set tags for the current headline." | 6026 "Set tags for the current headline." |
6090 (interactive) | 6027 (interactive) |
6091 (org-agenda-check-no-diary) | 6028 (org-agenda-check-no-diary) |
6092 (let* ((marker (or (get-text-property (point) 'org-marker) | 6029 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed |
6093 (org-agenda-error))) | 6030 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker) |
6094 (hdmarker (get-text-property (point) 'org-hd-marker)) | 6031 (org-agenda-error))) |
6095 (buffer (marker-buffer hdmarker)) | 6032 (buffer (marker-buffer hdmarker)) |
6096 (pos (marker-position hdmarker)) | 6033 (pos (marker-position hdmarker)) |
6097 (buffer-read-only nil) | 6034 (buffer-read-only nil) |
6098 newhead) | 6035 newhead) |
6099 (with-current-buffer buffer | 6036 (with-current-buffer buffer |
6110 (beginning-of-line 1))) | 6047 (beginning-of-line 1))) |
6111 | 6048 |
6112 (defun org-agenda-date-later (arg &optional what) | 6049 (defun org-agenda-date-later (arg &optional what) |
6113 "Change the date of this item to one day later." | 6050 "Change the date of this item to one day later." |
6114 (interactive "p") | 6051 (interactive "p") |
6052 (org-agenda-check-type t 'agenda 'timeline) | |
6115 (org-agenda-check-no-diary) | 6053 (org-agenda-check-no-diary) |
6116 (let* ((marker (or (get-text-property (point) 'org-marker) | 6054 (let* ((marker (or (get-text-property (point) 'org-marker) |
6117 (org-agenda-error))) | 6055 (org-agenda-error))) |
6118 (buffer (marker-buffer marker)) | 6056 (buffer (marker-buffer marker)) |
6119 (pos (marker-position marker))) | 6057 (pos (marker-position marker))) |
6133 (defun org-agenda-date-prompt (arg) | 6071 (defun org-agenda-date-prompt (arg) |
6134 "Change the date of this item. Date is prompted for, with default today. | 6072 "Change the date of this item. Date is prompted for, with default today. |
6135 The prefix ARG is passed to the `org-time-stamp' command and can therefore | 6073 The prefix ARG is passed to the `org-time-stamp' command and can therefore |
6136 be used to request time specification in the time stamp." | 6074 be used to request time specification in the time stamp." |
6137 (interactive "P") | 6075 (interactive "P") |
6076 (org-agenda-check-type t 'agenda 'timeline) | |
6138 (org-agenda-check-no-diary) | 6077 (org-agenda-check-no-diary) |
6139 (let* ((marker (or (get-text-property (point) 'org-marker) | 6078 (let* ((marker (or (get-text-property (point) 'org-marker) |
6140 (org-agenda-error))) | 6079 (org-agenda-error))) |
6141 (buffer (marker-buffer marker)) | 6080 (buffer (marker-buffer marker)) |
6142 (pos (marker-position marker))) | 6081 (pos (marker-position marker))) |
6149 (message "Time stamp changed to %s" org-last-changed-timestamp)))) | 6088 (message "Time stamp changed to %s" org-last-changed-timestamp)))) |
6150 | 6089 |
6151 (defun org-get-heading () | 6090 (defun org-get-heading () |
6152 "Return the heading of the current entry, without the stars." | 6091 "Return the heading of the current entry, without the stars." |
6153 (save-excursion | 6092 (save-excursion |
6154 (and (bolp) (end-of-line 1)) | 6093 (and (memq (char-before) '(?\n ?\r)) (skip-chars-forward "^\n\r")) |
6094 ;;FIXME???????? (and (bolp) (end-of-line 1)) | |
6155 (if (and (re-search-backward "[\r\n]\\*" nil t) | 6095 (if (and (re-search-backward "[\r\n]\\*" nil t) |
6156 (looking-at "[\r\n]\\*+[ \t]+\\(.*\\)")) | 6096 (looking-at "[\r\n]\\*+[ \t]+\\([^\r\n]*\\)")) |
6157 (match-string 1) | 6097 (match-string 1) |
6158 ""))) | 6098 ""))) |
6159 | 6099 |
6160 (defun org-agenda-diary-entry () | 6100 (defun org-agenda-diary-entry () |
6161 "Make a diary entry, like the `i' command from the calendar. | 6101 "Make a diary entry, like the `i' command from the calendar. |
6162 All the standard commands work: block, weekly etc" | 6102 All the standard commands work: block, weekly etc" |
6163 (interactive) | 6103 (interactive) |
6104 (org-agenda-check-type t 'agenda 'timeline) | |
6164 (require 'diary-lib) | 6105 (require 'diary-lib) |
6165 (let* ((char (progn | 6106 (let* ((char (progn |
6166 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic") | 6107 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic") |
6167 (read-char-exclusive))) | 6108 (read-char-exclusive))) |
6168 (cmd (cdr (assoc char | 6109 (cmd (cdr (assoc char |
6199 | 6140 |
6200 | 6141 |
6201 (defun org-agenda-execute-calendar-command (cmd) | 6142 (defun org-agenda-execute-calendar-command (cmd) |
6202 "Execute a calendar command from the agenda, with the date associated to | 6143 "Execute a calendar command from the agenda, with the date associated to |
6203 the cursor position." | 6144 the cursor position." |
6145 (org-agenda-check-type t 'agenda 'timeline) | |
6204 (require 'diary-lib) | 6146 (require 'diary-lib) |
6205 (unless (get-text-property (point) 'day) | 6147 (unless (get-text-property (point) 'day) |
6206 (error "Don't know which date to use for calendar command")) | 6148 (error "Don't know which date to use for calendar command")) |
6207 (let* ((oldf (symbol-function 'calendar-cursor-to-date)) | 6149 (let* ((oldf (symbol-function 'calendar-cursor-to-date)) |
6208 (point (point)) | 6150 (point (point)) |
6243 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset))) | 6185 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset))) |
6244 | 6186 |
6245 (defun org-agenda-goto-calendar () | 6187 (defun org-agenda-goto-calendar () |
6246 "Open the Emacs calendar with the date at the cursor." | 6188 "Open the Emacs calendar with the date at the cursor." |
6247 (interactive) | 6189 (interactive) |
6190 (org-agenda-check-type t 'agenda 'timeline) | |
6248 (let* ((day (or (get-text-property (point) 'day) | 6191 (let* ((day (or (get-text-property (point) 'day) |
6249 (error "Don't know which date to open in calendar"))) | 6192 (error "Don't know which date to open in calendar"))) |
6250 (date (calendar-gregorian-from-absolute day)) | 6193 (date (calendar-gregorian-from-absolute day)) |
6251 (calendar-move-hook nil) | 6194 (calendar-move-hook nil) |
6252 (view-diary-entries-initially nil)) | 6195 (view-diary-entries-initially nil)) |
6261 (calendar-cursor-to-date)) | 6204 (calendar-cursor-to-date)) |
6262 nil t)) | 6205 nil t)) |
6263 | 6206 |
6264 (defun org-agenda-convert-date () | 6207 (defun org-agenda-convert-date () |
6265 (interactive) | 6208 (interactive) |
6209 (org-agenda-check-type t 'agenda 'timeline) | |
6266 (let ((day (get-text-property (point) 'day)) | 6210 (let ((day (get-text-property (point) 'day)) |
6267 date s) | 6211 date s) |
6268 (unless day | 6212 (unless day |
6269 (error "Don't know which date to convert")) | 6213 (error "Don't know which date to convert")) |
6270 (setq date (calendar-gregorian-from-absolute day)) | 6214 (setq date (calendar-gregorian-from-absolute day)) |
6283 "Ethiopic: " (calendar-ethiopic-date-string date) "\n" | 6227 "Ethiopic: " (calendar-ethiopic-date-string date) "\n" |
6284 "Persian: " (calendar-persian-date-string date) "\n" | 6228 "Persian: " (calendar-persian-date-string date) "\n" |
6285 "Chinese: " (calendar-chinese-date-string date) "\n")) | 6229 "Chinese: " (calendar-chinese-date-string date) "\n")) |
6286 (with-output-to-temp-buffer "*Dates*" | 6230 (with-output-to-temp-buffer "*Dates*" |
6287 (princ s)) | 6231 (princ s)) |
6288 (fit-window-to-buffer (get-buffer-window "*Dates*")))) | 6232 (if (fboundp 'fit-window-to-buffer) |
6233 (fit-window-to-buffer (get-buffer-window "*Dates*"))))) | |
6289 | 6234 |
6290 ;;; Tags | 6235 ;;; Tags |
6291 | 6236 |
6292 (defun org-scan-tags (action matcher &optional todo-only) | 6237 (defun org-scan-tags (action matcher &optional todo-only) |
6293 "Scan headline tags with inheritance and produce output ACTION. | 6238 "Scan headline tags with inheritance and produce output ACTION. |
6306 'mouse-face 'highlight | 6251 'mouse-face 'highlight |
6307 'keymap org-agenda-keymap | 6252 'keymap org-agenda-keymap |
6308 'help-echo | 6253 'help-echo |
6309 (format "mouse-2 or RET jump to org file %s" | 6254 (format "mouse-2 or RET jump to org file %s" |
6310 (abbreviate-file-name (buffer-file-name))))) | 6255 (abbreviate-file-name (buffer-file-name))))) |
6256 lspos | |
6311 tags tags-list tags-alist (llast 0) rtn level category i txt | 6257 tags tags-list tags-alist (llast 0) rtn level category i txt |
6312 todo marker) | 6258 todo marker) |
6313 | 6259 |
6314 (save-excursion | 6260 (save-excursion |
6315 (goto-char (point-min)) | 6261 (goto-char (point-min)) |
6316 (when (eq action 'sparse-tree) (hide-sublevels 1)) | 6262 (when (eq action 'sparse-tree) (hide-sublevels 1)) |
6317 (while (re-search-forward re nil t) | 6263 (while (re-search-forward re nil t) |
6318 (setq todo (if (match-end 1) (match-string 2)) | 6264 (setq todo (if (match-end 1) (match-string 2)) |
6319 tags (if (match-end 4) (match-string 4))) | 6265 tags (if (match-end 4) (match-string 4))) |
6320 (goto-char (1+ (match-beginning 0))) | 6266 (goto-char (setq lspos (1+ (match-beginning 0)))) |
6321 (setq level (outline-level) | 6267 (setq level (outline-level) |
6322 category (org-get-category)) | 6268 category (org-get-category)) |
6323 (setq i llast llast level) | 6269 (setq i llast llast level) |
6324 ;; remove tag lists from same and sublevels | 6270 ;; remove tag lists from same and sublevels |
6325 (while (>= i level) | 6271 (while (>= i level) |
6347 (concat | 6293 (concat |
6348 (if org-tags-match-list-sublevels | 6294 (if org-tags-match-list-sublevels |
6349 (make-string (1- level) ?.) "") | 6295 (make-string (1- level) ?.) "") |
6350 (org-get-heading)) | 6296 (org-get-heading)) |
6351 category)) | 6297 category)) |
6298 (goto-char lspos) | |
6352 (setq marker (org-agenda-new-marker)) | 6299 (setq marker (org-agenda-new-marker)) |
6353 (add-text-properties | 6300 (add-text-properties |
6354 0 (length txt) | 6301 0 (length txt) |
6355 (append (list 'org-marker marker 'org-hd-marker marker | 6302 (append (list 'org-marker marker 'org-hd-marker marker |
6356 'category category) | 6303 'category category) |
6357 props) | 6304 props) |
6358 txt) | 6305 txt) |
6359 (push txt rtn)) | 6306 (push txt rtn)) |
6360 ;; if we are to skip sublevels, jump to end of subtree | 6307 ;; if we are to skip sublevels, jump to end of subtree |
6361 (or org-tags-match-list-sublevels (outline-end-of-subtree))))) | 6308 (point) |
6309 (or org-tags-match-list-sublevels (org-end-of-subtree))))) | |
6362 (nreverse rtn))) | 6310 (nreverse rtn))) |
6363 | 6311 |
6364 (defun org-tags-sparse-tree (&optional arg match) | 6312 (defun org-tags-sparse-tree (&optional arg match) |
6365 "Create a sparse tree according to tags search string MATCH. | 6313 "Create a sparse tree according to tags search string MATCH. |
6366 MATCH can contain positive and negative selection of tags, like | 6314 MATCH can contain positive and negative selection of tags, like |
6397 (setq matcher nil)) | 6345 (setq matcher nil)) |
6398 (setq matcher (if (> (length orlist) 1) (cons 'or orlist) (car orlist))) | 6346 (setq matcher (if (> (length orlist) 1) (cons 'or orlist) (car orlist))) |
6399 ;; Return the string and lisp forms of the matcher | 6347 ;; Return the string and lisp forms of the matcher |
6400 (cons match0 matcher))) | 6348 (cons match0 matcher))) |
6401 | 6349 |
6402 ;;(org-make-tags-matcher "&hello&-you") | |
6403 | |
6404 | |
6405 ;;;###autoload | 6350 ;;;###autoload |
6406 (defun org-tags-view (&optional todo-only match keep-modes) | 6351 (defun org-tags-view (&optional todo-only match keep-modes) |
6407 "Show all headlines for all `org-agenda-files' matching a TAGS criterions. | 6352 "Show all headlines for all `org-agenda-files' matching a TAGS criterions. |
6408 The prefix arg TODO-ONLY limits the search to TODO entries." | 6353 The prefix arg TODO-ONLY limits the search to TODO entries." |
6409 (interactive "P") | 6354 (interactive "P") |
6410 (org-agenda-maybe-reset-markers 'force) | 6355 (org-agenda-maybe-reset-markers 'force) |
6411 (org-compile-prefix-format org-agenda-prefix-format) | 6356 (org-compile-prefix-format org-agenda-prefix-format) |
6412 (let* ((org-agenda-keep-modes keep-modes) | 6357 (let* ((org-agenda-keep-modes keep-modes) |
6358 (org-tags-match-list-sublevels | |
6359 (if todo-only t org-tags-match-list-sublevels)) | |
6413 (win (selected-window)) | 6360 (win (selected-window)) |
6414 (completion-ignore-case t) | 6361 (completion-ignore-case t) |
6415 rtn rtnall files file pos matcher | 6362 rtn rtnall files file pos matcher |
6416 buffer) | 6363 buffer) |
6417 (setq matcher (org-make-tags-matcher match) | 6364 (setq matcher (org-make-tags-matcher match) |
6422 (switch-to-buffer-other-window | 6369 (switch-to-buffer-other-window |
6423 (get-buffer-create org-agenda-buffer-name)))) | 6370 (get-buffer-create org-agenda-buffer-name)))) |
6424 (setq buffer-read-only nil) | 6371 (setq buffer-read-only nil) |
6425 (erase-buffer) | 6372 (erase-buffer) |
6426 (org-agenda-mode) (setq buffer-read-only nil) | 6373 (org-agenda-mode) (setq buffer-read-only nil) |
6374 (set (make-local-variable 'org-agenda-type) 'tags) | |
6427 (set (make-local-variable 'org-agenda-redo-command) | 6375 (set (make-local-variable 'org-agenda-redo-command) |
6428 '(call-interactively 'org-tags-view)) | 6376 (list 'org-tags-view (list 'quote todo-only) |
6377 (list 'if 'current-prefix-arg nil match) t)) | |
6429 (setq files (org-agenda-files) | 6378 (setq files (org-agenda-files) |
6430 rtnall nil) | 6379 rtnall nil) |
6431 (while (setq file (pop files)) | 6380 (while (setq file (pop files)) |
6432 (catch 'nextfile | 6381 (catch 'nextfile |
6433 (org-check-agenda-file file) | 6382 (org-check-agenda-file file) |
6457 (add-text-properties (point-min) (1- (point)) | 6406 (add-text-properties (point-min) (1- (point)) |
6458 (list 'face 'org-link)) | 6407 (list 'face 'org-link)) |
6459 (setq pos (point)) | 6408 (setq pos (point)) |
6460 (insert match "\n") | 6409 (insert match "\n") |
6461 (add-text-properties pos (1- (point)) (list 'face 'org-warning)) | 6410 (add-text-properties pos (1- (point)) (list 'face 'org-warning)) |
6411 (setq pos (point)) | |
6412 (insert "Press `C-u r' to search again with new search string\n") | |
6413 (add-text-properties pos (1- (point)) (list 'face 'org-link)) | |
6462 (when rtnall | 6414 (when rtnall |
6463 (insert (mapconcat 'identity rtnall "\n"))) | 6415 (insert (mapconcat 'identity rtnall "\n"))) |
6464 (goto-char (point-min)) | 6416 (goto-char (point-min)) |
6465 (setq buffer-read-only t) | 6417 (setq buffer-read-only t) |
6466 (org-fit-agenda-window) | 6418 (org-fit-agenda-window) |
6473 (interactive) | 6425 (interactive) |
6474 (let* (;(inherit (org-get-inherited-tags)) | 6426 (let* (;(inherit (org-get-inherited-tags)) |
6475 (re (concat "^" outline-regexp)) | 6427 (re (concat "^" outline-regexp)) |
6476 (col (current-column)) | 6428 (col (current-column)) |
6477 (current (org-get-tags)) | 6429 (current (org-get-tags)) |
6478 tags hd) | 6430 tags hd empty) |
6479 (if arg | 6431 (if arg |
6480 (save-excursion | 6432 (save-excursion |
6481 (goto-char (point-min)) | 6433 (goto-char (point-min)) |
6482 (while (re-search-forward re nil t) | 6434 (while (re-search-forward re nil t) |
6483 (org-set-tags nil t)) | 6435 (org-set-tags nil t)) |
6491 (let ((org-add-colon-after-tag-completion t)) | 6443 (let ((org-add-colon-after-tag-completion t)) |
6492 (completing-read "Tags: " 'org-tags-completion-function | 6444 (completing-read "Tags: " 'org-tags-completion-function |
6493 nil nil current 'org-tags-history))) | 6445 nil nil current 'org-tags-history))) |
6494 (while (string-match "[-+&]+" tags) | 6446 (while (string-match "[-+&]+" tags) |
6495 (setq tags (replace-match ":" t t tags))) | 6447 (setq tags (replace-match ":" t t tags))) |
6496 (unless (string-match ":$" tags) (setq tags (concat tags ":"))) | 6448 (unless (setq empty (string-match "\\`[\t ]*\\'" tags)) |
6497 (unless (string-match "^:" tags) (setq tags (concat ":" tags)))) | 6449 (unless (string-match ":$" tags) (setq tags (concat tags ":"))) |
6450 (unless (string-match "^:" tags) (setq tags (concat ":" tags))))) | |
6498 (if (equal current "") | 6451 (if (equal current "") |
6499 (end-of-line 1) | 6452 (progn |
6453 (end-of-line 1) | |
6454 (or empty (insert " "))) | |
6500 (beginning-of-line 1) | 6455 (beginning-of-line 1) |
6501 (looking-at (concat "\\(.*\\)\\(" (regexp-quote current) "\\)[ \t]*")) | 6456 (looking-at (concat "\\(.*\\)\\(" (regexp-quote current) "\\)[ \t]*")) |
6502 (setq hd (match-string 1)) | 6457 (setq hd (match-string 1)) |
6503 (delete-region (match-beginning 0) (match-end 0)) | 6458 (delete-region (match-beginning 0) (match-end 0)) |
6504 (insert (org-trim hd) " ")) | 6459 (insert (org-trim hd) (if empty "" " "))) |
6505 (unless (equal tags "") | 6460 (unless (equal tags "") |
6506 (move-to-column (max (current-column) | 6461 (move-to-column (max (current-column) |
6507 (if (> org-tags-column 0) | 6462 (if (> org-tags-column 0) |
6508 org-tags-column | 6463 org-tags-column |
6509 (- (- org-tags-column) (length tags)))) | 6464 (- (- org-tags-column) (length tags)))) |
6551 (let (tags) | 6506 (let (tags) |
6552 (save-excursion | 6507 (save-excursion |
6553 (goto-char (point-min)) | 6508 (goto-char (point-min)) |
6554 (while (re-search-forward "[ \t]:\\([A-Za-z_:]+\\):[ \t\r\n]" nil t) | 6509 (while (re-search-forward "[ \t]:\\([A-Za-z_:]+\\):[ \t\r\n]" nil t) |
6555 (mapc (lambda (x) (add-to-list 'tags x)) | 6510 (mapc (lambda (x) (add-to-list 'tags x)) |
6556 (org-split-string (match-string-no-properties 1) ":")))) | 6511 (org-split-string (match-string 1) ":")))) |
6557 (mapcar 'list tags))) | 6512 (mapcar 'list tags))) |
6558 | 6513 |
6559 ;;; Link Stuff | 6514 ;;; Link Stuff |
6560 | 6515 |
6561 (defun org-find-file-at-mouse (ev) | 6516 (defun org-find-file-at-mouse (ev) |
11540 (interactive "P") | 11495 (interactive "P") |
11541 (if (org-at-table-p) | 11496 (if (org-at-table-p) |
11542 (org-table-paste-rectangle) | 11497 (org-table-paste-rectangle) |
11543 (org-paste-subtree arg))) | 11498 (org-paste-subtree arg))) |
11544 | 11499 |
11545 ;; FIXME: document tags | |
11546 (defun org-ctrl-c-ctrl-c (&optional arg) | 11500 (defun org-ctrl-c-ctrl-c (&optional arg) |
11547 "Call realign table, or recognize a table.el table, or update keywords. | 11501 "Call realign table, or recognize a table.el table, or update keywords. |
11548 When the cursor is inside a table created by the table.el package, | 11502 When the cursor is inside a table created by the table.el package, |
11549 activate that table. Otherwise, if the cursor is at a normal table | 11503 activate that table. Otherwise, if the cursor is at a normal table |
11550 created with org.el, re-align that table. This command works even if | 11504 created with org.el, re-align that table. This command works even if |
11551 the automatic table editor has been turned off. | 11505 the automatic table editor has been turned off. |
11506 | |
11507 If the cursor is in a headline, prompt for tags and insert them into | |
11508 the current line, aligned to `org-tags-column'. When in a headline and | |
11509 called with prefix arg, realign all tags in the current buffer. | |
11510 | |
11552 If the cursor is in one of the special #+KEYWORD lines, this triggers | 11511 If the cursor is in one of the special #+KEYWORD lines, this triggers |
11553 scanning the buffer for these lines and updating the information. | 11512 scanning the buffer for these lines and updating the information. |
11554 If the cursor is on a #+TBLFM line, re-apply the formulae to the table." | 11513 If the cursor is on a #+TBLFM line, re-apply the formulae to the table." |
11555 (interactive "P") | 11514 (interactive "P") |
11556 (let ((org-enable-table-editor t)) | 11515 (let ((org-enable-table-editor t)) |
11944 image-file-name-extensions) | 11903 image-file-name-extensions) |
11945 image-file-name-extensions) | 11904 image-file-name-extensions) |
11946 t) | 11905 t) |
11947 "\\'")))) | 11906 "\\'")))) |
11948 | 11907 |
11949 ;; Functions needed for compatibility with old outline.el | 11908 ;; Functions needed for compatibility with old outline.el. |
11909 | |
11910 ;; Programming for the old outline.el (that uses selective display | |
11911 ;; instead of `invisible' text properties) is a nightmare, mostly | |
11912 ;; because regular expressions can no longer be anchored at | |
11913 ;; beginning/end of line. Therefore a number of function need special | |
11914 ;; treatment when the old outline.el is being used. | |
11950 | 11915 |
11951 ;; The following functions capture almost the entire compatibility code | 11916 ;; The following functions capture almost the entire compatibility code |
11952 ;; between the different versions of outline-mode. The only other place | 11917 ;; between the different versions of outline-mode. The only other |
11953 ;; where this is important are the font-lock-keywords. Search for | 11918 ;; places where this is important are the font-lock-keywords, and in |
11954 ;; `org-noutline-p' to find it. | 11919 ;; `org-export-copy-visible'. Search for `org-noutline-p' to find them. |
11955 | 11920 |
11956 ;; C-a should go to the beginning of a *visible* line, also in the | 11921 ;; C-a should go to the beginning of a *visible* line, also in the |
11957 ;; new outline.el. I guess this should be patched into Emacs? | 11922 ;; new outline.el. I guess this should be patched into Emacs? |
11958 (defun org-beginning-of-line () | 11923 (defun org-beginning-of-line () |
11959 "Go to the beginning of the current line. If that is invisible, continue | 11924 "Go to the beginning of the current line. If that is invisible, continue |
11966 (if (org-invisible-p) | 11931 (if (org-invisible-p) |
11967 (while (and (not (bobp)) (org-invisible-p)) | 11932 (while (and (not (bobp)) (org-invisible-p)) |
11968 (backward-char 1) | 11933 (backward-char 1) |
11969 (beginning-of-line 1)) | 11934 (beginning-of-line 1)) |
11970 (forward-char 1)))) | 11935 (forward-char 1)))) |
11936 | |
11971 (when org-noutline-p | 11937 (when org-noutline-p |
11972 (define-key org-mode-map "\C-a" 'org-beginning-of-line)) | 11938 (define-key org-mode-map "\C-a" 'org-beginning-of-line)) |
11939 ;; FIXME: should I use substitute-key-definition to reach other bindings | |
11940 ;; of beginning-of-line? | |
11973 | 11941 |
11974 (defun org-invisible-p () | 11942 (defun org-invisible-p () |
11975 "Check if point is at a character currently not visible." | 11943 "Check if point is at a character currently not visible." |
11976 (if org-noutline-p | 11944 (if org-noutline-p |
11977 ;; Early versions of noutline don't have `outline-invisible-p'. | 11945 ;; Early versions of noutline don't have `outline-invisible-p'. |
11985 (defun org-back-to-heading (&optional invisible-ok) | 11953 (defun org-back-to-heading (&optional invisible-ok) |
11986 "Move to previous heading line, or beg of this line if it's a heading. | 11954 "Move to previous heading line, or beg of this line if it's a heading. |
11987 Only visible heading lines are considered, unless INVISIBLE-OK is non-nil." | 11955 Only visible heading lines are considered, unless INVISIBLE-OK is non-nil." |
11988 (if org-noutline-p | 11956 (if org-noutline-p |
11989 (outline-back-to-heading invisible-ok) | 11957 (outline-back-to-heading invisible-ok) |
11990 (if (looking-at outline-regexp) | 11958 (if (and (memq (char-before) '(?\n ?\r)) |
11959 (looking-at outline-regexp)) | |
11991 t | 11960 t |
11992 (if (re-search-backward (concat (if invisible-ok "\\([\r\n]\\|^\\)" "^") | 11961 (if (re-search-backward (concat (if invisible-ok "\\([\r\n]\\|^\\)" "^") |
11993 outline-regexp) | 11962 outline-regexp) |
11994 nil t) | 11963 nil t) |
11995 (if invisible-ok | 11964 (if invisible-ok |
12066 (save-excursion (outline-end-of-heading) (point)) | 12035 (save-excursion (outline-end-of-heading) (point)) |
12067 (if org-noutline-p | 12036 (if org-noutline-p |
12068 flag | 12037 flag |
12069 (if flag ?\r ?\n)))))) | 12038 (if flag ?\r ?\n)))))) |
12070 | 12039 |
12040 (defun org-end-of-subtree (&optional invisible-OK) | |
12041 ;; This is an exact copy of the original function, but it uses | |
12042 ;; `org-back-to-heading', to make it work also in invisible | |
12043 ;; trees. And is uses an invisible-OK argument. | |
12044 ;; Under Emacs this is not needed, but the old outline.el needs this fix. | |
12045 (org-back-to-heading invisible-OK) | |
12046 (let ((opoint (point)) | |
12047 (first t) | |
12048 (level (funcall outline-level))) | |
12049 (while (and (not (eobp)) | |
12050 (or first (> (funcall outline-level) level))) | |
12051 (setq first nil) | |
12052 (outline-next-heading)) | |
12053 (if (memq (preceding-char) '(?\n ?\^M)) | |
12054 (progn | |
12055 ;; Go to end of line before heading | |
12056 (forward-char -1) | |
12057 (if (memq (preceding-char) '(?\n ?\^M)) | |
12058 ;; leave blank line before heading | |
12059 (forward-char -1)))))) | |
12060 | |
12071 (defun org-show-subtree () | 12061 (defun org-show-subtree () |
12072 "Show everything after this heading at deeper levels." | 12062 "Show everything after this heading at deeper levels." |
12073 (outline-flag-region | 12063 (outline-flag-region |
12074 (point) | 12064 (point) |
12075 (save-excursion | 12065 (save-excursion |
12123 | 12113 |
12124 (run-hooks 'org-load-hook) | 12114 (run-hooks 'org-load-hook) |
12125 | 12115 |
12126 ;; arch-tag: e77da1a7-acc7-4336-b19e-efa25af3f9fd | 12116 ;; arch-tag: e77da1a7-acc7-4336-b19e-efa25af3f9fd |
12127 ;;; org.el ends here | 12117 ;;; org.el ends here |
12118 |