From: John Kitchin <jkitchin@andrew.cmu.edu>
To: ST <smntov@gmail.com>
Cc: Eric S Fraga <esflists@gmail.com>,
org-mode-email <Emacs-orgmode@gnu.org>,
Christian Moe <mail@christianmoe.com>,
Nicolas Goaziou <mail@nicolasgoaziou.fr>
Subject: Re: Structured links to headings with endless depth
Date: Tue, 13 Mar 2018 20:49:46 -0700 [thread overview]
Message-ID: <CAJ51ETraHiyaaoFtC7gQnE-eUcu3zaYHt+wWgfgEymgDUu_vQQ@mail.gmail.com> (raw)
In-Reply-To: <1520867316.1793.87.camel@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2191 bytes --]
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
@johnkitchin
http://kitchingroup.cheme.cmu.edu
On Mon, Mar 12, 2018 at 8:08 AM, ST <smntov@gmail.com> 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 <smntov@gmail.com> 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,
> >
>
>
>
[-- Attachment #2: Type: text/html, Size: 4258 bytes --]
next prev parent reply other threads:[~2018-03-14 3:49 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-12 10:09 Structured links to headings with endless depth ST
2018-03-12 10:29 ` Eric S Fraga
2018-03-12 10:39 ` ST
2018-03-12 13:08 ` Christian Moe
2018-03-12 13:46 ` ST
2018-03-12 14:10 ` Nicolas Goaziou
2018-03-12 15:08 ` ST
2018-03-14 3:49 ` John Kitchin [this message]
2018-03-14 6:58 ` Michael Brand
2019-05-06 16:34 ` Michael Brand
2019-05-07 3:26 ` Ihor Radchenko
2019-05-07 14:39 ` Michael Brand
2019-05-18 10:44 ` Ihor Radchenko
2018-03-14 10:10 ` ST
2018-03-14 13:26 ` Nicolas Goaziou
2018-03-14 18:11 ` ST
2018-03-14 18:32 ` Nicolas Goaziou
2018-03-14 18:46 ` ST
2018-03-14 14:15 ` John Kitchin
2018-03-14 18:07 ` ST
2018-03-12 12:43 ` ST
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:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
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=CAJ51ETraHiyaaoFtC7gQnE-eUcu3zaYHt+wWgfgEymgDUu_vQQ@mail.gmail.com \
--to=jkitchin@andrew.cmu.edu \
--cc=Emacs-orgmode@gnu.org \
--cc=esflists@gmail.com \
--cc=mail@christianmoe.com \
--cc=mail@nicolasgoaziou.fr \
--cc=smntov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* 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
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).