emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Dokos <nicholas.dokos@hp.com>
To: Nathan Neff <nathan.neff@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Use variable filename for remember template?
Date: Mon, 06 Jul 2009 22:42:36 -0400	[thread overview]
Message-ID: <8444.1246934556@gamaville.dokosmarshall.org> (raw)
In-Reply-To: Message from Nathan Neff <nathan.neff@gmail.com> of "Mon, 06 Jul 2009 17:27:19 CDT." <211769420907061527x410f47f6n7370768c24fc5ebb@mail.gmail.com>

Nathan Neff <nathan.neff@gmail.com> wrote:

> I am able to successfully read the contents of
> "/Users/nate/personal/booktemp.txt" into a new remember-note.
> 
> (setq org-remember-templates
>      '(("Book" ?b "\n* %^{Book Title} %t :READING:
> \n%[/Users/nate/personal/booktemp.txt]\n"
>               "L:journal.org")
>       ))
> 
> Now, I'd like to be able to specify an environment variable like $HOME
> instead of /Users/nate.
> 
> I'm a lisp beginner, and have tried something like
> 
> (setq personal-home-dir (getenv "HOME"))
> 
> (setq org-remember-templates
>      '(("Book" ?b (concat "\n* %^{Book Title} %t :READING: \n%["
 personal-home-dir "/personal/booktemp.txt]\n")
>               "L:journal.org")
>       ))
> 
> but I keep getting "Wrong type argument char-or-string-p" errors.
> 
> I'm guessing that the org-remember-templates function wants something
> other than a string, but I don't know where to go from here.
> 

No, it requires a string. The problem is that when you quote an expression
in lisp, you are saying "do not evaluate the innards of this expression".
But here you *want*  some of the innards evaluated: in particular, the call
to concat *has* to be evaluated in order to give you the required string.

Note that org-remember-templates is supposed to be a list of lists. Each inner
list has to have the form

     (string char string [string] [string])

where the square brackets indicate optional elements. That's the name of the
template, the char you use to invoke it, the template itself, the destination
file, and the headline.

The trick is to construct such a list without using quote. The lisp function
to construct lists is called (drum roll...) ``list''. So you can construct
the list like this:

    (list "Book" ?b 
          (concat "\n* %^{Book Title} %t :READING: \n%[" personal-home-dir "/personal/booktemp.txt]\n")
          "L:journal.org")

When evaluated [1], the above expression gives you the following list:

         ("Book" ?b 
          "\n* %^{Book Title} %t :READING: \n%[/home/nate/personal/booktemp.txt]\n"
          "L:journal.org")


That will serve fine as the inner list, but now we have to set org-remember-templates
to be a list with the inner list as its only element (unless of course you have more
than one template):

(setq org-remember-templates
      (list
            (list "Book" ?b 
                  (concat "\n* %^{Book Title} %t :READING: \n%[" personal-home-dir "/personal/booktemp.txt]\n")
                  "L:journal.org")))

will do that.

This method will work in general, but it is overkill for the simpler situation
where all of the elements of the inner list(s) are "constants", i.e. when you
evaluate them, they give you back what you started with (e.g. numbers, strings,
chars evaluate to themselves). In this situation, you can form the list like this:

      ("Book" ?b "..." "...")

except that when lisp sees such a form, it assumes it's a function call
with arguments, e.g. (+ 2 3) is a call to the function + with args 2 and 3.
It is in order to inhibit *this* evaluation that quoting is used - it makes
the quoted expression self-evaluating:

      '("Book" ?b "..." "...")

Look at the difference:

    (+ 2 3) --> 5
    '(+ 2 3) --> (+ 2 3)

If you have more questions (and you *should*! Even in the highly
unlikely situation that the above is crystal clear, it only scratches
the surface of a deep subject), try an introductory book on lisp,
perhaps "The Little Lisper" by Dan Friedman (the current edition is
called "The Little Schemer", co-authored with Matthias Felleisen, and it
discusses the Scheme dialect of Lisp, but the basic ideas are the
same). Emacs also comes with an Emacs Lisp Intro (which I have not
read) - you might look at that instead (or in addition): do C-h i m
Emacs Lisp Intro <RET>.

HTH,
Nick


[1] Try it: put the cursor at the end of 

(setq personal-home-dir (getenv "HOME"))

i.e. after the closing parenthesis, and press C-x C-e - the result is
displayed in the minibuffer (echo area). Of course, the main object here
is not the result of the expression, but the side effect: setq binds the
variable personal-home-dir to the value of (getenv "HOME"). But now that
personal-home-dir is defined, you can put the cursor at the end of the
list expression , press C-x C-e and you'll see the result of that
evaluation.

      parent reply	other threads:[~2009-07-07  2:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-06 22:27 Use variable filename for remember template? Nathan Neff
2009-07-07  0:35 ` Matthew Lundin
2009-07-07  2:42 ` Nick Dokos [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=8444.1246934556@gamaville.dokosmarshall.org \
    --to=nicholas.dokos@hp.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=nathan.neff@gmail.com \
    /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).