view lisp/textmodes/reftex-toc.el @ 105973:b7d8222914b4

2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-clone-subtree-with-time-shift): Make it work at the end of the buffer. * org-mobile.el (org-mobile-write-checksums): Specify coding system. (org-mobile-timestamp-buffer): Keep local variable/mode line at beginning of buffer. * org-latex.el (org-latex-entities-regexp): Fix typo in regexp. * org.el (org-block-todo-from-children-or-siblings-or-parent) (org-block-todo-from-checkboxes): Do not block changes to a nil TODO state. 2009-11-13 James TD Smith <ahktenzero@mohorovi.cc> * org-habit.el (org-habit-parse-todo): Indicate which habit is wrongly set up in the error messages. * org-colview.el (org-columns-display-here): Don't try to calculate values if the underlying property is not set. (org-columns-string-to-number): Convert age strings back into fractional days. (org-agenda-colview-summarize): Handle extended summary types properly. * org-colview-xemacs.el (org-columns-display-here): Don't try to calculate values if the underlying property is not set. (org-columns-string-to-number): Convert age strings back into fractional days. (org-agenda-colview-summarize): Handle extended summary types properly. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-exp.el (org-export-format-drawer-function): New variable. (org-export-format-drawer): New function. (org-export-preprocess-string): Pass the backend as a parameter to `org-export-remove-or-extract-drawers'. (org-export-remove-or-extract-drawers): New parameter BACKEND. * org-protocol.el (org-protocol-char-to-string): New defsubst. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-diary-entry-in-org-file): Add error message when no block is selected. * org-latex.el (org-export-latex-links): Check for protectedness in the last matched character, not after the match. * org-datetree.el (org-datetree-find-date-create): Respect restriction when KEEP-RESTRICTION is set. (org-datetree-file-entry-under): New function. (org-datetree-cleanup): New command. 2009-11-13 Dan Davison <davison@stats.ox.ac.uk> * org-src.el (org-edit-src-code): New optional argument context allows calling functions to avoid altering the saved window configuration. (org-edit-src-exit): Do not restore window configuration when this function is used in the context of saving the edit buffer. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-clock.el (org-clock-out, org-clock-cancel): Revert to instances to switching to with-current-buffer, because these seem to cause problems - no idea why. * org-agenda.el (org-agenda-add-entry-to-org-agenda-diary-file): Require diary-lib for (diary-date-display-form). 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-log-reschedule, org-log-redeadline): New options. (org-log-note-headings): Add templates for rescheduling and deadline changing. (org-startup-options): Add in-buffer settings for logging changing schedule and deadline time stamps. (org-deadline, org-schedule): Check for existing date and arrange for logging if the user requests it. (org-add-log-note): Prepare proper note buffers for rescheduling and deadline changes. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-diary-entry-in-org-file) (org-agenda-add-entry-to-org-agenda-diary-file) (org-agenda-insert-diary-make-new-entry): New functions. (org-agenda-diary-entry): Call `org-agenda-diary-entry-in-org-file' when appropriate. * org.el (org-calendar-insert-diary-entry-key): New option. (org-agenda-diary-file): New option. ("calendar"): Install our insertion function in the calendar. * org-remember.el (org-datetree): Require. (org-remember-templates): Add new positioning option. (org-remember-reference-date): New variable. (org-remember-apply-template): Store the reference date in a local variable. (org-remember-handler): Implement date tree positioning of entries. * org-datetree.el: New file. * org-latex.el (org-export-latex-preprocess): Protect targets in verbatim emphasis. * org-html.el (org-export-as-html): Protect targets in verbatim emphasis. * org-docbook.el (org-export-as-docbook): Protect targets in verbatim emphasis. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-clock.el (org-show-notification): Handle messages that contain a percent character. * org-remember.el (org-remember-apply-template): Turn of partial completion. * org-mobile.el (org-mobile-before-process-capture-hook): New hook. (org-mobile-pull): Run `org-mobile-before-process-capture-hook'. * org.el (org-indent-mode): Define variable already in org.el. (org-unfontify-region): Remove line-prefix and wrap-prefix properties only if org-indent-mode is active. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-icalendar.el (org-print-icalendar-entries): Save match data around call to verify function. (org-print-icalendar-entries): Add a call to the verification function. * org.el (org-speedbar-set-agenda-restriction): Remove unnecessary save-restrivtion' form. 2009-11-13 Dan Davison <davison@stats.ox.ac.uk> * org-exp.el (org-export-format-source-code-or-example): restrict scope of preserve-indentp to the let binding. (org-src): require org-src, since org-src-preserve-indentation is used. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-timer.el (org-timer-set-timer): Set variables org-timer-timer[123] correctly. * org-mobile.el (org-mobile-files-alist): Make it work when `agenda-archives' is included in `org-agenda-text-search-extra-files'. (org-mobile-push): Restore agenda after mobile push. 2009-11-13 John Wiegley <jwiegley@gmail.com> * org-clock.el (org-resolve-clocks-if-idle): Another fix to the way the amount of idle time is presented in the minibuffer. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-icalendar.el (org-print-icalendar-entries): Use org-icalendar-verify-function only if non-nil. * org.el (org-refile): Refile to clock only if the prefix arg is 2. (org-sparse-tree): Fix docstring to be in line with prompt. (org-update-parent-todo-statistics): Call `org-after-todo-statistics-hook' on each level. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-remember.el (org-remember-apply-template): Make sure the buffer exists. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-tab-ind-state): New variable. (org-cycle-level): New function. (org-cycle-level-after-item/entry-creation): New option. (org-flag-subtree): New function. (org-hide-archived-subtrees): Call `org-flag-subtree'. (org-set-effort): Indexed access. * org-list.el (org-cycle-item-indentation): New function. * org.el (org-refile): Make prefix argument 2 refile to current clock. (org-priority): Interpret action `remove' as call to remove the priority cookie. * org-remember.el (org-remember-apply-template): Don't depend on buffer name being like file name. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-clock.el (org-clock-play-sound): Expand file in org-clock-sound, to allow ~ for home. * org-remember.el (org-remember-handler): Set text-before-node-creation even if this already looks like a node, because the string might be needed on non-org-mode target files. * org-agenda.el (org-agenda-open-link): Make this work in agenda clocktables. (org-agenda-switch-to): Follow a link at point if org-return-follows-link' is set and there is nothing else to do in this line. 2009-11-13 James TD Smith <ahktenzero@mohorovi.cc> * org-colview-xemacs.el: Add in changes from org-colview.el 2009-11-13 Dan Davison <davison@stats.ox.ac.uk> * org-exp-blocks.el: Modify split separator regexp to avoid empty strings. 2009-11-13 James TD Smith <ahktenzero@mohorovi.cc> * org-colview.el (org-columns-new): Make this work with the new operators. (org-columns-store-format): Make this work with the new operators. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-src.el (org-src-preserve-indentation): Document that this variable is also used during export. * org-exp.el (org-export-format-source-code-or-example): Preserve indentation if a block has a -i option, or if `org-src-preserve-indentation' is set. * org-exp-blocks.el (org-export-blocks-preprocess): Preserve indentation if a block has a -i option, or if `org-src-preserve-indentation' is set. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-mode-map): Define the new archiving keys. (org-speed-commands-default): Define an archiving key in the speed command map. (org-org-menu): Improve the menu structure concerning archiving. * org-archive.el (org-archive-subtree-default-with-confirmation): New command. * org-agenda.el (org-agenda-mode-map): Define the new archiving keys. (org-agenda-menu): Add the new archiving commands to the menu. (org-agenda-archive-default) (org-agenda-archive-default-with-confirmation): New commands. (org-agenda-archive, org-agenda-archive-to-archive-sibling): Just call `org-agenda-archive-with'. (org-agenda-archive-with): New function. * org-table.el (org-table-convert-region): Inert spaces around "|" to avoid line beginnings like "|-1" which will be mistaken as hlines. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-offer-links-in-entry): Return nil if there are no links, t if a link has been selected. (org-open-at-point): Open attachment directory when called in the headline and there are no links in the entry body. (org-speed-commands-default): Add "o" for open-at-point as a speed command. * org-attach.el (org-attach-reveal): Optional prefix arg IF-EXISTS, which avoids creating the attachment directory if it does not yet exist. * org-agenda.el (org-agenda, org-run-agenda-series): Evaluate MATCH. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org.el ("abbrev"): Work with abbrev tables only after they have been loaded. * org-list.el (org-list-send-list): Fix bug related to match data. * org-latex.el (org-export-latex-fontify): Apply verbatim emphasis. (org-export-latex-make-header): Insert \obeylines if line breaks should be preserved. * org-exp.el (org-export-protect-verbatim): Add an `org-verbatim-emph' property to such text. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-icalendar.el (org-icalendar-use-plain-timestamp): New option. (org-print-icalendar-entries): Skip entries where the timestamp is not a deadline and not scheduled, if the user requests that. * org-latex.el (org-export-latex-quotation-marks): Allow a bracket before an opening quote. * org-archive.el (org-archive-subtree): Keep archive after archiving something. * org-id.el (org-id-update-id-locations): Add archive files if that is required by `org-id-extra-files'. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-src.el (org-src-window-setup): New option. (org-src-switch-to-buffer): New function. (org-edit-src-exit): Add optional argument CONTEXT and use it to restore window configuration. (org-edit-src-code, org-edit-src-continue, org-edit-src-exit): Call `org-src-switch-to-buffer'. * org.el (org-default-properties): Add STYLE property. (org-files-list): Use the function call to get the files. (org-additional-option-like-keywords): Add SETUPFILE to completion list. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-table.el (org-table-convert-region): Correctly interpret quoting in csv import. * org.el (org-icompleting-read): Make iswitchb completion work with lists and tables. * org-agenda.el (org-agenda-add-entry-text): Never add entry text while pushing the mobile agenda. 2009-11-13 John Wiegley <jwiegley@gmail.com> * org-clock.el (org-clock-auto-clock-resolution): Now takes three values: nil, t and `when-no-clock-is-running'. (org-clock-in): Use `org-clock-auto-clock-resolution' to determine whether or not to resolve Org buffers on clock in. 2009-11-13 James TD Smith <ahktenzero@mohorovi.cc> * org-colview.el (org-format-time-period): Function to format times in fractional days for display. (org-columns-display-here): Add support for showing a calculated value in place of the property. (org-columns): Set `org-columns-time' to the current time so time difference calculations will work. (org-columns-time): Use to store the current time when column view is displayed, so all time differences will use the same reference point. (org-columns-compile-map): There is now an extra position in each entry specifying the function to use to calculate the displayed value for the non-calculated properties in the column, (org-columns-compute-all): Set `org-columns-time' to the current time so time difference calculations will work. (org-columns-compute): Handle column operators where the values used are calculated from the underlying property. (org-columns-number-to-string): Handle the 'age' column format (org-columns-string-to-number): Correct the function name (was org-column...). Add support for the 'age' column format. (org-columns-compile-format): Support the additional parameter in org-columns-compile-map. 2009-11-13 Bastien Guerry <bzg@altern.org> * org.el (org-mode-hook): Turn `org-mode-hook' into a customizable variable. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-clock.el (org-clock-has-been-used): New variable. (org-clock-in): Set `org-clock-has-been-used'. (org-clock-save): Save only if clock data has been used or created during this session. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-clock.el (org-clock-persist): New value, to store only the clock history. (org-clock-save): Don't save the clock if only the history should be stored. (org-clock-load): Turn off John Wiegley's auto resolving mechanism when restoring a saved clock. 2009-11-13 John Wiegley <jwiegley@gmail.com> * org-clock.el (org-clock-display, org-clock-put-overlay): Use `org-time-clock-use-fractional'. * org.el (org-time-clocksum-use-fractional) (org-time-clocksum-fractional-format): Two new customizable variables which allow the user to select fractional times (1.25 instead of 1:25) in the `org-clock-display' report. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-ascii.el (org-export-ascii-table-keep-all-vertical-lines): New option. * org.el (org-tag-alist): Fix customization type. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-mobile.el (org-mobile-update-checksum-for-capture-file): Make sure the regexp search can fail without throwing an error. (org-mobile-apply): Save the inbox buffer after removing successfully applied changes. 2009-11-13 John Wiegley <jwiegley@gmail.com> * org-clock.el (org-resolve-clocks-if-idle): Fix to the way idle time is reported after the user comes back (but before they resolve time). * org.el (org-get-repeat): Change so that this function can be called with either `org-scheduled-string' or `org-deadline-string'. * org-clock.el (org-clock-auto-clock-resolution): Renamed `org-clock-disable-clock-resolution', since negatives don't sound good in customization variables. (org-clock-in): Don't use the auto-resolution logic if the user is clocking into a different task while an active clock is running. This then allows the default behavior of clocking out of the open task and then into the new task. * org.el (org-modules): Made this variable more consistent, since it was referring to Org, OrgMode and Org-mode, whereas the docs for the variable always refer to Org-mode. 2009-11-13 James TD Smith <ahktenzero@mohorovi.cc> * org.el (org-repeat-re): The changed org-repeat-re no longer matched simple +2d type repeaters. Fix it so it does. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-latex.el (org-export-latex-preprocess): Protect the vspace macro in the VERSE environment. 2009-11-13 John Wiegley <jwiegley@gmail.com> * org-habit.el (org-habit-get-priority): A new function that determines the relative priority of a habit, based on how long past its scheduled date it is, and how near the deadline is. * org-agenda.el (org-agenda-get-scheduled): Set habit priority using `org-habit-get-priority'. * org-habit.el (org-habit-build-graph): Start displaying colors from the first scheduled date, if that date is earlier than the first completion date. * org-habit.el: Changed all "color" variables to faces, and made them appropriate for light and dark backgrounds. * org-habit.el (org-habit-duration-to-days): Made this function more general. (org-habit-parse-todo): Parse the new ".+N/N" style repeater. * org-agenda.el (org-agenda-get-deadlines): Removed all mention of habits, since they don't use DEADLINE anymore. * org.el (org-repeat-re, org-display-custom-time) (org-timestamp-change): Extended to support the new ".+N/N" syntax, used for habits. * org-clock.el (org-clock-resolve-clock): Fixed an incorrect variable reference. * org-agenda.el (org-agenda-set-mode-name): Show Habit in the modeline when habits are being displayed (if that module is being loaded). 2009-11-13 James TD Smith <ahktenzero@mohorovi.cc> * org-clock.el (org-x11-idle-seconds): Add a method to get the X11 idle time using the xscreensaver extension. (org-user-idle-seconds): Use X11 idle time if available. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-next-line): New command. (org-agenda-previous-line): New commands. (org-agenda-show-and-scroll-up, org-agenda-show-scroll-down): New commands. (org-agenda-follow-mode): Do the follow immediately if the mode is turned on here. (previous-line, next-line): Replace keys with the corresponding org functions. (org-agenda-mode-map): Bind backspace and delete to the scrolling command. * org.el (org-icompleting-read): Turn off partial completion mode for the duration of this completion round. * org-latex.el (org-export-latex-fontify-headline): Protect TeX macros in author lines and similar stuff. * org.el (org-file-tags): Fix docstring. (org-get-buffer-tags): Add the #+FILETAGS tags. ("ecb"): Maks ecb show context after jumping into an Org file. 2009-11-13 John Wiegley <johnw@newartisans.com> * org-agenda.el (org-finalize-agenda): Draw habit consistency graphs after everything else in the buffer has been setup. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-mobile.el (org-mobile-apply): Count success and failure. * org.el (org-indent-line-function): Fix regexp replace problem. 2009-11-13 John Wiegley <johnw@newartisans.com> * org-clock.el (org-clock-disable-clock-resolution): New customization variable that disable automatic clock resolution on clock in. (org-clock-in): If `org-clock-disable-clock-resolution' is set, do not automatically resolve anything. This is does not affect idle-time resolution, however, if `org-clock-idle-time' is set. 2009-11-13 John Wiegley <johnw@newartisans.com> * org-habit.el: New file, which implements code to build a "habit consistency graph". * org-agenda.el (org-agenda-get-deadlines) (org-agenda-get-scheduled): Display consistency graphs when outputting habits into the agenda. The graphs are always relative to the current time. (org-format-agenda-item): Added new parameter `habitp', which indicates whether we are formatting a habit or not. Do not display "extra" leading information if habitp is true. * org.el (org-repeat-re): Improved regexp to include .+ and ++ leaders for repeat strings. (org-get-repeat): Now takes a string parameter `tagline', so the caller can obtain the SCHEDULED repeat, or the DEADLINE repeat. 2009-11-13 John Wiegley <johnw@newartisans.com> * org-agenda.el (org-agenda-auto-exclude-function): New customization variable for allowing the user to create an "auto exclusion" filter for doing context-aware auto tag filtering. (org-agenda-filter-by-tag): Changes to support the use of `org-agenda-auto-exclude-function'. See the new manual addition,. 2009-11-13 John Wiegley <johnw@newartisans.com> * org.el (org-files-list): Don't attempt to return a file name for Org buffers which have no associated file. * org-agenda.el (org-agenda-do-action): Fixed a typo. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-mobile.el (org-mobile-locate-entry): Interpret files relative to org-directory. (org-mobile-inbox-for-pull): Document the best location for this file. (org-mobile-check-setup): Verify `org-directory'. (org-mobile-create-index-file): Sort the files to be listed in index.org. 2009-11-13 James TD Smith <ahktenzero@mohorovi.cc> * org.el (org-fast-tag-selection): Add a way to display a description for a tag group. This is done by adding a string to either the startgroup or endgroup cell. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-clock.el (org-clock-resolve, org-resolve-clocks) (org-emacs-idle-seconds): Use `org-float-time' instead of `time-to-seconds' 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-sorting-strategy): Fix customization type. * org.el (org-pre-cycle-hook): Document that `empty' can also be the value of ARG when doing local cycling. 2009-11-13 John Wiegley <johnw@newartisans.com> * org-clock.el (org-clock-resolve-clock): If keeping or subtracting time results in a clock out at a time in the past, and if the resolution occurred due to idleness or invoking `M-x org-resolve-clocks', remember that past moment in time. On the next clock in, the user will be prompted to see if they want to back-date their new clock to then. (org-clock-resolve): Do not jump the user to the location of a dangling clock if the resolution is occuring due to an idle timeout. In that case there is typically only one dangling clock, the active one, and there is no value gained by shuffling their windows around to show it to them. Being prompted to resolve an idle clock should be as inobtrusive as possible. (org-resolve-clocks-if-idle): New function that resolves only the currently active clock if the user has exceeded the time returned by `org-user-idle-seconds', based on the value of `org-clock-idle-time'. (org-clock-in): If, after resolving clocks, (org-clock-out): Cancel the `org-clock-idle-timer' on clock out. * org-clock.el (org-clock-resolve-clock): New function that resolves a clock to a specific time, closing or resuming as need be, and possibly even starting a new clock. (org-clock-resolve): New function used by `org-resolve-clocks' that sets up for the call to `org-clock-resolve-clock'. It determines the time to resolve to based on a single-character selection from the user to either keep time, subtract away time or cancel the clock. (org-resolve-clocks): New user command which resolves dangling clocks -- that is, open but not active -- anywhere in the file list returned by `org-files-list'. (org-clock-in): Automatically resolve dangling clocks whenever a user clocks in. (org-clock-cancel): If the user cancels the solely clock in a LOGBOOK, remove the empty drawer. * org-clock.el (org-clock-idle-time): New user customizable option for detecting whether the user has left a clock idle. Note: it is only used in this commit to test whether it's worthwhile to check OS X to get the Mac user's current idle time. If the Emacs idle time is less than the value, the user hasn't been away long enough to be worth checking (a more expensive test than just getting Emacs idle time). (org-user-idle-seconds, org-mac-idle-seconds) (org-emacs-idle-seconds): This three functions, in conjunction with the user customization variable `org-clock-idle-time', return the number of seconds (as a floating point) that the user has been away from their Emacs (or, if running on OS X, their computer). * org-clock.el (org-find-open-clocks): New function that returns a list of all open clocks in the given FILE. Note that each clock it returns is a cons cell of the format (MARKER . START-TIME). This "clock" value is used by several of the new clock module utility functions. (org-is-active-clock): New inline function which tests whether the given clock value is the same as the currently active clock. Returns non-nil if this is the case. (org-with-clock-position): New macro that evaluates FORMS with point in the buffer and at the position of the given clock. Changes to the current clock are global. (org-with-clock): New macro that evaluates FORMS with point in the buffer and at the position of the given clock. However, changes to the current clock are local and have no effect on the user's active clock. This allows, for example, far any clock to be cancelled without cancelling the active clock. (org-clock-clock-in): New inline function that switches the active clock to the given clock. If either the argument RESUME, or the global `org-clock-in-resume', are non-nil, it will resume a clock that was previously left open. (org-clock-clock-out): New inline function that clocks out the given clock value without affecting the currently active clock. (org-clock-clock-cancel): New inline function that cancels the given clock value without affecting the currently active clock. * org-clock.el (org-clock-in): Before creating `org-clock-mode-line-timer', check to make sure an older timer is not currently running. (org-clock-out): Accept new third parameter `at-time', which permits a clock to be clocked out at a specific time. Note that no attempt is made to verify that the clock out time is later than the clock in time. * org.el (org-files-list): New utility function for returning a list of all open org-mode buffers, plus all files used to build the agenda buffer. Note that not all the files will necessarily be visited by a buffer at time of call. (org-entry-beginning-position): Like the function `line-beginning-position', this inline function returns the beginning position of the current heading/entry. (org-entry-end-position): Like the function `line-end-position', this inline function returns the end position of the current heading/entry. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-list): Mark the all-todo items line as a header line. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-exp.el (org-inlinetask-remove-END-maybe): Declare function. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-filter-make-matcher): Allow to filter entries that have no tags. (org-agenda-search-view): New customize group. (org-agenda-search-view-search-words-only): New option. (org-search-view): Implement substring search. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-outline-level): Add doc string. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-inlinetask.el (org-inlinetask-export): Re-introduce variable. (org-inlinetask-export-handler): Only export inline task if the user option calls for it. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-exp.el (org-export-handle-export-tags): Remove inlinetask END if present. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-latex.el (org-export-latex-tables): Don't format in protected regions. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-src.el (org-edit-src-code) (org-edit-src-find-region-and-lang, org-edit-src-exit): Handle macro editing. * org-agenda.el (org-prefix-category-max-length): New variable. (org-format-agenda-item): Use `org-prefix-category-max-length'. (org-compile-prefix-format): Set `org-prefix-category-max-length'. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-mobile.el (org-mobile-create-index-file): Improve the listing of tags and todo keywords. * org-latex.el (org-export-latex-format-image): New function. (org-export-latex-links): Use `org-export-latex-format-image'. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org-inlinetask.el (org-inlinetask-get-current-indentation) (org-inlinetask-remove-terminator): New functions. (org-inlinetask-export-handler): Terminate the description list. * org-exp.el (org-export-select-backend-specific-text): Remove the region markers. * org-inlinetask.el (org-inlinetask-export-handler): fix bug for tasks without content. * org-clock.el: Make sure the clock-in target position does not move to a different node by widening the buffer. * org-html.el (org-export-html-format-image): Wrap image into figure div only when there is a caption. * org-archive.el (org-archive-mark-done): Change default value to nil. 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-context): Call `bobp', not `eobp'. * org-clock.el (org-clock-cancel): Remove quotes from marker variables. * org.el (org-read-date-prefer-future): New allowed value `time'. (org-read-date-analyze): Shift day to tomorrow depending on time entered and value of `org-read-date-prefer-future'.
author Carsten Dominik <dominik@science.uva.nl>
date Fri, 13 Nov 2009 08:37:55 +0000
parents df4934f25eef
children 1d1d5d9bd884
line wrap: on
line source

;;; reftex-toc.el --- RefTeX's table of contents mode

;; Copyright (C) 1997, 1998, 1999, 2000, 2003, 2004, 2005, 2006, 2007,
;;   2008, 2009  Free Software Foundation, Inc.

;; Author: Carsten Dominik <dominik@science.uva.nl>
;; Maintainer: auctex-devel@gnu.org
;; Version: 4.31

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;;; Code:

(eval-when-compile (require 'cl))
(provide 'reftex-toc)
(require 'reftex)
;;;

(defvar reftex-toc-map (make-sparse-keymap)
  "Keymap used for *toc* buffer.")

(defvar reftex-toc-menu)
(defvar reftex-last-window-height nil)
(defvar reftex-last-window-width nil)
(defvar reftex-toc-include-labels-indicator nil)
(defvar reftex-toc-include-index-indicator nil)
(defvar reftex-toc-max-level-indicator nil)

(defun reftex-toc-mode ()
  "Major mode for managing Table of Contents for LaTeX files.
This buffer was created with RefTeX.
Press `?' for a summary of important key bindings.

