bug#81504: [PATCH] Restore current buffer after clone-indirect-buffer-hook errors
Sean Whitton <[email protected]> Thu, 30 Jul 2026 13:30:30 +0100
| Newsgroups | gmane.emacs.bugs |
|---|---|
| Message-ID | <[email protected]> |
Donjuanplatinum via "Bug reports for GNU Emacs, the Swiss army knife of text editors" [28/Jul 1:47am +08] wrote: > Version: 31.0.50 > Base-Commit: 810e9d675ba484dabade1a9f30201d2848c5e2ea > > In `make-indirect-buffer` with clone argument, if > `clone-indirect-buffer-hook` return an error, `current-buffer` will not > be restored. > > To make the error in emacs -Q: > > > (progn > (generate-new-buffer "base") > (with-current-buffer "base" (insert "text")) > (set-buffer "base") > (let ((clone-indirect-buffer-hook > (list (lambda () (error "hook error"))))) > (condition-case nil > (make-indirect-buffer "base" "ind" t) > (error nil))) > (buffer-name (current-buffer))) > > Expected: "base" > But get: "ind" > > The Clone path in Fmake_indirect_buffer use set_buffer_internal_1 to > restore the current-buffer, but when clone-indirect-buffer-hook return > an error, it will skip the set_buffer_internal_1. > > The attached patch replaces it with record_unwind_current_buffer so that > it will following the standard specpdl pattern to restore the current-buffer. Should we be restoring the current buffer here? I'm not sure there is any particular reason why we should, and calling code can always use with-current-buffer or save-current-buffer if it needs to ensure that it's restored? -- Sean Whitton