From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thorsten Jolitz Subject: Re: [FYI] Programming with org-dp (by example) Date: Mon, 05 Mar 2018 01:12:43 +0100 Message-ID: <871sgzs7lw.fsf@gmail.com> References: <877eqrs8xh.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:53033) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esdkZ-00027g-Et for emacs-orgmode@gnu.org; Sun, 04 Mar 2018 19:13:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esdkW-00071U-7A for emacs-orgmode@gnu.org; Sun, 04 Mar 2018 19:13:07 -0500 Received: from [195.159.176.226] (port=44806 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1esdkV-00070R-W0 for emacs-orgmode@gnu.org; Sun, 04 Mar 2018 19:13:04 -0500 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1esdiQ-0003ND-3v for emacs-orgmode@gnu.org; Mon, 05 Mar 2018 01:10:54 +0100 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" To: emacs-orgmode@gnu.org Thorsten Jolitz writes: PS Ups ... a few little bugs in the code, here is version 2 #+BEGIN_SRC emacs-lisp (defconst tj/radio-rgxp "^#\\+attr_org:[[:space:]]+:radio") (defconst tj/radio-temp "temp") (defconst tj/radio-wind "wind") (defvar tj/radio-rw '("temp" "wind")) ;read/write (defvar tj/radio-r '("take-a-walk")) ;read only (defvar tj/radio-temp-red '("freezing" "tropical")) (defvar tj/radio-temp-yellow '("cold" "hot")) (defvar tj/radio-temp-green '("normal" "warm")) (defvar tj/radio-wind-red '("hurricane")) (defvar tj/radio-wind-yellow '("storm")) (defvar tj/radio-wind-green '("breeze")) ;; rewire function (defun tj/radio-switch () "docstring" (interactive) (let ((stmp (time-stamp-string))) (forward-line) (org-dp-rewire 'plain-list 'tj/radio-cont ;cont t ;ins `(:attr_last_changed (,stmp)) ;aff nil ;elem ))) ;; mapping function (defun tj/radio-map () "docstring" (interactive) (let (temp wind) (org-dp-map '(tj/radio-switch) tj/radio-rgxp))) ;; HELPER FUNCTIONS ;; helper function to actually modify the content (defun tj/radio-cont (cont elem) "docstring" (let ((name (org-element-property :name elem)) (prompt-options (tj/radio-get-itm-labels cont)) (new-cont) (users-choice) (box-checked-p)) (cond ((member name tj/radio-rw) ;prompt user for value (progn (setq users-choice (ido-completing-read name prompt-options)) (set (intern name) users-choice) (setq new-cont (mapcar 'tj/radio-itm-rw cont)))) ((member name tj/radio-r) ;set value (setq new-cont (mapcar 'tj/radio-itm-r cont))) (t)) ;do nothing (or new-cont cont))) (defun tj/radio-get-itm-labels (cont) "docstring" (mapcar #'(lambda (itm) (string-remove-suffix "\n" (org-dp-contents itm t t))) cont)) (defun tj/radio-itm-rw (itm) "docstring" (let ((label (string-remove-suffix "\n" (org-dp-contents itm t t)))) (if (string-equal label users-choice) (org-element-put-property itm :checkbox 'on) (org-element-put-property itm :checkbox 'off)) itm)) (defun tj/radio-itm-r (itm) "docstring" (let ((label (string-remove-suffix "\n" (org-dp-contents itm t t)))) (org-element-put-property itm :checkbox 'off) (cond ((and (string-equal label "red") (not box-checked-p) (or (member temp tj/radio-temp-red) (member wind tj/radio-wind-red))) (org-element-put-property itm :checkbox 'on) (setq box-checked-p t)) ((and (string-equal label "yellow") (not box-checked-p) (or (member temp tj/radio-temp-yellow) (member wind tj/radio-wind-yellow))) (org-element-put-property itm :checkbox 'on) (setq box-checked-p t)) ((and (string-equal label "green") (not box-checked-p) (or (member temp tj/radio-temp-green) (member wind tj/radio-wind-green))) (org-element-put-property itm :checkbox 'on) (setq box-checked-p t))) itm)) #+END_SRC > Hello List, > due to some interest in org-dp recently on this list, I actually took > the challenge of implementing a feature request by John Kitchin (without > actually sticking close to the specification, this is just a showcase > for org-dp). > > Task: implement a radio-list with org checkboxes > Extra feature: a read only radio-list that changes its values > conditional on the values of read/write radio-lists (when mapping the > buffer) -- cheers, Thorsten