org-mouse.el 38 KB

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