Here are all local bindings.

\\{reftex-toc-map}"
  (interactive)
  (kill-all-local-variables)
  (setq major-mode 'reftex-toc-mode
        mode-name "TOC")
  (use-local-map reftex-toc-map)
  (set (make-local-variable 'transient-mark-mode) t)
  (when (featurep 'xemacs)
    (set (make-local-variable 'zmacs-regions) t))
  (set (make-local-variable 'revert-buffer-function) 'reftex-toc-revert)
  (set (make-local-variable 'reftex-toc-include-labels-indicator) "")
  (set (make-local-variable 'reftex-toc-max-level-indicator)
       (if (= reftex-toc-max-level 100)
           "ALL"
         (int-to-string reftex-toc-max-level)))
  (setq mode-line-format
        (list "----  " 'mode-line-buffer-identification
              "  " 'global-mode-string "   (" mode-name ")"
              "  L<" 'reftex-toc-include-labels-indicator ">"
              "  I<" 'reftex-toc-include-index-indicator ">"
              "  T<" 'reftex-toc-max-level-indicator ">"
              " -%-"))
  (setq truncate-lines t)
  (when (featurep 'xemacs)
    ;; XEmacs needs the call to make-local-hook
    (make-local-hook 'post-command-hook)
    (make-local-hook 'pre-command-hook))
  (make-local-variable 'reftex-last-follow-point)
  (add-hook 'post-command-hook 'reftex-toc-post-command-hook nil t)
  (add-hook 'pre-command-hook  'reftex-toc-pre-command-hook nil t)
  (easy-menu-add reftex-toc-menu reftex-toc-map)
  (run-hooks 'reftex-toc-mode-hook))

(defvar reftex-last-toc-file nil
  "Stores the file name from which `reftex-toc' was called.  For redo command.")


(defvar reftex-toc-return-marker (make-marker)
  "Marker which makes it possible to return from toc to old position.")

(defconst reftex-toc-help
"                      AVAILABLE KEYS IN TOC BUFFER
                      ============================
n / p      next-line / previous-line
SPC        Show the corresponding location of the LaTeX document.
TAB        Goto the location and keep the *toc* window.
RET        Goto the location and hide the *toc* window (also on mouse-2).
< / >      Promote / Demote section, or all sections in region.
C-c >      Display Index. With prefix arg, restrict index to current section.
q / k      Hide/Kill *toc* buffer, return to position of reftex-toc command.
l i c F    Toggle display of  [l]abels,  [i]ndex,  [c]ontext,  [F]ile borders.
t          Change maximum toc depth (e.g. `3 t' hides levels greater than 3).
f / g      Toggle follow mode / Refresh *toc* buffer.
a / d      Toggle auto recenter / Toggle dedicated frame
r / C-u r  Reparse the LaTeX document     / Reparse entire LaTeX document.
.          In other window, show position from where `reftex-toc' was called.
M-%        Global search and replace to rename label at point.
x          Switch to TOC of external document (with LaTeX package `xr').
z          Jump to a specific section (e.g. '3 z' goes to section 3).")

(defun reftex-toc (&optional rebuild reuse)
  "Show the table of contents for the current document.
When called with a raw C-u prefix, rescan the document first."

;; The REUSE argument means, search all visible frames for a window
;; displaying the toc window.  If yes, reuse this window.

  (interactive)

  (if (or (not (string= reftex-last-toc-master (reftex-TeX-master-file)))
          current-prefix-arg)
      (reftex-erase-buffer "*toc*"))

  (setq reftex-last-toc-file   (buffer-file-name))
  (setq reftex-last-toc-master (reftex-TeX-master-file))

  (set-marker reftex-toc-return-marker (point))

  ;; If follow mode is active, arrange to delay it one command
  (if reftex-toc-follow-mode
      (setq reftex-toc-follow-mode 1))

  (and reftex-toc-include-index-entries
       (reftex-ensure-index-support))
  (or reftex-support-index
      (setq reftex-toc-include-index-entries nil))

  ;; Ensure access to scanning info and rescan buffer if prefix are is '(4)
  (reftex-access-scan-info current-prefix-arg)

  (let* ((this-buf (current-buffer))
         (docstruct-symbol reftex-docstruct-symbol)
         (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol)))
         (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data)))
         (here-I-am (if (boundp 'reftex-rebuilding-toc)
                        (get 'reftex-toc :reftex-data)
                      (car (reftex-where-am-I))))
         (unsplittable (if (fboundp 'frame-property)
                           (frame-property (selected-frame) 'unsplittable)
                         (frame-parameter (selected-frame) 'unsplittable)))
         offset toc-window)

    (if (setq toc-window (get-buffer-window
                          "*toc*"
                          (if reuse 'visible)))
        (select-window toc-window)
      (when (or (not reftex-toc-keep-other-windows)
                (< (window-height) (* 2 window-min-height)))
        (delete-other-windows))

      (setq reftex-last-window-width (window-width)
            reftex-last-window-height (window-height))  ; remember

      (unless unsplittable
        (if reftex-toc-split-windows-horizontally
            (split-window-horizontally
             (floor (* (window-width)
                       reftex-toc-split-windows-fraction)))
          (split-window-vertically
           (floor (* (window-height)
                     reftex-toc-split-windows-fraction)))))

      (switch-to-buffer "*toc*"))

    (or (eq major-mode 'reftex-toc-mode) (reftex-toc-mode))
    (set (make-local-variable 'reftex-docstruct-symbol) docstruct-symbol)
    (setq reftex-toc-include-labels-indicator
          (if (eq reftex-toc-include-labels t)
              "ALL"
            reftex-toc-include-labels))
    (setq reftex-toc-include-index-indicator
          (if (eq reftex-toc-include-index-entries t)
              "ALL"
            reftex-toc-include-index-entries))

    (cond
     ((= (buffer-size) 0)
      ;; buffer is empty - fill it with the table of contents
      (message "Building *toc* buffer...")

      (setq buffer-read-only nil)
      (insert (format
"TABLE-OF-CONTENTS on %s
SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [l]abels [f]ollow [x]r [?]Help
------------------------------------------------------------------------------
" (abbreviate-file-name reftex-last-toc-master)))

      (if (reftex-use-fonts)
          (put-text-property (point-min) (point) 'face reftex-toc-header-face))
      (put-text-property (point-min) (point) 'intangible t)
      (put-text-property (point-min) (1+ (point-min)) 'xr-alist xr-alist)

      (setq offset
            (reftex-insert-docstruct
             this-buf
             t ; include toc
             reftex-toc-include-labels
             reftex-toc-include-index-entries
             reftex-toc-include-file-boundaries
             reftex-toc-include-context
             nil ; counter
             nil ; commented
             here-I-am
             ""     ; xr-prefix
             t      ; a toc buffer
             ))

      (run-hooks 'reftex-display-copied-context-hook)
      (message "Building *toc* buffer...done.")
      (setq buffer-read-only t))
     (t
      ;; Only compute the offset
      (setq offset
            (or (reftex-get-offset this-buf here-I-am
                                   (if reftex-toc-include-labels " " nil)
                                   t
                                   reftex-toc-include-index-entries
                                   reftex-toc-include-file-boundaries)
                (reftex-last-assoc-before-elt
                 'toc here-I-am
                 (symbol-value reftex-docstruct-symbol))))
      (put 'reftex-toc :reftex-line 3)
      (goto-char (point-min))
      (forward-line 2)))

    ;; Find the correct starting point
    (reftex-find-start-point (point) offset (get 'reftex-toc :reftex-line))
    (setq reftex-last-follow-point (point))))

(defun reftex-toc-recenter (&optional arg)
  "Display the TOC window and highlight line corresponding to current position."
  (interactive "P")
  (let ((buf (current-buffer))
        (frame (selected-frame)))
    (reftex-toc arg t)
    (if (= (count-lines 1 (point)) 2)
        (let ((current-prefix-arg nil))
          (select-window (get-buffer-window buf frame))
          (reftex-toc nil t)))
    (and (> (point) 1)
         (not (get-text-property (point) 'intangible))
         (memq reftex-highlight-selection '(cursor both))
         (reftex-highlight 2
                           (or (previous-single-property-change
                                (min (point-max) (1+ (point))) :data)
                               (point-min))
                           (or (next-single-property-change (point) :data)
                               (point-max))))
    (select-window (get-buffer-window buf frame))))

(defun reftex-toc-pre-command-hook ()
  ;; used as pre command hook in *toc* buffer
  (reftex-unhighlight 0)
  )

(defun reftex-toc-post-command-hook ()
  ;; used in the post-command-hook for the *toc* buffer
  (when (get-text-property (point) :data)
    (put 'reftex-toc :reftex-data (get-text-property (point) :data))
    (and (> (point) 1)
         (not (get-text-property (point) 'intangible))
         (memq reftex-highlight-selection '(cursor both))
         (reftex-highlight 2
           (or (previous-single-property-change (1+ (point)) :data)
               (point-min))
           (or (next-single-property-change (point) :data)
               (point-max)))))
  (if (integerp reftex-toc-follow-mode)
      ;; remove delayed action
      (setq reftex-toc-follow-mode t)
    (and (not (reftex-toc-dframe-p))
         reftex-toc-follow-mode
         (not (equal reftex-last-follow-point (point)))
         ;; show context in other window
         (setq reftex-last-follow-point (point))
         (condition-case nil
             (reftex-toc-visit-location nil (not reftex-revisit-to-follow))
           (error t)))))

(defun reftex-re-enlarge ()
  ;; Enlarge window to a remembered size.
  (if reftex-toc-split-windows-horizontally
      (enlarge-window-horizontally
       (max 0 (- (or reftex-last-window-width (window-width))
                 (window-width))))
    (enlarge-window
     (max 0 (- (or reftex-last-window-height (window-height))
               (window-height))))))

(defun reftex-toc-dframe-p (&optional frame error)
  ;; Check if FRAME is the dedicated TOC frame.
  ;; If yes, and ERROR is non-nil, throw an error.
  (setq frame (or frame (selected-frame)))
  (let ((res (equal
              (if (fboundp 'frame-property)
                  (frame-property frame 'name)
                (frame-parameter  frame 'name))
              "RefTeX TOC Frame")))
    (if (and res error)
        (error "This frame is view-only.  Use `C-c =' to create toc window for commands"))
    res))

(defun reftex-toc-show-help ()
  "Show a summary of special key bindings."
  (interactive)
  (reftex-toc-dframe-p nil 'error)
  (with-output-to-temp-buffer "*RefTeX Help*"
    (princ reftex-toc-help))
  (reftex-enlarge-to-fit "*RefTeX Help*" t)
  ;; If follow mode is active, arrange to delay it one command
  (if reftex-toc-follow-mode
      (setq reftex-toc-follow-mode 1)))

(defun reftex-toc-next (&optional arg)
  "Move to next selectable item."
  (interactive "p")
  (when (featurep 'xemacs) (setq zmacs-region-stays t))
  (setq reftex-callback-fwd t)
  (or (eobp) (forward-char 1))
  (goto-char (or (next-single-property-change (point) :data)
                 (point))))
(defun reftex-toc-previous (&optional arg)
  "Move to previous selectable item."
  (interactive "p")
  (when (featurep 'xemacs) (setq zmacs-region-stays t))
  (setq reftex-callback-fwd nil)
  (goto-char (or (previous-single-property-change (point) :data)
                 (point))))
(defun reftex-toc-next-heading (&optional arg)
  "Move to next table of contentes line."
  (interactive "p")
  (when (featurep 'xemacs) (setq zmacs-region-stays t))
  (end-of-line)
  (re-search-forward "^ " nil t arg)
  (beginning-of-line))
(defun reftex-toc-previous-heading (&optional arg)
  "Move to previous table of contentes line."
  (interactive "p")
  (when (featurep 'xemacs) (setq zmacs-region-stays t))
  (re-search-backward "^ " nil t arg))
(defun reftex-toc-toggle-follow ()
  "Toggle follow (other window follows with context)."
  (interactive)
  (setq reftex-last-follow-point -1)
  (setq reftex-toc-follow-mode (not reftex-toc-follow-mode)))
(defun reftex-toc-toggle-file-boundary ()
  "Toggle inclusion of file boundaries in *toc* buffer."
  (interactive)
  (setq reftex-toc-include-file-boundaries
        (not reftex-toc-include-file-boundaries))
  (reftex-toc-revert))
(defun reftex-toc-toggle-labels (arg)
  "Toggle inclusion of labels in *toc* buffer.
With prefix ARG, prompt for a label type and include only labels of
that specific type."
  (interactive "P")
  (setq reftex-toc-include-labels
        (if arg (reftex-query-label-type)
          (not reftex-toc-include-labels)))
  (reftex-toc-revert))
(defun reftex-toc-toggle-index (arg)
  "Toggle inclusion of index in *toc* buffer.
With prefix arg, prompt for an index tag and include only entries of that
specific index."
  (interactive "P")
  (setq reftex-toc-include-index-entries
        (if arg (reftex-index-select-tag)
          (not reftex-toc-include-index-entries)))
  (reftex-toc-revert))
(defun reftex-toc-toggle-context ()
  "Toggle inclusion of label context in *toc* buffer.
Label context is only displayed when the labels are there as well."
  (interactive)
  (setq reftex-toc-include-context (not reftex-toc-include-context))
  (reftex-toc-revert))
(defun reftex-toc-max-level (arg)
  "Set the maximum level of toc lines in this buffer to value of prefix ARG.
When no prefix is given, set the max level to a large number, so that all
levels are shown.  For eaxample, to set the level to 3, type `3 m'."
  (interactive "P")
  (setq reftex-toc-max-level (if arg
                                 (prefix-numeric-value arg)
                               100))
  (setq reftex-toc-max-level-indicator
        (if arg (int-to-string reftex-toc-max-level) "ALL"))
  (reftex-toc-revert))
(defun reftex-toc-view-line ()
  "View document location in other window."
  (interactive)
  (reftex-toc-dframe-p nil 'error)
  (reftex-toc-visit-location))
(defun reftex-toc-goto-line-and-hide ()
  "Go to document location in other window.  Hide the *toc* window."
  (interactive)
  (reftex-toc-dframe-p nil 'error)
  (reftex-toc-visit-location 'hide))
(defun reftex-toc-goto-line ()
  "Go to document location in other window. *toc* window stays."
  (interactive)
  (reftex-toc-dframe-p nil 'error)
  (reftex-toc-visit-location t))
(defun reftex-toc-mouse-goto-line-and-hide (ev)
  "Go to document location in other window.  Hide the *toc* window."
  (interactive "e")
  (mouse-set-point ev)
  (reftex-toc-dframe-p nil 'error)
  (reftex-toc-visit-location 'hide))
(defun reftex-toc-show-calling-point ()
  "Show point where reftex-toc was called from."
  (interactive)
  (reftex-toc-dframe-p nil 'error)
  (let ((this-window (selected-window)))
    (unwind-protect
        (progn
          (switch-to-buffer-other-window
           (marker-buffer reftex-toc-return-marker))
          (goto-char (marker-position reftex-toc-return-marker))
          (recenter '(4)))
      (select-window this-window))))
(defun reftex-toc-quit ()
  "Hide the *toc* window and do not move point.
If the toc window is the only window on the dedicated TOC frame, the frame
is destroyed."
  (interactive)
  (if (and (one-window-p)
           (reftex-toc-dframe-p)
           (> (length (frame-list)) 1))
      (delete-frame)
    (or (one-window-p) (delete-window))
    (switch-to-buffer (marker-buffer reftex-toc-return-marker))
    (reftex-re-enlarge)
    (goto-char (or (marker-position reftex-toc-return-marker) (point)))))
(defun reftex-toc-quit-and-kill ()
  "Kill the *toc* buffer."
  (interactive)
  (kill-buffer "*toc*")
  (or (one-window-p) (delete-window))
  (switch-to-buffer (marker-buffer reftex-toc-return-marker))
  (reftex-re-enlarge)
  (goto-char (marker-position reftex-toc-return-marker)))
(defun reftex-toc-display-index (&optional arg)
  "Display the index buffer for the current document.
This works just like `reftex-display-index' from a LaTeX buffer.
With prefix arg 1, restrict index to the section at point."
  (interactive "P")
  (reftex-toc-dframe-p nil 'error)
  (let ((data (get-text-property (point) :data))
        (docstruct (symbol-value reftex-docstruct-symbol))
        bor eor restr)
    (when (equal arg 2)
      (setq bor (reftex-last-assoc-before-elt 'toc data docstruct)
            eor (assoc 'toc (cdr (memq bor docstruct)))
            restr (list (nth 6 bor) bor eor)))
    (reftex-toc-goto-line)
    (reftex-display-index (if restr nil arg) restr)))

;; Rescanning the document and rebuilding the TOC buffer.
(defun reftex-toc-rescan (&rest ignore)
  "Regenerate the *toc* buffer by reparsing file of section at point."
  (interactive)
  (if (and reftex-enable-partial-scans
           (null current-prefix-arg))
      (let* ((data (get-text-property (point) :data))
             (what (car data))
             (file (cond ((eq what 'toc) (nth 3 data))
                         ((memq what '(eof bof file-error)) (nth 1 data))
                         ((stringp what) (nth 3 data))
                         ((eq what 'index) (nth 3 data))))
             (line (+ (count-lines (point-min) (point)) (if (bolp) 1 0))))
        (if (not file)
            (error "Don't know which file to rescan.  Try `C-u r'")
          (put 'reftex-toc :reftex-line line)
          (switch-to-buffer-other-window
           (reftex-get-file-buffer-force file))
          (setq current-prefix-arg '(4))
          (let ((reftex-rebuilding-toc t))
            (reftex-toc))))
    (reftex-toc-Rescan))
  (reftex-kill-temporary-buffers))

(defun reftex-toc-Rescan (&rest ignore)
  "Regenerate the *toc* buffer by reparsing the entire document."
  (interactive)
  (let* ((line (+ (count-lines (point-min) (point)) (if (bolp) 1 0))))
    (put 'reftex-toc :reftex-line line))
  (switch-to-buffer-other-window
   (reftex-get-file-buffer-force reftex-last-toc-file))
  (setq current-prefix-arg '(16))
  (let ((reftex-rebuilding-toc t))
    (reftex-toc)))

(defun reftex-toc-revert (&rest ignore)
  "Regenerate the *toc* from the internal lists."
  (interactive)
  (let ((unsplittable
         (if (fboundp 'frame-property)
             (frame-property (selected-frame) 'unsplittable)
           (frame-parameter (selected-frame) 'unsplittable)))
        (reftex-rebuilding-toc t))
    (if unsplittable
        (switch-to-buffer
         (reftex-get-file-buffer-force reftex-last-toc-file))
      (switch-to-buffer-other-window
       (reftex-get-file-buffer-force reftex-last-toc-file))))
  (reftex-erase-buffer "*toc*")
  (setq current-prefix-arg nil)
  (reftex-toc t))

(defun reftex-toc-external (&rest ignore)
  "Switch to table of contents of an external document."
  (interactive)
  (reftex-toc-dframe-p nil 'error)
  (let* ((old-buf (current-buffer))
         (xr-alist (get-text-property 1 'xr-alist))
         (xr-index (reftex-select-external-document
                   xr-alist 0)))
    (switch-to-buffer-other-window (or (reftex-get-file-buffer-force
                                        (cdr (nth xr-index xr-alist)))
                                       (error "Cannot switch document")))
    (reftex-toc)
    (if (equal old-buf (current-buffer))
        (message "")
      (message "Switched document"))))

(defun reftex-toc-jump (arg)
  "Jump to a specific section.  E.g. '3 z' jumps to section 3.
Useful for large TOC's."
  (interactive "P")
  (goto-char (point-min))
  (re-search-forward
   (concat "^ *" (number-to-string (if (numberp arg) arg 1)) " ")
   nil t)
  (beginning-of-line))

;; Promotion/Demotion stuff

(defvar delta)
(defvar mpos)
(defvar pro-or-de)
(defvar start-pos)
(defvar start-line)
(defvar mark-line)

(defun reftex-toc-demote (&optional arg)
  "Demote section at point.  If region is active, apply to all in region."
  (interactive "p")
  (reftex-toc-do-promote 1))
(defun reftex-toc-promote (&optional arg)
  "Promote section at point.  If region is active, apply to all in region."
  (interactive "p")
  (reftex-toc-do-promote -1))
(defun reftex-toc-do-promote (delta)
  "Workhorse for reftex-toc-promote and reftex-to-demote.
Changes the level of sections in the current region, or just the section at
point."
  ;; We should not do anything unless we are sure this is going to work for
  ;; each section in the region.  Therefore we first collect information and
  ;; test.
  (let* ((start-line (+ (count-lines (point-min) (point))
			(if (bolp) 1 0)))
	 (mark-line  (if (reftex-region-active-p)
			 (save-excursion (goto-char (mark))
					 (+ (count-lines (point-min) (point))
					    (if (bolp) 1 0)))))
         (start-pos (point))
         (pro-or-de (if (> delta 0) "de" "pro"))
         beg end entries data sections nsec mpos msg)
    (setq msg
          (catch 'exit
            (if (reftex-region-active-p)
                ;; A region is dangerous, check if we have a brandnew scan,
                ;; to make sure we are not missing any section statements.
                (if (not (reftex-toc-check-docstruct))
                    (reftex-toc-load-all-files-for-promotion)   ;; exits
                  (setq beg (min (point) (mark))
                        end (max (point) (mark))))
              (setq beg (point) end (point)))
            (goto-char beg)
            (while (and (setq data (get-text-property (point) :data))
                        (<= (point) end))
              (if (eq (car data) 'toc) (push (cons data (point)) entries))
              (goto-char (or (next-single-property-change (point) :data)
                             (point-max))))
            (setq entries (nreverse entries))
            ;; Get the relevant section numbers, for an informative message
            (goto-char start-pos)
            (setq sections (reftex-toc-extract-section-number (car entries)))
            (if (> (setq nsec (length entries)) 1)
                (setq sections
                      (concat sections "-"
                              (reftex-toc-extract-section-number
                               (nth (1- nsec) entries)))))
            ;; Run through the list and prepare the changes.
            (setq entries (mapcar 'reftex-toc-promote-prepare entries))
            ;; Ask for permission
            (if (or (not reftex-toc-confirm-promotion)           ; never confirm
                    (and (integerp reftex-toc-confirm-promotion) ; confirm if many
                         (< nsec reftex-toc-confirm-promotion))
                    (yes-or-no-p                                 ; ask
                     (format "%s %d toc-entr%s (section%s %s)? "
                             (if (< delta 0) "Promote" "Demote")
                             nsec
                             (if (= 1 nsec) "y" "ies")
                             (if (= 1 nsec) "" "s")
                             sections)))
                nil              ; we have permission, do nothing
              (error "Abort"))   ; abort, we don't have permission
            ;; Do the changes
            (mapc 'reftex-toc-promote-action entries)
            ;; Rescan the document and rebuilt the toc buffer
            (save-window-excursion
              (reftex-toc-Rescan))
            (reftex-toc-restore-region start-line mark-line)
            (message "%d section%s %smoted"
                     nsec (if (= 1 nsec) "" "s") pro-or-de)
            nil))
    (if msg (progn (ding) (message "%s" msg)))))


(defun reftex-toc-restore-region (point-line &optional mark-line)
  (when mark-line
    (goto-char (point-min))
    (forward-line (1- mark-line))
    (setq mpos (point)))
  (when point-line
    (goto-char (point-min))
    (forward-line (1- point-line)))
  (if mark-line
      (progn
        (set-mark mpos)
        (if (featurep 'xemacs)
            (zmacs-activate-region)
          (setq mark-active t
                deactivate-mark nil)))))

(defvar name1)
(defvar dummy)
(defvar dummy2)

(defun reftex-toc-promote-prepare (x)
  "Look at a toc entry and see if we could pro/demote it.
Expects the level change DELTA to be dynamically scoped into this function.
This function prepares everything for the changes, but does not do it.
The return value is a list with information needed when doing the
promotion/demotion later."
  (let* ((data (car x))
         (toc-point (cdr x))
         (marker (nth 4 data))
         (literal (nth 7 data))
         (load nil)
         (name nil)
         ;; Here follows some paranoid code to make very sure we are not
         ;; going to break anything
         (name1         ; dummy
          (if (and (markerp marker) (marker-buffer marker))
              ;; Buffer is still live and we have the marker.
              (progn
                (save-excursion
                  ;; Goto the buffer and check of section is unchanged
                  (set-buffer (marker-buffer marker))
                  (goto-char (marker-position marker))
                  (if (looking-at (regexp-quote literal))
                      ;; OK, get the makro name
                      (progn
                        (beginning-of-line 1)
                        (if (looking-at reftex-section-regexp)
                            (setq name (reftex-match-string 2))
                          (error "Something is wrong!  Contact maintainer!")))
                    ;; Section has changed, request scan and loading
                    ;; We use a variable to delay until after the safe-exc.
                    ;; because otherwise we loose the region.
                    (setq load t)))
                ;; Scan document and load all files, this exits command
                (if load (reftex-toc-load-all-files-for-promotion))) ; exits
            ;; We don't have a live marker: scan and load files.
            (reftex-toc-load-all-files-for-promotion)))
         (level (cdr (assoc name reftex-section-levels-all)))
         (dummy (if (not (integerp level))
                    (progn
                      (goto-char toc-point)
                      (error "Cannot %smote special sections" pro-or-de))))
         ;; Delta is dynamically scoped into here...
         (newlevel (if (>= level 0) (+ delta level) (- level delta)))
         (dummy2 (if (or (and (>= level 0) (= newlevel -1))
                         (and (< level 0)  (= newlevel 0)))
                     (error "Cannot %smote \\%s" pro-or-de name)))
         (newname (reftex-toc-newhead-from-alist newlevel name
                                                 reftex-section-levels-all)))
    (if (and name newname)
        (list data name newname toc-point)
      (goto-char toc-point)
      (error "Cannot %smote \\%s" pro-or-de name))))

(defun reftex-toc-promote-action (x)
  "Change the level of a toc entry.
DELTA and PRO-OR-DE are assumed to be dynamically scoped into this function."
  (let* ((data (car x))
         (name (nth 1 x))
         (newname (nth 2 x))
         (marker (nth 4 data)))
    (with-current-buffer (marker-buffer marker)
      (goto-char (marker-position marker))
      (if (looking-at (concat "\\([ \t]*\\\\\\)" (regexp-quote name)))
          (replace-match (concat "\\1" newname))
        (error "Fatal error during %smotion" pro-or-de)))))

(defun reftex-toc-extract-section-number (entry)
  "Get the numbering of a toc entry, for message purposes."
  (if (string-match "\\s-*\\(\\S-+\\)" (nth 2 (car entry)))
      (match-string 1 (nth 2 (car entry)))
    "?"))

(defun reftex-toc-newhead-from-alist (nlevel head alist)
  "Get new heading with level NLEVEL from ALIST.
If there are no such entries, return nil.
If there are several different entries with same new level, choose
the one with the smallest distance to the assocation of HEAD in the alist.
This makes it possible for promotion to work several sets of headings,
if these sets are sorted blocks in the alist."
  (let* ((al alist)
         (ass (assoc head al))
         (pos (length (memq ass al)))
         dist (mindist 1000) newhead)
    (while al
      (if (equal (cdar al) nlevel)
          (progn
            (setq dist (abs (- (length al) pos)))
            (if (< dist mindist)
                (setq newhead (car (car al))
                      mindist dist))))
      (setq al (cdr al)))
    newhead))

(defun reftex-toc-check-docstruct ()
  "Check if the current docstruct is fully up to date and all files visited."
  ;; We do this by checking if all sections are on the right position
  (let ((docstruct (symbol-value reftex-docstruct-symbol))
        entry marker empoint)
    (catch 'exit
      (while (setq entry (pop docstruct))
        (if (eq (car entry) 'toc)
            (progn
              (setq marker (nth 4 entry)
                    empoint (nth 8 entry))
              (if (not (and (markerp marker)
                            (marker-buffer marker)
                            (= (marker-position marker) empoint)))
                  (throw 'exit nil)))))
      t)))

(defun reftex-toc-load-all-files-for-promotion ()
  "Make sure all files of the document are being visited by buffers,
and that the scanning info is absolutely up to date.
We do this by rescanning with reftex-keep-temporary-buffers bound to t.
The variable PRO-OR-DE is assumed to be dynamically scoped into this function.
When finished, we exit with an error message."
  (let ((reftex-keep-temporary-buffers t))
    (reftex-toc-Rescan)
    (reftex-toc-restore-region start-line mark-line)
    (throw 'exit
           "TOC had to be updated first.  Please check selection and repeat the command.")))

(defun reftex-toc-rename-label ()
  "Rename the currently selected label in the *TOC* buffer.
This launches a global search and replace in order to rename a label.
Renaming a label is hardly ever necessary - the only exeption is after
promotion/demotion in connection with a package like fancyref, where the
label prefix determines the wording of a reference."
  (interactive)
  (let* ((toc (get-text-property (point) :data))
         (label (car toc)) newlabel)
    (if (not (stringp label))
        (error "This is not a label entry"))
    (setq newlabel (read-string (format "Rename label \"%s\" to:" label)))
    (if (assoc newlabel (symbol-value reftex-docstruct-symbol))
        (if (not (y-or-n-p
                  (format "Label '%s' exists. Use anyway? " label)))
            (error "Abort")))
    (save-excursion
      (save-window-excursion
        (reftex-toc-visit-location t)
        (condition-case nil
            (reftex-query-replace-document
             (concat "{" (regexp-quote label) "}")
             (format "{%s}" newlabel))
          (error t))))
    (reftex-toc-rescan)))


(defun reftex-toc-visit-location (&optional final no-revisit)
  ;; Visit the tex file corresponding to the toc entry on the current line.
  ;; If FINAL is t, stay there
  ;; If FINAL is 'hide, hide the *toc* window.
  ;; Otherwise, move cursor back into *toc* window.
  ;; NO-REVISIT means don't visit files, just use live buffers.
  ;; This function is pretty clever about finding back a section heading,
  ;; even if the buffer is not live, or things like outline, x-symbol etc.
  ;; have been active.

  (let* ((toc (get-text-property (point) :data))
         (toc-window (selected-window))
         show-window show-buffer match)

    (unless toc (error "Don't know which toc line to visit"))

    (cond

     ((eq (car toc) 'toc)
      ;; a toc entry
      (setq match (reftex-toc-find-section toc no-revisit)))

     ((eq (car toc) 'index)
      ;; an index entry
      (setq match (reftex-index-show-entry toc no-revisit)))

     ((memq (car toc) '(bof eof))
      ;; A file entry
      (setq match
            (let ((where (car toc))
                  (file (nth 1 toc)))
              (if (or (not no-revisit) (reftex-get-buffer-visiting file))
                  (progn
                    (switch-to-buffer-other-window
                     (reftex-get-file-buffer-force file nil))
                    (goto-char (if (eq where 'bof) (point-min) (point-max))))
                (message "%s" reftex-no-follow-message) nil))))

     ((stringp (car toc))
      ;; a label
      (setq match (reftex-show-label-location toc reftex-callback-fwd
                                                no-revisit t))))

    (setq show-window (selected-window)
          show-buffer (current-buffer))

    (unless match
      (select-window toc-window)
      (error "Cannot find location"))

    (select-window toc-window)

    ;; use the `final' parameter to decide what to do next
    (cond
     ((eq final t)
      (reftex-unhighlight 0)
      (select-window show-window))
     ((eq final 'hide)
      (reftex-unhighlight 0)
      (or (one-window-p) (delete-window))
      ;; If `show-window' is still live, show-buffer is already visible
      ;; so let's not make it visible in yet-another-window.
      (if (window-live-p show-window)
	  (set-buffer show-buffer)
	(switch-to-buffer show-buffer))
      (reftex-re-enlarge))
     (t nil))))

(defun reftex-toc-find-section (toc &optional no-revisit)
  (let* ((file (nth 3 toc))
         (marker (nth 4 toc))
         (level (nth 5 toc))
         (literal (nth 7 toc))
         (emergency-point (nth 8 toc))
         (match
          (cond
           ((and (markerp marker) (marker-buffer marker))
            ;; Buffer is still live and we have the marker.  Should be easy.
            (switch-to-buffer-other-window (marker-buffer marker))
            (push-mark nil)
            (goto-char (marker-position marker))
            (or (looking-at (regexp-quote literal))
                (looking-at (reftex-make-regexp-allow-for-ctrl-m literal))
                (looking-at (reftex-make-desperate-section-regexp literal))
                (looking-at (concat "\\\\"
                                    (regexp-quote
                                     (car
                                      (rassq level
                                             reftex-section-levels-all)))
                                    "[[{]?"))))
           ((or (not no-revisit)
                (reftex-get-buffer-visiting file))
            ;; Marker is lost.  Use the backup method.
            (switch-to-buffer-other-window
             (reftex-get-file-buffer-force file nil))
            (goto-char (or emergency-point (point-min)))
            (or (looking-at (regexp-quote literal))
                (let ((len (length literal)))
                  (or (reftex-nearest-match (regexp-quote literal) len)
                      (reftex-nearest-match
                       (reftex-make-regexp-allow-for-ctrl-m literal) len)
                      (reftex-nearest-match
                       (reftex-make-desperate-section-regexp literal) len)))))
           (t (message "%s" reftex-no-follow-message) nil))))
    (when match
      (goto-char (match-beginning 0))
      (if (not (= (point) (point-max))) (recenter 1))
      (reftex-highlight 0 (match-beginning 0) (match-end 0) (current-buffer)))
    match))

(defun reftex-make-desperate-section-regexp (old)
  ;; Return a regexp which will still match a section statement even if
  ;; x-symbol or isotex or the like have been at work in the mean time.
  (let* ((n (1+ (string-match "[[{]" old)))
         (new (regexp-quote (substring old 0 (1+ (string-match "[[{]" old)))))
         (old (substring old n)))
    (while (string-match
            "\\([\r\n]\\)\\|\\(\\`\\|[ \t\n\r]\\)\\([a-zA-Z0-9]+\\)\\([ \t\n\r]\\|}\\'\\)"
            old)
      (if (match-beginning 1)
          (setq new (concat new "[^\n\r]*[\n\r]"))
        (setq new (concat new "[^\n\r]*" (match-string 3 old))))
      (setq old (substring old (match-end 0))))
    new))

;; Auto recentering of TOC window

(defun reftex-recenter-toc-when-idle ()
  (and (> (buffer-size) 5)
       reftex-mode
       (not (active-minibuffer-window))
       (fboundp 'reftex-toc-mode)
       (get-buffer-window "*toc*" 'visible)
       (string= reftex-last-toc-master (reftex-TeX-master-file))
       (let (current-prefix-arg)
         (reftex-toc-recenter))))

(defun reftex-toggle-auto-toc-recenter ()
  "Toggle the automatic recentering of the toc window.
When active, leaving point idle will make the toc window jump to the correct
section."
  (interactive)
  (if reftex-toc-auto-recenter-timer
      (progn
        (if (featurep 'xemacs)
            (delete-itimer reftex-toc-auto-recenter-timer)
          (cancel-timer reftex-toc-auto-recenter-timer))
        (setq reftex-toc-auto-recenter-timer nil)
        (message "Automatic recentering of toc windwo was turned off"))
    (setq reftex-toc-auto-recenter-timer
          (if (featurep 'xemacs)
              (start-itimer "RefTeX Idle Timer for recenter"
                            'reftex-recenter-toc-when-idle
                            reftex-idle-time reftex-idle-time t)
            (run-with-idle-timer
             reftex-idle-time t 'reftex-recenter-toc-when-idle)))
    (message "Automatic recentering of toc window was turned on")))

(defun reftex-toc-toggle-dedicated-frame ()
  "Toggle the display of a separate frame for the TOC.
This frame is not used by the `reftex-toc' commands, but it is useful to
always show the current section in connection with the option
`reftex-auto-recenter-toc'."
  (interactive)
  (catch 'exit
    (let* ((frames (frame-list)) frame
           (get-frame-prop-func (if (fboundp 'frame-property)
                                    'frame-property
                                  'frame-parameter)))
      (while (setq frame (pop frames))
        (if (equal (funcall get-frame-prop-func frame 'name)
                   "RefTeX TOC Frame")
            (progn
              (delete-frame frame)
              (throw 'exit nil))))
      (reftex-make-separate-toc-frame))))

(defun reftex-make-separate-toc-frame ()
  ;; Create a new fame showing only the toc buffer.
  (let ((current-frame (selected-frame))
        (current-window (selected-window))
        (current-toc-window (get-buffer-window "*toc*" 'visible))
        current-toc-frame)
    (if (and current-toc-window
             (not (equal (selected-frame) (window-frame current-toc-window))))
        nil
      (setq current-toc-frame
            (make-frame
             '((name . "RefTeX TOC Frame")
               (height . 20) (width . 60)
               (unsplittable . t)
               (minibuffer . nil)
               (default-toolbar-visible-p . nil)
               (menubar-visible-p . nil)
               (horizontal-scrollbar-visible-p . nil))))
      (select-frame current-toc-frame)
      (switch-to-buffer "*toc*")
      (select-frame current-frame)
      (cond ((fboundp 'x-focus-frame)
             (x-focus-frame current-frame))
            ((and (featurep 'xemacs) ; `focus-frame' is a nop in Emacs.
                  (fboundp 'focus-frame))
             (focus-frame current-frame)))
      (select-window current-window)
      (when (eq reftex-auto-recenter-toc 'frame)
        (unless reftex-toc-auto-recenter-timer
          (reftex-toggle-auto-toc-recenter))
        (add-hook 'delete-frame-hook 'reftex-toc-delete-frame-hook)))))

(defun reftex-toc-delete-frame-hook (frame)
  (if (and reftex-toc-auto-recenter-timer
           (reftex-toc-dframe-p frame))
      (progn
      (reftex-toggle-auto-toc-recenter))))

;; Table of Contents map
(define-key reftex-toc-map (if (featurep 'xemacs) [(button2)] [(mouse-2)])
  'reftex-toc-mouse-goto-line-and-hide)
(define-key reftex-toc-map [follow-link] 'mouse-face)

(substitute-key-definition
 'next-line 'reftex-toc-next reftex-toc-map global-map)
(substitute-key-definition
 'previous-line 'reftex-toc-previous reftex-toc-map global-map)

(loop for x in
      '(("n"        . reftex-toc-next)
        ("p"        . reftex-toc-previous)
        ("?"        . reftex-toc-show-help)
        (" "        . reftex-toc-view-line)
        ("\C-m"     . reftex-toc-goto-line-and-hide)
        ("\C-i"     . reftex-toc-goto-line)
        ("\C-c>"    . reftex-toc-display-index)
        ("r"        . reftex-toc-rescan)
        ("R"        . reftex-toc-Rescan)
        ("g"        . revert-buffer)
        ("q"        . reftex-toc-quit);
        ("k"        . reftex-toc-quit-and-kill)
        ("f"        . reftex-toc-toggle-follow);
        ("a"        . reftex-toggle-auto-toc-recenter)
        ("d"        . reftex-toc-toggle-dedicated-frame)
        ("F"        . reftex-toc-toggle-file-boundary)
        ("i"        . reftex-toc-toggle-index)
        ("l"        . reftex-toc-toggle-labels)
        ("t"        . reftex-toc-max-level)
        ("c"        . reftex-toc-toggle-context)
;        ("%"        . reftex-toc-toggle-commented)
        ("\M-%"     . reftex-toc-rename-label)
        ("x"        . reftex-toc-external)
        ("z"        . reftex-toc-jump)
        ("."        . reftex-toc-show-calling-point)
        ("\C-c\C-n" . reftex-toc-next-heading)
        ("\C-c\C-p" . reftex-toc-previous-heading)
        (">"        . reftex-toc-demote)
        ("<"        . reftex-toc-promote))
      do (define-key reftex-toc-map (car x) (cdr x)))

(loop for key across "0123456789" do
      (define-key reftex-toc-map (vector (list key)) 'digit-argument))
(define-key reftex-toc-map "-" 'negative-argument)

(easy-menu-define
 reftex-toc-menu reftex-toc-map
 "Menu for Table of Contents buffer"
 '("TOC"
   ["Show Location" reftex-toc-view-line t]
   ["Go To Location" reftex-toc-goto-line t]
   ["Exit & Go To Location" reftex-toc-goto-line-and-hide t]
   ["Show Calling Point" reftex-toc-show-calling-point t]
   ["Quit" reftex-toc-quit t]
   "--"
   ("Edit"
    ["Promote" reftex-toc-promote t]
    ["Demote" reftex-toc-demote t]
    ["Rename Label" reftex-toc-rename-label t])
   "--"
   ["Index" reftex-toc-display-index t]
   ["External Document TOC  " reftex-toc-external t]
   "--"
   ("Update"
    ["Rebuilt *toc* Buffer" revert-buffer t]
    ["Rescan One File" reftex-toc-rescan reftex-enable-partial-scans]
    ["Rescan Entire Document" reftex-toc-Rescan t])
   ("Options"
    "TOC Items"
    ["File Boundaries" reftex-toc-toggle-file-boundary :style toggle
     :selected reftex-toc-include-file-boundaries]
    ["Labels" reftex-toc-toggle-labels :style toggle
     :selected reftex-toc-include-labels]
    ["Index Entries" reftex-toc-toggle-index :style toggle
     :selected reftex-toc-include-index-entries]
    ["Context" reftex-toc-toggle-context :style toggle
     :selected reftex-toc-include-context]
    "--"
    ["Follow Mode" reftex-toc-toggle-follow :style toggle
     :selected reftex-toc-follow-mode]
    ["Auto Recenter" reftex-toggle-auto-toc-recenter :style toggle
     :selected reftex-toc-auto-recenter-timer]
    ["Dedicated Frame" reftex-toc-toggle-dedicated-frame t])
   "--"
   ["Help" reftex-toc-show-help t]))


;; arch-tag: 92400ce2-0b86-4c89-a606-4ed71acea17e
;;; reftex-toc.el ends here