From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: (org-element-context) :end property Date: Fri, 02 Oct 2015 23:50:53 +0200 Message-ID: <878u7laqiq.fsf@nicolasgoaziou.fr> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi8CY-0001Cl-Ri for emacs-orgmode@gnu.org; Fri, 02 Oct 2015 17:49:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zi8CX-00035e-MM for emacs-orgmode@gnu.org; Fri, 02 Oct 2015 17:49:14 -0400 Received: from relay4-d.mail.gandi.net ([2001:4b98:c:538::196]:56251) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi8CX-00035U-G6 for emacs-orgmode@gnu.org; Fri, 02 Oct 2015 17:49:13 -0400 In-Reply-To: (Thomas S. Dye's message of "Fri, 02 Oct 2015 11:37:27 -1000") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: "Thomas S. Dye" Cc: emacs-org list Hello, Thomas S. Dye 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