Subject: bug#21201: 25.0.50; (buffer-modified-p) errors inside cl-letf

From: Nicolas Richard <[email-masked]>
Date: Thu, 06 Aug 2015 22:07:13 +0200

Artur Malabarba <[email-masked]> writes:

> From emacs -Q, run the following:
>
> (cl-letf (((buffer-modified-p)))
>   (insert "ookok"))
>
> You'll get an error from trying to set a nil buffer.

Here is a fix:
--8<---------------cut here---------------start------------->8---
modified   lisp/emacs-lisp/cl-lib.el
@@ -634,8 +634,10 @@ If ALIST is non-nil, the new pairs are prepended to it."
 ;; Some more Emacs-related place types.
 (gv-define-simple-setter buffer-file-name set-visited-file-name t)
 (gv-define-setter buffer-modified-p (flag &optional buf)
-  `(with-current-buffer ,buf
-     (set-buffer-modified-p ,flag)))
+  (if buf
+      `(with-current-buffer ,buf
+         (set-buffer-modified-p ,flag))
+    `(set-buffer-modified-p ,flag)))
 (gv-define-simple-setter buffer-name rename-buffer t)
 (gv-define-setter buffer-string (store)
   `(insert (prog1 ,store (erase-buffer))))
--8<---------------cut here---------------end--------------->8---

-- 
Nico