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.
This commit is contained in:
parent
6ba251d473
commit
af6fdf3071
|
@ -93,6 +93,9 @@ functions. The Org version of these functions skips over inline tasks
|
||||||
*** ~org-element-context~ no longer return objects in keywords
|
*** ~org-element-context~ no longer return objects in keywords
|
||||||
~org-element-context~ used to return objects on some keywords, i.e.,
|
~org-element-context~ used to return objects on some keywords, i.e.,
|
||||||
=TITLE=, =DATE= and =AUTHOR=. It now returns only the keyword.
|
=TITLE=, =DATE= and =AUTHOR=. It now returns only the keyword.
|
||||||
|
*** Behavior of ~org-return~ changed
|
||||||
|
If point is before or after the headline title, insert newline without
|
||||||
|
changing the headline.
|
||||||
** Removed functions
|
** Removed functions
|
||||||
*** Removed function ~org-translate-time~
|
*** Removed function ~org-translate-time~
|
||||||
Use ~org-timestamp-translate~ instead.
|
Use ~org-timestamp-translate~ instead.
|
||||||
|
|
38
lisp/org.el
38
lisp/org.el
|
@ -21185,16 +21185,36 @@ 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
|
object (e.g., within a comment). In these case, you need to use
|
||||||
`org-open-at-point' directly."
|
`org-open-at-point' directly."
|
||||||
(interactive)
|
(interactive)
|
||||||
(if (and (save-excursion
|
(if (and (not (bolp))
|
||||||
(beginning-of-line)
|
(save-excursion (beginning-of-line)
|
||||||
(looking-at org-todo-line-regexp))
|
(looking-at org-complex-heading-regexp)))
|
||||||
(match-beginning 3)
|
;; At headline.
|
||||||
(>= (point) (match-beginning 3)))
|
(let ((tags-column (when (match-beginning 5)
|
||||||
;; Point is on headline tags. Do not break them: add a newline
|
(save-excursion (goto-char (match-beginning 5))
|
||||||
;; after the headline instead.
|
(current-column))))
|
||||||
(progn (org-show-entry)
|
;; Test if before or after headline title.
|
||||||
|
(string (when (not (or (< (point)
|
||||||
|
(or (match-end 3)
|
||||||
|
(match-end 2)
|
||||||
|
(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.
|
||||||
|
(org-string-nw-p
|
||||||
|
(delete-and-extract-region (point) (match-end 4))))))
|
||||||
|
;; Adjust alignment of tags.
|
||||||
|
(when (and tags-column string)
|
||||||
|
(org-align-tags-here (if org-auto-align-tags
|
||||||
|
org-tags-column
|
||||||
|
tags-column)))
|
||||||
(end-of-line)
|
(end-of-line)
|
||||||
(if indent (newline-and-indent) (newline)))
|
(org-show-entry)
|
||||||
|
(if indent (newline-and-indent) (newline))
|
||||||
|
(and string (save-excursion (insert (org-trim string)))))
|
||||||
(let* ((context (if org-return-follows-link (org-element-context)
|
(let* ((context (if org-return-follows-link (org-element-context)
|
||||||
(org-element-at-point)))
|
(org-element-at-point)))
|
||||||
(type (org-element-type context)))
|
(type (org-element-type context)))
|
||||||
|
|
|
@ -834,7 +834,7 @@
|
||||||
;;; Editing
|
;;; Editing
|
||||||
|
|
||||||
(ert-deftest test-org/return ()
|
(ert-deftest test-org/return ()
|
||||||
"Test RET (`org-return') specifications."
|
"Test `org-return' specifications."
|
||||||
;; Regular test.
|
;; Regular test.
|
||||||
(should
|
(should
|
||||||
(equal "Para\ngraph"
|
(equal "Para\ngraph"
|
||||||
|
@ -878,11 +878,36 @@
|
||||||
(org-test-with-temp-text "- A\n<point>- B"
|
(org-test-with-temp-text "- A\n<point>- B"
|
||||||
(org-return t)
|
(org-return t)
|
||||||
(buffer-string))))
|
(buffer-string))))
|
||||||
;; Special case: on tags part of a headline, add a newline below it
|
;; On tags part of a headline, add a newline below it instead of
|
||||||
;; instead of breaking it.
|
;; breaking it.
|
||||||
(should
|
(should
|
||||||
(equal "* H :tag:\n"
|
(equal "* H :tag:\n"
|
||||||
(org-test-with-temp-text "* H :<point>tag:"
|
(org-test-with-temp-text "* H :<point>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 "* <point>TODO H :tag:"
|
||||||
|
(org-return)
|
||||||
|
(buffer-string))))
|
||||||
|
(should
|
||||||
|
(equal "* TODO [#B] H :tag:\n"
|
||||||
|
(org-test-with-temp-text "* TODO<point> [#B] H :tag:"
|
||||||
|
(org-return)
|
||||||
|
(buffer-string))))
|
||||||
|
;; At headline text, break headline text but preserve tags.
|
||||||
|
(should
|
||||||
|
(equal "* TODO [#B] foo :tag:\nbar"
|
||||||
|
(let (org-auto-align-tags)
|
||||||
|
(org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
|
||||||
|
(org-return)
|
||||||
|
(buffer-string)))))
|
||||||
|
;; At bol of headline insert newline.
|
||||||
|
(should
|
||||||
|
(equal "\n* h"
|
||||||
|
(org-test-with-temp-text "<point>* h"
|
||||||
(org-return)
|
(org-return)
|
||||||
(buffer-string)))))
|
(buffer-string)))))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue