1 ;;; less.el --- less style view mode
3 ;; Copyright (C) 2005, 2007 William Xu
5 ;; Author: William Xu <william.xwl@gmail.com>
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program; if not, write to the Free Software
20 ;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 ;; View file like a simple `less'. Provide limited less keys, mainly j,
26 ;; k, f, b, g, G, etc.
28 ;; Put this file into your load-path and the following into your ~/.emacs:
31 ;; Then use `M-x less-minor-mode' to toggle `less-minor-mode'.
33 ;; There's also a `view-less.el' in XEmacs. But it does too much for me,
34 ;; i just wanna less keys like j, k, f, b, g, G, not to mess with other
35 ;; keys in major mode.
40 (define-minor-mode less-minor-mode
41 "Toggle less-minor-mode.
43 With less-minor-mode enabled, you could use `less' like keys to view files.
44 \\{less-minor-mode-map}."
46 '(("j" . less-scroll-up-one-line
)
47 ("k" . less-scroll-down-one-line
)
50 ("g" . beginning-of-buffer
)
53 ("\x7f" . scroll-down
)
55 (set (make-local-variable 'buffer-read-only
) less-minor-mode
))
57 (defun less-scroll-up-one-line ()
62 (defun less-scroll-down-one-line ()
63 "Scroll down one line."
68 "Quit `less-minor-mode'."
73 (defun auto-less-minor-mode ()
74 "Auto enter `less-minor-mode' when visiting read-only files. You can
75 add this to `find-file-hooks'."
76 (unless (file-writable-p buffer-file-name
)
80 (defun less-minor-mode-on ()
81 "Turn on `less-minor-mode'."
85 (defun less-minor-mode-off ()
86 "Turn off `less-minor-mode'."