summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2016-02-22 23:50:41 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2016-02-23 14:07:32 +0100
commit24033e3c672bed3728ec5ec4c6134b767b10cfc8 (patch)
tree03ec11965783027723af2cefbaa78130ca1bfaa4
parent7c0618b04dd39ab03075d077abaf8b15220445cf (diff)
downloadorg-mode-24033e3c672bed3728ec5ec4c6134b767b10cfc8.tar.gz
Move `org-edit-headline'
* lisp/org-colview.el (org-edit-headline): Move from here... * lisp/org.el (org-edit-headline): ... to here. Also refactor code. Accept to set headline non-interactively. * testing/lisp/test-org.el (test-org/edit-headline): New test.
-rw-r--r--lisp/org-colview.el19
-rw-r--r--lisp/org.el16
-rw-r--r--testing/lisp/test-org.el40
3 files changed, 56 insertions, 19 deletions
diff --git a/lisp/org-colview.el b/lisp/org-colview.el
index 36feb90..ec095bb 100644
--- a/lisp/org-colview.el
+++ b/lisp/org-colview.el
@@ -600,25 +600,6 @@ Where possible, use the standard interface for changing this line."
(org-move-to-column col)
(org-columns-update key))))))
-(defun org-edit-headline () ; FIXME: this is not columns specific. Make interactive????? Use from agenda????
- "Edit the current headline, the part without TODO keyword, TAGS."
- (org-back-to-heading)
- (when (looking-at org-todo-line-regexp)
- (let ((pos (point))
- (pre (buffer-substring (match-beginning 0) (match-beginning 3)))
- (txt (match-string 3))
- (post "")
- txt2)
- (if (string-match (org-re "[ \t]+:[[:alnum:]:_@#%]+:[ \t]*$") txt)
- (setq post (match-string 0 txt)
- txt (substring txt 0 (match-beginning 0))))
- (setq txt2 (read-string "Edit: " txt))
- (when (not (equal txt txt2))
- (goto-char pos)
- (insert pre txt2 post)
- (delete-region (point) (point-at-eol))
- (org-set-tags nil t)))))
-
(defun org-columns-edit-allowed ()
"Edit the list of allowed values for the current property."
(interactive)
diff --git a/lisp/org.el b/lisp/org.el
index 0b163fe..8847a6c 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7866,6 +7866,22 @@ This is a list with the following elements:
(org-back-to-heading t)
(buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
+(defun org-edit-headline (&optional heading)
+ "Edit the current headline.
+Set it to HEADING when provided."
+ (interactive)
+ (org-with-wide-buffer
+ (org-back-to-heading t)
+ (when (looking-at org-complex-heading-regexp)
+ (let* ((old (match-string-no-properties 4))
+ (new (org-trim (or heading (read-string "Edit: " old)))))
+ (unless (equal old new)
+ (if old (replace-match new t t nil 4)
+ (goto-char (or (match-end 3) (match-end 2) (match-end 1)))
+ (insert " " new))
+ (org-set-tags nil t)
+ (when (looking-at "[ \t]*$") (replace-match "")))))))
+
(defun org-insert-heading-after-current ()
"Insert a new heading with same level as current, after current subtree."
(interactive)
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index b0b7539..7ca55b6 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -1531,6 +1531,46 @@ SCHEDULED: <2014-03-04 tue.>"
(let (org-odd-levels-only)
(org-map-entries #'point "yes&no"))))))
+(ert-deftest test-org/edit-headline ()
+ "Test `org-edit-headline' specifications."
+ (should
+ (equal "* B"
+ (org-test-with-temp-text "* A"
+ (org-edit-headline "B")
+ (buffer-string))))
+ ;; Handle empty headings.
+ (should
+ (equal "* "
+ (org-test-with-temp-text "* A"
+ (org-edit-headline "")
+ (buffer-string))))
+ (should
+ (equal "* A"
+ (org-test-with-temp-text "* "
+ (org-edit-headline "A")
+ (buffer-string))))
+ ;; Handle TODO keywords and priority cookies.
+ (should
+ (equal "* TODO B"
+ (org-test-with-temp-text "* TODO A"
+ (org-edit-headline "B")
+ (buffer-string))))
+ (should
+ (equal "* [#A] B"
+ (org-test-with-temp-text "* [#A] A"
+ (org-edit-headline "B")
+ (buffer-string))))
+ (should
+ (equal "* TODO [#A] B"
+ (org-test-with-temp-text "* TODO [#A] A"
+ (org-edit-headline "B")
+ (buffer-string))))
+ ;; Handle tags.
+ (equal "* B :tag:"
+ (org-test-with-temp-text "* A :tag:"
+ (let ((org-tags-column 4)) (org-edit-headline "B"))
+ (buffer-string))))
+
;;; Keywords