rpdillon/todotxt.el

[FR] Copy task

pyluyten opened this issue · 2 comments

Copy task could be done in two ways
I guess the second one is the right thing

  • Completely copy a row, like with y, then the user has to "e" the task
  • Offer a minibuffer for a new task but already containing tags of the current task

This does the first version, but automatically "e"dits the task. I have a few things like this in my .emacs / init.el :)

(defun todotxt-duplicate-item ()
  (interactive)
  (todotxt-add-item (todotxt-get-current-line-as-string))
  (todotxt-edit-item))

This one does your 2nd suggestion :)

The one bug/gotcha is that it duplicates the item first, so if you C-g cancel the edit, you'll still find your cursor on an empty task with the tags/priority.

(defun todotxt-duplicate-item ()
  (interactive)
  (let* ((line (todotxt-get-current-line-as-string))
   (prio (todotxt-get-priority line)))
    (todotxt-add-item
     (mapconcat 'identity
	  (cons (if prio (concat "(" prio ")") "")
		(nreverse (todotxt-get-tag-completion-list-from-string line)))
	  " ")))
  (todotxt-edit-item))