Bad-ptr / persp-mode.el

named perspectives(set of buffers/window configs) for emacs
400 stars 44 forks source link

Terminals come back with no process #72

Closed WhittlesJr closed 7 years ago

WhittlesJr commented 7 years ago

If I have a perspective with terminal windows (specifically multi-term windows), and save / close / exit emacs / load the perspective, I'll get the multi-term buffers back in the same windows with the same names, but the mode line says "Term: line no process." And I can't just start a new multi-term process in the same (named) buffer, because that creates a new buffer. So I have to kill the named buffer and start a new multi-term process and then rename it to what it was originally. Not very convenient.

I'm not sure if this is something persp-mode can control, as every other window session saver I've tried has the same behavior. But if persp-mode could somehow (configurably?) start up term buffers in their respective windows on startup, it would be most excellent. Better yet, what if it could even save off the cwd and cd to that directory on startup? That would be badass.

Bad-ptr commented 7 years ago

It may look like this:


(with-eval-after-load "persp-mode"
  (require 'multi-term)
  (with-eval-after-load "multi-term"

    (persp-def-buffer-save/load
     :mode 'term-mode :tag-symbol 'def-multiterm-buffer
     :predicate #'(lambda (b) (memq b multi-term-buffer-list))
     :save-vars '(default-directory)
     :save-function #'(lambda (b tag lvars)
                        (let ((bname (buffer-name b)))
                          (push
                           (cons 'multi-term-dedicated-bufferp
                                 (eq b multi-term-dedicated-buffer))
                           lvars)
                          (push
                           (cons 'multi-term-buffer-shell
                                 (car (last (process-command
                                             (get-buffer-process b)))))
                           lvars)
                          (list tag bname lvars)))
     :after-load-function
     #'(lambda (b &rest _)
         (with-current-buffer b
           (let ((shell-name (or multi-term-buffer-shell
                                 multi-term-program
                                 (getenv "SHELL")
                                 (getenv "ESHELL")
                                 "/bin/sh"))
                 (term-name (buffer-name (current-buffer))))
             (cd (or default-directory
                     (expand-file-name multi-term-default-dir)))
             (if multi-term-program-switches
                 (term-ansi-make-term term-name shell-name nil
                                      multi-term-program-switches)
               (term-ansi-make-term term-name shell-name)))
           (setq multi-term-buffer-list (nconc multi-term-buffer-list (list b)))
           (multi-term-internal))))))

I'm not using multi-term, so I didn't test it.

WhittlesJr commented 7 years ago

"I didn't test it" Works perfectly

You, good sir, deserve a cookie. This is amazing! This will save me hours and hours of recreating terminal buffers over the course of my life.

Would it be possible to roll this functionality into persp-mode? It would make the package even more robust.

Bad-ptr commented 7 years ago

Would it be possible to roll this functionality into persp-mode?

No, I don't want it. Because the persp-mode is already ~4000 lines of code and I it seems to me that not many users of persp-mode needs this feature (may be I'm wrong). Hovewer I will add it to the readme.

WhittlesJr commented 7 years ago

Sure, makes sense. Thanks for adding the gist!