From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Expose value-begin and value-end instead of just value in org-element API Date: Wed, 21 Feb 2018 12:17:22 +0100 Message-ID: <87k1v6k2wt.fsf@nicolasgoaziou.fr> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:38085) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoSOt-0005NY-CF for emacs-orgmode@gnu.org; Wed, 21 Feb 2018 06:17:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eoSOs-0003tL-AY for emacs-orgmode@gnu.org; Wed, 21 Feb 2018 06:17:27 -0500 Received: from relay3-d.mail.gandi.net ([2001:4b98:c:538::195]:59669) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eoSOs-0003sg-3B for emacs-orgmode@gnu.org; Wed, 21 Feb 2018 06:17:26 -0500 In-Reply-To: (John Kitchin's message of "Tue, 20 Feb 2018 11:59:31 -0800") 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" To: John Kitchin Cc: "Somelauw ." , "emacs-orgmode@gnu.org" Hello, John Kitchin writes: > +1 on this. > > I also have some janky code to do things like go to the beginning/end of > the value in a src block. Here is my solution to mark the code in a src > block. > > (defun ob-ipython-mark-code () > "Mark the code in the block." > (interactive) > (org-edit-special) > (let ((p0 (point-min)) > (p1 (point-max))) > (goto-char p0) > (org-edit-src-exit) > (set-mark (point)) > (goto-char (+ (point) (- p1 2))))) You get the beginning of the code of a source block with (org-with-point-at (org-element-property :post-affiliated element) (line-beginning-position 2)) and its end with (org-with-point-at (org-element-property :end element) (line-beginning-position (- (org-element-property :post-blank element)))) >From there, you can easily construct something that doesn't rely on `org-edit-special'. >> I think it would be preferable to also expose the value by beginning and >> ending buffer positions for the following reasons: >> - Consistency with elements that expose contents-begin and contents-end. The point is terminal elements are not consistent with non-terminal ones, and should not be. >> - More powerful. In my evil-org plugin I want to be able to mark the value >> property of the org element at point (so the user can do stuff like easily >> copy the code of the current code block), but to do so I need the beginning >> and ending position in the buffer of "value". The org-element API does >> currently not provide clean way to retrieve these positions. See above. It is quite simple to extract this information from the parse tree. >> - It's usually more efficient to return the beginning and ending positions >> than to retrieve the substring that contains the value, which may require a >> large buffer partition to be copied. Efficiency is a moot point because you still need to store the value of the block. If you remove it, the parse tree is no longer an equivalent representation of the document. Regards, -- Nicolas Goaziou