Skip to main content
2 / 2
replaced http://ja.stackoverflow.com/ with https://ja.stackoverflow.com/

Jisami Zonu Tsugioさんの回答の通りcl.elと、cl-lib.elとの互換性の無さが原因だそうですが、
https://ja.stackoverflow.com/a/5459/3510
fletをマクロ展開すると、cl-letfが出てきますので、これを使えば、cl-lib.el に収録されている範囲で書き換えが可能ではないでしょうか。

(require 'cl-lib)

(defun foo () (get-buffer "hoge"))
(cl-letf (((symbol-function 'get-buffer)
           (lambda (buf-or-name)
             (car-safe
              (member buf-or-name
                      '("hoge" "fuga"))))))
  (or (get-buffer "hoge")
      (error "A"))
  (or (foo)
      (error "B")))
;=> "hoge"

参考: fletのマクロ展開

(flet ((get-buffer (buf-or-name)
          (car-safe (member buf-or-name '("hoge" "fuga")))))
   (or (get-buffer "hoge") (error "A"))
  (or (foo)))
===>
(letf
    (((symbol-function 'get-buffer)
       (cl-function
        (lambda
            (buf-or-name)
          (cl-block get-buffer
            (car-safe
             (member buf-or-name
                     '("hoge" "fuga"))))))))
  (or
   (get-buffer "hoge")
   (error "A"))
  (or
   (foo)))
g000001
  • 1,296
  • 8
  • 13