From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: coding help needed: set, increase and log review priority Date: Wed, 02 May 2018 08:26:12 -0700 Message-ID: References: <696e1993-b53a-31f4-7ae5-d4a24ff5dc1d@gmx.de> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42616) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDte6-0005jv-EL for emacs-orgmode@gnu.org; Wed, 02 May 2018 11:26:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fDte4-0006H9-UZ for emacs-orgmode@gnu.org; Wed, 02 May 2018 11:26:18 -0400 Received: from mail-pg0-x229.google.com ([2607:f8b0:400e:c05::229]:41372) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fDte4-0006FJ-P1 for emacs-orgmode@gnu.org; Wed, 02 May 2018 11:26:16 -0400 Received: by mail-pg0-x229.google.com with SMTP id m21-v6so10881461pgv.8 for ; Wed, 02 May 2018 08:26:16 -0700 (PDT) In-reply-to: <696e1993-b53a-31f4-7ae5-d4a24ff5dc1d@gmx.de> 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: Julius Dittmar Cc: Org Mode Julius Dittmar writes: > Hi, > > lisp is still a mystery to me, so I need help coding some functions I > would like to use. > > What I want is a property 'ReviewPriority', which can take integer > values, and a property 'LastReview'. I need functions that > > - increase ReviewPriority by one, assuming an initial 0 if there's no > value set, up to a hard-coded maximum of 5, set LastReview to the > current date, and log the change (new value and date are sufficient) in > the LOGBOOK drawer Here is a lightly commented function that does this all of these I think. M-x f0 will increment the ReviewPriority C-1 M-x f0 will set the ReviewPriority to 1 C-n M-x f0 will set the ReviewPriority to min(n, 5) where n is a number The main things to keep in mind are that property entries are strings, and you have to convert them back and forth between numbers. I don't know a better way to make a logbook entry that doesn't end up opening a notes buffer. #+BEGIN_SRC emacs-lisp (defun f0 (&optional new-review-priority-n) "- increase ReviewPriority by one, assuming an initial 0 if there's no value set, up to a hard-coded maximum of 5, set LastReview to the current date, and log the change (new value and date are sufficient) in the LOGBOOK drawer" (interactive "p") (let* ( ;; this will be a string of 0 or the ReviewPriority (current-review-priority (or (org-entry-get nil "ReviewPriority") "0")) ;; convert it to a number for incrementing (current-review-priority-n (string-to-number current-review-priority)) ;; placeholder variables new-review-priority) (setq new-review-priority-n (if new-review-priority-n (min new-review-priority-n 5) ;; no numeric prefix, so increment existing (min (incf current-review-priority-n) 5)) ;; this is what will be written to properties new-review-priority (number-to-string new-review-priority-n)) (org-entry-put nil "ReviewPriority" new-review-priority) (org-entry-put nil "LastReview" (format-time-string "%Y-%m-%d" (current-time))) (org-add-log-setup 'state (format "Review Priority %s" new-review-priority) current-review-priority 'time)))) #+END_SRC You could make helper functions that do those too, , e.g. a function that calls (f0 3) will set the ReviewPriority to 3. And, a function like this #+BEGIN_SRC emacs-lisp (defun f2 (n) (interactive "nN: ") (f0 n)) #+END_SRC will prompt you for a number and then set the properties. Anyway, Hopefully that can get you started. You can learn more about the functions with C-h f in Emacs. > > - set ReviewPriority to a fixed value (for example 1), set LastReview to > the current date, and log the change in the LOGBOOK drawer > > - set ReviewPriority to a user-given value (clipping to the acceptable > value range of 0 to 5 would be a boon, but is not necessary), set > LastReview to the current date, and log the change in the LOGBOOK drawer. > > Additionally I'd like to bind the increase function to C-c r and the > function with user input to C-c R. > > Any help welcome! > > Thanks in advance, > > Julius -- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu