org-mouse.el 38 KB

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