emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* File local circular links
@ 2015-09-03 13:42 Michael Brand
  2015-09-03 14:06 ` Nicolas Goaziou
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Brand @ 2015-09-03 13:42 UTC (permalink / raw)
  To: Org Mode

Hi all

I use a hack to work around a missing feature that I would like to
call "file local circular links". It works until
release_8.2.10-2341-g8094d01 but stops with
release_8.2.10-2342-gcfe5bc9

    commit cfe5bc97f8b18ccbf49d0764746c7563ce8d29da
    Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
    Date:   Mon Aug 3 01:06:32 2015 +0200

        Fix link search

and I would like to ask for some help to get it work again.

File local circular links does this: C-c C-o on line 1 of the file

-------------------------------------
[[:file local circular link:]]
some text
[[:file local circular link:]]
-------------------------------------

moves to line 3 and C-c C-o again moves back to line 1. (It does not
follow all links when there are more than two but this limitation is a
different story.)

The hack that I used so far is

#+BEGIN_SRC emacs-lisp
  (defun f-org-link-exec (str)
    (let* ((context (org-element-context))
           (link (let ((up (org-element-property :parent context)))
                   (if (eq (org-element-type up) 'link) up context)))
           (avoid-pos (org-element-property :begin link)))
      (cond
       ;; [[<<xy>>]]: Remove the angular brackets to let `org-link-search'
       ;; match `str' as an angular bracket link.
       ((string-match "^<<\\(.*\\)>>$" str)
        (let ((org-execute-file-search-functions nil))
          (org-link-search (match-string 1 str) 'dedicated avoid-pos)))
       ;; [[_:xy:]] (abbreviated with "#+LINK: _ file:bla.org:::") or
       ;; [[:xy:]]: Bind `org-link-search-must-match-exact-headline' to nil
       ;; temporarily.
       ((string-match-p "^:.*:$" str)
        (let ((org-execute-file-search-functions nil)
              (org-link-search-must-match-exact-headline nil))
          ;; The leading part may be "[[link_abbreviation" or just "[[".
          (org-link-search (concat "\\[\\[[^:]*" (regexp-quote str) "\\]\\]")
                           'fuzzy avoid-pos))))))
  (add-hook 'org-execute-file-search-functions 'f-org-link-exec)
#+END_SRC

The problematic part is the use of org-link-search which changed. In
the above example it is called as

#+BEGIN_SRC emacs-lisp
  (let ((org-execute-file-search-functions nil)
        (org-link-search-must-match-exact-headline nil))
    (org-link-search "\\[\\[[^:]*:file local circular link:\\]\\]"))
#+END_SRC

and after the commit org-link-search errors with "cond: No match for
fuzzy expression: \[\[[^:]*:file local circular link:\]\]". To me it
looks like if support for regular expressions for fuzzy links has been
dropped. I can not use the regexp search here because it invokes the
org-occur sparse tree.

How can I deal with this?

Michael

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: File local circular links
  2015-09-03 13:42 File local circular links Michael Brand
@ 2015-09-03 14:06 ` Nicolas Goaziou
  2015-09-04 16:36   ` Michael Brand
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Goaziou @ 2015-09-03 14:06 UTC (permalink / raw)
  To: Michael Brand; +Cc: Org Mode

Hello,

Michael Brand <michael.ch.brand@gmail.com> writes:

> I use a hack to work around a missing feature that I would like to
> call "file local circular links". It works until
> release_8.2.10-2341-g8094d01 but stops with
> release_8.2.10-2342-gcfe5bc9
>
>     commit cfe5bc97f8b18ccbf49d0764746c7563ce8d29da
>     Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
>     Date:   Mon Aug 3 01:06:32 2015 +0200
>
>         Fix link search
>
> and I would like to ask for some help to get it work again.
>
> File local circular links does this: C-c C-o on line 1 of the file
>
> -------------------------------------
> [[:file local circular link:]]
> some text
> [[:file local circular link:]]
> -------------------------------------
>
> moves to line 3 and C-c C-o again moves back to line 1. (It does not
> follow all links when there are more than two but this limitation is a
> different story.)
>
> The hack that I used so far is
>
> #+BEGIN_SRC emacs-lisp
>   (defun f-org-link-exec (str)
>     (let* ((context (org-element-context))
>            (link (let ((up (org-element-property :parent context)))
>                    (if (eq (org-element-type up) 'link) up context)))
>            (avoid-pos (org-element-property :begin link)))
>       (cond
>        ;; [[<<xy>>]]: Remove the angular brackets to let `org-link-search'
>        ;; match `str' as an angular bracket link.
>        ((string-match "^<<\\(.*\\)>>$" str)
>         (let ((org-execute-file-search-functions nil))
>           (org-link-search (match-string 1 str) 'dedicated avoid-pos)))
>        ;; [[_:xy:]] (abbreviated with "#+LINK: _ file:bla.org:::") or
>        ;; [[:xy:]]: Bind `org-link-search-must-match-exact-headline' to nil
>        ;; temporarily.
>        ((string-match-p "^:.*:$" str)
>         (let ((org-execute-file-search-functions nil)
>               (org-link-search-must-match-exact-headline nil))
>           ;; The leading part may be "[[link_abbreviation" or just "[[".
>           (org-link-search (concat "\\[\\[[^:]*" (regexp-quote str) "\\]\\]")
>                            'fuzzy avoid-pos))))))
>   (add-hook 'org-execute-file-search-functions 'f-org-link-exec)
> #+END_SRC
>
> The problematic part is the use of org-link-search which changed. In
> the above example it is called as
>
> #+BEGIN_SRC emacs-lisp
>   (let ((org-execute-file-search-functions nil)
>         (org-link-search-must-match-exact-headline nil))
>     (org-link-search "\\[\\[[^:]*:file local circular link:\\]\\]"))
> #+END_SRC
>
> and after the commit org-link-search errors with "cond: No match for
> fuzzy expression: \[\[[^:]*:file local circular link:\]\]". To me it
> looks like if support for regular expressions for fuzzy links has been
> dropped. I can not use the regexp search here because it invokes the
> org-occur sparse tree.

I don't know anything like regular expression support for fuzzy links.

> How can I deal with this?

Can't you simply do

  (org-link-search ":file local circular link:" (point))

?

You could also use target-links, or define a new type of link that would
trigger a search in the buffer, see `org-add-link-type'.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: File local circular links
  2015-09-03 14:06 ` Nicolas Goaziou
@ 2015-09-04 16:36   ` Michael Brand
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Brand @ 2015-09-04 16:36 UTC (permalink / raw)
  To: Org Mode

Hi Nicolas

On Thu, Sep 3, 2015 at 4:06 PM, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
> Can't you simply do
>
>   (org-link-search ":file local circular link:" (point))
>
> ?

In my previous example the

  (org-link-search "[[:file local circular link:]]" (point))

to get enough from the org-link-search argument AVOID-POS would work
to jump between the two links. But when the second link is in a
headline

-------------------------------------
[[:file local circular link:]]
some text
* [[:file local circular link:]]
-------------------------------------

the second link jumps only to itself with the new org-link-search. I
understand that this is desired behavior because the headline gets
priority over the target on line 1. Before your change the target on
line 1 was the match when following the link on line 3, which was a
bug that I wrongly relied on to jump backwards. My conclusion is that
org-link-search is the wrong function for my purpose and I will have
to implement something with re-search-forward on my own.

> You could also use target-links

My main requirement is that the link has to be also the target, not a
link and a target side by side. How could that be fulfilled with
target-links?

Michael

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-09-04 16:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-03 13:42 File local circular links Michael Brand
2015-09-03 14:06 ` Nicolas Goaziou
2015-09-04 16:36   ` Michael Brand

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