From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: A Microsoftesque detail in org Date: Sat, 16 May 2015 17:28:39 +0200 Message-ID: <87mw14h788.fsf@gmx.us> References: <87382yji8z.fsf@iki.fi> <87lhgqxeq0.fsf@gmx.us> <87k2w99cc0.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:33802) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yte1A-0000D2-1V for emacs-orgmode@gnu.org; Sat, 16 May 2015 11:28:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yte16-0000xi-PF for emacs-orgmode@gnu.org; Sat, 16 May 2015 11:28:47 -0400 Received: from mout.gmx.net ([212.227.17.22]:63055) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yte16-0000xc-Fe for emacs-orgmode@gnu.org; Sat, 16 May 2015 11:28:44 -0400 Received: from W530 ([88.19.189.71]) by mail.gmx.com (mrgmx102) with ESMTPSA (Nemesis) id 0Lpgew-1ZMwxj2kKM-00fUzp for ; Sat, 16 May 2015 17:28:42 +0200 In-Reply-To: <87k2w99cc0.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Sat, 16 May 2015 10:05:35 +0200") 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: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, Thanks for the comments. Nicolas Goaziou writes: > "RET breaks headline text" may be more accurate. OK. >> + (let* ((context (if org-return-follows-link (org-element-context) >> + (org-element-at-point))) >> + (type (org-element-type context))) >> + (cond >> + ;; At a headline >> + ((and (eq type 'headline) (not (bolp))) > > You are removing an optimization here.=20 > > Checking if point is on a headline/inlinetask doesn't require to use > `org-element-at-point'/`org-element-context'. It is faster to simply > check for `org-outline-regexp' (or derived) at bol. > > This optimization is less important than it used to be, now that > properties drawers are at a fixed location. Nevertheless, it might be > worth keeping it in mind. I did it 'cause it's easier, I think, to read a single cond than first an if and then a cond. The latter also seems easier to fix in the future. >> + (org-show-entry) >> + (let ((string "")) >> + (unless (and (save-excursion >> + (beginning-of-line) >> + (looking-at org-complex-heading-regexp)) >> + (or (and (match-beginning 3) >> + (< (point) >> + (save-excursion >> + (goto-char (match-beginning 4)) >> + (skip-chars-backward " \t") >> + (point)))) >> + (and (match-beginning 5) >> + (>=3D (point) (match-beginning 5))))) >> + ;; Point is on headline keywords, tags or cookies. Do not break >> + ;; them: add a newline after the headline instead. >> + (setq string (delete-and-extract-region >> + (point) (or (match-beginning 5) >> + (line-end-position)))) > > The `setq' is not necessary here. Bind it within `let' instead. You are right. >> + (when (match-beginning 5) >> + (insert (make-string (length string) ?\ )))) > > ?\ -> ?\s >=20=20=20 > If you add this feature, please augment `test-org/return' from > "test-org.el" accordingly. Done and and attached. Anybody against pushing this? =E2=80=94Rasmus --=20 There are known knowns; there are things we know that we know --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-org.el-RET-breaks-headline-text.patch >From a7e6e6b9c96c13be9ebdc0a5c4c2f5033cefbfc7 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Fri, 15 May 2015 13:08:11 +0200 Subject: [PATCH 1/2] org.el: RET breaks headline text * org.el (org-return): RET breaks headline text. * test-org.el (test-org/return): Test org-return on headline text. * ORG-NEWS: Add entry on new org-return behavior. --- etc/ORG-NEWS | 4 ++++ lisp/org.el | 32 ++++++++++++++++++++++---------- testing/lisp/test-org.el | 28 ++++++++++++++++++++++++++-- 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 3803060..a3e1ae2 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -93,6 +93,10 @@ functions. The Org version of these functions skips over inline tasks *** ~org-element-context~ no longer return objects in keywords ~org-element-context~ used to return objects on some keywords, i.e., =TITLE=, =DATE= and =AUTHOR=. It now returns only the keyword. +*** Behavior of ~org-return~ changed +If point is before or after the true headline text, insert newline +without changing the text. If point is on headline text preserve +tags. ** Removed functions *** Removed function ~org-translate-time~ Use ~org-timestamp-translate~ instead. diff --git a/lisp/org.el b/lisp/org.el index 4b44a94..93183f9 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -21185,16 +21185,28 @@ will not happen if point is in a table or on a \"dead\" object (e.g., within a comment). In these case, you need to use `org-open-at-point' directly." (interactive) - (if (and (save-excursion - (beginning-of-line) - (looking-at org-todo-line-regexp)) - (match-beginning 3) - (>= (point) (match-beginning 3))) - ;; Point is on headline tags. Do not break them: add a newline - ;; after the headline instead. - (progn (org-show-entry) - (end-of-line) - (if indent (newline-and-indent) (newline))) + (if (and (not (bolp)) + (save-excursion (beginning-of-line) + (looking-at org-complex-heading-regexp))) + ;; At a headline. + (let ((string (if (or (< (point) + (save-excursion + (goto-char (match-beginning 4)) + (skip-chars-backward " \t") + (point))) + (and (match-beginning 5) + (>= (point) (match-beginning 5)))) + ;; Point is on headline keywords, tags or cookies. Do not break + ;; them: add a newline after the headline instead. + "" + (delete-and-extract-region (point) (or (match-beginning 5) + (line-end-position)))))) + (when (match-beginning 5) + (insert (make-string (length string) ?\s))) + (end-of-line) + (org-show-entry) + (if indent (newline-and-indent) (newline)) + (save-excursion (insert (org-trim string)))) (let* ((context (if org-return-follows-link (org-element-context) (org-element-at-point))) (type (org-element-type context))) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 7d09288..ecfece5 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -878,12 +878,36 @@ (org-test-with-temp-text "- A\n- B" (org-return t) (buffer-string)))) - ;; Special case: on tags part of a headline, add a newline below it - ;; instead of breaking it. + ;; On tags part of a headline, add a newline below it instead of + ;; breaking it. (should (equal "* H :tag:\n" (org-test-with-temp-text "* H :tag:" (org-return) + (buffer-string)))) + ;; Before headline text, add a newline below it instead of breaking + ;; it. + (should + (equal "* TODO H :tag:\n" + (org-test-with-temp-text "* TODO H :tag:" + (org-return) + (buffer-string)))) + (should + (equal "* TODO [#B] H :tag:\n" + (org-test-with-temp-text "* TODO [#B] H :tag:" + (org-return) + (buffer-string)))) + ;; At headline text, break headline text but preserve tags. + (should + (equal "* TODO [#B] foo :tag:\nbar" + (org-test-with-temp-text "* TODO [#B] foobar :tag:" + (org-return) + (buffer-string)))) + ;; At bol of headline insert newline. + (should + (equal "\n* h" + (org-test-with-temp-text "* h" + (org-return) (buffer-string))))) (ert-deftest test-org/meta-return () -- 2.4.0 --=-=-=--