org-mouse.el 38 KB

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