emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Łukasz Stelmach" <lukasz.stelmach@iem.pw.edu.pl>
To: emacs-orgmode@gnu.org
Subject: Re: org-prefere-future for other applications
Date: Tue, 02 Mar 2010 11:38:56 +0100	[thread overview]
Message-ID: <87r5o39fen.fsf@dasa3.iem.pw.edu.pl> (raw)
In-Reply-To: 11DCBC21-0FEB-41E6-935B-5E4C4ABE151E@gmail.com

Carsten Dominik <carsten.dominik@gmail.com> 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

      reply	other threads:[~2010-03-02 10:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-27 12:29 org-prefere-future for other applications Łukasz Stelmach
2010-03-01 12:38 ` Carsten Dominik
2010-03-01 12:40 ` Carsten Dominik
2010-03-02 10:38   ` Łukasz Stelmach [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=87r5o39fen.fsf@dasa3.iem.pw.edu.pl \
    --to=lukasz.stelmach@iem.pw.edu.pl \
    --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).