org-keys.el 42 KB

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