(vc-register): Allow registering a file passed as a
[bpt/emacs.git] / lisp / follow.el
index ef1b223..3edc62e 100644 (file)
@@ -1,19 +1,18 @@
 ;;; follow.el --- synchronize windows showing the same buffer
 
 ;; Copyright (C) 1995, 1996, 1997, 1999, 2001, 2002, 2003, 2004,
-;;   2005 Free Software Foundation, Inc.
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: Anders Lindgren <andersl@andersl.com>
 ;; Maintainer: FSF (Anders' email bounces, Sep 2005)
 ;; Created: 1995-05-25
 ;; Keywords: display, window, minor-mode, convenience
-;; Last Changed: 1999-11-17
 
 ;; This file is part of GNU Emacs.
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -36,9 +35,9 @@
 ;; The feeling of a "virtual window" has been accomplished by the use
 ;; of two major techniques:
 ;;
-;; * The windows always displays adjacent sections of the buffer.
+;; * 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.)
+;;   others will follow.  (Hence the name Follow mode.)
 ;;
 ;; * Should the point (cursor) end up outside a window, another
 ;;   window displaying that point is selected, if possible.  This
 ;;   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 would have been
-;; one. Imagine yourself editing a large function, or section of text,
+;; 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:
+;; autoloaded when activated (see below).  Then do the following:
 ;;
 ;; * Find your favorite file (preferably a long one).
 ;;
 ;;                 +----------+----------+
 ;;
 ;;   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' is active, the two windows will follow eachother!
+;;   immediately below the end of the left-hand window.  As long as
+;;   `follow-mode' 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
+;;   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
 ;; (global-set-key [f7] 'follow-delete-other-windows-and-split)
 
 
-;; There exists two system variables that controls the appearence of
-;; lines that are wider than the window containing them.  The default
-;; is to truncate long lines whenever a window isn't as wide as the
-;; frame.
+;; There exist two system variables that control the appearence 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, please place the following
 ;; lines in your init file:
 
 
 ;; The correct way to cofigurate Follow mode, or any other mode for
-;; that matter, is to create one (or more) function that does
-;; whatever you would like to do.  The function is then added to
+;; that matter, is to create one or more functions that do
+;; whatever you would like to do.  These functions are then added to
 ;; a hook.
 ;;
 ;; When `Follow' mode is activated, functions stored in the hook
 
 ;; Usage:
 ;;
-;; To activate issue the command "M-x follow-mode"
-;; and press return. To deactivate, do it again.
+;; 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 is active.
 ;;
 ;;     follow-scroll-up                         C-c . C-v
-;;             Scroll text in a Follow Mode window chain up.
+;;             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
-;;             Maximise the visible area of the current buffer,
-;;             and enter Follow Mode.  This is a very convenient
-;;             way to start Follow Mode, hence it is recomended
-;;             that this command is added to the global keymap.
+;;             Maximize the visible area of the current buffer,
+;;             and enter Follow mode.  This is a very convenient
+;;             way to start Follow mode, hence we recomend that
+;;             this command be added to the global keymap.
 ;;
 ;;     follow-recenter                          C-c . C-l
 ;;             Place the point in the center of the middle window,
 ;;             in this frame.
 ;;
 ;;     follow-switch-to-buffer-all              C-c . C-b
