1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-12-03 08:30:03 +00:00
org-mode/lisp/org-mouse.el

1109 lines
38 KiB
EmacsLisp
Raw Normal View History

;;; org-mouse.el --- Better mouse support for Org -*- lexical-binding: t; -*-
2008-01-31 10:32:52 +00:00
;; Copyright (C) 2006-2024 Free Software Foundation, Inc.
2008-01-31 10:32:52 +00:00
;; Author: Piotr Zielinski <piotr dot zielinski at gmail dot com>
;; Maintainer: Carsten Dominik <carsten.dominik@gmail.com>
2008-01-31 10:36:18 +00:00
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
2008-01-31 10:36:18 +00:00
;; 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.
2008-01-31 10:32:52 +00:00
2008-01-31 10:36:18 +00:00
;; 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.
2008-01-31 10:32:52 +00:00
2008-01-31 10:36:18 +00:00
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
2008-01-31 10:32:52 +00:00
;;; Commentary:
;;
2008-01-31 10:36:18 +00:00
;; Org-mouse provides mouse support for org-mode.
2008-01-31 10:32:52 +00:00
;;
;; https://orgmode.org
2008-01-31 10:32:52 +00:00
;;
;; Org mouse implements the following features:
;; * following links with the left mouse button
2008-01-31 10:32:52 +00:00
;; * subtree expansion/collapse (org-cycle) with the left mouse button
;; * several context menus on the right mouse button:
;; + general text
;; + headlines
;; + timestamps
;; + priorities
;; + links
;; + tags
;; * promoting/demoting/moving subtrees with mouse-3
;; + if the drag starts and ends in the same line then promote/demote
2008-04-24 08:29:47 +00:00
;; + otherwise move the subtree
2008-01-31 10:32:52 +00:00
;;
;; Use
2008-01-31 10:36:18 +00:00
;; ---
2008-01-31 10:32:52 +00:00
;;
;; To use this package, put the following line in your .emacs:
;;
;; (require 'org-mouse)
;;
2008-12-16 16:25:37 +00:00
;; FIXME:
2008-01-31 10:32:52 +00:00
;; + deal with folding / unfolding issues
;; TODO (This list is only theoretical, if you'd like to have some
;; feature implemented or a bug fix please send me an email, even if
;; something similar appears in the list below. This will help me get
;; the priorities right.):
2008-01-31 10:33:13 +00:00
;;
2008-01-31 10:32:52 +00:00
;; + org-store-link, insert link
;; + org tables
;; + occur with the current word/tag (same menu item)
;; + ctrl-c ctrl-c, for example, renumber the current list
;; + internal links
2008-01-31 10:36:18 +00:00
;; Please email the maintainer with new feature suggestions / bugs
2008-01-31 10:32:52 +00:00
;; History:
;;
;; Since version 5.10: Changes are listed in the general Org docs.
2008-01-31 10:36:18 +00:00
;;
;; Version 5.09;; + Version number synchronization with Org mode.
2008-01-31 10:36:18 +00:00
;;
;; Version 0.25
;; + made compatible with Org 4.70 (thanks to Carsten for the patch)
2008-01-31 10:36:18 +00:00
;;
2008-01-31 10:33:55 +00:00
;; Version 0.24
;; + minor changes to the table menu
;;
2008-01-31 10:33:46 +00:00
;; Version 0.23
;; + preliminary support for tables and calculation marks
;; + context menu support for org-agenda-undo & org-sort-entries
;;
;; Version 0.22
;; + handles undo support for the agenda buffer (requires Org >=4.58)
2008-01-31 10:33:46 +00:00
;;
2008-01-31 10:33:13 +00:00
;; Version 0.21
;; + selected text activates its context menu
;; + shift-middleclick or right-drag inserts the text from the clipboard in the form of a link
;;
;; Version 0.20
2008-04-24 08:29:47 +00:00
;; + the new "TODO Status" submenu replaces the "Cycle TODO" menu item
2008-01-31 10:33:13 +00:00
;; + the TODO menu can now list occurrences of a specific TODO keyword
;; + #+STARTUP line is now recognized
;;
2008-01-31 10:32:52 +00:00
;; Version 0.19
;; + added support for dragging URLs to the org-buffer
;;
;; Version 0.18
;; + added support for agenda blocks
;;
;; Version 0.17
;; + toggle checkboxes with a single click
;;
;; Version 0.16
;; + added support for checkboxes
;;
;; Version 0.15
;; + Org now works with the Agenda buffer as well
2008-01-31 10:32:52 +00:00
;;
;; Version 0.14
;; + added a menu option that converts plain list items to outline items
;;
2008-04-24 08:29:47 +00:00
;; Version 0.13
2008-01-31 10:32:52 +00:00
;; + "Insert Heading" now inserts a sibling heading if the point is
;; on "***" and a child heading otherwise
2008-04-24 08:29:47 +00:00
;;
2008-01-31 10:32:52 +00:00
;; Version 0.12
;; + compatible with Emacs 21
;; + custom agenda commands added to the main menu
;; + moving trees should now work between windows in the same frame
;;
;; Version 0.11
;; + fixed org-mouse-at-link (thanks to Carsten)
;; + removed [follow-link] bindings
;;
;; Version 0.10
;; + added a menu option to remove highlights
;; + compatible with Org 4.21 now
2008-01-31 10:32:52 +00:00
;;
2008-04-24 08:29:47 +00:00
;; Version 0.08:
2008-01-31 10:32:52 +00:00
;; + trees can be moved/promoted/demoted by dragging with the right
;; mouse button (mouse-3)
;; + small changes in the above function
;;
;; Versions 0.01 -- 0.07: (I don't remember)
;;; Code:
(require 'org-macs)
(org-assert-version)
2008-01-31 10:36:18 +00:00
(require 'org)
2016-07-25 13:46:09 +00:00
(require 'cl-lib)
2008-01-31 10:32:52 +00:00
(defvar org-agenda-allow-remote-undo)
(defvar org-agenda-undo-list)
(defvar org-agenda-custom-commands)
(declare-function org-agenda-change-all-lines "org-agenda"
2008-11-24 11:21:40 +00:00
(newhead hdmarker &optional fixface just-this))
(declare-function org-verify-change-for-undo "org-agenda" (l1 l2))
(declare-function org-apply-on-list "org-list" (function init-value &rest args))
(declare-function org-agenda-earlier "org-agenda" (arg))
(declare-function org-agenda-later "org-agenda" (arg))
(defvar org-mouse-main-buffer nil
"Active buffer for mouse operations.")
2008-01-31 10:36:18 +00:00
(defvar org-mouse-plain-list-regexp "\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) "
"Regular expression that matches a plain list.")
(defvar org-mouse-direct t
"Internal variable indicating whether the current action is direct.
If t, then the current action has been invoked directly through the buffer
it is intended to operate on. If nil, then the action has been invoked
indirectly, for example, through the agenda buffer.")
2008-01-31 10:32:52 +00:00
(defgroup org-mouse nil
"Mouse support for `org-mode'."
2008-01-31 10:36:18 +00:00
:tag "Org Mouse"
2008-01-31 10:32:52 +00:00
:group 'org)
(defcustom org-mouse-punctuation ":"
2008-01-31 10:36:18 +00:00
"Punctuation used when inserting text by drag and drop."
2008-01-31 10:32:52 +00:00
:type 'string)
(defcustom org-mouse-features
'(context-menu yank-link activate-stars activate-bullets activate-checkboxes)
"The features of org-mouse that should be activated.
Changing this variable requires a restart of Emacs to get activated."
:type '(set :greedy t
(const :tag "Mouse-3 shows context menu" context-menu)
(const :tag "C-mouse-1 and mouse-3 move trees" move-tree)
(const :tag "S-mouse-2 and drag-mouse-3 yank link" yank-link)
(const :tag "Activate headline stars" activate-stars)
(const :tag "Activate item bullets" activate-bullets)
2008-12-04 14:33:43 +00:00
(const :tag "Activate checkboxes" activate-checkboxes)))
2008-01-31 10:32:52 +00:00
(defun org-mouse-re-search-line (regexp)
2008-01-31 10:36:18 +00:00
"Search the current line for a given regular expression."
2008-01-31 10:32:52 +00:00
(beginning-of-line)
(re-search-forward regexp (line-end-position) t))
2008-01-31 10:32:52 +00:00
(defun org-mouse-end-headline ()
"Go to the end of current headline (ignoring tags)."
(interactive)
(end-of-line)
(skip-chars-backward "\t ")
(when (looking-back ":[A-Za-z]+:" (line-beginning-position))
2008-01-31 10:32:52 +00:00
(skip-chars-backward ":A-Za-z")
(skip-chars-backward "\t ")))
(defvar-local org-mouse-context-menu-function nil
2008-01-31 10:36:18 +00:00
"Function to create the context menu.
The value of this variable is the function invoked by
`org-mouse-context-menu' as the context menu.")
2008-01-31 10:33:13 +00:00
2008-01-31 10:32:52 +00:00
(defun org-mouse-show-context-menu (event prefix)
2008-01-31 10:36:18 +00:00
"Invoke the context menu.
If the value of `org-mouse-context-menu-function' is a function, then
2008-04-24 08:29:47 +00:00
this function is called. Otherwise, the current major mode menu is used."
2008-01-31 10:32:52 +00:00
(interactive "@e \nP")
(if (and (= (event-click-count event) 1)
2008-04-24 08:29:47 +00:00
(or (not mark-active)
(sit-for
(/ (if (fboundp 'mouse-double-click-time) ; Emacs >= 29
(mouse-double-click-time)
double-click-time)
1000.0))))
2008-01-31 10:32:52 +00:00
(progn
2008-12-16 16:24:04 +00:00
(select-window (posn-window (event-start event)))
2008-01-31 10:33:13 +00:00
(when (not (org-mouse-mark-active))
(goto-char (posn-point (event-start event)))
(when (not (eolp)) (save-excursion (run-hooks 'post-command-hook)))
(sit-for 0))
2008-01-31 10:32:52 +00:00
(if (functionp org-mouse-context-menu-function)
2008-01-31 10:33:13 +00:00
(funcall org-mouse-context-menu-function event)
(popup-menu (mouse-menu-major-mode-map) event prefix)))
2008-01-31 10:32:52 +00:00
(setq this-command 'mouse-save-then-kill)
(mouse-save-then-kill event)))
(defun org-mouse-line-position ()
"Return `:beginning' or `:middle' or `:end', depending on the point position.
2008-01-31 10:36:18 +00:00
If the point is at the end of the line, return `:end'.
If the point is separated from the beginning of the line only by white
space and *'s (`org-mouse-bolp'), return `:beginning'. Otherwise,
return `:middle'."
2008-01-31 10:32:52 +00:00
(cond
((eolp) :end)
2008-01-31 10:36:18 +00:00
((org-mouse-bolp) :beginning)
2008-01-31 10:32:52 +00:00
(t :middle)))
(defun org-mouse-empty-line ()
"Return non-nil if the line contains only white space."
2008-01-31 10:32:52 +00:00
(save-excursion (beginning-of-line) (looking-at "[ \t]*$")))
(defun org-mouse-next-heading ()
2008-01-31 10:36:18 +00:00
"Go to the next heading.
If there is none, ensure that the point is at the beginning of an empty line."
2008-01-31 10:32:52 +00:00
(unless (outline-next-heading)
(beginning-of-line)
(unless (org-mouse-empty-line)
(end-of-line)
(newline))))
(defun org-mouse-insert-heading ()
2008-01-31 10:36:18 +00:00
"Insert a new heading, as `org-insert-heading'.
If the point is at the :beginning (`org-mouse-line-position') of the line,
insert the new heading before the current line. Otherwise, insert it
after the current heading."
2008-01-31 10:32:52 +00:00
(interactive)
(cl-case (org-mouse-line-position)
2008-01-31 10:36:18 +00:00
(:beginning (beginning-of-line)
(org-insert-heading))
2008-01-31 10:32:52 +00:00
(t (org-mouse-next-heading)
(org-insert-heading))))
2008-04-24 08:29:47 +00:00
(defun org-mouse-timestamp-today (&optional shift units)
"Change the timestamp into SHIFT UNITS in the future.
2008-01-31 10:36:18 +00:00
For the acceptable UNITS, see `org-timestamp-change'."
2008-01-31 10:32:52 +00:00
(interactive)
(org-time-stamp nil)
(when shift (org-timestamp-change shift units)))
2008-01-31 10:32:52 +00:00
(defun org-mouse-keyword-menu (keywords function &optional selected itemformat)
2008-01-31 10:36:18 +00:00
"A helper function.
Returns a menu fragment consisting of KEYWORDS. When a keyword
is selected by the user, FUNCTION is called with the selected
keyword as the only argument.
If SELECTED is nil, then all items are normal menu items. If
SELECTED is a function, then each item is a checkbox, which is
enabled for a given keyword if (funcall SELECTED keyword) return
2008-01-31 10:36:18 +00:00
non-nil. If SELECTED is neither nil nor a function, then the
items are radio buttons. A radio button is enabled for the
2008-04-24 08:29:47 +00:00
keyword `equal' to SELECTED.
2008-01-31 10:36:18 +00:00
ITEMFORMAT governs formatting of the elements of KEYWORDS. If it
is a function, it is invoked with the keyword as the only
argument. If it is a string, it is interpreted as the format
string to (format ITEMFORMAT keyword). If it is neither a string
nor a function, elements of KEYWORDS are used directly."
2008-04-24 08:29:47 +00:00
(mapcar
(lambda (keyword)
2021-09-29 07:22:47 +00:00
(vector (cond
((functionp itemformat) (funcall itemformat keyword))
((stringp itemformat) (format itemformat keyword))
(t keyword))
`(funcall #',function ,keyword)
2021-09-29 07:22:47 +00:00
:style (cond
((null selected) t)
((functionp selected) 'toggle)
(t 'radio))
:selected (if (functionp selected)
(and (funcall selected keyword) t)
(equal selected keyword))))
keywords))
2008-04-24 08:29:47 +00:00
2008-01-31 10:32:52 +00:00
(defun org-mouse-remove-match-and-spaces ()
2008-01-31 10:36:18 +00:00
"Remove the match, make just one space around the point."
2008-01-31 10:32:52 +00:00
(interactive)
(replace-match "")
2008-01-31 10:33:13 +00:00
(just-one-space))
(defvar org-mouse-rest)
(defun org-mouse-replace-match-and-surround
(_newtext &optional _fixedcase _literal _string subexp)
2008-01-31 10:36:18 +00:00
"The same as `replace-match', but surrounds the replacement with spaces."
(apply #'replace-match org-mouse-rest)
2008-01-31 10:33:13 +00:00
(save-excursion
2008-04-24 08:29:47 +00:00
(goto-char (match-beginning (or subexp 0)))
2008-01-31 10:33:13 +00:00
(just-one-space)
2008-04-24 08:29:47 +00:00
(goto-char (match-end (or subexp 0)))
2008-01-31 10:33:13 +00:00
(just-one-space)))
2008-04-24 08:29:47 +00:00
2008-01-31 10:33:46 +00:00
(defun org-mouse-keyword-replace-menu (keywords &optional group itemformat
nosurround)
2008-01-31 10:36:18 +00:00
"A helper function.
Returns a menu fragment consisting of KEYWORDS. When a keyword
is selected, group GROUP of the current match is replaced by the
keyword. The method ensures that both ends of the replacement
are separated from the rest of the text in the buffer by
2008-12-16 16:25:37 +00:00
individual spaces (unless NOSURROUND is non-nil).
2008-01-31 10:36:18 +00:00
The final entry of the menu is always \"None\", which removes the
match.
ITEMFORMAT governs formatting of the elements of KEYWORDS. If it
is a function, it is invoked with the keyword as the only
argument. If it is a string, it is interpreted as the format
string to (format ITEMFORMAT keyword). If it is neither a string
nor a function, elements of KEYWORDS are used directly."
2008-01-31 10:32:52 +00:00
(setq group (or group 0))
2008-04-24 08:29:47 +00:00
(let ((replace (org-mouse-match-closure
(if nosurround #'replace-match
#'org-mouse-replace-match-and-surround))))
2008-01-31 10:33:13 +00:00
(append
2008-04-24 08:29:47 +00:00
(org-mouse-keyword-menu
2008-01-31 10:33:13 +00:00
keywords
(lambda (keyword) (funcall replace keyword t t nil group))
2008-01-31 10:33:13 +00:00
(match-string group)
itemformat)
2008-04-24 08:29:47 +00:00
`(["None" org-mouse-remove-match-and-spaces
2008-01-31 10:33:13 +00:00
:style radio
:selected ,(not (member (match-string group) keywords))]))))
2008-04-24 08:29:47 +00:00
2008-01-31 10:32:52 +00:00
(defun org-mouse-show-headlines ()
2008-01-31 10:36:18 +00:00
"Change the visibility of the current org buffer to only show headlines."
2008-04-24 08:29:47 +00:00
(interactive)
(let ((this-command 'org-cycle)
2008-01-31 10:32:52 +00:00
(last-command 'org-cycle)
(org-cycle-global-status nil))
(org-cycle '(4))
(org-cycle '(4))))
(defun org-mouse-show-overview ()
2008-01-31 10:36:18 +00:00
"Change visibility of current org buffer to first-level headlines only."
2008-04-24 08:29:47 +00:00
(interactive)
2008-01-31 10:32:52 +00:00
(let ((org-cycle-global-status nil))
(org-cycle '(4))))
(defun org-mouse-set-priority (priority)
2008-01-31 10:36:18 +00:00
"Set the priority of the current headline to PRIORITY."
(org-priority priority))
2008-01-31 10:32:52 +00:00
(defvar org-mouse-priority-regexp "\\[#\\([A-Z]\\)\\]"
2008-01-31 10:36:18 +00:00
"Regular expression matching the priority indicator.
Differs from `org-priority-regexp' in that it doesn't contain the
leading `.*?'.")
2008-01-31 10:32:52 +00:00
(defun org-mouse-get-priority (&optional default)
2008-01-31 10:36:18 +00:00
"Return the priority of the current headline.
DEFAULT is returned if no priority is given in the headline."
2008-04-24 08:29:47 +00:00
(save-excursion
2008-01-31 10:32:52 +00:00
(if (org-mouse-re-search-line org-mouse-priority-regexp)
(match-string 1)
(when default (char-to-string org-priority-default)))))
2008-01-31 10:32:52 +00:00
(defun org-mouse-delete-timestamp ()
2008-01-31 10:36:18 +00:00
"Deletes the current timestamp as well as the preceding keyword.
2008-01-31 10:32:52 +00:00
SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
(when (or (org-at-date-range-p) (org-at-timestamp-p 'lax))
(replace-match "") ;delete the timestamp
2008-01-31 10:32:52 +00:00
(skip-chars-backward " :A-Z")
(when (looking-at " *[A-Z][A-Z]+:")
(replace-match ""))))
2008-04-24 08:29:47 +00:00
(defun org-mouse-looking-at (regexp skipchars &optional movechars)
2008-01-31 10:32:52 +00:00
(save-excursion
(let ((point (point)))
(if (looking-at regexp) t
(skip-chars-backward skipchars)
(forward-char (or movechars 0))
(when (looking-at regexp)
(> (match-end 0) point))))))
2008-04-24 08:29:47 +00:00
2008-01-31 10:32:52 +00:00
(defun org-mouse-priority-list ()
(cl-loop for priority from ?A to org-priority-lowest
collect (char-to-string priority)))
2008-01-31 10:32:52 +00:00
(defun org-mouse-todo-menu (state)
"Create the menu with TODO keywords."
(append
(let ((kwds org-todo-keywords-1))
(org-mouse-keyword-menu
kwds
#'org-todo
(lambda (kwd) (equal state kwd))))))
2008-01-31 10:32:52 +00:00
(defun org-mouse-tag-menu () ;todo
"Create the tags menu."
2008-01-31 10:32:52 +00:00
(append
(let ((tags (org-get-tags nil t)))
2008-04-24 08:29:47 +00:00
(org-mouse-keyword-menu
(sort (mapcar #'car (org-get-buffer-tags)) #'string-lessp)
(lambda (tag)
2021-09-29 07:22:47 +00:00
(org-mouse-set-tags
(sort (if (member tag tags)
(delete tag tags)
(cons tag tags))
#'string-lessp)))
(lambda (tag) (member tag tags))
2008-01-31 10:32:52 +00:00
))
'("--"
["Align Tags Here" (org-align-tags) t]
["Align Tags in Buffer" (org-align-tags t) t]
["Set Tags ..." (org-set-tags-command) t])))
2008-04-24 08:29:47 +00:00
2008-01-31 10:32:52 +00:00
(defun org-mouse-set-tags (tags)
(org-set-tags tags))
2008-04-24 08:29:47 +00:00
2008-01-31 10:32:52 +00:00
(defun org-mouse-insert-checkbox ()
(interactive)
(and (org-at-item-p)
(goto-char (match-end 0))
(unless (org-at-item-checkbox-p)
(delete-horizontal-space)
(insert " [ ] "))))
(defun org-mouse-agenda-type (type)
(pcase type
(`tags "Tags: ")
(`todo "TODO: ")
(`tags-tree "Tags tree: ")
(`todo-tree "TODO tree: ")
(`occur-tree "Occur tree: ")
(_ "Agenda command ???")))
2008-01-31 10:32:52 +00:00
2008-01-31 10:33:13 +00:00
(defun org-mouse-list-options-menu (alloptions &optional function)
2008-04-24 08:29:47 +00:00
(let ((options (save-match-data
2008-01-31 10:33:13 +00:00
(split-string (match-string-no-properties 1)))))
(print options)
(cl-loop for name in alloptions
collect
(vector name
`(progn
(replace-match
(mapconcat 'identity
(sort (if (member ',name ',options)
(delete ',name ',options)
(cons ',name ',options))
'string-lessp)
" ")
nil nil nil 1)
(when (functionp ',function) (funcall ',function)))
:style 'toggle
:selected (and (member name options) t)))))
2008-01-31 10:33:13 +00:00
2008-01-31 10:32:52 +00:00
(defun org-mouse-clip-text (text maxlength)
(if (> (length text) maxlength)
(concat (substring text 0 (- maxlength 3)) "...")
text))
(defun org-mouse-popup-global-menu ()
2008-04-24 08:29:47 +00:00
(popup-menu
2008-01-31 10:32:52 +00:00
`("Main Menu"
["Show Overview" org-mouse-show-overview t]
["Show Headlines" org-mouse-show-headlines t]
["Show All" org-show-all t]
2008-01-31 10:32:52 +00:00
["Remove Highlights" org-remove-occur-highlights
:visible org-occur-highlights]
"--"
2008-04-24 08:29:47 +00:00
["Check Deadlines"
2008-01-31 10:32:52 +00:00
(if (functionp 'org-check-deadlines-and-todos)
(org-check-deadlines-and-todos org-deadline-warning-days)
Tiny formatting fixes * lisp/ox.el (org-export-table-dimensions): * lisp/ox-texinfo.el (org-texinfo-template): * lisp/ox-md.el (org-md-link): * lisp/ox-icalendar.el (org-icalendar-use-UTC-date-time-p): * lisp/ox-ascii.el (org-ascii-fixed-width): * lisp/org.el (org-context): * lisp/org-table.el (org-table-eval-formula) (org-table-export): * lisp/org-refile.el: * lisp/org-plot.el (org-plot/gnuplot-to-grid-data): * lisp/org-num.el (org-num): * lisp/org-mouse.el (org-mouse-popup-global-menu) (org-mouse-context-menu): * lisp/org-macro.el (org-macro): * lisp/org-lint.el (org-lint): * lisp/org-keys.el (org-keys): * lisp/org-duration.el: * lisp/org-clock.el (org-clock-get-last-clock-out-time) (org-clock-update-mode-line, org-find-open-clocks): * lisp/org-agenda.el (org-diary) (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item) (org-agenda-highlight-todo, org-cmp-alpha) (org-agenda-filter-by-category): * lisp/ol.el (org-link-expand-abbrev, ol): * lisp/ol-docview.el (ol-docview): * lisp/ol-bibtex.el (org-execute-file-search-in-bibtex) (org-bibtex, org-bibtex-read): * lisp/ol-bbdb.el (org-bbdb-anniversary-description): * lisp/ob-tangle.el (org-babel-tangle-jump-to-org): * lisp/ob-table.el (org-babel-table-truncate-at-newline): * lisp/ob-stan.el: * lisp/ob-sqlite.el (org-babel-sqlite-table-or-scalar): * lisp/ob-sql.el: * lisp/ob-shen.el: * lisp/ob-shell.el (org-babel-prep-session:shell) (org-babel-prep-session:shell): * lisp/ob-sed.el (org-babel-execute:sed) (org-babel-execute:sed): * lisp/ob-screen.el: * lisp/ob-sass.el: * lisp/ob-ruby.el (org-babel-prep-session:ruby) (org-babel-prep-session:ruby): * lisp/ob-ref.el (org-babel-ref-resolve, ob-ref): * lisp/ob-python.el (org-babel-prep-session:python) (org-babel-prep-session:python): * lisp/ob-plantuml.el: * lisp/ob-picolisp.el: * lisp/ob-perl.el: * lisp/ob-org.el: * lisp/ob-octave.el (org-babel-prep-session:octave) (org-babel-prep-session:octave) (org-babel-octave-evaluate-session): * lisp/ob-ocaml.el: * lisp/ob-mscgen.el (org-babel-execute:mscgen) (org-babel-execute:mscgen): * lisp/ob-maxima.el: (ob-maxima): * lisp/ob-matlab.el: * lisp/ob-makefile.el: * lisp/ob-lua.el (org-babel-prep-session:lua) (org-babel-prep-session:lua): * lisp/ob-lisp.el: * lisp/ob-ledger.el: * lisp/ob-latex.el (org-babel-expand-body:latex) (org-babel-expand-body:latex, ob-latex): * lisp/ob-js.el: * lisp/ob-java.el: * lisp/ob-io.el (org-babel-prep-session:io) (org-babel-prep-session:io): * lisp/ob-hledger.el: * lisp/ob-haskell.el: * lisp/ob-groovy.el (org-babel-groovy-wrapper-method) (org-babel-groovy-evaluate): * lisp/ob-gnuplot.el: * lisp/ob-fortran.el (org-babel-expand-body:fortran) (org-babel-expand-body:fortran): * lisp/ob-forth.el (org-babel-forth-session-execute): * lisp/ob-exp.el (ob-exp): * lisp/ob-eval.el: * lisp/ob-emacs-lisp.el: * lisp/ob-ebnf.el: * lisp/ob-dot.el: * lisp/ob-ditaa.el: * lisp/ob-css.el: * lisp/ob-core.el (org-babel-put-rownames): * lisp/ob-coq.el: * lisp/ob-comint.el: * lisp/ob-calc.el: * lisp/ob-awk.el: * lisp/ob-asymptote.el: * lisp/ob-abc.el: * lisp/ob-R.el (org-babel-prep-session:R): Formatting fixes.
2020-02-18 21:57:37 +00:00
(org-check-deadlines org-deadline-warning-days))
t]
2008-01-31 10:32:52 +00:00
["Check TODOs" org-show-todo-tree t]
2008-04-24 08:29:47 +00:00
("Check Tags"
,@(org-mouse-keyword-menu
(sort (mapcar #'car (org-get-buffer-tags)) #'string-lessp)
(lambda (tag) (org-tags-sparse-tree nil tag)))
2008-01-31 10:32:52 +00:00
"--"
["Custom Tag ..." org-tags-sparse-tree t])
["Check Phrase ..." org-occur]
"--"
["Display Agenda" org-agenda-list t]
["Display TODO List" org-todo-list t]
2008-04-24 08:29:47 +00:00
("Display Tags"
,@(org-mouse-keyword-menu
(sort (mapcar #'car (org-get-buffer-tags)) #'string-lessp)
(lambda (tag) (org-tags-view nil tag)))
2008-01-31 10:32:52 +00:00
"--"
["Custom Tag ..." org-tags-view t])
["Display Calendar" org-goto-calendar t]
"--"
2008-04-24 08:29:47 +00:00
,@(org-mouse-keyword-menu
(mapcar #'car org-agenda-custom-commands)
(lambda (key)
2021-09-29 07:22:47 +00:00
(org-agenda nil (string-to-char key)))
2008-04-24 08:29:47 +00:00
nil
(lambda (key)
(let ((entry (assoc key org-agenda-custom-commands)))
(org-mouse-clip-text
(cond
((stringp (nth 1 entry)) (nth 1 entry))
((stringp (nth 2 entry))
(concat (org-mouse-agenda-type (nth 1 entry))
(nth 2 entry)))
(t "Agenda Command `%s'"))
30))))
2008-01-31 10:32:52 +00:00
"--"
2008-04-24 08:29:47 +00:00
["Delete Blank Lines" delete-blank-lines
2008-01-31 10:32:52 +00:00
:visible (org-mouse-empty-line)]
["Insert Checkbox" org-mouse-insert-checkbox
:visible (and (org-at-item-p) (not (org-at-item-checkbox-p)))]
2008-04-24 08:29:47 +00:00
["Insert Checkboxes"
2008-01-31 10:32:52 +00:00
(org-mouse-for-each-item 'org-mouse-insert-checkbox)
:visible (and (org-at-item-p) (not (org-at-item-checkbox-p)))]
["Plain List to Outline" org-mouse-transform-to-outline
:visible (org-at-item-p)])))
(defun org-mouse-get-context (contextlist context)
2008-01-31 10:33:46 +00:00
(let ((contextdata (assq context contextlist)))
2008-01-31 10:32:52 +00:00
(when contextdata
2008-04-24 08:29:47 +00:00
(save-excursion
Silence byte-compiler * lisp/ob-core.el (org-babel-process-params): Silence byte-compiler. * lisp/ob-groovy.el (org-babel-groovy-evaluate): * lisp/ob-haskell.el (org-babel-execute:haskell): * lisp/ob-io.el (org-babel-io-evaluate): * lisp/ob-octave.el (org-babel-octave-evaluate-external-process): (org-babel-octave-evaluate-session): * lisp/ob-perl.el (org-babel-perl-evaluate): * lisp/ob-python.el (org-babel-python-evaluate-external-process): (org-babel-python-evaluate-session): * lisp/ob-ruby.el (org-babel-ruby-pp-wrapper-method): (org-babel-ruby-evaluate): * lisp/ob-scala.el: * lisp/ob-tangle.el: (org-babel-tangle-collect-blocks): * lisp/org-agenda.el (org-agenda-get-category-icon): (org-agenda-todo-yesterday): * lisp/org-bbdb.el (org-bbdb-anniv-extract-date): (org-bbdb-make-anniv-hash): (org-bbdb-anniversaries-future): * lisp/org-bibtex.el (org-bibtex-fleshout): (org-bibtex-read): (org-bibtex-write): * lisp/org-capture.el (org-capture-set-target-location): (org-capture-get-indirect-buffer): (org-mks): * lisp/org-clock.el (org-clock--oldest-date): (org-clock-resolve): (org-clock-sum): (org-clock-special-range): (org-clocktable-steps): * lisp/org-ctags.el (org-ctags-create-tags): * lisp/org-element.el (org-element--interpret-affiliated-keywords): (org-element--cache-shift-positions): (org-element--cache-sync): (org-element--cache-submit-request): * lisp/org-habit.el (org-habit-parse-todo): * lisp/org-inlinetask.el (org-inlinetask-hide-tasks): * lisp/org-lint.el (org-lint--generate-reports): * lisp/org-mouse.el (org-mouse-get-context): * lisp/org-plot.el (org-plot/gnuplot-to-grid-data): (org-plot/gnuplot): * lisp/ox-ascii.el (org-ascii--current-text-width): (org-ascii--current-justification): (org-ascii--build-caption): (org-ascii--checkbox): (org-ascii-item): * lisp/ox-html.el (org-html-footnote-section): * lisp/ox-latex.el (org-latex--make-option-string): * lisp/ox-odt.el (org-odt-toc): (org-odt-add-automatic-style): (org-odt-format-label): (org-odt-link--inline-image): (org-odt--render-image/formula): (org-odt--enumerable-image-p): (org-odt--enumerable-latex-image-p): (org-odt--enumerable-formula-p): (org-odt-do-format-code): (org-odt-table-cell): Silence byte-compiler.
2016-07-25 14:34:48 +00:00
(goto-char (nth 1 contextdata))
(re-search-forward ".*" (nth 2 contextdata))))))
2008-01-31 10:32:52 +00:00
(defun org-mouse-for-each-item (funct)
;; Functions called by `org-apply-on-list' need an argument.
(let ((wrap-fun (lambda (_) (funcall funct))))
(when (ignore-errors (goto-char (org-in-item-p)))
(save-excursion (org-apply-on-list wrap-fun nil)))))
2008-01-31 10:32:52 +00:00
(defun org-mouse-bolp ()
"Return true if there only spaces, tabs, and `*' before point.
This means, between the beginning of line and the point."
2008-01-31 10:32:52 +00:00
(save-excursion
(skip-chars-backward " \t*") (bolp)))
2008-04-24 08:29:47 +00:00
2008-01-31 10:33:13 +00:00
(defun org-mouse-insert-item (text)
(cl-case (org-mouse-line-position)
(:beginning ; insert before
2008-04-24 08:29:47 +00:00
(beginning-of-line)
2008-01-31 10:33:13 +00:00
(looking-at "[ \t]*")
(open-line 1)
(indent-to-column (- (match-end 0) (match-beginning 0)))
2008-01-31 10:33:13 +00:00
(insert "+ "))
(:middle ; insert after
2008-04-24 08:29:47 +00:00
(end-of-line)
(newline t)
2008-01-31 10:33:13 +00:00
(indent-relative)
(insert "+ "))
(:end ; insert text here
2008-04-24 08:29:47 +00:00
(skip-chars-backward " \t")
(kill-region (point) (line-end-position))
(unless (looking-back org-mouse-punctuation (line-beginning-position))
2008-01-31 10:33:13 +00:00
(insert (concat org-mouse-punctuation " ")))))
(insert text)
(beginning-of-line))
Replace all uses of the old `defadvice` with the new `advice-add` * lisp/org.el (org-run-like-in-org-mode): Strength reduce `eval` to `cl-progv`. (org--check-org-structure-template-alist): Strength reduce `eval` to `symbol-value`. (org-map-entries, org-eval-in-calendar, org-diary-sexp-entry): Make sure we use the new lexically scoped dialect. (org--math-always-on): New function, extracted from advice. (org-cdlatex-mode): Use it with `advice-add`. (org-self-insert-command): Simplify `and`+`listp` into `consp`. (org-submit-bug-report): Make sure we use the new lexically scoped dialect. * lisp/org-protocol.el (org-protocol-convert-query-to-plist): Use `cl-mapcan`. (org--protocol-detect-protocol-server): New function, extracted from advice. (server-visit-files): Use it with `advice-add`. * lisp/org-mouse.el (org--mouse-dnd-insert-text): New function, extracted from advice. (dnd-insert-text): Use it with `advice-add`. (org--mouse-dnd-open-file): New function, extracted from advice. (dnd-open-file): Use it with `advice-add`. (org--mouse-open-at-point): New function, extracted from advice. (org-mode-hook): Advise `org-open-at-point` with `advice-add`. * lisp/org-ctags.el (org--ctags-load-tag-list): New function, extracted from advice. (visit-tags-table): Use it with `advice-add`. (org--ctags-set-org-mark-before-finding-tag): New function, extracted from advice. (xref-find-definitions): Use it with `advice-add`. * lisp/org-compat.el (org-bookmark-jump-unhide): Accept (unused) args. (save-place-find-file-hook): Use `advice-add`. (org--ecb-show-context): New function, extracted from advice. (ecb-method-clicked): Use it with `advice-add`. (org-mark-jump-unhide): Accept (unused) args. (pop-to-mark-command, exchange-point-and-mark, pop-global-mark): Use `advice-add`. Along the way, remove some redundant `:group` args (redundant because they specify the same group as would be used by default anyway) and make a few other simplifications. Also don't bother putting `advice-add` within an eval-after-load since the advice machinery already takes care of handling it.
2022-04-01 05:50:01 +00:00
(advice-add 'dnd-insert-text :around #'org--mouse-dnd-insert-text)
(defun org--mouse-dnd-insert-text (orig-fun window action text &rest args)
Use (derived-mode-p 'org-mode) instead of (eq major-mode 'org-mode). * org.el (org-show-hierarchy-above, org-cycle) (org-global-cycle, org-files-list, org-store-link) (org-link-search, org-open-file, org-display-outline-path) (org-refile-get-location, org-update-all-dblocks) (org-change-tag-in-region, org-entry-properties) (org-save-all-org-buffers, org-revert-all-org-buffers) (org-buffer-list, org-cdlatex-mode) (org-install-agenda-files-menu, org-end-of-subtree) (org-speedbar-set-agenda-restriction): Use (derived-mode-p 'org-mode) instead of (eq major-mode 'org-mode). * org-timer.el (org-timer-set-timer): Ditto. * org-table.el (orgtbl-mode, org-table-align, orgtbl-mode): Ditto. * org-src.el (org-edit-src-exit, org-edit-src-code) (org-edit-fixed-width-region, org-edit-src-exit): Ditto. * org-remember.el (org-remember-handler): Ditto. * org-mouse.el (dnd-open-file, org-mouse-insert-item): Ditto. * org-macs.el (org-get-limited-outline-regexp): Ditto. * org-lparse.el (org-replace-region-by): Ditto. * org-latex.el (org-latex-to-pdf-process) (org-replace-region-by-latex): Ditto. * org-indent.el (org-indent-indent-buffer): Ditto. * org-id.el (org-id-store-link, org-id-update-id-locations) (org-id-store-link): Ditto. * org-html.el (org-export-html-preprocess) (org-replace-region-by-html): Ditto. * org-footnote.el (org-footnote-normalize) (org-footnote-goto-definition) (org-footnote-create-definition, org-footnote-normalize): Ditto. * org-docbook.el (org-replace-region-by-docbook): Ditto. * org-ctags.el (find-tag): Ditto. * org-colview.el (org-columns-redo) (org-columns-display-here, org-columns-edit-value) (org-columns-redo): Ditto. * org-colview-xemacs.el (org-columns-redo) (org-columns-display-here, org-columns-edit-value) (org-columns-redo): Ditto. * org-capture.el (org-capture-insert-template-here) (org-capture, org-capture-finalize) (org-capture-set-target-location) (org-capture-insert-template-here): Ditto. * org-ascii.el (org-replace-region-by-ascii): Ditto. * org-archive.el (org-archive-subtree): Ditto. * org-agenda.el (org-agenda) (org-agenda-get-restriction-and-command) (org-agenda-get-some-entry-text, org-search-view) (org-tags-view, org-agenda-get-day-entries) (org-agenda-format-item, org-agenda-goto, org-agenda-kill) (org-agenda-archive-with, org-agenda-switch-to): Ditto.
2012-04-20 18:03:45 +00:00
(if (derived-mode-p 'org-mode)
2008-01-31 10:33:13 +00:00
(org-mouse-insert-item text)
Replace all uses of the old `defadvice` with the new `advice-add` * lisp/org.el (org-run-like-in-org-mode): Strength reduce `eval` to `cl-progv`. (org--check-org-structure-template-alist): Strength reduce `eval` to `symbol-value`. (org-map-entries, org-eval-in-calendar, org-diary-sexp-entry): Make sure we use the new lexically scoped dialect. (org--math-always-on): New function, extracted from advice. (org-cdlatex-mode): Use it with `advice-add`. (org-self-insert-command): Simplify `and`+`listp` into `consp`. (org-submit-bug-report): Make sure we use the new lexically scoped dialect. * lisp/org-protocol.el (org-protocol-convert-query-to-plist): Use `cl-mapcan`. (org--protocol-detect-protocol-server): New function, extracted from advice. (server-visit-files): Use it with `advice-add`. * lisp/org-mouse.el (org--mouse-dnd-insert-text): New function, extracted from advice. (dnd-insert-text): Use it with `advice-add`. (org--mouse-dnd-open-file): New function, extracted from advice. (dnd-open-file): Use it with `advice-add`. (org--mouse-open-at-point): New function, extracted from advice. (org-mode-hook): Advise `org-open-at-point` with `advice-add`. * lisp/org-ctags.el (org--ctags-load-tag-list): New function, extracted from advice. (visit-tags-table): Use it with `advice-add`. (org--ctags-set-org-mark-before-finding-tag): New function, extracted from advice. (xref-find-definitions): Use it with `advice-add`. * lisp/org-compat.el (org-bookmark-jump-unhide): Accept (unused) args. (save-place-find-file-hook): Use `advice-add`. (org--ecb-show-context): New function, extracted from advice. (ecb-method-clicked): Use it with `advice-add`. (org-mark-jump-unhide): Accept (unused) args. (pop-to-mark-command, exchange-point-and-mark, pop-global-mark): Use `advice-add`. Along the way, remove some redundant `:group` args (redundant because they specify the same group as would be used by default anyway) and make a few other simplifications. Also don't bother putting `advice-add` within an eval-after-load since the advice machinery already takes care of handling it.
2022-04-01 05:50:01 +00:00
(apply orig-fun window action text args)))
2008-01-31 10:32:52 +00:00
Replace all uses of the old `defadvice` with the new `advice-add` * lisp/org.el (org-run-like-in-org-mode): Strength reduce `eval` to `cl-progv`. (org--check-org-structure-template-alist): Strength reduce `eval` to `symbol-value`. (org-map-entries, org-eval-in-calendar, org-diary-sexp-entry): Make sure we use the new lexically scoped dialect. (org--math-always-on): New function, extracted from advice. (org-cdlatex-mode): Use it with `advice-add`. (org-self-insert-command): Simplify `and`+`listp` into `consp`. (org-submit-bug-report): Make sure we use the new lexically scoped dialect. * lisp/org-protocol.el (org-protocol-convert-query-to-plist): Use `cl-mapcan`. (org--protocol-detect-protocol-server): New function, extracted from advice. (server-visit-files): Use it with `advice-add`. * lisp/org-mouse.el (org--mouse-dnd-insert-text): New function, extracted from advice. (dnd-insert-text): Use it with `advice-add`. (org--mouse-dnd-open-file): New function, extracted from advice. (dnd-open-file): Use it with `advice-add`. (org--mouse-open-at-point): New function, extracted from advice. (org-mode-hook): Advise `org-open-at-point` with `advice-add`. * lisp/org-ctags.el (org--ctags-load-tag-list): New function, extracted from advice. (visit-tags-table): Use it with `advice-add`. (org--ctags-set-org-mark-before-finding-tag): New function, extracted from advice. (xref-find-definitions): Use it with `advice-add`. * lisp/org-compat.el (org-bookmark-jump-unhide): Accept (unused) args. (save-place-find-file-hook): Use `advice-add`. (org--ecb-show-context): New function, extracted from advice. (ecb-method-clicked): Use it with `advice-add`. (org-mark-jump-unhide): Accept (unused) args. (pop-to-mark-command, exchange-point-and-mark, pop-global-mark): Use `advice-add`. Along the way, remove some redundant `:group` args (redundant because they specify the same group as would be used by default anyway) and make a few other simplifications. Also don't bother putting `advice-add` within an eval-after-load since the advice machinery already takes care of handling it.
2022-04-01 05:50:01 +00:00
(advice-add 'dnd-open-file :around #'org--mouse-dnd-open-file)
(defun org--mouse-dnd-open-file (orig-fun uri &rest args)
Use (derived-mode-p 'org-mode) instead of (eq major-mode 'org-mode). * org.el (org-show-hierarchy-above, org-cycle) (org-global-cycle, org-files-list, org-store-link) (org-link-search, org-open-file, org-display-outline-path) (org-refile-get-location, org-update-all-dblocks) (org-change-tag-in-region, org-entry-properties) (org-save-all-org-buffers, org-revert-all-org-buffers) (org-buffer-list, org-cdlatex-mode) (org-install-agenda-files-menu, org-end-of-subtree) (org-speedbar-set-agenda-restriction): Use (derived-mode-p 'org-mode) instead of (eq major-mode 'org-mode). * org-timer.el (org-timer-set-timer): Ditto. * org-table.el (orgtbl-mode, org-table-align, orgtbl-mode): Ditto. * org-src.el (org-edit-src-exit, org-edit-src-code) (org-edit-fixed-width-region, org-edit-src-exit): Ditto. * org-remember.el (org-remember-handler): Ditto. * org-mouse.el (dnd-open-file, org-mouse-insert-item): Ditto. * org-macs.el (org-get-limited-outline-regexp): Ditto. * org-lparse.el (org-replace-region-by): Ditto. * org-latex.el (org-latex-to-pdf-process) (org-replace-region-by-latex): Ditto. * org-indent.el (org-indent-indent-buffer): Ditto. * org-id.el (org-id-store-link, org-id-update-id-locations) (org-id-store-link): Ditto. * org-html.el (org-export-html-preprocess) (org-replace-region-by-html): Ditto. * org-footnote.el (org-footnote-normalize) (org-footnote-goto-definition) (org-footnote-create-definition, org-footnote-normalize): Ditto. * org-docbook.el (org-replace-region-by-docbook): Ditto. * org-ctags.el (find-tag): Ditto. * org-colview.el (org-columns-redo) (org-columns-display-here, org-columns-edit-value) (org-columns-redo): Ditto. * org-colview-xemacs.el (org-columns-redo) (org-columns-display-here, org-columns-edit-value) (org-columns-redo): Ditto. * org-capture.el (org-capture-insert-template-here) (org-capture, org-capture-finalize) (org-capture-set-target-location) (org-capture-insert-template-here): Ditto. * org-ascii.el (org-replace-region-by-ascii): Ditto. * org-archive.el (org-archive-subtree): Ditto. * org-agenda.el (org-agenda) (org-agenda-get-restriction-and-command) (org-agenda-get-some-entry-text, org-search-view) (org-tags-view, org-agenda-get-day-entries) (org-agenda-format-item, org-agenda-goto, org-agenda-kill) (org-agenda-archive-with, org-agenda-switch-to): Ditto.
2012-04-20 18:03:45 +00:00
(if (derived-mode-p 'org-mode)
2008-01-31 10:33:13 +00:00
(org-mouse-insert-item uri)
Replace all uses of the old `defadvice` with the new `advice-add` * lisp/org.el (org-run-like-in-org-mode): Strength reduce `eval` to `cl-progv`. (org--check-org-structure-template-alist): Strength reduce `eval` to `symbol-value`. (org-map-entries, org-eval-in-calendar, org-diary-sexp-entry): Make sure we use the new lexically scoped dialect. (org--math-always-on): New function, extracted from advice. (org-cdlatex-mode): Use it with `advice-add`. (org-self-insert-command): Simplify `and`+`listp` into `consp`. (org-submit-bug-report): Make sure we use the new lexically scoped dialect. * lisp/org-protocol.el (org-protocol-convert-query-to-plist): Use `cl-mapcan`. (org--protocol-detect-protocol-server): New function, extracted from advice. (server-visit-files): Use it with `advice-add`. * lisp/org-mouse.el (org--mouse-dnd-insert-text): New function, extracted from advice. (dnd-insert-text): Use it with `advice-add`. (org--mouse-dnd-open-file): New function, extracted from advice. (dnd-open-file): Use it with `advice-add`. (org--mouse-open-at-point): New function, extracted from advice. (org-mode-hook): Advise `org-open-at-point` with `advice-add`. * lisp/org-ctags.el (org--ctags-load-tag-list): New function, extracted from advice. (visit-tags-table): Use it with `advice-add`. (org--ctags-set-org-mark-before-finding-tag): New function, extracted from advice. (xref-find-definitions): Use it with `advice-add`. * lisp/org-compat.el (org-bookmark-jump-unhide): Accept (unused) args. (save-place-find-file-hook): Use `advice-add`. (org--ecb-show-context): New function, extracted from advice. (ecb-method-clicked): Use it with `advice-add`. (org-mark-jump-unhide): Accept (unused) args. (pop-to-mark-command, exchange-point-and-mark, pop-global-mark): Use `advice-add`. Along the way, remove some redundant `:group` args (redundant because they specify the same group as would be used by default anyway) and make a few other simplifications. Also don't bother putting `advice-add` within an eval-after-load since the advice machinery already takes care of handling it.
2022-04-01 05:50:01 +00:00
(apply orig-fun uri args)))
2008-01-31 10:33:13 +00:00
(defun org-mouse-match-closure (function)
(let ((match (match-data t)))
(lambda (&rest rest)
(save-match-data
(set-match-data match)
(apply function rest)))))
2008-01-31 10:33:13 +00:00
(defun org-mouse-yank-link (click)
(interactive "e")
;; Give temporary modes such as isearch a chance to turn off.
(run-hooks 'mouse-leave-buffer-hook)
(mouse-set-point click)
(setq mouse-selection-click-count 0)
(delete-horizontal-space)
(insert-for-yank (concat " [[" (current-kill 0) "]] ")))
(defun org-mouse-context-menu (&optional event)
(let* ((stamp-prefixes (list org-deadline-string org-scheduled-string))
(contextlist (org-context))
(get-context (lambda (context) (org-mouse-get-context contextlist context))))
(cond
((org-mouse-mark-active)
(let ((region-string (buffer-substring (region-beginning) (region-end))))
(popup-menu
`(nil
["Sparse Tree" (org-occur ',region-string)]
["Find in Buffer" (occur ',region-string)]
["Grep in Current Dir"
(grep (format "grep -rnH -e '%s' *" ',region-string))]
["Grep in Parent Dir"
(grep (format "grep -rnH -e '%s' ../*" ',region-string))]
"--"
["Convert to Link"
(progn (save-excursion (goto-char (region-beginning)) (insert "[["))
(save-excursion (goto-char (region-end)) (insert "]]")))]
["Insert Link Here" (org-mouse-yank-link ',event)]))))
((save-excursion (beginning-of-line) (looking-at "[ \t]*#\\+STARTUP: \\(.*\\)"))
2008-01-31 10:33:13 +00:00
(popup-menu
`(nil
,@(org-mouse-list-options-menu (mapcar #'car org-startup-options)
'org-mode-restart))))
((or (eolp)
(and (looking-at "\\( \\|\t\\)\\(\\+:[0-9a-zA-Z_:]+\\)?\\( \\|\t\\)+$")
(looking-back " \\|\t" (- (point) 2)
(line-beginning-position))))
(org-mouse-popup-global-menu))
((funcall get-context :checkbox)
(popup-menu
'(nil
["Toggle" org-toggle-checkbox t]
["Remove" org-mouse-remove-match-and-spaces t]
""
["All Clear" (org-mouse-for-each-item
(lambda ()
(when (save-excursion (org-at-item-checkbox-p))
(replace-match "[ ] "))))]
["All Set" (org-mouse-for-each-item
2008-01-31 10:32:52 +00:00
(lambda ()
(when (save-excursion (org-at-item-checkbox-p))
(replace-match "[X] "))))]
["All Toggle" (org-mouse-for-each-item 'org-toggle-checkbox) t]
["All Remove" (org-mouse-for-each-item
(lambda ()
(when (save-excursion (org-at-item-checkbox-p))
(org-mouse-remove-match-and-spaces))))]
)))
((and (org-mouse-looking-at "\\b\\w+" "a-zA-Z0-9_")
(member (match-string 0) org-todo-keywords-1))
(popup-menu
`(nil
,@(org-mouse-todo-menu (match-string 0))
2008-01-31 10:33:46 +00:00
"--"
["Check TODOs" org-show-todo-tree t]
["List all TODO keywords" org-todo-list t]
[,(format "List only %s" (match-string 0))
(org-todo-list (match-string 0)) t]
)))
((and (org-mouse-looking-at "\\b[A-Z]+:" "A-Z")
(member (match-string 0) stamp-prefixes))
(popup-menu
`(nil
,@(org-mouse-keyword-replace-menu stamp-prefixes)
2008-01-31 10:33:46 +00:00
"--"
["Check Deadlines" org-check-deadlines t]
)))
((org-mouse-looking-at org-mouse-priority-regexp "[]A-Z#") ; priority
(popup-menu `(nil ,@(org-mouse-keyword-replace-menu
(org-mouse-priority-list) 1 "Priority %s" t))))
((funcall get-context :link)
2008-01-31 10:32:52 +00:00
(popup-menu
'(nil
["Open" org-open-at-point t]
["Open in Emacs" (org-open-at-point t) t]
"--"
["Copy link" (org-kill-new (match-string 0))]
["Cut link"
(progn
(kill-region (match-beginning 0) (match-end 0))
(just-one-space))]
2008-01-31 10:32:52 +00:00
"--"
["Grep for TODOs"
(grep (format "grep -nH -i 'todo\\|fixme' %s*" (match-string 2)))]
; ["Paste file link" ((insert "file:") (yank))]
)))
((org-mouse-looking-at ":\\([A-Za-z0-9_]+\\):" "A-Za-z0-9_" -1) ;tags
(popup-menu
`(nil
[,(format-message "Display `%s'" (match-string 1))
(org-tags-view nil ,(match-string 1))]
[,(format-message "Sparse Tree `%s'" (match-string 1))
(org-tags-sparse-tree nil ,(match-string 1))]
"--"
,@(org-mouse-tag-menu))))
((org-at-timestamp-p 'lax)
(popup-menu
'(nil
["Show Day" org-open-at-point t]
["Change Timestamp" org-time-stamp t]
["Delete Timestamp" (org-mouse-delete-timestamp) t]
["Compute Time Range" org-evaluate-time-range (org-at-date-range-p)]
"--"
["Set for Today" org-mouse-timestamp-today]
["Set for Tomorrow" (org-mouse-timestamp-today 1 'day)]
["Set in 1 Week" (org-mouse-timestamp-today 7 'day)]
["Set in 2 Weeks" (org-mouse-timestamp-today 14 'day)]
["Set in a Month" (org-mouse-timestamp-today 1 'month)]
"--"
["+ 1 Day" (org-timestamp-change 1 'day)]
["+ 1 Week" (org-timestamp-change 7 'day)]
["+ 1 Month" (org-timestamp-change 1 'month)]
"--"
["- 1 Day" (org-timestamp-change -1 'day)]
["- 1 Week" (org-timestamp-change -7 'day)]
["- 1 Month" (org-timestamp-change -1 'month)])))
((funcall get-context :table-special)
(let ((mdata (match-data)))
(cl-incf (car mdata) 2)
(store-match-data mdata))
(message "match: %S" (match-string 0))
(popup-menu `(nil ,@(org-mouse-keyword-replace-menu
'(" " "!" "^" "_" "$" "#" "*" "'") 0
(lambda (mark)
(cl-case (string-to-char mark)
(? "( ) Nothing Special")
(?! "(!) Column Names")
(?^ "(^) Field Names Above")
(?_ "(^) Field Names Below")
(?$ "($) Formula Parameters")
(?# "(#) Recalculation: Auto")
(?* "(*) Recalculation: Manual")
Tiny formatting fixes * lisp/ox.el (org-export-table-dimensions): * lisp/ox-texinfo.el (org-texinfo-template): * lisp/ox-md.el (org-md-link): * lisp/ox-icalendar.el (org-icalendar-use-UTC-date-time-p): * lisp/ox-ascii.el (org-ascii-fixed-width): * lisp/org.el (org-context): * lisp/org-table.el (org-table-eval-formula) (org-table-export): * lisp/org-refile.el: * lisp/org-plot.el (org-plot/gnuplot-to-grid-data): * lisp/org-num.el (org-num): * lisp/org-mouse.el (org-mouse-popup-global-menu) (org-mouse-context-menu): * lisp/org-macro.el (org-macro): * lisp/org-lint.el (org-lint): * lisp/org-keys.el (org-keys): * lisp/org-duration.el: * lisp/org-clock.el (org-clock-get-last-clock-out-time) (org-clock-update-mode-line, org-find-open-clocks): * lisp/org-agenda.el (org-diary) (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item) (org-agenda-highlight-todo, org-cmp-alpha) (org-agenda-filter-by-category): * lisp/ol.el (org-link-expand-abbrev, ol): * lisp/ol-docview.el (ol-docview): * lisp/ol-bibtex.el (org-execute-file-search-in-bibtex) (org-bibtex, org-bibtex-read): * lisp/ol-bbdb.el (org-bbdb-anniversary-description): * lisp/ob-tangle.el (org-babel-tangle-jump-to-org): * lisp/ob-table.el (org-babel-table-truncate-at-newline): * lisp/ob-stan.el: * lisp/ob-sqlite.el (org-babel-sqlite-table-or-scalar): * lisp/ob-sql.el: * lisp/ob-shen.el: * lisp/ob-shell.el (org-babel-prep-session:shell) (org-babel-prep-session:shell): * lisp/ob-sed.el (org-babel-execute:sed) (org-babel-execute:sed): * lisp/ob-screen.el: * lisp/ob-sass.el: * lisp/ob-ruby.el (org-babel-prep-session:ruby) (org-babel-prep-session:ruby): * lisp/ob-ref.el (org-babel-ref-resolve, ob-ref): * lisp/ob-python.el (org-babel-prep-session:python) (org-babel-prep-session:python): * lisp/ob-plantuml.el: * lisp/ob-picolisp.el: * lisp/ob-perl.el: * lisp/ob-org.el: * lisp/ob-octave.el (org-babel-prep-session:octave) (org-babel-prep-session:octave) (org-babel-octave-evaluate-session): * lisp/ob-ocaml.el: * lisp/ob-mscgen.el (org-babel-execute:mscgen) (org-babel-execute:mscgen): * lisp/ob-maxima.el: (ob-maxima): * lisp/ob-matlab.el: * lisp/ob-makefile.el: * lisp/ob-lua.el (org-babel-prep-session:lua) (org-babel-prep-session:lua): * lisp/ob-lisp.el: * lisp/ob-ledger.el: * lisp/ob-latex.el (org-babel-expand-body:latex) (org-babel-expand-body:latex, ob-latex): * lisp/ob-js.el: * lisp/ob-java.el: * lisp/ob-io.el (org-babel-prep-session:io) (org-babel-prep-session:io): * lisp/ob-hledger.el: * lisp/ob-haskell.el: * lisp/ob-groovy.el (org-babel-groovy-wrapper-method) (org-babel-groovy-evaluate): * lisp/ob-gnuplot.el: * lisp/ob-fortran.el (org-babel-expand-body:fortran) (org-babel-expand-body:fortran): * lisp/ob-forth.el (org-babel-forth-session-execute): * lisp/ob-exp.el (ob-exp): * lisp/ob-eval.el: * lisp/ob-emacs-lisp.el: * lisp/ob-ebnf.el: * lisp/ob-dot.el: * lisp/ob-ditaa.el: * lisp/ob-css.el: * lisp/ob-core.el (org-babel-put-rownames): * lisp/ob-coq.el: * lisp/ob-comint.el: * lisp/ob-calc.el: * lisp/ob-awk.el: * lisp/ob-asymptote.el: * lisp/ob-abc.el: * lisp/ob-R.el (org-babel-prep-session:R): Formatting fixes.
2020-02-18 21:57:37 +00:00
(?' "(') Recalculation: None")))
t))))
((assq :table contextlist)
(popup-menu
'(nil
["Align Table" org-ctrl-c-ctrl-c]
["Blank Field" org-table-blank-field]
["Edit Field" org-table-edit-field]
"--"
("Column"
["Move Column Left" org-metaleft]
["Move Column Right" org-metaright]
["Delete Column" org-shiftmetaleft]
["Insert Column" org-shiftmetaright]
2008-01-31 10:33:46 +00:00
"--"
["Enable Narrowing" (setq org-table-limit-column-width (not org-table-limit-column-width)) :selected org-table-limit-column-width :style toggle])
("Row"
["Move Row Up" org-metaup]
["Move Row Down" org-metadown]
["Delete Row" org-shiftmetaup]
["Insert Row" org-shiftmetadown]
["Sort lines in region" org-table-sort-lines (org-at-table-p)]
"--"
["Insert Hline" org-table-insert-hline])
("Rectangle"
["Copy Rectangle" org-copy-special]
["Cut Rectangle" org-cut-special]
["Paste Rectangle" org-paste-special]
["Fill Rectangle" org-table-wrap-region])
"--"
["Set Column Formula" org-table-eval-formula]
["Set Field Formula" (org-table-eval-formula '(4))]
["Edit Formulas" org-table-edit-formulas]
"--"
["Recalculate Line" org-table-recalculate]
["Recalculate All" (org-table-recalculate '(4))]
["Iterate All" (org-table-recalculate '(16))]
2008-01-31 10:32:52 +00:00
"--"
["Toggle Recalculate Mark" org-table-rotate-recalc-marks]
["Sum Column/Rectangle" org-table-sum
:active (or (org-at-table-p) (org-region-active-p))]
["Field Info" org-table-field-info]
["Debug Formulas"
(setq org-table-formula-debug (not org-table-formula-debug))
:style toggle :selected org-table-formula-debug]
)))
((and (assq :headline contextlist) (not (eolp)))
(let ((priority (org-mouse-get-priority t)))
(popup-menu
`("Headline Menu"
("Tags and Priorities"
,@(org-mouse-keyword-menu
(org-mouse-priority-list)
(lambda (keyword)
(org-mouse-set-priority (string-to-char keyword)))
priority "Priority %s")
"--"
,@(org-mouse-tag-menu))
("TODO Status"
,@(org-mouse-todo-menu (org-get-todo-state)))
["Show Tags"
(with-current-buffer org-mouse-main-buffer (org-agenda-show-tags))
:visible (not org-mouse-direct)]
["Show Priority"
(with-current-buffer org-mouse-main-buffer (org-agenda-show-priority))
:visible (not org-mouse-direct)]
,@(if org-mouse-direct '("--") nil)
["New Heading" org-mouse-insert-heading :visible org-mouse-direct]
["Set Deadline"
(progn (org-mouse-end-headline) (insert " ") (org-deadline))
:active (not (save-excursion
(org-mouse-re-search-line org-deadline-regexp)))]
["Schedule Task"
(progn (org-mouse-end-headline) (insert " ") (org-schedule))
:active (not (save-excursion
(org-mouse-re-search-line org-scheduled-regexp)))]
["Insert Timestamp"
(progn (org-mouse-end-headline) (insert " ") (org-time-stamp nil)) t]
; ["Timestamp (inactive)" org-time-stamp-inactive t]
"--"
["Archive Subtree" org-archive-subtree]
["Cut Subtree" org-cut-special]
["Copy Subtree" org-copy-special]
["Paste Subtree" org-paste-special :visible org-mouse-direct]
("Sort Children"
["Alphabetically" (org-sort-entries nil ?a)]
["Numerically" (org-sort-entries nil ?n)]
["By Time/Date" (org-sort-entries nil ?t)]
"--"
["Reverse Alphabetically" (org-sort-entries nil ?A)]
["Reverse Numerically" (org-sort-entries nil ?N)]
["Reverse By Time/Date" (org-sort-entries nil ?T)])
"--"
["Move Trees" org-mouse-move-tree :active nil]
))))
(t
(org-mouse-popup-global-menu)))))
2008-01-31 10:32:52 +00:00
2008-01-31 10:33:13 +00:00
(defun org-mouse-mark-active ()
(and mark-active transient-mark-mode))
2008-01-31 10:32:52 +00:00
(defun org-mouse-in-region-p (pos)
2008-04-24 08:29:47 +00:00
(and (org-mouse-mark-active)
(>= pos (region-beginning))
2008-01-31 10:33:13 +00:00
(< pos (region-end))))
2008-01-31 10:32:52 +00:00
(defun org-mouse-down-mouse (event)
(interactive "e")
(setq this-command last-command)
2008-01-31 10:33:13 +00:00
(unless (and (= 1 (event-click-count event))
2008-01-31 10:32:52 +00:00
(org-mouse-in-region-p (posn-point (event-start event))))
(mouse-drag-region event)))
(add-hook 'org-mode-hook
(lambda ()
2021-05-19 23:24:39 +00:00
(setq org-mouse-context-menu-function #'org-mouse-context-menu)
(when (memq 'context-menu org-mouse-features)
(org-defkey org-mouse-map [mouse-3] nil)
2021-05-19 23:24:39 +00:00
(org-defkey org-mode-map [mouse-3] #'org-mouse-show-context-menu))
(org-defkey org-mode-map [down-mouse-1] #'org-mouse-down-mouse)
(when (memq 'context-menu org-mouse-features)
2021-05-19 23:24:39 +00:00
(org-defkey org-mouse-map [C-drag-mouse-1] #'org-mouse-move-tree)
(org-defkey org-mouse-map [C-down-mouse-1] #'org-mouse-move-tree-start))
(when (memq 'yank-link org-mouse-features)
2021-05-19 23:24:39 +00:00
(org-defkey org-mode-map [S-mouse-2] #'org-mouse-yank-link)
(org-defkey org-mode-map [drag-mouse-3] #'org-mouse-yank-link))
(when (memq 'move-tree org-mouse-features)
2021-05-19 23:24:39 +00:00
(org-defkey org-mouse-map [drag-mouse-3] #'org-mouse-move-tree)
(org-defkey org-mouse-map [down-mouse-3] #'org-mouse-move-tree-start))
(when (memq 'activate-stars org-mouse-features)
(font-lock-add-keywords
nil
`((,org-outline-regexp
0 `(face org-link mouse-face highlight keymap ,org-mouse-map)
'prepend))
t))
(when (memq 'activate-bullets org-mouse-features)
(font-lock-add-keywords
nil
`(("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +"
(1 `(face org-link keymap ,org-mouse-map mouse-face highlight)
'prepend)))
t))
(when (memq 'activate-checkboxes org-mouse-features)
(font-lock-add-keywords
nil
`(("^[ \t]*\\(?:[-+*]\\|[0-9]+[.)]\\)[ \t]+\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\(\\[[- X]\\]\\)"
(1 `(face nil keymap ,org-mouse-map mouse-face highlight) prepend)))
t))
Replace all uses of the old `defadvice` with the new `advice-add` * lisp/org.el (org-run-like-in-org-mode): Strength reduce `eval` to `cl-progv`. (org--check-org-structure-template-alist): Strength reduce `eval` to `symbol-value`. (org-map-entries, org-eval-in-calendar, org-diary-sexp-entry): Make sure we use the new lexically scoped dialect. (org--math-always-on): New function, extracted from advice. (org-cdlatex-mode): Use it with `advice-add`. (org-self-insert-command): Simplify `and`+`listp` into `consp`. (org-submit-bug-report): Make sure we use the new lexically scoped dialect. * lisp/org-protocol.el (org-protocol-convert-query-to-plist): Use `cl-mapcan`. (org--protocol-detect-protocol-server): New function, extracted from advice. (server-visit-files): Use it with `advice-add`. * lisp/org-mouse.el (org--mouse-dnd-insert-text): New function, extracted from advice. (dnd-insert-text): Use it with `advice-add`. (org--mouse-dnd-open-file): New function, extracted from advice. (dnd-open-file): Use it with `advice-add`. (org--mouse-open-at-point): New function, extracted from advice. (org-mode-hook): Advise `org-open-at-point` with `advice-add`. * lisp/org-ctags.el (org--ctags-load-tag-list): New function, extracted from advice. (visit-tags-table): Use it with `advice-add`. (org--ctags-set-org-mark-before-finding-tag): New function, extracted from advice. (xref-find-definitions): Use it with `advice-add`. * lisp/org-compat.el (org-bookmark-jump-unhide): Accept (unused) args. (save-place-find-file-hook): Use `advice-add`. (org--ecb-show-context): New function, extracted from advice. (ecb-method-clicked): Use it with `advice-add`. (org-mark-jump-unhide): Accept (unused) args. (pop-to-mark-command, exchange-point-and-mark, pop-global-mark): Use `advice-add`. Along the way, remove some redundant `:group` args (redundant because they specify the same group as would be used by default anyway) and make a few other simplifications. Also don't bother putting `advice-add` within an eval-after-load since the advice machinery already takes care of handling it.
2022-04-01 05:50:01 +00:00
(advice-add 'org-open-at-point :around #'org--mouse-open-at-point)))
(defun org--mouse-open-at-point (orig-fun &rest args)
(let ((context (org-context)))
(cond
((assq :headline-stars context) (org-cycle))
((assq :checkbox context) (org-toggle-checkbox))
((assq :item-bullet context)
(let ((org-cycle-include-plain-lists t)) (org-cycle)))
((org-footnote-at-reference-p) nil)
(t (apply orig-fun args)))))
2008-01-31 10:32:52 +00:00
(defun org-mouse-move-tree-start (_event)
2008-01-31 10:32:52 +00:00
(interactive "e")
(message "Same line: promote/demote, (***):move before, (text): make a child"))
(defun org-mouse-make-marker (position)
(with-current-buffer (window-buffer (posn-window position))
(copy-marker (posn-point position))))
(defun org-mouse-move-tree (event)
;; todo: handle movements between different buffers
(interactive "e")
(save-excursion
(let* ((start (org-mouse-make-marker (event-start event)))
(end (org-mouse-make-marker (event-end event)))
(sbuf (marker-buffer start))
(ebuf (marker-buffer end)))
(when (and sbuf ebuf)
(set-buffer sbuf)
(goto-char start)
(org-back-to-heading)
(if (and (eq sbuf ebuf)
(equal
(point)
(save-excursion (goto-char end) (org-back-to-heading) (point))))
;; if the same line then promote/demote
(if (>= end start) (org-demote-subtree) (org-promote-subtree))
;; if different lines then move
(org-cut-subtree)
(set-buffer ebuf)
(goto-char end)
(org-back-to-heading)
(when (and (eq sbuf ebuf)
(equal
(point)
(save-excursion (goto-char start)
(org-back-to-heading) (point))))
(progn (org-end-of-subtree nil t)
(unless (eobp) (backward-char)))
2008-01-31 10:32:52 +00:00
(end-of-line)
(if (eobp) (newline) (forward-char)))
(when (looking-at org-outline-regexp)
(let ((level (- (match-end 0) (match-beginning 0))))
(when (> end (match-end 0))
(progn (org-end-of-subtree nil t)
(unless (eobp) (backward-char)))
(end-of-line)
(if (eobp) (newline) (forward-char))
(setq level (1+ level)))
(org-paste-subtree level)
(save-excursion
(progn (org-end-of-subtree nil t)
(unless (eobp) (backward-char)))
(when (bolp) (delete-char -1))))))))))
2008-01-31 10:32:52 +00:00
(defun org-mouse-transform-to-outline ()
(interactive)
(org-back-to-heading)
(let ((minlevel 1000)
(replace-text (concat (make-string (org-current-level) ?*) "* ")))
2008-01-31 10:32:52 +00:00
(beginning-of-line 2)
(save-excursion
Don't use `outline-regexp' anymore. Use `org-outline-regexp' instead or `outline-regexp'. Also use the new defconst `org-outline-regexp-bol' to match `org-outline-regexp' at the beginning of line. * org.el (org-outline-regexp-bol): New defconst. (org-outline-level, org-set-font-lock-defaults, org-cycle) (org-overview, org-content, org-flag-drawer) (org-first-headline-recenter, org-insert-todo-heading) (org-map-region, org-move-subtree-down, org-paste-subtree) (org-kill-is-subtree-p, org-context-p, org-refile) (org-refile-new-child, org-toggle-comment, org-todo) (org-add-planning-info, org-add-log-setup, org-scan-tags) (org-set-tags, org-insert-property-drawer) (org-prepare-agenda-buffers, org-preview-latex-fragment) (org-speed-command-default-hook, org-check-for-hidden) (org-toggle-item, org-toggle-heading) (org-indent-line-function, org-set-autofill-regexps) (org-fill-paragraph, org-toggle-fixed-width-section) (org-yank-generic, org-yank-folding-would-swallow-text) (org-first-sibling-p, org-goto-sibling) (org-goto-first-child, org-show-entry): Use `org-outline-regexp' and `org-outline-regexp-bol'. * org-remember.el (org-remember-handler): Use `org-outline-regexp-bol'. * org-mouse.el (org-mouse-match-todo-keyword, org-mode-hook) (org-mouse-move-tree, org-mouse-transform-to-outline): Use `org-outline-regexp' and `org-outline-regexp-bol'. * org-macs.el (org-with-limited-levels) (org-get-limited-outline-regexp): Use `org-outline-regexp'. * org-indent.el (org-indent-outline-re) (org-indent-refresh-section, org-indent-refresh-to): Use `org-outline-regexp' and `org-outline-regexp-bol'. * org-html.el (org-export-as-html): Use `org-outline-regexp-bol'. * org-footnote.el (org-footnote-at-definition-p) (org-footnote-normalize): Use `org-outline-regexp' and `org-outline-regexp-bol'. * org-exp.el (org-export-preprocess-string): Don't redefine `outline-regexp'. * org-docbook.el (org-export-as-docbook): Use `org-outline-regexp-bol'. * org-colview.el (org-columns, org-columns-compute): Use `org-outline-regexp' and `org-outline-regexp-bol'. * org-colview-xemacs.el (org-columns, org-columns-compute): Use `org-outline-regexp-bol'. * org-clock.el (org-clock-insert-selection-line) (org-clock-in, org-clock-out, org-dblock-write:clocktable): Use `org-outline-regexp' and `org-outline-regexp-bol'. * org-ascii.el (org-export-as-ascii) (org-export-ascii-push-links): Use `org-outline-regexp' and `org-outline-regexp-bol'. * org-archive.el (org-archive-to-archive-sibling) (org-archive-all-done): Use `org-outline-regexp' and `org-outline-regexp-bol'. * org-agenda.el (org-agenda, org-search-view) (org-agenda-list-stuck-projects, org-agenda-get-timestamps) (org-agenda-get-progress, org-agenda-get-blocks): Use `org-outline-regexp' and `org-outline-regexp-bol'.
2011-07-17 19:17:08 +00:00
(while (not (or (eobp) (looking-at org-outline-regexp)))
2008-01-31 10:32:52 +00:00
(when (looking-at org-mouse-plain-list-regexp)
(setq minlevel (min minlevel (- (match-end 1) (match-beginning 1)))))
(forward-line)))
Don't use `outline-regexp' anymore. Use `org-outline-regexp' instead or `outline-regexp'. Also use the new defconst `org-outline-regexp-bol' to match `org-outline-regexp' at the beginning of line. * org.el (org-outline-regexp-bol): New defconst. (org-outline-level, org-set-font-lock-defaults, org-cycle) (org-overview, org-content, org-flag-drawer) (org-first-headline-recenter, org-insert-todo-heading) (org-map-region, org-move-subtree-down, org-paste-subtree) (org-kill-is-subtree-p, org-context-p, org-refile) (org-refile-new-child, org-toggle-comment, org-todo) (org-add-planning-info, org-add-log-setup, org-scan-tags) (org-set-tags, org-insert-property-drawer) (org-prepare-agenda-buffers, org-preview-latex-fragment) (org-speed-command-default-hook, org-check-for-hidden) (org-toggle-item, org-toggle-heading) (org-indent-line-function, org-set-autofill-regexps) (org-fill-paragraph, org-toggle-fixed-width-section) (org-yank-generic, org-yank-folding-would-swallow-text) (org-first-sibling-p, org-goto-sibling) (org-goto-first-child, org-show-entry): Use `org-outline-regexp' and `org-outline-regexp-bol'. * org-remember.el (org-remember-handler): Use `org-outline-regexp-bol'. * org-mouse.el (org-mouse-match-todo-keyword, org-mode-hook) (org-mouse-move-tree, org-mouse-transform-to-outline): Use `org-outline-regexp' and `org-outline-regexp-bol'. * org-macs.el (org-with-limited-levels) (org-get-limited-outline-regexp): Use `org-outline-regexp'. * org-indent.el (org-indent-outline-re) (org-indent-refresh-section, org-indent-refresh-to): Use `org-outline-regexp' and `org-outline-regexp-bol'. * org-html.el (org-export-as-html): Use `org-outline-regexp-bol'. * org-footnote.el (org-footnote-at-definition-p) (org-footnote-normalize): Use `org-outline-regexp' and `org-outline-regexp-bol'. * org-exp.el (org-export-preprocess-string): Don't redefine `outline-regexp'. * org-docbook.el (org-export-as-docbook): Use `org-outline-regexp-bol'. * org-colview.el (org-columns, org-columns-compute): Use `org-outline-regexp' and `org-outline-regexp-bol'. * org-colview-xemacs.el (org-columns, org-columns-compute): Use `org-outline-regexp-bol'. * org-clock.el (org-clock-insert-selection-line) (org-clock-in, org-clock-out, org-dblock-write:clocktable): Use `org-outline-regexp' and `org-outline-regexp-bol'. * org-ascii.el (org-export-as-ascii) (org-export-ascii-push-links): Use `org-outline-regexp' and `org-outline-regexp-bol'. * org-archive.el (org-archive-to-archive-sibling) (org-archive-all-done): Use `org-outline-regexp' and `org-outline-regexp-bol'. * org-agenda.el (org-agenda, org-search-view) (org-agenda-list-stuck-projects, org-agenda-get-timestamps) (org-agenda-get-progress, org-agenda-get-blocks): Use `org-outline-regexp' and `org-outline-regexp-bol'.
2011-07-17 19:17:08 +00:00
(while (not (or (eobp) (looking-at org-outline-regexp)))
2008-01-31 10:32:52 +00:00
(when (and (looking-at org-mouse-plain-list-regexp)
(eq minlevel (- (match-end 1) (match-beginning 1))))
(replace-match replace-text))
(forward-line))))
2008-01-31 10:36:18 +00:00
(defvar org-mouse-cmd) ;dynamically scoped from `org-with-remote-undo'.
2008-01-31 10:36:18 +00:00
2008-01-31 10:32:52 +00:00
(defun org-mouse-do-remotely (command)
;; (org-agenda-check-no-diary)
2008-01-31 10:32:52 +00:00
(when (get-text-property (point) 'org-marker)
(let* ((anticol (- (line-end-position) (point)))
2008-01-31 10:32:52 +00:00
(marker (get-text-property (point) 'org-marker))
(buffer (marker-buffer marker))
(pos (marker-position marker))
(hdmarker (get-text-property (point) 'org-hd-marker))
(buffer-read-only nil)
(newhead "--- removed ---")
(org-mouse-direct nil)
(org-mouse-main-buffer (current-buffer)))
(when (eq (with-current-buffer buffer major-mode) 'org-mode)
(let ((endmarker (with-current-buffer buffer
(org-end-of-subtree nil t)
(unless (eobp) (forward-char 1))
(point-marker))))
2008-01-31 10:33:46 +00:00
(org-with-remote-undo buffer
(with-current-buffer buffer
(widen)
(goto-char pos)
(org-fold-show-hidden-entry)
2008-01-31 10:33:46 +00:00
(save-excursion
(and (outline-next-heading)
(org-fold-heading nil))) ; show the next heading
2008-01-31 10:33:46 +00:00
(org-back-to-heading)
(setq marker (point-marker))
(goto-char (max (line-beginning-position) (- (line-end-position) anticol)))
2008-01-31 10:33:46 +00:00
(funcall command)
(message "_cmd: %S" org-mouse-cmd)
2008-01-31 10:33:46 +00:00
(message "this-command: %S" this-command)
(unless (eq (marker-position marker) (marker-position endmarker))
(setq newhead (org-get-heading))))
2008-04-24 08:29:47 +00:00
2008-01-31 10:33:46 +00:00
(beginning-of-line 1)
2008-01-31 10:32:52 +00:00
(save-excursion
2008-01-31 10:33:46 +00:00
(org-agenda-change-all-lines newhead hdmarker 'fixface))))
2008-01-31 10:32:52 +00:00
t))))
(defun org-mouse-agenda-context-menu (&optional _event)
2008-01-31 10:32:52 +00:00
(or (org-mouse-do-remotely 'org-mouse-context-menu)
2008-04-24 08:29:47 +00:00
(popup-menu
2008-01-31 10:32:52 +00:00
'("Agenda"
("Agenda Files")
"--"
2008-01-31 10:33:46 +00:00
["Undo" (progn (message "last command: %S" last-command) (setq this-command 'org-agenda-undo) (org-agenda-undo))
2008-04-24 08:29:47 +00:00
:visible (if (eq last-command 'org-agenda-undo)
2008-01-31 10:33:46 +00:00
org-agenda-pending-undo-list
org-agenda-undo-list)]
2008-01-31 10:32:52 +00:00
["Rebuild Buffer" org-agenda-redo t]
2008-04-24 08:29:47 +00:00
["New Diary Entry"
org-agenda-diary-entry (org-agenda-check-type nil 'agenda) t]
2008-01-31 10:32:52 +00:00
"--"
2008-04-24 08:29:47 +00:00
["Goto Today" org-agenda-goto-today
(org-agenda-check-type nil 'agenda) t]
2008-04-24 08:29:47 +00:00
["Display Calendar" org-agenda-goto-calendar
(org-agenda-check-type nil 'agenda) t]
2008-01-31 10:32:52 +00:00
("Calendar Commands"
2008-04-24 08:29:47 +00:00
["Phases of the Moon" org-agenda-phases-of-moon
(org-agenda-check-type nil 'agenda)]
2008-04-24 08:29:47 +00:00
["Sunrise/Sunset" org-agenda-sunrise-sunset
(org-agenda-check-type nil 'agenda)]
2008-04-24 08:29:47 +00:00
["Holidays" org-agenda-holidays
(org-agenda-check-type nil 'agenda)]
2008-04-24 08:29:47 +00:00
["Convert" org-agenda-convert-date
(org-agenda-check-type nil 'agenda)]
2008-01-31 10:32:52 +00:00
"--"
["Create iCalendar file" org-icalendar-combine-agenda-files t])
2008-01-31 10:32:52 +00:00
"--"
2008-04-24 08:29:47 +00:00
["Day View" org-agenda-day-view
2008-01-31 10:32:52 +00:00
:active (org-agenda-check-type nil 'agenda)
org-agenda: rework ndays and span handling * org-agenda.el (org-agenda-custom-commands-local-options): Allow org-agenda-span to be a symbol. (org-agenda-ndays): Make obsolete. (org-agenda-span): New variable superseding org-agenda-ndays. (org-agenda-menu): Use org-agenda-current-span. (org-agenda-current-span): New local variable storing current span. (org-agenda-list): Take a span instead of ndays as argument. This function is now responsible for computing the ndays based on span. (org-agenda-ndays-to-span): Return span only if number of days really matches. (org-agenda-span-to-ndays): New function. (org-agenda-manipulate-query): Use org-agenda-compute-starting-span. (org-agenda-goto-today): Use org-agenda-compute-starting-span. (org-agenda-later): Do not give compute a new span, use the current one. (org-agenda-day-view, org-agenda-week-view) (org-agenda-month-view, org-agenda-year-view): Stop touching org-agenda-ndays. (org-agenda-change-time-span): Only compute starting-span. (org-agenda-compute-starting-span): New function derived from the old org-agenda-compute-time-span. (org-agenda-set-mode-name): Compute mode based on org-agenda-current-span. (org-agenda-span-name): New function. * org-mouse.el: Replace Replace org-agenda-ndays by org-agenda-current-span. * org.texi, orgguide.texi: Replace org-agenda-ndays by org-agenda-span. Add a paragraph about org-agenda-span and say that org-agenda-ndays is now deprecated. This patch is pretty huge, so I'll give a bit of context about it. I'm weird, but I used org-agenda-ndays set to 14. Unfortunately, this settings was interpreted as a month view. Pressing 'f' key to see later, would show me the next month, which was not at all what I wanted. On the same idea, day view or week view would change my org-agenda-ndays settings, which I think is not a good idea. Changing user setting is *bad*. :-) So I rewrote the things this way: - Rename org-agenda-span to org-agenda-current-span Which has the same meaning has before, except it can be numeric. - Rename org-agenda-ndays to org-agenda-span I think the name is better choosen. You can set it to a symbol instead of only a numeric value. That means you can set it to 'month and it will show you the number of days of the current month in your agenda. Better than 30. But you can still set it to 30, or 31, or whatever you want. - Do not change org-agenda-span. Never. - Use org-agenda-current-span for navigation. That means if you press 'f', it will shows you really the next org-agenda-current-span ndays, and not something based on "I think you want a weekly view".
2010-12-03 16:50:50 +00:00
:style radio :selected (eq org-agenda-current-span 'day)]
2008-04-24 08:29:47 +00:00
["Week View" org-agenda-week-view
2008-01-31 10:32:52 +00:00
:active (org-agenda-check-type nil 'agenda)
org-agenda: rework ndays and span handling * org-agenda.el (org-agenda-custom-commands-local-options): Allow org-agenda-span to be a symbol. (org-agenda-ndays): Make obsolete. (org-agenda-span): New variable superseding org-agenda-ndays. (org-agenda-menu): Use org-agenda-current-span. (org-agenda-current-span): New local variable storing current span. (org-agenda-list): Take a span instead of ndays as argument. This function is now responsible for computing the ndays based on span. (org-agenda-ndays-to-span): Return span only if number of days really matches. (org-agenda-span-to-ndays): New function. (org-agenda-manipulate-query): Use org-agenda-compute-starting-span. (org-agenda-goto-today): Use org-agenda-compute-starting-span. (org-agenda-later): Do not give compute a new span, use the current one. (org-agenda-day-view, org-agenda-week-view) (org-agenda-month-view, org-agenda-year-view): Stop touching org-agenda-ndays. (org-agenda-change-time-span): Only compute starting-span. (org-agenda-compute-starting-span): New function derived from the old org-agenda-compute-time-span. (org-agenda-set-mode-name): Compute mode based on org-agenda-current-span. (org-agenda-span-name): New function. * org-mouse.el: Replace Replace org-agenda-ndays by org-agenda-current-span. * org.texi, orgguide.texi: Replace org-agenda-ndays by org-agenda-span. Add a paragraph about org-agenda-span and say that org-agenda-ndays is now deprecated. This patch is pretty huge, so I'll give a bit of context about it. I'm weird, but I used org-agenda-ndays set to 14. Unfortunately, this settings was interpreted as a month view. Pressing 'f' key to see later, would show me the next month, which was not at all what I wanted. On the same idea, day view or week view would change my org-agenda-ndays settings, which I think is not a good idea. Changing user setting is *bad*. :-) So I rewrote the things this way: - Rename org-agenda-span to org-agenda-current-span Which has the same meaning has before, except it can be numeric. - Rename org-agenda-ndays to org-agenda-span I think the name is better choosen. You can set it to a symbol instead of only a numeric value. That means you can set it to 'month and it will show you the number of days of the current month in your agenda. Better than 30. But you can still set it to 30, or 31, or whatever you want. - Do not change org-agenda-span. Never. - Use org-agenda-current-span for navigation. That means if you press 'f', it will shows you really the next org-agenda-current-span ndays, and not something based on "I think you want a weekly view".
2010-12-03 16:50:50 +00:00
:style radio :selected (eq org-agenda-current-span 'week)]
2008-01-31 10:32:52 +00:00
"--"
["Show Logbook entries" org-agenda-log-mode
2008-04-24 08:29:47 +00:00
:style toggle :selected org-agenda-show-log
:active (org-agenda-check-type nil 'agenda)]
2008-01-31 10:32:52 +00:00
["Include Diary" org-agenda-toggle-diary
2008-04-24 08:29:47 +00:00
:style toggle :selected org-agenda-include-diary
2008-01-31 10:32:52 +00:00
:active (org-agenda-check-type nil 'agenda)]
["Use Time Grid" org-agenda-toggle-time-grid
:style toggle :selected org-agenda-use-time-grid
:active (org-agenda-check-type nil 'agenda)]
["Follow Mode" org-agenda-follow-mode
:style toggle :selected org-agenda-follow-mode]
"--"
["Quit" org-agenda-quit t]
["Exit and Release Buffers" org-agenda-exit t]
))))
2008-01-31 10:33:13 +00:00
(defun org-mouse-get-gesture (event)
(let ((startxy (posn-x-y (event-start event)))
(endxy (posn-x-y (event-end event))))
(if (< (car startxy) (car endxy)) :right :left)))
; (setq org-agenda-mode-hook nil)
(defvar org-agenda-mode-map)
2008-04-24 08:29:47 +00:00
(add-hook 'org-agenda-mode-hook
(lambda ()
(setq org-mouse-context-menu-function #'org-mouse-agenda-context-menu)
(org-defkey org-agenda-mode-map [mouse-3] #'org-mouse-show-context-menu)
(org-defkey org-agenda-mode-map [down-mouse-3] #'org-mouse-move-tree-start)
(org-defkey org-agenda-mode-map [C-mouse-4] #'org-agenda-earlier)
(org-defkey org-agenda-mode-map [C-mouse-5] #'org-agenda-later)
(org-defkey org-agenda-mode-map [drag-mouse-3]
(lambda (event) (interactive "e")
(cl-case (org-mouse-get-gesture event)
(:left (org-agenda-earlier 1))
(:right (org-agenda-later 1)))))))
2008-01-31 10:32:52 +00:00
(provide 'org-mouse)
2008-03-04 12:04:31 +00:00
;;; org-mouse.el ends here