org-mouse.el 37 KB

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