emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Creating links to ITEMs in captured column views (code attached)
@ 2009-02-02 22:43 Taru Karttunen
  0 siblings, 0 replies; only message in thread
From: Taru Karttunen @ 2009-02-02 22:43 UTC (permalink / raw)
  To: Org-mode ml

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

Hello

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
  :PROPERTIES:
  :Foo:      bar
  :ID:       cd40863f-6980-406c-8501-29fdd3f170cb
  :END:

#+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")
#+END_SRC

* 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)
#+END:


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

_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-02-02 22:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-02 22:43 Creating links to ITEMs in captured column views (code attached) Taru Karttunen

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