emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] coding help needed: set, increase and log review priority


From: John Kitchin
Subject: Re: [O] coding help needed: set, increase and log review priority
Date: Wed, 02 May 2018 08:26:12 -0700
User-agent: mu4e 1.0; emacs 25.3.1

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



reply via email to

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