* bug#28412: 26.0.50; Let save-some-buffers accept write-contents-functions
@ 2017-09-10 21:50 Eric Abrahamsen
[not found] ` <handler.28412.B.15050803219580.ack@debbugs.gnu.org>
2017-09-18 16:16 ` bug#28412: 26.0.50; Let save-some-buffers accept write-contents-functions Kaushal Modi
0 siblings, 2 replies; 20+ messages in thread
From: Eric Abrahamsen @ 2017-09-10 21:50 UTC (permalink / raw)
To: 28412
[-- Attachment #1: Type: text/plain, Size: 400 bytes --]
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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-First-whack-at-write-contents-functions-for-non-file.patch --]
[-- Type: text/x-diff, Size: 7052 bytes --]
From af4f811439785113fe2be71f499006776958755b Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Thu, 25 May 2017 15:28:19 +0800
Subject: [PATCH] First whack at write-contents-functions for non-file buffers
---
lisp/files.el | 106 +++++++++++++++++++++++++++++++---------------------------
1 file changed, 56 insertions(+), 50 deletions(-)
diff --git a/lisp/files.el b/lisp/files.el
index 8ac1993754..c074fa7995 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -4943,29 +4943,14 @@ basic-save-buffer
(if (buffer-base-buffer)
(set-buffer (buffer-base-buffer)))
(if (or (buffer-modified-p)
- ;; handle the case when no modification has been made but
- ;; the file disappeared since visited
+ ;; Handle the case when no modification has been made but
+ ;; the file disappeared since visited.
(and buffer-file-name
(not (file-exists-p buffer-file-name))))
(let ((recent-save (recent-auto-save-p))
setmodes)
- ;; If buffer has no file name, ask user for one.
- (or buffer-file-name
- (let ((filename
- (expand-file-name
- (read-file-name "File to save in: "
- nil (expand-file-name (buffer-name))))))
- (if (file-exists-p filename)
- (if (file-directory-p filename)
- ;; Signal an error if the user specified the name of an
- ;; existing directory.
- (error "%s is a directory" filename)
- (unless (y-or-n-p (format-message
- "File `%s' exists; overwrite? "
- filename))
- (error "Canceled"))))
- (set-visited-file-name filename)))
- (or (verify-visited-file-modtime (current-buffer))
+ (or (null buffer-file-name)
+ (verify-visited-file-modtime (current-buffer))
(not (file-exists-p buffer-file-name))
(yes-or-no-p
(format
@@ -4977,6 +4962,7 @@ basic-save-buffer
(save-excursion
(and (> (point-max) (point-min))
(not find-file-literally)
+ (null buffer-read-only)
(/= (char-after (1- (point-max))) ?\n)
(not (and (eq selective-display t)
(= (char-after (1- (point-max))) ?\r)))
@@ -4989,41 +4975,60 @@ basic-save-buffer
(save-excursion
(goto-char (point-max))
(insert ?\n))))
- ;; Support VC version backups.
- (vc-before-save)
;; Don't let errors prevent saving the buffer.
(with-demoted-errors (run-hooks 'before-save-hook))
- (or (run-hook-with-args-until-success 'write-contents-functions)
- (run-hook-with-args-until-success 'local-write-file-hooks)
- (run-hook-with-args-until-success 'write-file-functions)
- ;; If a hook returned t, file is already "written".
- ;; Otherwise, write it the usual way now.
- (let ((dir (file-name-directory
- (expand-file-name buffer-file-name))))
- (unless (file-exists-p dir)
- (if (y-or-n-p
- (format-message
- "Directory `%s' does not exist; create? " dir))
- (make-directory dir t)
- (error "Canceled")))
- (setq setmodes (basic-save-buffer-1))))
+ ;; Give `write-contents-functions' a chance to
+ ;; short-circuit the whole process.
+ (unless (run-hook-with-args-until-success 'write-contents-functions)
+ ;; If buffer has no file name, ask user for one.
+ (or buffer-file-name
+ (let ((filename
+ (expand-file-name
+ (read-file-name "File to save in: "
+ nil (expand-file-name (buffer-name))))))
+ (if (file-exists-p filename)
+ (if (file-directory-p filename)
+ ;; Signal an error if the user specified the name of an
+ ;; existing directory.
+ (error "%s is a directory" filename)
+ (unless (y-or-n-p (format-message
+ "File `%s' exists; overwrite? "
+ filename))
+ (error "Canceled"))))
+ (set-visited-file-name filename)))
+ ;; Support VC version backups.
+ (vc-before-save)
+ (or (run-hook-with-args-until-success 'local-write-file-hooks)
+ (run-hook-with-args-until-success 'write-file-functions)
+ ;; If a hook returned t, file is already "written".
+ ;; Otherwise, write it the usual way now.
+ (let ((dir (file-name-directory
+ (expand-file-name buffer-file-name))))
+ (unless (file-exists-p dir)
+ (if (y-or-n-p
+ (format-message
+ "Directory `%s' does not exist; create? " dir))
+ (make-directory dir t)
+ (error "Canceled")))
+ (setq setmodes (basic-save-buffer-1)))))
;; Now we have saved the current buffer. Let's make sure
;; that buffer-file-coding-system is fixed to what
;; actually used for saving by binding it locally.
- (if save-buffer-coding-system
- (setq save-buffer-coding-system last-coding-system-used)
- (setq buffer-file-coding-system last-coding-system-used))
- (setq buffer-file-number
- (nthcdr 10 (file-attributes buffer-file-name)))
- (if setmodes
- (condition-case ()
- (progn
- (unless
- (with-demoted-errors
- (set-file-modes buffer-file-name (car setmodes)))
- (set-file-extended-attributes buffer-file-name
- (nth 1 setmodes))))
- (error nil))))
+ (when buffer-file-name
+ (if save-buffer-coding-system
+ (setq save-buffer-coding-system last-coding-system-used)
+ (setq buffer-file-coding-system last-coding-system-used))
+ (setq buffer-file-number
+ (nthcdr 10 (file-attributes buffer-file-name)))
+ (if setmodes
+ (condition-case ()
+ (progn
+ (unless
+ (with-demoted-errors
+ (set-file-modes buffer-file-name (car setmodes)))
+ (set-file-extended-attributes buffer-file-name
+ (nth 1 setmodes))))
+ (error nil)))))
;; If the auto-save file was recent before this command,
;; delete it now.
(delete-auto-save-file-if-necessary recent-save)
@@ -5255,7 +5260,8 @@ save-some-buffers
(and pred
(progn
(set-buffer buffer)
- (and buffer-offer-save (> (buffer-size) 0)))))
+ (and buffer-offer-save (> (buffer-size) 0))))
+ write-contents-functions)
(or (not (functionp pred))
(with-current-buffer buffer (funcall pred)))
(if arg
--
2.13.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* bug#28412: Acknowledgement (26.0.50; Let save-some-buffers accept write-contents-functions)
[not found] ` <handler.28412.B.15050803219580.ack@debbugs.gnu.org>
@ 2017-09-10 22:01 ` Eric Abrahamsen
2017-09-11 15:03 ` Eli Zaretskii
0 siblings, 1 reply; 20+ messages in thread
From: Eric Abrahamsen @ 2017-09-10 22:01 UTC (permalink / raw)
To: 28412
[-- Attachment #1: Type: text/plain, Size: 65 bytes --]
Damn, I think that was the wrong patch.
Here's the latest one.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-write-contents-functions-to-short-circuit-buff.patch --]
[-- Type: text/x-diff, Size: 11183 bytes --]
From 7b5f18648e3d4b2aa9a5af536a624d6518d8fdd7 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Thu, 25 May 2017 15:28:19 +0800
Subject: [PATCH] Allow write-contents-functions to short-circuit buffer saving
* lisp/files.el (basic-save-buffer): If write-contents-functions is
non-nil, give the functions in that hook a chance to save buffer
contents before checking if buffer is visiting a file.
(save-some-buffers): If write-contents-functions is non nil,
consider the buffer eligible for a save prompt.
* doc/lispref/files.texi (Saving Buffers): Mention new behavior, note
that special-mode buffers can use this to "save" themselves.
---
doc/lispref/files.texi | 18 +++++--
lisp/files.el | 136 +++++++++++++++++++++++++++----------------------
2 files changed, 87 insertions(+), 67 deletions(-)
diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi
index 2b692dbf68..a6ee0cc69c 100644
--- a/doc/lispref/files.texi
+++ b/doc/lispref/files.texi
@@ -457,15 +457,23 @@ Saving Buffers
@defvar write-contents-functions
This works just like @code{write-file-functions}, but it is intended
for hooks that pertain to the buffer's contents, not to the particular
-visited file or its location. Such hooks are usually set up by major
-modes, as buffer-local bindings for this variable. This variable
-automatically becomes buffer-local whenever it is set; switching to a
-new major mode always resets this variable, but calling
-@code{set-visited-file-name} does not.
+visited file or its location, and can be used to create arbitrary save
+processes for buffers that aren't visiting files at all. Such hooks
+are usually set up by major modes, as buffer-local bindings for this
+variable. This variable automatically becomes buffer-local whenever
+it is set; switching to a new major mode always resets this variable,
+but calling @code{set-visited-file-name} does not.
If any of the functions in this hook returns non-@code{nil}, the file
is considered already written and the rest are not called and neither
are the functions in @code{write-file-functions}.
+
+When using this hook to save buffers that are not visiting files (for
+instance, special-mode buffers), keep in mind that, if the function
+fails to save correctly and returns a @code{nil} value,
+@code{save-buffer} will go on to prompt the user for a file to save
+the buffer in. If this is undesirable, consider having the function
+fail by raising an error.
@end defvar
@defopt before-save-hook
diff --git a/lisp/files.el b/lisp/files.el
index 8ac1993754..1f88f86b76 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -514,10 +514,12 @@ 'write-contents-hooks
'write-contents-functions "22.1")
(defvar write-contents-functions nil
"List of functions to be called before writing out a buffer to a file.
-Only used by `save-buffer'.
-If one of them returns non-nil, the file is considered already written
-and the rest are not called and neither are the functions in
-`write-file-functions'.
+
+Only used by `save-buffer'. If one of them returns non-nil, the
+file is considered already written and the rest are not called
+and neither are the functions in `write-file-functions'. This
+hook can thus be used to create save behavior for buffers that
+are not visiting a file at all.
This variable is meant to be used for hooks that pertain to the
buffer's contents, not to the particular visited file; thus,
@@ -4932,9 +4934,12 @@ save-buffer-coding-system
(defun basic-save-buffer (&optional called-interactively)
"Save the current buffer in its visited file, if it has been modified.
-The hooks `write-contents-functions' and `write-file-functions' get a chance
-to do the job of saving; if they do not, then the buffer is saved in
-the visited file in the usual way.
+
+The hooks `write-contents-functions', `local-write-file-hooks'
+and `write-file-functions' get a chance to do the job of saving;
+if they do not, then the buffer is saved in the visited file in
+the usual way.
+
Before and after saving the buffer, this function runs
`before-save-hook' and `after-save-hook', respectively."
(interactive '(called-interactively))
@@ -4943,29 +4948,14 @@ basic-save-buffer
(if (buffer-base-buffer)
(set-buffer (buffer-base-buffer)))
(if (or (buffer-modified-p)
- ;; handle the case when no modification has been made but
- ;; the file disappeared since visited
+ ;; Handle the case when no modification has been made but
+ ;; the file disappeared since visited.
(and buffer-file-name
(not (file-exists-p buffer-file-name))))
(let ((recent-save (recent-auto-save-p))
setmodes)
- ;; If buffer has no file name, ask user for one.
- (or buffer-file-name
- (let ((filename
- (expand-file-name
- (read-file-name "File to save in: "
- nil (expand-file-name (buffer-name))))))
- (if (file-exists-p filename)
- (if (file-directory-p filename)
- ;; Signal an error if the user specified the name of an
- ;; existing directory.
- (error "%s is a directory" filename)
- (unless (y-or-n-p (format-message
- "File `%s' exists; overwrite? "
- filename))
- (error "Canceled"))))
- (set-visited-file-name filename)))
- (or (verify-visited-file-modtime (current-buffer))
+ (or (null buffer-file-name)
+ (verify-visited-file-modtime (current-buffer))
(not (file-exists-p buffer-file-name))
(yes-or-no-p
(format
@@ -4977,6 +4967,7 @@ basic-save-buffer
(save-excursion
(and (> (point-max) (point-min))
(not find-file-literally)
+ (null buffer-read-only)
(/= (char-after (1- (point-max))) ?\n)
(not (and (eq selective-display t)
(= (char-after (1- (point-max))) ?\r)))
@@ -4989,46 +4980,65 @@ basic-save-buffer
(save-excursion
(goto-char (point-max))
(insert ?\n))))
- ;; Support VC version backups.
- (vc-before-save)
;; Don't let errors prevent saving the buffer.
(with-demoted-errors (run-hooks 'before-save-hook))
- (or (run-hook-with-args-until-success 'write-contents-functions)
- (run-hook-with-args-until-success 'local-write-file-hooks)
- (run-hook-with-args-until-success 'write-file-functions)
- ;; If a hook returned t, file is already "written".
- ;; Otherwise, write it the usual way now.
- (let ((dir (file-name-directory
- (expand-file-name buffer-file-name))))
- (unless (file-exists-p dir)
- (if (y-or-n-p
- (format-message
- "Directory `%s' does not exist; create? " dir))
- (make-directory dir t)
- (error "Canceled")))
- (setq setmodes (basic-save-buffer-1))))
+ ;; Give `write-contents-functions' a chance to
+ ;; short-circuit the whole process.
+ (unless (run-hook-with-args-until-success 'write-contents-functions)
+ ;; If buffer has no file name, ask user for one.
+ (or buffer-file-name
+ (let ((filename
+ (expand-file-name
+ (read-file-name "File to save in: "
+ nil (expand-file-name (buffer-name))))))
+ (if (file-exists-p filename)
+ (if (file-directory-p filename)
+ ;; Signal an error if the user specified the name of an
+ ;; existing directory.
+ (error "%s is a directory" filename)
+ (unless (y-or-n-p (format-message
+ "File `%s' exists; overwrite? "
+ filename))
+ (error "Canceled"))))
+ (set-visited-file-name filename)))
+ ;; Support VC version backups.
+ (vc-before-save)
+ (or (run-hook-with-args-until-success 'local-write-file-hooks)
+ (run-hook-with-args-until-success 'write-file-functions)
+ ;; If a hook returned t, file is already "written".
+ ;; Otherwise, write it the usual way now.
+ (let ((dir (file-name-directory
+ (expand-file-name buffer-file-name))))
+ (unless (file-exists-p dir)
+ (if (y-or-n-p
+ (format-message
+ "Directory `%s' does not exist; create? " dir))
+ (make-directory dir t)
+ (error "Canceled")))
+ (setq setmodes (basic-save-buffer-1)))))
;; Now we have saved the current buffer. Let's make sure
;; that buffer-file-coding-system is fixed to what
;; actually used for saving by binding it locally.
- (if save-buffer-coding-system
- (setq save-buffer-coding-system last-coding-system-used)
- (setq buffer-file-coding-system last-coding-system-used))
- (setq buffer-file-number
- (nthcdr 10 (file-attributes buffer-file-name)))
- (if setmodes
- (condition-case ()
- (progn
- (unless
- (with-demoted-errors
- (set-file-modes buffer-file-name (car setmodes)))
- (set-file-extended-attributes buffer-file-name
- (nth 1 setmodes))))
- (error nil))))
- ;; If the auto-save file was recent before this command,
- ;; delete it now.
- (delete-auto-save-file-if-necessary recent-save)
- ;; Support VC `implicit' locking.
- (vc-after-save)
+ (when buffer-file-name
+ (if save-buffer-coding-system
+ (setq save-buffer-coding-system last-coding-system-used)
+ (setq buffer-file-coding-system last-coding-system-used))
+ (setq buffer-file-number
+ (nthcdr 10 (file-attributes buffer-file-name)))
+ (if setmodes
+ (condition-case ()
+ (progn
+ (unless
+ (with-demoted-errors
+ (set-file-modes buffer-file-name (car setmodes)))
+ (set-file-extended-attributes buffer-file-name
+ (nth 1 setmodes))))
+ (error nil)))
+ ;; Support VC `implicit' locking.
+ (vc-after-save))
+ ;; If the auto-save file was recent before this command,
+ ;; delete it now.
+ (delete-auto-save-file-if-necessary recent-save))
(run-hooks 'after-save-hook))
(or noninteractive
(not called-interactively)
@@ -5255,7 +5265,9 @@ save-some-buffers
(and pred
(progn
(set-buffer buffer)
- (and buffer-offer-save (> (buffer-size) 0)))))
+ (and buffer-offer-save (> (buffer-size) 0))))
+ (buffer-local-value
+ 'write-contents-functions buffer))
(or (not (functionp pred))
(with-current-buffer buffer (funcall pred)))
(if arg
--
2.13.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* bug#28412: Acknowledgement (26.0.50; Let save-some-buffers accept write-contents-functions)
2017-09-10 22:01 ` bug#28412: Acknowledgement (26.0.50; Let save-some-buffers accept write-contents-functions) Eric Abrahamsen
@ 2017-09-11 15:03 ` Eli Zaretskii
2017-09-11 21:41 ` Eric Abrahamsen
0 siblings, 1 reply; 20+ messages in thread
From: Eli Zaretskii @ 2017-09-11 15:03 UTC (permalink / raw)
To: Eric Abrahamsen; +Cc: 28412
> Resent-Sender: help-debbugs@gnu.org
> From: Eric Abrahamsen <eric@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.
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#28412: Acknowledgement (26.0.50; Let save-some-buffers accept write-contents-functions)
2017-09-11 15:03 ` Eli Zaretskii
@ 2017-09-11 21:41 ` Eric Abrahamsen
2017-09-12 14:41 ` Eli Zaretskii
0 siblings, 1 reply; 20+ messages in thread
From: Eric Abrahamsen @ 2017-09-11 21:41 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 28412
> 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))))))
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#28412: Acknowledgement (26.0.50; Let save-some-buffers accept write-contents-functions)
2017-09-11 21:41 ` Eric Abrahamsen
@ 2017-09-12 14:41 ` Eli Zaretskii
2017-09-12 23:18 ` Eric Abrahamsen
0 siblings, 1 reply; 20+ messages in thread
From: Eli Zaretskii @ 2017-09-12 14:41 UTC (permalink / raw)
To: Eric Abrahamsen; +Cc: 28412
> From: Eric Abrahamsen <eric@ericabrahamsen.net>
> Cc: 28412@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.
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#28412: Acknowledgement (26.0.50; Let save-some-buffers accept write-contents-functions)
2017-09-12 14:41 ` Eli Zaretskii
@ 2017-09-12 23:18 ` Eric Abrahamsen
0 siblings, 0 replies; 20+ messages in thread
From: Eric Abrahamsen @ 2017-09-12 23:18 UTC (permalink / raw)
To: 28412
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Eric Abrahamsen <eric@ericabrahamsen.net>
>> Cc: 28412@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.
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#28412: 26.0.50; Let save-some-buffers accept write-contents-functions
2017-09-10 21:50 bug#28412: 26.0.50; Let save-some-buffers accept write-contents-functions Eric Abrahamsen
[not found] ` <handler.28412.B.15050803219580.ack@debbugs.gnu.org>
@ 2017-09-18 16:16 ` Kaushal Modi
2017-09-18 18:04 ` Eli Zaretskii
1 sibling, 1 reply; 20+ messages in thread
From: Kaushal Modi @ 2017-09-18 16:16 UTC (permalink / raw)
To: 28412
[-- Attachment #1: Type: text/plain, Size: 789 bytes --]
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
[-- Attachment #2: Type: text/html, Size: 1235 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#28412: 26.0.50; Let save-some-buffers accept write-contents-functions
2017-09-18 16:16 ` bug#28412: 26.0.50; Let save-some-buffers accept write-contents-functions Kaushal Modi
@ 2017-09-18 18:04 ` Eli Zaretskii
2017-09-18 18:14 ` Eric Abrahamsen
2017-09-18 19:12 ` Eric Abrahamsen
0 siblings, 2 replies; 20+ messages in thread
From: Eli Zaretskii @ 2017-09-18 18:04 UTC (permalink / raw)
To: Kaushal Modi, Eric Abrahamsen; +Cc: 28412
> From: Kaushal Modi <kaushal.modi@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?
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#28412: 26.0.50; Let save-some-buffers accept write-contents-functions
2017-09-18 18:04 ` Eli Zaretskii
@ 2017-09-18 18:14 ` Eric Abrahamsen
2017-09-18 19:25 ` Eli Zaretskii
2017-09-18 19:12 ` Eric Abrahamsen
1 sibling, 1 reply; 20+ messages in thread
From: Eric Abrahamsen @ 2017-09-18 18:14 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 28412, Kaushal Modi
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Kaushal Modi <kaushal.modi@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
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#28412: 26.0.50; Let save-some-buffers accept write-contents-functions
2017-09-18 18:04 ` Eli Zaretskii
2017-09-18 18:14 ` Eric Abrahamsen
@ 2017-09-18 19:12 ` Eric Abrahamsen
2017-09-18 19:23 ` Kaushal Modi
2017-09-18 19:28 ` Eli Zaretskii
1 sibling, 2 replies; 20+ messages in thread
From: Eric Abrahamsen @ 2017-09-18 19:12 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 28412, Kaushal Modi
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Kaushal Modi <kaushal.modi@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?
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#28412: 26.0.50; Let save-some-buffers accept write-contents-functions
2017-09-18 19:12 ` Eric Abrahamsen
@ 2017-09-18 19:23 ` Kaushal Modi
2017-09-18 20:53 ` Eric Abrahamsen
2017-09-19 16:09 ` Eli Zaretskii
2017-09-18 19:28 ` Eli Zaretskii
1 sibling, 2 replies; 20+ messages in thread
From: Kaushal Modi @ 2017-09-18 19:23 UTC (permalink / raw)
To: Eric Abrahamsen, Eli Zaretskii; +Cc: 28412
[-- Attachment #1: Type: text/plain, Size: 933 bytes --]
On Mon, Sep 18, 2017 at 3:12 PM Eric Abrahamsen <eric@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
[-- Attachment #2: Type: text/html, Size: 1455 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#28412: 26.0.50; Let save-some-buffers accept write-contents-functions
2017-09-18 18:14 ` Eric Abrahamsen
@ 2017-09-18 19:25 ` Eli Zaretskii
2017-09-18 20:30 ` Eric Abrahamsen
0 siblings, 1 reply; 20+ messages in thread
From: Eli Zaretskii @ 2017-09-18 19:25 UTC (permalink / raw)
To: Eric Abrahamsen; +Cc: 28412, kaushal.modi
> From: Eric Abrahamsen <eric@ericabrahamsen.net>
> Cc: Kaushal Modi <kaushal.modi@gmail.com>, 28412@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.
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#28412: 26.0.50; Let save-some-buffers accept write-contents-functions
2017-09-18 19:12 ` Eric Abrahamsen
2017-09-18 19:23 ` Kaushal Modi
@ 2017-09-18 19:28 ` Eli Zaretskii
1 sibling, 0 replies; 20+ messages in thread
From: Eli Zaretskii @ 2017-09-18 19:28 UTC (permalink / raw)
To: Eric Abrahamsen; +Cc: 28412, kaushal.modi
> From: Eric Abrahamsen <eric@ericabrahamsen.net>
> Cc: Kaushal Modi <kaushal.modi@gmail.com>, 28412@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).
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#28412: 26.0.50; Let save-some-buffers accept write-contents-functions
2017-09-18 19:25 ` Eli Zaretskii
@ 2017-09-18 20:30 ` Eric Abrahamsen
0 siblings, 0 replies; 20+ messages in thread
From: Eric Abrahamsen @ 2017-09-18 20:30 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 28412, kaushal.modi
On 09/18/17 22:25 PM, Eli Zaretskii wrote:
>> From: Eric Abrahamsen <eric@ericabrahamsen.net>
>> Cc: Kaushal Modi <kaushal.modi@gmail.com>, 28412@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.
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#28412: 26.0.50; Let save-some-buffers accept write-contents-functions
2017-09-18 19:23 ` Kaushal Modi
@ 2017-09-18 20:53 ` Eric Abrahamsen
2017-09-18 21:48 ` Kaushal Modi
2017-09-19 16:09 ` Eli Zaretskii
1 sibling, 1 reply; 20+ messages in thread
From: Eric Abrahamsen @ 2017-09-18 20:53 UTC (permalink / raw)
To: Kaushal Modi; +Cc: 28412
Kaushal Modi <kaushal.modi@gmail.com> writes:
> On Mon, Sep 18, 2017 at 3:12 PM Eric Abrahamsen <eric@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))
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#28412: 26.0.50; Let save-some-buffers accept write-contents-functions
2017-09-18 20:53 ` Eric Abrahamsen
@ 2017-09-18 21:48 ` Kaushal Modi
2017-09-19 16:13 ` Eli Zaretskii
0 siblings, 1 reply; 20+ messages in thread
From: Kaushal Modi @ 2017-09-18 21:48 UTC (permalink / raw)
To: Eric Abrahamsen; +Cc: 28412
[-- Attachment #1: Type: text/plain, Size: 657 bytes --]
On Mon, Sep 18, 2017 at 4:53 PM Eric Abrahamsen <eric@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
[-- Attachment #2: Type: text/html, Size: 1163 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#28412: 26.0.50; Let save-some-buffers accept write-contents-functions
2017-09-18 19:23 ` Kaushal Modi
2017-09-18 20:53 ` Eric Abrahamsen
@ 2017-09-19 16:09 ` Eli Zaretskii
1 sibling, 0 replies; 20+ messages in thread
From: Eli Zaretskii @ 2017-09-19 16:09 UTC (permalink / raw)
To: Kaushal Modi; +Cc: eric, 28412
> From: Kaushal Modi <kaushal.modi@gmail.com>
> Date: Mon, 18 Sep 2017 19:23:10 +0000
> Cc: 28412@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.
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#28412: 26.0.50; Let save-some-buffers accept write-contents-functions
2017-09-18 21:48 ` Kaushal Modi
@ 2017-09-19 16:13 ` Eli Zaretskii
2017-09-25 14:46 ` Kaushal Modi
2017-10-19 15:25 ` Eric Abrahamsen
0 siblings, 2 replies; 20+ messages in thread
From: Eli Zaretskii @ 2017-09-19 16:13 UTC (permalink / raw)
To: Kaushal Modi; +Cc: eric, 28412
> From: Kaushal Modi <kaushal.modi@gmail.com>
> Date: Mon, 18 Sep 2017 21:48:15 +0000
> Cc: Eli Zaretskii <eliz@gnu.org>, 28412@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);
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#28412: 26.0.50; Let save-some-buffers accept write-contents-functions
2017-09-19 16:13 ` Eli Zaretskii
@ 2017-09-25 14:46 ` Kaushal Modi
2017-10-19 15:25 ` Eric Abrahamsen
1 sibling, 0 replies; 20+ messages in thread
From: Kaushal Modi @ 2017-09-25 14:46 UTC (permalink / raw)
To: 28412; +Cc: eric, Stefan Monnier
[-- Attachment #1: Type: text/plain, Size: 488 bytes --]
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
[-- Attachment #2: Type: text/html, Size: 972 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#28412: 26.0.50; Let save-some-buffers accept write-contents-functions
2017-09-19 16:13 ` Eli Zaretskii
2017-09-25 14:46 ` Kaushal Modi
@ 2017-10-19 15:25 ` Eric Abrahamsen
1 sibling, 0 replies; 20+ messages in thread
From: Eric Abrahamsen @ 2017-10-19 15:25 UTC (permalink / raw)
To: 28412-done
closing
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2017-10-19 15:25 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-10 21:50 bug#28412: 26.0.50; Let save-some-buffers accept write-contents-functions Eric Abrahamsen
[not found] ` <handler.28412.B.15050803219580.ack@debbugs.gnu.org>
2017-09-10 22:01 ` bug#28412: Acknowledgement (26.0.50; Let save-some-buffers accept write-contents-functions) Eric Abrahamsen
2017-09-11 15:03 ` Eli Zaretskii
2017-09-11 21:41 ` Eric Abrahamsen
2017-09-12 14:41 ` Eli Zaretskii
2017-09-12 23:18 ` Eric Abrahamsen
2017-09-18 16:16 ` bug#28412: 26.0.50; Let save-some-buffers accept write-contents-functions Kaushal Modi
2017-09-18 18:04 ` Eli Zaretskii
2017-09-18 18:14 ` Eric Abrahamsen
2017-09-18 19:25 ` Eli Zaretskii
2017-09-18 20:30 ` Eric Abrahamsen
2017-09-18 19:12 ` Eric Abrahamsen
2017-09-18 19:23 ` Kaushal Modi
2017-09-18 20:53 ` Eric Abrahamsen
2017-09-18 21:48 ` Kaushal Modi
2017-09-19 16:13 ` Eli Zaretskii
2017-09-25 14:46 ` Kaushal Modi
2017-10-19 15:25 ` Eric Abrahamsen
2017-09-19 16:09 ` Eli Zaretskii
2017-09-18 19:28 ` Eli Zaretskii
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).