我正在使用org-mode
来组织自己(到目前为止非常有用!)。但是,它有点烦人的写作
#+begin_comment
...
#+end_comment
每次我想插入一个环境。
问题
是否有针对特定环境插入#+begin_
和#+end_
的快捷方式?
以C-c C-o comment RET
插入
\begin{comment}
\end{comment}
latex-mode
中的。
答案 0 :(得分:17)
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。
答案 1 :(得分:3)
现在,相应的模板部分称为Structure Template,插入序列由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)
答案 2 :(得分:1)
不像迈克尔·马克特的答案那么优雅,但可能更具扩展性。
1)您可以选择一个区域并将块放在它周围,或者您可以将块放在点上。
2)关键字扩展和历史。
3)击键:C-c 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)))
答案 3 :(得分:1)
您可以查看“org-auctex-keys.el”,这是我创建的一种次要模式,用于在Org文档中提供AUCTeX键绑定。
在这种情况下,您将使用C-c C-e插入环境(提示输入环境名称),就像AUCTeX所做的那样。
如果您有兴趣,请查看https://github.com/fniessen/org-auctex-key-bindings。