emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rasmus <rasmus@gmx.us>
To: emacs-orgmode@gnu.org
Subject: Re: A Microsoftesque detail in org
Date: Fri, 15 May 2015 13:27:51 +0200	[thread overview]
Message-ID: <87lhgqxeq0.fsf@gmx.us> (raw)
In-Reply-To: 87382yji8z.fsf@iki.fi

[-- Attachment #1: Type: text/plain, Size: 1639 bytes --]

Hi Jarmo,

Jarmo Hurri <jarmo.hurri@iki.fi> writes:

> I was just amazed by the following detail in org. In the example below,
> if my cursor is anywhere inside the word "Example", and I press Enter, a
> new line will be inserted below, and the cursor will jump to the next
> line. The location of the cursor inside the heading line is ignored, and
> the heading line will not be broken.
>
> # --------------------------------------------------------------------
> * Example
>   Some text.
> # --------------------------------------------------------------------
>
> This immediately reminded me of Microsoft products, where the software
> tries to be too intelligent, thus making it harder for the user. In this
> case, I needed to figure out that Ctrl-o is needed to break the line.
>
> I would suggest that the original interpretation of Enter would not be
> messed with. Messing with Alt-Enter and such is fine, but Enter, please
> no.

I disagree.  Consider the more complete example:

* TODO [#A] foo bar        :tag:

With your behavior you can (i) break the TODO tag; (ii) break the cookie;
(iii) break the tag.  At least (i) and (ii) are quite destructive.  I, for
one, would hate to have to readjust my tags every time I break a headline.
Call me spoiled by MS if you like and if you think it's relevant.

Yet, not being able to break between foo and bar is quite annoying.

The attached patch re-enables breaks in region four of
org-complex-heading-regexp, i.e. from the cookie up to tags.  A quick test
suggests it works nicely.

WDYT?

—Rasmus

-- 
However beautiful the theory, you should occasionally look at the evidence

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-org.el-RET-works-in-headline-text.patch --]
[-- Type: text/x-diff, Size: 4637 bytes --]

From 8a2477cb70770526939a6c665026802d46db21ea Mon Sep 17 00:00:00 2001
From: Rasmus <rasmus@gmx.us>
Date: Fri, 15 May 2015 13:08:11 +0200
Subject: [PATCH 2/2] org.el: RET works in headline text

* org.el (org-return): RET works in headline text.
---
 lisp/org.el | 93 +++++++++++++++++++++++++++++++++++--------------------------
 1 file changed, 54 insertions(+), 39 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 4b44a94..8adec05 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -21185,45 +21185,60 @@ 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)))
-    (let* ((context (if org-return-follows-link (org-element-context)
-		      (org-element-at-point)))
-	   (type (org-element-type context)))
-      (cond
-       ;; In a table, call `org-table-next-row'.
-       ((or (and (eq type 'table)
-		 (>= (point) (org-element-property :contents-begin context))
-		 (< (point) (org-element-property :contents-end context)))
-	    (org-element-lineage context '(table-row table-cell) t))
-	(org-table-justify-field-maybe)
-	(call-interactively #'org-table-next-row))
-       ;; On a link or a timestamp but not on white spaces after it,
-       ;; call `org-open-line' if `org-return-follows-link' allows it.
-       ((and org-return-follows-link
-	     (memq type '(link timestamp))
-	     (< (point)
-		(save-excursion (goto-char (org-element-property :end context))
-				(skip-chars-backward " \t")
-				(point))))
-	(call-interactively #'org-open-at-point))
-       ;; In a list, make sure indenting keeps trailing text within.
-       ((and indent
-	     (not (eolp))
-	     (org-element-lineage context '(item)))
-	(let ((trailing-data
-	       (delete-and-extract-region (point) (line-end-position))))
-	  (newline-and-indent)
-	  (save-excursion (insert trailing-data))))
-       (t (if indent (newline-and-indent) (newline)))))))
+  (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)))
+      (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)
+			      (>= (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))))
+	  (when (match-beginning 5)
+	    (insert (make-string (length string) ?\ ))))
+	(end-of-line)
+	(if indent (newline-and-indent) (newline))
+	(save-excursion (insert (org-trim string)))))
+     ;; In a table, call `org-table-next-row'.
+     ((or (and (eq type 'table)
+	       (>= (point) (org-element-property :contents-begin context))
+	       (< (point) (org-element-property :contents-end context)))
+	  (org-element-lineage context '(table-row table-cell) t))
+      (org-table-justify-field-maybe)
+      (call-interactively #'org-table-next-row))
+     ;; On a link or a timestamp but not on white spaces after it,
+     ;; call `org-open-line' if `org-return-follows-link' allows it.
+     ((and org-return-follows-link
+	   (memq type '(link timestamp))
+	   (< (point)
+	      (save-excursion (goto-char (org-element-property :end context))
+			      (skip-chars-backward " \t")
+			      (point))))
+      (call-interactively #'org-open-at-point))
+     ;; In a list, make sure indenting keeps trailing text within.
+     ((and indent
+	   (not (eolp))
+	   (org-element-lineage context '(item)))
+      (let ((trailing-data
+	     (delete-and-extract-region (point) (line-end-position))))
+	(newline-and-indent)
+	(save-excursion (insert trailing-data))))
+     (t (if indent (newline-and-indent) (newline))))))
 
 (defun org-return-indent ()
   "Goto next table row or insert a newline and indent.
-- 
2.4.0


  parent reply	other threads:[~2015-05-15 11:28 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-15  9:35 A Microsoftesque detail in org Jarmo Hurri
2015-05-15  9:57 ` Rainer M Krug
2015-05-15 11:16 ` Doug Lewan
2015-05-15 11:27 ` Rasmus [this message]
2015-05-16  8:05   ` Nicolas Goaziou
2015-05-16 15:28     ` Rasmus
2015-05-16 17:26       ` Titus von der Malsburg
2015-05-16 19:00         ` Rasmus
2015-05-16 21:43           ` Titus von der Malsburg
2015-05-17 13:25         ` Rasmus
2015-05-17 20:24   ` Jarmo Hurri
2015-05-17 21:15     ` Rasmus
2015-05-18  0:39       ` Titus von der Malsburg
2015-05-18  3:40         ` Thomas S. Dye
2015-05-18 12:15         ` Jarmo Hurri
2015-05-18  8:33       ` Brett Witty
2015-05-18  9:02         ` Rainer M Krug
2015-05-18  9:48           ` Rasmus
2015-05-18 11:29             ` Rainer M Krug
2015-05-18 13:07         ` William Denton
2015-05-18 14:37         ` Suvayu Ali
2015-05-18 15:39           ` Rasmus
2015-05-19  9:39             ` Suvayu Ali
2015-05-20 23:04   ` Rasmus
2015-05-15 19:29 ` Titus von der Malsburg
2015-05-15 20:27   ` Thomas S. Dye
2015-05-16  3:43     ` Bob Newell

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=87lhgqxeq0.fsf@gmx.us \
    --to=rasmus@gmx.us \
    --cc=emacs-orgmode@gnu.org \
    /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).