org-mouse.el 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  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. ;; http://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)))
  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-set-tags nil t) t]
  386. ["Align Tags in Buffer" (org-set-tags t t) t]
  387. ["Set Tags ..." (org-set-tags) t])))
  388. (defun org-mouse-set-tags (tags)
  389. (save-excursion
  390. ;; remove existing tags first
  391. (beginning-of-line)
  392. (when (org-mouse-re-search-line ":\\(\\([A-Za-z_]+:\\)+\\)")
  393. (replace-match ""))
  394. ;; set new tags if any
  395. (when tags
  396. (end-of-line)
  397. (insert " :" (mapconcat 'identity tags ":") ":")
  398. (org-set-tags nil t))))
  399. (defun org-mouse-insert-checkbox ()
  400. (interactive)
  401. (and (org-at-item-p)
  402. (goto-char (match-end 0))
  403. (unless (org-at-item-checkbox-p)
  404. (delete-horizontal-space)
  405. (insert " [ ] "))))
  406. (defun org-mouse-agenda-type (type)
  407. (pcase type
  408. (`tags "Tags: ")
  409. (`todo "TODO: ")
  410. (`tags-tree "Tags tree: ")
  411. (`todo-tree "TODO tree: ")
  412. (`occur-tree "Occur tree: ")
  413. (_ "Agenda command ???")))
  414. (defun org-mouse-list-options-menu (alloptions &optional function)
  415. (let ((options (save-match-data
  416. (split-string (match-string-no-properties 1)))))
  417. (print options)
  418. (cl-loop for name in alloptions
  419. collect
  420. (vector name
  421. `(progn
  422. (replace-match
  423. (mapconcat 'identity
  424. (sort (if (member ',name ',options)
  425. (delete ',name ',options)
  426. (cons ',name ',options))
  427. 'string-lessp)
  428. " ")
  429. nil nil nil 1)
  430. (when (functionp ',function) (funcall ',function)))
  431. :style 'toggle
  432. :selected (and (member name options) t)))))
  433. (defun org-mouse-clip-text (text maxlength)
  434. (if (> (length text) maxlength)
  435. (concat (substring text 0 (- maxlength 3)) "...")
  436. text))
  437. (defun org-mouse-popup-global-menu ()
  438. (popup-menu
  439. `("Main Menu"
  440. ["Show Overview" org-mouse-show-overview t]
  441. ["Show Headlines" org-mouse-show-headlines t]
  442. ["Show All" outline-show-all t]
  443. ["Remove Highlights" org-remove-occur-highlights
  444. :visible org-occur-highlights]
  445. "--"
  446. ["Check Deadlines"
  447. (if (functionp 'org-check-deadlines-and-todos)
  448. (org-check-deadlines-and-todos org-deadline-warning-days)
  449. (org-check-deadlines org-deadline-warning-days)) t]
  450. ["Check TODOs" org-show-todo-tree t]
  451. ("Check Tags"
  452. ,@(org-mouse-keyword-menu
  453. (sort (mapcar 'car (org-get-buffer-tags)) 'string-lessp)
  454. #'(lambda (tag) (org-tags-sparse-tree nil tag)))
  455. "--"
  456. ["Custom Tag ..." org-tags-sparse-tree t])
  457. ["Check Phrase ..." org-occur]
  458. "--"
  459. ["Display Agenda" org-agenda-list t]
  460. ["Display TODO List" org-todo-list t]
  461. ("Display Tags"
  462. ,@(org-mouse-keyword-menu
  463. (sort (mapcar 'car (org-get-buffer-tags)) 'string-lessp)
  464. #'(lambda (tag) (org-tags-view nil tag)))
  465. "--"
  466. ["Custom Tag ..." org-tags-view t])
  467. ["Display Calendar" org-goto-calendar t]
  468. "--"
  469. ,@(org-mouse-keyword-menu
  470. (mapcar 'car org-agenda-custom-commands)
  471. #'(lambda (key)
  472. (eval `(org-agenda nil (string-to-char ,key))))
  473. nil
  474. #'(lambda (key)
  475. (let ((entry (assoc key org-agenda-custom-commands)))
  476. (org-mouse-clip-text
  477. (cond
  478. ((stringp (nth 1 entry)) (nth 1 entry))
  479. ((stringp (nth 2 entry))
  480. (concat (org-mouse-agenda-type (nth 1 entry))
  481. (nth 2 entry)))
  482. (t "Agenda Command `%s'"))
  483. 30))))
  484. "--"
  485. ["Delete Blank Lines" delete-blank-lines
  486. :visible (org-mouse-empty-line)]
  487. ["Insert Checkbox" org-mouse-insert-checkbox
  488. :visible (and (org-at-item-p) (not (org-at-item-checkbox-p)))]
  489. ["Insert Checkboxes"
  490. (org-mouse-for-each-item 'org-mouse-insert-checkbox)
  491. :visible (and (org-at-item-p) (not (org-at-item-checkbox-p)))]
  492. ["Plain List to Outline" org-mouse-transform-to-outline
  493. :visible (org-at-item-p)])))
  494. (defun org-mouse-get-context (contextlist context)
  495. (let ((contextdata (assq context contextlist)))
  496. (when contextdata
  497. (save-excursion
  498. (goto-char (nth 1 contextdata))
  499. (re-search-forward ".*" (nth 2 contextdata))))))
  500. (defun org-mouse-for-each-item (funct)
  501. ;; Functions called by `org-apply-on-list' need an argument.
  502. (let ((wrap-fun (lambda (_) (funcall funct))))
  503. (when (ignore-errors (goto-char (org-in-item-p)))
  504. (save-excursion (org-apply-on-list wrap-fun nil)))))
  505. (defun org-mouse-bolp ()
  506. "Return true if there only spaces, tabs, and `*' before point.
  507. This means, between the beginning of line and the point."
  508. (save-excursion
  509. (skip-chars-backward " \t*") (bolp)))
  510. (defun org-mouse-insert-item (text)
  511. (cl-case (org-mouse-line-position)
  512. (:beginning ; insert before
  513. (beginning-of-line)
  514. (looking-at "[ \t]*")
  515. (open-line 1)
  516. (indent-to-column (- (match-end 0) (match-beginning 0)))
  517. (insert "+ "))
  518. (:middle ; insert after
  519. (end-of-line)
  520. (newline t)
  521. (indent-relative)
  522. (insert "+ "))
  523. (:end ; insert text here
  524. (skip-chars-backward " \t")
  525. (kill-region (point) (point-at-eol))
  526. (unless (looking-back org-mouse-punctuation (line-beginning-position))
  527. (insert (concat org-mouse-punctuation " ")))))
  528. (insert text)
  529. (beginning-of-line))
  530. (defadvice dnd-insert-text (around org-mouse-dnd-insert-text activate)
  531. (if (derived-mode-p 'org-mode)
  532. (org-mouse-insert-item text)
  533. ad-do-it))
  534. (defadvice dnd-open-file (around org-mouse-dnd-open-file activate)
  535. (if (derived-mode-p 'org-mode)
  536. (org-mouse-insert-item uri)
  537. ad-do-it))
  538. (defun org-mouse-match-closure (function)
  539. (let ((match (match-data t)))
  540. `(lambda (&rest rest)
  541. (save-match-data
  542. (set-match-data ',match)
  543. (apply ',function rest)))))
  544. (defun org-mouse-yank-link (click)
  545. (interactive "e")
  546. ;; Give temporary modes such as isearch a chance to turn off.
  547. (run-hooks 'mouse-leave-buffer-hook)
  548. (mouse-set-point click)
  549. (setq mouse-selection-click-count 0)
  550. (delete-horizontal-space)
  551. (insert-for-yank (concat " [[" (current-kill 0) "]] ")))
  552. (defun org-mouse-context-menu (&optional event)
  553. (let* ((stamp-prefixes (list org-deadline-string org-scheduled-string))
  554. (contextlist (org-context))
  555. (get-context (lambda (context) (org-mouse-get-context contextlist context))))
  556. (cond
  557. ((org-mouse-mark-active)
  558. (let ((region-string (buffer-substring (region-beginning) (region-end))))
  559. (popup-menu
  560. `(nil
  561. ["Sparse Tree" (org-occur ',region-string)]
  562. ["Find in Buffer" (occur ',region-string)]
  563. ["Grep in Current Dir"
  564. (grep (format "grep -rnH -e '%s' *" ',region-string))]
  565. ["Grep in Parent Dir"
  566. (grep (format "grep -rnH -e '%s' ../*" ',region-string))]
  567. "--"
  568. ["Convert to Link"
  569. (progn (save-excursion (goto-char (region-beginning)) (insert "[["))
  570. (save-excursion (goto-char (region-end)) (insert "]]")))]
  571. ["Insert Link Here" (org-mouse-yank-link ',event)]))))
  572. ((save-excursion (beginning-of-line) (looking-at "[ \t]*#\\+STARTUP: \\(.*\\)"))
  573. (popup-menu
  574. `(nil
  575. ,@(org-mouse-list-options-menu (mapcar 'car org-startup-options)
  576. 'org-mode-restart))))
  577. ((or (eolp)
  578. (and (looking-at "\\( \\|\t\\)\\(+:[0-9a-zA-Z_:]+\\)?\\( \\|\t\\)+$")
  579. (looking-back " \\|\t" (- (point) 2)
  580. (line-beginning-position))))
  581. (org-mouse-popup-global-menu))
  582. ((funcall get-context :checkbox)
  583. (popup-menu
  584. '(nil
  585. ["Toggle" org-toggle-checkbox t]
  586. ["Remove" org-mouse-remove-match-and-spaces t]
  587. ""
  588. ["All Clear" (org-mouse-for-each-item
  589. (lambda ()
  590. (when (save-excursion (org-at-item-checkbox-p))
  591. (replace-match "[ ] "))))]
  592. ["All Set" (org-mouse-for-each-item
  593. (lambda ()
  594. (when (save-excursion (org-at-item-checkbox-p))
  595. (replace-match "[X] "))))]
  596. ["All Toggle" (org-mouse-for-each-item 'org-toggle-checkbox) t]
  597. ["All Remove" (org-mouse-for-each-item
  598. (lambda ()
  599. (when (save-excursion (org-at-item-checkbox-p))
  600. (org-mouse-remove-match-and-spaces))))]
  601. )))
  602. ((and (org-mouse-looking-at "\\b\\w+" "a-zA-Z0-9_")
  603. (member (match-string 0) org-todo-keywords-1))
  604. (popup-menu
  605. `(nil
  606. ,@(org-mouse-todo-menu (match-string 0))
  607. "--"
  608. ["Check TODOs" org-show-todo-tree t]
  609. ["List all TODO keywords" org-todo-list t]
  610. [,(format "List only %s" (match-string 0))
  611. (org-todo-list (match-string 0)) t]
  612. )))
  613. ((and (org-mouse-looking-at "\\b[A-Z]+:" "A-Z")
  614. (member (match-string 0) stamp-prefixes))
  615. (popup-menu
  616. `(nil
  617. ,@(org-mouse-keyword-replace-menu stamp-prefixes)
  618. "--"
  619. ["Check Deadlines" org-check-deadlines t]
  620. )))
  621. ((org-mouse-looking-at org-mouse-priority-regexp "[]A-Z#") ; priority
  622. (popup-menu `(nil ,@(org-mouse-keyword-replace-menu
  623. (org-mouse-priority-list) 1 "Priority %s" t))))
  624. ((funcall get-context :link)
  625. (popup-menu
  626. '(nil
  627. ["Open" org-open-at-point t]
  628. ["Open in Emacs" (org-open-at-point t) t]
  629. "--"
  630. ["Copy link" (org-kill-new (match-string 0))]
  631. ["Cut link"
  632. (progn
  633. (kill-region (match-beginning 0) (match-end 0))
  634. (just-one-space))]
  635. "--"
  636. ["Grep for TODOs"
  637. (grep (format "grep -nH -i 'todo\\|fixme' %s*" (match-string 2)))]
  638. ; ["Paste file link" ((insert "file:") (yank))]
  639. )))
  640. ((org-mouse-looking-at ":\\([A-Za-z0-9_]+\\):" "A-Za-z0-9_" -1) ;tags
  641. (popup-menu
  642. `(nil
  643. [,(format-message "Display `%s'" (match-string 1))
  644. (org-tags-view nil ,(match-string 1))]
  645. [,(format-message "Sparse Tree `%s'" (match-string 1))
  646. (org-tags-sparse-tree nil ,(match-string 1))]
  647. "--"
  648. ,@(org-mouse-tag-menu))))
  649. ((org-at-timestamp-p 'lax)
  650. (popup-menu
  651. '(nil
  652. ["Show Day" org-open-at-point t]
  653. ["Change Timestamp" org-time-stamp t]
  654. ["Delete Timestamp" (org-mouse-delete-timestamp) t]
  655. ["Compute Time Range" org-evaluate-time-range (org-at-date-range-p)]
  656. "--"
  657. ["Set for Today" org-mouse-timestamp-today]
  658. ["Set for Tomorrow" (org-mouse-timestamp-today 1 'day)]
  659. ["Set in 1 Week" (org-mouse-timestamp-today 7 'day)]
  660. ["Set in 2 Weeks" (org-mouse-timestamp-today 14 'day)]
  661. ["Set in a Month" (org-mouse-timestamp-today 1 'month)]
  662. "--"
  663. ["+ 1 Day" (org-timestamp-change 1 'day)]
  664. ["+ 1 Week" (org-timestamp-change 7 'day)]
  665. ["+ 1 Month" (org-timestamp-change 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. ((funcall get-context :table-special)
  671. (let ((mdata (match-data)))
  672. (cl-incf (car mdata) 2)
  673. (store-match-data mdata))
  674. (message "match: %S" (match-string 0))
  675. (popup-menu `(nil ,@(org-mouse-keyword-replace-menu
  676. '(" " "!" "^" "_" "$" "#" "*" "'") 0
  677. (lambda (mark)
  678. (cl-case (string-to-char mark)
  679. (? "( ) Nothing Special")
  680. (?! "(!) Column Names")
  681. (?^ "(^) Field Names Above")
  682. (?_ "(^) Field Names Below")
  683. (?$ "($) Formula Parameters")
  684. (?# "(#) Recalculation: Auto")
  685. (?* "(*) Recalculation: Manual")
  686. (?' "(') Recalculation: None"))) t))))
  687. ((assq :table contextlist)
  688. (popup-menu
  689. '(nil
  690. ["Align Table" org-ctrl-c-ctrl-c]
  691. ["Blank Field" org-table-blank-field]
  692. ["Edit Field" org-table-edit-field]
  693. "--"
  694. ("Column"
  695. ["Move Column Left" org-metaleft]
  696. ["Move Column Right" org-metaright]
  697. ["Delete Column" org-shiftmetaleft]
  698. ["Insert Column" org-shiftmetaright]
  699. "--"
  700. ["Enable Narrowing" (setq org-table-limit-column-width (not org-table-limit-column-width)) :selected org-table-limit-column-width :style toggle])
  701. ("Row"
  702. ["Move Row Up" org-metaup]
  703. ["Move Row Down" org-metadown]
  704. ["Delete Row" org-shiftmetaup]
  705. ["Insert Row" org-shiftmetadown]
  706. ["Sort lines in region" org-table-sort-lines (org-at-table-p)]
  707. "--"
  708. ["Insert Hline" org-table-insert-hline])
  709. ("Rectangle"
  710. ["Copy Rectangle" org-copy-special]
  711. ["Cut Rectangle" org-cut-special]
  712. ["Paste Rectangle" org-paste-special]
  713. ["Fill Rectangle" org-table-wrap-region])
  714. "--"
  715. ["Set Column Formula" org-table-eval-formula]
  716. ["Set Field Formula" (org-table-eval-formula '(4))]
  717. ["Edit Formulas" org-table-edit-formulas]
  718. "--"
  719. ["Recalculate Line" org-table-recalculate]
  720. ["Recalculate All" (org-table-recalculate '(4))]
  721. ["Iterate All" (org-table-recalculate '(16))]
  722. "--"
  723. ["Toggle Recalculate Mark" org-table-rotate-recalc-marks]
  724. ["Sum Column/Rectangle" org-table-sum
  725. :active (or (org-at-table-p) (org-region-active-p))]
  726. ["Field Info" org-table-field-info]
  727. ["Debug Formulas"
  728. (setq org-table-formula-debug (not org-table-formula-debug))
  729. :style toggle :selected org-table-formula-debug]
  730. )))
  731. ((and (assq :headline contextlist) (not (eolp)))
  732. (let ((priority (org-mouse-get-priority t)))
  733. (popup-menu
  734. `("Headline Menu"
  735. ("Tags and Priorities"
  736. ,@(org-mouse-keyword-menu
  737. (org-mouse-priority-list)
  738. #'(lambda (keyword)
  739. (org-mouse-set-priority (string-to-char keyword)))
  740. priority "Priority %s")
  741. "--"
  742. ,@(org-mouse-tag-menu))
  743. ("TODO Status"
  744. ,@(org-mouse-todo-menu (org-get-todo-state)))
  745. ["Show Tags"
  746. (with-current-buffer org-mouse-main-buffer (org-agenda-show-tags))
  747. :visible (not org-mouse-direct)]
  748. ["Show Priority"
  749. (with-current-buffer org-mouse-main-buffer (org-agenda-show-priority))
  750. :visible (not org-mouse-direct)]
  751. ,@(if org-mouse-direct '("--") nil)
  752. ["New Heading" org-mouse-insert-heading :visible org-mouse-direct]
  753. ["Set Deadline"
  754. (progn (org-mouse-end-headline) (insert " ") (org-deadline))
  755. :active (not (save-excursion
  756. (org-mouse-re-search-line org-deadline-regexp)))]
  757. ["Schedule Task"
  758. (progn (org-mouse-end-headline) (insert " ") (org-schedule))
  759. :active (not (save-excursion
  760. (org-mouse-re-search-line org-scheduled-regexp)))]
  761. ["Insert Timestamp"
  762. (progn (org-mouse-end-headline) (insert " ") (org-time-stamp nil)) t]
  763. ; ["Timestamp (inactive)" org-time-stamp-inactive t]
  764. "--"
  765. ["Archive Subtree" org-archive-subtree]
  766. ["Cut Subtree" org-cut-special]
  767. ["Copy Subtree" org-copy-special]
  768. ["Paste Subtree" org-paste-special :visible org-mouse-direct]
  769. ("Sort Children"
  770. ["Alphabetically" (org-sort-entries nil ?a)]
  771. ["Numerically" (org-sort-entries nil ?n)]
  772. ["By Time/Date" (org-sort-entries nil ?t)]
  773. "--"
  774. ["Reverse Alphabetically" (org-sort-entries nil ?A)]
  775. ["Reverse Numerically" (org-sort-entries nil ?N)]
  776. ["Reverse By Time/Date" (org-sort-entries nil ?T)])
  777. "--"
  778. ["Move Trees" org-mouse-move-tree :active nil]
  779. ))))
  780. (t
  781. (org-mouse-popup-global-menu)))))
  782. (defun org-mouse-mark-active ()
  783. (and mark-active transient-mark-mode))
  784. (defun org-mouse-in-region-p (pos)
  785. (and (org-mouse-mark-active)
  786. (>= pos (region-beginning))
  787. (< pos (region-end))))
  788. (defun org-mouse-down-mouse (event)
  789. (interactive "e")
  790. (setq this-command last-command)
  791. (unless (and (= 1 (event-click-count event))
  792. (org-mouse-in-region-p (posn-point (event-start event))))
  793. (mouse-drag-region event)))
  794. (add-hook 'org-mode-hook
  795. #'(lambda ()
  796. (setq org-mouse-context-menu-function 'org-mouse-context-menu)
  797. (when (memq 'context-menu org-mouse-features)
  798. (org-defkey org-mouse-map [mouse-3] nil)
  799. (org-defkey org-mode-map [mouse-3] 'org-mouse-show-context-menu))
  800. (org-defkey org-mode-map [down-mouse-1] 'org-mouse-down-mouse)
  801. (when (memq 'context-menu org-mouse-features)
  802. (org-defkey org-mouse-map [C-drag-mouse-1] 'org-mouse-move-tree)
  803. (org-defkey org-mouse-map [C-down-mouse-1] 'org-mouse-move-tree-start))
  804. (when (memq 'yank-link org-mouse-features)
  805. (org-defkey org-mode-map [S-mouse-2] 'org-mouse-yank-link)
  806. (org-defkey org-mode-map [drag-mouse-3] 'org-mouse-yank-link))
  807. (when (memq 'move-tree org-mouse-features)
  808. (org-defkey org-mouse-map [drag-mouse-3] 'org-mouse-move-tree)
  809. (org-defkey org-mouse-map [down-mouse-3] 'org-mouse-move-tree-start))
  810. (when (memq 'activate-stars org-mouse-features)
  811. (font-lock-add-keywords
  812. nil
  813. `((,org-outline-regexp
  814. 0 `(face org-link mouse-face highlight keymap ,org-mouse-map)
  815. 'prepend))
  816. t))
  817. (when (memq 'activate-bullets org-mouse-features)
  818. (font-lock-add-keywords
  819. nil
  820. `(("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +"
  821. (1 `(face org-link keymap ,org-mouse-map mouse-face highlight)
  822. 'prepend)))
  823. t))
  824. (when (memq 'activate-checkboxes org-mouse-features)
  825. (font-lock-add-keywords
  826. nil
  827. `(("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(\\[[ X]\\]\\)"
  828. (2 `(face bold keymap ,org-mouse-map mouse-face highlight) t)))
  829. t))
  830. (defadvice org-open-at-point (around org-mouse-open-at-point activate)
  831. (let ((context (org-context)))
  832. (cond
  833. ((assq :headline-stars context) (org-cycle))
  834. ((assq :checkbox context) (org-toggle-checkbox))
  835. ((assq :item-bullet context)
  836. (let ((org-cycle-include-plain-lists t)) (org-cycle)))
  837. ((org-footnote-at-reference-p) nil)
  838. (t ad-do-it))))))
  839. (defun org-mouse-move-tree-start (_event)
  840. (interactive "e")
  841. (message "Same line: promote/demote, (***):move before, (text): make a child"))
  842. (defun org-mouse-make-marker (position)
  843. (with-current-buffer (window-buffer (posn-window position))
  844. (copy-marker (posn-point position))))
  845. (defun org-mouse-move-tree (event)
  846. ;; todo: handle movements between different buffers
  847. (interactive "e")
  848. (save-excursion
  849. (let* ((start (org-mouse-make-marker (event-start event)))
  850. (end (org-mouse-make-marker (event-end event)))
  851. (sbuf (marker-buffer start))
  852. (ebuf (marker-buffer end)))
  853. (when (and sbuf ebuf)
  854. (set-buffer sbuf)
  855. (goto-char start)
  856. (org-back-to-heading)
  857. (if (and (eq sbuf ebuf)
  858. (equal
  859. (point)
  860. (save-excursion (goto-char end) (org-back-to-heading) (point))))
  861. ;; if the same line then promote/demote
  862. (if (>= end start) (org-demote-subtree) (org-promote-subtree))
  863. ;; if different lines then move
  864. (org-cut-subtree)
  865. (set-buffer ebuf)
  866. (goto-char end)
  867. (org-back-to-heading)
  868. (when (and (eq sbuf ebuf)
  869. (equal
  870. (point)
  871. (save-excursion (goto-char start)
  872. (org-back-to-heading) (point))))
  873. (progn (org-end-of-subtree nil t)
  874. (unless (eobp) (backward-char)))
  875. (end-of-line)
  876. (if (eobp) (newline) (forward-char)))
  877. (when (looking-at org-outline-regexp)
  878. (let ((level (- (match-end 0) (match-beginning 0))))
  879. (when (> end (match-end 0))
  880. (progn (org-end-of-subtree nil t)
  881. (unless (eobp) (backward-char)))
  882. (end-of-line)
  883. (if (eobp) (newline) (forward-char))
  884. (setq level (1+ level)))
  885. (org-paste-subtree level)
  886. (save-excursion
  887. (progn (org-end-of-subtree nil t)
  888. (unless (eobp) (backward-char)))
  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 org-mouse-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. (org-end-of-subtree nil t)
  922. (unless (eobp) (forward-char 1))
  923. (point-marker))))
  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 (point-marker))
  934. (goto-char (max (point-at-bol) (- (point-at-eol) anticol)))
  935. (funcall command)
  936. (message "_cmd: %S" org-mouse-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) t]
  957. "--"
  958. ["Goto Today" org-agenda-goto-today
  959. (org-agenda-check-type nil 'agenda) t]
  960. ["Display Calendar" org-agenda-goto-calendar
  961. (org-agenda-check-type nil 'agenda) t]
  962. ("Calendar Commands"
  963. ["Phases of the Moon" org-agenda-phases-of-moon
  964. (org-agenda-check-type nil 'agenda)]
  965. ["Sunrise/Sunset" org-agenda-sunrise-sunset
  966. (org-agenda-check-type nil 'agenda)]
  967. ["Holidays" org-agenda-holidays
  968. (org-agenda-check-type nil 'agenda)]
  969. ["Convert" org-agenda-convert-date
  970. (org-agenda-check-type nil 'agenda)]
  971. "--"
  972. ["Create iCalendar file" org-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)]
  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. (cl-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