emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* (org-element-context) :end property
@ 2015-10-02 21:37 Thomas S. Dye
  2015-10-02 21:50 ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas S. Dye @ 2015-10-02 21:37 UTC (permalink / raw)
  To: emacs-org list

Aloha all,

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?

All the best,
Tom
-- 
Thomas S. Dye
http://www.tsdye.com

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

* Re: (org-element-context) :end property
  2015-10-02 21:37 (org-element-context) :end property Thomas S. Dye
@ 2015-10-02 21:50 ` Nicolas Goaziou
  2015-10-02 22:26   ` Thomas S. Dye
  2015-10-03  4:09   ` Thomas S. Dye
  0 siblings, 2 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2015-10-02 21:50 UTC (permalink / raw)
  To: Thomas S. Dye; +Cc: emacs-org list

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

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

* Re: (org-element-context) :end property
  2015-10-02 21:50 ` Nicolas Goaziou
@ 2015-10-02 22:26   ` Thomas S. Dye
  2015-10-03  4:09   ` Thomas S. Dye
  1 sibling, 0 replies; 6+ messages in thread
From: Thomas S. Dye @ 2015-10-02 22:26 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-org list

Aloha Nicolas,

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

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

Perfect.  Thanks!

All the best,
Tom

-- 
Thomas S. Dye
http://www.tsdye.com

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

* Re: (org-element-context) :end property
  2015-10-02 21:50 ` Nicolas Goaziou
  2015-10-02 22:26   ` Thomas S. Dye
@ 2015-10-03  4:09   ` Thomas S. Dye
  2015-10-04 14:12     ` John Kitchin
  1 sibling, 1 reply; 6+ messages in thread
From: Thomas S. Dye @ 2015-10-03  4:09 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-org list

Aloha all,

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
>
> 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)))

To wrap this up, the revised unlinkify function (and a hydra with the
org-link-edit functions) are here:

https://github.com/abo-abo/hydra/wiki/Org-mode-links

All the best,
Tom
-- 
Thomas S. Dye
http://www.tsdye.com

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

* Re: (org-element-context) :end property
  2015-10-03  4:09   ` Thomas S. Dye
@ 2015-10-04 14:12     ` John Kitchin
  2015-10-04 14:48       ` Kyle Meyer
  0 siblings, 1 reply; 6+ messages in thread
From: John Kitchin @ 2015-10-04 14:12 UTC (permalink / raw)
  To: Thomas S. Dye; +Cc: emacs-org list, Nicolas Goaziou

Neat! Where does one find org-link-edit.el? Is it this one:
https://github.com/kyleam/org-link-edit?



Thomas S. Dye writes:

> Aloha all,
>
> Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>
>> Hello,
>>
>>
>> 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)))
>
> To wrap this up, the revised unlinkify function (and a hydra with the
> org-link-edit functions) are here:
>
> https://github.com/abo-abo/hydra/wiki/Org-mode-links
>
> All the best,
> Tom

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

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

* Re: (org-element-context) :end property
  2015-10-04 14:12     ` John Kitchin
@ 2015-10-04 14:48       ` Kyle Meyer
  0 siblings, 0 replies; 6+ messages in thread
From: Kyle Meyer @ 2015-10-04 14:48 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-org list

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> Neat! Where does one find org-link-edit.el? Is it this one:
> https://github.com/kyleam/org-link-edit?

It is that one, but it's also in contrib.

-- 
Kyle

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

end of thread, other threads:[~2015-10-04 14:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-02 21:37 (org-element-context) :end property Thomas S. Dye
2015-10-02 21:50 ` Nicolas Goaziou
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

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