Subject: Re: bug#12895: 24.3.50; Replacement for flet

From: Katsumi Yamaoka <[email-masked]>
Date: Fri, 16 Nov 2012 16:04:40 +0900

Stefan Monnier wrote:
> Such override should be done with an advice.

But why I haven't yet replaced flet used in
message-read-from-minibuffer is that I don't yet have a solution
better than this:

	(flet ((mail-abbrev-in-expansion-header-p nil t))
	  (read-from-minibuffer prompt initial-contents))

;; This makes mail-abbrev-expand work even in a minibuffer, not
;; in a message header.

Not only this, there will probably be lots of situations where
flet is handy to use.  Here's the one I've implemented in a
certain package so as to silence the byte compiler:

(defmacro my-flet (bindings &rest body)
  "Make temporary overriding function definitions.

\(fn ((FUNC ARGLIST BODY...) ...) FORM...)"
  `(let (fn origs)
     (dolist (bind ',bindings)
       (setq fn (car bind))
       (push (cons fn (and (fboundp fn) (symbol-function fn))) origs)
       (fset fn (cons 'lambda (cdr bind))))
     (unwind-protect
	 (progn ,@body)
       (dolist (orig origs)
	 (if (cdr orig)
	     (fset (car orig) (cdr orig))
	   (fmakunbound (car orig)))))))