org-mouse.el 38 KB

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