emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] Automatically build lists of links to related articles


From: Juan Reyero
Subject: [O] Automatically build lists of links to related articles
Date: Fri, 19 Aug 2011 11:52:14 +0200

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 via email to

[Prev in Thread] Current Thread [Next in Thread]