emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Use variable filename for remember template?
@ 2009-07-06 22:27 Nathan Neff
  2009-07-07  0:35 ` Matthew Lundin
  2009-07-07  2:42 ` Nick Dokos
  0 siblings, 2 replies; 3+ messages in thread
From: Nathan Neff @ 2009-07-06 22:27 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

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.

Any help is appreciated.

Thanks,
-Nate

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Use variable filename for remember template?
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Matthew Lundin @ 2009-07-07  0:35 UTC (permalink / raw)
  To: Nathan Neff; +Cc: emacs-orgmode

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

> Hello,
>
> 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.

How about the following?

--8<---------------cut here---------------start------------->8---
 (setq org-remember-templates
      '(("Book" ?b "\n* %^{Book Title} %t :READING:
 \n%[~/personal/booktemp.txt]\n"
               "L:journal.org")
       ))
--8<---------------cut here---------------end--------------->8---

Best,
Matt

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Use variable filename for remember template?
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Nick Dokos @ 2009-07-07  2:42 UTC (permalink / raw)
  To: Nathan Neff; +Cc: emacs-orgmode

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-07-07  2:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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

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).