[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: |
Wed, 11 Sep 2013 17:40:12 +0200 |
Jambunathan K <address@hidden> writes:
> Nicolas Goaziou <address@hidden> writes:
>
>> I don't understand. Are you talking about the error message? There is no
>> "canonical" C-down position, so I'm a bit confused.
>
> Put your cursor on the blank line between. Do a C-down. You will see
> the cursor moving and also an error reported. So, the "empty line" is a
> position where a C-down operation would land you in. It is a position
> from nowhere.
I don't think it happens in latest version.
> I see some issues when the point is position some where deep inside
> invisible parts of the tree.
>
> For example, visit
>
> "~/src/worg/org-tutorials/org-reference-guide-es.org"
>
> Get in to a state where ALL headlines are visible but none of body text
> is visible.
>
> Position your cursor randomly, like so.
>
> M-: (goto-char (mod (random) (point-max)))
>
> Then C-down.
>
> Within let's say 10 attempts, you will see that a headline is skipped
> and the cursor lands on subsequent headline.
Fixed. This deserves a new version:
(defun org-forward-linear-element ()
"Move forward to next element, ignoring depth.
The function implements some special moves for convenience:
- On an affiliated keyword, jump to the beginning of the
relative element.
- On an item or a footnote definition, move to the second
element inside, if any.
- On a table, jump after it.
- On a verse block, stop after each blank line."
(interactive)
(when (eobp) (user-error "Cannot move further down"))
(let* ((element (org-element-at-point))
(type (org-element-type element))
(post-affiliated (org-element-property :post-affiliated 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)))
(cond ((not element)
(skip-chars-forward " \r\t\n")
(or (eobp) (beginning-of-line)))
;; On affiliated keywords, move to element's beginning.
((and post-affiliated (< (point) post-affiliated))
(goto-char post-affiliated))
;; At a table row, move to the end of the table.
((eq type 'table-row)
(goto-char (org-element-property
:end (org-element-property :parent element))))
((eq type 'table) (goto-char end))
((not contents-begin) (goto-char end))
;; If current element contents are invisible, skip the
;; element altogether.
((outline-invisible-p (line-end-position))
(case type
(headline
(org-with-limited-levels (outline-next-visible-heading 1)))
;; At a plain list, make sure we move to the next item
;; instead of skipping the whole list.
(plain-list (forward-char)
(org-forward-linear-element))
(otherwise (goto-char end))))
((>= (point) contents-end) (goto-char end))
((>= (point) contents-begin)
;; Handle special cases. In all other situations, point
;; is where it should be.
(case type
(paragraph (goto-char end))
;; At a plain list, try to move to second element in
;; first item, if possible.
(plain-list (end-of-line)
(org-forward-linear-element))
;; Consider blank lines as separators in verse blocks to
;; ease editing.
(verse-block
(beginning-of-line)
(if (not (re-search-forward "^[ \t]*$" contents-end t))
(goto-char end)
(skip-chars-forward " \r\t\n")
(if (= (point) contents-end) (goto-char contents)
(beginning-of-line))))))
;; When contents start on the middle of a line (e.g. in
;; items and footnote definitions), try to reach first
;; element starting after current line.
((> (line-end-position) contents-begin)
(end-of-line)
(org-forward-linear-element))
(t (goto-char contents-begin)))))
Regards,
--
Nicolas Goaziou
- Re: [O] Outline cycling does not preserve point's position, (continued)
- 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/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/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, Jambunathan K, 2013/09/12
- Re: [O] Outline cycling does not preserve point's position,
Nicolas Goaziou <=
- 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/11
- 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, Sebastien Vauban, 2013/09/12
- 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/14
- Re: [O] Outline cycling does not preserve point's position, Carsten Dominik, 2013/09/13
- Re: [O] Outline cycling does not preserve point's position, Nicolas Goaziou, 2013/09/13
- Re: [O] Outline cycling does not preserve point's position, Carsten Dominik, 2013/09/14