[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Outline cycling does not preserve point's position
From: |
Nicolas Goaziou |
Subject: |
Re: [O] Outline cycling does not preserve point's position |
Date: |
Tue, 10 Sep 2013 18:33:16 +0200 |
Hello,
Suvayu Ali <address@hidden> writes:
> On Tue, Sep 10, 2013 at 11:02:35AM +0200, Carsten Dominik wrote:
>>
>> On 10.9.2013, at 10:50, Suvayu Ali <address@hidden> wrote:
>>
>> > On Tue, Sep 10, 2013 at 10:16:06AM +0200, Carsten Dominik wrote:
>> >>
>> >> The question is: What are people using C-arrow for?
>> >>
>> >> I think the main application is reasonably fast motion
>> >> and selection in a *linear* way. Is this correct, or do people
>> >> disagree here with me?
>> >
>> > I use it for navigating a buffer (not necessarily Org) linearly; i.e. go
>> > back and forth between parts I'm working on or to peruse the contents of
>> > a file. That said, often I feel the need for a navigation command which
>> > allows me to navigate the semantics of the buffer (which exactly what
>> > Nicolas's elements based navigation does).
>> >
>> >> The amazing element motion commands Nicolas has implement
>> >> correspond to sexp motion, as he has said himself.
>> >> Maybe C-M-f and C-M-b are the better binding match for these?
>> >
>> > I think you are right here. There is a need for both. For me, I use
>> > linear navigation more commonly; so I would prefer C-<up/down> for
>> > linear navigation and some other bindings (like C-M-f/b, as you suggest)
>> > for the elements based motion.
>>
>> And by linear, I think we don't mean strictly linear, but on a
>> paragraph/table/item scale, ignoring hierarchy.
>
> Yes. However I think I differ a bit on items. For me in a list like
> the following, I would call moving by paragraphs _within_ the list items
> linear; so, "Lorem..." → "Cras..." → "Integer..." → "Aenean..." →
> "Pellentesque...", and so on.
Here's a first draft for the linear forward motion. Disclaimer: I didn't
test it thoroughly.
(defun org-forward-linear-element ()
(interactive)
(when (eobp) (user-error "Cannot move further down"))
(let* ((origin (point))
(element (org-element-at-point))
(type (org-element-type element))
(contents-begin (org-element-property :contents-begin element))
(contents-end (org-element-property :contents-end element))
(end (let ((end (org-element-property :end element)) (parent
element))
(while (and (setq parent (org-element-property :parent
parent))
(= (org-element-property :contents-end parent)
end))
(setq end (org-element-property :end parent)))
end)))
(skip-chars-forward " \r\t\n")
(or (eobp) (goto-char (max (line-beginning-position) origin)))
(cond ((or (eobp) (= (point) end)))
((not contents-begin) (goto-char end))
((< (point) contents-begin)
(cond ((eq type 'item)
(end-of-line)
(org-forward-and-down-element))
((eq type 'table-row) (goto-char end))
(t (goto-char contents-begin))))
((>= (point) contents-end) (goto-char end))
((eq type 'paragraph) (goto-char end))
((eq type 'plain-list)
(end-of-line)
(org-forward-and-down-element))
((eq type 'table)
(forward-line)
(when (>= (point) contents-end) (goto-char end)))
((eq type 'verse-block)
(or (re-search-forward "^[ \t]*$" contents-end t)
(goto-char end)))
(t (error "This shouldn't happen")))
(when (org-invisible-p2) (goto-char end))))
WDYT?
Regards,
--
Nicolas Goaziou
- Re: [O] Outline cycling does not preserve point's position, (continued)
- Re: [O] Outline cycling does not preserve point's position, Carsten Dominik, 2013/09/09
- Re: [O] Outline cycling does not preserve point's position, Carsten Dominik, 2013/09/10
- Re: [O] Outline cycling does not preserve point's position, Eric Abrahamsen, 2013/09/10
- Re: [O] Outline cycling does not preserve point's position, Suvayu Ali, 2013/09/10
- Re: [O] Outline cycling does not preserve point's position, Suvayu Ali, 2013/09/10
- Re: [O] Outline cycling does not preserve point's position, Carsten Dominik, 2013/09/10
- Re: [O] Outline cycling does not preserve point's position, Carsten Dominik, 2013/09/10
- Re: [O] Outline cycling does not preserve point's position, Suvayu Ali, 2013/09/10
- Re: [O] Outline cycling does not preserve point's position, Carsten Dominik, 2013/09/10
- Re: [O] Outline cycling does not preserve point's position, Suvayu Ali, 2013/09/10
- Re: [O] Outline cycling does not preserve point's position,
Nicolas Goaziou <=
- Re: [O] Outline cycling does not preserve point's position, Suvayu Ali, 2013/09/10
- Re: [O] Outline cycling does not preserve point's position, Suvayu Ali, 2013/09/10
- Re: [O] Outline cycling does not preserve point's position, Nicolas Goaziou, 2013/09/10
- Re: [O] Outline cycling does not preserve point's position, Suvayu Ali, 2013/09/10
- Re: [O] Outline cycling does not preserve point's position, Nicolas Goaziou, 2013/09/10
- Re: [O] Outline cycling does not preserve point's position, Carsten Dominik, 2013/09/10
- Re: [O] Outline cycling does not preserve point's position, Suvayu Ali, 2013/09/11
- Re: [O] Outline cycling does not preserve point's position, Jambunathan K, 2013/09/12
- Re: [O] Outline cycling does not preserve point's position, Nicolas Goaziou, 2013/09/12
- Re: [O] Outline cycling does not preserve point's position, Jambunathan K, 2013/09/12