Gnus development mailing list
 help / color / mirror / Atom feed
* function to pack folders
@ 1998-02-02 18:22 Mark Moll
  1998-02-02 20:00 ` Colin Rafferty
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Moll @ 1998-02-02 18:22 UTC (permalink / raw)
  Cc: mmoll+


I wrote this little function to renumber articles in my nnml folders. I
don't know that much about elisp, but this seemed a reasonable way to do it.
For some reason, however, I get the following error when I call the function 
below in the summary buffer.

      Symbol's value as variable is void: group

It's probably something very trivial, but can anybody tell me what I'm
doing wrong?

(defun mm-pack-folder ()
  "Renumber the articles such that holes in the numbering are removed."
  (interactive)
  (let ((group gnus-newsgroup-name)
	(folder (replace-in-string
		 (replace-in-string group 
				    "\\(nnml\\+archive:\\)\\(.*\\)"
				    "archive/\\2")
		 "\\(nnml:\\)\\(.*\\)" "\\2"))
	(dir (concat message-directory folder)))
    (call-process "gunzip" nil nil nil (concat dir "/*.gz"))
    (call-process "folder" nil nil nil (concat "+" folder) "-pack")
    (nnml-generate-nov-databases-1 (concat dir))
    (call-process "gzip" nil nil nil (concat dir "/*"))
    (gnus-summary-reselect-current-group)))

-- 
Mark Moll    


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

* Re: function to pack folders
  1998-02-02 18:22 function to pack folders Mark Moll
@ 1998-02-02 20:00 ` Colin Rafferty
  0 siblings, 0 replies; 2+ messages in thread
From: Colin Rafferty @ 1998-02-02 20:00 UTC (permalink / raw)


Mark Moll writes:

> I wrote this little function to renumber articles in my nnml folders. I
> don't know that much about elisp, but this seemed a reasonable way to do it.
> For some reason, however, I get the following error when I call the function 
> below in the summary buffer.

>       Symbol's value as variable is void: group

> It's probably something very trivial, but can anybody tell me what I'm
> doing wrong?

> ...
>   (let ((group gnus-newsgroup-name)
>         (folder (replace-in-string
>                  (replace-in-string group 
>                                     "\\(nnml\\+archive:\\)\\(.*\\)"
>                                     "archive/\\2")
>                  "\\(nnml:\\)\\(.*\\)" "\\2"))
>         (dir (concat message-directory folder)))
> ...

Short answers (two independent solutions):

1. Use `let*' instead of `let'.
2. Use `gnus-newsgroup-name' instead of `group' in the call to
   `replace-in-string'.

Long answer:

The problem is the `group' in the call to replace-in-string.  Since you
are using `let', the variables are not bound until the body is being
executed.

Specifically, a `let' form is really just syntactic sugar for calling a
lambda-expression, and you cannot use the values of some of the
arguments to evaluate the other arguments.

For example, imagine I had the following let form:

    (let ((x (* 2 3))
          (y (+ 5 6)))
      (+ x y))

It will be translated into the following:

    (funcall #'(lambda (x y)
                 (+ x y))
             (* 2 3)
             (+ 5 6))

Therefore, if you have something that looks like this:

    (let ((group gnus-newsgroup-name)
          (folder (replace-in-string
                   (replace-in-string group 
                                      "\\(nnml\\+archive:\\)\\(.*\\)"
                                      "archive/\\2")
                   "\\(nnml:\\)\\(.*\\)" "\\2"))
          (dir (concat message-directory folder)))
      (call-process "gunzip" nil nil nil (concat dir "/*.gz"))
      (call-process "folder" nil nil nil (concat "+" folder) "-pack")
      (nnml-generate-nov-databases-1 (concat dir))
      (call-process "gzip" nil nil nil (concat dir "/*"))
      (gnus-summary-reselect-current-group))

It would be translated into this:

    (funcall #'(lambda (group folder dir)
                 (call-process "gunzip" nil nil nil (concat dir "/*.gz"))
                 (call-process "folder" nil nil nil (concat "+" folder) "-pack")
                 (nnml-generate-nov-databases-1 (concat dir))
                 (call-process "gzip" nil nil nil (concat dir "/*"))
                 (gnus-summary-reselect-current-group))
             gnus-newsgroup-name
             (replace-in-string (replace-in-string group 
                                                   "\\(nnml\\+archive:\\)\\(.*\\)"
                                                   "archive/\\2")
                                "\\(nnml:\\)\\(.*\\)" "\\2")
             (concat message-directory folder))

As you can see, the reference to `group' in the `replace-in-string' is
unbound, since it only exists in the lambda-expression itself.

By the way, while I was writing this reply, I realized that, while `let'
is a built-in function, I could write it as a macro.  I really need to
get a more exciting job.

    (defmacro mac-let (varlist &rest body)
      "Macro version of let."
      (append
       (list 'funcall
             (append
              (list 'lambda
                    (mapcar #'(lambda (varspec)
                                (cond ((symbolp varspec) varspec)
                                      ((consp varspec) (car varspec))
                                      (error "invalid varspec %s" varspec)))
                            varlist))
              body))
       (mapcar #'(lambda (varspec)
                   (and (consp varspec) (car (cdr varspec))))
               varlist)))

I'll leave writing `mac-let*' as an exercise to the reader. :-)

-- 
Colin


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

end of thread, other threads:[~1998-02-02 20:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-02-02 18:22 function to pack folders Mark Moll
1998-02-02 20:00 ` Colin Rafferty

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 NNTP newsgroup(s).