all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: "Thomas S. Dye" <tsd@tsdye.com>
Cc: emacs-org list <emacs-orgmode@gnu.org>
Subject: Re: (org-element-context) :end property
Date: Fri, 02 Oct 2015 23:50:53 +0200	[thread overview]
Message-ID: <878u7laqiq.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <m2lhblt0iw.fsf@tsdye.com> (Thomas S. Dye's message of "Fri, 02 Oct 2015 11:37:27 -1000")

Hello,

Thomas S. Dye <tsd@tsdye.com> 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	other threads:[~2015-10-02 21:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-02 21:37 (org-element-context) :end property Thomas S. Dye
2015-10-02 21:50 ` Nicolas Goaziou [this message]
2015-10-02 22:26   ` Thomas S. Dye
2015-10-03  4:09   ` Thomas S. Dye
2015-10-04 14:12     ` John Kitchin
2015-10-04 14:48       ` Kyle Meyer

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878u7laqiq.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=tsd@tsdye.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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.