org-mouse.el 38 KB

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