Skip to content

Instantly share code, notes, and snippets.

@djg
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djg/af42e453e06f47c568e0 to your computer and use it in GitHub Desktop.
Save djg/af42e453e06f47c568e0 to your computer and use it in GitHub Desktop.
;; I'm always opening a buffer in the wrong window. These function
;; help move the newly opened buffer to another window and restore the
;; buffer I was previously looking at.
(defun djg/buf-move (dir errmsg)
(let* ((other-win (windmove-find-other-window dir))
(buf-this-buf (window-buffer (selected-window))))
(if (null other-win)
(error errmsg)
(set-window-buffer other-win buf-this-buf)
(switch-to-prev-buffer))))
(defun djg/buf-move-left ()
"Move the current buffer left and replace with previous buffer.
If there is no split, ie no window on the left of the current
one, an error is signaled."
(interactive)
(djg/buf-move 'left "No left split"))
(defun djg/buf-move-right ()
"Move the current buffer right and replace with previous buffer.
If there is no split, ie no window on the right of the current
one, an error is signaled."
(interactive)
(djg/buf-move 'right "No right split"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment