[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: What's wrong with this elisp code?
From: |
Glenn Morris |
Subject: |
Re: What's wrong with this elisp code? |
Date: |
Fri, 04 Aug 2006 13:51:11 -0700 |
User-agent: |
Gnus (www.gnus.org), GNU Emacs (www.gnu.org/software/emacs/) |
ken wrote:
> Is there some other way that this variable could be defined other than
> with defvar?
Yes, the way that Jeff Miller already said: inside a let binding so
that it only exists for the duration of the calling function:
bar -> Symbol's value as variable is void: bar
(defun foo ()
(let ((bar "BAR"))
(message "the value of bar is %s" bar)))
(foo) -> "the value of bar is BAR"
bar -> Symbol's value as variable is void: bar
Making your own definition of the variable `bar' outside of the
function `foo' will be no help at all, since this global binding is
hidden inside the let statement.
The Emacs calendar does a few things in this way, which can make it
difficult to follow.
To achieve what you want, use the already posted solution, or adapt
the definition of the function `diary-mail-entries' (see documentation
of that function for example cron usage), eg to:
(require 'diary-lib)
(defun diary-to-file (file &optional ndays)
"Write the diary entries for the next NDAYS (default 1) to FILE."
(interactive (list (read-file-name "Write diary to file: ")
(prefix-numeric-value current-prefix-arg)))
(let ((diary-display-hook 'fancy-diary-display))
(list-diary-entries (calendar-current-date) (or ndays 1))
(with-temp-buffer
(insert
(if (get-buffer fancy-diary-buffer)
(with-current-buffer fancy-diary-buffer (buffer-string))
"No diary entries found"))
(write-region (point-min) (point-max) file nil nil nil t))))
Message not available