comparison lisp/org/org-src.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 2a8a3a69c1c7
children b92e7ae35c75
comparison
equal deleted inserted replaced
105972:371db60eff06 105973:b7d8222914b4
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc. 4 ;; Free Software Foundation, Inc.
5 ;; 5 ;;
6 ;; Author: Carsten Dominik <carsten at orgmode dot org> 6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Bastien Guerry <bzg AT altern DOT org> 7 ;; Bastien Guerry <bzg AT altern DOT org>
8 ;; Dan Davison <davison at stats dot ox dot ac dot uk>
8 ;; Keywords: outlines, hypermedia, calendar, wp 9 ;; Keywords: outlines, hypermedia, calendar, wp
9 ;; Homepage: http://orgmode.org 10 ;; Homepage: http://orgmode.org
10 ;; Version: 6.31a 11 ;; Version: 6.33
11 ;; 12 ;;
12 ;; This file is part of GNU Emacs. 13 ;; This file is part of GNU Emacs.
13 ;; 14 ;;
14 ;; GNU Emacs is free software: you can redistribute it and/or modify 15 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by 16 ;; it under the terms of the GNU General Public License as published by
31 32
32 ;;; Code: 33 ;;; Code:
33 34
34 (require 'org-macs) 35 (require 'org-macs)
35 (require 'org-compat) 36 (require 'org-compat)
37 (eval-when-compile
38 (require 'cl))
36 39
37 (declare-function org-do-remove-indentation "org" (&optional n)) 40 (declare-function org-do-remove-indentation "org" (&optional n))
38 (declare-function org-get-indentation "org" (&optional line)) 41 (declare-function org-get-indentation "org" (&optional line))
42 (declare-function org-switch-to-buffer-other-window "org" (&rest args))
39 43
40 (defcustom org-edit-src-region-extra nil 44 (defcustom org-edit-src-region-extra nil
41 "Additional regexps to identify regions for editing with `org-edit-src-code'. 45 "Additional regexps to identify regions for editing with `org-edit-src-code'.
42 For examples see the function `org-edit-src-find-region-and-lang'. 46 For examples see the function `org-edit-src-find-region-and-lang'.
43 The regular expression identifying the begin marker should end with a newline, 47 The regular expression identifying the begin marker should end with a newline,
79 (const artist-mode) 83 (const artist-mode)
80 (const picture-mode) 84 (const picture-mode)
81 (const fundamental-mode) 85 (const fundamental-mode)
82 (function :tag "Other (specify)"))) 86 (function :tag "Other (specify)")))
83 87
88 (defcustom org-src-preserve-indentation nil
89 "If non-nil, leading whitespace characters in source code
90 blocks are preserved on export, and when switching between the
91 org buffer and the language mode edit buffer. If this variable
92 is nil then, after editing with \\[org-edit-src-code], the
93 minimum (across-lines) number of leading whitespace characters
94 are removed from all lines, and the code block is uniformly
95 indented according to the value of `org-edit-src-content-indentation'."
96 :group 'org-edit-structure
97 :type 'boolean)
98
84 (defcustom org-edit-src-content-indentation 2 99 (defcustom org-edit-src-content-indentation 2
85 "Indentation for the content is a source code block. 100 "Indentation for the content of a source code block.
86 This should be the number of spaces added to the indentation of the #+begin 101 This should be the number of spaces added to the indentation of the #+begin
87 line in order to compute the indentation of the block content after 102 line in order to compute the indentation of the block content after
88 editing it with \\[org-edit-src-code]." 103 editing it with \\[org-edit-src-code]. Has no effect if
104 `org-src-preserve-indentation' is non-nil."
89 :group 'org-edit-structure 105 :group 'org-edit-structure
90 :type 'integer) 106 :type 'integer)
91 107
92 (defcustom org-edit-src-persistent-message t 108 (defcustom org-edit-src-persistent-message t
93 "Non-nil means show persistent exit help message while editing src examples. 109 "Non-nil means show persistent exit help message while editing src examples.
96 When nil, the message will only be shown intermittently in the echo area." 112 When nil, the message will only be shown intermittently in the echo area."
97 :group 'org-edit-structure 113 :group 'org-edit-structure
98 :type 'boolean) 114 :type 'boolean)
99 115
100 116
117 (defcustom org-src-window-setup 'reorganize-frame
118 "How the source code edit buffer should be displayed.
119 Possible values for this option are:
120
121 current-window Show edit buffer in the current window, keeping all other
122 windows.
123 other-window Use `switch-to-buffer-other-window' to display edit buffer.
124 reorganize-frame Show only two windows on the current frame, the current
125 window and the edit buffer. When exiting the edit buffer,
126 return to one window.
127 other-frame Use `switch-to-buffer-other-frame' to display edit buffer.
128 Also, when exiting the edit buffer, kill that frame."
129 :group 'org-edit-structure
130 :type '(choice
131 (const current-window)
132 (const other-frame)
133 (const other-window)
134 (const reorganize-frame)))
135
101 (defvar org-src-mode-hook nil 136 (defvar org-src-mode-hook nil
102 "Hook run after Org switched a source code snippet to its Emacs mode. 137 "Hook run after Org switched a source code snippet to its Emacs mode.
103 This hook will run 138 This hook will run
104 139
105 - when editing a source code snippet with \"C-c '\". 140 - when editing a source code snippet with \"C-c '\".
109 or similar things which you want to have when editing a source code file, 144 or similar things which you want to have when editing a source code file,
110 but which mess up the display of a snippet in Org exported files.") 145 but which mess up the display of a snippet in Org exported files.")
111 146
112 (defcustom org-src-lang-modes 147 (defcustom org-src-lang-modes
113 '(("ocaml" . tuareg) ("elisp" . emacs-lisp) ("ditaa" . artist) 148 '(("ocaml" . tuareg) ("elisp" . emacs-lisp) ("ditaa" . artist)
114 ("asymptote" . asy)) 149 ("asymptote" . asy) ("dot" . fundamental))
115 "Alist mapping languages to their major mode. 150 "Alist mapping languages to their major mode.
116 The key is the language name, the value is the string that should 151 The key is the language name, the value is the string that should
117 be inserted as the name of the major mode. For many languages this is 152 be inserted as the name of the major mode. For many languages this is
118 simple, but for language where this is not the case, this variable 153 simple, but for language where this is not the case, this variable
119 provides a way to simplify things on the user side. 154 provides a way to simplify things on the user side.
133 (defvar org-edit-src-from-org-mode nil) 168 (defvar org-edit-src-from-org-mode nil)
134 (defvar org-edit-src-picture nil) 169 (defvar org-edit-src-picture nil)
135 (defvar org-edit-src-beg-marker nil) 170 (defvar org-edit-src-beg-marker nil)
136 (defvar org-edit-src-end-marker nil) 171 (defvar org-edit-src-end-marker nil)
137 (defvar org-edit-src-overlay nil) 172 (defvar org-edit-src-overlay nil)
138 (defvar org-edit-src-nindent nil) 173 (defvar org-edit-src-block-indentation nil)
174 (defvar org-edit-src-saved-temp-window-config nil)
175
176 (defvar org-src-ask-before-returning-to-edit-buffer t
177 "If nil, when org-edit-src code is used on a block that already
178 has an active edit buffer, it will switch to that edit buffer
179 immediately; otherwise it will ask whether you want to return
180 to the existing edit buffer.")
139 181
140 (define-minor-mode org-src-mode 182 (define-minor-mode org-src-mode
141 "Minor mode for language major mode buffers generated by org. 183 "Minor mode for language major mode buffers generated by org.
142 This minor mode is turned on in two situations: 184 This minor mode is turned on in two situations:
143 - when editing a source code snippet with \"C-c '\". 185 - when editing a source code snippet with \"C-c '\".
144 - When formatting a source code snippet for export with htmlize. 186 - When formatting a source code snippet for export with htmlize.
145 There is a mode hook, and keybindings for `org-edit-src-exit' and 187 There is a mode hook, and keybindings for `org-edit-src-exit' and
146 `org-edit-src-save'") 188 `org-edit-src-save'")
147 189
148 (defun org-edit-src-code () 190 (defun org-edit-src-code (&optional context)
149 "Edit the source code example at point. 191 "Edit the source code example at point.
150 The example is copied to a separate buffer, and that buffer is switched 192 The example is copied to a separate buffer, and that buffer is switched
151 to the correct language mode. When done, exit with \\[org-edit-src-exit]. 193 to the correct language mode. When done, exit with \\[org-edit-src-exit].
152 This will remove the original code in the Org buffer, and replace it with 194 This will remove the original code in the Org buffer, and replace it with
153 the edited version." 195 the edited version. Optional argument CONTEXT is used by
196 \\[org-edit-src-save] when calling this function."
154 (interactive) 197 (interactive)
198 (unless (eq context 'save)
199 (setq org-edit-src-saved-temp-window-config (current-window-configuration)))
155 (let ((line (org-current-line)) 200 (let ((line (org-current-line))
201 (col (current-column))
156 (case-fold-search t) 202 (case-fold-search t)
157 (msg (substitute-command-keys 203 (msg (substitute-command-keys
158 "Edit, then exit with C-c ' (C-c and single quote)")) 204 "Edit, then exit with C-c ' (C-c and single quote)"))
159 (info (org-edit-src-find-region-and-lang)) 205 (info (org-edit-src-find-region-and-lang))
160 (org-mode-p (eq major-mode 'org-mode)) 206 (org-mode-p (eq major-mode 'org-mode))
161 (beg (make-marker)) 207 (beg (make-marker))
162 (end (make-marker)) 208 (end (make-marker))
163 nindent ovl lang lang-f single lfmt code begline buffer) 209 (preserve-indentation org-src-preserve-indentation)
210 block-nindent total-nindent ovl lang lang-f single lfmt code begline buffer)
164 (if (not info) 211 (if (not info)
165 nil 212 nil
166 (setq beg (move-marker beg (nth 0 info)) 213 (setq beg (move-marker beg (nth 0 info))
167 end (move-marker end (nth 1 info)) 214 end (move-marker end (nth 1 info))
168 code (buffer-substring-no-properties beg end) 215 code (buffer-substring-no-properties beg end)
169 lang (or (cdr (assoc (nth 2 info) org-src-lang-modes)) 216 lang (or (cdr (assoc (nth 2 info) org-src-lang-modes))
170 (nth 2 info)) 217 (nth 2 info))
171 lang (if (symbolp lang) (symbol-name lang) lang) 218 lang (if (symbolp lang) (symbol-name lang) lang)
172 single (nth 3 info) 219 single (nth 3 info)
173 lfmt (nth 4 info) 220 lfmt (nth 4 info)
174 nindent (nth 5 info) 221 block-nindent (nth 5 info)
175 lang-f (intern (concat lang "-mode")) 222 lang-f (intern (concat lang "-mode"))
176 begline (save-excursion (goto-char beg) (org-current-line))) 223 begline (save-excursion (goto-char beg) (org-current-line)))
177 (unless (functionp lang-f) 224 (unless (functionp lang-f)
178 (error "No such language mode: %s" lang-f)) 225 (error "No such language mode: %s" lang-f))
179 (org-goto-line line) 226 (org-goto-line line)
180 (if (and (setq buffer (org-edit-src-find-buffer beg end)) 227 (if (and (setq buffer (org-edit-src-find-buffer beg end))
181 (y-or-n-p "Return to existing edit buffer? [n] will revert changes: ")) 228 (if org-src-ask-before-returning-to-edit-buffer
182 (switch-to-buffer buffer) 229 (y-or-n-p "Return to existing edit buffer? [n] will revert changes: ") t))
230 (org-src-switch-to-buffer buffer 'return)
183 (when buffer 231 (when buffer
184 (with-current-buffer buffer 232 (with-current-buffer buffer
185 (if (boundp 'org-edit-src-overlay) 233 (if (boundp 'org-edit-src-overlay)
186 (org-delete-overlay org-edit-src-overlay))) 234 (org-delete-overlay org-edit-src-overlay)))
187 (kill-buffer buffer)) 235 (kill-buffer buffer))
188 (setq buffer (generate-new-buffer 236 (setq buffer (generate-new-buffer
189 (org-src-construct-edit-buffer-name (buffer-name) lang))) 237 (org-src-construct-edit-buffer-name (buffer-name) lang)))
190 (setq ovl (org-make-overlay beg end)) 238 (setq ovl (org-make-overlay beg end))
191 (org-overlay-put ovl 'face 'secondary-selection)
192 (org-overlay-put ovl 'edit-buffer buffer) 239 (org-overlay-put ovl 'edit-buffer buffer)
193 (org-overlay-put ovl 'help-echo "Click with mouse-1 to switch to buffer editing this segment") 240 (org-overlay-put ovl 'help-echo "Click with mouse-1 to switch to buffer editing this segment")
194 (org-overlay-put ovl 'face 'secondary-selection) 241 (org-overlay-put ovl 'face 'secondary-selection)
195 (org-overlay-put ovl 242 (org-overlay-put ovl
196 'keymap 243 'keymap
197 (let ((map (make-sparse-keymap))) 244 (let ((map (make-sparse-keymap)))
198 (define-key map [mouse-1] 'org-edit-src-continue) 245 (define-key map [mouse-1] 'org-edit-src-continue)
199 map)) 246 map))
200 (org-overlay-put ovl :read-only "Leave me alone") 247 (org-overlay-put ovl :read-only "Leave me alone")
201 (switch-to-buffer buffer) 248 (org-src-switch-to-buffer buffer 'edit)
249 (if (eq single 'macro-definition)
250 (setq code (replace-regexp-in-string "\\\\n" "\n" code t t)))
202 (insert code) 251 (insert code)
203 (remove-text-properties (point-min) (point-max) 252 (remove-text-properties (point-min) (point-max)
204 '(display nil invisible nil intangible nil)) 253 '(display nil invisible nil intangible nil))
205 (org-do-remove-indentation) 254 (unless preserve-indentation
255 (setq total-nindent (or (org-do-remove-indentation) 0)))
206 (let ((org-inhibit-startup t)) 256 (let ((org-inhibit-startup t))
207 (funcall lang-f)) 257 (funcall lang-f))
208 (set (make-local-variable 'org-edit-src-force-single-line) single) 258 (set (make-local-variable 'org-edit-src-force-single-line) single)
209 (set (make-local-variable 'org-edit-src-from-org-mode) org-mode-p) 259 (set (make-local-variable 'org-edit-src-from-org-mode) org-mode-p)
260 (set (make-local-variable 'org-src-preserve-indentation) preserve-indentation)
210 (when lfmt 261 (when lfmt
211 (set (make-local-variable 'org-coderef-label-format) lfmt)) 262 (set (make-local-variable 'org-coderef-label-format) lfmt))
212 (when org-mode-p 263 (when org-mode-p
213 (goto-char (point-min)) 264 (goto-char (point-min))
214 (while (re-search-forward "^," nil t) 265 (while (re-search-forward "^," nil t)
266 (if (eq (org-current-line) line) (setq total-nindent (1+ total-nindent)))
215 (replace-match ""))) 267 (replace-match "")))
216 (org-goto-line (1+ (- line begline))) 268 (org-goto-line (1+ (- line begline)))
269 (org-move-to-column
270 (if preserve-indentation col (max 0 (- col total-nindent))))
217 (org-set-local 'org-edit-src-beg-marker beg) 271 (org-set-local 'org-edit-src-beg-marker beg)
218 (org-set-local 'org-edit-src-end-marker end) 272 (org-set-local 'org-edit-src-end-marker end)
219 (org-set-local 'org-edit-src-overlay ovl) 273 (org-set-local 'org-edit-src-overlay ovl)
220 (org-set-local 'org-edit-src-nindent nindent) 274 (org-set-local 'org-edit-src-block-indentation block-nindent)
221 (org-src-mode) 275 (org-src-mode)
222 (set-buffer-modified-p nil) 276 (set-buffer-modified-p nil)
223 (and org-edit-src-persistent-message 277 (and org-edit-src-persistent-message
224 (org-set-local 'header-line-format msg))) 278 (org-set-local 'header-line-format msg)))
225 (message "%s" msg) 279 (message "%s" msg)
227 281
228 (defun org-edit-src-continue (e) 282 (defun org-edit-src-continue (e)
229 (interactive "e") 283 (interactive "e")
230 (mouse-set-point e) 284 (mouse-set-point e)
231 (let ((buf (get-char-property (point) 'edit-buffer))) 285 (let ((buf (get-char-property (point) 'edit-buffer)))
232 (if buf (switch-to-buffer buf) 286 (if buf (org-src-switch-to-buffer buf 'continue)
233 (error "Something is wrong here")))) 287 (error "Something is wrong here"))))
288
289 (defun org-src-switch-to-buffer (buffer context)
290 (case org-src-window-setup
291 ('current-window
292 (switch-to-buffer buffer))
293 ('other-window
294 (switch-to-buffer-other-window buffer))
295 ('other-frame
296 (case context
297 ('exit
298 (let ((frame (selected-frame)))
299 (switch-to-buffer-other-frame buffer)
300 (delete-frame frame)))
301 ('save
302 (kill-buffer (current-buffer))
303 (switch-to-buffer buffer))
304 (t
305 (switch-to-buffer-other-frame buffer))))
306 ('reorganize-frame
307 (if (eq context 'edit) (delete-other-windows))
308 (org-switch-to-buffer-other-window buffer)
309 (if (eq context 'exit) (delete-other-windows)))
310 (t
311 (message "Invalid value %s for org-src-window-setup"
312 (symbol-name org-src-window-setup))
313 (switch-to-buffer buffer))))
234 314
235 (defun org-src-construct-edit-buffer-name (org-buffer-name lang) 315 (defun org-src-construct-edit-buffer-name (org-buffer-name lang)
236 "Construct the buffer name for a source editing buffer" 316 "Construct the buffer name for a source editing buffer"
237 (concat "*Org Src " org-buffer-name "[ " lang " ]*")) 317 (concat "*Org Src " org-buffer-name "[ " lang " ]*"))
238 318
259 and the buffer is switched into `artist-mode' for editing. When done, 339 and the buffer is switched into `artist-mode' for editing. When done,
260 exit with \\[org-edit-src-exit]. The edited text will then replace 340 exit with \\[org-edit-src-exit]. The edited text will then replace
261 the fragment in the Org-mode buffer." 341 the fragment in the Org-mode buffer."
262 (interactive) 342 (interactive)
263 (let ((line (org-current-line)) 343 (let ((line (org-current-line))
344 (col (current-column))
264 (case-fold-search t) 345 (case-fold-search t)
265 (msg (substitute-command-keys 346 (msg (substitute-command-keys
266 "Edit, then exit with C-c ' (C-c and single quote)")) 347 "Edit, then exit with C-c ' (C-c and single quote)"))
267 (org-mode-p (eq major-mode 'org-mode)) 348 (org-mode-p (eq major-mode 'org-mode))
268 (beg (make-marker)) 349 (beg (make-marker))
269 (end (make-marker)) 350 (end (make-marker))
270 nindent ovl beg1 end1 code begline buffer) 351 (preserve-indentation org-src-preserve-indentation)
352 block-nindent ovl beg1 end1 code begline buffer)
271 (beginning-of-line 1) 353 (beginning-of-line 1)
272 (if (looking-at "[ \t]*[^:\n \t]") 354 (if (looking-at "[ \t]*[^:\n \t]")
273 nil 355 nil
274 (if (looking-at "[ \t]*\\(\n\\|\\'\\)") 356 (if (looking-at "[ \t]*\\(\n\\|\\'\\)")
275 (setq beg1 (point) end1 beg1) 357 (setq beg1 (point) end1 beg1)
310 (org-overlay-put ovl :read-only "Leave me alone") 392 (org-overlay-put ovl :read-only "Leave me alone")
311 (switch-to-buffer buffer) 393 (switch-to-buffer buffer)
312 (insert code) 394 (insert code)
313 (remove-text-properties (point-min) (point-max) 395 (remove-text-properties (point-min) (point-max)
314 '(display nil invisible nil intangible nil)) 396 '(display nil invisible nil intangible nil))
315 (setq nindent (org-do-remove-indentation)) 397 (setq block-nindent (or (org-do-remove-indentation) 0))
316 (cond 398 (cond
317 ((eq org-edit-fixed-width-region-mode 'artist-mode) 399 ((eq org-edit-fixed-width-region-mode 'artist-mode)
318 (fundamental-mode) 400 (fundamental-mode)
319 (artist-mode 1)) 401 (artist-mode 1))
320 (t (funcall org-edit-fixed-width-region-mode))) 402 (t (funcall org-edit-fixed-width-region-mode)))
323 (set (make-local-variable 'org-edit-src-picture) t) 405 (set (make-local-variable 'org-edit-src-picture) t)
324 (goto-char (point-min)) 406 (goto-char (point-min))
325 (while (re-search-forward "^[ \t]*: ?" nil t) 407 (while (re-search-forward "^[ \t]*: ?" nil t)
326 (replace-match "")) 408 (replace-match ""))
327 (org-goto-line (1+ (- line begline))) 409 (org-goto-line (1+ (- line begline)))
410 (org-move-to-column (max 0 (- col block-nindent 2)))
328 (org-set-local 'org-edit-src-beg-marker beg) 411 (org-set-local 'org-edit-src-beg-marker beg)
329 (org-set-local 'org-edit-src-end-marker end) 412 (org-set-local 'org-edit-src-end-marker end)
330 (org-set-local 'org-edit-src-overlay ovl) 413 (org-set-local 'org-edit-src-overlay ovl)
331 (org-set-local 'org-edit-src-nindent nindent) 414 (org-set-local 'org-edit-src-block-indentation block-nindent)
415 (org-set-local 'org-edit-src-content-indentation 0)
416 (org-set-local 'org-src-preserve-indentation nil)
332 (org-src-mode) 417 (org-src-mode)
333 (set-buffer-modified-p nil) 418 (set-buffer-modified-p nil)
334 (and org-edit-src-persistent-message 419 (and org-edit-src-persistent-message
335 (org-set-local 'header-line-format msg))) 420 (org-set-local 'header-line-format msg)))
336 (message "%s" msg) 421 (message "%s" msg)
337 t))) 422 t)))
338 423
339 (defun org-edit-src-find-region-and-lang () 424 (defun org-edit-src-find-region-and-lang ()
340 "Find the region and language for a local edit. 425 "Find the region and language for a local edit.
341 Return a list with beginning and end of the region, a string representing 426 Return a list with beginning and end of the region, a string representing
342 the language, a switch telling of the content should be in a single line." 427 the language, a switch telling if the content should be in a single line."
343 (let ((re-list 428 (let ((re-list
344 (append 429 (append
345 org-edit-src-region-extra 430 org-edit-src-region-extra
346 '( 431 '(
347 ("<src\\>[^<]*>[ \t]*\n?" "\n?[ \t]*</src>" lang) 432 ("<src\\>[^<]*>[ \t]*\n?" "\n?[ \t]*</src>" lang)
358 ("^[ \t]*#\\+latex:" "\n" "latex" single-line) 443 ("^[ \t]*#\\+latex:" "\n" "latex" single-line)
359 ("^[ \t]*#\\+begin_latex.*\n" "\n[ \t]*#\\+end_latex" "latex") 444 ("^[ \t]*#\\+begin_latex.*\n" "\n[ \t]*#\\+end_latex" "latex")
360 ("^[ \t]*#\\+ascii:" "\n" "fundamental" single-line) 445 ("^[ \t]*#\\+ascii:" "\n" "fundamental" single-line)
361 ("^[ \t]*#\\+begin_ascii.*\n" "\n[ \t]*#\\+end_ascii" "fundamental") 446 ("^[ \t]*#\\+begin_ascii.*\n" "\n[ \t]*#\\+end_ascii" "fundamental")
362 ("^[ \t]*#\\+docbook:" "\n" "xml" single-line) 447 ("^[ \t]*#\\+docbook:" "\n" "xml" single-line)
448 ("^[ \t]*#\\+macro:[ \t]+\\S-+\\( \\|$\\)"
449 "\n" "fundamental" macro-definition)
363 ("^[ \t]*#\\+begin_docbook.*\n" "\n[ \t]*#\\+end_docbook" "xml") 450 ("^[ \t]*#\\+begin_docbook.*\n" "\n[ \t]*#\\+end_docbook" "xml")
364 ))) 451 )))
365 (pos (point)) 452 (pos (point))
366 re1 re2 single beg end lang lfmt match-re1 ind entry) 453 re1 re2 single beg end lang lfmt match-re1 ind entry)
367 (catch 'exit 454 (catch 'exit
416 (save-match-data 503 (save-match-data
417 (if (string-match "-l[ \t]+\\\\?\"\\([^\t\r\n\"]+\\)\\\\?\"" s) 504 (if (string-match "-l[ \t]+\\\\?\"\\([^\t\r\n\"]+\\)\\\\?\"" s)
418 (match-string 1 s)))) 505 (match-string 1 s))))
419 506
420 (defun org-edit-src-get-indentation (pos) 507 (defun org-edit-src-get-indentation (pos)
421 "Extract the label format." 508 "Count leading whitespace characters on line"
422 (save-match-data 509 (save-match-data
423 (goto-char pos) 510 (goto-char pos)
424 (org-get-indentation))) 511 (org-get-indentation)))
425 512
426 (defun org-edit-src-exit () 513 (defun org-edit-src-exit (&optional context)
427 "Exit special edit and protect problematic lines." 514 "Exit special edit and protect problematic lines."
428 (interactive) 515 (interactive)
429 (unless org-edit-src-from-org-mode 516 (unless org-edit-src-from-org-mode
430 (error "This is not a sub-editing buffer, something is wrong...")) 517 (error "This is not a sub-editing buffer, something is wrong..."))
431 (let ((beg org-edit-src-beg-marker) 518 (let* ((beg org-edit-src-beg-marker)
432 (end org-edit-src-end-marker) 519 (end org-edit-src-end-marker)
433 (ovl org-edit-src-overlay) 520 (ovl org-edit-src-overlay)
434 (buffer (current-buffer)) 521 (buffer (current-buffer))
435 (nindent org-edit-src-nindent) 522 (single (org-bound-and-true-p org-edit-src-force-single-line))
436 code line) 523 (macro (eq single 'macro-definition))
524 (total-nindent (+ (or org-edit-src-block-indentation 0)
525 org-edit-src-content-indentation))
526 (preserve-indentation org-src-preserve-indentation)
527 (delta 0) code line col indent)
437 (untabify (point-min) (point-max)) 528 (untabify (point-min) (point-max))
438 (save-excursion 529 (save-excursion
439 (goto-char (point-min)) 530 (goto-char (point-min))
440 (if (looking-at "[ \t\n]*\n") (replace-match "")) 531 (if (looking-at "[ \t\n]*\n") (replace-match ""))
441 (if (re-search-forward "\n[ \t\n]*\\'" nil t) (replace-match ""))) 532 (unless macro
533 (if (re-search-forward "\n[ \t\n]*\\'" nil t) (replace-match ""))))
442 (setq line (if (org-bound-and-true-p org-edit-src-force-single-line) 534 (setq line (if (org-bound-and-true-p org-edit-src-force-single-line)
443 1 535 1
444 (org-current-line))) 536 (org-current-line))
445 (when (org-bound-and-true-p org-edit-src-force-single-line) 537 col (current-column))
538 (when single
446 (goto-char (point-min)) 539 (goto-char (point-min))
447 (while (re-search-forward "\n" nil t) 540 (if (re-search-forward "\\s-+\\'" nil t) (replace-match ""))
448 (replace-match " "))
449 (goto-char (point-min)) 541 (goto-char (point-min))
450 (if (looking-at "\\s-*") (replace-match " ")) 542 (let ((cnt 0))
451 (if (re-search-forward "\\s-+\\'" nil t) 543 (while (re-search-forward "\n" nil t)
452 (replace-match ""))) 544 (setq cnt (1+ cnt))
545 (replace-match (if macro "\\n" " ") t t))
546 (when (and macro (> cnt 0))
547 (goto-char (point-max)) (insert "\\n")))
548 (goto-char (point-min))
549 (if (looking-at "\\s-*") (replace-match " ")))
453 (when (org-bound-and-true-p org-edit-src-from-org-mode) 550 (when (org-bound-and-true-p org-edit-src-from-org-mode)
454 (goto-char (point-min)) 551 (goto-char (point-min))
455 (while (re-search-forward 552 (while (re-search-forward
456 (if (org-mode-p) "^\\(.\\)" "^\\([*]\\|[ \t]*#\\+\\)") nil t) 553 (if (org-mode-p) "^\\(.\\)" "^\\([*]\\|[ \t]*#\\+\\)") nil t)
554 (if (eq (org-current-line) line) (setq delta (1+ delta)))
457 (replace-match ",\\1"))) 555 (replace-match ",\\1")))
458 (when (org-bound-and-true-p org-edit-src-picture) 556 (when (org-bound-and-true-p org-edit-src-picture)
557 (setq preserve-indentation nil)
459 (untabify (point-min) (point-max)) 558 (untabify (point-min) (point-max))
460 (goto-char (point-min)) 559 (goto-char (point-min))
461 (while (re-search-forward "^" nil t) 560 (while (re-search-forward "^" nil t)
462 (replace-match ": "))) 561 (replace-match ": ")))
463 (when nindent 562 (unless (or single preserve-indentation (= total-nindent 0))
464 (setq nindent (make-string (+ org-edit-src-content-indentation nindent) 563 (setq indent (make-string total-nindent ?\ ))
465 ?\ ))
466 (goto-char (point-min)) 564 (goto-char (point-min))
467 (while (re-search-forward "^" nil t) 565 (while (re-search-forward "^" nil t)
468 (replace-match nindent))) 566 (replace-match indent)))
567 (if (org-bound-and-true-p org-edit-src-picture)
568 (setq total-nindent (+ total-nindent 2)))
469 (setq code (buffer-string)) 569 (setq code (buffer-string))
470 (set-buffer-modified-p nil) 570 (set-buffer-modified-p nil)
471 (switch-to-buffer (marker-buffer beg)) 571 (org-src-switch-to-buffer (marker-buffer beg) (or context 'exit))
472 (kill-buffer buffer) 572 (kill-buffer buffer)
473 (goto-char beg) 573 (goto-char beg)
474 (delete-region beg end) 574 (delete-region beg end)
475 (insert code) 575 (insert code)
476 (goto-char beg) 576 (goto-char beg)
577 (if single (just-one-space))
477 (org-goto-line (1- (+ (org-current-line) line))) 578 (org-goto-line (1- (+ (org-current-line) line)))
579 (org-move-to-column (if preserve-indentation col (+ col total-nindent delta)))
478 (move-marker beg nil) 580 (move-marker beg nil)
479 (move-marker end nil))) 581 (move-marker end nil))
582 (unless (eq context 'save)
583 (when org-edit-src-saved-temp-window-config
584 (set-window-configuration org-edit-src-saved-temp-window-config)
585 (setq org-edit-src-saved-temp-window-config nil))))
480 586
481 (defun org-edit-src-save () 587 (defun org-edit-src-save ()
482 "Save parent buffer with current state source-code buffer." 588 "Save parent buffer with current state source-code buffer."
483 (interactive) 589 (interactive)
484 (save-window-excursion 590 (let ((p (point)) (m (mark)) msg)
485 (let ((p (point)) (m (mark)) msg) 591 (save-window-excursion
486 (org-edit-src-exit) 592 (org-edit-src-exit 'save)
487 (save-buffer) 593 (save-buffer)
488 (setq msg (current-message)) 594 (setq msg (current-message))
489 (org-edit-src-code) 595 (if (eq org-src-window-setup 'other-frame)
490 (push-mark m 'nomessage) 596 (let ((org-src-window-setup 'current-window))
491 (goto-char (min p (point-max))) 597 (org-edit-src-code 'save))
492 (message (or msg ""))))) 598 (org-edit-src-code 'save)))
599 (push-mark m 'nomessage)
600 (goto-char (min p (point-max)))
601 (message (or msg ""))))
493 602
494 (defun org-src-mode-configure-edit-buffer () 603 (defun org-src-mode-configure-edit-buffer ()
495 (when org-edit-src-from-org-mode 604 (when org-edit-src-from-org-mode
496 (setq buffer-offer-save t) 605 (setq buffer-offer-save t)
497 (setq buffer-file-name 606 (setq buffer-file-name