From: Juan Reyero <joanmg@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Automatically build lists of links to related articles
Date: Fri, 19 Aug 2011 11:52:14 +0200 [thread overview]
Message-ID: <CAKSxNJi3AOLLtUvOmVe=vc1a5suYNO-qq2VpijcEyE9V47-uew@mail.gmail.com> (raw)
Greetings,
I write articles in their own page, with a main heading as the title.
I've written a function that builds a table with links to other
articles that share tags with the heading under which the table is
built (and that share the same language, assuming that the :lang:
property is set). The function I've come up with works, but it is
rather ugly. I want it to work during export time, and the only way
I've found to access the target's file name has been to rely on ftname
being bound.
I suspect I must be missing something rather obvious. Any hints on a
better way to do this, one that doesn't rely on undocumented variable
names bound by the export function? Here's my function:
(defun related-entries ()
(let* ((entries ())
(heading (nth 4 (org-heading-components)))
(with-tags (org-get-tags-at (point) t))
(origin-props (org-entry-properties nil 'standard))
(match-lang (cdr (or (assoc "lang" origin-props)
(assoc "LANG" origin-props)))))
(org-map-entries
(lambda ()
(let* ((tags (org-get-tags-at (point) t))
(current-heading (nth 4 (org-heading-components)))
(props (org-entry-properties nil 'standard))
(lang (cdr (or (assoc "lang" props)
(assoc "LANG" props))))
(blurb (cdr (or (assoc "blurb" props)
(assoc "BLURB" props))))
(fname (if (boundp 'ftname) ;; during export
(file-relative-name (buffer-file-name)
(file-name-directory ftname))
(buffer-file-name))))
(if (and (not (string= current-heading heading))
(or (not match-lang) (and lang (equal lang match-lang)))
(intersection tags with-tags :test 'equal))
(let ((art-name (nth 4 (org-heading-components))))
(add-to-list 'entries
(list (concat "[[file:" fname "::" art-name
"][" art-name "]]"
(if blurb
(concat " --- " blurb)
"")))
t)))))
nil
(org-publish-get-base-files (if (boundp 'project) ;; during export
project
(org-publish-get-project-from-filename
(buffer-file-name)))))
entries))
Best regards,
jm
--
http://juanreyero.com/
http://alandair.com
reply other threads:[~2011-08-19 9:52 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAKSxNJi3AOLLtUvOmVe=vc1a5suYNO-qq2VpijcEyE9V47-uew@mail.gmail.com' \
--to=joanmg@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).