emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] A Microsoftesque detail in org


From: Rasmus
Subject: Re: [O] A Microsoftesque detail in org
Date: Fri, 15 May 2015 13:27:51 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Hi Jarmo,

Jarmo Hurri <address@hidden> 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
>From 8a2477cb70770526939a6c665026802d46db21ea Mon Sep 17 00:00:00 2001
From: Rasmus <address@hidden>
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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]