persp-mode.el icon indicating copy to clipboard operation
persp-mode.el copied to clipboard

Persp-mode automatically save buffer w/o physical file

Open sfavazza opened this issue 1 year ago • 6 comments

I am not sure whether it is intended, but why persp-mode save buffers not baked by a physical file?

In some layout files I see lines containing the following: (def-buffer "<buffer-name>" nil <mode-they-where-active-at-saving-time>)

This causes an annoying hanging issue when trying to open a shell from the list of docker containers (see this issue).

Should I create an ad-hoc filter to prevent this or is it an unintended behavior?

sfavazza avatar Nov 06 '24 15:11 sfavazza

why persp-mode save buffers not baked by a physical file?

Because it will fail to restore window configuration with missing buffer. However it is not necessary to restore major-mode of such buffer.

Bad-ptr avatar Nov 13 '24 01:11 Bad-ptr

Because it will fail to restore window configuration with missing buffer.

But if it is possible to filter out buffer with programmable criteria and be still capable to reload a configuration, would it make sense to have an option to automatically filter out file-less buffer from saving them in the layer configuration?

However it is not necessary to restore major-mode of such buffer.

What do you mean? Is there something I should do on my side?

sfavazza avatar Nov 28 '24 18:11 sfavazza

Is there something I should do on my side?

You can create a custom load function like described here: https://github.com/Bad-ptr/persp-mode.el?tab=readme-ov-file#custom-saveload-buffer-function-example something like

(with-eval-after-load "persp-mode-autoloads"
  (let ((docker-loadf
            (lambda (savelist)
                (when (dockerbufferp savelist) ;; here you must implement `dockerbufferp' predicate
                   (get-buffer-create (cadr savelist))))))
  (push docker-loadf persp-load-buffer-functions)))

Bad-ptr avatar Jan 10 '25 12:01 Bad-ptr

why persp-mode save buffers not baked by a physical file?

Because it will fail to restore window configuration with missing buffer. However it is not necessary to restore major-mode of such buffer.

Then having the possibility to filter out the buffers not backed by a physical file, would break the window configuration restoration?

sfavazza avatar Mar 18 '25 15:03 sfavazza

Then having the possibility to filter out the buffers not backed by a physical file, would break the window configuration restoration?

Yes, if the buffer was displayed while saving window configuration.

Bad-ptr avatar Mar 21 '25 16:03 Bad-ptr

Rereading this thread(and with recent changes), I think that you can utilize the persp-filter-save-buffers-functions:

(with-eval-after-load "persp-mode"
  (add-hook 'persp-filter-save-buffers-functions
    (lambda (b) (not (buffer-local-value 'buffer-file-name b)))))

This will prevent from saving buffers not backed by a file.

it will fail to restore window configuration with missing buffer

I hope this is fixed now 5adf105f7168cd88357702d07768844b4788507a: https://github.com/Bad-ptr/persp-mode.el/blob/2e42688f6aeaa80b304f3a7d0c08168c222f14b9/persp-mode.el#L1064

window-restore-killed-buffer-windows

  • t means to restore the window and show some other buffer in it.

Probably introduced at or before Emacs version 30.1

Bad-ptr avatar Jul 26 '25 15:07 Bad-ptr