org-mouse.el 37 KB

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