I've tried to setup a skeleton to speed up entering org source blocks
(define-skeleton skel-org-block
"Insert an org block, querying for type."
"Type: "
"#+begin_" str " " (setq v1 (skeleton-read "Language and headers?: ")) "\n"
_ - \n
"#+end_" str "\n")
(global-set-key (kbd "C-c b") 'skel-org-block)
This works fine in a fresh .org file. But problems occur when I try to add a new source block above an existing one:
- Doing
C-c b
above the block
#+begin_src python
blah
#+end_src
adds a comma before the first line of the old block:
#+begin_src python
#+end_src
,#+begin_src python
blah
#+end_src
- If I'm adding a new block via
C-c b
to the very end of an org file, I can leave the "Language and headers?: " prompt in the minibuffer blank, and I get a simple org block. If I repeat this above an existing org block, I get a message sayingorg-edit-src-code: No such language mode: nil-mode
.
Something's clearly going wrong with the line (setq v1 (skeleton-read "Language and headers?: "))
, but I'm not sure what.
Is there a fix? Is there a simpler skeleton to help me create an org block on the fly, with headers? (I could always remove the setq
line, but I'd like to be able to specify language and switches.)
– NickD Oct 31 '21 at 21:42` on Worg, but it wasn't working for me -- looking at the documentation, it turns out I needed `(require 'org-tempo)` in my init file. I wasn't aware of `C-c C-,`, which does what I want. The idea with the skeleton was that that I could order the construction of the block, so that I could get the language and headers out of the way before entering the functional code, and avoid having to move the cursor back and forth after creating the block. But your suggestions solve my use cases now. (If you add it as an answer I'll accept it).– nonreligious Nov 01 '21 at 08:15