Refactor SPC w and SPC b regarding deletion

The motivation is to clean redundent actions and bring more consistency
between `SPC b` and `SPC w` by:
- using capital letters for ace-window actions
- reusing the same letters between window and buffer when possible
- adding support for universal prefix argument to delete both window
and buffer

Details of changes:

Buffer

- `SPC b k` has been removed since the functionality is
available directly in Helm by selecting the kill buffer action

- `SPC b m` (buffer move) has been removed because the functionality
is available via `SPC w` with `SPC w h/j/k/l`, `SPC w H/J/K/L` and
`SPC w M` (see window section for the new `SPC w M`).

- `SPC b K` (kill other buffers) is now `SPC b m` to map with `SPC w m`
(kill other window or maximize). Using the universal prefix argument
`SPC u SPC b m` will also kill the windows.

- `SPC b C-k` (kill buffer matching regexp) is now simply on `SPC b k`.

- `SPC b D` now kills a buffer using ace-window.

- `SPC b d` and `SPC b D` now accept an universal prefix argument to
also delete the window. So `SPC u SPC b d` and `SPC u SPC b D` delete
the buffer and the window.

Window

- `SPC w M` now swap the window using ace-window.

- old `SPC w M` (center window) is now on `SPC w c` and `SPC w C` uses
ace-window.

- `SPC w SPC` (select window) is now on `SPC w W` since it uses
ace-window.

- `SPC w d` and `SPC w D` now accepts an universal prefix argument to
delete the window and the buffer.
This commit is contained in:
syl20bnr 2016-06-25 23:40:41 -04:00
parent 878c45abf9
commit b30c393b8d
7 changed files with 114 additions and 87 deletions

View File

