我org-mode
用来组织自己(到目前为止非常有用!)。不过写起来有点烦
#+begin_comment
...
#+end_comment
每次我想插入一个环境。
问题
是否有为给定环境插入#+begin_
and的快捷方式?#+end_
以同样的方式C-c C-o comment RET
插入
\begin{comment}
\end{comment}
在latex-mode
.
我org-mode
用来组织自己(到目前为止非常有用!)。不过写起来有点烦
#+begin_comment
...
#+end_comment
每次我想插入一个环境。
问题
是否有为给定环境插入#+begin_
and的快捷方式?#+end_
以同样的方式C-c C-o comment RET
插入
\begin{comment}
\end{comment}
在latex-mode
.
Org 有一个名为“Easy templates”的工具:http: //orgmode.org/manual/Easy-Templates.html
缺少评论模板,但您可以添加它:
(add-to-list 'org-structure-template-alist '("C" "#+begin_comment\n?\n#+end_comment"))
并通过键入<C
后跟 TAB 来使用它。
或者,您可以使用 yasnippet。
现在相应的模板部分称为结构模板,插入序列由调用C-c C-,
。我没有(require 'org-tempo)
被描述为支持插入键,例如<s TAB
.
评论环境已经在org-structure-template-alist
. 所以评论将由
C-c C-, C
仍然可以添加用户定义的序列,例如,
C-c C-, [TAB|RET|SPC] src python :results output :session
交付
#+begin_src python :results output :session
#+end_src
(emacs 25.2.2,组织模式 9.2)
您可以查看“org-auctex-keys.el”,这是我创建的一种次要模式,用于在 Org 文档中提供 AUCTeX 键绑定。
在这种情况下,您将使用 Cc Ce 插入环境(提示输入环境名称),就像 AUCTeX 所做的那样。
如果您有兴趣,请查看https://github.com/fniessen/org-auctex-key-bindings。
不像 Michael Markert 的答案那么优雅,但可能更具扩展性。
1)您可以选择一个区域并将块放在它周围,或者您可以将块放在点上。
2)关键字扩展和历史。
3) 击键:抄送 b
该命令可以进一步扩展。例如,对于 src 块,可以支持各种开关,如 -n -r 和导出到文件。
(defun list-major-modes ()
"Returns list of potential major mode names (without the final -mode).
Note, that this is guess work."
(interactive)
(let (l)
(mapatoms #'(lambda (f) (and
(commandp f)
(string-match "-mode$" (symbol-name f))
;; auto-loaded
(or (and (autoloadp (symbol-function f))
(let ((doc (documentation f)))
(when doc
(and
(let ((docSplit (help-split-fundoc doc f)))
(and docSplit ;; car is argument list
(null (cdr (read (car docSplit)))))) ;; major mode starters have no arguments
(if (string-match "[mM]inor" doc) ;; If the doc contains "minor"...
(string-match "[mM]ajor" doc) ;; it should also contain "major".
t) ;; else we cannot decide therefrom
))))
(null (help-function-arglist f)))
(setq l (cons (substring (symbol-name f) 0 -5) l)))))
(when (called-interactively-p 'any)
(with-current-buffer (get-buffer-create "*Major Modes*")
(clear-buffer-delete)
(let ((standard-output (current-buffer)))
(display-completion-list l)
(display-buffer (current-buffer)))))
l))
(defvar org-insert-block-hist nil
"History for command `org-insert-block'")
(defvar org-insert-block-hist/src:major nil
"History for major mode in org src blocks.")
(defvar org-insert-block-list (append org-protecting-blocks
'("comment" ""))
"List of block types offered as completion for command `org-insert-block'")
;; block_src switches: -n () -r (references) -l "((%s))" (label format) -k (keep labels)
(defvar org-insert-block-list-specials
"Assoc list of Commands for reading additional specification of org-blocks.")
(setq org-insert-block-list-specials
'(("src" . (concat " " (completing-read "Major mode:"
(list-major-modes)
nil nil
(car org-insert-block-hist/src:major)
'(org-insert-block-hist/src:major . 1)
)))))
(defun org-insert-block (bl &optional b e attributes)
"Put region between b and e into org-block of kind bl.
If b or e is nil then put org-block limiters around point.
The string attributes is inserted behind the string #+begin_... "
(interactive
(let ((usereg (use-region-p))
(blKind (completing-read "Input block kind (tab: completion, uparrow: history):"
org-insert-block-list nil nil (car org-insert-block-hist) '(org-insert-block-hist . 1))))
(list
blKind
(when usereg (region-beginning))
(when usereg (region-end))
(let ((spec (assoc blKind org-insert-block-list-specials)))
(when spec (eval (cdr spec)))
))))
(let ((begBlock (concat "\n#+begin_" bl attributes "\n"))
(endBlock (concat "\n#+end_" bl "\n")))
(if (and b e)
(save-restriction
(narrow-to-region b e)
(goto-char (point-min))
(insert begBlock)
(goto-char (point-max))
(insert endBlock)
(indent-region (point-min) (point-max)))
(let ((p (point)))
(insert endBlock)
(goto-char p)
(insert begBlock))
)))
(add-hook 'org-mode-hook '(lambda ()
(local-set-key (kbd "C-c b") 'org-insert-block)))