org-mouse.el 39 KB

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