大家是如何輸入類似#+BEGIB_QUOTE這樣的命令的?

如果手動輸入的話感覺很麻煩呀, 但是google了下沒有發現emacs的org-mode有類似的快捷鍵. 因爲我用的是spacemacs, 也沒有查到相關快捷鍵. 希望請教下大家.

<q [tab]

謝謝, 不過這個我試過了, 不過沒有成功, 得到的結果是invalid register, 對了, 我用的是evil

在insert模式里试

https://orgmode.org/manual/Easy-templates.html 这边有相关文档

謝謝大家, 剛剛我才發現需要在新行鍵入<q然後tab才能生效, 我之前都是在已有內容後面嘗試, 所以都失敗了.

最新的 org 已经有内置快捷键插入 block 模板了, C-c C-, (org-insert-structure-template)

2 个赞

也可以用 YASnippet,不过得需要自己写个模板。

嗯,不过我挺喜欢org 内置的模版系统的,简单实用

根据网上找到的,改了一点点,选定region,然后 < 或 *

  (defhydra hydra-org-block-template (:color blue :hint nil)
    "
_c_enter  qu_o_te     _e_macs-lisp    _L_aTeX:
_l_atex   _E_xample   p_y_thon        _i_ndex:
_a_scii   _v_erse     ip_Y_thon       _I_NCLUDE:
_s_rc     _n_ote      _R_             _H_TML:
_h_tml    _S_HELL     _p_erl          _A_SCII:
^ ^       ^ ^         _P_erl tangled
"
    ("s" (hot-expand-block "<s"))
    ("E" (hot-expand-block "<e"))
    ("o" (hot-expand-block "<q"))
    ("v" (hot-expand-block "<v"))
    ("c" (hot-expand-block "<c"))
    ("l" (hot-expand-block "<l"))
    ("h" (hot-expand-block "<h"))
    ("a" (hot-expand-block "<a"))
    ("L" (hot-expand-block "<L"))
    ("i" (hot-expand-block "<i"))
    ("n" (hot-expand-block "<not"))
    ("e" (hot-expand-block "<s" "emacs-lisp"))
    ("y" (hot-expand-block "<s" "python :results output"))
    ("Y" (hot-expand-block "<s" "ipython :session :exports both :results raw drawer\n$0"))
    ;; ("g" (hot-expand-block "<s" "go :imports '\(\"fmt\"\)"))
    ("p" (hot-expand-block "<s" "perl"))
    ("R" (hot-expand-block "<s" "ess-r"))
    ("S" (hot-expand-block "<s" "sh"))
    ("u" (hot-expand-block "<s" "plantuml :file CHANGE.png"))
    ("P" (progn
           (insert "#+HEADERS: :results output :exports both :shebang \"#!/usr/bin/env perl\"\n")
           (hot-expand-block "<s" "perl")))
    ("I" (hot-expand-block "<I"))
    ("H" (hot-expand-block "<H"))
    ("A" (hot-expand-block "<A"))
    ("<" self-insert-command "ins")
    ("q" nil "quit"))

  (defun hot-expand-block (str &optional mod)
    "Expand org template."
    (let (text)
      (when (region-active-p)
        (setq text (buffer-substring (region-beginning) (region-end)))
        (delete-region (region-beginning) (region-end)))
      (insert str)
      (org-try-structure-completion)
      (when mod (insert mod) (forward-line))
      (when text (insert text))))

  (define-key org-mode-map "<"
    (lambda () (interactive)
      (if (or (region-active-p) (looking-back "^" nil))
          (hydra-org-block-template/body)
        (self-insert-command 1)))
    )

  (defhydra hydra-org-emphasize-template (:color blue :hint t)
    ("*" (hot-expand-emphasize ?*) "bold")
    ("/" (hot-expand-emphasize ?/) "italic")
    ("_" (hot-expand-emphasize ?_) "underline")
    ("=" (hot-expand-emphasize ?=) "verbatim")
    ("~" (hot-expand-emphasize ?~) "code")
    ("+" (hot-expand-emphasize ?+) "strike-through")
    ("q" nil "quit"))

  (defun hot-expand-emphasize (&optional CHAR)
    "Expand org template."
    (if (region-active-p)
      (org-emphasize CHAR)
      (self-insert-command 1)))

  (define-key org-mode-map "*"
    (lambda () (interactive)
      (if (region-active-p)
          (hydra-org-emphasize-template/body)
        (self-insert-command 1))))

cool!!