unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Glenn Morris <rgm+news@stanford.edu>
Subject: Re: What's wrong with this elisp code?
Date: Fri, 04 Aug 2006 13:51:11 -0700	[thread overview]
Message-ID: <jjbqr0w7gg.fsf@xoc5.Stanford.EDU> (raw)
In-Reply-To: mailman.4866.1154720372.9609.help-gnu-emacs@gnu.org

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

  parent reply	other threads:[~2006-08-04 20:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-03 17:35 What's wrong with this elisp code? ken
2006-08-03 19:16 ` Peter Dyballa
     [not found]   ` <44D24F39.5080607@speakeasy.net>
     [not found]     ` <52A05EBB-9A5D-48C9-8A2A-553908FD097E@Web.DE>
     [not found]       ` <44D25BD4.7040006@speakeasy.net>
     [not found]         ` <C1580EEC-6A6C-4FE3-8295-070AC6D482AD@Web.DE>
     [not found]           ` <44D327DF.6090500@speakeasy.net>
2006-08-04 11:27             ` Peter Dyballa
2006-08-04 19:39               ` ken
2006-08-04 20:04                 ` Peter Dyballa
     [not found]               ` <mailman.4866.1154720372.9609.help-gnu-emacs@gnu.org>
2006-08-04 20:51                 ` Glenn Morris [this message]
     [not found]             ` <mailman.4842.1154691137.9609.help-gnu-emacs@gnu.org>
2006-08-04 22:23               ` Glenn Morris
2006-08-05  0:06                 ` ken
     [not found] <mailman.4811.1154626598.9609.help-gnu-emacs@gnu.org>
2006-08-04  3:31 ` Jeff Miller
     [not found]   ` <44D32639.80305@speakeasy.net>
2006-08-04 19:53     ` Jeff Miller

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.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jjbqr0w7gg.fsf@xoc5.Stanford.EDU \
    --to=rgm+news@stanford.edu \
    /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.
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).