From mboxrd@z Thu Jan 1 00:00:00 1970 From: Juan Reyero Subject: Automatically build lists of links to related articles Date: Fri, 19 Aug 2011 11:52:14 +0200 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([140.186.70.92]:54844) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QuLkP-0003xz-VA for emacs-orgmode@gnu.org; Fri, 19 Aug 2011 05:52:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QuLkO-0001i0-Kc for emacs-orgmode@gnu.org; Fri, 19 Aug 2011 05:52:17 -0400 Received: from mail-fx0-f41.google.com ([209.85.161.41]:58691) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QuLkO-0001hg-ES for emacs-orgmode@gnu.org; Fri, 19 Aug 2011 05:52:16 -0400 Received: by fxg9 with SMTP id 9so2278922fxg.0 for ; Fri, 19 Aug 2011 02:52:15 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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). =A0The 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. =A0Any hints on a better way to do this, one that doesn't rely on undocumented variable names bound by the export function? =A0Here's my function: (defun related-entries () =A0(let* ((entries ()) =A0 =A0 =A0 =A0 (heading (nth 4 (org-heading-components))) =A0 =A0 =A0 =A0 (with-tags (org-get-tags-at (point) t)) =A0 =A0 =A0 =A0 (origin-props (org-entry-properties nil 'standard)) =A0 =A0 =A0 =A0 (match-lang (cdr (or (assoc "lang" origin-props) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(assoc "LANG" or= igin-props))))) =A0 =A0(org-map-entries =A0 =A0 (lambda () =A0 =A0 =A0 (let* ((tags (org-get-tags-at (point) t)) =A0 =A0 =A0 =A0 =A0 =A0 =A0(current-heading (nth 4 (org-heading-components)= )) =A0 =A0 =A0 =A0 =A0 =A0 =A0(props (org-entry-properties nil 'standard)) =A0 =A0 =A0 =A0 =A0 =A0 =A0(lang (cdr (or (assoc "lang" props) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (assoc "LANG" props= )))) =A0 =A0 =A0 =A0 =A0 =A0 =A0(blurb (cdr (or (assoc "blurb" props) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(assoc "BLURB" p= rops)))) =A0 =A0 =A0 =A0 =A0 =A0 =A0(fname (if (boundp 'ftname) ;; during export =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (file-relative-name (buffer= -file-name) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 (file-name-directory ftname)) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (buffer-file-name)))) =A0 =A0 =A0 =A0 (if (and (not (string=3D current-heading heading)) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(or (not match-lang) (and lang (equal la= ng match-lang))) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(intersection tags with-tags :test 'equa= l)) =A0 =A0 =A0 =A0 =A0 =A0 (let ((art-name (nth 4 (org-heading-components)))) =A0 =A0 =A0 =A0 =A0 =A0 =A0 (add-to-list 'entries =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(list (concat "[[fil= e:" fname "::" art-name =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0"][" art-name "]]" =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0(if blurb =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0(concat " --- " blurb) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0""))) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0t))))) =A0 =A0 nil =A0 =A0 (org-publish-get-base-files (if (boundp 'project) ;; during export =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pro= ject =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (org-pu= blish-get-project-from-filename =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(buf= fer-file-name))))) =A0 =A0entries)) Best regards, jm -- http://juanreyero.com/ http://alandair.com