From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: Outline cycling does not preserve point's position Date: Fri, 13 Sep 2013 12:57:21 +0200 Message-ID: <56775B3D-85D2-4B73-A7C8-DC7AB4348C12@gmail.com> References: <7CB7B681-DD2E-446C-AE45-DDCA204EE95C@gmail.com> <5855E8E1-9730-4A29-89FF-E35C64E54EDD@gmail.com> <20130910073257.GO20690@kuru.dyndns-at-home.com> <20130910075345.GP20690@kuru.dyndns-at-home.com> <25A21DB7-B2E5-47BB-8A64-594A15CB24B8@gmail.com> <20130910085057.GQ20690@kuru.dyndns-at-home.com> <4ED2509E-8A2E-4ED2-BFCF-CB7B27F1D2B4@gmail.com> <20130910095043.GR20690@kuru.dyndns-at-home.com> <87a9jk8wmr.fsf@gmail.com> <20130910185843.GA20690@kuru.dyndns-at-home.com> <871u4w8nkq.fsf@gmail.com> <8761u8m5sd.fsf@gmail.com> <87ioy78vib.fsf@gmail.com> <878uz3e5nu.fsf@gmail.com> <87txhr74f7.fsf@gmail.com> <87zjrjcp4e.fsf@gmail.com> <87fvtb6sbo.fsf@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 6.5 \(1508\)) Content-Type: multipart/signed; boundary="Apple-Mail=_AA949C38-6F91-4872-9BCB-F523DD484C64"; protocol="application/pgp-signature"; micalg=pgp-sha1 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VKR49-0002Kq-By for emacs-orgmode@gnu.org; Fri, 13 Sep 2013 06:57:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VKR40-0003go-Qu for emacs-orgmode@gnu.org; Fri, 13 Sep 2013 06:57:33 -0400 Received: from mail-ea0-x230.google.com ([2a00:1450:4013:c01::230]:52786) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VKR40-0003en-FZ for emacs-orgmode@gnu.org; Fri, 13 Sep 2013 06:57:24 -0400 Received: by mail-ea0-f176.google.com with SMTP id q16so490870ead.7 for ; Fri, 13 Sep 2013 03:57:23 -0700 (PDT) In-Reply-To: <87fvtb6sbo.fsf@gmail.com> 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: Nicolas Goaziou Cc: "emacs-orgmode@gnu.org Mode" --Apple-Mail=_AA949C38-6F91-4872-9BCB-F523DD484C64 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hi Nicolas, thanks for these. Please see the two comments below. On Sep 11, 2013, at 10:01 PM, Nicolas Goaziou = wrote: > Jambunathan K writes: >=20 >> I am happy with whatever is the latest version. You may want to = commit >> it. >=20 > I copy here[fn:1] the current version, for the record, along with its = backward > counterpart. Some points are still to be discussed: >=20 > 1. What to do on node properties? I think they should be covered with a single C-down, so treated like a = single paragraph. > 2. What to do on source blocks? At the beginning of the block (at the src line) I think it should jump = over the full src block. Inside the block, it can use text-modes forward paragraph. At lease these would be my suggestions. Thank you for all your work around this issue! When the functions are done, please go ahead and commit them and bind = them to C-up/down. Regards - Carsten >=20 >=20 > [fn:1] Here is the code: >=20 > (defun org-forward-linear-element () > "Move forward to beginning of 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)) > (=3D (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)))) > ((>=3D (point) contents-end) (goto-char end)) > ((>=3D (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 (=3D (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))))) >=20 > (defun org-backward-linear-element () > "Move backward to start of previous element, ignoring depth." > (interactive) > (when (bobp) (user-error "Cannot move further up")) > (let* ((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)) > (post-affiliated (org-element-property :post-affiliated = element)) > (begin (org-element-property :begin element))) > (cond ((not element) (goto-char (point-min))) > ((=3D (point) begin) > (backward-char) > (org-backward-linear-element)) > ((and post-affiliated (<=3D (point) post-affiliated)) = (goto-char begin)) > ((eq type 'table-row) > (goto-char (org-element-property > :contents-begin (org-element-property :parent = element)))) > ((eq type 'table) (goto-char begin)) > ((not contents-begin) > (goto-char (or post-affiliated begin))) > ((eq type 'paragraph) > (goto-char contents-begin) > ;; When at first paragraph in an item or a footnote > ;; definition, move directly to beginning of line. > (let ((parent-contents > (org-element-property > :contents-begin (org-element-property :parent = element)))) > (when (and parent-contents (=3D parent-contents = contents-begin)) > (beginning-of-line)))) > ((eq type 'verse-block) > (if (=3D (point) contents-begin) > (goto-char (or post-affiliated begin)) > ;; Inside a verse block, see blank lines as paragraph > ;; separators. > (let ((origin (point))) > (skip-chars-backward " \r\t\n" contents-begin) > (when (re-search-backward "^[ \t]*$" contents-begin = 'move) > (skip-chars-forward " \r\t\n" origin) > (if (=3D (point) origin) (goto-char contents-begin) > (beginning-of-line)))))) > ;; At the end of a greater element, move to the beginning of > ;; the last element within. > ((>=3D (point) contents-end) > (goto-char (1- contents-end)) > (org-backward-linear-element)) > (t (goto-char (or post-affiliated begin)))) > ;; Ensure we never leave point invisible. > (when (outline-invisible-p (point)) (beginning-of-visual-line)))) >=20 >=20 > Regards, >=20 > --=20 > Nicolas Goaziou --Apple-Mail=_AA949C38-6F91-4872-9BCB-F523DD484C64 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- iQEcBAEBAgAGBQJSMu+RAAoJEO+gg/nAZuwMTSkIAMmrRYc1JyI892vtWE43Upx9 /nZ8aVJzHTQ/qPzBegh6bG9DxvlfpQzAyZBCMjSMHkkldouvpb3BcglzzLYHphvB 8XyjIKnjwq9f73y0adEBYwiJVIKGL0w3g5X345XLx/OkNfVA/pXDL3el5xkBpXxO yXRYNxZ/OO12biM+k2zinFL4n6Ksx44DoSqjedMecApTu1vWxg3JMg8u6xUtnhoW QopFkK1yEg0ZoZl8oYnrmimYdLEIYRYXj2R93ooP4ucykLaneAtt5jFHVbwhywsH nl53LGZaHTuFWvUVGpLm6rLw1mj+tocHKtgdVtzunrZhhyzTwfMao13V0yptNck= =HvYu -----END PGP SIGNATURE----- --Apple-Mail=_AA949C38-6F91-4872-9BCB-F523DD484C64--