* Re: [PATCH] org.el: Added a new interactive function which inserts a code block
2012-05-08 19:19 [PATCH] org.el: Added a new interactive function which inserts a code block Florian Adamsky
@ 2012-05-08 18:30 ` Eric Schulte
2012-05-08 20:41 ` Bastien
0 siblings, 1 reply; 5+ messages in thread
From: Eric Schulte @ 2012-05-08 18:30 UTC (permalink / raw)
To: Florian Adamsky; +Cc: emacs-orgmode
Hi Florian,
You function looks good (although two lines in the middle are not
indented correctly).
Have you tried typing "<s" and then pressing TAB. This is how I insert
code blocks, as well as <q for quote blocks, etc...
That said your function does more than the <s approach because it also
limits the languages to those which are supported. If others think this
is generally useful I'd be happy to add it to ob.el.
Thanks for sharing,
Florian Adamsky <fa-orgmode@haktar.org> writes:
> 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
>
--
Eric Schulte
http://cs.unm.edu/~eschulte/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] org.el: Added a new interactive function which inserts a code block
@ 2012-05-08 19:19 Florian Adamsky
2012-05-08 18:30 ` Eric Schulte
0 siblings, 1 reply; 5+ messages in thread
From: Florian Adamsky @ 2012-05-08 19:19 UTC (permalink / raw)
To: emacs-orgmode
[-- 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."
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] org.el: Added a new interactive function which inserts a code block
2012-05-08 18:30 ` Eric Schulte
@ 2012-05-08 20:41 ` Bastien
2012-05-08 22:19 ` Michael Hannon
2012-05-09 1:47 ` Eric S Fraga
0 siblings, 2 replies; 5+ messages in thread
From: Bastien @ 2012-05-08 20:41 UTC (permalink / raw)
To: Eric Schulte; +Cc: emacs-orgmode, Florian Adamsky
Hi Florian and Eric,
Eric Schulte <eric.schulte@gmx.com> writes:
> Have you tried typing "<s" and then pressing TAB. This is how I insert
> code blocks, as well as <q for quote blocks, etc...
>
> That said your function does more than the <s approach because it also
> limits the languages to those which are supported. If others think this
> is generally useful I'd be happy to add it to ob.el.
Don't we have this already?
<s TAB M-TAB
inserts
#+begin_src
and offers completion over ̀org-babel-load-languages' (see
`pcomplete/org-mode/block-option/src' in org-pcomplete.el)
This spares us new keybindings :)
--
Bastien
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] org.el: Added a new interactive function which inserts a code block
2012-05-08 20:41 ` Bastien
@ 2012-05-08 22:19 ` Michael Hannon
2012-05-09 1:47 ` Eric S Fraga
1 sibling, 0 replies; 5+ messages in thread
From: Michael Hannon @ 2012-05-08 22:19 UTC (permalink / raw)
To: Bastien, Eric Schulte; +Cc: emacs-orgmode@gnu.org
Bastien <bzg@gnu.org> wrote:
> Eric Schulte <eric.schulte@gmx.com> writes:
>
>> Have you tried typing "<s" and then pressing TAB. This is how
> I insert
>> code blocks, as well as <q for quote blocks, etc...
>>
>> That said your function does more than the <s approach because it also
>> limits the languages to those which are supported. If others think this
>> is generally useful I'd be happy to add it to ob.el.
>
> Don't we have this already?
>
> <s TAB M-TAB
>
> inserts
>
> #+begin_src
>
> and offers completion over ̀org-babel-load-languages' (see
> `pcomplete/org-mode/block-option/src' in org-pcomplete.el)
>
> This spares us new keybindings :)
That's very cool. I wasn't aware of that. I notice that on my system the completion list does not include "cpp", which is indeed accepted and processed correctly.
-- Mike
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] org.el: Added a new interactive function which inserts a code block
2012-05-08 20:41 ` Bastien
2012-05-08 22:19 ` Michael Hannon
@ 2012-05-09 1:47 ` Eric S Fraga
1 sibling, 0 replies; 5+ messages in thread
From: Eric S Fraga @ 2012-05-09 1:47 UTC (permalink / raw)
To: Bastien; +Cc: emacs-orgmode, Florian Adamsky, Eric Schulte
Bastien <bzg@gnu.org> writes:
> Hi Florian and Eric,
>
> Eric Schulte <eric.schulte@gmx.com> writes:
>
>> Have you tried typing "<s" and then pressing TAB. This is how I insert
>> code blocks, as well as <q for quote blocks, etc...
>>
>> That said your function does more than the <s approach because it also
>> limits the languages to those which are supported. If others think this
>> is generally useful I'd be happy to add it to ob.el.
>
> Don't we have this already?
>
> <s TAB M-TAB
>
> inserts
>
> #+begin_src
>
> and offers completion over ̀org-babel-load-languages' (see
> `pcomplete/org-mode/block-option/src' in org-pcomplete.el)
>
> This spares us new keybindings :)
Thanks for this! I didn't know that completion was possible at that
point. Mind you, the list of possible completions seems to be somewhat
limited. I wonder where the list comes from? (I know: I should look at
the code... ;-)
For the OP, I use yasnippet [1] to introduce src code blocks:
,----[ src ]
| #name : #+begin_src language options ...#+end_src
| # --
| #+name: $1
| #+begin_src $2 $3
| $0
| #+end_src
`----
Footnotes:
[1] https://github.com/capitaomorte/yasnippet
--
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.1.50.1
: using Org release_7.8.09-544-g505cc7
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-05-09 1:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-08 19:19 [PATCH] org.el: Added a new interactive function which inserts a code block Florian Adamsky
2012-05-08 18:30 ` Eric Schulte
2012-05-08 20:41 ` Bastien
2012-05-08 22:19 ` Michael Hannon
2012-05-09 1:47 ` Eric S Fraga
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).