From mboxrd@z Thu Jan 1 00:00:00 1970 From: Cecil Westerhof Subject: Re: Check checkbox and move to end of list Date: Thu, 23 Jan 2014 20:51:14 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c123b665c93804f0a89044 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50074) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6QJ3-0004xX-Cy for emacs-orgmode@gnu.org; Thu, 23 Jan 2014 14:51:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W6QJ2-00010S-8C for emacs-orgmode@gnu.org; Thu, 23 Jan 2014 14:51:17 -0500 Received: from mail-qc0-x230.google.com ([2607:f8b0:400d:c01::230]:61655) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6QJ2-00010H-3Q for emacs-orgmode@gnu.org; Thu, 23 Jan 2014 14:51:16 -0500 Received: by mail-qc0-f176.google.com with SMTP id e16so3108182qcx.21 for ; Thu, 23 Jan 2014 11:51:14 -0800 (PST) In-Reply-To: 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: emacs-orgmode@gnu.org --001a11c123b665c93804f0a89044 Content-Type: text/plain; charset=ISO-8859-1 2014/1/23 Cecil Westerhof > The following function does (mostly) what I want: > (defun dcbl-check-checkbox-and-move-to-end () > (interactive) > (save-excursion > (let* ((struct (org-list-struct)) > (struct-old (copy-tree struct)) > (item (line-beginning-position)) > (item-checkbox-type (org-list-get-checkbox item struct))) > (if (not item-checkbox-type) > (message "No checkbox found") > (if (string-equal item-checkbox-type "[X]") > (message "Checkbox already checked") > (org-list-set-checkbox item struct "[X]") > (org-list-write-struct struct (org-list-parents-alist struct) > struct-old) > (org-list-send-item item 'end struct)))))) > Update of the count in the parent did not go correctly always. This code does the update correct. (Only the last command is appended.) (defun dcbl-check-checkbox-and-move-to-end () (interactive) (save-excursion (let* ((struct (org-list-struct)) (struct-old (copy-tree struct)) (item (line-beginning-position)) (item-checkbox-type (org-list-get-checkbox item struct))) (if (not item-checkbox-type) (message "No checkbox found") (if (string-equal item-checkbox-type "[X]") (message "Checkbox already checked") (org-list-set-checkbox item struct "[X]") (org-list-write-struct struct (org-list-parents-alist struct) struct-old) (dcbl-move-item-to-end-of-list item) (org-update-statistics-cookies nil)))))) -- Cecil Westerhof --001a11c123b665c93804f0a89044 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
2014/1/23 Cecil Westerhof <= cldwesterhof@gmail.com>
T= he following function does (mostly) what I want:
(defun dcbl-check-checkbox-and-move-to-end ()
=A0 (interactive)
=A0 (= save-excursion
=A0=A0=A0 (let* ((struct=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (org-list-stru= ct))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (struct-old=A0=A0=A0=A0=A0=A0=A0=A0 = (copy-tree struct))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (item=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0 (line-beginning-position))
=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 (item-checkbox-type (org-list-get-checkbox item struct))) =A0=A0=A0=A0=A0 (if (not item-checkbox-type)
=A0=A0=A0=A0=A0=A0=A0=A0=A0= (message "No checkbox found")
=A0=A0=A0=A0=A0=A0=A0 (if (stri= ng-equal item-checkbox-type "[X]")
=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0 (message "Checkbox already checked")
=A0=A0=A0=A0=A0=A0= =A0=A0=A0 (org-list-set-checkbox item struct "[X]")
=A0=A0=A0=A0=A0=A0=A0=A0=A0 (org-list-write-struct struct (org-list-parents= -alist struct) struct-old)
=A0=A0=A0=A0=A0=A0=A0=A0=A0 (org-list-send-it= em item 'end struct))))))

Update of the count in the parent did not go correctly always. This code do= es the update correct. (Only the last command is appended.)
(defun dcbl-= check-checkbox-and-move-to-end ()
=A0 (interactive)
=A0 (save-excursi= on
=A0=A0=A0 (let* ((struct=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (org-list-stru= ct))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (struct-old=A0=A0=A0=A0=A0=A0=A0=A0 = (copy-tree struct))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (item=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0 (line-beginning-position))
=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 (item-checkbox-type (org-list-get-checkbox item struct))) =A0=A0=A0=A0=A0 (if (not item-checkbox-type)
=A0=A0=A0=A0=A0=A0=A0=A0=A0= (message "No checkbox found")
=A0=A0=A0=A0=A0=A0=A0 (if (stri= ng-equal item-checkbox-type "[X]")
=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0 (message "Checkbox already checked")
=A0=A0=A0=A0=A0=A0= =A0=A0=A0 (org-list-set-checkbox item struct "[X]")
=A0=A0=A0=A0=A0=A0=A0=A0=A0 (org-list-write-struct struct (org-list-parents= -alist struct) struct-old)
=A0=A0=A0=A0=A0=A0=A0=A0=A0 (dcbl-move-item-t= o-end-of-list item)
=A0=A0=A0=A0=A0=A0=A0=A0=A0 (org-update-statistics-c= ookies nil))))))


--
Cecil Westerhof
--001a11c123b665c93804f0a89044--