Skip to content

[layouts] Fix error in switch-to-prev-buffer when persp-mode is excluded#17196

Open
bcc32 wants to merge 3 commits into
syl20bnr:developfrom
janestreet:fix-void-function-when-persp-mode-excluded
Open

[layouts] Fix error in switch-to-prev-buffer when persp-mode is excluded#17196
bcc32 wants to merge 3 commits into
syl20bnr:developfrom
janestreet:fix-void-function-when-persp-mode-excluded

Conversation

@bcc32

@bcc32 bcc32 commented Dec 19, 2025

Copy link
Copy Markdown
Collaborator

When the persp-mode package is excluded by
dotspacemacs-excluded-packages, and the spacemacs-layouts layer is
still enabled---as it is by default---the advice around functions
listed in spacemacs-layouts-restricted-functions can error, causing
the user to be unable to kill buffers, etc.

This PR just makes the advice check whether persp-contain-buffer-p
is actually defined before attempting to potentially call it around
buffer-list.

This PR also:

  1. Fixes up some outdated docstrings
  2. Removes a pointless private macro by just expanding it in the only
    callsite
  3. Fixes the customization :set function to avoid an unnecessary extra
    variable, and also correctly use set-default-toplevel-value to
    avoid issues if the variable is currently let-bound.

Use set-default-toplevel-value to match the default setter's behavior
w.r.t. let-binding.

Update the docstring to remove mention of the deleted macro.

Avoid an unnecessary extra variable to store the old value by simply
reading the variable before setting it.
@bcc32 bcc32 force-pushed the fix-void-function-when-persp-mode-excluded branch from cda97e3 to df900db Compare December 19, 2025 18:22
Comment on lines 89 to 98
:type '(repeat function)
:set (lambda (_ value)
(dolist (fn spacemacs--old-layouts-restricted-functions)
(advice-remove fn 'spacemacs-layouts//advice-with-persp-buffer-list))
(setq spacemacs--old-layouts-restricted-functions value
spacemacs-layouts-restricted-functions value)
(dolist (fn spacemacs-layouts-restricted-functions)
:set (lambda (var new-value)
(ignore-error void-variable
(let ((old-value (default-toplevel-value var)))
(dolist (fn old-value)
(advice-remove fn 'spacemacs-layouts//advice-with-persp-buffer-list))))
(set-default-toplevel-value var new-value)
(dolist (fn new-value)
(advice-add fn :around 'spacemacs-layouts//advice-with-persp-buffer-list))))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When reloading the configuration, the custom set function is run after the value is already set to the new-value (if the variable is set as a layer variable in dotspacemacs-configuration-layers). Hence in this case, with this change, the advice will not be removed correctly. (I should have added a comment here.)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's pretty confusing, but good catch. How about instead of trying to handle the case where the variable is set but the :setter isn't run, in the :setter---which seems really hard in the general case---we just make Spacemacs call the setter (if any) for layer variables set by :variables?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants