diff options
| author | Matthew White <mehw.is.me@inventati.org> | 2021-08-24 02:30:17 +0000 |
|---|---|---|
| committer | Matthew White <mehw.is.me@inventati.org> | 2021-10-20 23:23:31 +0200 |
| commit | 34c9f6aaa0942795d5b50b67ad8842ac57e2b02f (patch) | |
| tree | a9d85146d9808401c94db248641ca5a4659ecd99 | |
| parent | fddaba1fa61b832305d57607f9f827d09b05a773 (diff) | |
make-persp, persp-activate: force update current-buffer
Before executing BODY, 'make-persp' saves the current buffer, and then
restores it after. Hence, if the 'current-buffer' is changed in BODY,
that change is lost. Notify this in the docstring.
Force 'persp-activate' to update the current buffer with the buffer in
the current window.
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | perspective.el | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 099c492..d830157 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,11 +44,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed +- `make-persp`: document that executing BODY saves/restores the `current-buffer`. - `persp-set-buffer`: follow the coding style of `persp-add-buffer`. ### Fixed +- `persp-activate`: force update the `current-buffer` to the current window's buffer due to `make-persp` saving/restoring the `current-buffer` when executing it's BODY. This properly updates the `current-buffer` to what should be the real current buffer when switching to a new perspective. - `persp-add-buffer`: discard unexisting buffer as argument. - Added a workaround for potential problems caused by recursive minibuffer use. diff --git a/perspective.el b/perspective.el index 69e2b19..3eb6374 100644 --- a/perspective.el +++ b/perspective.el @@ -428,7 +428,12 @@ ARGS will be interpreted by `format-message'." ARGS is a list of keyword arguments followed by an optional BODY. The keyword arguments set the fields of the perspective struct. If BODY is given, it is executed to set the window configuration -for the perspective." +for the perspective. + +Save point, and current buffer before executing BODY, and then +restore them after. If the current buffer is changed in BODY, +that change is lost when getting out, hence the current buffer +will need to be changed again after calling `make-persp'." (declare (indent defun)) (let ((keywords)) (while (keywordp (car args)) @@ -442,6 +447,9 @@ for the perspective." ,(when args ;; Body form given `(save-excursion ,@args)) + ;; If the `current-buffer' changes while in `save-excursion', + ;; that change isn't kept when getting out, since the current + ;; buffer is saved before executing BODY and restored after. (run-hooks 'persp-created-hook)) persp))) @@ -714,6 +722,8 @@ If NORECORD is non-nil, do not update the (when (marker-position (persp-point-marker persp)) (goto-char (persp-point-marker persp))) (persp-update-modestring) + ;; force update of `current-buffer' + (set-buffer (window-buffer)) (run-hooks 'persp-activated-hook)) (defun persp-switch-quick (char) |
