From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?utf-8?Q?=C5=81ukasz_Stelmach?= Subject: Re: org-prefere-future for other applications Date: Tue, 02 Mar 2010 11:38:56 +0100 Message-ID: <87r5o39fen.fsf@dasa3.iem.pw.edu.pl> References: <87hbp2g8ue.fsf@dasa3.iem.pw.edu.pl> <11DCBC21-0FEB-41E6-935B-5E4C4ABE151E@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NmPVt-0004tr-VN for emacs-orgmode@gnu.org; Tue, 02 Mar 2010 05:39:42 -0500 Received: from [140.186.70.92] (port=39330 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NmPVm-0004aq-JY for emacs-orgmode@gnu.org; Tue, 02 Mar 2010 05:39:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NmPVO-0000ii-Hk for emacs-orgmode@gnu.org; Tue, 02 Mar 2010 05:39:11 -0500 Received: from lo.gmane.org ([80.91.229.12]:42939) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NmPVN-0000ib-N8 for emacs-orgmode@gnu.org; Tue, 02 Mar 2010 05:39:10 -0500 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1NmPVL-0006Ze-8m for emacs-orgmode@gnu.org; Tue, 02 Mar 2010 11:39:07 +0100 Received: from dasa3.iem.pw.edu.pl ([194.29.147.110]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 02 Mar 2010 11:39:07 +0100 Received: from lukasz.stelmach by dasa3.iem.pw.edu.pl with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 02 Mar 2010 11:39:07 +0100 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: emacs-orgmode@gnu.org Carsten Dominik writes: > On Feb 27, 2010, at 1:29 PM, Łukasz Stelmach wrote: >> I've tried to rearrange org-read-date and some other helper function >> to make them usable from other applications which might not want to >> prefere future dates. Unfortunatelly I can't do it without making >> org-read- date *require* additional argument (prefer-future) >> everytime it is called in orgmode like this: >> >> (org-read-date ... org-read-date-prefer-future) > > > Ah, may be this is what this is about: > > (defun org-my-read-date (&optional prefer-future) > (let ((org-read-date-prefer-future prefer-future)) > (org-read-date))) > > ????? So this is dynamic soping? Thats what I needed, thanks. Scoping is one of subjects that always gives me a bit of a headache, no matter what language I use. Now with a function like this: --8<---------------cut here---------------start------------->8--- (defun stl/org-read-date (&optional with-time to-time from-string prompt default-time default-input prefer-future) "A wrapper around `org-read-date' to make it ignore the global `org-read-date-prefer-future' value." (let ((org-read-date-prefer-future prefer-future)) (org-read-date with-time to-time from-string prompt default-time default-input))) --8<---------------cut here---------------end--------------->8--- and a two others --8<---------------cut here---------------start------------->8--- (defun stl/org-ledger-ask-cleared () (let (c) (while (not (member (setq c (read-char "Cleared [Y/n/p]?")) '(?y ?n ?p ?\n ?\r ?\ )))) (cond ((eq c ?n) "") ((eq c ?p) "! ") (t "* ")))) (defun stl/org-ledger-read-invoice () (let ((c (read-string "Invoice number:"))) (if (string-match ".+" c) (concat "(" c ") ") ""))) --8<---------------cut here---------------end--------------->8--- and a template: --8<---------------cut here---------------start------------->8--- ("Expense" ?E "%(format-time-string \"%Y-%m-%d\" (stl/org-read-date nil 'to-time)) %(stl/org-ledger-ask-cleared)%(stl/org-ledger-read-invoice)%^{Description} %^{Debit||Expense:Cash|Assets:Checking|Liabilities:Visa} %^{Credit||Expense:Food|Expense:Supplies}\t%^{Amount}\n\n%!" "~/org/ledger.dat" bottom) --8<---------------cut here---------------end--------------->8--- I can use remember to add transactions to my ledger *without* havig to specify full date (most of times you register transactions from the past, right?). Cool :-) -- Miłego dnia, Łukasz Stelmach