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.
This commit is contained in:
parent
7c0618b04d
commit
24033e3c67
|
@ -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)
|
||||
|
|
16
lisp/org.el
16
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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue