branch: elpa/crux
commit dc1606b6d447cc8e27516f048f100f6ac05ff645
Author: Charles Comstock <[email protected]>
Commit: Charles Comstock <[email protected]>
Add crux-transpose-windows for swapping the buffers between two windows
This is copied directly from
https://www.emacswiki.org/emacs/TransposeWindows, and renamed to
crux-tranpose-windows. The wiki page mentions the original author as
Thomas Bellman. It does not appear to be published in any existing
package that I could find.
Amend documentation string to appease checkdoc
Added documentation explaining ARG count > 1 or < -1
Use cl-plusp over plusp
---
README.md | 1 +
crux.el | 16 ++++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/README.md b/README.md
index 840f85f..ced8cfa 100644
--- a/README.md
+++ b/README.md
@@ -50,6 +50,7 @@ Command | Suggested
Keybinding(s) |
`crux-view-url` | <kbd>C-c u</kbd> | Open a new
buffer containing the contents of URL.
`crux-eval-and-replace` | <kbd>C-c e</kbd> | Eval a bit of
Emacs Lisp code and replace it with its result.
`crux-swap-windows` | <kbd>C-c s</kbd> | Swap two
active windows.
+`crux-tranpose-windows` | <kbd>C-x 4 t</kbd> | Transpose
the buffers between two windows.
`crux-delete-file-and-buffer` | <kbd>C-c D</kbd> | Delete
current file and buffer.
`crux-rename-file-and-buffer` | <kbd>C-c r</kbd> | Rename the
current buffer and its visiting file if any.
`crux-visit-term-buffer` | <kbd>C-c t</kbd> | Open a
terminal emulator (`ansi-term`).
diff --git a/crux.el b/crux.el
index f7c1ec8..b81d664 100644
--- a/crux.el
+++ b/crux.el
@@ -346,6 +346,22 @@ buffer is not visiting a file."
(set-window-start w2 s1)))
(other-window 1))
+;; modified from https://www.emacswiki.org/emacs/TransposeWindows
+(defun crux-transpose-windows (arg)
+ "Transpose the buffers shown in two windows.
+Prefix ARG determines if the current windows buffer is swapped
+with the next or previous window, and the number of
+transpositions to execute in sequence."
+ (interactive "p")
+ (let ((selector (if (>= arg 0) 'next-window 'previous-window)))
+ (while (/= arg 0)
+ (let ((this-win (window-buffer))
+ (next-win (window-buffer (funcall selector))))
+ (set-window-buffer (selected-window) next-win)
+ (set-window-buffer (funcall selector) this-win)
+ (select-window (funcall selector)))
+ (setq arg (if (cl-plusp arg) (1- arg) (1+ arg))))))
+
(defun crux-switch-to-previous-buffer ()
"Switch to previously open buffer.
Repeated invocations toggle between the two most recently open buffers."