emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Taru Karttunen <taruti@taruti.net>
To: Org-mode ml <emacs-orgmode@gnu.org>
Subject: Creating links to ITEMs in captured column views (code attached)
Date: Tue, 3 Feb 2009 00:43:40 +0200	[thread overview]
Message-ID: <20090202224340.GA6739@taruti.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 391 bytes --]


I was using a captured column view to display some properties
and wanted the ITEMs to be displayed as nice links to the
proper destinations.

The code has two purposes:
+ to number items according to their heading number in export (dirty)
+ to create links to the headings

Attached is an org-mode file that contains an example on how
it is used and the elisp code.

- Taru Karttunen

[-- Attachment #2: ex.org --]
[-- Type: text/plain, Size: 2153 bytes --]

#+TITLE: Captured column view item links
#+OPTIONS: toc:nil
#+COLUMNS:   %25ITEM(Item) %10Foo{+} %ID

* Captured column view item links

I was using a captured column view to display some properties
and wanted the items to be displayed as nice links.

Here is the result of a quick hacking session for the list archives.

*** ITEMs are numbered with heading numbers (dirty)
*** ITEMs are linked with a heading link or link to the id if it exists

* Elisp
  :Foo:      bar
  :ID:       cd40863f-6980-406c-8501-29fdd3f170cb

#+BEGIN_SRC emacs-lisp
(defvar taruti-org-hc '())

(defun taruti-org-hlist (string id)
  (labels ((taruti-inc-last (l) (let* ((rl (reverse l)))
				(setcar rl (+ 1 (car rl)))
				(reverse rl)))
	   (taruti-org-hc-f (m) 
			    (let* ((nl (if org-odd-levels-only (/ (+ 1 (length m)) 2) (length m)))
				   (ol (length taruti-org-hc)))
			      (setq taruti-org-hc
				    (if (> nl ol)
					(append taruti-org-hc '(1))
				      (taruti-inc-last (subseq taruti-org-hc 0 nl))))
			      (apply 'concat (mapcar (lambda (e) (format "%d." e)) taruti-org-hc)))))

    (when (string-match "\\(\\*+\\) \\(.+\\)" string)
      (let ((m1 (substring string (match-beginning 1) (match-end 1)))
	    (m2 (substring string (match-beginning 2) (match-end 2))))
	(if (zerop (length id))
	    (concat "[[*" m2 "][" (taruti-org-hc-f m1) " " m2 "]]")
	    (concat "[[id:" id "][" (taruti-org-hc-f m1) " " m2 "]]"))))))

(defun taruti-org-hlist-reset (x) (setq taruti-org-hc '()) x)

(taruti-org-hlist "** Foobar")

* Output

#+BEGIN: columnview :hlines 1 :id global
| Item                               | Foo |   |
| [[*Captured column view item links][1. Captured column view item links]] |     |   |
| [[id:cd40863f-6980-406c-8501-29fdd3f170cb][2. Elisp]]                           | bar |   |
| [[*Output][3. Output]]                          |     |   |
#+TBLFM: @1$1='(taruti-org-hlist-reset $1)::@1$3='(concat)::$1='(taruti-org-hlist $1 $3)::$3='(concat)

[-- Attachment #3: Type: text/plain, Size: 204 bytes --]

Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.

                 reply	other threads:[~2009-02-02 22:44 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:

  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=20090202224340.GA6739@taruti.net \
    --to=taruti@taruti.net \
    --cc=emacs-orgmode@gnu.org \


* 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


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).