Last active
January 7, 2021 18:28
-
-
Save lgatto/8285041 to your computer and use it in GitHub Desktop.
Insert appropriate code chunk in emacs buffer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defun insert-md-code-chunk () | |
| "Insert Rmd code chunk" | |
| (interactive) | |
| (insert "```\n\n```") | |
| (backward-char 4)) | |
| (defun insert-rmd-code-chunk () | |
| "Insert Rmd code chunk" | |
| (interactive) | |
| (insert "```{r}\n\n```") | |
| (backward-char 4)) | |
| (defun insert-rnw-code-chunk () | |
| "Insert Rnw code chunk" | |
| (interactive) | |
| (insert "<<>>=\n\n@") | |
| (backward-char 2)) | |
| (defun insert-org-code-chunk () | |
| "Insert org code chunk" | |
| (interactive) | |
| (insert "#+BEGIN_SRC R :session *R*\n\n#+END_SRC") | |
| (backward-char 10)) | |
| (defun insert-code-chunk () | |
| "Insert appropriate code chunk based on buffer extension" | |
| (interactive) | |
| (pcase (file-name-extension (buffer-file-name)) | |
| (`"Rnw" (insert-rnw-code-chunk)) | |
| (`"org" (insert-org-code-chunk)) | |
| (`"Rmd" (insert-rmd-code-chunk)) | |
| (`"md" (insert-md-code-chunk)) | |
| (code (message "Unknown buffer extension")))) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(defun insert-el-code-chunk ()
"Insert emacs-lisp code chunk"
(interactive)
(insert "#+BEGIN_SRC emacs-lisp\n\n#+END_SRC")
(backward-char 10))