From mboxrd@z Thu Jan 1 00:00:00 1970 From: Florian Adamsky Subject: [PATCH] org.el: Added a new interactive function which inserts a code block Date: Tue, 8 May 2012 21:19:09 +0200 Message-ID: <20120508211909.7e532ba3@asmara> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/kAg0o5mqcCzLP=ydMspSu4o" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:60947) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRqX2-0002vc-BB for emacs-orgmode@gnu.org; Tue, 08 May 2012 15:57:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SRqX0-0000wZ-Jn for emacs-orgmode@gnu.org; Tue, 08 May 2012 15:57:11 -0400 Received: from static.109.81.47.78.clients.your-server.de ([78.47.81.109]:44482 helo=haktar.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRqX0-0000wE-80 for emacs-orgmode@gnu.org; Tue, 08 May 2012 15:57:10 -0400 Received: from asmara (pD9E2DB11.dip.t-dialin.net [217.226.219.17]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: cit) by haktar.org (Postfix) with ESMTPSA id 73E083DE0E03 for ; Tue, 8 May 2012 21:19:10 +0200 (CEST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --MP_/kAg0o5mqcCzLP=ydMspSu4o Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 --MP_/kAg0o5mqcCzLP=ydMspSu4o Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=org.el.diff 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." --MP_/kAg0o5mqcCzLP=ydMspSu4o--