Bad-ptr / persp-mode.el

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

Save persp only if not nil in persp-before-make-frame #25

Closed syl20bnr closed 8 years ago

syl20bnr commented 8 years ago

Hi Constantin,

This PR fixes a crash on startup of the emacsclient because of nil persp variable. Not sure if this nil persp is expected but in the meantime this PR fixes the crash.

For more info see https://github.com/syl20bnr/spacemacs/issues/4120 and https://github.com/syl20bnr/spacemacs/issues/4121

Cheers, syl20bnr

Bad-ptr commented 8 years ago

Hi Constantin,

Hello.

crash on startup of the emacsclient because of nil persp variable.

Hmhmm... This is something strange. Need to look deeper.

Bad-ptr commented 8 years ago

ok, it was a long time ago when I started emacs daemon last time.) And first of all it looks like the persp-alambda and so the persp-hook-once macros do not work anymore.

Could you test this branch https://github.com/Bad-ptr/persp-mode.el/tree/alambda-no-more ? (can't test it myself until tomorrow)

Bad-ptr commented 8 years ago

Well, I tested that branch myself and I think it must solve the https://github.com/syl20bnr/spacemacs/issues/4121 issue(and https://github.com/syl20bnr/spacemacs/issues/4187 too). It's merged into master now.

Bad-ptr commented 8 years ago

As for this https://github.com/syl20bnr/spacemacs/issues/4120 issue, probably I can add custom variable to not restore window configuration for new frames.

syl20bnr commented 8 years ago

Sorry for the late reply, I tested last persp-mode from MELPA and the emacsclient crash is still here. I'll ask some people if they can test it on their side.

Bad-ptr commented 8 years ago

Sorry for the late reply

It's ok.)

the emacsclient crash is still here

This is very strange because I can not reproduce it myself. Actually any action on the nil perspective must be valid.

Bad-ptr commented 8 years ago

Well I think I know how to get more debug information:

  1. Start emacs daemon with --debug-init and ensure that it's started normally: emacs --daemon --debug-init && echo 'Emacs daemon started normally.'
  2. Check that the persp-mode is not active: emacsclient --eval 'persp-mode' (it must print nil)
  3. Check that the persp-mode-start-and-remove-from-make-frame-hook is in the after-make-frame-functions list: emacsclient --eval "(memq #'persp-mode-start-and-remove-from-make-frame-hook after-make-frame-functions)"
  4. Remove the persp-mode-start-and-remove-from-make-frame-hook from the after-make-frame-functions list: emacsclient --eval "(setq after-make-frame-functions (delete #'persp-mode-start-and-remove-from-make-frame-hook after-make-frame-functions))"
  5. Create an emacs frame: emacsclient -t
  6. In the created frame evaluate this expression(M-:): (persp-mode-start-and-remove-from-make-frame-hook (selected-frame))
Bad-ptr commented 8 years ago

