GNU bug report logs -
#28412
26.0.50; Let save-some-buffers accept write-contents-functions
Previous Next
Reported by: Eric Abrahamsen <eric <at> ericabrahamsen.net>
Date: Sun, 10 Sep 2017 21:52:02 UTC
Severity: wishlist
Found in version 26.0.50
Done: Eric Abrahamsen <eric <at> ericabrahamsen.net>
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 28412 in the body.
You can then email your comments to 28412 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#28412
; Package
emacs
.
(Sun, 10 Sep 2017 21:52:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Eric Abrahamsen <eric <at> ericabrahamsen.net>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Sun, 10 Sep 2017 21:52:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
This is about letting `save-some-buffers' check
`write-contents-functions' before insisting on a buffer having a file to
write to.
There was a conversations about this on emacs.devel:
https://lists.gnu.org/archive/html/emacs-devel/2017-05/msg00653.html
The patch I ended up with is attached.
I'm reporting this just so the patch (and the idea) doesn't get lost. I
still think it's worth doing.
[0001-First-whack-at-write-contents-functions-for-non-file.patch (text/x-diff, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#28412
; Package
emacs
.
(Sun, 10 Sep 2017 22:03:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 28412 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Damn, I think that was the wrong patch.
Here's the latest one.
[0001-Allow-write-contents-functions-to-short-circuit-buff.patch (text/x-diff, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#28412
; Package
emacs
.
(Mon, 11 Sep 2017 15:04:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 28412 <at> debbugs.gnu.org (full text, mbox):
> Resent-Sender: help-debbugs <at> gnu.org
> From: Eric Abrahamsen <eric <at> ericabrahamsen.net>
> Date: Sun, 10 Sep 2017 15:01:34 -0700
>
> Here's the latest one.
Thanks. Can we have some simple tests for this, both with and without
visiting a file?
This also needs a NEWS entry. And please mention the bug number in
the log message.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#28412
; Package
emacs
.
(Mon, 11 Sep 2017 21:43:01 GMT)
Full text and
rfc822 format available.
Message #14 received at 28412 <at> debbugs.gnu.org (full text, mbox):
> Thanks. Can we have some simple tests for this, both with and without
> visiting a file?
Is this sufficient, do you think?
(ert-deftest files-test-no-file-write-contents ()
"Test that `write-contents-functions' permits saving a file.
Usually `basic-save-buffer' will prompt for a file name if the
current buffer has none. It should first call the functions in
`write-contents-functions', and if one of them returns non-nil,
consider the buffer saved, without prompting for a file
name (Bug#28412)."
(let ((read-file-name-function
(lambda (&rest _ignore)
(error "Prompting for file name"))))
;; With contents function, and no file.
(with-temp-buffer
(setq write-contents-functions
(list (lambda () t)))
(set-buffer-modified-p t)
(should (null (save-buffer))))
;; With no contents function and no file. This should reach the
;; `read-file-name' prompt.
(with-temp-buffer
(set-buffer-modified-p t)
(should-error (save-buffer) :type 'error))
;; Then a buffer visiting a file: should save normally.
(files-tests--with-temp-file temp-file-name
(with-current-buffer (find-file-noselect temp-file-name)
(setq write-contents-functions nil)
(insert "p")
(should (null (save-buffer)))
(should (eq (buffer-size) 1))))))
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#28412
; Package
emacs
.
(Tue, 12 Sep 2017 14:42:01 GMT)
Full text and
rfc822 format available.
Message #17 received at 28412 <at> debbugs.gnu.org (full text, mbox):
> From: Eric Abrahamsen <eric <at> ericabrahamsen.net>
> Cc: 28412 <at> debbugs.gnu.org
> Date: Mon, 11 Sep 2017 14:41:08 -0700
>
> > Thanks. Can we have some simple tests for this, both with and without
> > visiting a file?
>
> Is this sufficient, do you think?
Yes, I think so. Thanks.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#28412
; Package
emacs
.
(Tue, 12 Sep 2017 23:21:01 GMT)
Full text and
rfc822 format available.
Message #20 received at submit <at> debbugs.gnu.org (full text, mbox):
Eli Zaretskii <eliz <at> gnu.org> writes:
>> From: Eric Abrahamsen <eric <at> ericabrahamsen.net>
>> Cc: 28412 <at> debbugs.gnu.org
>> Date: Mon, 11 Sep 2017 14:41:08 -0700
>>
>> > Thanks. Can we have some simple tests for this, both with and without
>> > visiting a file?
>>
>> Is this sufficient, do you think?
>
> Yes, I think so. Thanks.
Okay, thank you. Pushed as 9b980e2691.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#28412
; Package
emacs
.
(Mon, 18 Sep 2017 16:17:01 GMT)
Full text and
rfc822 format available.
Message #23 received at 28412 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hello Eric, Eli:
I became a victim of this change because of these overlapping use-cases:
- I use ggtags.el that creates a hidden (is that the right term for that?)
buffer (starting with space) to fontify code snippets using the file's
major mode.
- The major mode I use (verilog-mode) sets write-file-functions to a
non-nil value.
So each time I quit emacs, I get a prompt to save that hidden buffer "
*Code-Fontify*" (which it didn't earlier, as intended).
Details: https://github.com/leoliu/ggtags/issues/157
I suggested calling (set-buffer-modified-p nil) in that special buffer.
But is that the best way to fix this? Or should save-some-buffers never try
to save buffers whose names begin with space?
PS: Please CC me on the replies, else I won't get those.
--
Kaushal Modi
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#28412
; Package
emacs
.
(Mon, 18 Sep 2017 18:06:01 GMT)
Full text and
rfc822 format available.
Message #26 received at 28412 <at> debbugs.gnu.org (full text, mbox):
> From: Kaushal Modi <kaushal.modi <at> gmail.com>
> Date: Mon, 18 Sep 2017 16:16:05 +0000
>
> - I use ggtags.el that creates a hidden (is that the right term for that?) buffer (starting with space) to fontify
> code snippets using the file's major mode.
> - The major mode I use (verilog-mode) sets write-file-functions to a non-nil value.
>
> So each time I quit emacs, I get a prompt to save that hidden buffer " *Code-Fontify*" (which it didn't earlier, as
> intended).
>
> Details: https://github.com/leoliu/ggtags/issues/157
>
> I suggested calling (set-buffer-modified-p nil) in that special buffer.
>
> But is that the best way to fix this? Or should save-some-buffers never try to save buffers whose names begin
> with space?
Exempting buffers whose name starts with a space sounds reasonable.
Eric?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#28412
; Package
emacs
.
(Mon, 18 Sep 2017 18:15:02 GMT)
Full text and
rfc822 format available.
Message #29 received at 28412 <at> debbugs.gnu.org (full text, mbox):
Eli Zaretskii <eliz <at> gnu.org> writes:
>> From: Kaushal Modi <kaushal.modi <at> gmail.com>
>> Date: Mon, 18 Sep 2017 16:16:05 +0000
>>
>> - I use ggtags.el that creates a hidden (is that the right term for that?) buffer (starting with space) to fontify
>> code snippets using the file's major mode.
>> - The major mode I use (verilog-mode) sets write-file-functions to a non-nil value.
>>
>> So each time I quit emacs, I get a prompt to save that hidden buffer " *Code-Fontify*" (which it didn't earlier, as
>> intended).
>>
>> Details: https://github.com/leoliu/ggtags/issues/157
>>
>> I suggested calling (set-buffer-modified-p nil) in that special buffer.
>>
>> But is that the best way to fix this? Or should save-some-buffers never try to save buffers whose names begin
>> with space?
>
> Exempting buffers whose name starts with a space sounds reasonable.
> Eric?
Sounds fine to me. I'm trying to think if there's some more general
interactive-vs-non-interactive case that should be protected against,
but I can't really come up with anything. The whole point of
`save-some-buffers' is the user prompt, and this seems like a fine way
to create an exception to the prompt.
I can fix it up -- the patch should go to emacs-26, right?
Eric
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#28412
; Package
emacs
.
(Mon, 18 Sep 2017 19:13:01 GMT)
Full text and
rfc822 format available.
Message #32 received at 28412 <at> debbugs.gnu.org (full text, mbox):
Eli Zaretskii <eliz <at> gnu.org> writes:
>> From: Kaushal Modi <kaushal.modi <at> gmail.com>
>> Date: Mon, 18 Sep 2017 16:16:05 +0000
>>
>> - I use ggtags.el that creates a hidden (is that the right term for that?) buffer (starting with space) to fontify
>> code snippets using the file's major mode.
>> - The major mode I use (verilog-mode) sets write-file-functions to a non-nil value.
>>
>> So each time I quit emacs, I get a prompt to save that hidden buffer " *Code-Fontify*" (which it didn't earlier, as
>> intended).
>>
>> Details: https://github.com/leoliu/ggtags/issues/157
>>
>> I suggested calling (set-buffer-modified-p nil) in that special buffer.
>>
>> But is that the best way to fix this? Or should save-some-buffers never try to save buffers whose names begin
>> with space?
>
> Exempting buffers whose name starts with a space sounds reasonable.
> Eric?
Also, there don't appear to be any built-in functions or regexps for
dealing with "hidden" buffers, I'm assuming:
(not (string-prefix-p " " (buffer-name buffer)))
is okay?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#28412
; Package
emacs
.
(Mon, 18 Sep 2017 19:24:02 GMT)
Full text and
rfc822 format available.
Message #35 received at 28412 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On Mon, Sep 18, 2017 at 3:12 PM Eric Abrahamsen <eric <at> ericabrahamsen.net>
wrote:
> Also, there don't appear to be any built-in functions or regexps for
> dealing with "hidden" buffers, I'm assuming:
>
> (not (string-prefix-p " " (buffer-name buffer)))
>
> is okay?
>
That crossed my mind too. So I had started looking for its existing
implementation, and found this in buff-menu.el inside list-buffers--refresh
function:
(string= (substring name 0 1) " ")
I was wondering if that should be wrapped into a function like
buffer-internal-p (based on the many docstrings like below in buff-menu.el:
"By default, the Buffer Menu lists all buffers except those whose names
start with a space (which are for internal use)."). Having a function like
this would be better than having that logic implemented in different ways
in the emacs core.
I just don't know the best place to put this function definition. Eli?
--
Kaushal Modi
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#28412
; Package
emacs
.
(Mon, 18 Sep 2017 19:27:01 GMT)
Full text and
rfc822 format available.
Message #38 received at 28412 <at> debbugs.gnu.org (full text, mbox):
> From: Eric Abrahamsen <eric <at> ericabrahamsen.net>
> Cc: Kaushal Modi <kaushal.modi <at> gmail.com>, 28412 <at> debbugs.gnu.org
> Date: Mon, 18 Sep 2017 11:14:35 -0700
>
> I can fix it up -- the patch should go to emacs-26, right?
Yes, thanks. Don't forget to mention the exception in the docs.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#28412
; Package
emacs
.
(Mon, 18 Sep 2017 19:30:02 GMT)
Full text and
rfc822 format available.
Message #41 received at 28412 <at> debbugs.gnu.org (full text, mbox):
> From: Eric Abrahamsen <eric <at> ericabrahamsen.net>
> Cc: Kaushal Modi <kaushal.modi <at> gmail.com>, 28412 <at> debbugs.gnu.org
> Date: Mon, 18 Sep 2017 12:12:01 -0700
>
> Also, there don't appear to be any built-in functions or regexps for
> dealing with "hidden" buffers, I'm assuming:
>
> (not (string-prefix-p " " (buffer-name buffer)))
>
> is okay?
Yes, but I think aref would be simpler (and probably faster).
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#28412
; Package
emacs
.
(Mon, 18 Sep 2017 20:31:01 GMT)
Full text and
rfc822 format available.
Message #44 received at 28412 <at> debbugs.gnu.org (full text, mbox):
On 09/18/17 22:25 PM, Eli Zaretskii wrote:
>> From: Eric Abrahamsen <eric <at> ericabrahamsen.net>
>> Cc: Kaushal Modi <kaushal.modi <at> gmail.com>, 28412 <at> debbugs.gnu.org
>> Date: Mon, 18 Sep 2017 11:14:35 -0700
>>
>> I can fix it up -- the patch should go to emacs-26, right?
>
> Yes, thanks. Don't forget to mention the exception in the docs.
Okay, done.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#28412
; Package
emacs
.
(Mon, 18 Sep 2017 20:54:02 GMT)
Full text and
rfc822 format available.
Message #47 received at 28412 <at> debbugs.gnu.org (full text, mbox):
Kaushal Modi <kaushal.modi <at> gmail.com> writes:
> On Mon, Sep 18, 2017 at 3:12 PM Eric Abrahamsen <eric <at> ericabrahamsen.net> wrote:
>
> Also, there don't appear to be any built-in functions or regexps for
> dealing with "hidden" buffers, I'm assuming:
>
> (not (string-prefix-p " " (buffer-name buffer)))
>
> is okay?
>
> That crossed my mind too. So I had started looking for its existing implementation, and found this in buff-menu.el inside list-buffers--refresh function:
>
> (string= (substring name 0 1) " ")
>
> I was wondering if that should be wrapped into a function like buffer-internal-p (based on the many docstrings like below in buff-menu.el: "By default, the Buffer Menu lists all buffers except those whose names start with a space
> (which are for internal use)."). Having a function like this would be better than having that logic implemented in different ways in the emacs core.
>
> I just don't know the best place to put this function definition. Eli?
It might be nice to have something like:
(defsubst buffer-internal-p (buf)
(eq (aref (buffer-name buf) 0) ?\s))
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#28412
; Package
emacs
.
(Mon, 18 Sep 2017 21:49:01 GMT)
Full text and
rfc822 format available.
Message #50 received at 28412 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On Mon, Sep 18, 2017 at 4:53 PM Eric Abrahamsen <eric <at> ericabrahamsen.net>
wrote:
>
> It might be nice to have something like:
>
> (defsubst buffer-internal-p (buf)
> (eq (aref (buffer-name buf) 0) ?\s))
>
Yup. I also see this in the "(emacs) Undo" Info node:
Some specialized buffers do not make undo records. Buffers whose
names start with spaces never do; these buffers are used internally by
Emacs to hold text that users don’t normally look at or edit.
But I cannot find the code that implements that.
It would be nice to have these places to use the same defsubst.
Btw I confirm the fix. Thanks!
--
Kaushal Modi
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#28412
; Package
emacs
.
(Tue, 19 Sep 2017 16:11:02 GMT)
Full text and
rfc822 format available.
Message #53 received at 28412 <at> debbugs.gnu.org (full text, mbox):
> From: Kaushal Modi <kaushal.modi <at> gmail.com>
> Date: Mon, 18 Sep 2017 19:23:10 +0000
> Cc: 28412 <at> debbugs.gnu.org
>
> (string= (substring name 0 1) " ")
>
> I was wondering if that should be wrapped into a function like buffer-internal-p (based on the many docstrings
> like below in buff-menu.el: "By default, the Buffer Menu lists all buffers except those whose names start with a
> space (which are for internal use)."). Having a function like this would be better than having that logic
> implemented in different ways in the emacs core.
>
> I just don't know the best place to put this function definition. Eli?
I'm not sure such a simple test should be canonicalized.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#28412
; Package
emacs
.
(Tue, 19 Sep 2017 16:14:01 GMT)
Full text and
rfc822 format available.
Message #56 received at 28412 <at> debbugs.gnu.org (full text, mbox):
> From: Kaushal Modi <kaushal.modi <at> gmail.com>
> Date: Mon, 18 Sep 2017 21:48:15 +0000
> Cc: Eli Zaretskii <eliz <at> gnu.org>, 28412 <at> debbugs.gnu.org
>
> Yup. I also see this in the "(emacs) Undo" Info node:
>
> Some specialized buffers do not make undo records. Buffers whose
> names start with spaces never do; these buffers are used internally by
> Emacs to hold text that users don’t normally look at or edit.
>
> But I cannot find the code that implements that.
It's in get-buffer-create:
bset_undo_list (b, SREF (name, 0) != ' ' ? Qnil : Qt);
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#28412
; Package
emacs
.
(Mon, 25 Sep 2017 14:47:02 GMT)
Full text and
rfc822 format available.
Message #59 received at 28412 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
To close the loop:
A better fix (I confirm this iteration of the fix too -- fix for the ggtags
issue[3]) for this was later applied in commit 3d3778d8[1]. See this
emacs-devel thread[2] for discussion that arrived to this conclusion.
[1]:
http://git.savannah.gnu.org/cgit/emacs.git/commit/?h=emacs-26&id=3d3778d82a87139ef50a24146f5bad2a57a82094
[2]: http://lists.gnu.org/archive/html/emacs-devel/2017-09/msg00858.html
[3]: https://github.com/leoliu/ggtags/issues/157
--
Kaushal Modi
[Message part 2 (text/html, inline)]
Reply sent
to
Eric Abrahamsen <eric <at> ericabrahamsen.net>
:
You have taken responsibility.
(Thu, 19 Oct 2017 15:27:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Eric Abrahamsen <eric <at> ericabrahamsen.net>
:
bug acknowledged by developer.
(Thu, 19 Oct 2017 15:27:02 GMT)
Full text and
rfc822 format available.
Message #64 received at 28412-done <at> debbugs.gnu.org (full text, mbox):
closing
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Fri, 17 Nov 2017 12:24:04 GMT)
Full text and
rfc822 format available.
This bug report was last modified 7 years and 294 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.