view lisp/dframe.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 a9dc0e7c3f2b
children 1d1d5d9bd884
line wrap: on
line source

;;; dframe --- dedicate frame support modes

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

;; Author: Eric M. Ludlam <zappo@gnu.org>
;; Keywords: file, tags, tools

(defvar dframe-version "1.3"
  "The current version of the dedicated frame library.")

;; 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:
;;
;; This code was developed and maintained as a part of speedbar since 1996.
;; It became its own support utility in Aug 2000.
;;
;; Dedicated frame mode is an Emacs independent library for supporting
;; a program/buffer combination that resides in a dedicated frame.
;; Support of this nature requires several complex interactions with the
;; user which this library will provide, including:
;;
;; * Creation of a frame.  Positioned relatively.
;;   Includes a frame cache for User position caching.
;; * Switching between frames.
;; * Timed activities using idle-timers
;; * Frame/buffer killing hooks
;; * Mouse-3 position relative menu
;; * Mouse motion, help-echo hacks
;; * Mouse clicking, double clicking, & XEmacs image clicking hack
;; * Mode line hacking
;; * Utilities for use in a program covering:
;;    o keymap massage for some actions
;;    o working with an associated buffer
;;    o shift-click
;;    o detaching a frame
;;    o focus-shifting & optional frame jumping
;;    o currently active frame.
;;    o message/y-or-n-p
;;    o mouse set point
;;
;; To Use:
;; 1) (require 'dframe)
;; 2) Variable Setup:
;;   -frame-parameters -- Frame parameters for Emacs.
;;   -frame-plist -- Frame parameters for XEmacs.
;;   -- Not on parameter lists: They can optionally include width
;;      and height.  If width or height is not included, then it will
;;      be provided to match the originating frame.  In general,
;;      turning off the menu bar, mode line, and minibuffer can
;;      provide a smaller window, or more display area.
;;   -track-mouse-flag -- mouse tracking on/off specific to your tool.
;;   -update-flag -- app toggle for timer use.  Init from
;;     `dframe-have-timer-flag'.  This is nil for terminals, since
;;     updating a frame in a terminal is not useful to the user.
;;   -key-map -- Your keymap.  Call `dframe-update-keymap' on it.
;;   -buffer, -frame, -cached-frame -- Variables used to track your
;;     applications buffer, frame, or frame cache (when hidden).  See
;;     `dframe-frame-mode' for details.
;;   -before-delete-hook, -before-popup-hook, -after-create-hook --
;;     Hooks to have called.  The `-after-create-hook' probably wants
;;     to call a function which calls `dframe-reposition-frame' in an
;;     appropriate manner.
;; 3) Function Setup:
;;   your-frame-mode -- function to toggle your app frame on and off.
;;     its tasks are:
;;       a) create a buffer
;;       b) Call `dframe-frame-mode'.  (See its doc)
;;       c) If successful (your -frame variable has a value), call
;;          timer setup if applicable.
;;   your-frame-reposition- -- Function to call from after-create-hook to
;;     reposition your frame with `dframe-repsoition-frame'.
;;   your-mode -- Set up the major mode of the buffer for your app.
;;     Set these variables: dframe-track-mouse-function,
;;                          dframe-help-echo-function,
;;                          dframe-mouse-click-function,
;;                          dframe-mouse-position-function.
;;   See speedbar's implementation of these functions.
;;    `speedbar-current-frame', `speedbar-get-focus', `speedbar-message',
;;    `speedbar-y-or-n-p', `speedbar-set-timer', `speedbar-click',
;;    `speedbar-position-cursor-on-line'
;; 4) Handling mouse clicks, and help text:
;;   dframe-track-mouse, dframe-help-echo-function --
;;    These variables need to be set to functions that display info
;;    based on the mouse's position.
;;   Text propert 'help-echo, set to `dframe-help-echo', which will
;;    call `dframe-help-echo-function'.
;;   Have a `-click' function, it can call `dframe-quick-mouse' for
;;    positioning.  If the variable `dframe-power-click' is non-nil,
;;    then `shift' was held down during the click.

;;; Bugs
;;
;;  * The timer managers doesn't handle multiple different timeouts.
;;  * You can't specify continuous timeouts (as opposed to just idle timers.)

(defvar x-pointer-hand2)
(defvar x-pointer-top-left-arrow)

;;; Code:

