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