emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] (org-element-context) :end property


From: Nicolas Goaziou
Subject: Re: [O] (org-element-context) :end property
Date: Fri, 02 Oct 2015 23:50:53 +0200

Hello,

Thomas S. Dye <address@hidden> writes:

> I've started to use John Kitchin's unlinkify function, which he posted
> to the list last year.
>
> (defun jk/unlinkify ()
>   "Replace an org-link with the description, or if this absent, the path."
>   (interactive)
>   (let ((eop (org-element-context)))
>     (when (eq 'link (car eop))
>       (message "%s" eop)
>       (let* ((start (org-element-property :begin eop))
>              (end (org-element-property :end eop))
>              (contents-begin (org-element-property :contents-begin eop))
>              (contents-end (org-element-property :contents-end eop))
>              (path (org-element-property :path eop))
>              (desc (and contents-begin
>                         contents-end
>                         (buffer-substring contents-begin contents-end))))
>         (setf (buffer-substring start end) (or desc path))))))
>
> However, I get different results depending on whether the link ends with
> a space or a character, e.g.
>
> Foo [[http:www.tsdye.com][desc]] bar.
> Foo [[http:www.tsdye.com][desc]], bar.
>
> Foo descbar.
> Foo desc, bar.
>
> How can I fix this?  I'm guessing that org-element-context sets :end
> differently depending on the character following the link?

White spaces following an object are included in the object. They are
stored in :post-blank property. You can add them with

  (setf (buffer-substring start end)
        (concat (or desc path) 
                (make-string (org-element-property :post-blank eop) ?\s)))


Regards,

-- 
Nicolas Goaziou



reply via email to

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