;;; Compatibility functions
;;
(defalias 'dframe-frame-parameter
  (if (fboundp 'frame-parameter) 'frame-parameter
    (lambda (frame parameter)
      "Return FRAME's PARAMETER value."
      (cdr (assoc parameter (frame-parameters frame))))))


;;; Variables
;;
(defgroup dframe nil
  "Faces used in dframe."
  :prefix "dframe-"
  :group 'dframe)

(defvar dframe-have-timer-flag (if (fboundp 'display-graphic-p)
				   (display-graphic-p)
				 window-system)
  "Non-nil means that timers are available for this Emacs.
This is nil for terminals, since updating a frame in a terminal
is not useful to the user.")

(defcustom dframe-update-speed
  (if (featurep 'xemacs) 2		; 1 is too obrusive in XEmacs
    1)
  "Idle time in seconds needed before dframe will update itself.
Updates occur to allow dframe to display directory information
relevant to the buffer you are currently editing."
  :group 'dframe
  :type 'integer)

(defcustom dframe-activity-change-focus-flag nil
  "Non-nil means the selected frame will change based on activity.
Thus, if a file is selected for edit, the buffer will appear in the
selected frame and the focus will change to that frame."
  :group 'dframe
  :type 'boolean)

(defcustom dframe-after-select-attached-frame-hook nil
  "Hook run after dframe has selected the attached frame."
  :group 'dframe
  :type 'hook)

(defvar dframe-track-mouse-function nil
  "*A function to call when the mouse is moved in the given frame.
Typically used to display info about the line under the mouse.")
(make-variable-buffer-local 'dframe-track-mouse-function)

(defvar dframe-help-echo-function nil
  "*A function to call when help-echo is used in newer versions of Emacs.
Typically used to display info about the line under the mouse.")
(make-variable-buffer-local 'dframe-help-echo-function)

(defvar dframe-mouse-click-function nil
  "*A function to call when the mouse is clicked.
Valid clicks are mouse 2, our double mouse 1.")
(make-variable-buffer-local 'dframe-mouse-click-function)

(defvar dframe-mouse-position-function nil
  "*A function to call to position the cursor for a mouse click.")
(make-variable-buffer-local 'dframe-mouse-position-function)

(defvar dframe-power-click nil
  "Never set this by hand.  Value is t when S-mouse activity occurs.")

(defvar dframe-timer nil
  "The dframe timer used for updating the buffer.")
(make-variable-buffer-local 'dframe-timer)

(defvar dframe-attached-frame nil
  "The frame which started a frame mode.
This is the frame from which all interesting activities will go
for the mode using dframe.")
(make-variable-buffer-local 'dframe-attached-frame)

(defvar dframe-controlled nil
  "Is this buffer controlled by a dedicated frame.
Local to those buffers, as a function called that created it.")
(make-variable-buffer-local 'dframe-controlled)

(defun dframe-update-keymap (map)
  "Update the keymap MAP for dframe default bindings."
  ;; Frame control
  (define-key map "q" 'dframe-close-frame)
  (define-key map "Q" 'delete-frame)

  ;; Override switch to buffer to never hack our frame.
  (substitute-key-definition 'switch-to-buffer
			     'dframe-switch-buffer-attached-frame
			     map global-map)

  (if (featurep 'xemacs)
      (progn
	;; mouse bindings so we can manipulate the items on each line
	(define-key map 'button2 'dframe-click)
	(define-key map '(shift button2) 'dframe-power-click)
	;; Info doc fix from Bob Weiner
	(if (featurep 'infodoc)
	    nil
	  (define-key map 'button3 'dframe-popup-kludge))
	)

    ;; mouse bindings so we can manipulate the items on each line
    ;; (define-key map [down-mouse-1] 'dframe-double-click)
    (define-key map [follow-link] 'mouse-face)
    (define-key map [mouse-2] 'dframe-click)
    ;; This is the power click for new frames, or refreshing a cache
    (define-key map [S-mouse-2] 'dframe-power-click)
    ;; This adds a small unecessary visual effect
    ;;(define-key map [down-mouse-2] 'dframe-quick-mouse)

    (define-key map [down-mouse-3] 'dframe-popup-kludge)

    ;; This lets the user scroll as if we had a scrollbar... well maybe not
    (define-key map [mode-line mouse-2] 'dframe-mouse-hscroll)
    ;; another handy place users might click to get our menu.
    (define-key map [mode-line down-mouse-1]
      'dframe-popup-kludge)

    ;; We can't switch buffers with the buffer mouse menu.  Lets hack it.
    (define-key map [C-down-mouse-1] 'dframe-hack-buffer-menu)

    ;; Lastly, we want to track the mouse.  Play here
    (define-key map [mouse-movement] 'dframe-track-mouse)
    ))

(defun dframe-live-p (frame)
  "Return non-nil if FRAME is currently available."
  (and frame (frame-live-p frame) (frame-visible-p frame)))

(defun dframe-frame-mode (arg frame-var cache-var buffer-var frame-name
			      local-mode-fn
			      &optional
			      parameters
			      delete-hook popup-hook create-hook
			      )
  "Manage a frame for an application, enabling it when ARG is positive.
FRAME-VAR is a variable used to cache the frame being used.
This frame is either resurrected, hidden, killed, etc based on
the value.
CACHE-VAR is a variable used to cache a cached frame.
BUFFER-VAR is a variable used to cache the buffer being used in dframe.
This buffer will have `dframe-frame-mode' run on it.
FRAME-NAME is the name of the frame to create.
LOCAL-MODE-FN is the function used to call this one.
PARAMETERS are frame parameters to apply to this dframe.
DELETE-HOOK are hooks to run when deleting a frame.
POPUP-HOOK are hooks to run before showing a frame.
CREATE-HOOK are hooks to run after creating a frame."
  ;; toggle frame on and off.
  (if (not arg) (if (dframe-live-p (symbol-value frame-var))
		    (setq arg -1) (setq arg 1)))
  ;; Make sure the current buffer is set.
  (set-buffer (symbol-value buffer-var))
  ;; turn the frame off on neg number
  (if (and (numberp arg) (< arg 0))
      (progn
	(run-hooks 'delete-hook)
	(if (and (symbol-value frame-var)
		 (frame-live-p (symbol-value frame-var)))
	    (progn
	      (set cache-var (symbol-value frame-var))
	      (make-frame-invisible (symbol-value frame-var))))
	(set frame-var nil))
    ;; Set this as our currently attached frame
    (setq dframe-attached-frame (selected-frame))
    (run-hooks 'popup-hook)
    ;; Updated the buffer passed in to contain all the hacks needed
    ;; to make it work well in a dedicated window.
    (with-current-buffer (symbol-value buffer-var)
      ;; Declare this buffer a dedicated frame
      (setq dframe-controlled local-mode-fn)

      (if (featurep 'xemacs)
	  (progn
	    ;; Hack the XEmacs mouse-motion handler
	    (set (make-local-variable 'mouse-motion-handler)
		 'dframe-track-mouse-xemacs)
	    ;; Hack the double click handler
	    (make-local-variable 'mouse-track-click-hook)
	    (add-hook 'mouse-track-click-hook
		      (lambda (event count)
			(if (/= (event-button event) 1)
			    nil		; Do normal operations.
			  (cond ((eq count 1)
				 (dframe-quick-mouse event))
				((or (eq count 2)
				     (eq count 3))
				 (dframe-click event)
				 (dframe-quick-mouse event)))
			  ;; Don't do normal operations.
			  t))))
	;; Enable mouse tracking in emacs
	(if dframe-track-mouse-function
	    (set (make-local-variable 'track-mouse) t))) ;this could be messy.
;;;;  DISABLED: This causes problems for users with multiple frames.
;;;;       ;; Set this up special just for the passed in buffer
;;;;       ;; Terminal minibuffer stuff does not require this.
;;;;       (if (and (or (assoc 'minibuffer parameters)
;;;; 		   ;; XEmacs plist is not an association list
;;;; 		   (member 'minibuffer parameters))
;;;; 	       window-system (not (eq window-system 'pc))
;;;; 	       (null default-minibuffer-frame))
;;;; 	  (progn
;;;; 	    (make-local-variable 'default-minibuffer-frame)
;;;; 	    (setq default-minibuffer-frame dframe-attached-frame))
;;;; 	)
      ;; Override `temp-buffer-show-hook' so that help and such
      ;; put their stuff into a frame other than our own.
      ;; Correct use of `temp-buffer-show-function': Bob Weiner
      (if (and (boundp 'temp-buffer-show-hook)
	       (boundp 'temp-buffer-show-function))
	  (progn (make-local-variable 'temp-buffer-show-hook)
		 (setq temp-buffer-show-hook temp-buffer-show-function)))
      (make-local-variable 'temp-buffer-show-function)
      (setq temp-buffer-show-function 'dframe-temp-buffer-show-function)
      ;; If this buffer is killed, we must make sure that we destroy
      ;; the frame the dedicated window is in.
      (add-hook 'kill-buffer-hook `(lambda ()
				     (let ((skilling (boundp 'skilling)))
				       (if skilling
					   nil
					 (if dframe-controlled
					     (progn
					       (funcall dframe-controlled -1)
					       (setq ,buffer-var nil)
					       )))))
		t t)
      )
    ;; Get the frame to work in
    (if (frame-live-p (symbol-value cache-var))
	(progn
	  (set frame-var (symbol-value cache-var))
	  (make-frame-visible (symbol-value frame-var))
	  (select-frame (symbol-value frame-var))
	  (set-window-dedicated-p (selected-window) nil)
	  (if (not (eq (current-buffer) (symbol-value buffer-var)))
	      (switch-to-buffer (symbol-value buffer-var)))
	  (set-window-dedicated-p (selected-window) t)
	  (raise-frame (symbol-value frame-var))
	  )
      (if (frame-live-p (symbol-value frame-var))
	  (raise-frame (symbol-value frame-var))
	(set frame-var
	      (if (featurep 'xemacs)
		  ;; Only guess height if it is not specified.
		  (if (member 'height parameters)
		      (make-frame parameters)
		    (make-frame (nconc (list 'height
					     (dframe-needed-height))
				       parameters)))
		(let* ((mh (dframe-frame-parameter dframe-attached-frame
						   'menu-bar-lines))
		       (paramsa
			;; Only add a guessed height if one is not specified
			;; in the input parameters.
			(if (assoc 'height parameters)
			    parameters
			  (append
			   parameters
			   (list (cons 'height (+ (or mh 0) (frame-height)))))))
		       (params
			;; Only add a guessed width if one is not specified
			;; in the input parameters.
			(if (assoc 'width parameters)
			    paramsa
			  (append
			   paramsa
			   (list (cons 'width (frame-width))))))
		       (frame
			(if (not (eq window-system 'x))
			    (make-frame params)
			  (let ((x-pointer-shape x-pointer-top-left-arrow)
				(x-sensitive-text-pointer-shape
				 x-pointer-hand2))
			    (make-frame params)))))
		  frame)))
	;; Put the buffer into the frame
	(save-excursion
	  (select-frame (symbol-value frame-var))
	  (switch-to-buffer (symbol-value buffer-var))
	  (set-window-dedicated-p (selected-window) t))
	;; Run hooks (like reposition)
	(run-hooks 'create-hook)
	;; Frame name
	(if (and (or (null window-system) (eq window-system 'pc))
		 (fboundp 'set-frame-name))
	    (save-window-excursion
	      (select-frame (symbol-value frame-var))
	      (set-frame-name frame-name)))
	;; On a terminal, raise the frame or the user will
	;; be confused.
	(if (not window-system)
	    (select-frame (symbol-value frame-var)))
	))) )

(defun dframe-reposition-frame (new-frame parent-frame location)
  "Move NEW-FRAME to be relative to PARENT-FRAME.
LOCATION can be one of 'random, 'left, 'right, 'left-right, or 'top-bottom."
  (if (featurep 'xemacs)
      (dframe-reposition-frame-xemacs new-frame parent-frame location)
    (dframe-reposition-frame-emacs new-frame parent-frame location)))

;; Not defined in builds without X, but behind window-system test.
(declare-function x-display-pixel-width "xfns.c" (&optional terminal))
(declare-function x-display-pixel-height "xfns.c" (&optional terminal))

(defun dframe-reposition-frame-emacs (new-frame parent-frame location)
  "Move NEW-FRAME to be relative to PARENT-FRAME.
LOCATION can be one of 'random, 'left-right, 'top-bottom, or
a cons cell indicating a position of the form (LEFT . TOP)."
  ;; Position dframe.
  ;; Do no positioning if not on a windowing system,
  (unless (or (not window-system) (eq window-system 'pc))
    (let* ((pfx (dframe-frame-parameter parent-frame 'left))
	   (pfy (dframe-frame-parameter parent-frame 'top))
	   (pfw (frame-pixel-width parent-frame))
	   (pfh (frame-pixel-height parent-frame))
	   (nfw (frame-pixel-width new-frame))
	   (nfh (frame-pixel-height new-frame))
	   newleft newtop)
      ;; Rebuild pfx,pfy to be absolute positions.
      (setq pfx (if (not (consp pfx))
		    pfx
		  ;; If pfx is a list, that means we grow
		  ;; from a specific edge of the display.
		  ;; Convert that to the distance from the
		  ;; left side of the display.
		  (if (eq (car pfx) '-)
		      ;; A - means distance from the right edge
		      ;; of the display, or DW - pfx - framewidth
		      (- (x-display-pixel-width) (car (cdr pfx)) pfw)
		    (car (cdr pfx))))
	    pfy (if (not (consp pfy))
		    pfy
		  ;; If pfy is a list, that means we grow
		  ;; from a specific edge of the display.
		  ;; Convert that to the distance from the
		  ;; left side of the display.
		  (if (eq (car pfy) '-)
		      ;; A - means distance from the right edge
		      ;; of the display, or DW - pfx - framewidth
		      (- (x-display-pixel-height) (car (cdr pfy)) pfh)
		    (car (cdr pfy)))))
      (cond ((eq location 'right)
	     (setq newleft (+ pfx pfw 5)
		   newtop pfy))
	    ((eq location 'left)
	     (setq newleft (- pfx 10 nfw)
		   newtop pfy))
	    ((eq location 'left-right)
	     (setq newleft
		   ;; Decide which side to put it on.  200 is just a
		   ;; buffer for the left edge of the screen.  The
		   ;; extra 10 is just dressings for window
		   ;; decorations.
		   (let* ((left-guess (- pfx 10 nfw))
			  (right-guess (+ pfx pfw 5))
			  (left-margin left-guess)
			  (right-margin (- (x-display-pixel-width)
					   right-guess 5 nfw)))
		     (cond ((>= left-margin 0) left-guess)
			   ((>= right-margin 0) right-guess)
			   ;; otherwise choose side we overlap less
			   ((> left-margin right-margin) 0)
			   (t (- (x-display-pixel-width) nfw 5))))
		   newtop pfy))
	    ((eq location 'top-bottom)
	     (setq newleft pfx
		   newtop
		   ;; Try and guess if we should be on the top or bottom.
		   (let* ((top-guess (- pfy 15 nfh))
			  (bottom-guess (+ pfy 5 pfh))
			  (top-margin top-guess)
			  (bottom-margin (- (x-display-pixel-height)
					    bottom-guess 5 nfh)))
		     (cond ((>= top-margin 0) top-guess)
			   ((>= bottom-margin 0) bottom-guess)
			   ;; Choose a side to overlap the least.
			   ((> top-margin bottom-margin) 0)
			   (t (- (x-display-pixel-height) nfh 5))))))
	    ((consp location)
	     (setq newleft (or (car location) 0)
		   newtop (or (cdr location) 0)))
	    (t nil))
      (modify-frame-parameters new-frame
			       (list (cons 'left newleft)
				     (cons 'top newtop))))))

(defun dframe-reposition-frame-xemacs (new-frame parent-frame location)
  "Move NEW-FRAME to be relative to PARENT-FRAME.
LOCATION can be one of 'random, 'left-right, or 'top-bottom."
  ;; Not yet implemented
  )

;; XEmacs function only.
(defun dframe-needed-height (&optional frame)
  "The needed height for the tool bar FRAME (in characters)."
  (or frame (setq frame (selected-frame)))
  ;; The 1 is the missing modeline/minibuffer
  (+ 1 (/ (frame-pixel-height frame)
	  ;; This obscure code avoids a byte compiler warning in Emacs.
	  (let ((f 'face-height))
	    (funcall f 'default frame)))))

(defun dframe-detach (frame-var cache-var buffer-var)
  "Detatch the frame in symbol FRAME-VAR.
CACHE-VAR and BUFFER-VAR are symbols as in `dframe-frame-mode'"
  (with-current-buffer (symbol-value buffer-var)
    (rename-buffer (buffer-name) t)
    (let ((oldframe (symbol-value frame-var)))
      (set buffer-var nil)
      (set frame-var nil)
      (set cache-var nil)
      ;; FIXME: Looks very suspicious.  Luckily this function is unused.
      (make-variable-buffer-local frame-var)
      (set frame-var oldframe)
      )))

;;; Special frame event proxies
;;
(if (boundp 'special-event-map)
    (progn
      (define-key special-event-map [make-frame-visible]
	'dframe-handle-make-frame-visible)
      (define-key special-event-map [iconify-frame]
	'dframe-handle-iconify-frame)
      (define-key special-event-map [delete-frame]
	'dframe-handle-delete-frame))
  )

(defvar dframe-make-frame-visible-function nil
  "Function used when a dframe controlled frame is de-iconified.
The function must take an EVENT.")
(defvar dframe-iconify-frame-function nil
  "Function used when a dframe controlled frame is iconified.
The function must take an EVENT.")
(defvar dframe-delete-frame-function nil
  "Function used when a frame attached to a dframe frame is deleted.
The function must take an EVENT.")

(defun dframe-handle-make-frame-visible (e)
  "Handle a `make-frame-visible' event.
Should enable auto-updating if the last state was also enabled.
Argument E is the event making the frame visible."
  (interactive "e")
  (let ((f last-event-frame))
    (if (and (dframe-attached-frame f)
	     dframe-make-frame-visible-function)
	(funcall dframe-make-frame-visible-function e)
      )))

(defun dframe-handle-iconify-frame (e)
  "Handle a `iconify-frame' event.
Should disable auto-updating if the last state was also enabled.
Argument E is the event iconifying the frame."
  (interactive "e")
  (let ((f last-event-frame))
    (if (and (dframe-attached-frame f)
	     dframe-iconify-frame-function e)
	(funcall dframe-iconify-frame-function)
      )))

(defun dframe-handle-delete-frame (e)
  "Handle `delete-frame' event.
Argument E is the event deleting the frame."
  (interactive "e")
  (let ((fl (frame-list))
	(sf (selected-frame)))
    ;; Loop over all frames.  If dframe-delete-frame-function is
    ;; non-nil, call it.
    (while fl
      (select-frame (car fl))
      (if dframe-delete-frame-function
	  (funcall dframe-delete-frame-function e))
      (setq fl (cdr fl)))
    (if (frame-live-p sf)
	(select-frame sf))
    (handle-delete-frame e)))


;;; Utilities
;;
(defun dframe-get-focus (frame-var activator &optional hook)
  "Change frame focus to or from a dedicated frame.
If the selected frame is not in the symbol FRAME-VAR, then FRAME-VAR
frame is selected.  If the FRAME-VAR is active, then select the
attached frame.  If FRAME-VAR is nil, ACTIVATOR is called to
created it.  HOOK is an optional argument of hooks to run when
selecting FRAME-VAR."
  (interactive)
  (if (eq (selected-frame) (symbol-value frame-var))
      (if (frame-live-p dframe-attached-frame)
	  (dframe-select-attached-frame))
    ;; make sure we have a frame
    (if (not (frame-live-p (symbol-value frame-var)))
	(funcall activator 1))
    ;; go there
    (select-frame (symbol-value frame-var))
    )
  (other-frame 0)
  ;; If updates are off, then refresh the frame (they want it now...)
  (run-hooks 'hook))


(defun dframe-close-frame ()
  "Close the current frame if it is dedicated."
  (interactive)
  (if dframe-controlled
      (let ((b (current-buffer)))
	(funcall dframe-controlled -1)
	(kill-buffer b))))

(defun dframe-current-frame (frame-var desired-major-mode)
  "Return the existing dedicated frame to use.
FRAME-VAR is the variable storing the currently active dedicated frame.
If the current frame's buffer uses DESIRED-MAJOR-MODE, then use that frame."
  (if (not (eq (selected-frame) (symbol-value frame-var)))
      (if (and (eq major-mode 'desired-major-mode)
	       (get-buffer-window (current-buffer))
	       (window-frame (get-buffer-window (current-buffer))))
	  (window-frame (get-buffer-window (current-buffer)))
	(symbol-value frame-var))
    (symbol-value frame-var)))

(defun dframe-attached-frame (&optional frame)
  "Return the attached frame belonging to the dframe controlled frame FRAME.
If optional arg FRAME is nil just return `dframe-attached-frame'."
  (save-excursion
    (if frame (select-frame frame))
    dframe-attached-frame))

(defun dframe-select-attached-frame (&optional frame)
  "Switch to the frame the dframe controlled frame FRAME was started from.
If optional arg FRAME is nil assume the attached frame is already selected
and just run the hooks `dframe-after-select-attached-frame-hook'.  Return
the attached frame."
  (let ((frame (dframe-attached-frame frame)))
    (if frame (select-frame frame))
    (prog1 frame
      (run-hooks 'dframe-after-select-attached-frame-hook))))

(defmacro dframe-with-attached-buffer (&rest forms)
  "Execute FORMS in the attached frame's special buffer.
Optionally select that frame if necessary."
  `(save-selected-window
     ;;(speedbar-set-timer speedbar-update-speed)
     (dframe-select-attached-frame)
     ,@forms
     (dframe-maybee-jump-to-attached-frame)))

(defun dframe-maybee-jump-to-attached-frame ()
  "Jump to the attached frame ONLY if this was not a mouse event."
  (when (or (not (dframe-mouse-event-p last-input-event))
            dframe-activity-change-focus-flag)
    (dframe-select-attached-frame)
    ;; KB: For what is this - raising the frame??
    (other-frame 0)))


(defvar dframe-suppress-message-flag nil
  "Non-nil means that `dframe-message' should just return a string.")

(defun dframe-message (fmt &rest args)
  "Like message, but for use in a dedicated frame.
Argument FMT is the format string, and ARGS are the arguments for message."
  (save-selected-window
    (if dframe-suppress-message-flag
	(apply 'format fmt args)
      (if dframe-attached-frame
          ;; KB: Here we do not need calling `dframe-select-attached-frame'
	  (select-frame dframe-attached-frame))
      (apply 'message fmt args))))

(defun dframe-y-or-n-p (prompt)
  "Like `y-or-n-p', but for use in a dedicated frame.
Argument PROMPT is the prompt to use."
  (save-selected-window
    (if (and ;;default-minibuffer-frame
	     dframe-attached-frame
	     ;;(not (eq default-minibuffer-frame dframe-attached-frame))
	     )
        ;; KB: Here we do not need calling `dframe-select-attached-frame'
	(select-frame dframe-attached-frame))
    (y-or-n-p prompt)))

;;; timer management
;;
;; Unlike speedbar with a dedicated set of routines, dframe has one master
;; timer, and all dframe users will use it.  At least until I figure out a way
;; around that problem.
;;
;; Advantage 1: Two apps with timer/frames can munge the master list
;;              to make sure they occur in order.
;; Advantage 2: If a user hits a key between timer functions, we can
;;	        interrupt them safely.
(defvar dframe-client-functions nil
  "List of client functions using the dframe timer.")

(defun dframe-set-timer (timeout fn &optional null-on-error)
  "Apply a timer with TIMEOUT, to call FN, or remove a timer if TIMEOUT is nil.
TIMEOUT is the number of seconds until the dframe controled program
timer is called again.  When TIMEOUT is nil, turn off all timeouts.
This function must be called from the buffer belonging to the program
who requested the timer.
If NULL-ON-ERROR is a symbol, set it to nil if we cannot create a timer."
  ;; First, fix up our list of client functions
  (if timeout
      (add-to-list 'dframe-client-functions fn)
    (setq dframe-client-functions (delete fn dframe-client-functions)))
  ;; Now decided what to do about the timout.
  (if (or
       ;; We have a timer, restart the timer with the new time.
       timeout
       ;; We have a timer, an off is requested, and no client
       ;; functions are left, shut er down.
       (and dframe-timer (not timeout) dframe-client-functions))
      ;; Only call the low level function if we are changing the state.
      (dframe-set-timer-internal timeout null-on-error)))

(defun dframe-set-timer-internal (timeout &optional null-on-error)
  "Apply a timer with TIMEOUT to call the dframe timer manager."
  (when dframe-timer
    (if (featurep 'xemacs)
	(delete-itimer dframe-timer)
      (cancel-timer dframe-timer))
    (setq dframe-timer nil))
  (when timeout
    (setq dframe-timer
	  (if (featurep 'xemacs)
	      (start-itimer "dframe" 'dframe-timer-fn
			    timeout timeout t)
	    (run-with-idle-timer timeout t 'dframe-timer-fn)))))

(defun dframe-timer-fn ()
  "Called due to the dframe timer.
Evaluates all cached timer functions in sequence."
  (let ((l dframe-client-functions))
    (while (and l (sit-for 0))
      (condition-case er
	  (funcall (car l))
	(error (message "DFRAME TIMER ERROR: %S" er)))
      (setq l (cdr l)))))

;;; Menu hacking for mouse-3
;;
(defconst dframe-pass-event-to-popup-mode-menu
  (let (max-args)
    (and (fboundp 'popup-mode-menu)
         (fboundp 'function-max-args)
         (setq max-args (function-max-args 'popup-mode-menu))
         (not (zerop max-args))))
  "The EVENT arg to `popup-mode-menu' was introduced in XEmacs 21.4.0.")

;; In XEmacs, we make popup menus work on the item over mouse (as
;; opposed to where the point happens to be.)  We attain this by
;; temporarily moving the point to that place.
;;    Hrvoje Niksic <hniksic@srce.hr>
(defalias 'dframe-popup-kludge
  (if (featurep 'xemacs)
      (lambda (event)                        ; XEmacs.
        "Pop up a menu related to the clicked on item.
Must be bound to EVENT."
        (interactive "e")
        (save-excursion
          (if dframe-pass-event-to-popup-mode-menu
              (popup-mode-menu event)
            (goto-char (event-closest-point event))
            (beginning-of-line)
            (forward-char (min 5 (- (save-excursion (end-of-line) (point))
                                    (save-excursion (beginning-of-line) (point)))))
            (popup-mode-menu))
          ;; Wait for menu to bail out.  `popup-mode-menu' (and other popup
          ;; menu functions) return immediately.
          (let (new)
            (while (not (misc-user-event-p (setq new (next-event))))
              (dispatch-event new))
            (dispatch-event new))))

    (lambda (e)                              ; Emacs.
      "Pop up a menu related to the clicked on item.
Must be bound to event E."
      (interactive "e")
      (save-excursion
        (mouse-set-point e)
        ;; This gets the cursor where the user can see it.
        (if (not (bolp)) (forward-char -1))
        (sit-for 0)
	(if (fboundp 'mouse-menu-major-mode-map)
	    (popup-menu (mouse-menu-major-mode-map) e)
	  (with-no-warnings	  ; don't warn about obsolete fallback
	    (mouse-major-mode-menu e nil)))))))

;;; Interactive user functions for the mouse
;;
(defalias 'dframe-mouse-event-p
  (if (featurep 'xemacs)
      'button-press-event-p
    (lambda (event)
      "Return t if the event is a mouse related event."
      (if (and (listp event)
               (member (event-basic-type event)
                       '(mouse-1 mouse-2 mouse-3)))
          t
        nil))))

(defun dframe-track-mouse (event)
  "For motion EVENT, display info about the current line."
  (interactive "e")
  (when (and dframe-track-mouse-function
	     (or (featurep 'xemacs) ;; XEmacs always safe?
		 (windowp (posn-window (event-end event))) ; Sometimes
					; there is no window to jump into.
		 ))

    (funcall dframe-track-mouse-function event)))

(defun dframe-track-mouse-xemacs (event)
  "For motion EVENT, display info about the current line."
  (if (functionp (default-value 'mouse-motion-handler))
      (funcall (default-value 'mouse-motion-handler) event))
  (if dframe-track-mouse-function
      (funcall dframe-track-mouse-function event)))

(defun dframe-help-echo (window &optional buffer position)
  "Display help based context.
The context is in WINDOW, viewing BUFFER, at POSITION.
BUFFER and POSITION are optional because XEmacs doesn't use them."
  (when (and (not dframe-track-mouse-function)
	     (bufferp buffer)
	     dframe-help-echo-function)
    (let ((dframe-suppress-message-flag t))
      (with-current-buffer buffer
	(save-excursion
	  (if position (goto-char position))
	  (funcall dframe-help-echo-function))))))

(defun dframe-mouse-set-point (e)
  "Set point based on event E.
Handles clicking on images in XEmacs."
  (if (and (featurep 'xemacs)
           (save-excursion
             (save-window-excursion
               (mouse-set-point e)
               (event-over-glyph-p e))))
      ;; We are in XEmacs, and clicked on a picture
      (let ((ext (event-glyph-extent e)))
	;; This position is back inside the extent where the
	;; junk we pushed into the property list lives.
	(if (extent-end-position ext)
	    (goto-char (1- (extent-end-position ext)))
	  (mouse-set-point e)))
    ;; We are not in XEmacs, OR we didn't click on a picture.
    (mouse-set-point e)))

(defun dframe-quick-mouse (e)
  "Since mouse events are strange, this will keep the mouse nicely positioned.
This should be bound to mouse event E."
  (interactive "e")
  (dframe-mouse-set-point e)
  (if dframe-mouse-position-function
      (funcall dframe-mouse-position-function)))

(defun dframe-power-click (e)
  "Activate any dframe mouse click as a power click.
A power click will dispose of cached data (if available) or bring a buffer
up into a different window.
This should be bound to mouse event E."
  (interactive "e")
  (let ((dframe-power-click t))
    (select-frame last-event-frame)
    (dframe-click e)))

(defun dframe-click (e)
  "Call our clients click function on a user click.
E is the event causing the click."
  (interactive "e")
  (dframe-mouse-set-point e)
  (when dframe-mouse-click-function
    ;; On the off chance of buffer switch, or something incorrectly
    ;; configured.
    (funcall dframe-mouse-click-function e)))

(defun dframe-double-click (e)
  "Activate the registered click function on a double click.
This must be bound to a mouse event.
This should be bound to mouse event E."
  (interactive "e")
  ;; Emacs only.  XEmacs handles this via `mouse-track-click-hook'.
  (cond ((eq (car e) 'down-mouse-1)
	 (dframe-mouse-set-point e))
	((eq (car e) 'mouse-1)
	 (dframe-quick-mouse e))
	((or (eq (car e) 'double-down-mouse-1)
	     (eq (car e) 'triple-down-mouse-1))
	 (dframe-click e))))

;;; Hacks of normal things.
;;
;; Some normal things that happen in one of these dedicated frames
;; must be handled specially, so that our dedicated frame isn't
;; messed up.
(defun dframe-temp-buffer-show-function (buffer)
  "Placed in the variable `temp-buffer-show-function' in dedicated frames.
If a user requests help using \\[help-command] <Key> the temp BUFFER will be
redirected into a window on the attached frame."
  (if dframe-attached-frame (dframe-select-attached-frame))
  (pop-to-buffer buffer nil)
  (other-window -1)
  ;; Fix for using this hook on some platforms: Bob Weiner
  (cond ((not (featurep 'xemacs))
	 (run-hooks 'temp-buffer-show-hook))
	((fboundp 'run-hook-with-args)
	 (run-hook-with-args 'temp-buffer-show-hook buffer))
	((and (boundp 'temp-buffer-show-hook)
	      (listp temp-buffer-show-hook))
	 (mapcar (function (lambda (hook) (funcall hook buffer)))
		 temp-buffer-show-hook))))

(defun dframe-hack-buffer-menu (e)
  "Control mouse 1 is buffer menu.
This hack overrides it so that the right thing happens in the main
Emacs frame, not in the dedicated frame.
Argument E is the event causing this activity."
  (interactive "e")
  (let ((fn (lookup-key global-map (if (featurep 'xemacs)
                                       '(control button1)
				     [C-down-mouse-1])))
	(oldbuff (current-buffer))
	(newbuff nil))
    (unwind-protect
	(save-excursion
	  (set-window-dedicated-p (selected-window) nil)
	  (call-interactively fn)
	  (setq newbuff (current-buffer)))
      (switch-to-buffer oldbuff)
      (set-window-dedicated-p (selected-window) t))
    (if (not (eq newbuff oldbuff))
	(dframe-with-attached-buffer
	 (switch-to-buffer newbuff)))))

(defun dframe-switch-buffer-attached-frame (&optional buffer)
  "Switch to BUFFER in the attached frame, and raise that frame.
This overrides the default behavior of `switch-to-buffer' which is
broken because of the dedicated frame."
  (interactive)
  ;; Assume we are in the dedicated frame.
  (other-frame 1)
  ;; Now switch buffers
  (if buffer
      (switch-to-buffer buffer)
    (call-interactively 'switch-to-buffer nil nil)))

;; XEmacs: this can be implemented using modeline keymaps, but there
;; is no use, as we have horizontal scrollbar (as the docstring
;; hints.)
(defun dframe-mouse-hscroll (e)
  "Read a mouse event E from the mode line, and horizontally scroll.
If the mouse is being clicked on the far left, or far right of the
mode-line.  This is only useful for non-XEmacs."
  (interactive "e")
  (let* ((x-point (car (nth 2 (car (cdr e)))))
	 (pixels-per-10-col (/ (* 10 (frame-pixel-width))
			       (frame-width)))
	 (click-col (1+ (/ (* 10 x-point) pixels-per-10-col)))
	 )
    (cond ((< click-col 3)
	   (scroll-left 2))
	  ((> click-col (- (window-width) 5))
	   (scroll-right 2))
	  (t (dframe-message
	      "Click on the edge of the modeline to scroll left/right")))
    ))

(provide 'dframe)

;; arch-tag: df9b91b6-e85e-4a76-a02e-b3cb5b686bd4
;;; dframe.el ends here