GNU bug report logs - #21201
25.0.50; (buffer-modified-p) errors inside cl-letf

Previous Next

Package: emacs;

Reported by: bruce.connor.am <at> gmail.com

Date: Thu, 6 Aug 2015 19:48:01 UTC

Severity: minor

Tags: fixed, patch

Merged with 29371

Found in versions 25.0.50, 26.0.50

Fixed in version 27.1

Done: Noam Postavsky <npostavs <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 21201 in the body.
You can then email your comments to 21201 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#21201; Package emacs. (Thu, 06 Aug 2015 19:48:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to bruce.connor.am <at> gmail.com:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 06 Aug 2015 19:48:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Artur Malabarba <bruce.connor.am <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.0.50; (buffer-modified-p) errors inside cl-letf
Date: Thu, 6 Aug 2015 20:47:34 +0100
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.

Using `(buffer-modified-p (current-buffer))' instead works.

Backtrace:
Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  set-buffer(nil)
  (save-current-buffer (set-buffer nil) (set-buffer-modified-p old))
  (unwind-protect (insert "ookok") (save-current-buffer (set-buffer
nil) (set-buffer-modified-p old)))
  (let* ((old (buffer-modified-p))) (unwind-protect (insert "ookok")
(save-current-buffer (set-buffer nil) (set-buffer-modified-p old))))
  eval((let* ((old (buffer-modified-p))) (unwind-protect (insert
"ookok") (save-current-buffer (set-buffer nil) (set-buffer-modified-p
old)))) nil)
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21201; Package emacs. (Thu, 06 Aug 2015 20:08:02 GMT) Full text and rfc822 format available.

Message #8 received at 21201 <at> debbugs.gnu.org (full text, mbox):

From: Nicolas Richard <youngfrog <at> members.fsf.org>
To: Artur Malabarba <bruce.connor.am <at> gmail.com>
Cc: 21201 <at> debbugs.gnu.org
Subject: Re: bug#21201: 25.0.50; (buffer-modified-p) errors inside cl-letf
Date: Thu, 06 Aug 2015 22:07:13 +0200
Artur Malabarba <bruce.connor.am <at> gmail.com> 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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21201; Package emacs. (Thu, 06 Aug 2015 21:45:03 GMT) Full text and rfc822 format available.

Message #11 received at 21201 <at> debbugs.gnu.org (full text, mbox):

From: Artur Malabarba <bruce.connor.am <at> gmail.com>
To: Nicolas Richard <youngfrog <at> members.fsf.org>
Cc: 21201 <at> debbugs.gnu.org
Subject: Re: bug#21201: 25.0.50; (buffer-modified-p) errors inside cl-letf
Date: Thu, 6 Aug 2015 22:44:52 +0100
2015-08-06 21:07 GMT+01:00 Nicolas Richard <youngfrog <at> members.fsf.org>:
> Artur Malabarba <bruce.connor.am <at> gmail.com> 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)))

Don't know if it's possible, but shouldn't it try to ensure that it's
in the same buffer as before?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21201; Package emacs. (Thu, 06 Aug 2015 22:51:01 GMT) Full text and rfc822 format available.

Message #14 received at 21201 <at> debbugs.gnu.org (full text, mbox):

From: Nicolas Richard <youngfrog <at> members.fsf.org>
To: Artur Malabarba <bruce.connor.am <at> gmail.com>
Cc: 21201 <at> debbugs.gnu.org
Subject: Re: bug#21201: 25.0.50; (buffer-modified-p) errors inside cl-letf
Date: Fri, 07 Aug 2015 00:50:45 +0200
Artur Malabarba <bruce.connor.am <at> gmail.com> writes:
> 2015-08-06 21:07 GMT+01:00 Nicolas Richard <youngfrog <at> members.fsf.org>:
>>  (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)))
>
> Don't know if it's possible, but shouldn't it try to ensure that it's
> in the same buffer as before?

I agree with you, but I don't know how to do that.




Merged 21201 29371. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Tue, 21 Nov 2017 01:57:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21201; Package emacs. (Tue, 17 Jul 2018 12:17:02 GMT) Full text and rfc822 format available.

Message #19 received at 21201 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Nicolas Richard <youngfrog <at> members.fsf.org>
Cc: 21201 <at> debbugs.gnu.org, Artur Malabarba <bruce.connor.am <at> gmail.com>
Subject: Re: bug#21201: 25.0.50; (buffer-modified-p) errors inside cl-letf
Date: Tue, 17 Jul 2018 08:16:09 -0400
[Message part 1 (text/plain, inline)]
tags 21201 + patch
quit

Nicolas Richard <youngfrog <at> members.fsf.org> writes:

> Artur Malabarba <bruce.connor.am <at> gmail.com> writes:
>> 2015-08-06 21:07 GMT+01:00 Nicolas Richard <youngfrog <at> members.fsf.org>:
>>>  (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)))
>>
>> Don't know if it's possible, but shouldn't it try to ensure that it's
>> in the same buffer as before?
>
> I agree with you, but I don't know how to do that.

This seems to work.

[0001-Allow-setf-of-buffer-modified-p-without-argument-Bug.patch (text/x-diff, inline)]
From 1481f8893ff04a83b578f403cd22c7bdd2ec65f0 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> gmail.com>
Date: Mon, 16 Jul 2018 22:14:32 -0400
Subject: [PATCH] Allow setf of buffer-modified-p without argument (Bug#21201)

* lisp/emacs-lisp/cl-lib.el (setf buffer-modified-p): Take current
buffer if optional argument BUF is not passed.
---
 lisp/emacs-lisp/cl-lib.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/emacs-lisp/cl-lib.el b/lisp/emacs-lisp/cl-lib.el
index 381784d1fd..ba5f9d64a1 100644
--- a/lisp/emacs-lisp/cl-lib.el
+++ b/lisp/emacs-lisp/cl-lib.el
@@ -521,8 +521,9 @@ cl-pairlis
 ;; 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)))
+  (macroexp-let2 nil buffer `(or ,buf (current-buffer))
+    `(with-current-buffer ,buffer
+       (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))))
-- 
2.11.0


Added tag(s) patch. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 17 Jul 2018 12:17:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21201; Package emacs. (Tue, 28 Aug 2018 00:02:02 GMT) Full text and rfc822 format available.

Message #24 received at 21201 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Nicolas Richard <youngfrog <at> members.fsf.org>
Cc: 21201 <at> debbugs.gnu.org, Artur Malabarba <bruce.connor.am <at> gmail.com>
Subject: Re: bug#21201: 25.0.50; (buffer-modified-p) errors inside cl-letf
Date: Mon, 27 Aug 2018 20:01:26 -0400
tags 21201 fixed
close 21201 27.1
quit

Noam Postavsky <npostavs <at> gmail.com> writes:

>  (gv-define-setter buffer-modified-p (flag &optional buf)
> -  `(with-current-buffer ,buf
> -     (set-buffer-modified-p ,flag)))
> +  (macroexp-let2 nil buffer `(or ,buf (current-buffer))
> +    `(with-current-buffer ,buffer
> +       (set-buffer-modified-p ,flag))))

Pushed to master.

[1: c8b86362d4]: 2018-08-27 18:54:23 -0400
  Allow setf of buffer-modified-p without argument (Bug#21201)
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=c8b86362d45a07e0aec0041cade551c3c663ea8c




Added tag(s) fixed. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 28 Aug 2018 00:02:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 27.1, send any further explanations to 21201 <at> debbugs.gnu.org and bruce.connor.am <at> gmail.com Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 28 Aug 2018 00:02:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 25 Sep 2018 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 6 years and 270 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.