emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-context at the beginning of a link
@ 2014-11-21 16:31 Alan Schmitt
  2014-11-21 22:37 ` Nicolas Goaziou
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Schmitt @ 2014-11-21 16:31 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 398 bytes --]

Hello,

I'm using a function that relies on `org-element-link-parser'. According
to the documentation, the point needs to be at the element of the link
for it to work. I wrote a small function that takes me to the beginning
of a link, but it fails when the point is already at the beginning of
the link. Here is a reproducible recipe showing the problem.

Open this attached tiny org file: 

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: link.org --]
[-- Type: text/x-org, Size: 36 bytes --]

Start

[[file:link.org][link]]

End

[-- Attachment #1.3: Type: text/plain, Size: 385 bytes --]


Put the point on the 'i' of "link", for instance by (goto-char 26).

Look up the context: (org-context). I get ((:link 8 31))

Go to the beginning of the link: (goto-char 8)

Look up the context: (org-context). I get ((:link nil 31))

Is there a reason why the context is different at the beginning of the
link?

Thanks,

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 494 bytes --]

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

* Re: org-context at the beginning of a link
  2014-11-21 16:31 org-context at the beginning of a link Alan Schmitt
@ 2014-11-21 22:37 ` Nicolas Goaziou
  2014-11-22 15:23   ` Alan Schmitt
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Goaziou @ 2014-11-21 22:37 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: emacs-orgmode

Hello,

Alan Schmitt <alan.schmitt@polytechnique.org> writes:

> I'm using a function that relies on `org-element-link-parser'. According
> to the documentation, the point needs to be at the element of the link
> for it to work.

Not what you are asking for, but it is probably wrong to call this
function directly. If you want to parse something, it's better to use
`org-element-context' (or `org-element-at-point' but it doesn't fit
here).

> I wrote a small function that takes me to the beginning
> of a link, but it fails when the point is already at the beginning of
> the link. Here is a reproducible recipe showing the problem.
>
> Open this attached tiny org file: 
> Start
>
> [[file:link.org][link]]
>
> End
>
> Put the point on the 'i' of "link", for instance by (goto-char 26).
>
> Look up the context: (org-context). I get ((:link 8 31))
>
> Go to the beginning of the link: (goto-char 8)
>
> Look up the context: (org-context). I get ((:link nil 31))
>
> Is there a reason why the context is different at the beginning of the
> link?

I don't know, but `org-context' is very different from
`org-element-context'. You probably mean to use the latter.


Regards,

-- 
Nicolas Goaziou

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

* Re: org-context at the beginning of a link
  2014-11-21 22:37 ` Nicolas Goaziou
@ 2014-11-22 15:23   ` Alan Schmitt
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Schmitt @ 2014-11-22 15:23 UTC (permalink / raw)
  To: emacs-orgmode

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

On 2014-11-21 23:37, Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
> Alan Schmitt <alan.schmitt@polytechnique.org> writes:
>
>> I'm using a function that relies on `org-element-link-parser'. According
>> to the documentation, the point needs to be at the element of the link
>> for it to work.
>
> Not what you are asking for, but it is probably wrong to call this
> function directly. If you want to parse something, it's better to use
> `org-element-context' (or `org-element-at-point' but it doesn't fit
> here).

Thank you for the suggestion. The reason I was using `org-context' is
because it is used in `org-next-link'.

Here is what I ended up doing. It works great, but please don't hesitate
to criticize is.

#+begin_src emacs-lisp
(defun as/org-link-p (elt)
  (eq 'link (org-element-type elt)))

(defun as/fetch-element-link (elt)
  (org-element-property :raw-link elt))

(defun as/fetch-current-or-next-link ()
  (let ((elt (org-element-context)))
    (save-excursion
      (as/fetch-element-link
       (if (as/org-link-p elt)
           elt
         (progn (org-next-link) (org-element-context)))))))
#+end_src

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 494 bytes --]

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

end of thread, other threads:[~2014-11-22 15:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-21 16:31 org-context at the beginning of a link Alan Schmitt
2014-11-21 22:37 ` Nicolas Goaziou
2014-11-22 15:23   ` Alan Schmitt

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