Ido Magal <i...@idomagal.com> writes: > On Fri, Jan 21, 2011 at 18:05, Eric Schulte <schulte.e...@gmail.com> 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,
Yes, it is certainly worth-while to look for existing org-* functions, I am still often finding myself re-implementing existing functions. > since agendas do much of this work. Is there a simpler solution than > mine? So your goal is to write a bunch of links into the Org-mode file following the code block? A couple of suggestions... - don't call `insert' from your code block, rather output a string and let Babel handle the insert for you - it looks like you are doing a good job of using existing link functions, however in addition to searching for functions with org and link in their names with C-h f org-link TAB you can try looking for org variables (thinking existing org regular expressions) with something like C-h v org-link TAB > > 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? > I have no idea, I haven't used these functions. > > Any help would be greatly appreciated. Hope this helps. Best -- Eric _______________________________________________ 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