Git Product home page Git Product logo

Comments (15)

seagle0128 avatar seagle0128 commented on September 13, 2024 2

I switch to use persp-mode, which provides saving and restoring features.
visit https://github.com/Bad-ptr/persp-mode.el.

from perspective-el.

pdex avatar pdex commented on September 13, 2024 2

I looked into persp-mode, but it doesn't play well with projectile (which is part of the reason I'm using perspectives). I'm not interested in using revive since desktop-save-mode can restore window configurations.

So I threw together some functionality to save/restore the buffers and perspective names using desktop-save-mode. I may spend some time figuring out how to save/restore everything else in the persp struct, but this does 99% of what I need.

  (defun perspectives-buffer-name-p (buffer)
    (if (and buffer
         (buffer-name buffer)
         (not (string-prefix-p "*" (buffer-name buffer)))
         (not (string-suffix-p "*" (buffer-name buffer))))
    t
      nil))

  (defun perspectives-hash-filter (current filtered parameters saving)
    (let ((value (cdr current))
      (result ())
      (keys (hash-table-keys (cdr current))))
      ;; for every perspective...
      (dolist (key keys)
    (let ((persp (gethash key value)))
      ;; that isn't killed...
      (if (not (persp-killed persp))
          (add-to-list
           'result
           (cons key
             ;; save the list of buffers
             (list (cons "buffers"
             (list
              (mapcar 'buffer-name (seq-filter 'perspectives-buffer-name-p (persp-buffers persp)))))))))))
    ;; return a different variable name so perspectives doesn't clobber it
    (cons 'perspectives-hash-serialized result)))

  ;; serialize perspectives hash
  (add-to-list 'frameset-filter-alist '(perspectives-hash . perspectives-hash-filter))
  ;; don't serialize anything else
  (add-to-list 'frameset-filter-alist '(persp-modestring . :never))
  (add-to-list 'frameset-filter-alist '(persp-recursive . :never))
  (add-to-list 'frameset-filter-alist '(persp-last . :never))
  (add-to-list 'frameset-filter-alist '(persp-curr . :never))

  (defun perspectives-restore-state ()
    (dolist (frame (frame-list))
      ;; get the serialized state off of the frame
      (let ((state (frame-parameter frame 'perspectives-hash-serialized)))
    (if state (progn
            (message "Found state, attempting restore")
            ;; delete it so we don't end up in a loop
            (set-frame-parameter frame 'perspectives-hash-serialized nil)
            (with-selected-frame frame
              (dolist (elem state)
            ;; recreate the perspective
            (with-perspective (car elem)
              (dolist (buffer-name (car (cdr (assoc "buffers" (cdr elem)))))
                ;; add the buffer back to the perspective
                (persp-add-buffer buffer-name)
                )))
              ))
      (message "No state found")
      )
    )))

  (add-hook 'desktop-after-read-hook 'perspectives-restore-state)

from perspective-el.

nex3 avatar nex3 commented on September 13, 2024

There's no built-in save/restore mechanism. You could add some code to your .emacs to create a bunch of perspectives whenever Emacs starts up.

from perspective-el.

tr37ion avatar tr37ion commented on September 13, 2024

Would you like to show me an example how to do this? I really like your approach and I would like to use it. I'm relatively new to Emacs. Hopefully, you can explain what I have too do that I get the last session saved and reloaded every time I restart Emacs. I tried so many other solutions today, yet yours is still the best one.

from perspective-el.

nex3 avatar nex3 commented on September 13, 2024

You can just add (persp-new "perspective-name") for all of the perspectives you want to create.

from perspective-el.

fvaresi avatar fvaresi commented on September 13, 2024

I was just trying to achieve something similar by using desktop-save-mode, but it doesn't work out-of-the-box.

I guess a little extra work is required to restore perspective state, will look into it when I find some time.

from perspective-el.

gcv avatar gcv commented on September 13, 2024

I took a shot at adding durability support. Please take a look: #80 (or my fork, https://github.com/gcv/perspective-el).

from perspective-el.

gcv avatar gcv commented on September 13, 2024

This feature is now available as persp-state-save and persp-state-load.

from perspective-el.

JPRuehmann avatar JPRuehmann commented on September 13, 2024

How can i automaticaly initialize persp-state-load at starting perspective, such as with persp-state-safe at emacs-kill.

from perspective-el.

gcv avatar gcv commented on September 13, 2024

@JPRuehmann: Please see #200.

from perspective-el.

alphapapa avatar alphapapa commented on September 13, 2024

FYI, you may find this new package interesting. It doesn't do exactly what perspective does, but it's similar: https://github.com/alphapapa/activities.el

from perspective-el.

gcv avatar gcv commented on September 13, 2024

Hi @alphapapa! I took a look at Activities. It looks really promising, and it's really nice that it's built on modern Emacs foundations. Perspective is certainly showing its age (first commit in March 2008), and pretty much all open long-lasting tickets result from it. I'll definitely try Activities as a daily driver once switch-to-buffer filtering arrives (it's something in Perspective I can't live without).

PS: Small correction to the Activities README (where it says "To date, only Burly and Bufler seem to offer the ability to restore one across Emacs sessions"): Perspective does allow saving and loading state, so perspectives can be restored in a new Emacs session. The implementation is less elegant than the bookmarks approach you chose, and probably more limited, but it works well enough.

from perspective-el.

seagle0128 avatar seagle0128 commented on September 13, 2024

Another great alternative is tabspaces, which is built on the built-in packages: tabbar and project (27.1+). It's simple but flexible.

Tabspaces leverages tab-bar.el and project.el (both built into emacs 27+) to create buffer-isolated workspaces (or “tabspaces”) that also integrate with your version-controlled projects. It should work with emacs 27+. It is tested to work with a single frame workflow, but should work with multiple frames as well.

from perspective-el.

alphapapa avatar alphapapa commented on September 13, 2024

I'll definitely try Activities as a daily driver once switch-to-buffer filtering arrives (it's something in Perspective I can't live without).

Understood. Well, I just pushed activities-switch-buffer. Please see alphapapa/activities.el#43 (comment) and let me know what you think.

from perspective-el.

alphapapa avatar alphapapa commented on September 13, 2024

PS: Small correction to the Activities README (where it says "To date, only Burly and Bufler seem to offer the ability to restore one across Emacs sessions"): Perspective does allow saving and loading state, so perspectives can be restored in a new Emacs session. The implementation is less elegant than the bookmarks approach you chose, and probably more limited, but it works well enough.

Thanks. I've updated it to mention non-file-backed buffers, which seems to be the key distinction. alphapapa/activities.el@80e76f2

from perspective-el.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.