helm and winner mode

108 views
Skip to first unread message

mak

unread,
Apr 1, 2012, 6:08:35 PM4/1/12
to emacs-helm
Hey all,

I like using winner mode (http://www.emacswiki.org/emacs/WinnerMode)
to undo windows configuration in Emacs. However, when I run `winner-
undo' after I run some helm command, I have to run `winner-undo' twice
because the first `winner-undo' takes me to the previous window
configuration with the buffer *helm* open (which I'm usually not
interested. That is, I'm only interested in returning to windows
configurations that don't contain the *helm* buffer).

If I wanna go back to the previous windows configuration, it's not a
big deal to run winner-undo twice. But if I want to go to an earlier
windows configuration, I may have to run winner-undo more than once to
get rid of the *helm* buffers.

So my questions are: do you guys use winner mode? If you do, how do
you deal with this issue?

Thank you in advance.

Cheers,
mak

Thierry Volpiatto

unread,
Apr 2, 2012, 1:56:08 AM4/2/12
to emacs...@googlegroups.com
Hi mak,

mak <makm...@gmail.com> writes:

> So my questions are: do you guys use winner mode? If you do, how do
> you deal with this issue?

You have the variable `winner-boring-buffers', but the problem is that
you have many *Helm-<this>*, *helm-<that>* buffers and it would be
difficult to add all buffers to this.
So the best is to use a regexp matching all helm buffers, here the code
to add to .emacs:

--8<---------------cut here---------------start------------->8---
;;; winner-mode config
;;
;;
(setq winner-boring-buffers '("*Completions*"
"*Compile-Log*"
"*inferior-lisp*"
"*Fuzzy Completions*"
"*Apropos*"
"*dvc-error*"
"*Help*"
"*cvs*"
"*Buffer List*"
"*Ibuffer*"
))

(when (require 'winner)
(defvar winner-boring-buffers-regexp
"\*[hH]elm.*\\|\*xhg.*\\|\*xgit.*")
(defun winner-set1 (conf)
;; For the format of `conf', see `winner-conf'.
(let* ((buffers nil)
(alive
;; Possibly update `winner-point-alist'
(loop for buf in (mapcar 'cdr (cdr conf))
for pos = (winner-get-point buf nil)
if (and pos (not (memq buf buffers)))
do (push buf buffers)
collect pos)))
(winner-set-conf (car conf))
(let (xwins) ; to be deleted

;; Restore points
(dolist (win (winner-sorted-window-list))
(unless (and (pop alive)
(setf (window-point win)
(winner-get-point (window-buffer win) win))
(not (or (member (buffer-name (window-buffer win))
winner-boring-buffers)
(string-match winner-boring-buffers-regexp
(buffer-name (window-buffer win))))))
(push win xwins))) ; delete this window

;; Restore marks
(letf (((current-buffer)))
(loop for buf in buffers
for entry = (cadr (assq buf winner-point-alist))
do (progn (set-buffer buf)
(set-mark (car entry))
(setf (winner-active-region) (cdr entry)))))
;; Delete windows, whose buffers are dead or boring.
;; Return t if this is still a possible configuration.
(or (null xwins)
(progn
(mapc 'delete-window (cdr xwins)) ; delete all but one
(unless (one-window-p t)
(delete-window (car xwins))
t))))))

(defalias 'winner-set 'winner-set1))
(winner-mode 1)
--8<---------------cut here---------------end--------------->8---

I forgot this because I was not using winner-mode anymore, but now you
remind me this, I will submit a patch to Emacs :-)

--
Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997

Makmiller Pedroso

unread,
Apr 2, 2012, 4:50:20 AM4/2/12
to emacs...@googlegroups.com
Hi Thierry,

That's awesome!! I've just tried the above code and it works like a charm.

> I forgot this because I was not using winner-mode anymore, but now you
> remind me this, I will submit a patch to Emacs :-)

Just out of curiosity, what do you use instead? Registers?

Thank you so much.
mak

Thierry Volpiatto

unread,
Apr 2, 2012, 4:53:54 AM4/2/12
to emacs...@googlegroups.com
Makmiller Pedroso <makm...@gmail.com> writes:

> Just out of curiosity, what do you use instead? Registers?

elscreen

Reply all
Reply to author
Forward
0 new messages