Subject: 24.3.50; `case' macro not expanded in advice

From: Drew Adams <[email-masked]>
Date: Wed, 1 Jan 2014 14:05:18 -0800 (PST)

1. This bug:

emacs -Q

Put this in a file foo.el and byte-compile it.

(eval-when-compile (require 'cl)) ;; case, 

(when (fboundp 'file-cache-add-file)
  (defadvice file-cache-add-file (around bmkp-autofile-filecache activate)
    "Respect option `bmkp-autofile-filecache'."
    (case bmkp-autofile-filecache
      (autofile-only     (bmkp-autofile-set (ad-get-arg 0) nil nil 'NO-UPDATE-P))
      (autofile+cache    (progn ad-do-it  (bmkp-autofile-set (ad-get-arg 0) nil nil 'NO-UPDATE-P 'MSG-P)))
      (cache-only        ad-do-it))))

emacs -Q
M-x load-file foo.elc

M-: (file-cache-add-file "foo.el")

Debugger entered--Lisp error: (void-function case)
  (case bmkp-autofile-filecache (autofile-only (bmkp-autofile-set file 
    nil nil (quote NO-UPDATE-P))) (autofile+cache (progn (setq
    ad-return-value (with-no-warnings (funcall ad--addoit-function
    file))) (bmkp-autofile-set file nil nil (quote NO-UPDATE-P) (quote
    MSG-P)))) (cache-only (setq ad-return-value (with-no-warnings
    (funcall ad--addoit-function file))))) 
  (let (ad-return-value) (case bmkp-autofile-filecache (autofile-only
    (bmkp-autofile-set file nil nil (quote NO-UPDATE-P)))
    (autofile+cache (progn (setq ad-return-value (with-no-warnings
    (funcall ad--addoit-function file))) (bmkp-autofile-set file nil nil
    (quote NO-UPDATE-P) (quote MSG-P)))) (cache-only (setq
    ad-return-value (with-no-warnings (funcall ad--addoit-function
    file))))) ad-return-value) 
  ad-Advice-file-cache-add-file(#[...])
  file-cache-add-file("foo.el")
  eval((file-cache-add-file "foo.el") nil)
  eval-expression((file-cache-add-file "foo.el") nil)
  call-interactively(eval-expression nil nil)
  command-execute(eval-expression)

2. Another (minor), related bug:

As a workaround, I defined a helper function, which has just the
`case' sexp, and I use that in the defadvice.  But then I get a
warning about `ad-do-it' being an undefined variable.  So I work
around that by adding (defvar ad-do-it).  But that's not right
either, since `ad-do-it' is not a variable.

Fixing #1 will take care of #2.  If you do not fix #1 then at least
the byte-compiler should not flag `ad-do-it' as an undefined
variable.

In GNU Emacs 24.3.50.1 (i686-pc-mingw32)
 of 2013-12-27 on ODIEONE
Bzr revision: 115778 [email-masked]
Windowing system distributor `Microsoft Corp.', version 6.1.7601
Configured using:
 `configure --prefix=/c/Devel/emacs/binary --enable-checking=yes,glyphs
 'CFLAGS=-O0 -g3' LDFLAGS=-Lc:/Devel/emacs/lib
 CPPFLAGS=-Ic:/Devel/emacs/include'