* Automatically build lists of links to related articles
@ 2011-08-19 9:52 Juan Reyero
0 siblings, 0 replies; only message in thread
From: Juan Reyero @ 2011-08-19 9:52 UTC (permalink / raw)
To: emacs-orgmode
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-08-19 9:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-19 9:52 Automatically build lists of links to related articles Juan Reyero
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).