org-keys.el 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  1. ;;; org-keys.el --- Key bindings for Org mode -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2018-2020 Free Software Foundation, Inc.
  3. ;; Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; GNU Emacs is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; This library adds bindings for Org mode buffers. It also
  17. ;; implements both Speed keys and Babel speed keys. See manual for
  18. ;; details.
  19. ;;; Code:
  20. (require 'cl-lib)
  21. (defvar org-outline-regexp)
  22. (declare-function org-add-note "org" ())
  23. (declare-function org-agenda "org" (&optional arg org-keys restriction))
  24. (declare-function org-agenda-file-to-front "org" (&optional to-end))
  25. (declare-function org-agenda-remove-restriction-lock "org" (&optional noupdate))
  26. (declare-function org-agenda-set-restriction-lock "org" (&optional type))
  27. (declare-function org-archive-subtree "org" (&optional find-done))
  28. (declare-function org-archive-subtree-default "org" ())
  29. (declare-function org-archive-subtree-default-with-confirmation "org" ())
  30. (declare-function org-archive-to-archive-sibling "org" ())
  31. (declare-function org-at-heading-p "org" (&optional ignored))
  32. (declare-function org-attach "org" ())
  33. (declare-function org-backward-element "org" ())
  34. (declare-function org-backward-heading-same-level "org" (arg &optional invisible-ok))
  35. (declare-function org-backward-paragraph "org" ())
  36. (declare-function org-backward-sentence "org" (&optional arg))
  37. (declare-function org-beginning-of-line "org" (&optional n))
  38. (declare-function org-clock-cancel "org" ())
  39. (declare-function org-clock-display "org" (&optional arg))
  40. (declare-function org-clock-goto "org" (&optional select))
  41. (declare-function org-clock-in "org" (&optional select start-time))
  42. (declare-function org-clock-in-last "org" (&optional arg))
  43. (declare-function org-clock-out "org" (&optional switch-to-state fail-quietly at-time))
  44. (declare-function org-clone-subtree-with-time-shift "org" (n &optional shift))
  45. (declare-function org-columns "org" (&optional global columns-fmt-string))
  46. (declare-function org-comment-dwim "org" (arg))
  47. (declare-function org-refile-copy "org" ())
  48. (declare-function org-copy-special "org" ())
  49. (declare-function org-copy-visible "org" (beg end))
  50. (declare-function org-ctrl-c-ctrl-c "org" (&optional arg))
  51. (declare-function org-ctrl-c-minus "org" ())
  52. (declare-function org-ctrl-c-ret "org" ())
  53. (declare-function org-ctrl-c-star "org" ())
  54. (declare-function org-ctrl-c-tab "org" (&optional arg))
  55. (declare-function org-cut-special "org" ())
  56. (declare-function org-cut-subtree "org" (&optional n))
  57. (declare-function org-cycle "org" (&optional arg))
  58. (declare-function org-cycle-agenda-files "org" ())
  59. (declare-function org-date-from-calendar "org" ())
  60. (declare-function org-dynamic-block-insert-dblock "org" (&optional arg))
  61. (declare-function org-dblock-update "org" (&optional arg))
  62. (declare-function org-deadline "org" (arg1 &optional time))
  63. (declare-function org-decrease-number-at-point "org" (&optional inc))
  64. (declare-function org-delete-backward-char "org" (n))
  65. (declare-function org-delete-char "org" (n))
  66. (declare-function org-delete-indentation "org" (&optional arg))
  67. (declare-function org-demote-subtree "org" ())
  68. (declare-function org-display-outline-path "org" (&optional file current separator just-return-string))
  69. (declare-function org-down-element "org" ())
  70. (declare-function org-edit-special "org" (&optional arg))
  71. (declare-function org-element-at-point "org-element" ())
  72. (declare-function org-element-type "org-element" (element))
  73. (declare-function org-emphasize "org" (&optional char))
  74. (declare-function org-end-of-line "org" (&optional n))
  75. (declare-function org-entry-put "org" (pom property value))
  76. (declare-function org-eval-in-calendar "org" (form &optional keepdate))
  77. (declare-function org-evaluate-time-range "org" (&optional to-buffer))
  78. (declare-function org-export-dispatch "org" (&optional arg))
  79. (declare-function org-feed-goto-inbox "org" (feed))
  80. (declare-function org-feed-update-all "org" ())
  81. (declare-function org-fill-paragraph "org" (&optional justify region))
  82. (declare-function org-find-file-at-mouse "org" (ev))
  83. (declare-function org-footnote-action "org" (&optional special))
  84. (declare-function org-force-cycle-archived "org" ())
  85. (declare-function org-force-self-insert "org" (n))
  86. (declare-function org-forward-element "org" ())
  87. (declare-function org-forward-heading-same-level "org" (arg &optional invisible-ok))
  88. (declare-function org-forward-paragraph "org" ())
  89. (declare-function org-forward-sentence "org" (&optional arg))
  90. (declare-function org-goto "org" (&optional alternative-interface))
  91. (declare-function org-goto-calendar "org" (&optional arg))
  92. (declare-function org-inc-effort "org" ())
  93. (declare-function org-increase-number-at-point "org" (&optional inc))
  94. (declare-function org-info-find-node "org" (&optional nodename))
  95. (declare-function org-insert-all-links "org" (arg &optional pre post))
  96. (declare-function org-insert-drawer "org" (&optional arg drawer))
  97. (declare-function org-insert-heading-respect-content "org" (&optional invisible-ok))
  98. (declare-function org-insert-last-stored-link "org" (arg))
  99. (declare-function org-insert-link "org" (&optional complete-file link-location default-description))
  100. (declare-function org-insert-structure-template "org" (type))
  101. (declare-function org-insert-todo-heading "org" (arg &optional force-heading))
  102. (declare-function org-insert-todo-heading-respect-content "org" (&optional force-state))
  103. (declare-function org-kill-line "org" (&optional arg))
  104. (declare-function org-kill-note-or-show-branches "org" ())
  105. (declare-function org-list-make-subtree "org" ())
  106. (declare-function org-mark-element "org" ())
  107. (declare-function org-mark-ring-goto "org" (&optional n))
  108. (declare-function org-mark-ring-push "org" (&optional pos buffer))
  109. (declare-function org-mark-subtree "org" (&optional up))
  110. (declare-function org-match-sparse-tree "org" (&optional todo-only match))
  111. (declare-function org-meta-return "org" (&optional arg))
  112. (declare-function org-metadown "org" (&optional _arg))
  113. (declare-function org-metaleft "org" (&optional _))
  114. (declare-function org-metaright "org" (&optional _arg))
  115. (declare-function org-metaup "org" (&optional _arg))
  116. (declare-function org-narrow-to-block "org" ())
  117. (declare-function org-narrow-to-element "org" ())
  118. (declare-function org-narrow-to-subtree "org" ())
  119. (declare-function org-next-block "org" (arg &optional backward block-regexp))
  120. (declare-function org-next-link "org" (&optional search-backward))
  121. (declare-function org-next-visible-heading "org" (arg))
  122. (declare-function org-open-at-mouse "org" (ev))
  123. (declare-function org-open-at-point "org" (&optional arg reference-buffer))
  124. (declare-function org-open-line "org" (n))
  125. (declare-function org-paste-special "org" (arg))
  126. (declare-function org-plot/gnuplot "org-plot" (&optional params))
  127. (declare-function org-previous-block "org" (arg &optional block-regexp))
  128. (declare-function org-previous-link "org" ())
  129. (declare-function org-previous-visible-heading "org" (arg))
  130. (declare-function org-priority "org" (&optional action show))
  131. (declare-function org-promote-subtree "org" ())
  132. (declare-function org-redisplay-inline-images "org" ())
  133. (declare-function org-refile "org" (&optional arg1 default-buffer rfloc msg))
  134. (declare-function org-reftex-citation "org" ())
  135. (declare-function org-reload "org" (&optional arg1))
  136. (declare-function org-remove-file "org" (&optional file))
  137. (declare-function org-resolve-clocks "org" (&optional only-dangling-p prompt-fn last-valid))
  138. (declare-function org-return "org" (&optional indent))
  139. (declare-function org-return-indent "org" ())
  140. (declare-function org-reveal "org" (&optional siblings))
  141. (declare-function org-schedule "org" (arg &optional time))
  142. (declare-function org-self-insert-command "org" (N))
  143. (declare-function org-set-effort "org" (&optional increment value))
  144. (declare-function org-set-property "org" (property value))
  145. (declare-function org-set-property-and-value "org" (use-last))
  146. (declare-function org-set-tags-command "org" (&optional arg))
  147. (declare-function org-shiftcontroldown "org" (&optional n))
  148. (declare-function org-shiftcontrolleft "org" ())
  149. (declare-function org-shiftcontrolright "org" ())
  150. (declare-function org-shiftcontrolup "org" (&optional n))
  151. (declare-function org-shiftdown "org" (&optional arg))
  152. (declare-function org-shiftleft "org" (&optional arg))
  153. (declare-function org-shiftmetadown "org" (&optional _arg))
  154. (declare-function org-shiftmetaleft "org" ())
  155. (declare-function org-shiftmetaright "org" ())
  156. (declare-function org-shiftmetaup "org" (&optional arg))
  157. (declare-function org-shiftright "org" (&optional arg))
  158. (declare-function org-shifttab "org" (&optional arg))
  159. (declare-function org-shiftup "org" (&optional arg))
  160. (declare-function org-show-all "org" (&optional types))
  161. (declare-function org-show-children "org" (&optional level))
  162. (declare-function org-show-subtree "org" ())
  163. (declare-function org-sort "org" (&optional with-case))
  164. (declare-function org-sparse-tree "org" (&optional arg type))
  165. (declare-function org-table-blank-field "org" ())
  166. (declare-function org-table-copy-down "org" (n))
  167. (declare-function org-table-create-or-convert-from-region "org" (arg))
  168. (declare-function org-table-create-with-table\.el "org-table" ())
  169. (declare-function org-table-edit-field "org" (arg))
  170. (declare-function org-table-eval-formula "org" (&optional arg equation suppress-align suppress-const suppress-store suppress-analysis))
  171. (declare-function org-table-field-info "org" (arg))
  172. (declare-function org-table-rotate-recalc-marks "org" (&optional newchar))
  173. (declare-function org-table-sum "org" (&optional beg end nlast))
  174. (declare-function org-table-toggle-coordinate-overlays "org" ())
  175. (declare-function org-table-toggle-formula-debugger "org" ())
  176. (declare-function org-time-stamp "org" (arg &optional inactive))
  177. (declare-function org-time-stamp-inactive "org" (&optional arg))
  178. (declare-function org-timer "org" (&optional restart no-insert))
  179. (declare-function org-timer-item "org" (&optional arg))
  180. (declare-function org-timer-pause-or-continue "org" (&optional stop))
  181. (declare-function org-timer-set-timer "org" (&optional opt))
  182. (declare-function org-timer-start "org" (&optional offset))
  183. (declare-function org-timer-stop "org" ())
  184. (declare-function org-todo "org" (&optional arg1))
  185. (declare-function org-toggle-archive-tag "org" (&optional find-done))
  186. (declare-function org-toggle-checkbox "org" (&optional toggle-presence))
  187. (declare-function org-toggle-comment "org" ())
  188. (declare-function org-toggle-fixed-width "org" ())
  189. (declare-function org-toggle-inline-images "org" (&optional include-linked))
  190. (declare-function org-latex-preview "org" (&optional arg))
  191. (declare-function org-toggle-narrow-to-subtree "org" ())
  192. (declare-function org-toggle-ordered-property "org" ())
  193. (declare-function org-toggle-pretty-entities "org" ())
  194. (declare-function org-toggle-tags-groups "org" ())
  195. (declare-function org-toggle-time-stamp-overlays "org" ())
  196. (declare-function org-transpose-element "org" ())
  197. (declare-function org-transpose-words "org" ())
  198. (declare-function org-tree-to-indirect-buffer "org" (&optional arg))
  199. (declare-function org-up-element "org" ())
  200. (declare-function org-update-statistics-cookies "org" (all))
  201. (declare-function org-yank "org" (&optional arg))
  202. (declare-function orgtbl-ascii-plot "org-table" (&optional ask))
  203. ;;; Variables
  204. (defvar org-mode-map (make-sparse-keymap)
  205. "Keymap fo Org mode.")
  206. (defvaralias 'org-CUA-compatible 'org-replace-disputed-keys)
  207. (defcustom org-replace-disputed-keys nil
  208. "Non-nil means use alternative key bindings for some keys.
  209. Org mode uses S-<cursor> keys for changing timestamps and priorities.
  210. These keys are also used by other packages like Shift Select mode,
  211. CUA mode or Windmove. If you want to use Org mode together with
  212. one of these other modes, or more generally if you would like to
  213. move some Org mode commands to other keys, set this variable and
  214. configure the keys with the variable `org-disputed-keys'.
  215. This option is only relevant at load-time of Org mode, and must be set
  216. *before* org.el is loaded. Changing it requires a restart of Emacs to
  217. become effective."
  218. :group 'org-startup
  219. :type 'boolean
  220. :safe #'booleanp)
  221. (defcustom org-use-extra-keys nil
  222. "Non-nil means use extra key sequence definitions for certain commands.
  223. This happens automatically if `window-system' is nil. This
  224. variable lets you do the same manually. You must set it before
  225. loading Org."
  226. :group 'org-startup
  227. :type 'boolean
  228. :safe #'booleanp)
  229. (defcustom org-disputed-keys
  230. '(([(shift up)] . [(meta p)])
  231. ([(shift down)] . [(meta n)])
  232. ([(shift left)] . [(meta -)])
  233. ([(shift right)] . [(meta +)])
  234. ([(control shift right)] . [(meta shift +)])
  235. ([(control shift left)] . [(meta shift -)]))
  236. "Keys for which Org mode and other modes compete.
  237. This is an alist, cars are the default keys, second element specifies
  238. the alternative to use when `org-replace-disputed-keys' is t.
  239. Keys can be specified in any syntax supported by `define-key'.
  240. The value of this option takes effect only at Org mode startup,
  241. therefore you'll have to restart Emacs to apply it after changing."
  242. :group 'org-startup
  243. :type 'alist)
  244. (defcustom org-mouse-1-follows-link
  245. (if (boundp 'mouse-1-click-follows-link) mouse-1-click-follows-link t)
  246. "Non-nil means mouse-1 on a link will follow the link.
  247. A longer mouse click will still set point. Needs to be set
  248. before org.el is loaded."
  249. :group 'org-link-follow
  250. :version "26.1"
  251. :package-version '(Org . "8.3")
  252. :type '(choice
  253. (const :tag "A double click follows the link" double)
  254. (const :tag "Unconditionally follow the link with mouse-1" t)
  255. (integer :tag "mouse-1 click does not follow the link if longer than N ms" 450))
  256. :safe t)
  257. (defcustom org-tab-follows-link nil
  258. "Non-nil means on links TAB will follow the link.
  259. Needs to be set before Org is loaded.
  260. This really should not be used, it does not make sense, and the
  261. implementation is bad."
  262. :group 'org-link-follow
  263. :type 'boolean)
  264. (defcustom org-follow-link-hook nil
  265. "Hook that is run after a link has been followed."
  266. :group 'org-link-follow
  267. :type 'hook)
  268. (defcustom org-return-follows-link nil
  269. "Non-nil means on links RET will follow the link.
  270. In tables, the special behavior of RET has precedence."
  271. :group 'org-link-follow
  272. :type 'boolean
  273. :safe t)
  274. ;;; Functions
  275. ;;;; Base functions
  276. (defun org-key (key)
  277. "Select key according to `org-replace-disputed-keys' and `org-disputed-keys'.
  278. Or return the original if not disputed."
  279. (when org-replace-disputed-keys
  280. (let* ((nkey (key-description key))
  281. (x (cl-find-if (lambda (x) (equal (key-description (car x)) nkey))
  282. org-disputed-keys)))
  283. (setq key (if x (cdr x) key))))
  284. key)
  285. (defun org-defkey (keymap key def)
  286. "Define a key, possibly translated, as returned by `org-key'."
  287. (define-key keymap (org-key key) def))
  288. (defun org-remap (map &rest commands)
  289. "In MAP, remap the functions given in COMMANDS.
  290. COMMANDS is a list of alternating OLDDEF NEWDEF command names."
  291. (let (new old)
  292. (while commands
  293. (setq old (pop commands) new (pop commands))
  294. (org-defkey map (vector 'remap old) new))))
  295. ;;; Mouse map
  296. (defvar org-mouse-map (make-sparse-keymap))
  297. (org-defkey org-mouse-map [mouse-2] 'org-open-at-mouse)
  298. (org-defkey org-mouse-map [mouse-3] 'org-find-file-at-mouse)
  299. (when org-mouse-1-follows-link
  300. (org-defkey org-mouse-map [follow-link] 'mouse-face))
  301. (when org-tab-follows-link
  302. (org-defkey org-mouse-map (kbd "<tab>") #'org-open-at-point)
  303. (org-defkey org-mouse-map (kbd "TAB") #'org-open-at-point))
  304. ;;; Read date map
  305. (defvar org-read-date-minibuffer-local-map
  306. (let* ((map (make-sparse-keymap)))
  307. (set-keymap-parent map minibuffer-local-map)
  308. (org-defkey map (kbd ".")
  309. (lambda () (interactive)
  310. ;; Are we at the beginning of the prompt?
  311. (if (looking-back "^[^:]+: "
  312. (let ((inhibit-field-text-motion t))
  313. (line-beginning-position)))
  314. (org-eval-in-calendar '(calendar-goto-today))
  315. (insert "."))))
  316. (org-defkey map (kbd "C-.")
  317. (lambda () (interactive)
  318. (org-eval-in-calendar '(calendar-goto-today))))
  319. (org-defkey map (kbd "M-S-<left>")
  320. (lambda () (interactive)
  321. (org-eval-in-calendar '(calendar-backward-month 1))))
  322. (org-defkey map (kbd "ESC S-<left>")
  323. (lambda () (interactive)
  324. (org-eval-in-calendar '(calendar-backward-month 1))))
  325. (org-defkey map (kbd "M-S-<right>")
  326. (lambda () (interactive)
  327. (org-eval-in-calendar '(calendar-forward-month 1))))
  328. (org-defkey map (kbd "ESC S-<right>")
  329. (lambda () (interactive)
  330. (org-eval-in-calendar '(calendar-forward-month 1))))
  331. (org-defkey map (kbd "M-S-<up>")
  332. (lambda () (interactive)
  333. (org-eval-in-calendar '(calendar-backward-year 1))))
  334. (org-defkey map (kbd "ESC S-<up>")
  335. (lambda () (interactive)
  336. (org-eval-in-calendar '(calendar-backward-year 1))))
  337. (org-defkey map (kbd "M-S-<down>")
  338. (lambda () (interactive)
  339. (org-eval-in-calendar '(calendar-forward-year 1))))
  340. (org-defkey map (kbd "ESC S-<down>")
  341. (lambda () (interactive)
  342. (org-eval-in-calendar '(calendar-forward-year 1))))
  343. (org-defkey map (kbd "S-<up>")
  344. (lambda () (interactive)
  345. (org-eval-in-calendar '(calendar-backward-week 1))))
  346. (org-defkey map (kbd "S-<down>")
  347. (lambda () (interactive)
  348. (org-eval-in-calendar '(calendar-forward-week 1))))
  349. (org-defkey map (kbd "S-<left>")
  350. (lambda () (interactive)
  351. (org-eval-in-calendar '(calendar-backward-day 1))))
  352. (org-defkey map (kbd "S-<right>")
  353. (lambda () (interactive)
  354. (org-eval-in-calendar '(calendar-forward-day 1))))
  355. (org-defkey map (kbd "!")
  356. (lambda () (interactive)
  357. (org-eval-in-calendar '(diary-view-entries))
  358. (message "")))
  359. (org-defkey map (kbd ">")
  360. (lambda () (interactive)
  361. (org-eval-in-calendar '(calendar-scroll-left 1))))
  362. (org-defkey map (kbd "<")
  363. (lambda () (interactive)
  364. (org-eval-in-calendar '(calendar-scroll-right 1))))
  365. (org-defkey map (kbd "C-v")
  366. (lambda () (interactive)
  367. (org-eval-in-calendar
  368. '(calendar-scroll-left-three-months 1))))
  369. (org-defkey map (kbd "M-v")
  370. (lambda () (interactive)
  371. (org-eval-in-calendar
  372. '(calendar-scroll-right-three-months 1))))
  373. map)
  374. "Keymap for minibuffer commands when using `org-read-date'.")
  375. ;;; Global bindings
  376. ;;;; Outline functions
  377. (define-key org-mode-map [menu-bar headings] 'undefined)
  378. (define-key org-mode-map [menu-bar hide] 'undefined)
  379. (define-key org-mode-map [menu-bar show] 'undefined)
  380. (define-key org-mode-map [remap outline-mark-subtree] #'org-mark-subtree)
  381. (define-key org-mode-map [remap outline-show-subtree] #'org-show-subtree)
  382. (define-key org-mode-map [remap outline-forward-same-level]
  383. #'org-forward-heading-same-level)
  384. (define-key org-mode-map [remap outline-backward-same-level]
  385. #'org-backward-heading-same-level)
  386. (define-key org-mode-map [remap outline-show-branches]
  387. #'org-kill-note-or-show-branches)
  388. (define-key org-mode-map [remap outline-promote] #'org-promote-subtree)
  389. (define-key org-mode-map [remap outline-demote] #'org-demote-subtree)
  390. (define-key org-mode-map [remap outline-insert-heading] #'org-ctrl-c-ret)
  391. (define-key org-mode-map [remap outline-next-visible-heading]
  392. #'org-next-visible-heading)
  393. (define-key org-mode-map [remap outline-previous-visible-heading]
  394. #'org-previous-visible-heading)
  395. (define-key org-mode-map [remap show-children] #'org-show-children)
  396. ;;;; Make `C-c C-x' a prefix key
  397. (org-defkey org-mode-map (kbd "C-c C-x") (make-sparse-keymap))
  398. ;;;; TAB key with modifiers
  399. (org-defkey org-mode-map (kbd "C-i") #'org-cycle)
  400. (org-defkey org-mode-map (kbd "<tab>") #'org-cycle)
  401. (org-defkey org-mode-map (kbd "C-<tab>") #'org-force-cycle-archived)
  402. ;; Override text-mode binding to expose `complete-symbol' for
  403. ;; pcomplete functionality.
  404. (org-defkey org-mode-map (kbd "M-<tab>") nil)
  405. (org-defkey org-mode-map (kbd "M-TAB") nil)
  406. (org-defkey org-mode-map (kbd "ESC <tab>") nil)
  407. (org-defkey org-mode-map (kbd "ESC TAB") nil)
  408. (org-defkey org-mode-map (kbd "<S-iso-leftab>") #'org-shifttab)
  409. (org-defkey org-mode-map (kbd "S-<tab>") #'org-shifttab)
  410. (org-defkey org-mode-map (kbd "S-TAB") #'org-shifttab)
  411. (define-key org-mode-map (kbd "<backtab>") #'org-shifttab)
  412. ;;;; RET/<return> key with modifiers
  413. (org-defkey org-mode-map (kbd "S-<return>") #'org-table-copy-down)
  414. (org-defkey org-mode-map (kbd "S-RET") #'org-table-copy-down)
  415. (org-defkey org-mode-map (kbd "M-S-<return>") #'org-insert-todo-heading)
  416. (org-defkey org-mode-map (kbd "M-S-RET") #'org-insert-todo-heading)
  417. (org-defkey org-mode-map (kbd "ESC S-<return>") #'org-insert-todo-heading)
  418. (org-defkey org-mode-map (kbd "ESC S-RET") #'org-insert-todo-heading)
  419. (org-defkey org-mode-map (kbd "M-<return>") #'org-meta-return)
  420. (org-defkey org-mode-map (kbd "M-RET") #'org-meta-return)
  421. (org-defkey org-mode-map (kbd "ESC <return>") #'org-meta-return)
  422. (org-defkey org-mode-map (kbd "ESC RET") #'org-meta-return)
  423. ;;;; Cursor keys with modifiers
  424. (org-defkey org-mode-map (kbd "M-<left>") #'org-metaleft)
  425. (org-defkey org-mode-map (kbd "M-<right>") #'org-metaright)
  426. (org-defkey org-mode-map (kbd "ESC <right>") #'org-metaright)
  427. (org-defkey org-mode-map (kbd "M-<up>") #'org-metaup)
  428. (org-defkey org-mode-map (kbd "ESC <up>") #'org-metaup)
  429. (org-defkey org-mode-map (kbd "M-<down>") #'org-metadown)
  430. (org-defkey org-mode-map (kbd "ESC <down>") #'org-metadown)
  431. (org-defkey org-mode-map (kbd "C-M-S-<right>") #'org-increase-number-at-point)
  432. (org-defkey org-mode-map (kbd "C-M-S-<left>") #'org-decrease-number-at-point)
  433. (org-defkey org-mode-map (kbd "M-S-<left>") #'org-shiftmetaleft)
  434. (org-defkey org-mode-map (kbd "ESC S-<left>") #'org-shiftmetaleft)
  435. (org-defkey org-mode-map (kbd "M-S-<right>") #'org-shiftmetaright)
  436. (org-defkey org-mode-map (kbd "ESC S-<right>") #'org-shiftmetaright)
  437. (org-defkey org-mode-map (kbd "M-S-<up>") #'org-shiftmetaup)
  438. (org-defkey org-mode-map (kbd "ESC S-<up>") #'org-shiftmetaup)
  439. (org-defkey org-mode-map (kbd "M-S-<down>") #'org-shiftmetadown)
  440. (org-defkey org-mode-map (kbd "ESC S-<down>") #'org-shiftmetadown)
  441. (org-defkey org-mode-map (kbd "S-<up>") #'org-shiftup)
  442. (org-defkey org-mode-map (kbd "S-<down>") #'org-shiftdown)
  443. (org-defkey org-mode-map (kbd "S-<left>") #'org-shiftleft)
  444. (org-defkey org-mode-map (kbd "S-<right>") #'org-shiftright)
  445. (org-defkey org-mode-map (kbd "C-S-<right>") #'org-shiftcontrolright)
  446. (org-defkey org-mode-map (kbd "C-S-<left>") #'org-shiftcontrolleft)
  447. (org-defkey org-mode-map (kbd "C-S-<up>") #'org-shiftcontrolup)
  448. (org-defkey org-mode-map (kbd "C-S-<down>") #'org-shiftcontroldown)
  449. ;;;; Extra keys for TTY access.
  450. ;; We only set them when really needed because otherwise the
  451. ;; menus don't show the simple keys
  452. (when (or org-use-extra-keys (not window-system))
  453. (org-defkey org-mode-map (kbd "C-c C-x c") #'org-table-copy-down)
  454. (org-defkey org-mode-map (kbd "C-c C-x m") #'org-meta-return)
  455. (org-defkey org-mode-map (kbd "C-c C-x M") #'org-insert-todo-heading)
  456. (org-defkey org-mode-map (kbd "C-c C-x RET") #'org-meta-return)
  457. (org-defkey org-mode-map (kbd "ESC RET") #'org-meta-return)
  458. (org-defkey org-mode-map (kbd "ESC <left>") #'org-metaleft)
  459. (org-defkey org-mode-map (kbd "C-c C-x l") #'org-metaleft)
  460. (org-defkey org-mode-map (kbd "ESC <right>") #'org-metaright)
  461. (org-defkey org-mode-map (kbd "C-c C-x r") #'org-metaright)
  462. (org-defkey org-mode-map (kbd "C-c C-x u") #'org-metaup)
  463. (org-defkey org-mode-map (kbd "C-c C-x d") #'org-metadown)
  464. (org-defkey org-mode-map (kbd "C-c C-x L") #'org-shiftmetaleft)
  465. (org-defkey org-mode-map (kbd "C-c C-x R") #'org-shiftmetaright)
  466. (org-defkey org-mode-map (kbd "C-c C-x U") #'org-shiftmetaup)
  467. (org-defkey org-mode-map (kbd "C-c C-x D") #'org-shiftmetadown)
  468. (org-defkey org-mode-map (kbd "C-c <up>") #'org-shiftup)
  469. (org-defkey org-mode-map (kbd "C-c <down>") #'org-shiftdown)
  470. (org-defkey org-mode-map (kbd "C-c <left>") #'org-shiftleft)
  471. (org-defkey org-mode-map (kbd "C-c <right>") #'org-shiftright)
  472. (org-defkey org-mode-map (kbd "C-c C-x <right>") #'org-shiftcontrolright)
  473. (org-defkey org-mode-map (kbd "C-c C-x <left>") #'org-shiftcontrolleft))
  474. ;;;; Narrowing bindings
  475. (org-defkey org-mode-map (kbd "C-x n s") #'org-narrow-to-subtree)
  476. (org-defkey org-mode-map (kbd "C-x n b") #'org-narrow-to-block)
  477. (org-defkey org-mode-map (kbd "C-x n e") #'org-narrow-to-element)
  478. ;;;; Remap usual Emacs bindings
  479. (org-remap org-mode-map
  480. 'self-insert-command 'org-self-insert-command
  481. 'delete-char 'org-delete-char
  482. 'delete-backward-char 'org-delete-backward-char
  483. 'kill-line 'org-kill-line
  484. 'open-line 'org-open-line
  485. 'yank 'org-yank
  486. 'comment-dwim 'org-comment-dwim
  487. 'move-beginning-of-line 'org-beginning-of-line
  488. 'move-end-of-line 'org-end-of-line
  489. 'forward-paragraph 'org-forward-paragraph
  490. 'backward-paragraph 'org-backward-paragraph
  491. 'backward-sentence 'org-backward-sentence
  492. 'forward-sentence 'org-forward-sentence
  493. 'fill-paragraph 'org-fill-paragraph
  494. 'delete-indentation 'org-delete-indentation
  495. 'transpose-words 'org-transpose-words)
  496. ;;;; All the other keys
  497. (org-defkey org-mode-map (kbd "|") #'org-force-self-insert)
  498. (org-defkey org-mode-map (kbd "C-c C-r") #'org-reveal)
  499. (org-defkey org-mode-map (kbd "C-M-t") #'org-transpose-element)
  500. (org-defkey org-mode-map (kbd "M-}") #'org-forward-element)
  501. (org-defkey org-mode-map (kbd "ESC }") #'org-forward-element)
  502. (org-defkey org-mode-map (kbd "M-{") #'org-backward-element)
  503. (org-defkey org-mode-map (kbd "ESC {") #'org-backward-element)
  504. (org-defkey org-mode-map (kbd "C-c C-^") #'org-up-element)
  505. (org-defkey org-mode-map (kbd "C-c C-_") #'org-down-element)
  506. (org-defkey org-mode-map (kbd "C-c C-f") #'org-forward-heading-same-level)
  507. (org-defkey org-mode-map (kbd "C-c C-b") #'org-backward-heading-same-level)
  508. (org-defkey org-mode-map (kbd "C-c M-f") #'org-next-block)
  509. (org-defkey org-mode-map (kbd "C-c M-b") #'org-previous-block)
  510. (org-defkey org-mode-map (kbd "C-c $") #'org-archive-subtree)
  511. (org-defkey org-mode-map (kbd "C-c C-x C-s") #'org-archive-subtree)
  512. (org-defkey org-mode-map (kbd "C-c C-x C-a") #'org-archive-subtree-default)
  513. (org-defkey org-mode-map (kbd "C-c C-x d") #'org-insert-drawer)
  514. (org-defkey org-mode-map (kbd "C-c C-x a") #'org-toggle-archive-tag)
  515. (org-defkey org-mode-map (kbd "C-c C-x A") #'org-archive-to-archive-sibling)
  516. (org-defkey org-mode-map (kbd "C-c C-x b") #'org-tree-to-indirect-buffer)
  517. (org-defkey org-mode-map (kbd "C-c C-x q") #'org-toggle-tags-groups)
  518. (org-defkey org-mode-map (kbd "C-c C-j") #'org-goto)
  519. (org-defkey org-mode-map (kbd "C-c C-t") #'org-todo)
  520. (org-defkey org-mode-map (kbd "C-c C-q") #'org-set-tags-command)
  521. (org-defkey org-mode-map (kbd "C-c C-s") #'org-schedule)
  522. (org-defkey org-mode-map (kbd "C-c C-d") #'org-deadline)
  523. (org-defkey org-mode-map (kbd "C-c ;") #'org-toggle-comment)
  524. (org-defkey org-mode-map (kbd "C-c C-w") #'org-refile)
  525. (org-defkey org-mode-map (kbd "C-c M-w") #'org-refile-copy)
  526. (org-defkey org-mode-map (kbd "C-c /") #'org-sparse-tree) ;minor-mode reserved
  527. (org-defkey org-mode-map (kbd "C-c \\") #'org-match-sparse-tree) ;minor-mode r.
  528. (org-defkey org-mode-map (kbd "C-c RET") #'org-ctrl-c-ret)
  529. (org-defkey org-mode-map (kbd "C-c C-x c") #'org-clone-subtree-with-time-shift)
  530. (org-defkey org-mode-map (kbd "C-c C-x v") #'org-copy-visible)
  531. (org-defkey org-mode-map (kbd "C-<return>") #'org-insert-heading-respect-content)
  532. (org-defkey org-mode-map (kbd "C-S-<return>") #'org-insert-todo-heading-respect-content)
  533. (org-defkey org-mode-map (kbd "C-c C-x C-n") #'org-next-link)
  534. (org-defkey org-mode-map (kbd "C-c C-x C-p") #'org-previous-link)
  535. (org-defkey org-mode-map (kbd "C-c C-l") #'org-insert-link)
  536. (org-defkey org-mode-map (kbd "C-c M-l") #'org-insert-last-stored-link)
  537. (org-defkey org-mode-map (kbd "C-c C-M-l") #'org-insert-all-links)
  538. (org-defkey org-mode-map (kbd "C-c C-o") #'org-open-at-point)
  539. (org-defkey org-mode-map (kbd "C-c %") #'org-mark-ring-push)
  540. (org-defkey org-mode-map (kbd "C-c &") #'org-mark-ring-goto)
  541. (org-defkey org-mode-map (kbd "C-c C-z") #'org-add-note) ;alternative binding
  542. (org-defkey org-mode-map (kbd "C-c .") #'org-time-stamp) ;minor-mode reserved
  543. (org-defkey org-mode-map (kbd "C-c !") #'org-time-stamp-inactive) ;minor-mode r.
  544. (org-defkey org-mode-map (kbd "C-c ,") #'org-priority) ;minor-mode reserved
  545. (org-defkey org-mode-map (kbd "C-c C-y") #'org-evaluate-time-range)
  546. (org-defkey org-mode-map (kbd "C-c >") #'org-goto-calendar)
  547. (org-defkey org-mode-map (kbd "C-c <") #'org-date-from-calendar)
  548. (org-defkey org-mode-map (kbd "C-,") #'org-cycle-agenda-files)
  549. (org-defkey org-mode-map (kbd "C-'") #'org-cycle-agenda-files)
  550. (org-defkey org-mode-map (kbd "C-c [") #'org-agenda-file-to-front)
  551. (org-defkey org-mode-map (kbd "C-c ]") #'org-remove-file)
  552. (org-defkey org-mode-map (kbd "C-c C-x <") #'org-agenda-set-restriction-lock)
  553. (org-defkey org-mode-map (kbd "C-c C-x >") #'org-agenda-remove-restriction-lock)
  554. (org-defkey org-mode-map (kbd "C-c -") #'org-ctrl-c-minus)
  555. (org-defkey org-mode-map (kbd "C-c *") #'org-ctrl-c-star)
  556. (org-defkey org-mode-map (kbd "C-c TAB") #'org-ctrl-c-tab)
  557. (org-defkey org-mode-map (kbd "C-c ^") #'org-sort)
  558. (org-defkey org-mode-map (kbd "C-c C-c") #'org-ctrl-c-ctrl-c)
  559. (org-defkey org-mode-map (kbd "C-c C-k") #'org-kill-note-or-show-branches)
  560. (org-defkey org-mode-map (kbd "C-c #") #'org-update-statistics-cookies)
  561. (org-defkey org-mode-map (kbd "RET") #'org-return)
  562. (org-defkey org-mode-map (kbd "C-j") #'org-return-indent)
  563. (org-defkey org-mode-map (kbd "C-c ?") #'org-table-field-info)
  564. (org-defkey org-mode-map (kbd "C-c SPC") #'org-table-blank-field)
  565. (org-defkey org-mode-map (kbd "C-c +") #'org-table-sum)
  566. (org-defkey org-mode-map (kbd "C-c =") #'org-table-eval-formula)
  567. (org-defkey org-mode-map (kbd "C-c '") #'org-edit-special)
  568. (org-defkey org-mode-map (kbd "C-c `") #'org-table-edit-field)
  569. (org-defkey org-mode-map (kbd "C-c \" a") #'orgtbl-ascii-plot)
  570. (org-defkey org-mode-map (kbd "C-c \" g") #'org-plot/gnuplot)
  571. (org-defkey org-mode-map (kbd "C-c |") #'org-table-create-or-convert-from-region)
  572. (org-defkey org-mode-map (kbd "C-#") #'org-table-rotate-recalc-marks)
  573. (org-defkey org-mode-map (kbd "C-c ~") #'org-table-create-with-table.el)
  574. (org-defkey org-mode-map (kbd "C-c C-a") #'org-attach)
  575. (org-defkey org-mode-map (kbd "C-c }") #'org-table-toggle-coordinate-overlays)
  576. (org-defkey org-mode-map (kbd "C-c {") #'org-table-toggle-formula-debugger)
  577. (org-defkey org-mode-map (kbd "C-c C-e") #'org-export-dispatch)
  578. (org-defkey org-mode-map (kbd "C-c :") #'org-toggle-fixed-width)
  579. (org-defkey org-mode-map (kbd "C-c C-x C-f") #'org-emphasize)
  580. (org-defkey org-mode-map (kbd "C-c C-x f") #'org-footnote-action)
  581. (org-defkey org-mode-map (kbd "C-c @") #'org-mark-subtree)
  582. (org-defkey org-mode-map (kbd "M-h") #'org-mark-element)
  583. (org-defkey org-mode-map (kbd "ESC h") #'org-mark-element)
  584. (org-defkey org-mode-map (kbd "C-c C-*") #'org-list-make-subtree)
  585. (org-defkey org-mode-map (kbd "C-c C-x C-w") #'org-cut-special)
  586. (org-defkey org-mode-map (kbd "C-c C-x M-w") #'org-copy-special)
  587. (org-defkey org-mode-map (kbd "C-c C-x C-y") #'org-paste-special)
  588. (org-defkey org-mode-map (kbd "C-c C-x C-t") #'org-toggle-time-stamp-overlays)
  589. (org-defkey org-mode-map (kbd "C-c C-x C-i") #'org-clock-in)
  590. (org-defkey org-mode-map (kbd "C-c C-x C-x") #'org-clock-in-last)
  591. (org-defkey org-mode-map (kbd "C-c C-x C-z") #'org-resolve-clocks)
  592. (org-defkey org-mode-map (kbd "C-c C-x C-o") #'org-clock-out)
  593. (org-defkey org-mode-map (kbd "C-c C-x C-j") #'org-clock-goto)
  594. (org-defkey org-mode-map (kbd "C-c C-x C-q") #'org-clock-cancel)
  595. (org-defkey org-mode-map (kbd "C-c C-x C-d") #'org-clock-display)
  596. (org-defkey org-mode-map (kbd "C-c C-x x") #'org-dynamic-block-insert-dblock)
  597. (org-defkey org-mode-map (kbd "C-c C-x C-u") #'org-dblock-update)
  598. (org-defkey org-mode-map (kbd "C-c C-x C-l") #'org-latex-preview)
  599. (org-defkey org-mode-map (kbd "C-c C-x C-v") #'org-toggle-inline-images)
  600. (org-defkey org-mode-map (kbd "C-c C-x C-M-v") #'org-redisplay-inline-images)
  601. (org-defkey org-mode-map (kbd "C-c C-x \\") #'org-toggle-pretty-entities)
  602. (org-defkey org-mode-map (kbd "C-c C-x C-b") #'org-toggle-checkbox)
  603. (org-defkey org-mode-map (kbd "C-c C-x p") #'org-set-property)
  604. (org-defkey org-mode-map (kbd "C-c C-x P") #'org-set-property-and-value)
  605. (org-defkey org-mode-map (kbd "C-c C-x e") #'org-set-effort)
  606. (org-defkey org-mode-map (kbd "C-c C-x E") #'org-inc-effort)
  607. (org-defkey org-mode-map (kbd "C-c C-x o") #'org-toggle-ordered-property)
  608. (org-defkey org-mode-map (kbd "C-c C-,") #'org-insert-structure-template)
  609. (org-defkey org-mode-map (kbd "C-c C-x .") #'org-timer)
  610. (org-defkey org-mode-map (kbd "C-c C-x -") #'org-timer-item)
  611. (org-defkey org-mode-map (kbd "C-c C-x 0") #'org-timer-start)
  612. (org-defkey org-mode-map (kbd "C-c C-x _") #'org-timer-stop)
  613. (org-defkey org-mode-map (kbd "C-c C-x ;") #'org-timer-set-timer)
  614. (org-defkey org-mode-map (kbd "C-c C-x ,") #'org-timer-pause-or-continue)
  615. (org-defkey org-mode-map (kbd "C-c C-x C-c") #'org-columns)
  616. (org-defkey org-mode-map (kbd "C-c C-x !") #'org-reload)
  617. (org-defkey org-mode-map (kbd "C-c C-x g") #'org-feed-update-all)
  618. (org-defkey org-mode-map (kbd "C-c C-x G") #'org-feed-goto-inbox)
  619. (org-defkey org-mode-map (kbd "C-c C-x [") #'org-reftex-citation)
  620. (org-defkey org-mode-map (kbd "C-c C-x I") #'org-info-find-node)
  621. ;;; Speed keys
  622. (defcustom org-use-speed-commands nil
  623. "Non-nil means activate single letter commands at beginning of a headline.
  624. This may also be a function to test for appropriate locations where speed
  625. commands should be active.
  626. For example, to activate speed commands when the point is on any
  627. star at the beginning of the headline, you can do this:
  628. (setq org-use-speed-commands
  629. (lambda () (and (looking-at org-outline-regexp) (looking-back \"^\\**\"))))"
  630. :group 'org-structure
  631. :type '(choice
  632. (const :tag "Never" nil)
  633. (const :tag "At beginning of headline stars" t)
  634. (function)))
  635. (defcustom org-speed-commands-user nil
  636. "Alist of additional speed commands.
  637. This list will be checked before `org-speed-commands-default'
  638. when the variable `org-use-speed-commands' is non-nil
  639. and when the cursor is at the beginning of a headline.
  640. The car of each entry is a string with a single letter, which must
  641. be assigned to `self-insert-command' in the global map.
  642. The cdr is either a command to be called interactively, a function
  643. to be called, or a form to be evaluated.
  644. An entry that is just a list with a single string will be interpreted
  645. as a descriptive headline that will be added when listing the speed
  646. commands in the Help buffer using the `?' speed command."
  647. :group 'org-structure
  648. :type '(repeat :value ("k" . ignore)
  649. (choice :value ("k" . ignore)
  650. (list :tag "Descriptive Headline" (string :tag "Headline"))
  651. (cons :tag "Letter and Command"
  652. (string :tag "Command letter")
  653. (choice
  654. (function)
  655. (sexp))))))
  656. (defcustom org-speed-command-hook
  657. '(org-speed-command-activate org-babel-speed-command-activate)
  658. "Hook for activating speed commands at strategic locations.
  659. Hook functions are called in sequence until a valid handler is
  660. found.
  661. Each hook takes a single argument, a user-pressed command key
  662. which is also a `self-insert-command' from the global map.
  663. Within the hook, examine the cursor position and the command key
  664. and return nil or a valid handler as appropriate. Handler could
  665. be one of an interactive command, a function, or a form.
  666. Set `org-use-speed-commands' to non-nil value to enable this
  667. hook. The default setting is `org-speed-command-activate'."
  668. :group 'org-structure
  669. :version "24.1"
  670. :type 'hook)
  671. (defconst org-speed-commands-default
  672. '(("Outline Navigation")
  673. ("n" . (org-speed-move-safe 'org-next-visible-heading))
  674. ("p" . (org-speed-move-safe 'org-previous-visible-heading))
  675. ("f" . (org-speed-move-safe 'org-forward-heading-same-level))
  676. ("b" . (org-speed-move-safe 'org-backward-heading-same-level))
  677. ("F" . org-next-block)
  678. ("B" . org-previous-block)
  679. ("u" . (org-speed-move-safe 'outline-up-heading))
  680. ("j" . org-goto)
  681. ("g" . (org-refile t))
  682. ("Outline Visibility")
  683. ("c" . org-cycle)
  684. ("C" . org-shifttab)
  685. (" " . org-display-outline-path)
  686. ("s" . org-toggle-narrow-to-subtree)
  687. ("k" . org-cut-subtree)
  688. ("=" . org-columns)
  689. ("Outline Structure Editing")
  690. ("U" . org-metaup)
  691. ("D" . org-metadown)
  692. ("r" . org-metaright)
  693. ("l" . org-metaleft)
  694. ("R" . org-shiftmetaright)
  695. ("L" . org-shiftmetaleft)
  696. ("i" . (progn (forward-char 1) (call-interactively
  697. 'org-insert-heading-respect-content)))
  698. ("^" . org-sort)
  699. ("w" . org-refile)
  700. ("a" . org-archive-subtree-default-with-confirmation)
  701. ("@" . org-mark-subtree)
  702. ("#" . org-toggle-comment)
  703. ("Clock Commands")
  704. ("I" . org-clock-in)
  705. ("O" . org-clock-out)
  706. ("Meta Data Editing")
  707. ("t" . org-todo)
  708. ("," . (org-priority))
  709. ("0" . (org-priority ?\ ))
  710. ("1" . (org-priority ?A))
  711. ("2" . (org-priority ?B))
  712. ("3" . (org-priority ?C))
  713. (":" . org-set-tags-command)
  714. ("e" . org-set-effort)
  715. ("E" . org-inc-effort)
  716. ("W" . (lambda(m) (interactive "sMinutes before warning: ")
  717. (org-entry-put (point) "APPT_WARNTIME" m)))
  718. ("Agenda Views etc")
  719. ("v" . org-agenda)
  720. ("/" . org-sparse-tree)
  721. ("Misc")
  722. ("o" . org-open-at-point)
  723. ("?" . org-speed-command-help)
  724. ("<" . (org-agenda-set-restriction-lock 'subtree))
  725. (">" . (org-agenda-remove-restriction-lock)))
  726. "The default speed commands.")
  727. (defun org-print-speed-command (e)
  728. (if (> (length (car e)) 1)
  729. (progn
  730. (princ "\n")
  731. (princ (car e))
  732. (princ "\n")
  733. (princ (make-string (length (car e)) ?-))
  734. (princ "\n"))
  735. (princ (car e))
  736. (princ " ")
  737. (if (symbolp (cdr e))
  738. (princ (symbol-name (cdr e)))
  739. (prin1 (cdr e)))
  740. (princ "\n")))
  741. (defun org-speed-command-help ()
  742. "Show the available speed commands."
  743. (interactive)
  744. (unless org-use-speed-commands
  745. (user-error "Speed commands are not activated, customize `org-use-speed-commands'"))
  746. (with-output-to-temp-buffer "*Help*"
  747. (princ "User-defined Speed commands\n===========================\n")
  748. (mapc #'org-print-speed-command org-speed-commands-user)
  749. (princ "\n")
  750. (princ "Built-in Speed commands\n=======================\n")
  751. (mapc #'org-print-speed-command org-speed-commands-default))
  752. (with-current-buffer "*Help*"
  753. (setq truncate-lines t)))
  754. (defun org-speed-move-safe (cmd)
  755. "Execute CMD, but make sure that the cursor always ends up in a headline.
  756. If not, return to the original position and throw an error."
  757. (interactive)
  758. (let ((pos (point)))
  759. (call-interactively cmd)
  760. (unless (and (bolp) (org-at-heading-p))
  761. (goto-char pos)
  762. (error "Boundary reached while executing %s" cmd))))
  763. (defun org-speed-command-activate (keys)
  764. "Hook for activating single-letter speed commands.
  765. `org-speed-commands-default' specifies a minimal command set.
  766. Use `org-speed-commands-user' for further customization."
  767. (when (or (and (bolp) (looking-at org-outline-regexp))
  768. (and (functionp org-use-speed-commands)
  769. (funcall org-use-speed-commands)))
  770. (cdr (assoc keys (append org-speed-commands-user
  771. org-speed-commands-default)))))
  772. ;;; Babel speed keys
  773. (defvar org-babel-key-prefix "\C-c\C-v"
  774. "The key prefix for Babel interactive key-bindings.
  775. See `org-babel-key-bindings' for the list of interactive Babel
  776. functions which are assigned key bindings, and see
  777. `org-babel-map' for the actual babel keymap.")
  778. (defvar org-babel-map (make-sparse-keymap)
  779. "The keymap for interactive Babel functions.")
  780. (defvar org-babel-key-bindings
  781. '(("p" . org-babel-previous-src-block)
  782. ("\C-p" . org-babel-previous-src-block)
  783. ("n" . org-babel-next-src-block)
  784. ("\C-n" . org-babel-next-src-block)
  785. ("e" . org-babel-execute-maybe)
  786. ("\C-e" . org-babel-execute-maybe)
  787. ("o" . org-babel-open-src-block-result)
  788. ("\C-o" . org-babel-open-src-block-result)
  789. ("\C-v" . org-babel-expand-src-block)
  790. ("v" . org-babel-expand-src-block)
  791. ("u" . org-babel-goto-src-block-head)
  792. ("\C-u" . org-babel-goto-src-block-head)
  793. ("g" . org-babel-goto-named-src-block)
  794. ("r" . org-babel-goto-named-result)
  795. ("\C-r" . org-babel-goto-named-result)
  796. ("\C-b" . org-babel-execute-buffer)
  797. ("b" . org-babel-execute-buffer)
  798. ("\C-s" . org-babel-execute-subtree)
  799. ("s" . org-babel-execute-subtree)
  800. ("\C-d" . org-babel-demarcate-block)
  801. ("d" . org-babel-demarcate-block)
  802. ("\C-t" . org-babel-tangle)
  803. ("t" . org-babel-tangle)
  804. ("\C-f" . org-babel-tangle-file)
  805. ("f" . org-babel-tangle-file)
  806. ("\C-c" . org-babel-check-src-block)
  807. ("c" . org-babel-check-src-block)
  808. ("\C-j" . org-babel-insert-header-arg)
  809. ("j" . org-babel-insert-header-arg)
  810. ("\C-l" . org-babel-load-in-session)
  811. ("l" . org-babel-load-in-session)
  812. ("\C-i" . org-babel-lob-ingest)
  813. ("i" . org-babel-lob-ingest)
  814. ("\C-I" . org-babel-view-src-block-info)
  815. ("I" . org-babel-view-src-block-info)
  816. ("\C-z" . org-babel-switch-to-session)
  817. ("z" . org-babel-switch-to-session-with-code)
  818. ("\C-a" . org-babel-sha1-hash)
  819. ("a" . org-babel-sha1-hash)
  820. ("h" . org-babel-describe-bindings)
  821. ("\C-x" . org-babel-do-key-sequence-in-edit-buffer)
  822. ("x" . org-babel-do-key-sequence-in-edit-buffer)
  823. ("k" . org-babel-remove-result-one-or-many)
  824. ("\C-\M-h" . org-babel-mark-block))
  825. "Alist of key bindings and interactive Babel functions.
  826. This list associates interactive Babel functions
  827. with keys. Each element of this list will add an entry to the
  828. `org-babel-map' using the letter key which is the `car' of the
  829. a-list placed behind the generic `org-babel-key-prefix'.")
  830. (define-key org-mode-map org-babel-key-prefix org-babel-map)
  831. (pcase-dolist (`(,key . ,def) org-babel-key-bindings)
  832. (define-key org-babel-map key def))
  833. (defun org-babel-speed-command-activate (keys)
  834. "Hook for activating single-letter code block commands."
  835. (when (and (bolp)
  836. (let ((case-fold-search t)) (looking-at "[ \t]*#\\+begin_src"))
  837. (eq 'src-block (org-element-type (org-element-at-point))))
  838. (cdr (assoc keys org-babel-key-bindings))))
  839. ;;;###autoload
  840. (defun org-babel-describe-bindings ()
  841. "Describe all keybindings behind `org-babel-key-prefix'."
  842. (interactive)
  843. (describe-bindings org-babel-key-prefix))
  844. (provide 'org-keys)
  845. ;;; org-keys.el ends here