From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nathan Neff Subject: Re: Can this function be written better? Date: Mon, 6 Dec 2010 21:00:50 -0600 Message-ID: References: <8739qapnz3.fsf@norang.ca> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: Received: from [140.186.70.92] (port=55225 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPnnR-00009T-H4 for emacs-orgmode@gnu.org; Mon, 06 Dec 2010 22:00:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PPnnP-0003jr-Ry for emacs-orgmode@gnu.org; Mon, 06 Dec 2010 22:00:53 -0500 Received: from mail-bw0-f43.google.com ([209.85.214.43]:53713) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PPnnP-0003jl-Kk for emacs-orgmode@gnu.org; Mon, 06 Dec 2010 22:00:51 -0500 Received: by bwz14 with SMTP id 14so10951460bwz.30 for ; Mon, 06 Dec 2010 19:00:50 -0800 (PST) In-Reply-To: <8739qapnz3.fsf@norang.ca> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Bernt Hansen Cc: emacs-orgmode > Hi Nate, > > I would probably write it like this: (but I'm no emacs-lisp expert > either) > > (defun njn/agenda-toggle-show-closed() > =A0"Toggle whether closed clock thingies are shown in the agenda" > =A0(interactive) > =A0(setq njn/org-agenda-show-closed (not njn/org-agenda-show-closed)) > =A0(setq org-agenda-log-mode-items (if njn/org-agenda-show-closed > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0(quote (closed clock)) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(q= uote (clock)))) > =A0(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 > =A0quote t) > =A0- everything non-nil is true > =A0- you can just check that directly in the (if ... ) > > My version basically does this: > =A01. toggle the boolean njn/org-agenda-shot-closed > =A02. set org-agenda-log-mode-items based on the boolean > =A03. 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 =3D org-agenda-log-mode-items - (closed) else org-agenda-log-mode-items =3D 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