From: John Kitchin <jkitchin@andrew.cmu.edu>
To: Julius Dittmar <Julius.Dittmar@gmx.de>
Cc: Org Mode <emacs-orgmode@gnu.org>
Subject: Re: coding help needed: set, increase and log review priority
Date: Wed, 02 May 2018 08:26:12 -0700 [thread overview]
Message-ID: <m2vac6ulij.fsf@andrew.cmu.edu> (raw)
In-Reply-To: <696e1993-b53a-31f4-7ae5-d4a24ff5dc1d@gmx.de>
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
prev parent reply other threads:[~2018-05-02 15:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-02 9:26 coding help needed: set, increase and log review priority Julius Dittmar
2018-05-02 15:26 ` John Kitchin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2vac6ulij.fsf@andrew.cmu.edu \
--to=jkitchin@andrew.cmu.edu \
--cc=Julius.Dittmar@gmx.de \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).