Here is a simple extension to Emacs that moves the line point is on to the top of the window. I use this all the time, to make text easier to read.
You can put the following code into a separate file and then load it from your .emacs file, or you can include it within your .emacs file.
Here is the definition:
;;; Line to top of window; ;;; replace three keystroke sequence C-u 0 C-l (defun line-to-top-of-window () "Move the line point is on to top of window." (interactive) (recenter 0))
Now for the keybinding.
Nowadays, function keys as well as mouse button events and non-ASCII characters are written within square brackets, without quotation marks. (In Emacs version 18 and before, you had to write different function key bindings for each different make of terminal.)
line-to-top-of-window to my F6 function key like
(global-set-key [f6] 'line-to-top-of-window)
For more information, see Rebinding Keys in Your Init File in The GNU Emacs Manual.
If you run two versions of GNU Emacs, such as versions 22 and 23, and use one .emacs file, you can select which code to evaluate with the following conditional:
(cond ((= 22 emacs-major-version) ;; evaluate version 22 code ( … )) ((= 23 emacs-major-version) ;; evaluate version 23 code ( … )))
For example, recent versions blink their cursors by default. I hate such blinking, as well as other features, so I placed the following in my .emacs file15:
(when (>= emacs-major-version 21) (blink-cursor-mode 0) ;; Insert newline when you press `C-n' (next-line) ;; at the end of the buffer (setq next-line-add-newlines t)
;; Turn on image viewing (auto-image-file-mode t)
;; Turn on menu bar (this bar has text) ;; (Use numeric argument to turn on) (menu-bar-mode 1)
;; Turn off tool bar (this bar has icons) ;; (Use numeric argument to turn on) (tool-bar-mode nil)
;; Turn off tooltip mode for tool bar ;; (This mode causes icon explanations to pop up) ;; (Use numeric argument to turn on) (tooltip-mode nil) ;; If tooltips turned on, make tips appear promptly (setq tooltip-delay 0.1) ; default is 0.7 second )
When I start instances of Emacs that do not load my .emacs file or any site file, I also turn off blinking:
emacs -q --no-site-file -eval '(blink-cursor-mode nil)'
Or nowadays, using an even more sophisticated set of options,
emacs -Q -D