* some lisp help (for complete 0-knowledge lisp emacs user :)) @ 2014-07-29 11:02 Xebar Saram 2014-07-29 12:21 ` Thorsten Jolitz 2014-08-04 14:45 ` some lisp help (for complete 0-knowledge lisp emacs user :)) Sebastien Vauban 0 siblings, 2 replies; 12+ messages in thread From: Xebar Saram @ 2014-07-29 11:02 UTC (permalink / raw) To: org mode [-- Attachment #1: Type: text/plain, Size: 1228 bytes --] Hi list so i know i should start to really learn lisp but real life (uni work, family etc) doesn't really allow me so im marking my 1st year anniversary of using emacs without grasping lisp (plus i am in generally coding inept :)) in any case.... :) i have this handy lisp snippet that i find very useful and maybe some others in the list will find as well. it allows to quick convert lines of text into org src/example blocks: (defun z-wrap-cblock-lisp () "Wrap region in quote block" (interactive) (save-excursion (save-restriction (and (region-active-p) (use-region-p) (narrow-to-region (region-beginning) (region-end))) (goto-char (point-min)) (insert "#+BEGIN_SRC emacs-lisp :results none\n") (goto-char (point-max)) (insert "#+END_SRC\n") (deactivate-mark)))) this works well but has some annoying flaws like you have to first manually mark the region you want to convert etc i was wondering: a)can some lisp coding master show me how to make this function auto select the line//X user defined lines/smart paragraph selection before it wraps it in the org block b)any improvement ideas from the community? thx alot in advance Z [-- Attachment #2: Type: text/html, Size: 2240 bytes --] ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: some lisp help (for complete 0-knowledge lisp emacs user :)) 2014-07-29 11:02 some lisp help (for complete 0-knowledge lisp emacs user :)) Xebar Saram @ 2014-07-29 12:21 ` Thorsten Jolitz [not found] ` <CAOQHXPoJT4gGTJfOrHAtOfuS53GmPFgSwBqr4OA0ECpE28K1wg@mail.gmail.com> 2014-08-04 14:45 ` some lisp help (for complete 0-knowledge lisp emacs user :)) Sebastien Vauban 1 sibling, 1 reply; 12+ messages in thread From: Thorsten Jolitz @ 2014-07-29 12:21 UTC (permalink / raw) To: emacs-orgmode Xebar Saram <zeltakc@gmail.com> writes: > Hi list > > so i know i should start to really learn lisp but real life (uni work, > family etc) doesn't really allow me so im marking my 1st year > anniversary of using emacs without grasping lisp (plus i am in > generally coding inept :)) > > in any case.... :) i have this handy lisp snippet that i find very > useful and maybe some others in the list will find as well. it allows > to quick convert lines of text into org src/example blocks: > > (defun z-wrap-cblock-lisp () > "Wrap region in quote block" > (interactive) > (save-excursion > (save-restriction > (and > (region-active-p) > (use-region-p) > (narrow-to-region (region-beginning) (region-end))) > (goto-char (point-min)) > (insert "#+BEGIN_SRC emacs-lisp :results none\n") > (goto-char (point-max)) > (insert "#+END_SRC\n") > (deactivate-mark)))) > > this works well but has some annoying flaws like you have to first > manually mark the region you want to convert etc > > i was wondering: > > a)can some lisp coding master show me how to make this function auto > select the line//X user defined lines/smart paragraph selection before > it wraps it in the org block > b)any improvement ideas from the community? Try this: #+begin_src emacs-lisp (defun tj/wrap-sexp-in-elisp-src-block () "Wrap sexp at point in elisp src block" (interactive) (let* ((marker (point-marker)) (beg (point)) (end (save-excursion (forward-sexp) (point))) (cut-strg (buffer-substring beg end))) (delete-region beg end) (goto-char (marker-position marker)) (insert (format "\n#+begin_src emacs-lisp\n%s\n#+end_src\n" cut-strg)) (set-marker marker nil))) #+end_src #+results: : tj/wrap-sexp-in-elisp-src-block MWE: (defun foo () "do foo" (message "foo")) 1. with point at the opening paren: #+begin_src emacs-lisp (defun foo () "do foo" (message "foo")) #+end_src 2. with point at the 'd' of defun: ( #+begin_src emacs-lisp defun #+end_src foo () "do foo" (message "foo")) 3. with point between 'do foo': (defun foo () "do #+begin_src emacs-lisp foo #+end_src " (message "foo")) This is actually quite useful, will add it to my init file (since I frequently get 'org-babel-demarcate-block: Args out of range' errors when trying to wrap a region). Note that the behaviour depends a bit on the major-mode. In emacs-lisp mode, a string is seen as one sexp, thus with point at the first double-quote of "hello world" I get #+begin_src emacs-lisp "hello world" #+end_src while in this message-mode buffer I get #+begin_src emacs-lisp "hello #+end_src world" -- cheers, Thorsten ^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <CAOQHXPoJT4gGTJfOrHAtOfuS53GmPFgSwBqr4OA0ECpE28K1wg@mail.gmail.com>]
[parent not found: <8761igs5e8.fsf@gmail.com>]
* Re: some lisp help (for complete 0-knowledge lisp emacs user :)) [not found] ` <8761igs5e8.fsf@gmail.com> @ 2014-07-29 12:48 ` Xebar Saram 2014-07-29 13:30 ` Elisp function for wrapping sexp or region in src-block (was Re: some lisp help) Thorsten Jolitz 0 siblings, 1 reply; 12+ messages in thread From: Xebar Saram @ 2014-07-29 12:48 UTC (permalink / raw) To: Thorsten Jolitz, org mode [-- Attachment #1: Type: text/plain, Size: 4894 bytes --] Thx and sorry about not posting to the list, was a gmail mistake (i really *need* to start with gnus..just to intimidating :)) wrapping in parens by marking the region kinda defeats the purpose sine the original function i posted (in the original post) already wraps the marked text in an orgmode block :) thanks and sorry for PM Z On Tue, Jul 29, 2014 at 3:42 PM, Thorsten Jolitz <tjolitz@gmail.com> wrote: > Xebar Saram <zeltakc@gmail.com> writes: > > why a PM??? > > > Thx Thorsten > > > > this works very well for code blocks. it seems though that for normal > > text paragraphs it dosent work that well. may i suggest an idea? can > > the function perhaps prompt the user (when you launch the function) > > for number of lines to wrap and then issue the wrap based on that? > > that could perhaps be the most accurate way to do that? or maybe > > perhaps have a separate function to just wrap current line? > > > > thx alot, appreciate as always your excellent help > > just wrap your paragraph in parens and call the command with point on > the beginning paren, and it will work - for any number of lines. > easy to do with package smartparens.el: > > mark region and type '(', region is wrapped automatically. > > > On Tue, Jul 29, 2014 at 3:21 PM, Thorsten Jolitz <tjolitz@gmail.com> > > wrote: > > > > > > Xebar Saram <zeltakc@gmail.com> writes: > > > > > Hi list > > > > > > so i know i should start to really learn lisp but real life (uni > > work, > > > family etc) doesn't really allow me so im marking my 1st year > > > anniversary of using emacs without grasping lisp (plus i am in > > > generally coding inept :)) > > > > > > in any case.... :) i have this handy lisp snippet that i find > > very > > > useful and maybe some others in the list will find as well. it > > allows > > > to quick convert lines of text into org src/example blocks: > > > > > > (defun z-wrap-cblock-lisp () > > > "Wrap region in quote block" > > > (interactive) > > > (save-excursion > > > (save-restriction > > > (and > > > (region-active-p) > > > (use-region-p) > > > (narrow-to-region (region-beginning) (region-end))) > > > (goto-char (point-min)) > > > (insert "#+BEGIN_SRC emacs-lisp :results none\n") > > > (goto-char (point-max)) > > > (insert "#+END_SRC\n") > > > (deactivate-mark)))) > > > > > > this works well but has some annoying flaws like you have to > > first > > > manually mark the region you want to convert etc > > > > > > i was wondering: > > > > > > a)can some lisp coding master show me how to make this function > > auto > > > select the line//X user defined lines/smart paragraph selection > > before > > > it wraps it in the org block > > > b)any improvement ideas from the community? > > > > > > Try this: > > > > #+begin_src emacs-lisp > > (defun tj/wrap-sexp-in-elisp-src-block () > > "Wrap sexp at point in elisp src block" > > (interactive) > > (let* ((marker (point-marker)) > > (beg (point)) > > (end (save-excursion > > (forward-sexp) (point))) > > (cut-strg (buffer-substring beg end))) > > (delete-region beg end) > > (goto-char (marker-position marker)) > > (insert > > (format > > "\n#+begin_src emacs-lisp\n%s\n#+end_src\n" > > cut-strg)) > > (set-marker marker nil))) > > #+end_src > > > > #+results: > > : tj/wrap-sexp-in-elisp-src-block > > > > MWE: > > > > (defun foo () > > "do foo" > > (message "foo")) > > > > 1. with point at the opening paren: > > > > > > #+begin_src emacs-lisp > > (defun foo () > > "do foo" > > (message "foo")) > > #+end_src > > > > 2. with point at the 'd' of defun: > > > > ( > > #+begin_src emacs-lisp > > defun > > #+end_src > > foo () > > "do foo" > > (message "foo")) > > > > 3. with point between 'do foo': > > > > (defun foo () > > "do > > #+begin_src emacs-lisp > > foo > > #+end_src > > " > > (message "foo")) > > > > > > This is actually quite useful, will add it to my init file (since > > I > > frequently get 'org-babel-demarcate-block: Args out of range' > > errors > > when trying to wrap a region). > > > > Note that the behaviour depends a bit on the major-mode. In > > emacs-lisp > > mode, a string is seen as one sexp, thus with point at the first > > double-quote of > > > > "hello world" > > > > I get > > > > #+begin_src emacs-lisp > > "hello world" > > #+end_src > > > > while in this message-mode buffer I get > > > > #+begin_src emacs-lisp > > "hello > > #+end_src > > world" > > > > -- > > cheers, > > Thorsten > > > > > > > > > > -- > cheers, > Thorsten > [-- Attachment #2: Type: text/html, Size: 7029 bytes --] ^ permalink raw reply [flat|nested] 12+ messages in thread
* Elisp function for wrapping sexp or region in src-block (was Re: some lisp help) 2014-07-29 12:48 ` Xebar Saram @ 2014-07-29 13:30 ` Thorsten Jolitz 2014-07-29 13:52 ` Thorsten Jolitz 0 siblings, 1 reply; 12+ messages in thread From: Thorsten Jolitz @ 2014-07-29 13:30 UTC (permalink / raw) To: emacs-orgmode Xebar Saram <zeltakc@gmail.com> writes: > Thx and sorry about not posting to the list, was a gmail mistake (i > really *need* to start with gnus..just to intimidating :)) > > wrapping in parens by marking the region kinda defeats the purpose > sine the original function i posted (in the original post) already > wraps the marked text in an orgmode block :) > > thanks and sorry for PM no problem since I really want this function too and was a bit frustrated often enough that it does not exist in Org-mode, I made it more flexible and generic now, for daily use: #+begin_src emacs-lisp (defun tj/wrap-sexp-or-reg-in-src-block (&optional lang lines) "Wrap sexp at point or region 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)) (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 "\n#+begin_src %s\n%s\n#+end_src\n" language cut-strg)) (set-marker marker nil))) #+end_src try it with ,---- | C-u M-x tj/wrap-sexp-or-reg-in-src-block `---- and you get what you want (negative line-number wrap backwards). > On Tue, Jul 29, 2014 at 3:42 PM, Thorsten Jolitz <tjolitz@gmail.com> > wrote: > > Xebar Saram <zeltakc@gmail.com> writes: > > why a PM??? > > > > Thx Thorsten > > > > this works very well for code blocks. it seems though that for > normal > > text paragraphs it dosent work that well. may i suggest an idea? > can > > the function perhaps prompt the user (when you launch the > function) > > for number of lines to wrap and then issue the wrap based on > that? > > that could perhaps be the most accurate way to do that? or maybe > > perhaps have a separate function to just wrap current line? > > > > thx alot, appreciate as always your excellent help > > > just wrap your paragraph in parens and call the command with point > on > the beginning paren, and it will work - for any number of lines. > easy to do with package smartparens.el: > > mark region and type '(', region is wrapped automatically. > > > > > On Tue, Jul 29, 2014 at 3:21 PM, Thorsten Jolitz > <tjolitz@gmail.com> > > wrote: > > > > > > Xebar Saram <zeltakc@gmail.com> writes: > > > > > Hi list > > > > > > so i know i should start to really learn lisp but real life > (uni > > work, > > > family etc) doesn't really allow me so im marking my 1st year > > > anniversary of using emacs without grasping lisp (plus i am in > > > generally coding inept :)) > > > > > > in any case.... :) i have this handy lisp snippet that i find > > very > > > useful and maybe some others in the list will find as well. it > > allows > > > to quick convert lines of text into org src/example blocks: > > > > > > (defun z-wrap-cblock-lisp () > > > "Wrap region in quote block" > > > (interactive) > > > (save-excursion > > > (save-restriction > > > (and > > > (region-active-p) > > > (use-region-p) > > > (narrow-to-region (region-beginning) (region-end))) > > > (goto-char (point-min)) > > > (insert "#+BEGIN_SRC emacs-lisp :results none\n") > > > (goto-char (point-max)) > > > (insert "#+END_SRC\n") > > > (deactivate-mark)))) > > > > > > this works well but has some annoying flaws like you have to > > first > > > manually mark the region you want to convert etc > > > > > > i was wondering: > > > > > > a)can some lisp coding master show me how to make this > function > > auto > > > select the line//X user defined lines/smart paragraph > selection > > before > > > it wraps it in the org block > > > b)any improvement ideas from the community? > > > > > > Try this: > > > > #+begin_src emacs-lisp > > (defun tj/wrap-sexp-in-elisp-src-block () > > "Wrap sexp at point in elisp src block" > > (interactive) > > (let* ((marker (point-marker)) > > (beg (point)) > > (end (save-excursion > > (forward-sexp) (point))) > > (cut-strg (buffer-substring beg end))) > > (delete-region beg end) > > (goto-char (marker-position marker)) > > (insert > > (format > > "\n#+begin_src emacs-lisp\n%s\n#+end_src\n" > > cut-strg)) > > (set-marker marker nil))) > > #+end_src > > > > #+results: > > : tj/wrap-sexp-in-elisp-src-block > > > > MWE: > > > > (defun foo () > > "do foo" > > (message "foo")) > > > > 1. with point at the opening paren: > > > > > > #+begin_src emacs-lisp > > (defun foo () > > "do foo" > > (message "foo")) > > #+end_src > > > > 2. with point at the 'd' of defun: > > > > ( > > #+begin_src emacs-lisp > > defun > > #+end_src > > foo () > > "do foo" > > (message "foo")) > > > > 3. with point between 'do foo': > > > > (defun foo () > > "do > > #+begin_src emacs-lisp > > foo > > #+end_src > > " > > (message "foo")) > > > > > > This is actually quite useful, will add it to my init file > (since > > I > > frequently get 'org-babel-demarcate-block: Args out of range' > > errors > > when trying to wrap a region). > > > > Note that the behaviour depends a bit on the major-mode. In > > emacs-lisp > > mode, a string is seen as one sexp, thus with point at the first > > double-quote of > > > > "hello world" > > > > I get > > > > #+begin_src emacs-lisp > > "hello world" > > #+end_src > > > > while in this message-mode buffer I get > > > > #+begin_src emacs-lisp > > "hello > > #+end_src > > world" > > > > -- > > cheers, > > Thorsten > > > > > > > > > > > -- > cheers, > Thorsten > > -- cheers, Thorsten ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Elisp function for wrapping sexp or region in src-block (was Re: some lisp help) 2014-07-29 13:30 ` Elisp function for wrapping sexp or region in src-block (was Re: some lisp help) Thorsten Jolitz @ 2014-07-29 13:52 ` Thorsten Jolitz 2014-07-29 14:48 ` Xebar Saram 0 siblings, 1 reply; 12+ messages in thread From: Thorsten Jolitz @ 2014-07-29 13:52 UTC (permalink / raw) To: emacs-orgmode Thorsten Jolitz <tjolitz@gmail.com> writes: > Xebar Saram <zeltakc@gmail.com> 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 ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Elisp function for wrapping sexp or region in src-block (was Re: some lisp help) 2014-07-29 13:52 ` Thorsten Jolitz @ 2014-07-29 14:48 ` Xebar Saram 2014-07-29 15:42 ` Thorsten Jolitz 2014-07-29 16:21 ` Xebar Saram 0 siblings, 2 replies; 12+ messages in thread From: Xebar Saram @ 2014-07-29 14:48 UTC (permalink / raw) To: Thorsten Jolitz; +Cc: org mode [-- Attachment #1: Type: text/plain, Size: 2511 bytes --] Hi again looks 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 <tjolitz@gmail.com> wrote: > Thorsten Jolitz <tjolitz@gmail.com> writes: > > > Xebar Saram <zeltakc@gmail.com> 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 > > > [-- Attachment #2: Type: text/html, Size: 3637 bytes --] ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Elisp function for wrapping sexp or region in src-block (was Re: some lisp help) 2014-07-29 14:48 ` Xebar Saram @ 2014-07-29 15:42 ` Thorsten Jolitz 2014-07-29 16:21 ` Xebar Saram 1 sibling, 0 replies; 12+ messages in thread From: Thorsten Jolitz @ 2014-07-29 15:42 UTC (permalink / raw) To: emacs-orgmode Xebar Saram <zeltakc@gmail.com> writes: Hi, > looks great but i think there may be a bug. can you try the new version in my RFC please and let me know if it works as expected. I invested a bit of time into this function because I actually need this quite often too, and I'm happy you pushed me to finally write it, thx for that. -- cheers, Thorsten ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Elisp function for wrapping sexp or region in src-block (was Re: some lisp help) 2014-07-29 14:48 ` Xebar Saram 2014-07-29 15:42 ` Thorsten Jolitz @ 2014-07-29 16:21 ` Xebar Saram 2014-07-29 16:23 ` Xebar Saram 1 sibling, 1 reply; 12+ messages in thread From: Xebar Saram @ 2014-07-29 16:21 UTC (permalink / raw) To: Thorsten Jolitz; +Cc: org mode [-- Attachment #1: Type: text/plain, Size: 2800 bytes --] 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 that Z On Tue, Jul 29, 2014 at 5:48 PM, Xebar Saram <zeltakc@gmail.com> wrote: > Hi again > > looks 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 <tjolitz@gmail.com> > wrote: > >> Thorsten Jolitz <tjolitz@gmail.com> writes: >> >> > Xebar Saram <zeltakc@gmail.com> 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 >> >> >> > [-- Attachment #2: Type: text/html, Size: 4224 bytes --] ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Elisp function for wrapping sexp or region in src-block (was Re: some lisp help) 2014-07-29 16:21 ` Xebar Saram @ 2014-07-29 16:23 ` Xebar Saram 2014-07-29 16:27 ` Xebar Saram 2014-07-29 16:36 ` Thorsten Jolitz 0 siblings, 2 replies; 12+ messages in thread From: Xebar Saram @ 2014-07-29 16:23 UTC (permalink / raw) To: Thorsten Jolitz; +Cc: org mode [-- Attachment #1: Type: text/plain, Size: 3050 bytes --] ok ignore above email, i just saw the previous email..damm gmail..grrr z On Tue, Jul 29, 2014 at 7:21 PM, Xebar Saram <zeltakc@gmail.com> wrote: > 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 that > > Z > > > On Tue, Jul 29, 2014 at 5:48 PM, Xebar Saram <zeltakc@gmail.com> wrote: > >> Hi again >> >> looks 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 <tjolitz@gmail.com> >> wrote: >> >>> Thorsten Jolitz <tjolitz@gmail.com> writes: >>> >>> > Xebar Saram <zeltakc@gmail.com> 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 >>> >>> >>> >> > [-- Attachment #2: Type: text/html, Size: 4722 bytes --] ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Elisp function for wrapping sexp or region in src-block (was Re: some lisp help) 2014-07-29 16:23 ` Xebar Saram @ 2014-07-29 16:27 ` Xebar Saram 2014-07-29 16:36 ` Thorsten Jolitz 1 sibling, 0 replies; 12+ messages in thread From: Xebar Saram @ 2014-07-29 16:27 UTC (permalink / raw) To: Thorsten Jolitz; +Cc: org mode [-- Attachment #1: Type: text/plain, Size: 3359 bytes --] Thorsten, thats amazing! thanks so much , really appreciate this i hope other people will also find it useful kind regards Z On Tue, Jul 29, 2014 at 7:23 PM, Xebar Saram <zeltakc@gmail.com> wrote: > ok ignore above email, i just saw the previous email..damm gmail..grrr > > z > > > On Tue, Jul 29, 2014 at 7:21 PM, Xebar Saram <zeltakc@gmail.com> wrote: > >> 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 that >> >> Z >> >> >> On Tue, Jul 29, 2014 at 5:48 PM, Xebar Saram <zeltakc@gmail.com> wrote: >> >>> Hi again >>> >>> looks 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 <tjolitz@gmail.com> >>> wrote: >>> >>>> Thorsten Jolitz <tjolitz@gmail.com> writes: >>>> >>>> > Xebar Saram <zeltakc@gmail.com> 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 >>>> >>>> >>>> >>> >> > [-- Attachment #2: Type: text/html, Size: 5355 bytes --] ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Elisp function for wrapping sexp or region in src-block (was Re: some lisp help) 2014-07-29 16:23 ` Xebar Saram 2014-07-29 16:27 ` Xebar Saram @ 2014-07-29 16:36 ` Thorsten Jolitz 1 sibling, 0 replies; 12+ messages in thread From: Thorsten Jolitz @ 2014-07-29 16:36 UTC (permalink / raw) To: emacs-orgmode Xebar Saram <zeltakc@gmail.com> writes: > ok ignore above email, i just saw the previous email..damm gmail..grrr RFC is just 'request for comments': ,---- | http://en.wikipedia.org/wiki/Request_for_Comments `---- PS I know that feeling, a (too) quick C-c C-c in gnus and that damned email is out ... ;) -- cheers, Thorsten ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: some lisp help (for complete 0-knowledge lisp emacs user :)) 2014-07-29 11:02 some lisp help (for complete 0-knowledge lisp emacs user :)) Xebar Saram 2014-07-29 12:21 ` Thorsten Jolitz @ 2014-08-04 14:45 ` Sebastien Vauban 1 sibling, 0 replies; 12+ messages in thread From: Sebastien Vauban @ 2014-08-04 14:45 UTC (permalink / raw) To: emacs-orgmode-mXXj517/zsQ Xebar Saram wrote: > Hi list > > so i know i should start to really learn lisp but real life (uni work, > family etc) doesn't really allow me so im marking my 1st year anniversary > of using emacs without grasping lisp (plus i am in generally coding inept > :)) > > in any case.... :) i have this handy lisp snippet that i find very useful > and maybe some others in the list will find as well. it allows to quick > convert lines of text into org src/example blocks: > > (defun z-wrap-cblock-lisp () > "Wrap region in quote block" > (interactive) > (save-excursion > (save-restriction > (and > (region-active-p) > (use-region-p) > (narrow-to-region (region-beginning) (region-end))) > (goto-char (point-min)) > (insert "#+BEGIN_SRC emacs-lisp :results none\n") > (goto-char (point-max)) > (insert "#+END_SRC\n") > (deactivate-mark)))) > > > this works well but has some annoying flaws like you have to first manually > mark the region you want to convert etc > > i was wondering: > > a)can some lisp coding master show me how to make this function auto select > the line//X user defined lines/smart paragraph selection before it wraps it > in the org block > b)any improvement ideas from the community? FYI, there's already C-c C-v C-d (`org-babel-demarcate-block')... Best regards, Seb -- Sebastien Vauban ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2014-08-04 14:45 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-07-29 11:02 some lisp help (for complete 0-knowledge lisp emacs user :)) Xebar Saram 2014-07-29 12:21 ` Thorsten Jolitz [not found] ` <CAOQHXPoJT4gGTJfOrHAtOfuS53GmPFgSwBqr4OA0ECpE28K1wg@mail.gmail.com> [not found] ` <8761igs5e8.fsf@gmail.com> 2014-07-29 12:48 ` Xebar Saram 2014-07-29 13:30 ` Elisp function for wrapping sexp or region in src-block (was Re: some lisp help) Thorsten Jolitz 2014-07-29 13:52 ` Thorsten Jolitz 2014-07-29 14:48 ` Xebar Saram 2014-07-29 15:42 ` Thorsten Jolitz 2014-07-29 16:21 ` Xebar Saram 2014-07-29 16:23 ` Xebar Saram 2014-07-29 16:27 ` Xebar Saram 2014-07-29 16:36 ` Thorsten Jolitz 2014-08-04 14:45 ` some lisp help (for complete 0-knowledge lisp emacs user :)) Sebastien Vauban
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).