Bad-ptr / persp-mode.el

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

Type error in persp-buffer-list-restricted #32

Closed mz-pdm closed 8 years ago

mz-pdm commented 8 years ago

On the line

(string-match-p "^.?kill-buffer.?$" (symbol-name ckit))

ckit may not be a symbol and then error is signaled. I assume that can happen due to the assignment

(setq ckit (caddr cbt))

The obvious solution is to add something like (symbolp ckit) immediately before the string-match-p call (I checked it helps in my case) but I dare to suggest polishing the whole pblr-ret block (cryptic variable names, weird ckit assignments, ...).

Bad-ptr commented 8 years ago

ckit may not be a symbol and then error is signaled.

Interesting... сan you provide an example case? Hmm.. let me guess -- it could be a lambda, right?

mz-pdm commented 8 years ago

Yes, it can be lambda, e.g.: (lambda (b) (memq b (persp-buffer-list-restricted (selected-frame))))

mz-pdm commented 8 years ago

Another very, very weird thing about that loop is that it breaks my IMAP, claiming that my mailboxes erroneously start with a slash (they actually don't). I found out that the necessary and sufficient condition to invoke that error is the interactive-form call. I can't find any explanation for that, maybe it's an Emacs bug, maybe it's a bug elsewhere, but when I prevent unnecessary interactive-form invocation by rewriting the condition to

  (when (and (eq (car cbt) t)
        (let ((ckit (cadr cbt)))
          (when (eq ckit 'call-interactively)
            (setq ckit (caddr cbt)))
          (and (symbolp ckit)
               (string-match-p "^.*?kill-buffer.*?$" (symbol-name ckit))
               (interactive-form ckit))))

my IMAP in Gnus starts working again. Mystery. I don't claim it's a persp-mode bug, but if anybody could explain what may be wrong with the interactive-form here, it would be very helpful. :-)

Bad-ptr commented 8 years ago

Yes, it can be lambda, e.g.: (lambda (b) (memq b (persp-buffer-list-restricted (selected-frame))))

But how did you get an error? I just tried to call different lambdas in different ways, but it looks like everything is working fine for me. What version of emacs are you using? (And maybe you can give a link to your emacs configuration?)

Another very, very weird thing about that loop is that it breaks my IMAP

Yes, strange. And I can not reproduce it. :( Have you tried M-x toggle-debug-on-error RET? What's in the *Backtrace* buffer? Or add some debug messages to the loop:

(message "----- %s step begins\n" i)
(when (and  (message "CBT: %s\n" cbt) (eq (car cbt) t)
        (let ((ckit (cadr cbt)))
          (when (eq ckit 'call-interactively)
            (setq ckit (caddr cbt)))
          (and (symbolp ckit)
               (string-match-p "^.*?kill-buffer.*?$" (symbol-name ckit))
               (interactive-form ckit))))
(message "---- %s step ends\n" i)
mz-pdm commented 8 years ago

But how did you get an error? I just tried to call different lambdas in different ways, but it looks like everything is working fine for me.

Here is an example cbt:

(t call-interactively (lambda nil (interactive) (my-persp-by-prefix "g"))

This comes from my hydra definition for switching perspectives:

(defhydra hydra-persp (global-map "C-z" :timeout 3)
  ...
  ("g" (my-persp-by-prefix "g") nil :exit t)
  ...)

I get that the error after pressing `C-z g'.

What version of emacs are you using?

24.5

(And maybe you can give a link to your emacs configuration?)

Unfortunately not, it's too complex. :-)

Ad the IMAP issue:

Have you tried M-x toggle-debug-on-error RET?

Of course, but it's not that easy. Things apparently don't break within the loop but later on. I'd suspect something like missing save-match-data but it's not that. And there is no error to hook to as something somewhere in Gnus/IMAP processing just returns nil (no error raised). I don't know where to look for the problem and I can't spend more time on complex debugging now. :-(

mz-pdm commented 8 years ago

I get that the error after pressing `C-z g'.

But only under some special circumstances, I don't know how to reproduce that easily. If you can simply believe me that (caddr cbt) may be lambda and not symbol, you can handle that situation easily in the code. If you're really curious how that can happen, I can try to dig into that later, but it's not necessary to fix the error.

Bad-ptr commented 8 years ago

If you can simply believe me

I believed you from the start of our discussion. But just believing is not enough in such cases.) So I needed as much information as possible to do a proper fix.

Now I managed to reproduce it: First i bound a lambda to a key:

(global-set-key (kbd "C-x k")
  (lambda ()
    (interactive)
    (call-interactively
      (lambda ()
        (interactive)
        (message "Hoho: %s" (persp-buffer-list-restricted (selected-frame) 0 nil))))))

Then switched to a new perspective, switched to the *Messages* buffer not adding it to the current perspective with persp-temporarily-display-buffer, then pressed C-x k and got the error.

I'm not sure how to handle that really correctly. But checking that the ckit is a symbol should work for most cases.

Thank you for the bug report and patience. I hope that this commit 7d46178b260cb600d378e9e3b746253cc9cb8a46 will help you.

mz-pdm commented 8 years ago

The fix seems to work for me, thanks!

Bad-ptr commented 8 years ago

You know what? Now I have a bug with gnus too.) That loop is really breaking the gnus somehow.

Bad-ptr commented 8 years ago

Finally 73398e164fe9371cc765a92f80de42e805fd3656.) This should fix it.