Subject: bug#16319: closed (Re: bug#16319: 24.3.50; `case' macro not expanded in advice)

From: [email-masked] (GNU bug Tracking System)
Date: Thu, 02 Jan 2014 15:15:04 +0000

Your bug report

#16319: 24.3.50; `case' macro not expanded in advice

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
16319: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16319
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#16319: 24.3.50; `case' macro not expanded in advice
From: Stefan Monnier <[email-masked]>
To: Drew Adams <[email-masked]>
Cc: [email-masked]
Date: Thu, 02 Jan 2014 10:14:46 -0500
List-Id: <debbugs-submit.debbugs.gnu.org>

Indeed macros in defadvice are expanded only at run-time.
Use advice-add which does not suffer from this problem.

        Stefan

Subject: 24.3.50; `case' macro not expanded in advice
From: Drew Adams <[email-masked]>
To: [email-masked]
Date: Wed, 1 Jan 2014 14:05:18 -0800 (PST)
List-Id: <debbugs-submit.debbugs.gnu.org>

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'