Initial Commit
[packages] / xemacs-packages / w3 / lisp / w3-emulate.el
1 ;;; w3-emulate.el --- All variable definitions for emacs-w3
2 ;; Author: $Author: fx $
3 ;; Created: $Date: 2001/05/29 15:52:51 $
4 ;; Version: $Revision: 1.3 $
5 ;; Keywords: comm, help, hypermedia
6
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8 ;;; Copyright (c) 1996 by William M. Perry <wmperry@cs.indiana.edu>
9 ;;; Copyright (c) 1996 - 1999 Free Software Foundation, Inc.
10 ;;;
11 ;;; This file is part of GNU Emacs.
12 ;;;
13 ;;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;;; it under the terms of the GNU General Public License as published by
15 ;;; the Free Software Foundation; either version 2, or (at your option)
16 ;;; any later version.
17 ;;;
18 ;;; GNU Emacs is distributed in the hope that it will be useful,
19 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ;;; GNU General Public License for more details.
22 ;;;
23 ;;; You should have received a copy of the GNU General Public License
24 ;;; along with GNU Emacs; see the file COPYING.  If not, write to the
25 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;;; Boston, MA 02111-1307, USA.
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28
29 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;;; Provide emulations of various other web browsers
31 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
32 (require 'w3-vars)
33 (require 'url-vars)
34
35 \f
36 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37 ;; First, we emulate Netscape 2.x
38 ;; ------------------------------
39 ;; This entails mainly a few new keybindings.
40 ;; Alt-S    == Save As
41 ;; Alt-M    == New Mail Message
42 ;; Alt-N    == New Window
43 ;; Alt-L    == Open Location
44 ;; Alt-O    == Open File
45 ;; Alt-P    == Print
46 ;; Alt-Q    == Quit
47 ;; Alt-F    == Search
48 ;; Alt-G    == Search Again
49 ;; Alt-R    == Reload
50 ;; Alt-I    == Load Images
51 ;; Alt-A    == Add Bookmark
52 ;; Alt-B    == Show Bookmark Window
53 ;; Alt-H    == Show History Window
54 ;; Alt-Left == Back
55 ;; Alt-Right== Forward
56 ;; Right    == Scroll left
57 ;; Left     == Scroll right
58 ;; Up       == Smooth scroll up
59 ;; Down     == Smooth scroll down
60 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
61
62 (define-key w3-netscape-emulation-minor-mode-map "\M-s" 'w3-save-as)
63 (define-key w3-netscape-emulation-minor-mode-map "\M-m" 'w3-mailto)
64 (define-key w3-netscape-emulation-minor-mode-map "\M-n" 'make-frame)
65 (define-key w3-netscape-emulation-minor-mode-map "\M-l" 'w3-fetch)
66 (define-key w3-netscape-emulation-minor-mode-map "\M-o" 'w3-open-local)
67 (define-key w3-netscape-emulation-minor-mode-map "\M-p" 'w3-print-this-url)
68 (define-key w3-netscape-emulation-minor-mode-map "\M-q" 'w3-quit)
69 (define-key w3-netscape-emulation-minor-mode-map "\M-f" 'w3-search-forward)
70 (define-key w3-netscape-emulation-minor-mode-map "\M-g" 'w3-search-again)
71 (define-key w3-netscape-emulation-minor-mode-map "\M-r" 'w3-reload-document)
72 (define-key w3-netscape-emulation-minor-mode-map "\M-i" 'w3-load-delayed-images)
73 (define-key w3-netscape-emulation-minor-mode-map "\M-a" 'w3-hotlist-add-document)
74 (define-key w3-netscape-emulation-minor-mode-map "\M-b" 'w3-hotlist-view)
75 (define-key w3-netscape-emulation-minor-mode-map "\M-h" 'w3-show-history-list)
76
77 (define-key w3-netscape-emulation-minor-mode-map [up]
78   (function (lambda () (interactive) (scroll-down 1))))
79 (define-key w3-netscape-emulation-minor-mode-map [down]
80   (function (lambda () (interactive) (scroll-up 1))))
81 (define-key w3-netscape-emulation-minor-mode-map [right] 'scroll-left)
82 (define-key w3-netscape-emulation-minor-mode-map [left] 'scroll-right)
83 (define-key w3-netscape-emulation-minor-mode-map [(meta left)]
84   'w3-history-backward)
85 (define-key w3-netscape-emulation-minor-mode-map [(meta right)]
86   'w3-history-forward)
87
88 (defun turn-on-netscape-emulation ()
89   (interactive)
90   (w3-lynx-emulation-minor-mode 0)
91   (w3-netscape-emulation-minor-mode 1))
92
93 (defun w3-netscape-emulation-minor-mode (&optional arg)
94   "Minor mode for emulating netscape key navigation."
95   (interactive "P")
96   (cond
97    ((null arg)
98     (setq w3-netscape-emulation-minor-mode
99           (not w3-netscape-emulation-minor-mode))
100     (if w3-netscape-emulation-minor-mode
101         (setq w3-lynx-emulation-minor-mode nil)))
102    ((= 0 arg)
103     (setq w3-netscape-emulation-minor-mode nil))
104    (t
105     (setq w3-lynx-emulation-minor-mode nil
106           w3-netscape-emulation-minor-mode t)))
107   )
108
109 (defsubst w3-skip-word ()
110   (skip-chars-forward "^ \t\n\r")
111   (skip-chars-forward " \t"))
112
113 \f
114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
115 ;; Now, lets try Lynx
116 ;; ------------------
117 ;; A few keybindings and modifications to some default functions
118 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
119
120 (defun turn-on-lynx-emulation ()
121   (interactive)
122   (w3-netscape-emulation-minor-mode 0)
123   (w3-lynx-emulation-minor-mode 1))
124
125 (defun w3-lynx-emulation-minor-mode (&optional arg)
126   "Minor mode for emulating lynx key navigation."
127   (interactive "P")
128   (cond
129    ((null arg)
130     (setq w3-lynx-emulation-minor-mode
131           (not w3-lynx-emulation-minor-mode))
132     (if w3-lynx-emulation-minor-mode
133         (setq w3-netscape-emulation-minor-mode nil)))
134    ((= 0 arg)
135     (setq w3-lynx-emulation-minor-mode nil))
136    (t
137     (setq w3-lynx-emulation-minor-mode t
138           w3-netscape-emulation-minor-mode nil))))
139
140 ;; The list of keybindings for lynx minor mode was compiled from:
141 ;; http://www.crl.com/~subir/lynx/lynx_help/keystroke_commands/keystroke_help.htm
142
143 ;; Movement
144 (define-key w3-lynx-emulation-minor-mode-map [up]   'widget-backward)
145 (define-key w3-lynx-emulation-minor-mode-map [down] 'widget-forward)
146 (define-key w3-lynx-emulation-minor-mode-map [right] 'widget-button-press)
147 (define-key w3-lynx-emulation-minor-mode-map [left] 'w3-history-backward)
148
149 ;; Scrolling
150 (define-key w3-lynx-emulation-minor-mode-map "+"    'w3-scroll-up)
151 (define-key w3-lynx-emulation-minor-mode-map "-"    'scroll-down)
152 (define-key w3-lynx-emulation-minor-mode-map "b"    'scroll-down)
153 (define-key w3-lynx-emulation-minor-mode-map "\C-a" 'w3-start-of-document)
154 (define-key w3-lynx-emulation-minor-mode-map "\C-e" 'w3-end-of-document)
155 (define-key w3-lynx-emulation-minor-mode-map "\C-f" 'scroll-up)
156 (define-key w3-lynx-emulation-minor-mode-map "\C-b" 'scroll-down)
157 (define-key w3-lynx-emulation-minor-mode-map "\C-n" (lambda () (interactive) (scroll-up 2)))
158 (define-key w3-lynx-emulation-minor-mode-map "\C-p" (lambda () (interactive) (scroll-down 2)))
159 (define-key w3-lynx-emulation-minor-mode-map ")"    'ignore) ; forward half
160 (define-key w3-lynx-emulation-minor-mode-map "("    'ignore) ; back half
161 (define-key w3-lynx-emulation-minor-mode-map "#"    'w3-toggle-toolbar)
162
163 ;; Dired bindings don't have any meaning for us
164
165 ;; Other
166 (define-key w3-lynx-emulation-minor-mode-map "?"   'w3-help)
167 (define-key w3-lynx-emulation-minor-mode-map "a"   'w3-hotlist-add-document)
168 (define-key w3-lynx-emulation-minor-mode-map "c"   'w3-mail-document-author)
169 (define-key w3-lynx-emulation-minor-mode-map "d"   'w3-download-url) 
170 (define-key w3-lynx-emulation-minor-mode-map "e"   'ignore) ; edit current
171 (define-key w3-lynx-emulation-minor-mode-map "f"   'dired)
172 (define-key w3-lynx-emulation-minor-mode-map "g"   'w3-fetch)
173 (define-key w3-lynx-emulation-minor-mode-map "h"   'w3-help)
174 (define-key w3-lynx-emulation-minor-mode-map "i"   'ignore)
175 (define-key w3-lynx-emulation-minor-mode-map "j"   'w3-use-hotlist)
176 (define-key w3-lynx-emulation-minor-mode-map "k"   'describe-mode)
177 (define-key w3-lynx-emulation-minor-mode-map "l"   'w3-complete-link)
178 (define-key w3-lynx-emulation-minor-mode-map "m"   'w3)
179 (define-key w3-lynx-emulation-minor-mode-map "n"   'w3-search-again)
180 (define-key w3-lynx-emulation-minor-mode-map "o"   'w3-preferences-edit)
181 (define-key w3-lynx-emulation-minor-mode-map "p"   'w3-print-this-url)
182 (define-key w3-lynx-emulation-minor-mode-map "q"   'w3-quit)
183 (define-key w3-lynx-emulation-minor-mode-map "r"   'w3-hotlist-delete)
184 (define-key w3-lynx-emulation-minor-mode-map "t"   'ignore) ; tag
185 (define-key w3-lynx-emulation-minor-mode-map "u"   'w3-history-backward)
186 (define-key w3-lynx-emulation-minor-mode-map "/"   'w3-search-forward)
187 (define-key w3-lynx-emulation-minor-mode-map "v"   'w3-hotlist-view)
188 (define-key w3-lynx-emulation-minor-mode-map "V"   'w3-hotlist-view)
189 (define-key w3-lynx-emulation-minor-mode-map "x"   'widget-button-press)
190 (define-key w3-lynx-emulation-minor-mode-map "z"   'keyboard-quit)
191 (define-key w3-lynx-emulation-minor-mode-map "="   'w3-document-information)
192 (define-key w3-lynx-emulation-minor-mode-map "\\"  'w3-source-document)
193 (define-key w3-lynx-emulation-minor-mode-map "!"   'shell)
194 (define-key w3-lynx-emulation-minor-mode-map "'"   'ignore) ; toggle comment
195 (define-key w3-lynx-emulation-minor-mode-map "`"   'ignore) ; toggle comment
196 (define-key w3-lynx-emulation-minor-mode-map "*"   'ignore) ; toggle image_links
197 (define-key w3-lynx-emulation-minor-mode-map "@"   'ignore) ; toggle raw 8-bit
198 (define-key w3-lynx-emulation-minor-mode-map "["   'ignore) ; pseudo-inlines
199 (define-key w3-lynx-emulation-minor-mode-map "]"   'ignore) ; send head
200 (define-key w3-lynx-emulation-minor-mode-map "\""  'ignore) ; toggle quoting
201 (define-key w3-lynx-emulation-minor-mode-map "\C-r" 'w3-reload-document)
202 (define-key w3-lynx-emulation-minor-mode-map "\C-w" 'w3-refresh-buffer)
203 (define-key w3-lynx-emulation-minor-mode-map "\C-u" 'ignore) ; erase input
204 (define-key w3-lynx-emulation-minor-mode-map "\C-g" 'keyboard-quit)
205 (define-key w3-lynx-emulation-minor-mode-map "\C-t" 'ignore) ; toggle trace
206 (define-key w3-lynx-emulation-minor-mode-map "\C-k" 'ignore) ; cookie jar
207
208 ;; Things to masquerade as other browsers in the user-agent field
209 ;; of an HTTP request.
210 (defun w3-masquerade-stub (arg app version)
211   (if (null arg)
212       (setq arg (if (equal url-package-name "Emacs-W3") 1 0)))
213   (if (= 0 arg)
214       (setq url-package-name "Emacs-W3"
215             url-package-version w3-version-number)
216     (setq url-package-name app
217           url-package-version version)))
218
219 (defun w3-lynx-masquerade-mode (&optional arg)
220   (interactive "P")
221   (w3-masquerade-stub arg "Lynx" "2.6"))
222
223 (defun turn-on-lynx-masquerade-mode ()
224   (interactive)
225   (w3-lynx-masquerade-mode 1))
226
227 (defun turn-off-lynx-masquerade-mode ()
228   (interactive)
229   (w3-lynx-masquerade-mode 0))
230
231 (defun w3-netscape-masquerade-mode (&optional arg)
232   (interactive "P")
233   (w3-masquerade-stub arg "Mozilla" "4.0"))
234
235 (defun turn-on-netscape-masquerade-mode ()
236   (interactive)
237   (w3-netscape-masquerade-mode 1))
238
239 (defun turn-off-netscape-masquerade-mode ()
240   (interactive)
241   (w3-netscape-masquerade-mode 0))
242
243 (defun w3-ie-masquerade-mode (&optional arg)
244   (interactive "P")
245   (w3-masquerade-stub arg "Internet_Explorer" "3.02"))
246
247 (defun turn-on-ie-masquerade-mode ()
248   (interactive)
249   (w3-ie-masquerade-mode 1))
250
251 (defun turn-off-ie-masquerade-mode ()
252   (interactive)
253   (w3-ie-masquerade-mode 0))
254
255 ;;
256 (provide 'w3-emulate)
257
258 ;;; Local Variables:
259 ;;; truncate-lines: t
260 ;;; End: