|
From: | Xebar Saram |
Subject: | Re: [O] Elisp function for wrapping sexp or region in src-block (was Re: some lisp help) |
Date: | Tue, 29 Jul 2014 19:23:21 +0300 |
hi i fell like an idiot but what is RFC, is that a repo of some sorts, would you mind pasting a link?sorry about thatZ
On Tue, Jul 29, 2014 at 5:48 PM, Xebar Saram <address@hidden> wrote:Hi againlooks great but i think there may be a bug. if there is 1 line then issues the function works perfect (although no prompt, which for 1 line is ideal). but using C-u before the M-x dosent seem to do anything at all, it just wraps the current line. do i need any dependencies or doing something wrong?thx alot again, i hope other people will find it as useful as i do (i literally use it 20-30 times a day....)On Tue, Jul 29, 2014 at 4:52 PM, Thorsten Jolitz <address@hidden> wrote:
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:
"Wrap sexp at point or region (point +-lines) in src block"
#+begin_src emacs-lisp
(defun tj/wrap-sexp-or-reg-in-src-block (&optional lang lines)
(interactive(bol (bolp))
(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))
(end (if lines"%s#+begin_src %s\n%s%s#+end_src\n"
(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
(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
[Prev in Thread] | Current Thread | [Next in Thread] |