emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] Structured links to headings with endless depth


From: John Kitchin
Subject: Re: [O] Structured links to headings with endless depth
Date: Tue, 13 Mar 2018 20:49:46 -0700

This is a tricky problem to generally solve. I think this does it approximately well enough. It is lightly tested and works by exactly matching headlines at subsequent levels. It will be problematic if you have headlines with : in them, and it assumes there is a level 1 headline to start in.

#+BEGIN_SRC emacs-lisp
(defun xpath-follow (path)
  (let* ((fields (split-string path "::"))
(fname (car fields))
(paths (split-string (cadr fields) ":"))
(level 0)
(current-point (point))
cp hls n found) 
    (org-mark-ring-push)
    (find-file fname)
    (save-restriction
      (while paths
(setq cp (pop paths))
(incf level)
(setq hls (org-element-map (org-element-parse-buffer) 'headline
    (lambda (hl)
      (when (eq level (org-element-property :level hl))
hl))))
(setq n (-find-index (lambda (hl)
       (string= cp (org-no-properties
    (org-element-property :raw-value hl))))
     hls))
(if (not n)
    (progn
      (goto-char current-point)
      (user-error "%s not found" cp))
  (goto-char (org-element-property :begin (nth n hls)))
  (org-narrow-to-subtree))))))

(org-link-set-parameters
 "xpath"
 :follow 'xpath-follow)
#+END_SRC


John

-----------------------------------
Professor John Kitchin 
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803

On Mon, Mar 12, 2018 at 8:08 AM, ST <address@hidden> wrote:
Hello,

Ss Christian has pointed out - introduce a separate CUSTOM_ID for text
with fixed structure and rather short verses is too heavy.

I do need to write a custom link type, if this use case is not of common
interest for the orgmode community.

Thank you,


On Mon, 2018-03-12 at 15:10 +0100, Nicolas Goaziou wrote:
> Hello,
>
> ST <address@hidden> writes:
>
> > I'm not that experienced in writing in lisp. Is it difficult to create
> > such custom link type? What is the closest link type that you would
> > recommend to take as starting point (link on code, if possible)?
>
> I'm not answering your question, but I suggest to use a CUSTOM_ID
> instead. This is readily available.
>
> Regards,
>




reply via email to

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