From: Nathan Neff <nathan.neff@gmail.com>
To: Bernt Hansen <bernt@norang.ca>
Cc: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: Can this function be written better?
Date: Mon, 6 Dec 2010 21:00:50 -0600 [thread overview]
Message-ID: <AANLkTin=FGV6LoQTGJOU28a72z70DRQukKo29xAT7es1@mail.gmail.com> (raw)
In-Reply-To: <8739qapnz3.fsf@norang.ca>
> Hi Nate,
>
> I would probably write it like this: (but I'm no emacs-lisp expert
> either)
>
> (defun njn/agenda-toggle-show-closed()
> "Toggle whether closed clock thingies are shown in the agenda"
> (interactive)
> (setq njn/org-agenda-show-closed (not njn/org-agenda-show-closed))
> (setq org-agenda-log-mode-items (if njn/org-agenda-show-closed
> (quote (closed clock))
> (quote (clock))))
> (message "%sShowing closed clock entries in agenda" (if njn/org-agenda-show-closed "" "NOT ")))
>
> You have a bug in your version - the test and report is backwards.
> When njn/org-agenda-show-closed is t you don't show closed items and
> when it's nil you do.
>
> - You don't need to check for equality with 't (and you don't need to
> quote t)
> - everything non-nil is true
> - you can just check that directly in the (if ... )
>
> My version basically does this:
> 1. toggle the boolean njn/org-agenda-shot-closed
> 2. set org-agenda-log-mode-items based on the boolean
> 3. report the value
Thanks Bernt -- hehe -- I never really noticed the bug.
I'd like to see if there's a way to avoid having a variable at all --
something like this (In functional language / Lisp speak, that is)
If org-agenda-log-mode-items contains (closed) then
org-agenda-log-mode-items = org-agenda-log-mode-items - (closed)
else
org-agenda-log-mode-items = org-agenda-log-mode-items + (closed)
end if
I'll try something on my own if I have 15-20 minutes to work on it tonight --
Thanks for the bugfix and this cool line:
(message "%sShowing closed clock entries in agenda" (if
njn/org-agenda-show-closed "" "NOT ")
--Nate
prev parent reply other threads:[~2010-12-07 3:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-06 18:29 Can this function be written better? Nathan Neff
2010-12-06 21:53 ` Bernt Hansen
2010-12-07 3:00 ` Nathan Neff [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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='AANLkTin=FGV6LoQTGJOU28a72z70DRQukKo29xAT7es1@mail.gmail.com' \
--to=nathan.neff@gmail.com \
--cc=bernt@norang.ca \
--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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.