org-mouse.el 39 KB

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