From 8a2477cb70770526939a6c665026802d46db21ea Mon Sep 17 00:00:00 2001 From: Rasmus 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