Emacs 在“组织”模式下插入环境的快捷方式`
我正在使用Emacs 在“组织”模式下插入环境的快捷方式`,emacs,org-mode,key-bindings,Emacs,Org Mode,Key Bindings,我正在使用org模式来组织我自己(到目前为止非常有用!)。然而,这是一种恼人的写作 #+begin_comment ... #+end_comment 每次我都要插入一个环境 问题 对于给定的环境,是否有插入#+开始和#+结束的快捷方式 同样地,C-C-o注释RET将插入 \begin{comment} \end{comment} 在latex模式下Org有一个名为“简易模板”的工具: 缺少注释模板,但您可以使用以下内容添加该模板: (add-to-list 'org-stru
org模式
来组织我自己(到目前为止非常有用!)。然而,这是一种恼人的写作
#+begin_comment
...
#+end_comment
每次我都要插入一个环境
问题
对于给定的环境,是否有插入#+开始
和#+结束
的快捷方式
同样地,C-C-o注释RET
将插入
\begin{comment}
\end{comment}
在latex模式下
Org有一个名为“简易模板”的工具:
缺少注释模板,但您可以使用以下内容添加该模板:
(add-to-list 'org-structure-template-alist '("C" "#+begin_comment\n?\n#+end_comment"))
然后通过键入
来使用它,虽然没有迈克尔·马克特的答案那么优雅,但可能更具可扩展性
1) 可以选择一个区域并在其周围放置块,也可以将块放置在点上
2) 关键词扩展和历史
3) 击键:C-C-b
该命令可以进一步扩展。例如,对于src块,可以支持各种开关,如-n-r和export-to-files
(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)))
您可以看看“org auctex keys.el”,这是我创建的一个次要模式,用于在org文档中提供auctex键绑定
在本例中,您将使用C-C-e插入环境(提示输入环境名称),就像AUCTeX所做的那样
如果您感兴趣,请访问。现在调用相应的模板部分,插入序列由C-C-,
调用。我没有(需要'org tempo)
,它被描述为支持插入键,比如,我刚刚发现还有另一个用于插入src块的按键:C-C-v d。更妙的是,如果在一个代码块内调用它,会将其分为两个独立的代码块,如果在代码块外调用,则会在当前选择的内容周围添加一个新的代码块。上面的注释本身就应该有一个向上投票(添加了stuff@malcook)
C-c C-, C
C-c C-, [TAB|RET|SPC] src python :results output :session
#+begin_src python :results output :session
#+end_src