I think this is it:

  1. Start the emacs daemon and ensure that it's started normally: emacs --daemon && echo 'Emacs daemon started normally.'
  2. Create a graphical emacs frame: emacsclient -c, make it fullscreen.
  3. Split windows many times: M-: (dolist (i '(1 2 3 4 5)) (if (= 0 (% i 2)) (split-window-horizontally) (split-window-vertically)))
  4. Start a virtual terminal application, make it's window small, then try to create a text emacs frame in it: emacsclinet -t Oops, crashed.
  5. Remove the persp-init-new-frame from the after-make-frame-functions: emacsclient --eval "(setq after-make-frame-functions (delete #'persp-init-new-frame after-make-frame-functions))"
  6. Create a text emacs frame again: emacsclinet -t, and try to launch the persp-init-new-frame manually: M-: (persp-init-new-frame (selected-frame)) and get an error, saying something like: (error "Window #<window 24 on *scratch*> too small to accommodate state")

Now it must be fixed: 56828b520e30662da7a20557971b47a99c56011a

Bad-ptr commented 8 years ago

Just tried to run spacemacs in Ubuntu 14.04.4 LTS with different emacs versions:

The standard ubuntu's 24.3.1 -- the only problem of spacemacs here is the helm-flx package, which depends on emacs 24.4. No crash here.)

24.4.2 -- built from sources(ftp://ftp.gnu.org/pub/gnu/emacs/emacs-24.4.tar.xz). No crash.

25.0.50.1 -- built from sources. No crash.

The only error I was able to get in all emacs versions is the apply: Device 1 is not a termcap terminal device, which is the cause of the bracketed-paste--tty-state-exit-hook in the kill-emacs-hook. What the bracketed-paste--tty-state-exit-hook is trying to do is to execute: (send-string-to-terminal "\e[?2004l") on emacs exit. This don't work if your current frame is a graphical frame. I consider it as a bug in the bracketed-paste.el.)

Also to support emacs 25 in your fork (https://github.com/syl20bnr/persp-mode.el), replace the: https://github.com/syl20bnr/persp-mode.el/blob/master/persp-mode.el#L580

(defmacro persp-alambda (arglist &rest body)
  "Anaphoric lambda."
  (declare (indent 1))
  `(labels ((self ,arglist ,@body))
     #'self))

with

(unless (fboundp 'self) (fset 'self nil))
(defmacro persp-alambda (args &rest body)
  "Anaphoric lambda."
  (declare (indent defun))
  `(lexical-let ((self))
     (setq self #'(lambda ,args
                    (letf (((symbol-function 'self) self))
                      ,@body)))
     self))

This will fix the *ERROR*: Symbol’s function definition is void: self for emacs 25 without breaking older emacses(prove me wrong:)). Just saying because I will break backward compatibility(if it is not already broken) in near feature and suppose users(even those who uses emacs 25) will switch to your fork.

syl20bnr commented 8 years ago

That's great, I'll test it again this evening. Thank you for the fix for my fork but the sooner I can get rid of this fork, the better :-)

syl20bnr commented 8 years ago

Big thank you for tracking the bug apply: Device 1 is not a termcap terminal device.

Bad-ptr commented 8 years ago

In the case if still get a crash(Just if you don't know how to debug emacs:))

If you can not create an emacs frame -- check the before-make-frame-hook and the after-make-frame-functions. Just remove functions from these lists one by one emacsclient --eval '(pop after-make-frame-functions)' and see after which removed function you can create the frame. After the frame is created -- M-x toggle-debug-on-error RET and try to execute the last removed function manually (You can run a function from the before-make-frame-hook list without arguments, but to run a function from the after-make-frame-functions you must pass the (selected-frame) as an argument).

If you can not kill emacs -- do the same for the kill-emacs-hook, the kill-emacs-query-functions and maybe the delete-frame-functions.

aaronjensen commented 8 years ago

@Bad-ptr fwiw on emacs 25 the fix to @syl20bnr's fork you mention above does not appear to work. If I emacsclient --eval '(pop after-make-frame-functions)' once to get rid of self then emacsclient starts as normal, but persp-mode can no longer create layouts. because *persp-hash* is nil

Bad-ptr commented 8 years ago

the fix ... you mention above does not appear to work

Ok, try this:

(unless (fboundp 'self) (fset 'self nil))
(defmacro persp-alambda (args &rest body)
  "Anaphoric lambda."
  (declare (indent defun))
  `(let ((lexical-binding t))
     (,(if (> emacs-major-version 25)
           'let
         'lexical-let) ((self))
         (setq self #'(lambda ,args
                        (letf (((symbol-function 'self) self))
                          ,@body)))
         self)))
aaronjensen commented 8 years ago

@Bad-ptr nope. emacsclient -t foo exits immediately. emacsclient -c foo displays:

Waiting for Emacs...
*ERROR*: Symbol’s function definition is void: self

then exits

Bad-ptr commented 8 years ago

This is bad :( Just to be sure that you are not doing something wrong: Can you provide a recipe of what you are doing to apply this (so-called:p)"fix"

aaronjensen commented 8 years ago

erg, I forgot to delete the .elc. Both fixes actually work for me, sorry about that.

Bad-ptr commented 8 years ago

I forgot to delete the .elc

hehe. I knew it!

aaronjensen commented 8 years ago

@Bad-ptr can you fix here or should @syl20bnr update his fork? Thanks!

Bad-ptr commented 8 years ago

@aaronjensen I'm planing to do a 'stable' release with some backward compatibility fixes. But I don't know when I'l do it)

syl20bnr commented 8 years ago

Sorry for being so late on this. I tested the last version on MELPA and it fixes the crash :+1: Thank you :100: