Move window manipulation functions to the Org config
This commit is contained in:
parent
dea44d7d39
commit
38dd27dc1e
@ -498,6 +498,92 @@ Copied from http://emacs-doctor.com/emacs-strip-tease.html
|
||||
"Use M-x hidden-mode-line-mode to make mode-line appear."))))
|
||||
#+END_SRC
|
||||
|
||||
** Window manipulation
|
||||
|
||||
*** Transpose windows
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(defun transpose-windows (arg)
|
||||
"Transpose the buffers shown in two windows."
|
||||
(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 (plusp arg) (1- arg) (1+ arg))))))
|
||||
#+END_SRC
|
||||
|
||||
*** Toggle window split between horizontal and vertical
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(defun toggle-window-split ()
|
||||
(interactive)
|
||||
(if (= (count-windows) 2)
|
||||
(let* ((this-win-buffer (window-buffer))
|
||||
(next-win-buffer (window-buffer (next-window)))
|
||||
(this-win-edges (window-edges (selected-window)))
|
||||
(next-win-edges (window-edges (next-window)))
|
||||
(this-win-2nd (not (and (<= (car this-win-edges)
|
||||
(car next-win-edges))
|
||||
(<= (cadr this-win-edges)
|
||||
(cadr next-win-edges)))))
|
||||
(splitter
|
||||
(if (= (car this-win-edges)
|
||||
(car (window-edges (next-window))))
|
||||
'split-window-horizontally
|
||||
'split-window-vertically)))
|
||||
(delete-other-windows)
|
||||
(let ((first-win (selected-window)))
|
||||
(funcall splitter)
|
||||
(if this-win-2nd (other-window 1))
|
||||
(set-window-buffer (selected-window) this-win-buffer)
|
||||
(set-window-buffer (next-window) next-win-buffer)
|
||||
(select-window first-win)
|
||||
(if this-win-2nd (other-window 1))))
|
||||
(error "This works only for two windows!")))
|
||||
#+END_SRC
|
||||
|
||||
*** Scroll up or down in a specific window
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(defun gpolonkai/scroll-window-up (window)
|
||||
"Scroll WINDOW up as `scroll-up-command' would."
|
||||
(interactive)
|
||||
(save-selected-window
|
||||
(select-window window)
|
||||
(scroll-up)))
|
||||
|
||||
(defun gpolonkai/scroll-window-down (window)
|
||||
"Scroll WINDOW down as `scroll-down-command' would."
|
||||
(interactive)
|
||||
(save-selected-window
|
||||
(select-window window)
|
||||
(scroll-down)))
|
||||
#+END_SRC
|
||||
|
||||
*** Bury a window
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(defun gpolonkai/bury-window (window)
|
||||
"Quit WINDOW without killing it."
|
||||
(interactive)
|
||||
(quit-window nil window))
|
||||
#+END_SRC
|
||||
|
||||
*** Kill current buffer and delete its window
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(defun gpolonkai/kill-this-buffer-delete-this-window ()
|
||||
"Kill the buffer in the current window, and then try to delete
|
||||
the current window."
|
||||
(interactive)
|
||||
(kill-this-buffer)
|
||||
(delete-window))
|
||||
#+END_SRC
|
||||
|
||||
** ~c-mode~ related
|
||||
|
||||
*** Copy the prototype of the current function
|
||||
|
1
init.el
1
init.el
@ -28,7 +28,6 @@
|
||||
;; Load my own functions
|
||||
(load "gnu-c-header")
|
||||
(load "round-number-to-decimals")
|
||||
(load "window-manip")
|
||||
|
||||
;; From gmane.emacs.orgmode
|
||||
;; (http://article.gmane.org/gmane.emacs.orgmode/75222)
|
||||
|
@ -1,63 +0,0 @@
|
||||
(defun transpose-windows (arg)
|
||||
"Transpose the buffers shown in two windows."
|
||||
(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 (plusp arg) (1- arg) (1+ arg))))))
|
||||
|
||||
(defun toggle-window-split ()
|
||||
(interactive)
|
||||
(if (= (count-windows) 2)
|
||||
(let* ((this-win-buffer (window-buffer))
|
||||
(next-win-buffer (window-buffer (next-window)))
|
||||
(this-win-edges (window-edges (selected-window)))
|
||||
(next-win-edges (window-edges (next-window)))
|
||||
(this-win-2nd (not (and (<= (car this-win-edges)
|
||||
(car next-win-edges))
|
||||
(<= (cadr this-win-edges)
|
||||
(cadr next-win-edges)))))
|
||||
(splitter
|
||||
(if (= (car this-win-edges)
|
||||
(car (window-edges (next-window))))
|
||||
'split-window-horizontally
|
||||
'split-window-vertically)))
|
||||
(delete-other-windows)
|
||||
(let ((first-win (selected-window)))
|
||||
(funcall splitter)
|
||||
(if this-win-2nd (other-window 1))
|
||||
(set-window-buffer (selected-window) this-win-buffer)
|
||||
(set-window-buffer (next-window) next-win-buffer)
|
||||
(select-window first-win)
|
||||
(if this-win-2nd (other-window 1))))
|
||||
(error "This works only for two windows!")))
|
||||
|
||||
(defun gpolonkai/scroll-window-up (window)
|
||||
"Scroll WINDOW up as `scroll-up-command' would."
|
||||
(interactive)
|
||||
(save-selected-window
|
||||
(select-window window)
|
||||
(scroll-up)))
|
||||
|
||||
(defun gpolonkai/scroll-window-down (window)
|
||||
"Scroll WINDOW down as `scroll-down-command' would."
|
||||
(interactive)
|
||||
(save-selected-window
|
||||
(select-window window)
|
||||
(scroll-down)))
|
||||
|
||||
(defun gpolonkai/bury-window (window)
|
||||
"Quit WINDOW without killing it."
|
||||
(interactive)
|
||||
(quit-window nil window))
|
||||
|
||||
(defun gpolonkai/kill-this-buffer-delete-this-window ()
|
||||
"Kill the buffer in the current window, and then try to delete
|
||||
the current window."
|
||||
(interactive)
|
||||
(kill-this-buffer)
|
||||
(delete-window))
|
Loading…
Reference in New Issue
Block a user