Use external tool `w3m' for dumping html to plain texts.
[xwl-elisp.git] / less.el
blob16b5ad4aa1a9e0fd743271737ca6ddc0aafffa94
1 ;;; less.el --- less style view mode
3 ;; Copyright (C) 2005, 2007 William Xu
5 ;; Author: William Xu <william.xwl@gmail.com>
6 ;; Version: 0.2
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)
11 ;; any later version.
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
21 ;; 02110-1301 USA
23 ;;; Commentary:
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:
29 ;; (require 'less)
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.
37 ;;; Code:
39 ;;;###autoload
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}."
45 nil " Less"
46 '(("j" . less-scroll-up-one-line)
47 ("k" . less-scroll-down-one-line)
48 ("f" . scroll-up)
49 ("b" . scroll-down)
50 ("g" . beginning-of-buffer)
51 ("G" . end-of-buffer)
52 (" " . scroll-up)
53 ("\x7f" . scroll-down)
54 ("e" . less-quit))
55 (set (make-local-variable 'buffer-read-only) less-minor-mode))
57 (defun less-scroll-up-one-line ()
58 "Scroll up one line."
59 (interactive)
60 (scroll-up 1))
62 (defun less-scroll-down-one-line ()
63 "Scroll down one line."
64 (interactive)
65 (scroll-down 1))
67 (defun less-quit ()
68 "Quit `less-minor-mode'."
69 (interactive)
70 (less-minor-mode -1))
72 ;;;###autoload
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)
77 (less-minor-mode 1)))
79 ;;;###autoload
80 (defun less-minor-mode-on ()
81 "Turn on `less-minor-mode'."
82 (less-minor-mode 1))
84 ;;;###autoload
85 (defun less-minor-mode-off ()
86 "Turn off `less-minor-mode'."
87 (less-minor-mode -1))
89 (provide 'less)
91 ;;; less.el ends here