Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

indirect buffers not saved by persp-save-state-to-file doesn't save #93

Open
notuntoward opened this issue May 20, 2018 · 5 comments
Open

Comments

@notuntoward
Copy link

I like persp-mode but wish that it could have indirect files (the result of, for example clone-indirect-buffer-other-window).

Say I have a file named

~/tmp/tmp.txt

and that I've cloned it, so that I have another buffer viewing the same file. The emacs modeline will call this ~/tmp/tmp.txt<2>.

Then, if I save the window configuration with persp-save-state-to-file, kill emacs, and then try to restore the config with persp-load-state-from-file, then the buffer positions will be correctly restored; the file ~/tmp/tmp.txt will be reloaded; and it will be in its original buffer.

However, the buffer where the indirect buffer was will be blank, and it will be given the name -tmp.txt<2>

It looks like persp-mode is trying to load a file named -tmp.txt<2> instead of recreating the indirect view.

@Bad-ptr
Copy link
Owner

Bad-ptr commented May 26, 2018

You can define a custom save/load function
https://github.com/Bad-ptr/persp-mode.el#custom-saveload-buffer-function-example

Something like this:

(with-eval-after-load "persp-mode"
  (defvar persp-indirrect-buffers-to-restore nil)

  (persp-def-buffer-save/load
   :tag-symbol 'def-indirect-buffer
   :predicate #'buffer-base-buffer
   :save-function
    #'(lambda (buf tag vars)
        (list tag (buffer-name buf) vars
              (buffer-name (buffer-base-buffer))))
    :load-function
    #'(lambda (savelist &rest _rest)
        (destructuring-bind
            (buf-name vars base-buf-name &rest _rest) (cdr savelist)
          (push (cons buf-name base-buf-name)
                persp-indirrect-buffers-to-restore)
          nil)))

  (add-hook 'persp-after-load-state-functions
            #'(lambda (&rest _args)
                (dolist (ibc persp-indirrect-buffers-to-restore)
                  (let* ((nbn (car ibc))
                         (bbn (cdr ibc))
                         (bb (get-buffer bbn)))
                    (when bb
                      (when (get-buffer nbn)
                        (setq nbn (generate-new-buffer-name nbn)))
                      (make-indirect-buffer bb nbn t))))
                (setq persp-indirrect-buffers-to-restore nil))))

@notuntoward
Copy link
Author

Thanks! However, it doesn't run on my machine (Window emacs 25.3.1). There are no errors when I save the configuration but when I try to load it with persp-load-state-from-file, I get the message:

persp-load-state-from-file: Invalid read syntax: "#"

I get the same error, if I open the saved configuration file and run it with M-x eval-buffer

@Bad-ptr
Copy link
Owner

Bad-ptr commented Jun 4, 2018

I updated the code in the previous post. But before running it, you must update the persp-mode.

@codygman
Copy link

codygman commented Oct 3, 2018

@Bad-ptr Your code above seemed to work, but then I noticed the indirect buffer had the entire contents of the file it was derived from. Is there anyway to make sure the indirect buffer is only the part of the buffer you cloned?

Here's an example:

persp-mode-org-indirect-buf-issue

@notuntoward
Copy link
Author

notuntoward commented Oct 15, 2018

With the latest persp-mode, I no longer get error messages but still can't save indirect buffers. There is also now a problem with package-autoremove.

With the latest persp-mode, I can save emacs buffer state with M-x persp-save-state-to-file, kill/restart emacs, and then restore the state with M-x persp-load-state-from-file. This correctly loads the files I was visiting before. If there were no indirect buffers, there are no other messages.

However, if I save/load an emacs state containing an indrect buffer, I get a minibuffer full of code and the indirect buffer is not restored. All the files are loaded in some buffer but only a blank scratch buffer is shown (screenshot below).

buffer-full-of-code

I should say that I'm also using the custom save/load function contributed by @Bad-ptr on May 26.

The other problems is that M-x package auto-remove now thinks that persp-mode is unused and wants to delete it. It looks like persp-mode isn't registering itself with the package manager, somehow.

This is on Windows emacs 26.1, and with the attached persp-mode invocation in my .emacs:

persp-mode-in-dotemacs.txt

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

No branches or pull requests

3 participants