emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Move to item to the bottom


From: Nicolas Goaziou
Subject: Re: [O] Move to item to the bottom
Date: Fri, 01 Jul 2011 08:35:55 +0200

Correcting myself, I paste here another try to the problem at
hand. Indeed, moving an item to a list he doesn't directly belong to
makes little sense. Thus, the item will be moved at the end of its list.

#+begin_src emacs-lisp
(defun ngz-move-item-at-bottom ()
  "Move item at point at the bottom of the list."
  (interactive)
  (if (not (org-at-item-p))
      (error "Not in a list")
    (let* ((item (point-at-bol))
           (struct (org-list-struct))
           (end (org-list-get-item-end item struct))
           (bullet (regexp-quote (org-list-get-bullet item struct)))
           (body (org-trim
                  (buffer-substring (progn (looking-at (concat "[ \t]*" bullet))
                                           (match-end 0))
                                    end)))
           (prevs (org-list-prevs-alist struct))
           (last-item (org-list-get-last-item item struct prevs))
           (ins-point (save-excursion (goto-char last-item) (point-at-eol)))
           (org-M-RET-may-split-line nil))
      (if (= item last-item)
          (error "Item is already at the bottom of the list")
        (save-excursion (org-list-insert-item ins-point struct prevs nil body))
        (delete-region item end)
        (org-list-repair)
        (org-update-checkbox-count-maybe)))))
#+end_src

That function will compute list structure two times (at
`org-list-struct' and `org-list-repair' calls), which is bad. It may be
interesting to implement an `org-list-delete-item' to solve that problem
(it would return structure of the list after deletion, removing the need
to recompute it). I'll add it to org-list.el if it proves useful enough
(i.e. others use-cases than this function).

Regards,

-- 
Nicolas Goaziou



reply via email to

[Prev in Thread] Current Thread [Next in Thread]