From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: John Kitchin <jkitchin@andrew.cmu.edu>
Cc: "Somelauw ." <somelauw@gmail.com>,
"emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
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 [thread overview]
Message-ID: <87k1v6k2wt.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <CAJ51ETrUDO+0MhLa-0vBZMQ+Mgx+wX3fLHmr2ocKAmz+joC3rA@mail.gmail.com> (John Kitchin's message of "Tue, 20 Feb 2018 11:59:31 -0800")
Hello,
John Kitchin <jkitchin@andrew.cmu.edu> 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
next prev parent reply other threads:[~2018-02-21 11:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-19 23:29 Expose value-begin and value-end instead of just value in org-element API Somelauw .
2018-02-20 19:59 ` John Kitchin
2018-02-21 11:17 ` Nicolas Goaziou [this message]
2018-02-21 21:13 ` Somelauw .
2018-02-26 3:43 ` John Kitchin
2018-02-26 10:05 ` Nicolas Goaziou
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
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k1v6k2wt.fsf@nicolasgoaziou.fr \
--to=mail@nicolasgoaziou.fr \
--cc=emacs-orgmode@gnu.org \
--cc=jkitchin@andrew.cmu.edu \
--cc=somelauw@gmail.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 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).