Skip navigation

The windows split capabilities of emacs is something I didn’t know before and became quite an important aspects of my editing work habits.

An emacs window is a viewport that looks into a buffer. The emacs screen begins by displaying a single window, but this screen space can later be divided among two or more windows. On the screen, the current window holds the cursor and views the current buffer.
A windows views one buffer at a time. Multiple windows can view one buffer, each window may view different parts of the same buffer, and each window carries its own value of Point. Any change to a buffer will be reflected in all the windows viewing that buffer.

Even with rudimentary knowledge of elisp I managed to hack a few functions to go into my dot file (the configuration file of the editor) to deal with them.

For instance, I depend a lot on this is one in my workflow as I happen to need several files open simultaneously, plus the shell, some folder in dired mode, etc. With it I can be sort of zooming in and out, maximizing any buffer and going back to the split as I please .

;; I want to be able to conmute between a split and a single window (sort of "C-x 1" for the one on focus)
(defun toggle-windows-split()
"Switch back and forth between one window and whatever split of windows we might have in the frame. The idea is to maximize the current buffer, while being able to go back to the previous split of windows in the frame simply by calling this command again."
(interactive)
(if (not(window-minibuffer-p (selected-window)))
(progn
(if (< 1 (count-windows))
(progn
(window-configuration-to-register ?u)
(delete-other-windows))
(jump-to-register ?u))))
(my-iswitchb-close))

Then, the convenient key binding:
(define-key global-map (kbd "C-`") 'toggle-windows-split)
(define-key global-map (kbd "C-~") 'toggle-windows-split)
(define-key global-map (kbd "C-|") 'toggle-windows-split) ; same key, on a spanish keyword mapping since I commute a lot between both

Below, a tweaking of the function other-window to go back and some key bindings to cycle through windows.

;; Window shifting. C-x-o lets us go forward a window (or several).
;; This one lets us go back one or more windows. From Glickstein.
(defun other-window-backward (&optional n)
"Select previous Nth window."
(interactive "P")
(other-window (- (prefix-numeric-value n))))

(define-key global-map (kbd “”) ‘other-window) ; [PgUp]
(define-key global-map (kbd “”) ‘other-window-backward) ; [PgDn]

(global-set-key [(control tab)] ‘other-window)
(global-set-key [(shift control tab)] ‘other-window-backward)

Also (stolen from someone else’s dot file) this is needed to shrink/expand windows without using the mouse.

(define-key global-map (kbd "C-M-<left>") 'shrink-window-horizontally)
(define-key global-map (kbd "C-M-<right>") 'enlarge-window-horizontally)
(define-key global-map (kbd "C-M-<top>") 'enlarge-window)
(define-key global-map (kbd "C-M-<down>") 'shrink-window)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: