[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Elisp function for wrapping sexp or region in src-block (was Re:
From: |
Thorsten Jolitz |
Subject: |
Re: [O] Elisp function for wrapping sexp or region in src-block (was Re: some lisp help) |
Date: |
Tue, 29 Jul 2014 15:52:21 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Thorsten Jolitz <address@hidden> writes:
> Xebar Saram <address@hidden> writes:
This is what I got in my init.el now (improved version with global
keybindings). And I like, will probably become one of those commands I
use all the time.
I already used it to wrap the following code in 3 src-blocks:
#+begin_src emacs-lisp
(defun tj/wrap-sexp-or-reg-in-src-block (&optional lang lines)
"Wrap sexp at point or region (point +-lines) in src block"
(interactive
(when current-prefix-arg
(list
(ido-completing-read "Org-Babel language: "
(mapcar
(lambda (--lang)
(symbol-name (car --lang)))
org-babel-load-languages)
nil nil nil nil "emacs-lisp")
(read-number "Number of lines to wrap: " 1))))
(let* ((language (or lang "emacs-lisp"))
(marker (point-marker))
(beg (point))
(bol (bolp))
(end (if lines
(save-excursion
(forward-line lines) (point))
(save-excursion
(forward-sexp) (point))))
(cut-strg (buffer-substring beg end)))
(delete-region beg end)
(goto-char (marker-position marker))
(insert
(format
"%s#+begin_src %s\n%s%s#+end_src\n"
(if bol "" "\n")
language
cut-strg
(if lines "" "\n")))
(set-marker marker nil)))
#+end_src
#+begin_src emacs-lisp
(global-set-key (kbd "C-c w l")
(lambda ()
(interactive)
(let ((current-prefix-arg '(4)))
(call-interactively
'tj/wrap-sexp-or-reg-in-src-block))))
#+end_src
#+begin_src emacs-lisp
(global-set-key (kbd "C-c w w")
'tj/wrap-sexp-or-reg-in-src-block)
#+end_src
--
cheers,
Thorsten
- [O] some lisp help (for complete 0-knowledge lisp emacs user :)), Xebar Saram, 2014/07/29
- Re: [O] some lisp help (for complete 0-knowledge lisp emacs user :)), Thorsten Jolitz, 2014/07/29
- Message not available
- Message not available
- Re: [O] some lisp help (for complete 0-knowledge lisp emacs user :)), Xebar Saram, 2014/07/29
- [O] Elisp function for wrapping sexp or region in src-block (was Re: some lisp help), Thorsten Jolitz, 2014/07/29
- Re: [O] Elisp function for wrapping sexp or region in src-block (was Re: some lisp help),
Thorsten Jolitz <=
- Re: [O] Elisp function for wrapping sexp or region in src-block (was Re: some lisp help), Xebar Saram, 2014/07/29
- Re: [O] Elisp function for wrapping sexp or region in src-block (was Re: some lisp help), Thorsten Jolitz, 2014/07/29
- Re: [O] Elisp function for wrapping sexp or region in src-block (was Re: some lisp help), Xebar Saram, 2014/07/29
- Re: [O] Elisp function for wrapping sexp or region in src-block (was Re: some lisp help), Xebar Saram, 2014/07/29
- Re: [O] Elisp function for wrapping sexp or region in src-block (was Re: some lisp help), Xebar Saram, 2014/07/29
- Re: [O] Elisp function for wrapping sexp or region in src-block (was Re: some lisp help), Thorsten Jolitz, 2014/07/29