org-mouse.el 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  1. ;;; org-mouse.el --- Better mouse support for org-mode
  2. ;; Copyright (C) 2006-2011 Free Software Foundation
  3. ;;
  4. ;; Author: Piotr Zielinski <piotr dot zielinski at gmail dot com>
  5. ;; Maintainer: Carsten Dominik <carsten at orgmode dot org>
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;;
  23. ;; Org-mouse provides mouse support for org-mode.
  24. ;;
  25. ;; http://orgmode.org
  26. ;;
  27. ;; Org-mouse implements the following features:
  28. ;; * following links with the left mouse button (in Emacs 22)
  29. ;; * subtree expansion/collapse (org-cycle) with the left mouse button
  30. ;; * several context menus on the right mouse button:
  31. ;; + general text
  32. ;; + headlines
  33. ;; + timestamps
  34. ;; + priorities
  35. ;; + links
  36. ;; + tags
  37. ;; * promoting/demoting/moving subtrees with mouse-3
  38. ;; + if the drag starts and ends in the same line then promote/demote
  39. ;; + otherwise move the subtree
  40. ;;
  41. ;; Use
  42. ;; ---
  43. ;;
  44. ;; To use this package, put the following line in your .emacs:
  45. ;;
  46. ;; (require 'org-mouse)
  47. ;;
  48. ;; FIXME:
  49. ;; + deal with folding / unfolding issues
  50. ;; TODO (This list is only theoretical, if you'd like to have some
  51. ;; feature implemented or a bug fix please send me an email, even if
  52. ;; something similar appears in the list below. This will help me get
  53. ;; the priorities right.):
  54. ;;
  55. ;; + org-store-link, insert link
  56. ;; + org tables
  57. ;; + occur with the current word/tag (same menu item)
  58. ;; + ctrl-c ctrl-c, for example, renumber the current list
  59. ;; + internal links
  60. ;; Please email the maintainer with new feature suggestions / bugs
  61. ;; History:
  62. ;;
  63. ;; Since version 5.10: Changes are listed in the general org-mode docs.
  64. ;;
  65. ;; Version 5.09;; + Version number synchronization with Org-mode.
  66. ;;
  67. ;; Version 0.25
  68. ;; + made compatible with org-mode 4.70 (thanks to Carsten for the patch)
  69. ;;
  70. ;; Version 0.24
  71. ;; + minor changes to the table menu
  72. ;;
  73. ;; Version 0.23
  74. ;; + preliminary support for tables and calculation marks
  75. ;; + context menu support for org-agenda-undo & org-sort-entries
  76. ;;
  77. ;; Version 0.22
  78. ;; + handles undo support for the agenda buffer (requires org-mode >=4.58)
  79. ;;
  80. ;; Version 0.21
  81. ;; + selected text activates its context menu
  82. ;; + shift-middleclick or right-drag inserts the text from the clipboard in the form of a link
  83. ;;
  84. ;; Version 0.20
  85. ;; + the new "TODO Status" submenu replaces the "Cycle TODO" menu item
  86. ;; + the TODO menu can now list occurrences of a specific TODO keyword
  87. ;; + #+STARTUP line is now recognized
  88. ;;
  89. ;; Version 0.19
  90. ;; + added support for dragging URLs to the org-buffer
  91. ;;
  92. ;; Version 0.18
  93. ;; + added support for agenda blocks
  94. ;;
  95. ;; Version 0.17
  96. ;; + toggle checkboxes with a single click
  97. ;;
  98. ;; Version 0.16
  99. ;; + added support for checkboxes
  100. ;;
  101. ;; Version 0.15
  102. ;; + org-mode now works with the Agenda buffer as well
  103. ;;
  104. ;; Version 0.14
  105. ;; + added a menu option that converts plain list items to outline items
  106. ;;
  107. ;; Version 0.13
  108. ;; + "Insert Heading" now inserts a sibling heading if the point is
  109. ;; on "***" and a child heading otherwise
  110. ;;
  111. ;; Version 0.12
  112. ;; + compatible with Emacs 21
  113. ;; + custom agenda commands added to the main menu
  114. ;; + moving trees should now work between windows in the same frame
  115. ;;
  116. ;; Version 0.11
  117. ;; + fixed org-mouse-at-link (thanks to Carsten)
  118. ;; + removed [follow-link] bindings
  119. ;;
  120. ;; Version 0.10
  121. ;; + added a menu option to remove highlights
  122. ;; + compatible with org-mode 4.21 now
  123. ;;
  124. ;; Version 0.08:
  125. ;; + trees can be moved/promoted/demoted by dragging with the right
  126. ;; mouse button (mouse-3)
  127. ;; + small changes in the above function
  128. ;;
  129. ;; Versions 0.01 -- 0.07: (I don't remember)
  130. ;;; Code:
  131. (eval-when-compile (require 'cl))
  132. (require 'org)
  133. (defvar org-agenda-allow-remote-undo)
  134. (defvar org-agenda-undo-list)
  135. (defvar org-agenda-custom-commands)
  136. (declare-function org-agenda-change-all-lines "org-agenda"
  137. (newhead hdmarker &optional fixface just-this))
  138. (declare-function org-verify-change-for-undo "org-agenda" (l1 l2))
  139. (declare-function org-apply-on-list "org-list" (function init-value &rest args))
  140. (declare-function org-agenda-earlier "org-agenda" (arg))
  141. (declare-function org-agenda-later "org-agenda" (arg))
  142. (defvar org-mouse-plain-list-regexp "\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) "
  143. "Regular expression that matches a plain list.")
  144. (defvar org-mouse-direct t
  145. "Internal variable indicating whether the current action is direct.
  146. If t, then the current action has been invoked directly through the buffer
  147. it is intended to operate on. If nil, then the action has been invoked
  148. indirectly, for example, through the agenda buffer.")
  149. (defgroup org-mouse nil
  150. "Mouse support for org-mode."
  151. :tag "Org Mouse"
  152. :group 'org)
  153. (defcustom org-mouse-punctuation ":"
  154. "Punctuation used when inserting text by drag and drop."
  155. :group 'org-mouse
  156. :type 'string)
  157. (defcustom org-mouse-features
  158. '(context-menu yank-link activate-stars activate-bullets activate-checkboxes)
  159. "The features of org-mouse that should be activated.
  160. Changing this variable requires a restart of Emacs to get activated."
  161. :group 'org-mouse
  162. :type '(set :greedy t
  163. (const :tag "Mouse-3 shows context menu" context-menu)
  164. (const :tag "C-mouse-1 and mouse-3 move trees" move-tree)
  165. (const :tag "S-mouse-2 and drag-mouse-3 yank link" yank-link)
  166. (const :tag "Activate headline stars" activate-stars)
  167. (const :tag "Activate item bullets" activate-bullets)
  168. (const :tag "Activate checkboxes" activate-checkboxes)))
  169. (defun org-mouse-re-search-line (regexp)
  170. "Search the current line for a given regular expression."
  171. (beginning-of-line)
  172. (re-search-forward regexp (point-at-eol) t))
  173. (defun org-mouse-end-headline ()
  174. "Go to the end of current headline (ignoring tags)."
  175. (interactive)
  176. (end-of-line)
  177. (skip-chars-backward "\t ")
  178. (when (org-looking-back ":[A-Za-z]+:")
  179. (skip-chars-backward ":A-Za-z")
  180. (skip-chars-backward "\t ")))
  181. (defvar org-mouse-context-menu-function nil
  182. "Function to create the context menu.
  183. The value of this variable is the function invoked by
  184. `org-mouse-context-menu' as the context menu.")
  185. (make-variable-buffer-local 'org-mouse-context-menu-function)
  186. (defun org-mouse-show-context-menu (event prefix)
  187. "Invoke the context menu.
  188. If the value of `org-mouse-context-menu-function' is a function, then
  189. this function is called. Otherwise, the current major mode menu is used."
  190. (interactive "@e \nP")
  191. (if (and (= (event-click-count event) 1)
  192. (or (not mark-active)
  193. (sit-for (/ double-click-time 1000.0))))
  194. (progn
  195. (select-window (posn-window (event-start event)))
  196. (when (not (org-mouse-mark-active))
  197. (goto-char (posn-point (event-start event)))
  198. (when (not (eolp)) (save-excursion (run-hooks 'post-command-hook)))
  199. (let ((redisplay-dont-pause t))
  200. (sit-for 0)))
  201. (if (functionp org-mouse-context-menu-function)
  202. (funcall org-mouse-context-menu-function event)
  203. (if (fboundp 'mouse-menu-major-mode-map)
  204. (popup-menu (mouse-menu-major-mode-map) event prefix)
  205. (org-no-warnings ; don't warn about fallback, obsolete since 23.1
  206. (mouse-major-mode-menu event prefix)))))
  207. (setq this-command 'mouse-save-then-kill)
  208. (mouse-save-then-kill event)))
  209. (defun org-mouse-line-position ()
  210. "Return `:beginning' or `:middle' or `:end', depending on the point position.
  211. If the point is at the end of the line, return `:end'.
  212. If the point is separated from the beginning of the line only by white
  213. space and *'s (`org-mouse-bolp'), return `:beginning'. Otherwise,
  214. return `:middle'."
  215. (cond
  216. ((eolp) :end)
  217. ((org-mouse-bolp) :beginning)
  218. (t :middle)))
  219. (defun org-mouse-empty-line ()
  220. "Return non-nil iff the line contains only white space."
  221. (save-excursion (beginning-of-line) (looking-at "[ \t]*$")))
  222. (defun org-mouse-next-heading ()
  223. "Go to the next heading.
  224. If there is none, ensure that the point is at the beginning of an empty line."
  225. (unless (outline-next-heading)
  226. (beginning-of-line)
  227. (unless (org-mouse-empty-line)
  228. (end-of-line)
  229. (newline))))
  230. (defun org-mouse-insert-heading ()
  231. "Insert a new heading, as `org-insert-heading'.
  232. If the point is at the :beginning (`org-mouse-line-position') of the line,
  233. insert the new heading before the current line. Otherwise, insert it
  234. after the current heading."
  235. (interactive)
  236. (case (org-mouse-line-position)
  237. (:beginning (beginning-of-line)
  238. (org-insert-heading))
  239. (t (org-mouse-next-heading)
  240. (org-insert-heading))))
  241. (defun org-mouse-timestamp-today (&optional shift units)
  242. "Change the timestamp into SHIFT UNITS in the future.
  243. For the acceptable UNITS, see `org-timestamp-change'."
  244. (interactive)
  245. (flet ((org-read-date (&rest rest) (current-time)))
  246. (org-time-stamp nil))
  247. (when shift
  248. (org-timestamp-change shift units)))
  249. (defun org-mouse-keyword-menu (keywords function &optional selected itemformat)
  250. "A helper function.
  251. Returns a menu fragment consisting of KEYWORDS. When a keyword
  252. is selected by the user, FUNCTION is called with the selected
  253. keyword as the only argument.
  254. If SELECTED is nil, then all items are normal menu items. If
  255. SELECTED is a function, then each item is a checkbox, which is
  256. enabled for a given keyword iff (funcall SELECTED keyword) return
  257. non-nil. If SELECTED is neither nil nor a function, then the
  258. items are radio buttons. A radio button is enabled for the
  259. keyword `equal' to SELECTED.
  260. ITEMFORMAT governs formatting of the elements of KEYWORDS. If it
  261. is a function, it is invoked with the keyword as the only
  262. argument. If it is a string, it is interpreted as the format
  263. string to (format ITEMFORMAT keyword). If it is neither a string
  264. nor a function, elements of KEYWORDS are used directly."
  265. (mapcar
  266. `(lambda (keyword)
  267. (vector (cond
  268. ((functionp ,itemformat) (funcall ,itemformat keyword))
  269. ((stringp ,itemformat) (format ,itemformat keyword))
  270. (t keyword))
  271. (list 'funcall ,function keyword)
  272. :style (cond
  273. ((null ,selected) t)
  274. ((functionp ,selected) 'toggle)
  275. (t 'radio))
  276. :selected (if (functionp ,selected)
  277. (and (funcall ,selected keyword) t)
  278. (equal ,selected keyword))))
  279. keywords))
  280. (defun org-mouse-remove-match-and-spaces ()
  281. "Remove the match, make just one space around the point."
  282. (interactive)
  283. (replace-match "")
  284. (just-one-space))
  285. (defvar rest)
  286. (defun org-mouse-replace-match-and-surround (newtext &optional fixedcase
  287. literal string subexp)
  288. "The same as `replace-match', but surrounds the replacement with spaces."
  289. (apply 'replace-match rest)
  290. (save-excursion
  291. (goto-char (match-beginning (or subexp 0)))
  292. (just-one-space)
  293. (goto-char (match-end (or subexp 0)))
  294. (just-one-space)))
  295. (defun org-mouse-keyword-replace-menu (keywords &optional group itemformat
  296. nosurround)
  297. "A helper function.
  298. Returns a menu fragment consisting of KEYWORDS. When a keyword
  299. is selected, group GROUP of the current match is replaced by the
  300. keyword. The method ensures that both ends of the replacement
  301. are separated from the rest of the text in the buffer by
  302. individual spaces (unless NOSURROUND is non-nil).
  303. The final entry of the menu is always \"None\", which removes the
  304. match.
  305. ITEMFORMAT governs formatting of the elements of KEYWORDS. If it
  306. is a function, it is invoked with the keyword as the only
  307. argument. If it is a string, it is interpreted as the format
  308. string to (format ITEMFORMAT keyword). If it is neither a string
  309. nor a function, elements of KEYWORDS are used directly."
  310. (setq group (or group 0))
  311. (let ((replace (org-mouse-match-closure
  312. (if nosurround 'replace-match
  313. 'org-mouse-replace-match-and-surround))))
  314. (append
  315. (org-mouse-keyword-menu
  316. keywords
  317. `(lambda (keyword) (funcall ,replace keyword t t nil ,group))
  318. (match-string group)
  319. itemformat)
  320. `(["None" org-mouse-remove-match-and-spaces
  321. :style radio
  322. :selected ,(not (member (match-string group) keywords))]))))
  323. (defun org-mouse-show-headlines ()
  324. "Change the visibility of the current org buffer to only show headlines."
  325. (interactive)
  326. (let ((this-command 'org-cycle)
  327. (last-command 'org-cycle)
  328. (org-cycle-global-status nil))
  329. (org-cycle '(4))
  330. (org-cycle '(4))))
  331. (defun org-mouse-show-overview ()
  332. "Change visibility of current org buffer to first-level headlines only."
  333. (interactive)
  334. (let ((org-cycle-global-status nil))
  335. (org-cycle '(4))))
  336. (defun org-mouse-set-priority (priority)
  337. "Set the priority of the current headline to PRIORITY."
  338. (flet ((read-char-exclusive () priority))
  339. (org-priority)))
  340. (defvar org-mouse-priority-regexp "\\[#\\([A-Z]\\)\\]"
  341. "Regular expression matching the priority indicator.
  342. Differs from `org-priority-regexp' in that it doesn't contain the
  343. leading '.*?'.")
  344. (defun org-mouse-get-priority (&optional default)
  345. "Return the priority of the current headline.
  346. DEFAULT is returned if no priority is given in the headline."
  347. (save-excursion
  348. (if (org-mouse-re-search-line org-mouse-priority-regexp)
  349. (match-string 1)
  350. (when default (char-to-string org-default-priority)))))
  351. ;; (defun org-mouse-at-link ()
  352. ;; (and (eq (get-text-property (point) 'face) 'org-link)
  353. ;; (save-excursion
  354. ;; (goto-char (previous-single-property-change (point) 'face))
  355. ;; (or (looking-at org-bracket-link-regexp)
  356. ;; (looking-at org-angle-link-re)
  357. ;; (looking-at org-plain-link-re)))))
  358. (defun org-mouse-delete-timestamp ()
  359. "Deletes the current timestamp as well as the preceding keyword.
  360. SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
  361. (when (or (org-at-date-range-p) (org-at-timestamp-p))
  362. (replace-match "") ; delete the timestamp
  363. (skip-chars-backward " :A-Z")
  364. (when (looking-at " *[A-Z][A-Z]+:")
  365. (replace-match ""))))
  366. (defun org-mouse-looking-at (regexp skipchars &optional movechars)
  367. (save-excursion
  368. (let ((point (point)))
  369. (if (looking-at regexp) t
  370. (skip-chars-backward skipchars)
  371. (forward-char (or movechars 0))
  372. (when (looking-at regexp)
  373. (> (match-end 0) point))))))
  374. (defun org-mouse-priority-list ()
  375. (loop for priority from ?A to org-lowest-priority
  376. collect (char-to-string priority)))
  377. (defun org-mouse-todo-menu (state)
  378. "Create the menu with TODO keywords."
  379. (append
  380. (let ((kwds org-todo-keywords-1))
  381. (org-mouse-keyword-menu
  382. kwds
  383. `(lambda (kwd) (org-todo kwd))
  384. (lambda (kwd) (equal state kwd))))))
  385. (defun org-mouse-tag-menu () ;todo
  386. "Create the tags menu."
  387. (append
  388. (let ((tags (org-get-tags)))
  389. (org-mouse-keyword-menu
  390. (sort (mapcar 'car (org-get-buffer-tags)) 'string-lessp)
  391. `(lambda (tag)
  392. (org-mouse-set-tags
  393. (sort (if (member tag (quote ,tags))
  394. (delete tag (quote ,tags))
  395. (cons tag (quote ,tags)))
  396. 'string-lessp)))
  397. `(lambda (tag) (member tag (quote ,tags)))
  398. ))
  399. '("--"
  400. ["Align Tags Here" (org-set-tags nil t) t]
  401. ["Align Tags in Buffer" (org-set-tags t t) t]
  402. ["Set Tags ..." (org-set-tags) t])))
  403. (defun org-mouse-set-tags (tags)
  404. (save-excursion
  405. ;; remove existing tags first
  406. (beginning-of-line)
  407. (when (org-mouse-re-search-line ":\\(\\([A-Za-z_]+:\\)+\\)")
  408. (replace-match ""))
  409. ;; set new tags if any
  410. (when tags
  411. (end-of-line)
  412. (insert " :" (mapconcat 'identity tags ":") ":")
  413. (org-set-tags nil t))))
  414. (defun org-mouse-insert-checkbox ()
  415. (interactive)
  416. (and (org-at-item-p)
  417. (goto-char (match-end 0))
  418. (unless (org-at-item-checkbox-p)
  419. (delete-horizontal-space)
  420. (insert " [ ] "))))
  421. (defun org-mouse-agenda-type (type)
  422. (case type
  423. ('tags "Tags: ")
  424. ('todo "TODO: ")
  425. ('tags-tree "Tags tree: ")
  426. ('todo-tree "TODO tree: ")
  427. ('occur-tree "Occur tree: ")
  428. (t "Agenda command ???")))
  429. (defun org-mouse-list-options-menu (alloptions &optional function)
  430. (let ((options (save-match-data
  431. (split-string (match-string-no-properties 1)))))
  432. (print options)
  433. (loop for name in alloptions
  434. collect
  435. (vector name
  436. `(progn
  437. (replace-match
  438. (mapconcat 'identity
  439. (sort (if (member ',name ',options)
  440. (delete ',name ',options)
  441. (cons ',name ',options))
  442. 'string-lessp)
  443. " ")
  444. nil nil nil 1)
  445. (when (functionp ',function) (funcall ',function)))
  446. :style 'toggle
  447. :selected (and (member name options) t)))))
  448. (defun org-mouse-clip-text (text maxlength)
  449. (if (> (length text) maxlength)
  450. (concat (substring text 0 (- maxlength 3)) "...")
  451. text))
  452. (defun org-mouse-popup-global-menu ()
  453. (popup-menu
  454. `("Main Menu"
  455. ["Show Overview" org-mouse-show-overview t]
  456. ["Show Headlines" org-mouse-show-headlines t]
  457. ["Show All" show-all t]
  458. ["Remove Highlights" org-remove-occur-highlights
  459. :visible org-occur-highlights]
  460. "--"
  461. ["Check Deadlines"
  462. (if (functionp 'org-check-deadlines-and-todos)
  463. (org-check-deadlines-and-todos org-deadline-warning-days)
  464. (org-check-deadlines org-deadline-warning-days)) t]
  465. ["Check TODOs" org-show-todo-tree t]
  466. ("Check Tags"
  467. ,@(org-mouse-keyword-menu
  468. (sort (mapcar 'car (org-get-buffer-tags)) 'string-lessp)
  469. #'(lambda (tag) (org-tags-sparse-tree nil tag)))
  470. "--"
  471. ["Custom Tag ..." org-tags-sparse-tree t])
  472. ["Check Phrase ..." org-occur]
  473. "--"
  474. ["Display Agenda" org-agenda-list t]
  475. ["Display Timeline" org-timeline t]
  476. ["Display TODO List" org-todo-list t]
  477. ("Display Tags"
  478. ,@(org-mouse-keyword-menu
  479. (sort (mapcar 'car (org-get-buffer-tags)) 'string-lessp)
  480. #'(lambda (tag) (org-tags-view nil tag)))
  481. "--"
  482. ["Custom Tag ..." org-tags-view t])
  483. ["Display Calendar" org-goto-calendar t]
  484. "--"
  485. ,@(org-mouse-keyword-menu
  486. (mapcar 'car org-agenda-custom-commands)
  487. #'(lambda (key)
  488. (eval `(flet ((read-char-exclusive () (string-to-char ,key)))
  489. (org-agenda nil))))
  490. nil
  491. #'(lambda (key)
  492. (let ((entry (assoc key org-agenda-custom-commands)))
  493. (org-mouse-clip-text
  494. (cond
  495. ((stringp (nth 1 entry)) (nth 1 entry))
  496. ((stringp (nth 2 entry))
  497. (concat (org-mouse-agenda-type (nth 1 entry))
  498. (nth 2 entry)))
  499. (t "Agenda Command '%s'"))
  500. 30))))
  501. "--"
  502. ["Delete Blank Lines" delete-blank-lines
  503. :visible (org-mouse-empty-line)]
  504. ["Insert Checkbox" org-mouse-insert-checkbox
  505. :visible (and (org-at-item-p) (not (org-at-item-checkbox-p)))]
  506. ["Insert Checkboxes"
  507. (org-mouse-for-each-item 'org-mouse-insert-checkbox)
  508. :visible (and (org-at-item-p) (not (org-at-item-checkbox-p)))]
  509. ["Plain List to Outline" org-mouse-transform-to-outline
  510. :visible (org-at-item-p)])))
  511. (defun org-mouse-get-context (contextlist context)
  512. (let ((contextdata (assq context contextlist)))
  513. (when contextdata
  514. (save-excursion
  515. (goto-char (second contextdata))
  516. (re-search-forward ".*" (third contextdata))))))
  517. (defun org-mouse-for-each-item (funct)
  518. ;; Functions called by `org-apply-on-list' need an argument
  519. (let ((wrap-fun (lambda (c) (funcall funct))))
  520. (when (ignore-errors (goto-char (org-in-item-p)))
  521. (save-excursion (org-apply-on-list wrap-fun nil)))))
  522. (defun org-mouse-bolp ()
  523. "Return true if there only spaces, tabs, and '*' before point.
  524. This means, between the beginning of line and the point."
  525. (save-excursion
  526. (skip-chars-backward " \t*") (bolp)))
  527. (defun org-mouse-insert-item (text)
  528. (case (org-mouse-line-position)
  529. (:beginning ; insert before
  530. (beginning-of-line)
  531. (looking-at "[ \t]*")
  532. (open-line 1)
  533. (org-indent-to-column (- (match-end 0) (match-beginning 0)))
  534. (insert "+ "))
  535. (:middle ; insert after
  536. (end-of-line)
  537. (newline t)
  538. (indent-relative)
  539. (insert "+ "))
  540. (:end ; insert text here
  541. (skip-chars-backward " \t")
  542. (kill-region (point) (point-at-eol))
  543. (unless (org-looking-back org-mouse-punctuation)
  544. (insert (concat org-mouse-punctuation " ")))))
  545. (insert text)
  546. (beginning-of-line))
  547. (defadvice dnd-insert-text (around org-mouse-dnd-insert-text activate)
  548. (if (eq major-mode 'org-mode)
  549. (org-mouse-insert-item text)
  550. ad-do-it))
  551. (defadvice dnd-open-file (around org-mouse-dnd-open-file activate)
  552. (if (eq major-mode 'org-mode)
  553. (org-mouse-insert-item uri)
  554. ad-do-it))
  555. (defun org-mouse-match-closure (function)
  556. (let ((match (match-data t)))
  557. `(lambda (&rest rest)
  558. (save-match-data
  559. (set-match-data ',match)
  560. (apply ',function rest)))))
  561. (defun org-mouse-match-todo-keyword ()
  562. (save-excursion
  563. (org-back-to-heading)
  564. (if (looking-at org-outline-regexp) (goto-char (match-end 0)))
  565. (or (looking-at (concat " +" org-todo-regexp " *"))
  566. (looking-at " \\( *\\)"))))
  567. (defun org-mouse-yank-link (click)
  568. (interactive "e")
  569. ;; Give temporary modes such as isearch a chance to turn off.
  570. (run-hooks 'mouse-leave-buffer-hook)
  571. (mouse-set-point click)
  572. (setq mouse-selection-click-count 0)
  573. (delete-horizontal-space)
  574. (insert-for-yank (concat " [[" (current-kill 0) "]] ")))
  575. (defun org-mouse-context-menu (&optional event)
  576. (let ((stamp-prefixes (list org-deadline-string org-scheduled-string))
  577. (contextlist (org-context)))
  578. (flet ((get-context (context) (org-mouse-get-context contextlist context)))
  579. (cond
  580. ((org-mouse-mark-active)
  581. (let ((region-string (buffer-substring (region-beginning) (region-end))))
  582. (popup-menu
  583. `(nil
  584. ["Sparse Tree" (org-occur ',region-string)]
  585. ["Find in Buffer" (occur ',region-string)]
  586. ["Grep in Current Dir"
  587. (grep (format "grep -rnH -e '%s' *" ',region-string))]
  588. ["Grep in Parent Dir"
  589. (grep (format "grep -rnH -e '%s' ../*" ',region-string))]
  590. "--"
  591. ["Convert to Link"
  592. (progn (save-excursion (goto-char (region-beginning)) (insert "[["))
  593. (save-excursion (goto-char (region-end)) (insert "]]")))]
  594. ["Insert Link Here" (org-mouse-yank-link ',event)]))))
  595. ((save-excursion (beginning-of-line) (looking-at "#\\+STARTUP: \\(.*\\)"))
  596. (popup-menu
  597. `(nil
  598. ,@(org-mouse-list-options-menu (mapcar 'car org-startup-options)
  599. 'org-mode-restart))))
  600. ((or (eolp)
  601. (and (looking-at "\\( \\|\t\\)\\(+:[0-9a-zA-Z_:]+\\)?\\( \\|\t\\)+$")
  602. (org-looking-back " \\|\t")))
  603. (org-mouse-popup-global-menu))
  604. ((get-context :checkbox)
  605. (popup-menu
  606. '(nil
  607. ["Toggle" org-toggle-checkbox t]
  608. ["Remove" org-mouse-remove-match-and-spaces t]
  609. ""
  610. ["All Clear" (org-mouse-for-each-item
  611. (lambda ()
  612. (when (save-excursion (org-at-item-checkbox-p))
  613. (replace-match "[ ]"))))]
  614. ["All Set" (org-mouse-for-each-item
  615. (lambda ()
  616. (when (save-excursion (org-at-item-checkbox-p))
  617. (replace-match "[X]"))))]
  618. ["All Toggle" (org-mouse-for-each-item 'org-toggle-checkbox) t]
  619. ["All Remove" (org-mouse-for-each-item
  620. (lambda ()
  621. (when (save-excursion (org-at-item-checkbox-p))
  622. (org-mouse-remove-match-and-spaces))))]
  623. )))
  624. ((and (org-mouse-looking-at "\\b\\w+" "a-zA-Z0-9_")
  625. (member (match-string 0) org-todo-keywords-1))
  626. (popup-menu
  627. `(nil
  628. ,@(org-mouse-todo-menu (match-string 0))
  629. "--"
  630. ["Check TODOs" org-show-todo-tree t]
  631. ["List all TODO keywords" org-todo-list t]
  632. [,(format "List only %s" (match-string 0))
  633. (org-todo-list (match-string 0)) t]
  634. )))
  635. ((and (org-mouse-looking-at "\\b[A-Z]+:" "A-Z")
  636. (member (match-string 0) stamp-prefixes))
  637. (popup-menu
  638. `(nil
  639. ,@(org-mouse-keyword-replace-menu stamp-prefixes)
  640. "--"
  641. ["Check Deadlines" org-check-deadlines t]
  642. )))
  643. ((org-mouse-looking-at org-mouse-priority-regexp "[]A-Z#") ; priority
  644. (popup-menu `(nil ,@(org-mouse-keyword-replace-menu
  645. (org-mouse-priority-list) 1 "Priority %s" t))))
  646. ((get-context :link)
  647. (popup-menu
  648. '(nil
  649. ["Open" org-open-at-point t]
  650. ["Open in Emacs" (org-open-at-point t) t]
  651. "--"
  652. ["Copy link" (org-kill-new (match-string 0))]
  653. ["Cut link"
  654. (progn
  655. (kill-region (match-beginning 0) (match-end 0))
  656. (just-one-space))]
  657. "--"
  658. ["Grep for TODOs"
  659. (grep (format "grep -nH -i 'todo\\|fixme' %s*" (match-string 2)))]
  660. ; ["Paste file link" ((insert "file:") (yank))]
  661. )))
  662. ((org-mouse-looking-at ":\\([A-Za-z0-9_]+\\):" "A-Za-z0-9_" -1) ;tags
  663. (popup-menu
  664. `(nil
  665. [,(format "Display '%s'" (match-string 1))
  666. (org-tags-view nil ,(match-string 1))]
  667. [,(format "Sparse Tree '%s'" (match-string 1))
  668. (org-tags-sparse-tree nil ,(match-string 1))]
  669. "--"
  670. ,@(org-mouse-tag-menu))))
  671. ((org-at-timestamp-p)
  672. (popup-menu
  673. '(nil
  674. ["Show Day" org-open-at-point t]
  675. ["Change Timestamp" org-time-stamp t]
  676. ["Delete Timestamp" (org-mouse-delete-timestamp) t]
  677. ["Compute Time Range" org-evaluate-time-range (org-at-date-range-p)]
  678. "--"
  679. ["Set for Today" org-mouse-timestamp-today]
  680. ["Set for Tomorrow" (org-mouse-timestamp-today 1 'day)]
  681. ["Set in 1 Week" (org-mouse-timestamp-today 7 'day)]
  682. ["Set in 2 Weeks" (org-mouse-timestamp-today 14 'day)]
  683. ["Set in a Month" (org-mouse-timestamp-today 1 'month)]
  684. "--"
  685. ["+ 1 Day" (org-timestamp-change 1 'day)]
  686. ["+ 1 Week" (org-timestamp-change 7 'day)]
  687. ["+ 1 Month" (org-timestamp-change 1 'month)]
  688. "--"
  689. ["- 1 Day" (org-timestamp-change -1 'day)]
  690. ["- 1 Week" (org-timestamp-change -7 'day)]
  691. ["- 1 Month" (org-timestamp-change -1 'month)])))
  692. ((get-context :table-special)
  693. (let ((mdata (match-data)))
  694. (incf (car mdata) 2)
  695. (store-match-data mdata))
  696. (message "match: %S" (match-string 0))
  697. (popup-menu `(nil ,@(org-mouse-keyword-replace-menu
  698. '(" " "!" "^" "_" "$" "#" "*" "'") 0
  699. (lambda (mark)
  700. (case (string-to-char mark)
  701. (? "( ) Nothing Special")
  702. (?! "(!) Column Names")
  703. (?^ "(^) Field Names Above")
  704. (?_ "(^) Field Names Below")
  705. (?$ "($) Formula Parameters")
  706. (?# "(#) Recalculation: Auto")
  707. (?* "(*) Recalculation: Manual")
  708. (?' "(') Recalculation: None"))) t))))
  709. ((assq :table contextlist)
  710. (popup-menu
  711. '(nil
  712. ["Align Table" org-ctrl-c-ctrl-c]
  713. ["Blank Field" org-table-blank-field]
  714. ["Edit Field" org-table-edit-field]
  715. "--"
  716. ("Column"
  717. ["Move Column Left" org-metaleft]
  718. ["Move Column Right" org-metaright]
  719. ["Delete Column" org-shiftmetaleft]
  720. ["Insert Column" org-shiftmetaright]
  721. "--"
  722. ["Enable Narrowing" (setq org-table-limit-column-width (not org-table-limit-column-width)) :selected org-table-limit-column-width :style toggle])
  723. ("Row"
  724. ["Move Row Up" org-metaup]
  725. ["Move Row Down" org-metadown]
  726. ["Delete Row" org-shiftmetaup]
  727. ["Insert Row" org-shiftmetadown]
  728. ["Sort lines in region" org-table-sort-lines (org-at-table-p)]
  729. "--"
  730. ["Insert Hline" org-table-insert-hline])
  731. ("Rectangle"
  732. ["Copy Rectangle" org-copy-special]
  733. ["Cut Rectangle" org-cut-special]
  734. ["Paste Rectangle" org-paste-special]
  735. ["Fill Rectangle" org-table-wrap-region])
  736. "--"
  737. ["Set Column Formula" org-table-eval-formula]
  738. ["Set Field Formula" (org-table-eval-formula '(4))]
  739. ["Edit Formulas" org-table-edit-formulas]
  740. "--"
  741. ["Recalculate Line" org-table-recalculate]
  742. ["Recalculate All" (org-table-recalculate '(4))]
  743. ["Iterate All" (org-table-recalculate '(16))]
  744. "--"
  745. ["Toggle Recalculate Mark" org-table-rotate-recalc-marks]
  746. ["Sum Column/Rectangle" org-table-sum
  747. :active (or (org-at-table-p) (org-region-active-p))]
  748. ["Field Info" org-table-field-info]
  749. ["Debug Formulas"
  750. (setq org-table-formula-debug (not org-table-formula-debug))
  751. :style toggle :selected org-table-formula-debug]
  752. )))
  753. ((and (assq :headline contextlist) (not (eolp)))
  754. (let ((priority (org-mouse-get-priority t)))
  755. (popup-menu
  756. `("Headline Menu"
  757. ("Tags and Priorities"
  758. ,@(org-mouse-keyword-menu
  759. (org-mouse-priority-list)
  760. #'(lambda (keyword)
  761. (org-mouse-set-priority (string-to-char keyword)))
  762. priority "Priority %s")
  763. "--"
  764. ,@(org-mouse-tag-menu))
  765. ("TODO Status"
  766. ,@(org-mouse-todo-menu (org-get-todo-state)))
  767. ["Show Tags"
  768. (with-current-buffer org-mouse-main-buffer (org-agenda-show-tags))
  769. :visible (not org-mouse-direct)]
  770. ["Show Priority"
  771. (with-current-buffer org-mouse-main-buffer (org-agenda-show-priority))
  772. :visible (not org-mouse-direct)]
  773. ,@(if org-mouse-direct '("--") nil)
  774. ["New Heading" org-mouse-insert-heading :visible org-mouse-direct]
  775. ["Set Deadline"
  776. (progn (org-mouse-end-headline) (insert " ") (org-deadline))
  777. :active (not (save-excursion
  778. (org-mouse-re-search-line org-deadline-regexp)))]
  779. ["Schedule Task"
  780. (progn (org-mouse-end-headline) (insert " ") (org-schedule))
  781. :active (not (save-excursion
  782. (org-mouse-re-search-line org-scheduled-regexp)))]
  783. ["Insert Timestamp"
  784. (progn (org-mouse-end-headline) (insert " ") (org-time-stamp nil)) t]
  785. ; ["Timestamp (inactive)" org-time-stamp-inactive t]
  786. "--"
  787. ["Archive Subtree" org-archive-subtree]
  788. ["Cut Subtree" org-cut-special]
  789. ["Copy Subtree" org-copy-special]
  790. ["Paste Subtree" org-paste-special :visible org-mouse-direct]
  791. ("Sort Children"
  792. ["Alphabetically" (org-sort-entries nil ?a)]
  793. ["Numerically" (org-sort-entries nil ?n)]
  794. ["By Time/Date" (org-sort-entries nil ?t)]
  795. "--"
  796. ["Reverse Alphabetically" (org-sort-entries nil ?A)]
  797. ["Reverse Numerically" (org-sort-entries nil ?N)]
  798. ["Reverse By Time/Date" (org-sort-entries nil ?T)])
  799. "--"
  800. ["Move Trees" org-mouse-move-tree :active nil]
  801. ))))
  802. (t
  803. (org-mouse-popup-global-menu))))))
  804. ;; (defun org-mouse-at-regexp (regexp)
  805. ;; (save-excursion
  806. ;; (let ((point (point))
  807. ;; (bol (progn (beginning-of-line) (point)))
  808. ;; (eol (progn (end-of-line) (point))))
  809. ;; (goto-char point)
  810. ;; (re-search-backward regexp bol 1)
  811. ;; (and (not (eolp))
  812. ;; (progn (forward-char)
  813. ;; (re-search-forward regexp eol t))
  814. ;; (<= (match-beginning 0) point)))))
  815. (defun org-mouse-mark-active ()
  816. (and mark-active transient-mark-mode))
  817. (defun org-mouse-in-region-p (pos)
  818. (and (org-mouse-mark-active)
  819. (>= pos (region-beginning))
  820. (< pos (region-end))))
  821. (defun org-mouse-down-mouse (event)
  822. (interactive "e")
  823. (setq this-command last-command)
  824. (unless (and (= 1 (event-click-count event))
  825. (org-mouse-in-region-p (posn-point (event-start event))))
  826. (mouse-drag-region event)))
  827. (add-hook 'org-mode-hook
  828. #'(lambda ()
  829. (setq org-mouse-context-menu-function 'org-mouse-context-menu)
  830. (when (memq 'context-menu org-mouse-features)
  831. (org-defkey org-mouse-map [mouse-3] nil)
  832. (org-defkey org-mode-map [mouse-3] 'org-mouse-show-context-menu))
  833. (org-defkey org-mode-map [down-mouse-1] 'org-mouse-down-mouse)
  834. (when (memq 'context-menu org-mouse-features)
  835. (org-defkey org-mouse-map [C-drag-mouse-1] 'org-mouse-move-tree)
  836. (org-defkey org-mouse-map [C-down-mouse-1] 'org-mouse-move-tree-start))
  837. (when (memq 'yank-link org-mouse-features)
  838. (org-defkey org-mode-map [S-mouse-2] 'org-mouse-yank-link)
  839. (org-defkey org-mode-map [drag-mouse-3] 'org-mouse-yank-link))
  840. (when (memq 'move-tree org-mouse-features)
  841. (org-defkey org-mouse-map [drag-mouse-3] 'org-mouse-move-tree)
  842. (org-defkey org-mouse-map [down-mouse-3] 'org-mouse-move-tree-start))
  843. (when (memq 'activate-stars org-mouse-features)
  844. (font-lock-add-keywords
  845. nil
  846. `((,org-outline-regexp
  847. 0 `(face org-link mouse-face highlight keymap ,org-mouse-map)
  848. 'prepend))
  849. t))
  850. (when (memq 'activate-bullets org-mouse-features)
  851. (font-lock-add-keywords
  852. nil
  853. `(("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +"
  854. (1 `(face org-link keymap ,org-mouse-map mouse-face highlight)
  855. 'prepend)))
  856. t))
  857. (when (memq 'activate-checkboxes org-mouse-features)
  858. (font-lock-add-keywords
  859. nil
  860. `(("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(\\[[ X]\\]\\)"
  861. (2 `(face bold keymap ,org-mouse-map mouse-face highlight) t)))
  862. t))
  863. (defadvice org-open-at-point (around org-mouse-open-at-point activate)
  864. (let ((context (org-context)))
  865. (cond
  866. ((assq :headline-stars context) (org-cycle))
  867. ((assq :checkbox context) (org-toggle-checkbox))
  868. ((assq :item-bullet context)
  869. (let ((org-cycle-include-plain-lists t)) (org-cycle)))
  870. (t ad-do-it))))))
  871. (defun org-mouse-move-tree-start (event)
  872. (interactive "e")
  873. (message "Same line: promote/demote, (***):move before, (text): make a child"))
  874. (defun org-mouse-make-marker (position)
  875. (with-current-buffer (window-buffer (posn-window position))
  876. (copy-marker (posn-point position))))
  877. (defun org-mouse-move-tree (event)
  878. ;; todo: handle movements between different buffers
  879. (interactive "e")
  880. (save-excursion
  881. (let* ((start (org-mouse-make-marker (event-start event)))
  882. (end (org-mouse-make-marker (event-end event)))
  883. (sbuf (marker-buffer start))
  884. (ebuf (marker-buffer end)))
  885. (when (and sbuf ebuf)
  886. (set-buffer sbuf)
  887. (goto-char start)
  888. (org-back-to-heading)
  889. (if (and (eq sbuf ebuf)
  890. (equal
  891. (point)
  892. (save-excursion (goto-char end) (org-back-to-heading) (point))))
  893. ;; if the same line then promote/demote
  894. (if (>= end start) (org-demote-subtree) (org-promote-subtree))
  895. ;; if different lines then move
  896. (org-cut-subtree)
  897. (set-buffer ebuf)
  898. (goto-char end)
  899. (org-back-to-heading)
  900. (when (and (eq sbuf ebuf)
  901. (equal
  902. (point)
  903. (save-excursion (goto-char start)
  904. (org-back-to-heading) (point))))
  905. (outline-end-of-subtree)
  906. (end-of-line)
  907. (if (eobp) (newline) (forward-char)))
  908. (when (looking-at org-outline-regexp)
  909. (let ((level (- (match-end 0) (match-beginning 0))))
  910. (when (> end (match-end 0))
  911. (outline-end-of-subtree)
  912. (end-of-line)
  913. (if (eobp) (newline) (forward-char))
  914. (setq level (1+ level)))
  915. (org-paste-subtree level)
  916. (save-excursion
  917. (outline-end-of-subtree)
  918. (when (bolp) (delete-char -1))))))))))
  919. (defun org-mouse-transform-to-outline ()
  920. (interactive)
  921. (org-back-to-heading)
  922. (let ((minlevel 1000)
  923. (replace-text (concat (match-string 0) "* ")))
  924. (beginning-of-line 2)
  925. (save-excursion
  926. (while (not (or (eobp) (looking-at org-outline-regexp)))
  927. (when (looking-at org-mouse-plain-list-regexp)
  928. (setq minlevel (min minlevel (- (match-end 1) (match-beginning 1)))))
  929. (forward-line)))
  930. (while (not (or (eobp) (looking-at org-outline-regexp)))
  931. (when (and (looking-at org-mouse-plain-list-regexp)
  932. (eq minlevel (- (match-end 1) (match-beginning 1))))
  933. (replace-match replace-text))
  934. (forward-line))))
  935. (defvar _cmd) ;dynamically scoped from `org-with-remote-undo'.
  936. (defun org-mouse-do-remotely (command)
  937. ; (org-agenda-check-no-diary)
  938. (when (get-text-property (point) 'org-marker)
  939. (let* ((anticol (- (point-at-eol) (point)))
  940. (marker (get-text-property (point) 'org-marker))
  941. (buffer (marker-buffer marker))
  942. (pos (marker-position marker))
  943. (hdmarker (get-text-property (point) 'org-hd-marker))
  944. (buffer-read-only nil)
  945. (newhead "--- removed ---")
  946. (org-mouse-direct nil)
  947. (org-mouse-main-buffer (current-buffer)))
  948. (when (eq (with-current-buffer buffer major-mode) 'org-mode)
  949. (let ((endmarker (with-current-buffer buffer
  950. (outline-end-of-subtree)
  951. (forward-char 1)
  952. (copy-marker (point)))))
  953. (org-with-remote-undo buffer
  954. (with-current-buffer buffer
  955. (widen)
  956. (goto-char pos)
  957. (org-show-hidden-entry)
  958. (save-excursion
  959. (and (outline-next-heading)
  960. (org-flag-heading nil))) ; show the next heading
  961. (org-back-to-heading)
  962. (setq marker (copy-marker (point)))
  963. (goto-char (max (point-at-bol) (- (point-at-eol) anticol)))
  964. (funcall command)
  965. (message "_cmd: %S" _cmd)
  966. (message "this-command: %S" this-command)
  967. (unless (eq (marker-position marker) (marker-position endmarker))
  968. (setq newhead (org-get-heading))))
  969. (beginning-of-line 1)
  970. (save-excursion
  971. (org-agenda-change-all-lines newhead hdmarker 'fixface))))
  972. t))))
  973. (defun org-mouse-agenda-context-menu (&optional event)
  974. (or (org-mouse-do-remotely 'org-mouse-context-menu)
  975. (popup-menu
  976. '("Agenda"
  977. ("Agenda Files")
  978. "--"
  979. ["Undo" (progn (message "last command: %S" last-command) (setq this-command 'org-agenda-undo) (org-agenda-undo))
  980. :visible (if (eq last-command 'org-agenda-undo)
  981. org-agenda-pending-undo-list
  982. org-agenda-undo-list)]
  983. ["Rebuild Buffer" org-agenda-redo t]
  984. ["New Diary Entry"
  985. org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline) t]
  986. "--"
  987. ["Goto Today" org-agenda-goto-today
  988. (org-agenda-check-type nil 'agenda 'timeline) t]
  989. ["Display Calendar" org-agenda-goto-calendar
  990. (org-agenda-check-type nil 'agenda 'timeline) t]
  991. ("Calendar Commands"
  992. ["Phases of the Moon" org-agenda-phases-of-moon
  993. (org-agenda-check-type nil 'agenda 'timeline)]
  994. ["Sunrise/Sunset" org-agenda-sunrise-sunset
  995. (org-agenda-check-type nil 'agenda 'timeline)]
  996. ["Holidays" org-agenda-holidays
  997. (org-agenda-check-type nil 'agenda 'timeline)]
  998. ["Convert" org-agenda-convert-date
  999. (org-agenda-check-type nil 'agenda 'timeline)]
  1000. "--"
  1001. ["Create iCalendar file" org-export-icalendar-combine-agenda-files t])
  1002. "--"
  1003. ["Day View" org-agenda-day-view
  1004. :active (org-agenda-check-type nil 'agenda)
  1005. :style radio :selected (eq org-agenda-current-span 'day)]
  1006. ["Week View" org-agenda-week-view
  1007. :active (org-agenda-check-type nil 'agenda)
  1008. :style radio :selected (eq org-agenda-current-span 'week)]
  1009. "--"
  1010. ["Show Logbook entries" org-agenda-log-mode
  1011. :style toggle :selected org-agenda-show-log
  1012. :active (org-agenda-check-type nil 'agenda 'timeline)]
  1013. ["Include Diary" org-agenda-toggle-diary
  1014. :style toggle :selected org-agenda-include-diary
  1015. :active (org-agenda-check-type nil 'agenda)]
  1016. ["Use Time Grid" org-agenda-toggle-time-grid
  1017. :style toggle :selected org-agenda-use-time-grid
  1018. :active (org-agenda-check-type nil 'agenda)]
  1019. ["Follow Mode" org-agenda-follow-mode
  1020. :style toggle :selected org-agenda-follow-mode]
  1021. "--"
  1022. ["Quit" org-agenda-quit t]
  1023. ["Exit and Release Buffers" org-agenda-exit t]
  1024. ))))
  1025. (defun org-mouse-get-gesture (event)
  1026. (let ((startxy (posn-x-y (event-start event)))
  1027. (endxy (posn-x-y (event-end event))))
  1028. (if (< (car startxy) (car endxy)) :right :left)))
  1029. ; (setq org-agenda-mode-hook nil)
  1030. (defvar org-agenda-mode-map)
  1031. (add-hook 'org-agenda-mode-hook
  1032. #'(lambda ()
  1033. (setq org-mouse-context-menu-function 'org-mouse-agenda-context-menu)
  1034. (org-defkey org-agenda-mode-map [mouse-3] 'org-mouse-show-context-menu)
  1035. (org-defkey org-agenda-mode-map [down-mouse-3] 'org-mouse-move-tree-start)
  1036. (org-defkey org-agenda-mode-map [C-mouse-4] 'org-agenda-earlier)
  1037. (org-defkey org-agenda-mode-map [C-mouse-5] 'org-agenda-later)
  1038. (org-defkey org-agenda-mode-map [drag-mouse-3]
  1039. #'(lambda (event) (interactive "e")
  1040. (case (org-mouse-get-gesture event)
  1041. (:left (org-agenda-earlier 1))
  1042. (:right (org-agenda-later 1)))))))
  1043. (provide 'org-mouse)
  1044. ;;; org-mouse.el ends here