File: follow.el.html
follow-mode(var)/follow-mode(fun) is a minor mode that combines windows into one tall
virtual window.
The feeling of a "virtual window" has been accomplished by the use of two major techniques:
* The windows always display adjacent sections of the buffer.
This means that whenever one window is moved, all the
others will follow. (Hence the name Follow mode.)
* Should point (cursor) end up outside a window, another
window displaying that point is selected, if possible. This
makes it possible to walk between windows using normal cursor
movement commands.
Follow mode comes to its prime when a large screen and two side-by-side window are used. The user can, with the help of Follow mode, use two full-height windows as though they are one. Imagine yourself editing a large function, or section of text, and being able to use 144 lines instead of the normal 72... (your mileage may vary).
To test this package, make sure follow is loaded, or will be
autoloaded when activated (see below). Then do the following:
* Find your favorite file (preferably a long one).
* Resize Emacs so that it will be wide enough for two full size
columns. Delete the other windows and split the window with
the commands C-x 1 C-x 3.
* Give the command:
M-x follow-mode <RETURN>
* Now the display should look something like (assuming the text "71"
is on line 71):
+----------+----------+
|1 |73 |
|2 |74 |
|3 |75 |
... ...
|71 |143 |
|72 |144 |
+----------+----------+
As you can see, the right-hand window starts at line 73, the line
immediately below the end of the left-hand window. As long as
follow-mode(var)/follow-mode(fun) is active, the two windows will follow each other!
* Play around and enjoy! Scroll one window and watch the other.
Jump to the beginning or end. Press Cursor down at the last
line of the left-hand window. Enter new lines into the
text. Enter long lines spanning several lines, or several
windows.
* Should you find Follow mode annoying, just type
M-x follow-mode <RETURN>
to turn it off.
The command follow-delete-other-windows-and-split maximizes the
visible area of the current buffer.
I recommend adding it, and follow-mode(var)/follow-mode(fun), to hotkeys in the global
key map. To do so, add the following lines (replacing [f7] and
[f8] with your favorite keys) to the init file:
(global-set-key [f8] #'follow-mode)
(global-set-key [f7] #'follow-delete-other-windows-and-split)
There exist two system variables that control the appearance of
lines wider than the window containing them. The default is to
truncate long lines whenever a window isn't as wide as the frame.
To make sure lines are never truncated, place the following lines in your Init file:
(setq truncate-lines nil)
(setq truncate-partial-width-windows nil)
One way to configure Follow mode is to create one or more functions
that do whatever you would like to do. These functions are then
added to a hook.
The keymap follow-mode-map contains key bindings activated by
follow-mode(var)/follow-mode(fun).
Example:
(add-hook 'follow-mode-hook 'my-follow-mode-hook)
(defun my-follow-mode-hook ()
(define-key follow-mode-map "\\C-ca" #'your-favorite-function)
(define-key follow-mode-map "\\C-cb" #'another-function))
Usage:
To activate, issue the command "M-x follow-mode" and press Return. To deactivate, do it again.
The following is a list of commands useful when follow-mode(var)/follow-mode(fun) is active.
follow-scroll-up C-c . C-v
Scroll text in a Follow mode window chain up.
follow-scroll-down C-c . v
Like follow-scroll-up, but in the other direction.
follow-delete-other-windows-and-split C-c . 1
Maximize the visible area of the current buffer,
and enter Follow mode. This is a very convenient
way to start Follow mode, hence we recommend that
this command be added to the global keymap.
follow-recenter C-c . C-l
Place point in the center of the middle window,
or a specified number of lines from either top or bottom.
follow-switch-to-buffer C-c . b
Switch buffer in all windows displaying the current buffer
in this frame.
follow-switch-to-buffer-all C-c . C-b
Switch buffer in all windows in the selected frame.
follow-switch-to-current-buffer-all
Show the current buffer in all windows on the current
frame and turn on follow-mode(var)/follow-mode(fun).
follow-first-window C-c . <
Select the first window in the frame showing the same buffer.
follow-last-window C-c . >
Select the last window in the frame showing the same buffer.
follow-next-window C-c . n
Select the next window in the frame showing the same buffer.
follow-previous-window C-c . p
Select the previous window showing the same buffer.
Well, it seems ok, but what if I really want to look at two different
positions in the text? Here are two simple methods to use:
1) Use multiple frames; follow mode only affects windows displayed
in the same frame. (My apologies to you who can't use frames.)
2) Bind follow-mode(var)/follow-mode(fun) to key so you can turn it off whenever
you want to view two locations. Of course, follow-mode(var)/follow-mode(fun) can
be reactivated by hitting the same key again.
Example from my ~/.emacs:
(global-set-key [f8] #'follow-mode)
Implementation:
The main method by which Follow mode aligns windows is via the
function follow-pre-redisplay-function, which is run before each
redisplay. This "fixes up" the alignment of other windows which are
showing the same Follow mode buffer, on the same frame as the
selected window. It does not try to deal with buffers other than
the buffer of the selected frame, or windows on other frames.
Comint mode specially calls follow-comint-scroll-to-bottom on
Follow mode buffers. This function scrolls the bottom-most window
in a window chain and aligns the other windows accordingly. Follow
mode adds a function to compilation-filter-hook to align
compilation buffers.
Defined variables (17)
follow-active-menu | The menu visible when Follow mode is active. |
follow-auto | Non-nil activates Follow mode whenever a file is loaded. |
follow-cache-command-list | List of commands that don’t require recalculation. |
follow-debug | If non-nil, emit Follow mode debugging messages. |
follow-fixed-window | If non-nil, the current window must not be scrolled. |
follow-hide-ghost-cursors | When non-nil, Follow mode attempts to hide the obtrusive cursors |
follow-inactive-menu | The menu visible when Follow mode is inactive. |
follow-inside-post-command-hook-call | Non-nil when inside Follow modes ‘post-command-hook’. |
follow-internal-force-redisplay | Non-nil when Follow mode should redisplay the windows. |
follow-mode | Non-nil if Follow mode is enabled. |
follow-mode-hook | Normal hook run by ‘follow-mode’. |
follow-mode-line-text | Text shown in the mode line when Follow mode is active. |
follow-mode-map | Minor mode keymap for Follow mode. |
follow-mode-prefix | Prefix key to use for follow commands in Follow mode. |
follow-prev-buffer | The buffer current at the last call to ‘follow-adjust-window’ or nil. |
follow-start-end-invalid | When non-nil, indicates ‘follow-windows-start-end-cache’ is invalid. |
follow-windows-start-end-cache | Cache used by ‘follow-window-start’ and ‘follow-window-end’. |