org-mouse.el 38 KB

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