From: Florian Adamsky <fa-orgmode@haktar.org>
To: emacs-orgmode@gnu.org
Subject: [PATCH] org.el: Added a new interactive function which inserts a code block
Date: Tue, 8 May 2012 21:19:09 +0200 [thread overview]
Message-ID: <20120508211909.7e532ba3@asmara> (raw)
[-- Attachment #1: Type: text/plain, Size: 656 bytes --]
Hello,
I do not always use code blocks in org-mode, but when I do, I have
forgotten the syntax :-). In order to prevent that situation I wrote a
little function which is similar to org-insert-link. I called that
function org-insert-code-block. This function reads the language per
minibuffer in and supports completion. It only allows languages which
are loaded via org-babel-load-languages.
Is this function also useful to others? I'm not a long-time Emacs lisp
hacker, so any comment is welcome. Has anyone an idea for a reasonable
keybinding for org-insert-code-block which is not already taken by
org-mode?
Thanks in advance.
Best regards,
Florian
[-- Attachment #2: org.el.diff --]
[-- Type: text/x-patch, Size: 822 bytes --]
diff --git a/lisp/org.el b/lisp/org.el
index 66f9c3e..19e91c0 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -9145,6 +9145,21 @@ a link description or nil."
"[[" (car link) "]]")))
;;;###autoload
+(defun org-insert-code-block ()
+ "Insert a code block. At the prompt, enter the language which is available.
+
+Completion can be used to insert any language which is loaded in
+org-babel-load-lanuages."
+ (interactive)
+ (setq language (completing-read
+ "Code block : "
+ (mapcar 'symbol-name
+ (mapcar 'car org-babel-load-languages))
+ nil nil))
+ (insert (concat "#+BEGIN_SRC " language "\n\n"))
+ (insert "#+END_SRC")
+ (previous-line))
+
(defun org-insert-link-global ()
"Insert a link like Org-mode does.
This command can be called in any mode to insert a link in Org-mode syntax."
next reply other threads:[~2012-05-08 19:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-08 19:19 Florian Adamsky [this message]
2012-05-08 18:30 ` [PATCH] org.el: Added a new interactive function which inserts a code block Eric Schulte
2012-05-08 20:41 ` Bastien
2012-05-08 22:19 ` Michael Hannon
2012-05-09 1:47 ` Eric S Fraga
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120508211909.7e532ba3@asmara \
--to=fa-orgmode@haktar.org \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).