On Wed, 2018-03-14 at 07:15 -0700, John Kitchin wrote:
> I don't think this should be in org-mode, it is still too fragile in
> many ways. 
> 
> 
> For example, what if you have a colon in your headlines, e.g. "A
> chapter about Romans 15:13".  That will will mess up the suggested
> approach that splits on ":".

My bad, I didn't mean to add this specific solution, but rather improve
it till it is no longer fragile. I appealed to those who are responsible
for adding new feature requests (as described on the website) to
consider this idea (and maybe find other more stable ways to implement
it). I'm not sure who they are...

> 
> What if you have duplicate headlines in a hierarchy, how would you
> specify the nth one?

Normally there shouldn't be identical headlines on the same level (on
different levels [[My_Book::2:2:2]] is perfectly fine). Should this
happen - take first occurrence.

> 
> What if you have some convention to start at level 2 headlines? what
> would you do then?
> 
> 
> What about include files?
> 
> 
> What if you skip a level for some reason? What should the path look
> like then?

Then your structure is not well-defined and you should not use such
links.

Thank you!

> 
> 
> 
> On Wed, Mar 14, 2018 at 3:10 AM, ST <smn...@gmail.com> wrote:
>         John, thank you for this solution!
>         
>         I posted this question also here:
>         
>         https://emacs.stackexchange.com/q/39384/18760
>         
>         So if you wish, you may add your solution also there.
>         
>         Somebody there, posted also a possible solution however the
>         syntax is
>         pretty heavy:
>         
>         [[org-heading:/path/to/file.org::*1:2:1]]
>         
>         There is a workaround using links abbreviations, but still it
>         is a
>         workaround...
>         
>         I think this kind of linking is useful for many general cases.
>         Christian
>         has expressed concerns that such links are easily breakable
>         which is
>         true but only for documents that are in draft phase (or those
>         which are
>         supposed to be restructured on regular basis - like ToDo
>         lists). However
>         documents that has been published, like books or scientific
>         papers, and
>         will no longer change - will benefit greatly from such linking
>         option.
>         Imagine you have a scientific paper in your archive that you
>         have
>         already published and removed write access from it in order
>         not to
>         change it accidentally. You do want to reference certain
>         chapter:section:subsection from it in your new paper, which
>         you are
>         currently writing, but creating a target
>         <<chapter:section:subsection>>
>         in the old paper is no longer an option...
>         
>         So may I ask as a feature request, to please add, following
>         link type as
>         standard to the org-mode:
>         
>         [[path/to/file.org::chapter:section:subsection:etc:optional
>         target]]
>         
>         - chapter/section/subsection could be also just numbers
>         - optional target target might be <<optional target target>>
>         - there is no need to add '*' (like
>         [[path/to/file.org::*chapter:section]] to the link, as ':'
>         after '::'
>         imply that headings are referred.
>         
>         Thank you!
>         
>         On Tue, 2018-03-13 at 20:49 -0700, John Kitchin wrote:
>         > 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 <smn...@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 <smn...@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,
>         >         >
>         >
>         >
>         >
>         >
>         >
>         
>         
> 
> 


Reply via email to