From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Move to item to the bottom Date: Fri, 01 Jul 2011 08:35:55 +0200 Message-ID: <87zkkya4ok.fsf@gmail.com> References: <878vsjb14b.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([140.186.70.92]:37465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QcXKe-0003tR-4q for emacs-orgmode@gnu.org; Fri, 01 Jul 2011 02:36:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QcXKc-0004Ra-V5 for emacs-orgmode@gnu.org; Fri, 01 Jul 2011 02:36:04 -0400 Received: from mail-ww0-f49.google.com ([74.125.82.49]:57151) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QcXKc-0004RV-Pz for emacs-orgmode@gnu.org; Fri, 01 Jul 2011 02:36:02 -0400 Received: by wwf22 with SMTP id 22so2368708wwf.30 for ; Thu, 30 Jun 2011 23:36:02 -0700 (PDT) In-Reply-To: <878vsjb14b.fsf@gmail.com> (Nicolas Goaziou's message of "Thu, 30 Jun 2011 20:55:16 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Marcelo de Moraes Serpa Cc: Org Mode 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