From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ido Magal Subject: Re: Embedded code Date: Thu, 3 Feb 2011 22:52:27 -0800 Message-ID: References: <2324250583714673900@unknownmsgid> <87aaizhz23.fsf@gmail.com> <4D3554AC.1060303@gmail.com> <8762tmfa74.fsf@gmail.com> <871v4a2b15.fsf@gmail.com> <87oc79elrj.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0812947805==" Return-path: Received: from [140.186.70.92] (port=51796 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PlFXK-0006kz-W8 for emacs-orgmode@gnu.org; Fri, 04 Feb 2011 01:53:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PlFXF-0008M5-Ek for emacs-orgmode@gnu.org; Fri, 04 Feb 2011 01:52:54 -0500 Received: from mail-ww0-f49.google.com ([74.125.82.49]:38776) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PlFXF-0008M1-4E for emacs-orgmode@gnu.org; Fri, 04 Feb 2011 01:52:49 -0500 Received: by wwb17 with SMTP id 17so1994098wwb.30 for ; Thu, 03 Feb 2011 22:52:47 -0800 (PST) In-Reply-To: <87oc79elrj.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Eric Schulte Cc: emacs-orgmode@gnu.org, Rainer M Krug --===============0812947805== Content-Type: multipart/alternative; boundary=0016e6d9728478c514049b6f5482 --0016e6d9728478c514049b6f5482 Content-Type: text/plain; charset=UTF-8 On Fri, Jan 21, 2011 at 18:05, Eric Schulte wrote: > > > There are a variety of ways to convert lists to strings, look at the > `format' function for printing any elisp value to a string. You can > also use something like the following to convert a list to a string > > #+begin_src emacs-lisp > (mapconcat (lambda (el) (format "%S" el)) '(1 2 3 4 5 6) "\t") > #+end_src > > ... > > You can use the inline code syntax for very small blocks, e.g. > > I've proceeded with my little project using the dynamic block, since it seems that this is what it was designed for. I wrote the following bit of code and would appreciate answers to a couple of questions. #+begin_src emacs-lisp :results silent (defun flatten-string-with-links (str) (let* ((newstr str)) ; find [[link][desc]] and replace with 'desc. (setq newstr (replace-regexp-in-string "\\[\\[[^\\[]+\\]\\[[^//[]+\\]\\]" (lambda (s) (save-match-data (nth 2 (split-string s "[\]\[]+")))) newstr)) ; find [[link]] and replace with 'link. (setq newstr (replace-regexp-in-string "\\[\\[[^\\[]+\\]\\]" (lambda(s) (save-match-data (nth 1 (split-string s "[\]\[]+")))) newstr)) newstr)) (defun org-dblock-write:tagged (params) (insert (mapconcat 'identity (org-map-entries (lambda() (let* (link desc innerlink) (setq desc (nth 4 (org-heading-components))) (setq desc (flatten-string-with-links desc)) (setq link (concat "file:" (abbreviate-file-name (buffer-file-name (buffer-base-buffer))) "::" (org-make-org-heading-search-string))) (org-make-link-string link desc))) (plist-get params :tag) (plist-get params :scope)) "\n"))) #+end_src * example :links: ** not a link ** [[http://google.com][link]] ** some text.[[http://google.com][link]] ** [[http://google.com]] ** some text. [[http://google.com][link]]. more text. [[http://google.com][link]]. final text. ** [[ http://www.knifecenter.com/kc_new/store_detail.html?s%3DAOBSHARP][brokenlink]] #+BEGIN: tagged :tag "links" #+END Q1: I've tried to leverage as much built-in org functionality as possible, but deeply suspect that I'm overlooking some, since agendas do much of this work. Is there a simpler solution than mine? Q2: The link generated for the last item ("broken link") does not work. Removing the "%" from the URL fixes it. This seems to be a bug in org-make-org-heading-search-string? Or am I misusing it? Any help would be greatly appreciated. --0016e6d9728478c514049b6f5482 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On Fri, Jan 21, 2011 at= 18:05, Eric Schulte <schulte.eric@gmail.com> wrote:

There are a variety of ways to convert lists to strings, look at the<= br> `format' function for printing any elisp value to a string. =C2=A0You c= an
also use something like the following to convert a list to a string

#+begin_src emacs-lisp
=C2=A0(mapconcat (lambda (el) (format "%S" el)) '(1 2 3 4 5 = 6) "\t")
#+end_src

...=C2=A0

You can use the inline code syntax for very small blocks, e.g.


I've proceeded with my little proj= ect using the dynamic block, since it seems that this is what it was design= ed for. I wrote the following bit of code and would appreciate answers to a= couple of questions.

#+begin_src emacs-lisp :results silent
<= div>(defun flatten-string-with-links (str)
=C2=A0=C2=A0(let* ((ne= wstr str))
=C2=A0=C2=A0 =C2=A0; find [[link][desc]] and replace w= ith 'desc.
=C2=A0=C2=A0 =C2=A0(setq newstr (replace-regexp-in-string "\\[\\[[^\\[= ]+\\]\\[[^//[]+\\]\\]"
=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0(lambda (s) (save-match-data
=C2=A0=C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 (nth 2 (split-string s "[\]\[]+")))) newstr))
=C2=A0=C2=A0 =C2=A0; find [[link]] and replace with 'link.
=C2=A0=C2=A0 =C2=A0(setq newstr (replace-regexp-in-string "\\[\\[[^= \\[]+\\]\\]"
=C2=A0 =C2=A0(lambda(s) (save-match-data
= =C2=A0 =C2=A0 =C2=A0(nth 1 (split-string s "[\]\[]+")))) newstr))=
=C2=A0=C2=A0newstr))

(defun org-d= block-write:tagged (params)
=C2=A0=C2=A0(insert (mapconcat 'identity
=C2=A0 =C2=A0 (org-map-e= ntries
= =C2=A0 =C2=A0 =C2=A0(lambda()
(let= * (link desc innerlink)
=C2=A0(setq desc (nth 4 (org-heading-components))= )
=C2=A0(s= etq desc (flatten-string-with-links desc))
=C2=A0(setq link (concat "= ;file:"
= =C2=A0 =C2=A0 (abbreviate-file-name (buffer-file-name (buffer-base-buffer))= )
=C2=A0 =C2=A0 "::"
= =C2=A0 =C2=A0 (org-make-org-heading-search-string)))
=C2=A0(org-make-lin= k-string link desc)))
(pli= st-get params :tag)
(plist-get params :scope))
=C2=A0 =C2=A0 =C2=A0"= \n")))
=C2=A0#+end_src

= * example = =C2=A0=C2=A0 =C2=A0 =C2=A0:links:
** not a link
** [[http://google.com][link]]
** some text.[[http://google.com][li= nk]]

=
#+BEGIN: tagged :tag "links"
#+END


Q1: I've tried to leverage as muc= h built-in org functionality as possible, but deeply suspect that I'm o= verlooking some, since agendas do much of this work. =C2=A0Is there a simpl= er solution than mine?

Q2: The link generated for the last item ("broken = link") does not work. =C2=A0Removing the "%" from the URL fi= xes it. =C2=A0This seems to be a bug in=C2=A0org-make-org-heading-search-st= ring? =C2=A0Or am I misusing it?

Any help would be greatly= appreciated.
--0016e6d9728478c514049b6f5482-- --===============0812947805== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --===============0812947805==--