@ -1825,8 +1825,12 @@ Windows manipulation commands (start with ~w~):
|------------------------+-----------------------------------------------------------------------------|
| ~SPC w =~ | balance split windows |
| ~SPC w b~ | force the focus back to the minibuffer (usefull with =helm= popups) |
| ~SPC w c~ | maximize/minimize a window and center it |
| ~SPC w C~ | maximize/minimize a window and center it using [[https://github.com/abo-abo/ace-window][ace-window]] |
| ~SPC w d~ | delete a window |
| ~SPC w D~ | delete another window using [[https://github.com/abo-abo/ace-window][ace-delete-window]] |
| ~SPC u SPC w d~ | delete a window and its current buffer (does not delete the file) |
| ~SPC w D~ | delete another window using [[https://github.com/abo-abo/ace-window][ace-window]] |
| ~SPC u SPC w D~ | delete another window and its current buffer using [[https://github.com/abo-abo/ace-window][ace-window]] |
| ~SPC w t~ | toggle window dedication (dedicated window cannot be reused by a mode) |
| ~SPC w f~ | toggle follow mode |
| ~SPC w F~ | create new frame |
@ -1839,7 +1843,7 @@ Windows manipulation commands (start with ~w~):
| ~SPC w l~ | move to window on the right |
| ~SPC w L~ | move window to the right |
| ~SPC w m~ | maximize/minimize a window (maximize is equivalent to delete other windows) |
| ~SPC w M~ | maximize/minimize a window, when maximized the buffer is centered |
| ~SPC w M~ | swap windows using [[https://github.com/abo-abo/ace-window][ace-window]] |
| ~SPC w o~ | cycle and focus between frames |
| ~SPC w p m~ | open messages buffer in a popup window |
| ~SPC w p p~ | close the current sticky popup window |
@ -1851,7 +1855,7 @@ Windows manipulation commands (start with ~w~):
| ~SPC w v~ or ~SPC w /~ | vertical split |
| ~SPC w V~ | vertical split and focus new window |
| ~SPC w w~ | cycle and focus between windows |
| ~SPC w SPC~ | select window using [[https://github.com/abo-abo/ace-window][ace-window]] |
| ~SPC w W~ | select window using [[https://github.com/abo-abo/ace-window][ace-window]] |
**** Window manipulation transient state
A convenient window manipulation transient state allows performing most of the
@ -1914,30 +1918,27 @@ By default Spacemacs uses =helm= to open files.
**** Buffers manipulation key bindings
Buffer manipulation commands (start with ~b~):
| Key Binding | Description |
|-------------+--------------------------------------------------------------------------|
| ~SPC TAB~ | switch to alternate buffer in the current window (switch back and forth) |
| ~SPC b b~ | switch to a buffer using =helm= |
| ~SPC b d~ | kill the current buffer (does not delete the visited file) |
| ~SPC b D~ | kill the current buffer and its window |
| ~SPC b e~ | erase the content of the buffer (ask for confirmation) |
| ~SPC b h~ | open =*spacemacs*= home buffer |
| ~SPC b k~ | kill a buffer |
| ~SPC b K~ | kill all buffers except the current one |
| ~SPC b C-k~ | kill all buffers matching the regexp |
| ~SPC b m h~ | move a buffer to the left |
| ~SPC b m j~ | move a buffer to the bottom |
| ~SPC b m k~ | move a buffer to the top |
| ~SPC b m l~ | move a buffer to the right |
| ~SPC b M~ | swap windows using [[https://github.com/abo-abo/ace-window][ace-swap-window]] |
| ~SPC b n~ | switch to next buffer avoiding special buffers |
| ~SPC b p~ | switch to previous buffer avoiding special buffers |
| ~SPC b P~ | copy clipboard and replace buffer (useful when pasting from a browser) |
| ~SPC b R~ | revert the current buffer (reload from disk) |
| ~SPC b s~ | switch to the =*scratch*= buffer (create it if needed) |
| ~SPC b w~ | toggle read-only (writable state) |
| ~SPC b Y~ | copy whole buffer to clipboard (useful when copying to a browser) |
| ~z f~ | Make current function or comments visible in buffer as much as possible |
| Key Binding | Description |
|-----------------+--------------------------------------------------------------------------|
| ~SPC TAB~ | switch to alternate buffer in the current window (switch back and forth) |
| ~SPC b b~ | switch to a buffer using [[https://github.com/emacs-helm/helm][helm]] |
| ~SPC b d~ | kill the current buffer (does not delete the visited file) |
| ~SPC u SPC b d~ | kill the current buffer and window (does not delete the visited file) |
| ~SPC b D~ | kill a visible buffer using [[https://github.com/abo-abo/ace-window][ace-window]] |
| ~SPC u SPC b D~ | kill a visible buffer and its window using [[https://github.com/abo-abo/ace-window][ace-window]] |
| ~SPC b e~ | erase the content of the buffer (ask for confirmation) |
| ~SPC b h~ | open =*spacemacs*= home buffer |
| ~SPC b n~ | switch to next buffer avoiding special buffers |
| ~SPC b m~ | kill all buffers except the current one |
| ~SPC u SPC b m~ | kill all buffers and windows except the current one |
| ~SPC b M~ | kill all buffers matching the regexp |
| ~SPC b p~ | switch to previous buffer avoiding special buffers |
| ~SPC b P~ | copy clipboard and replace buffer (useful when pasting from a browser) |
| ~SPC b R~ | revert the current buffer (reload from disk) |
| ~SPC b s~ | switch to the =*scratch*= buffer (create it if needed) |
| ~SPC b w~ | toggle read-only (writable state) |
| ~SPC b Y~ | copy whole buffer to clipboard (useful when copying to a browser) |
| ~z f~ | Make current function or comments visible in buffer as much as possible |
**** Buffers manipulation transient state
A convenient buffer manipulation transient state allows to quickly cycles through

View File

@ -206,6 +206,16 @@ automatically applied to."
(when (assoc ?_ register-alist)
(jump-to-register ?_))))
(defun spacemacs/ace-center-window ()
"Ace center window."
(interactive)
(require 'ace-window)
(aw-select
" Ace - Center Window"
(lambda (window)
(aw-switch-to-window window)
(spacemacs-centered-buffer-mode))))
(defun spacemacs/useless-buffer-p (buffer)
"Determines if a buffer is useful."
(let ((buf-paren-major-mode (get (with-current-buffer buffer
@ -374,7 +384,9 @@ removal."
;; from magnars
(defun spacemacs/sudo-edit (&optional arg)
(interactive "p")
(let ((fname (if (or arg (not buffer-file-name)) (read-file-name "File: ") buffer-file-name)))
(let ((fname (if (or arg (not buffer-file-name))
(read-file-name "File: ")
buffer-file-name)))
(find-file
(cond ((string-match-p "^/ssh:" fname)
(with-temp-buffer
@ -383,7 +395,8 @@ removal."
(let ((last-match-end nil)
(last-ssh-hostname nil))
(while (string-match "@\\\([^:|]+\\\)" fname last-match-end)
(setq last-ssh-hostname (or (match-string 1 fname) last-ssh-hostname))
(setq last-ssh-hostname (or (match-string 1 fname)
last-ssh-hostname))
(setq last-match-end (match-end 0)))
(insert (format "|sudo:%s" (or last-ssh-hostname "localhost"))))
(buffer-string)))
@ -396,26 +409,66 @@ removal."
(when (and
(not (memq major-mode spacemacs-large-file-modes-list))
size (> size (* 1024 1024 dotspacemacs-large-file-size))
(y-or-n-p (format "%s is a large file, open literally to avoid performance issues?"
(y-or-n-p (format (concat "%s is a large file, open literally to "
"avoid performance issues?")
filename)))
(setq buffer-read-only t)
(buffer-disable-undo)
(fundamental-mode))))
(defun spacemacs/delete-window (&optional arg)
"Delete the current window.
If the universal prefix argument is used then kill the buffer too."
(interactive "P")
(if (equal '(4) arg)
(kill-buffer-and-window)
(delete-window)))
(defun spacemacs/ace-delete-window (&optional arg)
"Ace delete window.
If the universal prefix argument is used then kill the buffer too."
(interactive "P")
(require 'ace-window)
(aw-select
" Ace - Delete Window"
(lambda (window)
(when (equal '(4) arg)
(with-selected-window window
(spacemacs/kill-this-buffer arg)))
(aw-delete-window window))))
;; our own implementation of kill-this-buffer from menu-bar.el
(defun spacemacs/kill-this-buffer ()
"Kill the current buffer."
(interactive)
(defun spacemacs/kill-this-buffer (&optional arg)
"Kill the current buffer.
If the universal prefix argument is used then kill also the window."
(interactive "P")
(if (window-minibuffer-p)
(abort-recursive-edit)
(kill-buffer (current-buffer))))
(if (equal '(4) arg)
(kill-buffer-and-window)
(kill-buffer))))
(defun spacemacs/ace-kill-this-buffer (&optional arg)
"Ace kill visible buffer in a window.
If the universal prefix argument is used then kill also the window."
(interactive "P")
(require 'ace-window)
(let (golden-ratio-mode)
(aw-select
" Ace - Kill buffer in Window"
(lambda (window)
(with-selected-window window
(spacemacs/kill-this-buffer arg))))))
;; found at http://emacswiki.org/emacs/KillingBuffers
(defun spacemacs/kill-other-buffers ()
"Kill all other buffers."
(interactive)
(when (yes-or-no-p (format "Killing all buffers except \"%s\"? " (buffer-name)))
(defun spacemacs/kill-other-buffers (&optional arg)
"Kill all other buffers.
If the universal prefix argument is used then will the windows too."
(interactive "P")
(when (yes-or-no-p (format "Killing all buffers except \"%s\"? "
(buffer-name)))
(mapc 'kill-buffer (delq (current-buffer) (buffer-list)))
(when (equal '(4) arg) (delete-other-windows))
(message "Buffers deleted!")))
;; from http://dfan.org/blog/2009/02/19/emacs-dedicated-windows/

View File

@ -18,7 +18,6 @@
("ai" "irc")
("as" "shells")
("b" "buffers")
("bm" "move")
("c" "compile/comments")
("C" "capture/colors")
("e" "errors")
@ -117,17 +116,15 @@
"au" 'undo-tree-visualize)
;; buffers --------------------------------------------------------------------
(spacemacs/set-leader-keys
"bd" 'spacemacs/kill-this-buffer
"bD" 'kill-buffer-and-window
"TAB" 'spacemacs/alternate-buffer
"bh" 'spacemacs/home
"bd" 'spacemacs/kill-this-buffer
"be" 'spacemacs/safe-erase-buffer
"bK" 'spacemacs/kill-other-buffers
"bk" 'ido-kill-buffer
"b C-k" 'spacemacs/kill-matching-buffers-rudely
"bP" 'spacemacs/copy-clipboard-to-whole-buffer
"bh" 'spacemacs/home
"bk" 'spacemacs/kill-matching-buffers-rudely
"bn" 'spacemacs/next-useful-buffer
"bm" 'spacemacs/kill-other-buffers
"bN" 'spacemacs/new-empty-buffer
"bP" 'spacemacs/copy-clipboard-to-whole-buffer
"bp" 'spacemacs/previous-useful-buffer
"bR" 'spacemacs/safe-revert-buffer
"bs" 'spacemacs/switch-to-scratch-buffer
@ -360,7 +357,7 @@
"w2" 'spacemacs/layout-double-columns
"w3" 'spacemacs/layout-triple-columns
"wb" 'spacemacs/switch-to-minibuffer-window
"wd" 'delete-window
"wd" 'spacemacs/delete-window
"wt" 'spacemacs/toggle-current-window-dedication
"wf" 'follow-mode
"wF" 'make-frame
@ -381,7 +378,7 @@
"wl" 'evil-window-right
"w <right>" 'evil-window-right
"wm" 'spacemacs/toggle-maximize-buffer
"wM" 'spacemacs-centered-buffer-mode
"wc" 'spacemacs-centered-buffer-mode
"wo" 'other-frame
"wr" 'spacemacs/rotate-windows
"wR" 'spacemacs/rotate-windows-backward

View File

@ -12,6 +12,7 @@
(setq spacemacs-base-packages
'(
(abbrev :location built-in)
ace-window
(bookmark :location built-in)
(dired :location built-in)
(dired-x :location built-in)
@ -52,6 +53,20 @@
(defun spacemacs-base/init-abbrev ()
(spacemacs|hide-lighter abbrev-mode))
(defun spacemacs-base/init-ace-window ()
(use-package ace-window
:defer t
:init
(progn
(spacemacs/set-leader-keys
"bD" 'spacemacs/ace-kill-this-buffer
"wC" 'spacemacs/ace-center-window
"wD" 'spacemacs/ace-delete-window
"wM" 'ace-swap-window
"wW" 'ace-window)
;; set ace-window keys to home-row
(setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l)))))
(defun spacemacs-base/init-bookmark ()
(use-package bookmark
:defer t

View File

@ -153,7 +153,6 @@ The available configurations are:
- ace-window
- avy
- buffer-move
- comint
- company
- elfeed

View File

@ -13,7 +13,6 @@
'(
ace-window
avy
buffer-move
comint
company
elfeed
@ -57,19 +56,6 @@
:dvorak
(setq-default avy-keys '(?a ?o ?e ?u ?h ?t ?n ?s))))
(defun keyboard-layout/pre-init-buffer-move ()
(kl|config buffer-move
:description
"Remap `buffer-move' bindings."
:loader
(spacemacs|use-package-add-hook buffer-move :post-init BODY)
:common
(kl/leader-correct-keys
"bmh"
"bmj"
"bmk"
"bml")))
(defun keyboard-layout/pre-init-comint ()
(kl|config comint-mode
:description

View File

@ -11,8 +11,6 @@
(setq spacemacs-ui-packages
'(ace-link
ace-window
buffer-move
(centered-cursor :location local)
desktop
(doc-view :location built-in)
@ -60,28 +58,6 @@
(goto-char (1+ res))
(widget-button-press (point))))))))
(defun spacemacs-ui/init-ace-window ()
(use-package ace-window
:defer t
:init
(progn
(spacemacs/set-leader-keys
"bM" 'ace-swap-window
"wD" 'ace-delete-window
"w SPC" 'ace-window)
;; set ace-window keys to home-row
(setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l)))))
(defun spacemacs-ui/init-buffer-move ()
(use-package buffer-move
:defer t
:init
(spacemacs/set-leader-keys
"bmh" 'buf-move-left
"bmj" 'buf-move-down
"bmk" 'buf-move-up
"bml" 'buf-move-right)))
(defun spacemacs-ui/init-centered-cursor ()
(use-package centered-cursor-mode
:commands (centered-cursor-mode