From mboxrd@z Thu Jan 1 00:00:00 1970 From: Xebar Saram Subject: Re: some lisp help (for complete 0-knowledge lisp emacs user :)) Date: Tue, 29 Jul 2014 15:48:24 +0300 Message-ID: References: <87d2cos6cz.fsf@gmail.com> <8761igs5e8.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7bd6c4e48f711904ff547432 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42351) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XC6pP-00079v-GM for emacs-orgmode@gnu.org; Tue, 29 Jul 2014 08:48:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XC6pN-0003wh-OY for emacs-orgmode@gnu.org; Tue, 29 Jul 2014 08:48:27 -0400 Received: from mail-oa0-x22b.google.com ([2607:f8b0:4003:c02::22b]:40948) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XC6pN-0003wZ-H0 for emacs-orgmode@gnu.org; Tue, 29 Jul 2014 08:48:25 -0400 Received: by mail-oa0-f43.google.com with SMTP id i7so10202963oag.30 for ; Tue, 29 Jul 2014 05:48:24 -0700 (PDT) In-Reply-To: <8761igs5e8.fsf@gmail.com> 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: Thorsten Jolitz , org mode --047d7bd6c4e48f711904ff547432 Content-Type: text/plain; charset=UTF-8 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 wrote: > Xebar Saram 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 > > wrote: > > > > > > Xebar Saram 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 > --047d7bd6c4e48f711904ff547432 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Thx and sorry about not posting to the list, was a gmail m= istake (i really *need* to start with gnus..just to intimidating :))
wrapping in parens by marking the region kinda defeats the pur= pose sine the original function i posted (in the original post) already wra= ps 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<= br> > 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:
>
>
> =C2=A0 =C2=A0 Xebar Saram <zel= takc@gmail.com> writes:
>
> =C2=A0 =C2=A0 > Hi list
> =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 > so i know i should start to really learn lisp but r= eal life (uni
> =C2=A0 =C2=A0 work,
> =C2=A0 =C2=A0 > family etc) doesn't really allow me so im marki= ng my 1st year
> =C2=A0 =C2=A0 > anniversary of using emacs without grasping lisp (p= lus i am in
> =C2=A0 =C2=A0 > generally coding inept :))
> =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 > in any case.... :) i have this handy lisp snippet t= hat i find
> =C2=A0 =C2=A0 very
> =C2=A0 =C2=A0 > useful and maybe some others in the list will find = as well. it
> =C2=A0 =C2=A0 allows
> =C2=A0 =C2=A0 > to quick convert lines of text into org src/example= blocks:
> =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 > (defun z-wrap-cblock-lisp ()
> =C2=A0 =C2=A0 > "Wrap region in quote block"
> =C2=A0 =C2=A0 > (interactive)
> =C2=A0 =C2=A0 > (save-excursion
> =C2=A0 =C2=A0 > (save-restriction
> =C2=A0 =C2=A0 > (and
> =C2=A0 =C2=A0 > (region-active-p)
> =C2=A0 =C2=A0 > (use-region-p)
> =C2=A0 =C2=A0 > (narrow-to-region (region-beginning) (region-end)))=
> =C2=A0 =C2=A0 > (goto-char (point-min))
> =C2=A0 =C2=A0 > (insert "#+BEGIN_SRC emacs-lisp :results none\= n")
> =C2=A0 =C2=A0 > (goto-char (point-max))
> =C2=A0 =C2=A0 > (insert "#+END_SRC\n")
> =C2=A0 =C2=A0 > (deactivate-mark))))
> =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 > this works well but has some annoying flaws like yo= u have to
> =C2=A0 =C2=A0 first
> =C2=A0 =C2=A0 > manually mark the region you want to convert etc > =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 > i was wondering:
> =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 > a)can some lisp coding master show me how to make t= his function
> =C2=A0 =C2=A0 auto
> =C2=A0 =C2=A0 > select the line//X user defined lines/smart paragra= ph selection
> =C2=A0 =C2=A0 before
> =C2=A0 =C2=A0 > it wraps it in the org block
> =C2=A0 =C2=A0 > b)any improvement ideas from the community?
>
>
> =C2=A0 =C2=A0 Try this:
>
> =C2=A0 =C2=A0 #+begin_src emacs-lisp
> =C2=A0 =C2=A0 (defun tj/wrap-sexp-in-elisp-src-block ()
> =C2=A0 =C2=A0 "Wrap sexp at point in elisp src block"
> =C2=A0 =C2=A0 (interactive)
> =C2=A0 =C2=A0 (let* ((marker (point-marker))
> =C2=A0 =C2=A0 (beg (point))
> =C2=A0 =C2=A0 (end (save-excursion
> =C2=A0 =C2=A0 (forward-sexp) (point)))
> =C2=A0 =C2=A0 (cut-strg (buffer-substring beg end)))
> =C2=A0 =C2=A0 (delete-region beg end)
> =C2=A0 =C2=A0 (goto-char (marker-position marker))
> =C2=A0 =C2=A0 (insert
> =C2=A0 =C2=A0 (format
> =C2=A0 =C2=A0 "\n#+begin_src emacs-lisp\n%s\n#+end_src\n" > =C2=A0 =C2=A0 cut-strg))
> =C2=A0 =C2=A0 (set-marker marker nil)))
> =C2=A0 =C2=A0 #+end_src
>
> =C2=A0 =C2=A0 #+results:
> =C2=A0 =C2=A0 : tj/wrap-sexp-in-elisp-src-block
>
> =C2=A0 =C2=A0 MWE:
>
> =C2=A0 =C2=A0 (defun foo ()
> =C2=A0 =C2=A0 "do foo"
> =C2=A0 =C2=A0 (message "foo"))
>
> =C2=A0 =C2=A0 1. with point at the opening paren:
>
>
> =C2=A0 =C2=A0 #+begin_src emacs-lisp
> =C2=A0 =C2=A0 (defun foo ()
> =C2=A0 =C2=A0 "do foo"
> =C2=A0 =C2=A0 (message "foo"))
> =C2=A0 =C2=A0 #+end_src
>
> =C2=A0 =C2=A0 2. with point at the 'd' of defun:
>
> =C2=A0 =C2=A0 (
> =C2=A0 =C2=A0 #+begin_src emacs-lisp
> =C2=A0 =C2=A0 defun
> =C2=A0 =C2=A0 #+end_src
> =C2=A0 =C2=A0 foo ()
> =C2=A0 =C2=A0 "do foo"
> =C2=A0 =C2=A0 (message "foo"))
>
> =C2=A0 =C2=A0 3. with point between 'do foo':
>
> =C2=A0 =C2=A0 (defun foo ()
> =C2=A0 =C2=A0 "do
> =C2=A0 =C2=A0 #+begin_src emacs-lisp
> =C2=A0 =C2=A0 foo
> =C2=A0 =C2=A0 #+end_src
> =C2=A0 =C2=A0 "
> =C2=A0 =C2=A0 (message "foo"))
>
>
> =C2=A0 =C2=A0 This is actually quite useful, will add it to my init fi= le (since
> =C2=A0 =C2=A0 I
> =C2=A0 =C2=A0 frequently get 'org-babel-demarcate-block: Args out = of range'
> =C2=A0 =C2=A0 errors
> =C2=A0 =C2=A0 when trying to wrap a region).
>
> =C2=A0 =C2=A0 Note that the behaviour depends a bit on the major-mode.= In
> =C2=A0 =C2=A0 emacs-lisp
> =C2=A0 =C2=A0 mode, a string is seen as one sexp, thus with point at t= he first
> =C2=A0 =C2=A0 double-quote of
>
> =C2=A0 =C2=A0 "hello world"
>
> =C2=A0 =C2=A0 I get
>
> =C2=A0 =C2=A0 #+begin_src emacs-lisp
> =C2=A0 =C2=A0 "hello world"
> =C2=A0 =C2=A0 #+end_src
>
> =C2=A0 =C2=A0 while in this message-mode buffer I get
>
> =C2=A0 =C2=A0 #+begin_src emacs-lisp
> =C2=A0 =C2=A0 "hello
> =C2=A0 =C2=A0 #+end_src
> =C2=A0 =C2=A0 world"
>
> =C2=A0 =C2=A0 --
> =C2=A0 =C2=A0 cheers,
> =C2=A0 =C2=A0 Thorsten
>
>
>
>

--
cheers,
Thorsten

--047d7bd6c4e48f711904ff547432--