Reputation: 5157
I want to make one keystroke, say C-F12
, to do delete-other-windows
or winner-undo
. I think it's easy if I already learning Emacs Lisp programming, and set a boolean flag. That is, if previously it run delete-other-window
, now it'll run winner-undo
.
How do you do that in Emacs Lisp?
Thanks
Upvotes: 1
Views: 171
Reputation: 3539
Here's a solution using the approach taken by Emacs' recenter-top-bottom function:
(defun delete-other-window-or-winner-undo ()
"call delete-other-window on first invocation and winner-undo on subsequent invocations"
(interactive)
(if (eq this-command last-command)
(winner-undo)
(delete-other-windows)))
(global-set-key (kbd "<C-f12>") 'delete-other-window-or-winner-undo)
Upvotes: 1
Reputation: 107879
(defun swdev-toggle-sole-window ()
(interactive)
(if (cdr (window-list))
(delete-other-windows)
(winner-undo)))
(global-set-key (kbd "<C-f12>") 'swdev-toggle-sole-window)
swdev-toggle-sole-window
, taking no argument.M-x
or through a key binding.C-f12
.Upvotes: 1
Reputation: 21192
Try something like this
(setq c-f12-winner-undo t)
(define-key (current-global-map) [C-f12]
(lambda()
(interactive)
(if c-f12-winner-undo
(winner-undo)
(delete-other-windows))
(setq c-f12-winner-undo (not c-f12-winner-undo))))
Upvotes: 3