-;;             Switch buffer in all windows in the active frame.
+;;             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
 ;;    in the same frame. (My apoligies to you who can't use frames.)
 ;;
 ;; 2) Bind `follow-mode' to key so you can turn it off whenever
-;;    you want to view two locations. Of course, `follow' mode can
+;;    you want to view two locations.  Of course, `follow' mode can
 ;;    be reactivated by hitting the same key again.
 ;;
 ;;    Example from my ~/.emacs:
 ;;
 ;; In an ideal world, follow mode would have been implemented in the
 ;; kernel of the display routines, making sure that the windows (using
-;; follow mode) ALWAYS are aligned. On planet earth, however, we must
+;; follow mode) ALWAYS are aligned.  On planet Earth, however, we must
 ;; accept a solution where we ALMOST ALWAYS can make sure that the
 ;; windows are aligned.
 ;;
 ;;
 ;; Note that only the selected window is checked, for the reason of
 ;; efficiency and code complexity. (I.e. it is possible to make a
-;; non-selected windows unaligned. It will, however, pop right back
+;; non-selected windows unaligned.  It will, however, pop right back
 ;; when it is selected.)
 
 ;;}}}
 ;; Should someone come up with a better solution, please let me
 ;; know.
 
+(require 'easymenu)
+
 (eval-when-compile
   (if (or (featurep 'bytecomp)
          (featurep 'byte-compile))
-      (cond ((string-match "XEmacs" emacs-version)
+      (cond ((featurep 'xemacs)
             ;; Make XEmacs shut up!  I'm using standard Emacs
             ;; functions, they are NOT obsolete!
             (if (eq (get 'force-mode-line-update 'byte-compile)
   :group 'windows
   :group 'convenience)
 
-(defvar follow-mode nil
-  "Variable indicating if Follow mode is active.")
-
 (defcustom follow-mode-hook nil
-  "*Hooks to run when follow-mode is turned on."
+  "Normal hook run by `follow-mode'."
   :type 'hook
   :group 'follow)
 
 (defcustom follow-mode-off-hook nil
-  "*Hooks to run when follow-mode is turned off."
+  "Hooks to run when Follow mode is turned off."
   :type 'hook
   :group 'follow)
+(make-obsolete-variable 'follow-mode-off-hook 'follow-mode-hook "22.2")
+
+;;{{{ Keymap/Menu
+
+;; Define keys for the follow-mode minor mode map and replace some
+;; functions in the global map.  All `follow' mode special functions
+;; can be found on (the somewhat cumbersome) "C-c . <key>"
+;; (Control-C dot <key>). (As of Emacs 19.29 the keys
+;; C-c <punctuation character> are reserved for minor modes.)
+;;
+;; To change the prefix, redefine `follow-mode-prefix' before
+;; `follow' is loaded, or see the section on `follow-mode-hook'
+;; above for an example of how to bind the keys the way you like.
+;;
+;; Please note that the keymap is defined the first time this file is
+;; loaded.  Also note that the only legal way to manipulate the
+;; keymap is to use `define-key'.  Don't change it using `setq' or
+;; similar!
+
+(defcustom follow-mode-prefix "\C-c."
+  "Prefix key to use for follow commands in Follow mode.
+The value of this variable is checked as part of loading Follow mode.
+After that, changing the prefix key requires manipulating keymaps."
+  :type 'string
+  :group 'follow)
+
+(defvar follow-mode-map
+  (let ((mainmap (make-sparse-keymap))
+        (map (make-sparse-keymap)))
+    (define-key map "\C-v"     'follow-scroll-up)
+    (define-key map "\M-v"     'follow-scroll-down)
+    (define-key map "v"                'follow-scroll-down)
+    (define-key map "1"                'follow-delete-other-windows-and-split)
+    (define-key map "b"                'follow-switch-to-buffer)
+    (define-key map "\C-b"     'follow-switch-to-buffer-all)
+    (define-key map "\C-l"     'follow-recenter)
+    (define-key map "<"                'follow-first-window)
+    (define-key map ">"                'follow-last-window)
+    (define-key map "n"                'follow-next-window)
+    (define-key map "p"                'follow-previous-window)
+
+    (define-key mainmap follow-mode-prefix map)
+
+    ;; Replace the standard `end-of-buffer', when in Follow mode.  (I
+    ;; don't see the point in trying to replace every function that
+    ;; could be enhanced in Follow mode.  End-of-buffer is a special
+    ;; case since it is very simple to define and it greatly enhances
+    ;; the look and feel of Follow mode.)
+    (define-key mainmap [remap end-of-buffer] 'follow-end-of-buffer)
+
+    mainmap)
+  "Minor mode keymap for Follow mode.")
+
+;; When the mode is not activated, only one item is visible to activate
+;; the mode.
+(defun follow-menu-filter (menu)
+  (if (bound-and-true-p follow-mode)
+      menu
+    '(["Follow mode"   follow-mode
+       :style toggle :selected follow-mode])))
+
+;; If there is a `tools' menu, we use it.  However, we can't add a
+;; minor-mode specific item to it (it's broken), so we make the
+;; contents ghosted when not in use, and add ourselves to the
+;; global map.
+(easy-menu-add-item nil '("Tools")
+  '("Follow"
+    ;; The Emacs code used to just grey out operations when follow-mode was
+    ;; not enabled, whereas the XEmacs code used to remove it altogether.
+    ;; Not sure which is preferable, but clearly the preference should not
+    ;; depend on the flavor.
+    :filter follow-menu-filter
+    ["Scroll Up"       follow-scroll-up        follow-mode]
+    ["Scroll Down"     follow-scroll-down      follow-mode]
+    "--"
+    ["Delete Other Windows and Split" follow-delete-other-windows-and-split follow-mode]
+    "--"
+    ["Switch To Buffer"        follow-switch-to-buffer follow-mode]
+    ["Switch To Buffer (all windows)" follow-switch-to-buffer-all follow-mode]
+    "--"
+    ["First Window"    follow-first-window     follow-mode]
+    ["Last Window"     follow-last-window      follow-mode]
+    ["Next Window"     follow-next-window      follow-mode]
+    ["Previous Window" follow-previous-window  follow-mode]
+    "--"
+    ["Recenter"                follow-recenter         follow-mode]
+    "--"
+    ["Follow mode"     follow-mode :style toggle :selected follow-mode]))
 
-(defvar follow-mode-map nil
-  "*Minor mode keymap for Follow mode.")
+;;}}}
 
 (defcustom follow-mode-line-text " Follow"
-  "*Text shown in the mode line when Follow mode is active.
+  "Text shown in the mode line when Follow mode is active.
 Defaults to \" Follow\".  Examples of other values
 are \" Fw\", or simply \"\"."
   :type 'string
   :group 'follow)
 
 (defcustom follow-auto nil
-  "*Non-nil activates Follow mode whenever a file is loaded."
+  "Non-nil activates Follow mode whenever a file is loaded."
   :type 'boolean
   :group 'follow)
 
-(defcustom follow-mode-prefix "\C-c."
-  "*Prefix key to use for follow commands in Follow mode.
-The value of this variable is checked as part of loading Follow mode.
-After that, changing the prefix key requires manipulating keymaps."
-  :type 'string
-  :group 'follow)
-
-(defcustom follow-intercept-processes
-  (fboundp 'start-process)
-  "*When non-nil, Follow Mode will monitor process output."
+(defcustom follow-intercept-processes (fboundp 'start-process)
+  "When non-nil, Follow mode will monitor process output."
   :type 'boolean
   :group 'follow)
 
-(defvar follow-emacs-version-xemacs-p
-  (string-match "XEmacs" emacs-version)
-  "Non-nil when running under XEmacs.")
-
-(defvar follow-avoid-tail-recenter-p
-  (not follow-emacs-version-xemacs-p)
-  "*When non-nil, patch emacs so that tail windows won't be recentered.
+(defvar follow-avoid-tail-recenter-p (not (featurep 'xemacs))
+  "*When non-nil, patch Emacs so that tail windows won't be recentered.
 
 A \"tail window\" is a window that displays only the end of
 the buffer.  Normally it is practical for the user that empty
 windows are recentered automatically.  However, when using
-Follow Mode it breaks the display when the end is displayed
+Follow mode it breaks the display when the end is displayed
 in a window \"above\" the last window.  This is for
 example the case when displaying a short page in info.
 
-Must be set before Follow Mode is loaded.
+Must be set before Follow mode is loaded.
 
 Please note that it is not possible to fully prevent Emacs from
 recentering empty windows.  Please report if you find a repeatable
@@ -380,38 +451,6 @@ Used by `follow-window-size-change'.")
 (defvar follow-windows-start-end-cache nil
   "Cache used by `follow-window-start-end'.")
 
-;;}}}
-;;{{{ Bug report
-
-(eval-when-compile (require 'reporter))
-
-(defun follow-submit-feedback ()
-  "Submit feedback on Follow mode to the author: andersl@andersl.com"
-  (interactive)
-  (require 'reporter)
-  (and (y-or-n-p "Do you really want to submit a report on Follow mode? ")
-       (reporter-submit-bug-report
-       "Anders Lindgren <andersl@andersl.com>"
-       "follow.el"
-       '(post-command-hook
-         pre-command-hook
-         window-size-change-functions
-         window-scroll-functions
-         follow-mode-hook
-         follow-mode-off-hook
-         follow-auto
-         follow-intercept-processes
-         follow-avoid-tail-recenter-p
-         follow-process-filter-alist)
-       nil
-       nil
-       (concat
-        "Hi Anders!\n\n"
-        "(I have read the section on how to report bugs in the "
-        "Emacs manual.)\n\n"
-        "Even though I know you are busy, I thought you might "
-        "want to know...\n\n"))))
-
 ;;}}}
 ;;{{{ Debug messages
 
@@ -424,190 +463,11 @@ Used by `follow-window-size-change'.")
   (if (and (boundp 'follow-debug) follow-debug)
       (apply 'message args)))
 
-;;}}}
-
-;;{{{ Keymap/Menu
-
-;;; Define keys for the follow-mode minor mode map and replace some
-;;; functions in the global map.  All `follow' mode special functions
-;;; can be found on (the somewhat cumbersome) "C-c . <key>"
-;;; (Control-C dot <key>). (As of Emacs 19.29 the keys
-;;; C-c <punctuation character> are reserved for minor modes.)
-;;;
-;;; To change the prefix, redefine `follow-mode-prefix' before
-;;; `follow' is loaded, or see the section on `follow-mode-hook'
-;;; above for an example of how to bind the keys the way you like.
-;;;
-;;; Please note that the keymap is defined the first time this file is
-;;; loaded.  Also note that the only legal way to manipulate the
-;;; keymap is to use `define-key'.  Don't change it using `setq' or
-;;; similar!
-
-
-(if follow-mode-map
-    nil
-  (setq follow-mode-map (make-sparse-keymap))
-  (let ((map (make-sparse-keymap)))
-    (define-key map "\C-v"     'follow-scroll-up)
-    (define-key map "\M-v"     'follow-scroll-down)
-    (define-key map "v"                'follow-scroll-down)
-    (define-key map "1"                'follow-delete-other-windows-and-split)
-    (define-key map "b"                'follow-switch-to-buffer)
-    (define-key map "\C-b"     'follow-switch-to-buffer-all)
-    (define-key map "\C-l"     'follow-recenter)
-    (define-key map "<"                'follow-first-window)
-    (define-key map ">"                'follow-last-window)
-    (define-key map "n"                'follow-next-window)
-    (define-key map "p"                'follow-previous-window)
-
-    (define-key follow-mode-map follow-mode-prefix map)
-
-    ;; Replace the standard `end-of-buffer', when in Follow Mode.  (I
-    ;; don't see the point in trying to replace every function that
-    ;; could be enhanced in Follow mode.  End-of-buffer is a special
-    ;; case since it is very simple to define and it greatly enhances
-    ;; the look and feel of Follow mode.)
-    ;;
-    ;; (The function `substitute-key-definition' does not work
-    ;; in all versions of Emacs.)
-    (mapcar
-     (function
-      (lambda (pair)
-       (let ((old (car pair))
-             (new (cdr pair)))
-         (mapcar (function (lambda (key)
-                             (define-key follow-mode-map key new)))
-                 (where-is-internal old global-map)))))
-     '((end-of-buffer      . follow-end-of-buffer)
-       (fkey-end-of-buffer . follow-end-of-buffer)))
-
-    ;;;
-    ;;; The menu.
-    ;;;
-
-    (if (not follow-emacs-version-xemacs-p)
-
-       ;;
-       ;; Emacs
-       ;;
-       (let ((menumap (funcall (symbol-function 'make-sparse-keymap)
-                       "Follow"))
-             (count 0)
-             id)
-         (mapcar
-          (function
-           (lambda (item)
-             (setq id
-                   (or (cdr item)
-                       (progn
-                         (setq count (+ count 1))
-                         (intern (format "separator-%d" count)))))
-             (define-key menumap (vector id) item)
-             (or (eq id 'follow-mode)
-                 (put id 'menu-enable 'follow-mode))))
-          ;; In reverse order:
-          '(("Toggle Follow mode" . follow-mode)
-            ("--")
-            ("Recenter"           . follow-recenter)
-            ("--")
-            ("Previous Window"    . follow-previous-window)
-            ("Next Windows"       . follow-next-window)
-            ("Last Window"        . follow-last-window)
-            ("First Window"       . follow-first-window)
-            ("--")
-            ("Switch To Buffer (all windows)"
-                                  . follow-switch-to-buffer-all)
-            ("Switch To Buffer"   . follow-switch-to-buffer)
-            ("--")
-            ("Delete Other Windows and Split"
-                                  . follow-delete-other-windows-and-split)
-            ("--")
-            ("Scroll Down"        . follow-scroll-down)
-            ("Scroll Up"          . follow-scroll-up)))
-
-         ;; If there is a `tools' meny, we use it. However, we can't add a
-         ;; minor-mode specific item to it (it's broken), so we make the
-         ;; contents ghosted when not in use, and add ourselves to the
-         ;; global map.  If no `tools' menu is present, just make a
-         ;; top-level menu visible when the mode is activated.
-
-         (let ((tools-map (lookup-key (current-global-map) [menu-bar tools]))
-               (last nil))
-           (if (sequencep tools-map)
-               (progn
-                 ;; Find the last entry in the menu and store it in `last'.
-                 (mapcar (function
-                          (lambda (x)
-                            (setq last (or (cdr-safe
-                                            (cdr-safe
-                                             (cdr-safe x)))
-                                           last))))
-                         tools-map)
-                 (if last
-                     (progn
-                       (funcall (symbol-function 'define-key-after)
-                                 tools-map [separator-follow] '("--") last)
-                       (funcall (symbol-function 'define-key-after)
-                                tools-map [follow] (cons "Follow" menumap)
-                                'separator-follow))
-                   ;; Didn't find the last item, Adding to the top of
-                   ;; tools.  (This will probably never happend...)
-                   (define-key (current-global-map) [menu-bar tools follow]
-                     (cons "Follow" menumap))))
-             ;; No tools menu, add "Follow" to the menubar.
-             (define-key follow-mode-map [menu-bar follow]
-               (cons "Follow" menumap)))))
-
-      ;;
-      ;; XEmacs.
-      ;;
-
-      ;; place the menu in the `Tools' menu.
-      (let ((menu '("Follow"
-                   :filter follow-menu-filter
-                   ["Scroll Up" follow-scroll-up t]
-                   ["Scroll Down" follow-scroll-down t]
-                   ["Delete Other Windows and Split"
-                    follow-delete-other-windows-and-split t]
-                   ["Switch To Buffer" follow-switch-to-buffer t]
-                   ["Switch To Buffer (all windows)"
-                    follow-switch-to-buffer-all t]
-                   ["First Window" follow-first-window t]
-                   ["Last Window" follow-last-window t]
-                   ["Next Windows" follow-next-window t]
-                   ["Previous Window" follow-previous-window t]
-                   ["Recenter" follow-recenter t]
-                   ["Deactivate" follow-mode t])))
-
-       ;; Why not just `(set-buffer-menubar current-menubar)'?  The
-       ;; question is a very good question.  The reason is that under
-       ;; Emacs, neither `set-buffer-menubar' nor
-       ;; `current-menubar' is defined, hence the byte-compiler will
-       ;; warn.
-       (funcall (symbol-function 'set-buffer-menubar)
-                (symbol-value 'current-menubar))
-       (funcall (symbol-function 'add-submenu) '("Tools") menu))
-
-      ;; When the mode is not activated, only one item is visible:
-      ;; "Activate".
-      (defun follow-menu-filter (menu)
-       (if follow-mode
-           menu
-         '(["Activate          " follow-mode t]))))))
-
-
-;;; Register the follow mode keymap.
-(or (assq 'follow-mode minor-mode-map-alist)
-    (setq minor-mode-map-alist
-         (cons (cons 'follow-mode follow-mode-map) minor-mode-map-alist)))
-
 ;;}}}
 ;;{{{ Cache
 
-(let ((cmds follow-cache-command-list))
-  (while cmds
-    (put (car cmds) 'follow-mode-use-cache t)
-    (setq cmds (cdr cmds))))
+(dolist (cmd follow-cache-command-list)
+  (put cmd 'follow-mode-use-cache t))
 
 ;;}}}
 
@@ -615,20 +475,18 @@ Used by `follow-window-size-change'.")
 
 ;;;###autoload
 (defun turn-on-follow-mode ()
-  "Turn on Follow mode. Please see the function `follow-mode'."
-  (interactive)
+  "Turn on Follow mode.  Please see the function `follow-mode'."
   (follow-mode 1))
 
 
 ;;;###autoload
 (defun turn-off-follow-mode ()
-  "Turn off Follow mode. Please see the function `follow-mode'."
-  (interactive)
+  "Turn off Follow mode.  Please see the function `follow-mode'."
   (follow-mode -1))
 
-
+(put 'follow-mode 'permanent-local t)
 ;;;###autoload
-(defun follow-mode (arg)
+(define-minor-mode follow-mode
   "Minor mode that combines windows into one tall virtual window.
 
 The feeling of a \"virtual window\" has been accomplished by the use
@@ -636,7 +494,7 @@ of two major techniques:
 
 * The windows always displays adjacent sections of the buffer.
   This means that whenever one window is moved, all the
-  others will follow.  (Hence the name Follow Mode.)
+  others will follow.  (Hence the name Follow mode.)
 
 * Should the point (cursor) end up outside a window, another
   window displaying that point is selected, if possible.  This
@@ -644,9 +502,9 @@ of two major techniques:
   movement commands.
 
 Follow mode comes to its prime when used on a large screen and two
-side-by-side window are used. The user can, with the help of Follow
+side-by-side windows are used.  The user can, with the help of Follow
 mode, use two full-height windows as though they would have been
-one. Imagine yourself editing a large function, or section of text,
+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).
 
@@ -654,50 +512,29 @@ To split one large window into two side-by-side windows, the commands
 `\\[split-window-horizontally]' or \
 `M-x follow-delete-other-windows-and-split' can be used.
 
-Only windows displayed in the same frame follow each-other.
+Only windows displayed in the same frame follow each other.
 
 If the variable `follow-intercept-processes' is non-nil, Follow mode
 will listen to the output of processes and redisplay accordingly.
 \(This is the default.)
 
-When Follow mode is switched on, the hook `follow-mode-hook'
-is called.  When turned off, `follow-mode-off-hook' is called.
+This command runs the normal hook `follow-mode-hook'.
 
 Keys specific to Follow mode:
 \\{follow-mode-map}"
-  (interactive "P")
-  (make-local-variable 'follow-mode)
-  (put 'follow-mode 'permanent-local t)
-  (let ((follow-mode-orig follow-mode))
-    (setq follow-mode
-         (if (null arg)
-             (not follow-mode)
-           (> (prefix-numeric-value arg) 0)))
-    (if (and follow-mode follow-intercept-processes)
-       (follow-intercept-process-output))
-    (cond ((and follow-mode (not follow-mode-orig)) ; On
-          ;; XEmacs: If this is non-nil, the window will scroll before
-          ;; the point will have a chance to get into the next window.
-          (if (boundp 'scroll-on-clipped-lines)
-              (set 'scroll-on-clipped-lines nil))
-          (force-mode-line-update)
-          (add-hook 'post-command-hook 'follow-post-command-hook t)
-          (run-hooks 'follow-mode-hook))
-
-         ((and (not follow-mode) follow-mode-orig) ; Off
-          (force-mode-line-update)
-          (run-hooks 'follow-mode-off-hook)))))
-
-
-;; Register follow-mode as a minor mode.
-
-(if (fboundp 'add-minor-mode)
-    ;; XEmacs
-    (funcall (symbol-function 'add-minor-mode)
-            'follow-mode 'follow-mode-line-text)
-  (or (assq 'follow-mode minor-mode-alist)
-      (setq minor-mode-alist
-           (cons '(follow-mode follow-mode-line-text) minor-mode-alist))))
+  :keymap follow-mode-map
+  (when (and follow-mode follow-intercept-processes)
+    (follow-intercept-process-output))
+  (cond (follow-mode ; On
+         ;; XEmacs: If this is non-nil, the window will scroll before
+         ;; the point will have a chance to get into the next window.
+         (when (boundp 'scroll-on-clipped-lines)
+          (setq scroll-on-clipped-lines nil))
+         (force-mode-line-update)
+         (add-hook 'post-command-hook 'follow-post-command-hook t))
+
+        ((not follow-mode) ; Off
+         (force-mode-line-update))))
 
 ;;}}}
 ;;{{{ Find file hook
@@ -708,7 +545,7 @@ Keys specific to Follow mode:
 (add-hook 'find-file-hook 'follow-find-file-hook t)
 
 (defun follow-find-file-hook ()
-  "Find-file hook for Follow Mode.  See the variable `follow-auto'."
+  "Find-file hook for Follow mode.  See the variable `follow-auto'."
   (if follow-auto (follow-mode t)))
 
 ;;}}}
@@ -721,7 +558,7 @@ Keys specific to Follow mode:
 
 ;;{{{ Scroll
 
-;; `scroll-up' and `-down', but for windows in Follow Mode.
+;; `scroll-up' and `-down', but for windows in Follow mode.
 ;;
 ;; Almost like the real thing, excpet when the cursor ends up outside
 ;; the top or bottom...  In our case however, we end up outside the
@@ -737,7 +574,7 @@ Keys specific to Follow mode:
 ;; good redisplay abstraction.)
 
 (defun follow-scroll-up (&optional arg)
-  "Scroll text in a Follow Mode window chain up.
+  "Scroll text in a Follow mode window chain up.
 
 If called with no ARG, the `next-screen-context-lines' last lines of
 the bottom window in the chain will be visible in the top window.
@@ -745,7 +582,7 @@ the bottom window in the chain will be visible in the top window.
 If called with an argument, scroll ARG lines up.
 Negative ARG means scroll downward.
 
-Works like `scroll-up' when not in Follow Mode."
+Works like `scroll-up' when not in Follow mode."
   (interactive "P")
   (cond ((not (and (boundp 'follow-mode) follow-mode))
         (scroll-up arg))
@@ -766,7 +603,7 @@ Works like `scroll-up' when not in Follow Mode."
 
 
 (defun follow-scroll-down (&optional arg)
-  "Scroll text in a Follow Mode window chain down.
+  "Scroll text in a Follow mode window chain down.
 
 If called with no ARG, the `next-screen-context-lines' top lines of
 the top window in the chain will be visible in the bottom window.
@@ -774,7 +611,7 @@ the top window in the chain will be visible in the bottom window.
 If called with an argument, scroll ARG lines down.
 Negative ARG means scroll upward.
 
-Works like `scroll-up' when not in Follow Mode."
+Works like `scroll-up' when not in Follow mode."
   (interactive "P")
   (cond ((not (and (boundp 'follow-mode) follow-mode))
         (scroll-up arg))
@@ -801,16 +638,16 @@ Works like `scroll-up' when not in Follow Mode."
 
 ;;;###autoload
 (defun follow-delete-other-windows-and-split (&optional arg)
-  "Create two side by side windows and enter Follow Mode.
+  "Create two side by side windows and enter Follow mode.
 
 Execute this command to display as much as possible of the text
 in the selected window.  All other windows, in the current
 frame, are deleted and the selected window is split in two
-side-by-side windows. Follow Mode is activated, hence the
+side-by-side windows.  Follow mode is activated, hence the
 two windows always will display two successive pages.
 \(If one window is moved, the other one will follow.)
 
-If ARG is positive, the leftmost window is selected.  If it negative,
+If ARG is positive, the leftmost window is selected.  If negative,
 the rightmost is selected.  If ARG is nil, the leftmost window is
 selected if the original window is the first one in the frame.
 
@@ -834,7 +671,7 @@ in your `~/.emacs' file, replacing [f7] by your favourite key:
     (follow-mode 1)))
 
 (defun follow-switch-to-buffer (buffer)
-  "Show BUFFER in all windows in the current Follow Mode window chain."
+  "Show BUFFER in all windows in the current Follow mode window chain."
   (interactive "BSwitch to Buffer: ")
   (let ((orig-window (selected-window))
        (windows (follow-all-followers)))
@@ -862,7 +699,7 @@ Defaults to current buffer."
 
 
 (defun follow-switch-to-current-buffer-all ()
-  "Show current buffer in all windows on this frame, and enter Follow Mode.
+  "Show current buffer in all windows on this frame, and enter Follow mode.
 
 To bind this command to a hotkey place the following line
 in your `~/.emacs' file:
@@ -875,7 +712,7 @@ in your `~/.emacs' file:
 ;;}}}
 ;;{{{ Movement
 
-;; Note, these functions are not very useful, atleast not unless you
+;; Note, these functions are not very useful, at least not unless you
 ;; rebind the rather cumbersome key sequence `C-c . p'.
 
 (defun follow-next-window ()
@@ -915,8 +752,8 @@ in your `~/.emacs' file:
 Rearrange all other windows around the middle window.
 
 With a positive argument, place the current line ARG lines
-from the top.  With a negative, place it -ARG lines from the
-bottom."
+from the top.  With a negative argument, place it -ARG lines
+from the bottom."
   (interactive "P")
   (if arg
       (let ((p (point))
@@ -959,10 +796,10 @@ Follow mode since the windows should always be aligned."
 ;;{{{ End of buffer
 
 (defun follow-end-of-buffer (&optional arg)
-  "Move point to the end of the buffer, Follow Mode style.
+  "Move point to the end of the buffer, Follow mode style.
 
 If the end is not visible, it will be displayed in the last possible
-window in the Follow Mode window chain.
+window in the Follow mode window chain.
 
 The mark is left at the previous position.  With arg N, put point N/10
 of the way from the true end."
@@ -993,7 +830,7 @@ of the way from the true end."
   "Return all windows displaying the same buffer as the TESTWIN.
 The list contains only windows displayed in the same frame as TESTWIN.
 If TESTWIN is nil the selected window is used."
-  (or (and testwin (window-live-p testwin))
+  (or (window-live-p testwin)
       (setq testwin (selected-window)))
   (let* ((top (frame-first-window (window-frame testwin)))
         (win top)
@@ -1033,7 +870,7 @@ window, normally is the end plus one.
 If WIN is nil, the selected window is used.
 
 Returns (end-pos end-of-buffer-p)"
-  (if follow-emacs-version-xemacs-p
+  (if (featurep 'xemacs)
       ;; XEmacs can calculate the end of the window by using
       ;; the 'guarantee options. GOOD!
       (let ((end (window-end win t)))
@@ -1146,7 +983,7 @@ Note that this handles the case when the cache has been set to nil."
 ;; should start at a full screen line.
 
 (defsubst follow-windows-aligned-p (win-start-end)
-  "Non-nil if the follower WINDOWS are aligned."
+  "Non-nil if the follower windows are aligned."
   (let ((res t))
     (save-excursion
        (goto-char (window-start (car (car win-start-end))))
@@ -1166,7 +1003,7 @@ Note that this handles the case when the cache has been set to nil."
 ;; no one will be recentered.)
 
 (defun follow-point-visible-all-windows-p (win-start-end)
-  "Non-nil when the window-point is visible in all windows."
+  "Non-nil when the `window-point' is visible in all windows."
   (let ((res t))
     (while (and res win-start-end)
       (setq res (follow-pos-visible (window-point (car (car win-start-end)))
@@ -1294,7 +1131,7 @@ Return the selected window."
 (defun follow-redisplay (&optional windows win)
   "Reposition the WINDOWS around WIN.
 Should the point be too close to the roof we redisplay everything
-from the top. WINDOWS should contain a list of windows to
+from the top.  WINDOWS should contain a list of windows to
 redisplay, it is assumed that WIN is a member of the list.
 Should WINDOWS be nil, the windows displaying the
 same buffer as WIN, in the current frame, are used.
@@ -1375,8 +1212,8 @@ START."
 (defun follow-estimate-first-window-start (windows win start)
   "Estimate the position of the first window.
 
-Returns (EXACT . POS). If EXACT is non-nil, POS is the starting
-position of the first window. Otherwise it is a good guess."
+Returns (EXACT . POS).  If EXACT is non-nil, POS is the starting
+position of the first window.  Otherwise it is a good guess."
   (let ((pred (car (follow-split-followers windows win)))
        (exact nil))
     (save-excursion
@@ -1430,7 +1267,7 @@ position of the first window. Otherwise it is a good guess."
     (let ((done nil)
          win-start
          res)
-      ;; Always calculate what happend when no line is displayed in the first
+      ;; Always calculate what happens when no line is displayed in the first
       ;; window. (The `previous' res is needed below!)
       (goto-char guess)
       (vertical-motion 0 (car windows))
@@ -1478,7 +1315,7 @@ position of the first window. Otherwise it is a good guess."
   "Make sure windows displaying the end of a buffer aren't recentered.
 
 This is done by reading and rewriting the start position of
-non-first windows in Follow Mode."
+non-first windows in Follow mode."
   (if follow-avoid-tail-recenter-p
       (let* ((orig-buffer (current-buffer))
            (top (frame-first-window (selected-frame)))
@@ -1511,7 +1348,7 @@ non-first windows in Follow Mode."
 ;;}}}
 ;;{{{ Post Command Hook
 
-;;; The magic little box. This function is called after every command.
+;; The magic little box. This function is called after every command.
 
 ;; This is not as complicated as it seems. It is simply a list of common
 ;; display situations and the actions to take, plus commands for redrawing
@@ -1671,9 +1508,9 @@ non-first windows in Follow Mode."
                    (setq win-start-end (follow-windows-start-end windows))
                    (follow-invalidate-cache)
                    ;; When the point ends up in another window. This
-                   ;; happends when dest is in the beginning of the
+                   ;; happens when dest is in the beginning of the
                    ;; file and the selected window is not the first.
-                   ;; It can also, in rare situations happend when
+                   ;; It can also, in rare situations happen when
                    ;; long lines are used and there is a big
                    ;; difference between the width of the windows.
                    ;; (When scrolling one line in a wide window which
@@ -1735,17 +1572,17 @@ non-first windows in Follow Mode."
 
 ;;;; Scroll-bar support code.
 
-;;; Why is it needed? Well, if the selected window is in follow mode,
-;;; all its follower stick to it blindly. If one of them is scrolled,
-;;; it immediately returns to the original position when the mouse is
-;;; released. If the selected window is not a follower of the dragged
-;;; window the windows will be unaligned.
+;; Why is it needed? Well, if the selected window is in follow mode,
+;; all its follower stick to it blindly. If one of them is scrolled,
+;; it immediately returns to the original position when the mouse is
+;; released. If the selected window is not a follower of the dragged
+;; window the windows will be unaligned.
 
-;;; The advices doesn't get compiled. Aestetically, this might be a
-;;; problem but in practical life it isn't.
+;; The advices doesn't get compiled. Aestetically, this might be a
+;; problem but in practical life it isn't.
 
-;;; Discussion: Now when the other windows in the chain follow the
-;;; dragged, should we really select it?
+;; Discussion: Now when the other windows in the chain follow the
+;; dragged, should we really select it?
 
 (cond ((fboundp 'scroll-bar-drag)
        ;;;
@@ -1770,7 +1607,7 @@ non-first windows in Follow Mode."
                 (after
                  ,(intern (concat "follow-" (symbol-name (car cmds))))
                  activate)
-                "Adviced by Follow Mode."
+                "Adviced by Follow mode."
                 (follow-redraw-after-event (ad-get-arg 0))))
           (setq cmds (cdr cmds))))
 
@@ -1828,7 +1665,7 @@ non-first windows in Follow Mode."
       (defun follow-xemacs-scrollbar-support (window)
        "Redraw windows showing the same buffer as shown in WINDOW.
 WINDOW is either the dragged window, or a cons containing the
-window as its first element. This is called while the user drags
+window as its first element.  This is called while the user drags
 the scrollbar.
 
 WINDOW can be an object or a window."
@@ -1851,29 +1688,29 @@ WINDOW can be an object or a window."
 ;;}}}
 ;;{{{ Process output
 
-;;; The following sections installs a spy that listens to process
-;;; output and tries to reposition the windows whose buffers are in
-;;; Follow mode.  We play safe as much as possible...
-;;;
-;;; When follow-mode is activated all active processes are
-;;; intercepted.  All new processes that change their filter function
-;;; using `set-process-filter' are also intercepted.  The reason is
-;;; that a process can cause a redisplay recentering "tail" windows.
-;;; Note that it doesn't hurt to spy on more processes than needed.
-;;;
-;;; Technically, we set the process filter to `follow-generic-filter'.
-;;; The original filter is stored in `follow-process-filter-alist'.
-;;; Our generic filter calls the original filter, or inserts the
-;;; output into the buffer, if the buffer originally didn't have an
-;;; output filter.  It also makes sure that the windows connected to
-;;; the buffer are aligned.
-;;;
-;;; Discussion: How do we find processes that don't call
-;;; `set-process-filter'?  (How often are processes created in a
-;;; buffer after Follow mode are activated?)
-;;;
-;;; Discussion: Should we also advice `process-filter' to make our
-;;; filter invisible to others?
+;; The following sections installs a spy that listens to process
+;; output and tries to reposition the windows whose buffers are in
+;; Follow mode.  We play safe as much as possible...
+;;
+;; When follow-mode is activated all active processes are
+;; intercepted.  All new processes that change their filter function
+;; using `set-process-filter' are also intercepted.  The reason is
+;; that a process can cause a redisplay recentering "tail" windows.
+;; Note that it doesn't hurt to spy on more processes than needed.
+;;
+;; Technically, we set the process filter to `follow-generic-filter'.
+;; The original filter is stored in `follow-process-filter-alist'.
+;; Our generic filter calls the original filter, or inserts the
+;; output into the buffer, if the buffer originally didn't have an
+;; output filter.  It also makes sure that the windows connected to
+;; the buffer are aligned.
+;;
+;; Discussion: How do we find processes that don't call
+;; `set-process-filter'?  (How often are processes created in a
+;; buffer after Follow mode are activated?)
+;;
+;; Discussion: Should we also advice `process-filter' to make our
+;; filter invisible to others?
 
 ;;{{{ Advice for `set-process-filter'
 
@@ -1881,9 +1718,9 @@ WINDOW can be an object or a window."
 ;; filter...
 
 (defadvice set-process-filter (before follow-set-process-filter activate)
-  "Ensure process output will be displayed correctly in Follow Mode buffers.
+  "Ensure process output will be displayed correctly in Follow mode buffers.
 
-Follow Mode inserts its own process filter to do its
+Follow mode inserts its own process filter to do its
 magic stuff before the real process filter is called."
   (if follow-intercept-processes
       (progn
@@ -1957,8 +1794,8 @@ magic stuff before the real process filter is called."
 (defun follow-intercept-process-output ()
   "Intercept all active processes.
 
-This is needed so that Follow Mode can track all display events in the
-system.  (See `follow-mode')"
+This is needed so that Follow mode can track all display events in the
+system.  (See `follow-mode'.)"
   (interactive)
   (let ((list (process-list)))
     (while list
@@ -1971,7 +1808,7 @@ system.  (See `follow-mode')"
 
 
 (defun follow-stop-intercept-process-output ()
-  "Stop Follow Mode from spying on processes.
+  "Stop Follow mode from spying on processes.
 
 All current spypoints are removed and no new will be added.
 
@@ -1980,31 +1817,28 @@ connected to processes.
 
 The only reason to call this function is if the Follow mode spy filter
 would interfere with some other package.  If this happens, please
-report this using the `follow-submit-feedback' function."
+report this using the `report-emacs-bug' function."
   (interactive)
   (follow-tidy-process-filter-alist)
-  (let ((list (process-list)))
-    (while list
-      (if (eq (process-filter (car list)) 'follow-generic-filter)
-         (progn
-           (follow-call-set-process-filter
-            (car list)
-            (cdr-safe (assq (car list) follow-process-filter-alist)))
-           (setq follow-process-filter-alist
-                 (delq (assq (car list) follow-process-filter-alist)
-                       follow-process-filter-alist))))
-      (setq list (cdr list))))
+  (dolist (process (process-list))
+    (when (eq (follow-call-process-filter process) 'follow-generic-filter)
+      (follow-call-set-process-filter
+       process
+       (cdr-safe (assq process follow-process-filter-alist)))
+      (setq follow-process-filter-alist
+           (delq (assq process follow-process-filter-alist)
+                 follow-process-filter-alist))))
   (setq follow-intercept-processes nil))
 
 ;;}}}
 ;;{{{ The filter
 
-;;; The following section is a naive method to make buffers with
-;;; process output to work with Follow mode. Whenever the start of the
-;;; window displaying the buffer is moved, we moves it back to its
-;;; original position and try to select a new window.  (If we fail,
-;;; the normal redisplay functions of Emacs will scroll it right
-;;; back!)
+;; The following section is a naive method to make buffers with
+;; process output to work with Follow mode. Whenever the start of the
+;; window displaying the buffer is moved, we moves it back to its
+;; original position and try to select a new window.  (If we fail,
+;; the normal redisplay functions of Emacs will scroll it right
+;; back!)
 
 (defun follow-generic-filter (proc output)
   "Process output filter for process connected to buffers in Follow mode."
@@ -2049,7 +1883,7 @@ report this using the `follow-submit-feedback' function."
     ;; If we're in follow mode, do our stuff.  Select a new window and
     ;; redisplay.  (Actually, it is redundant to check `buf', but I
     ;; feel it's more correct.)
-    (if (and buf win (window-live-p win))
+    (if (and buf (window-live-p win))
        (progn
          (set-buffer buf)
          (if (and (boundp 'follow-mode) follow-mode)
@@ -2129,13 +1963,13 @@ report this using the `follow-submit-feedback' function."
   (follow-invalidate-cache)
 
   ;; Normally, if the display has been changed, it is redrawn.  All
-  ;; windows showing only the end of a buffer is unconditionally
-  ;; recentered, we can't prevent it by calling
+  ;; windows showing only the end of a buffer are unconditionally
+  ;; recentered; we can't prevent that by calling
   ;; `follow-avoid-tail-recenter'.
   ;;
-  ;; By performing a redisplay on our own, Emacs need not perform
-  ;; the above described redisplay.  (However, bu performing it when
-  ;; there are input available just seems to make things worse.)
+  ;; We force a redisplay here on our own, so Emacs does need to.
+  ;; (However, redisplaying when there's input available just seems
+  ;; to make things worse, so we exclude that case.)
   (if (and follow-avoid-tail-recenter-p
           (not (input-pending-p)))
       (sit-for 0)))
@@ -2165,8 +1999,8 @@ report this using the `follow-submit-feedback' function."
 
 (defun follow-window-size-change (frame)
   "Redraw all windows in FRAME, when in Follow mode."
-  ;; Below, we call `post-command-hook'. This makes sure that we
-  ;; doesn't start a mutally recursive endless loop.
+  ;; Below, we call `post-command-hook'.  This makes sure that we
+  ;; don't start a mutually recursive endless loop.
   (if follow-inside-post-command-hook
       nil
     (let ((buffers '())
@@ -2190,12 +2024,12 @@ report this using the `follow-submit-feedback' function."
                      (setq windows (follow-all-followers win))
                      (if (memq orig-window windows)
                          (progn
-                           ;; Make sure we're redrawing around the
-                           ;; selected window.
-                           ;;
-                           ;; We must be really careful not to do this
-                           ;; when we are (indirectly) called by
-                           ;; `post-command-hook'.
+                            ;; Make sure we're redrawing around the
+                            ;; selected window.
+                            ;;
+                            ;; We must be really careful not to do this
+                            ;; when we are (indirectly) called by
+                            ;; `post-command-hook'.
                            (select-window orig-window)
                            (follow-post-command-hook)
                            (setq orig-window (selected-window)))
@@ -2219,7 +2053,7 @@ report this using the `follow-submit-feedback' function."
 ;; unless we are in `slow-search-mode', i.e. only a few lines
 ;; of text is visible.
 
-(if follow-emacs-version-xemacs-p
+(if (featurep 'xemacs)
     (defadvice isearch-done (before follow-isearch-done activate)
       (if (and (boundp 'follow-mode)
               follow-mode
@@ -2235,28 +2069,28 @@ report this using the `follow-submit-feedback' function."
 ;;}}}
 ;;{{{ Tail window handling
 
-;;; In Emacs (not XEmacs) windows showing nothing are sometimes
-;;; recentered.  When in Follow Mode, this is not desireable for
-;;; non-first windows in the window chain.  This section tries to
-;;; make the windows stay where they should be.
-;;;
-;;; If the display is updated, all windows starting at (point-max) are
-;;; going to be recentered at the next redisplay, unless we do a
-;;; read-and-write cycle to update the `force' flag inside the windows.
-;;;
-;;; In 19.30, a new varible `window-scroll-functions' is called every
-;;; time a window is recentered.  It is not perfect for our situation,
-;;; since when it is called for a tail window, it is to late.  However,
-;;; if it is called for another window, we can try to update our
-;;; windows.
-;;;
-;;; By patching `sit-for' we can make sure that to catch all explicit
-;;; updates initiated by lisp programs.  Internal calls, on the other
-;;; hand, are not handled.
-;;;
-;;; Please note that the function `follow-avoid-tail-recenter' is also
-;;; called from other places, e.g. `post-command-hook' and
-;;; `post-command-idle-hook'.
+;; In Emacs (not XEmacs) windows showing nothing are sometimes
+;; recentered.  When in Follow mode, this is not desirable for
+;; non-first windows in the window chain.  This section tries to
+;; make the windows stay where they should be.
+;;
+;; If the display is updated, all windows starting at (point-max) are
+;; going to be recentered at the next redisplay, unless we do a
+;; read-and-write cycle to update the `force' flag inside the windows.
+;;
+;; In 19.30, a new varible `window-scroll-functions' is called every
+;; time a window is recentered.  It is not perfect for our situation,
+;; since when it is called for a tail window, it is to late.  However,
+;; if it is called for another window, we can try to update our
+;; windows.
+;;
+;; By patching `sit-for' we can make sure that to catch all explicit
+;; updates initiated by lisp programs.  Internal calls, on the other
+;; hand, are not handled.
+;;
+;; Please note that the function `follow-avoid-tail-recenter' is also
+;; called from other places, e.g. `post-command-hook' and
+;; `post-command-idle-hook'.
 
 ;; If this function is called it is too late for this window, but
 ;; we might save other windows from being recentered.
@@ -2270,10 +2104,10 @@ report this using the `follow-submit-feedback' function."
 
 (if follow-avoid-tail-recenter-p
     (defadvice sit-for (before follow-sit-for activate)
-      "Adviced by Follow Mode.
+      "Adviced by Follow mode.
 
 Avoid to recenter windows displaying only the end of a file as when
-displaying a short file in two windows, using Follow Mode."
+displaying a short file in two windows, using Follow mode."
       (follow-avoid-tail-recenter)))
 
 
@@ -2283,7 +2117,7 @@ displaying a short file in two windows, using Follow Mode."
 (if (and follow-avoid-tail-recenter-p
         (fboundp 'move-overlay))
     (defadvice move-overlay (before follow-move-overlay activate)
-      "Adviced by Follow Mode.
+      "Adviced by Follow mode.
 Don't recenter windows showing only the end of a buffer.
 This prevents `mouse-drag-region' from messing things up."
       (follow-avoid-tail-recenter)))
@@ -2328,9 +2162,40 @@ This prevents `mouse-drag-region' from messing things up."
 
 ;;{{{ The end
 
-;;;
-;;; We're done!
-;;;
+(defun follow-unload-function ()
+  "Unload Follow mode library."
+  (easy-menu-remove-item nil '("Tools") "Follow")
+  (follow-stop-intercept-process-output)
+  (dolist (group '((before
+                   ;; XEmacs
+                   isearch-done
+                   ;; both
+                   set-process-filter sit-for move-overlay)
+                  (after
+                   ;; Emacs
+                   scroll-bar-drag scroll-bar-drag-1 scroll-bar-scroll-down
+                   scroll-bar-scroll-up scroll-bar-set-window-start
+                   ;; XEmacs
+                   scrollbar-line-down scrollbar-line-up scrollbar-page-down
+                   scrollbar-page-up scrollbar-to-bottom scrollbar-to-top
+                   scrollbar-vertical-drag
+                   ;; both
+                   process-filter)))
+    (let ((class (car group)))
+      (dolist (fun (cdr group))
+       (when (functionp fun)
+         (condition-case nil
+             (progn
+               (ad-remove-advice fun class
+                                 (intern (concat "follow-" (symbol-name fun))))
+               (ad-update fun))
+           (error nil))))))
+  ;; continue standard processing
+  nil)
+
+;;
+;; We're done!
+;;
 
 (provide 'follow)