>From 112b91cdc2887b1cc4451549dd4dd0c2e6a370ac Mon Sep 17 00:00:00 2001 From: Rasmus Date: Fri, 15 May 2015 13:08:11 +0200 Subject: [PATCH 1/3] 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 | 222 +++++++---------------------------------------- testing/lisp/test-org.el | 31 ++++++- 3 files changed, 61 insertions(+), 196 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..a46cb86 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -19845,189 +19845,6 @@ boundaries." (org-defkey org-mode-map "\C-c|" 'org-table-create-or-convert-from-region) (org-defkey org-mode-map [(control ?#)] 'org-table-rotate-recalc-marks) (org-defkey org-mode-map "\C-c~" 'org-table-create-with-table.el) -(org-defkey org-mode-map "\C-c\C-a" 'org-attach) -(org-defkey org-mode-map "\C-c}" 'org-table-toggle-coordinate-overlays) -(org-defkey org-mode-map "\C-c{" 'org-table-toggle-formula-debugger) -(org-defkey org-mode-map "\C-c\C-e" 'org-export-dispatch) -(org-defkey org-mode-map "\C-c:" 'org-toggle-fixed-width) -(org-defkey org-mode-map "\C-c\C-x\C-f" 'org-emphasize) -(org-defkey org-mode-map "\C-c\C-xf" 'org-footnote-action) -(org-defkey org-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull) -(org-defkey org-mode-map "\C-c\C-x\C-mp" 'org-mobile-push) -(org-defkey org-mode-map "\C-c@" 'org-mark-subtree) -(org-defkey org-mode-map "\M-h" 'org-mark-element) -(org-defkey org-mode-map [?\C-c (control ?*)] 'org-list-make-subtree) -;;(org-defkey org-mode-map [?\C-c (control ?-)] 'org-list-make-list-from-subtree) - -(org-defkey org-mode-map "\C-c\C-x\C-w" 'org-cut-special) -(org-defkey org-mode-map "\C-c\C-x\M-w" 'org-copy-special) -(org-defkey org-mode-map "\C-c\C-x\C-y" 'org-paste-special) - -(org-defkey org-mode-map "\C-c\C-x\C-t" 'org-toggle-time-stamp-overlays) -(org-defkey org-mode-map "\C-c\C-x\C-i" 'org-clock-in) -(org-defkey org-mode-map "\C-c\C-x\C-x" 'org-clock-in-last) -(org-defkey org-mode-map "\C-c\C-x\C-z" 'org-resolve-clocks) -(org-defkey org-mode-map "\C-c\C-x\C-o" 'org-clock-out) -(org-defkey org-mode-map "\C-c\C-x\C-j" 'org-clock-goto) -(org-defkey org-mode-map "\C-c\C-x\C-q" 'org-clock-cancel) -(org-defkey org-mode-map "\C-c\C-x\C-d" 'org-clock-display) -(org-defkey org-mode-map "\C-c\C-x\C-r" 'org-clock-report) -(org-defkey org-mode-map "\C-c\C-x\C-u" 'org-dblock-update) -(org-defkey org-mode-map "\C-c\C-x\C-l" 'org-toggle-latex-fragment) -(org-defkey org-mode-map "\C-c\C-x\C-v" 'org-toggle-inline-images) -(org-defkey org-mode-map "\C-c\C-x\C-\M-v" 'org-redisplay-inline-images) -(org-defkey org-mode-map "\C-c\C-x\\" 'org-toggle-pretty-entities) -(org-defkey org-mode-map "\C-c\C-x\C-b" 'org-toggle-checkbox) -(org-defkey org-mode-map "\C-c\C-xp" 'org-set-property) -(org-defkey org-mode-map "\C-c\C-xP" 'org-set-property-and-value) -(org-defkey org-mode-map "\C-c\C-xe" 'org-set-effort) -(org-defkey org-mode-map "\C-c\C-xE" 'org-inc-effort) -(org-defkey org-mode-map "\C-c\C-xo" 'org-toggle-ordered-property) -(org-defkey org-mode-map "\C-c\C-xi" 'org-insert-columns-dblock) -(org-defkey org-mode-map [(control ?c) (control ?x) ?\;] 'org-timer-set-timer) - -(org-defkey org-mode-map "\C-c\C-x." 'org-timer) -(org-defkey org-mode-map "\C-c\C-x-" 'org-timer-item) -(org-defkey org-mode-map "\C-c\C-x0" 'org-timer-start) -(org-defkey org-mode-map "\C-c\C-x_" 'org-timer-stop) -(org-defkey org-mode-map "\C-c\C-x," 'org-timer-pause-or-continue) - -(define-key org-mode-map "\C-c\C-x\C-c" 'org-columns) - -(define-key org-mode-map "\C-c\C-x!" 'org-reload) - -(define-key org-mode-map "\C-c\C-xg" 'org-feed-update-all) -(define-key org-mode-map "\C-c\C-xG" 'org-feed-goto-inbox) - -(define-key org-mode-map "\C-c\C-x[" 'org-reftex-citation) - - -(when (featurep 'xemacs) - (org-defkey org-mode-map 'button3 'popup-mode-menu)) - - -(defconst org-speed-commands-default - '( - ("Outline Navigation") - ("n" . (org-speed-move-safe 'org-next-visible-heading)) - ("p" . (org-speed-move-safe 'org-previous-visible-heading)) - ("f" . (org-speed-move-safe 'org-forward-heading-same-level)) - ("b" . (org-speed-move-safe 'org-backward-heading-same-level)) - ("F" . org-next-block) - ("B" . org-previous-block) - ("u" . (org-speed-move-safe 'outline-up-heading)) - ("j" . org-goto) - ("g" . (org-refile t)) - ("Outline Visibility") - ("c" . org-cycle) - ("C" . org-shifttab) - (" " . org-display-outline-path) - ("s" . org-narrow-to-subtree) - ("=" . org-columns) - ("Outline Structure Editing") - ("U" . org-metaup) - ("D" . org-metadown) - ("r" . org-metaright) - ("l" . org-metaleft) - ("R" . org-shiftmetaright) - ("L" . org-shiftmetaleft) - ("i" . (progn (forward-char 1) (call-interactively - 'org-insert-heading-respect-content))) - ("^" . org-sort) - ("w" . org-refile) - ("a" . org-archive-subtree-default-with-confirmation) - ("@" . org-mark-subtree) - ("#" . org-toggle-comment) - ("Clock Commands") - ("I" . org-clock-in) - ("O" . org-clock-out) - ("Meta Data Editing") - ("t" . org-todo) - ("," . (org-priority)) - ("0" . (org-priority ?\ )) - ("1" . (org-priority ?A)) - ("2" . (org-priority ?B)) - ("3" . (org-priority ?C)) - (":" . org-set-tags-command) - ("e" . org-set-effort) - ("E" . org-inc-effort) - ("W" . (lambda(m) (interactive "sMinutes before warning: ") - (org-entry-put (point) "APPT_WARNTIME" m))) - ("Agenda Views etc") - ("v" . org-agenda) - ("/" . org-sparse-tree) - ("Misc") - ("o" . org-open-at-point) - ("?" . org-speed-command-help) - ("<" . (org-agenda-set-restriction-lock 'subtree)) - (">" . (org-agenda-remove-restriction-lock)) - ) - "The default speed commands.") - -(defun org-print-speed-command (e) - (if (> (length (car e)) 1) - (progn - (princ "\n") - (princ (car e)) - (princ "\n") - (princ (make-string (length (car e)) ?-)) - (princ "\n")) - (princ (car e)) - (princ " ") - (if (symbolp (cdr e)) - (princ (symbol-name (cdr e))) - (prin1 (cdr e))) - (princ "\n"))) - -(defun org-speed-command-help () - "Show the available speed commands." - (interactive) - (if (not org-use-speed-commands) - (user-error "Speed commands are not activated, customize `org-use-speed-commands'") - (with-output-to-temp-buffer "*Help*" - (princ "User-defined Speed commands\n===========================\n") - (mapc 'org-print-speed-command org-speed-commands-user) - (princ "\n") - (princ "Built-in Speed commands\n=======================\n") - (mapc 'org-print-speed-command org-speed-commands-default)) - (with-current-buffer "*Help*" - (setq truncate-lines t)))) - -(defun org-speed-move-safe (cmd) - "Execute CMD, but make sure that the cursor always ends up in a headline. -If not, return to the original position and throw an error." - (interactive) - (let ((pos (point))) - (call-interactively cmd) - (unless (and (bolp) (org-at-heading-p)) - (goto-char pos) - (error "Boundary reached while executing %s" cmd)))) - -(defvar org-self-insert-command-undo-counter 0) - -(defvar org-table-auto-blank-field) ; defined in org-table.el -(defvar org-speed-command nil) - -(define-obsolete-function-alias - 'org-speed-command-default-hook 'org-speed-command-activate "24.3") - -(defun org-speed-command-activate (keys) - "Hook for activating single-letter speed commands. -`org-speed-commands-default' specifies a minimal command set. -Use `org-speed-commands-user' for further customization." - (when (or (and (bolp) (looking-at org-outline-regexp)) - (and (functionp org-use-speed-commands) - (funcall org-use-speed-commands))) - (cdr (assoc keys (append org-speed-commands-user - org-speed-commands-default))))) - -(define-obsolete-function-alias - 'org-babel-speed-command-hook 'org-babel-speed-command-activate "24.3") - -(defun org-babel-speed-command-activate (keys) - "Hook for activating single-letter code block commands." - (when (and (bolp) (looking-at org-babel-src-block-regexp)) - (cdr (assoc keys org-babel-key-bindings)))) (defcustom org-speed-command-hook '(org-speed-command-default-hook org-babel-speed-command-hook) @@ -21185,16 +21002,35 @@ 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 ((tags-column (when (match-beginning 5) + (save-excursion (goto-char (match-beginning 5)) + (current-column)))) + (string (when (not (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. + (org-string-nw-p + (delete-and-extract-region (point) + (progn (goto-char (or (match-beginning 5) + (line-end-position))) + (skip-chars-backward " \t") + (point))))))) + ;; 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) + (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) (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..2f21c8e 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -834,7 +834,7 @@ ;;; Editing (ert-deftest test-org/return () - "Test RET (`org-return') specifications." + "Test `org-return' specifications." ;; Regular test. (should (equal "Para\ngraph" @@ -878,12 +878,37 @@ (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" + (let (org-auto-align-tags) + (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.1