org-keys.el 43 KB

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