[Date Prev][Date Next][Thread Prev][][Date Index][Thread Index]

Re: customizing w3m-search-* variables in .emacs-w3m file



Info の執筆を行ってくださっている皆さん,ご苦労様です.皆さんの努力に
敬服します.

さて,相変わらず暇がありませんので,詳細検討はしていませんが.

>> On Mon, 16 Dec 2002 19:59:03 +0900
>> 「山」== yamaoka@jpl.org (Katsumi Yamaoka) said as follows:

山> (Japanese) いくつかのユーザオプションが、.emacs-w3m ファイルの中で
山> eval-after-load を使わないとカスタマイズできないことに、Romain さ
山> んの info の記述を見て気が付きました。

[emacs-w3m:04118] の問題とは別でしょうか?

解決策自体はまだないのですが,何か設定を担当する関数を括り出してしまわ
ないと駄目だと思います.手元では,w3m-key-binding の設定を 
~/.emacs-w3m で可能にするために以下のような変更を検討中ですが,もっと
一般的な枠組みにしないと駄目だろうなあ,と思って pending しています.

山> たとえばw3m-search-quick-search-engine-alist と 
山> w3m-search-engine-alist です。w3m-search.el モジュールは w3m.el が
山> 常時 load してしまっても問題無いと思うのだけれど、いかがでしょう? 
山> それとも、そんなこと始めると、結局全部常時 load するハメになる?

全モジュールを常時 load するのは時間がかかりますし,良くないのではない
でしょうか.w3m-vars.el を作るしかないでしょうか….

-- 
土屋 雅稔 ( TSUCHIYA Masatoshi )

--- w3m.el	18 Nov 2002 12:24:55 -0000	1.768
+++ w3m.el	17 Dec 2002 04:40:04 -0000
@@ -452,46 +454,6 @@
   :group 'w3m
   :type '(repeat coding-system))
 
-(defcustom w3m-key-binding nil
-  "*This variable decides default key mapping used in w3m-mode buffers."
-  :group 'w3m
-  :type '(choice
-	  (const :tag "Use Info-like key mapping." info)
-	  (const :tag "Use Lynx-like key mapping." nil))
-  ;; Since the following form won't be byte-compiled, you developers
-  ;; should never use CL macros like `caaaar', `when', `unless' ...
-  :set (lambda (symbol value)
-	 (prog1
-	     (if (fboundp 'custom-set-default)
-		 (custom-set-default symbol value)
-	       ;; XEmacs or Emacs 19 does not have `custom-set-default'.
-	       (set-default symbol value))
-	   (if (or noninteractive
-		   ;; Loading w3m.elc is just in progress...
-		   (not (featurep 'w3m)))
-	       nil
-	     (if (and;; Gnus binds `w3m-mode-map' for compiling.
-		  (boundp 'w3m-mode-map)
-		  (boundp 'w3m-info-like-map)
-		  (boundp 'w3m-lynx-like-map))
-		 ;; It won't be bound at the first time.
-		 (setq w3m-mode-map (if (eq value 'info)
-					w3m-info-like-map
-				      w3m-lynx-like-map)
-		       w3m-minor-mode-map (w3m-make-minor-mode-keymap)))
-	     (let ((buffers (buffer-list)))
-	       (save-excursion
-		 (while buffers
-		   (set-buffer (car buffers))
-		   (if (eq major-mode 'w3m-mode)
-		       (condition-case nil
-			   (progn
-			     (use-local-map w3m-mode-map)
-			     (w3m-setup-toolbar)
-			     (w3m-setup-menu))
-			 (error)))
-		   (setq buffers (cdr buffers)))))))))
-
 (defcustom w3m-use-cygdrive (eq system-type 'windows-nt)
   "*If non-nil, use /cygdrive/ rule when expand-file-name."
   :group 'w3m
@@ -4974,232 +4936,6 @@
   (run-hooks 'w3m-delete-buffer-hook)
   (w3m-select-buffer-update))
 
-(defvar w3m-lynx-like-map nil
-  "Lynx-like keymap used in w3m-mode buffers.")
-(unless w3m-lynx-like-map
-  (let ((map (make-keymap)))
-    (suppress-keymap map)
-    (define-key map " " 'w3m-scroll-up-or-next-url)
-    (define-key map "b" 'w3m-scroll-down-or-previous-url)
-    (define-key map [backspace] 'w3m-scroll-down-or-previous-url)
-    (define-key map [delete] 'w3m-scroll-down-or-previous-url)
-    (if (featurep 'xemacs)
-	(define-key map [(shift space)] 'w3m-scroll-down-or-previous-url)
-      ;; Note: It does not have an effect on Emacs 19.
-      (define-key map [?\S-\ ] 'w3m-scroll-down-or-previous-url))
-    (define-key map "h" 'backward-char)
-    (define-key map "j" 'next-line)
-    (define-key map "k" 'previous-line)
-    (define-key map "l" 'forward-char)
-    (define-key map "J" (lambda () (interactive) (scroll-up 1)))
-    (define-key map "K" (lambda () (interactive) (scroll-down 1)))
-    (define-key map "\M-g" 'goto-line)
-    (define-key map "\C-?" 'w3m-scroll-down-or-previous-url)
-    (define-key map "\t" 'w3m-next-anchor)
-    (define-key map [tab] 'w3m-next-anchor)
-    (define-key map [(shift tab)] 'w3m-previous-anchor)
-    (define-key map [(shift iso-lefttab)] 'w3m-previous-anchor)
-    (define-key map [down] 'w3m-next-anchor)
-    (define-key map "\M-\t" 'w3m-previous-anchor)
-    (define-key map [up] 'w3m-previous-anchor)
-    (define-key map "\C-m" 'w3m-view-this-url)
-    (define-key map [(shift return)] 'w3m-view-this-url-new-session)
-    (define-key map [(shift kp-enter)] 'w3m-view-this-url-new-session)
-    (define-key map [right] 'w3m-view-this-url)
-    (if (featurep 'xemacs)
-	(progn
-	  (define-key map [(button2)] 'w3m-mouse-view-this-url)
-	  (define-key map [(shift button2)]
-	    'w3m-mouse-view-this-url-new-session))
-      (define-key map [mouse-2] 'w3m-mouse-view-this-url)
-      (define-key map [S-mouse-2] 'w3m-mouse-view-this-url-new-session))
-    (define-key map "\C-c\C-@" 'w3m-history-store-position)
-    (if (featurep 'xemacs)
-	(define-key map [?\C-c (control space)] 'w3m-history-store-position)
-      ;; `C- ' doesn't mean `C-SPC' in XEmacs.
-      (define-key map [?\C-c ?\C-\ ] 'w3m-history-store-position))
-    (define-key map "\C-c\C-v" 'w3m-history-restore-position)
-    (define-key map [left] 'w3m-view-previous-page)
-    (define-key map "B" 'w3m-view-previous-page)
-    (define-key map "N" 'w3m-view-next-page)
-    (define-key map "^" 'w3m-view-parent-page)
-    (define-key map "d" 'w3m-download-this-url)
-    (define-key map "u" 'w3m-print-this-url)
-    (define-key map "I" 'w3m-view-image)
-    (define-key map "\M-i" 'w3m-save-image)
-    (define-key map "c" 'w3m-print-current-url)
-    (define-key map "M" 'w3m-view-url-with-external-browser)
-    (define-key map "G" 'w3m-goto-url-new-session)
-    (define-key map "g" 'w3m-goto-url)
-    (define-key map "T" 'w3m-toggle-inline-images)
-    (define-key map "t" 'w3m-toggle-inline-image)
-    (when (w3m-display-graphic-p)
-      (define-key map "\M-[" 'w3m-zoom-out-image)
-      (define-key map "\M-]" 'w3m-zoom-in-image))
-    (define-key map "U" 'w3m-goto-url)
-    (define-key map "V" 'w3m-goto-url)
-    (define-key map "v" 'w3m-bookmark-view)
-    (define-key map "q" 'w3m-close-window)
-    (define-key map "Q" 'w3m-quit)
-    (define-key map "\M-n" 'w3m-copy-buffer)
-    (define-key map "\C-c\C-t" 'w3m-copy-buffer)
-    (define-key map "\C-c\C-p" 'w3m-previous-buffer)
-    (define-key map "\C-c\C-n" 'w3m-next-buffer)
-    (define-key map "\C-c\C-w" 'w3m-delete-buffer)
-    (define-key map "\C-c\M-w" 'w3m-delete-other-buffers)
-    (define-key map "\C-c\C-s" 'w3m-select-buffer)
-    (define-key map "\C-c\C-a" 'w3m-switch-buffer)
-    (define-key map "r" 'w3m-redisplay-this-page)
-    (define-key map "R" 'w3m-reload-this-page)
-    (define-key map "?" 'describe-mode)
-    (define-key map "\M-a" 'w3m-bookmark-add-this-url)
-    (define-key map "\M-k" 'w3m-cookie)
-    (define-key map "a" 'w3m-bookmark-add-current-url)
-    (define-key map "+" 'w3m-antenna-add-current-url)
-    (define-key map "]" 'w3m-next-form)
-    (define-key map "[" 'w3m-previous-form)
-    (define-key map "}" 'w3m-next-image)
-    (define-key map "{" 'w3m-previous-image)
-    (define-key map "H" 'w3m-gohome)
-    (define-key map "A" 'w3m-antenna)
-    (define-key map "W" 'w3m-weather)
-    (define-key map "S" 'w3m-search)
-    (define-key map "D" 'w3m-dtree)
-    (define-key map ">" 'w3m-scroll-left)
-    (define-key map "<" 'w3m-scroll-right)
-    (define-key map "." 'w3m-shift-left)
-    (define-key map "," 'w3m-shift-right)
-    (define-key map "\M-l" 'w3m-horizontal-recenter)
-    (define-key map "\C-a" 'w3m-beginning-of-line)
-    (define-key map "\C-e" 'w3m-end-of-line)
-    (define-key map "\\" 'w3m-view-source)
-    (define-key map "=" 'w3m-view-header)
-    (define-key map "s" 'w3m-history)
-    (define-key map "E" 'w3m-edit-current-url)
-    (define-key map "e" 'w3m-edit-this-url)
-    (define-key map "C" (make-sparse-keymap))
-    (define-key map "Ct" 'w3m-redisplay-with-content-type)
-    (define-key map "Cc" 'w3m-redisplay-with-charset)
-    (define-key map "CC" 'w3m-redisplay-and-reset)
-    (define-key map "\C-c\C-b" 'report-emacs-w3m-bug)
-    (define-key map "\C-c\C-c" 'w3m-submit-form)
-    (define-key map "\C-c\C-k" 'w3m-process-stop)
-    (setq w3m-lynx-like-map map)))
-
-(defvar w3m-info-like-map nil
-  "Info-like keymap used in w3m-mode buffers.")
-(unless w3m-info-like-map
-  (let ((map (make-keymap)))
-    (suppress-keymap map)
-    (define-key map [backspace] 'w3m-scroll-down-or-previous-url)
-    (define-key map [delete] 'w3m-scroll-down-or-previous-url)
-    (define-key map "\C-?" 'w3m-scroll-down-or-previous-url)
-    (if (featurep 'xemacs)
-	(define-key map [(shift space)] 'w3m-scroll-down-or-previous-url)
-      ;; Note: It does not have an effect on Emacs 19.
-      (define-key map [?\S-\ ] 'w3m-scroll-down-or-previous-url))
-    (define-key map "\t" 'w3m-next-anchor)
-    (define-key map [tab] 'w3m-next-anchor)
-    (define-key map [(shift tab)] 'w3m-previous-anchor)
-    (define-key map [(shift iso-lefttab)] 'w3m-previous-anchor)
-    (define-key map "\M-\t" 'w3m-previous-anchor)
-    (define-key map "\C-m" 'w3m-view-this-url)
-    (define-key map [(shift return)] 'w3m-view-this-url-new-session)
-    (define-key map [(shift kp-enter)] 'w3m-view-this-url-new-session)
-    (if (featurep 'xemacs)
-	(progn
-	  (define-key map [(button2)] 'w3m-mouse-view-this-url)
-	  (define-key map [(shift button2)]
-	    'w3m-mouse-view-this-url-new-session))
-      (define-key map [mouse-2] 'w3m-mouse-view-this-url)
-      (define-key map [S-mouse-2] 'w3m-mouse-view-this-url-new-session))
-    (define-key map "\C-c\C-@" 'w3m-history-store-position)
-    (define-key map [?\C-c?\C- ] 'w3m-history-store-position)
-    (define-key map "\C-c\C-v" 'w3m-history-restore-position)
-    (define-key map " " 'w3m-scroll-up-or-next-url)
-    (define-key map "a" 'w3m-bookmark-add-current-url)
-    (define-key map "\M-a" 'w3m-bookmark-add-this-url)
-    (define-key map "+" 'w3m-antenna-add-current-url)
-    (define-key map "A" 'w3m-antenna)
-    (define-key map "b" 'w3m-scroll-down-or-previous-url)
-    (define-key map "c" 'w3m-print-this-url)
-    (define-key map "!" 'w3m-redisplay-with-content-type)
-    (define-key map "d" 'w3m-download)
-    (define-key map "D" 'w3m-download-this-url)
-    (define-key map "e" 'w3m-edit-current-url)
-    (define-key map "E" 'w3m-edit-this-url)
-    (define-key map "f" 'undefined) ;; reserved.
-    (define-key map "g" 'w3m-goto-url)
-    (define-key map "\M-g" 'goto-line)
-    (define-key map "G" 'w3m-goto-url-new-session)
-    (define-key map "h" 'describe-mode)
-    (define-key map "H" 'w3m-gohome)
-    (define-key map "i" (if (w3m-display-graphic-p)
-			    'w3m-toggle-inline-image
-			  'w3m-view-image))
-    (define-key map "I" 'w3m-toggle-inline-images)
-    (when (w3m-display-graphic-p)
-      (define-key map "\M-[" 'w3m-zoom-out-image)
-      (define-key map "\M-]" 'w3m-zoom-in-image))
-    (define-key map "\M-i" 'w3m-save-image)
-    (define-key map "l" 'w3m-view-previous-page)
-    (define-key map "\C-l" 'recenter)
-    (define-key map [(control L)] 'w3m-reload-this-page)
-    (define-key map "M" 'w3m-view-url-with-external-browser)
-    (define-key map "n" 'w3m-view-next-page)
-    (define-key map "N" 'w3m-namazu)
-    (define-key map "\M-n" 'w3m-copy-buffer)
-    (define-key map "\M-k" 'w3m-cookie)
-    (define-key map "\C-c\C-t" 'w3m-copy-buffer)
-    (define-key map "\C-c\C-p" 'w3m-previous-buffer)
-    (define-key map "\C-c\C-n" 'w3m-next-buffer)
-    (define-key map "\C-c\C-w" 'w3m-delete-buffer)
-    (define-key map "\C-c\M-w" 'w3m-delete-other-buffers)
-    (define-key map "\C-c\C-s" 'w3m-select-buffer)
-    (define-key map "\C-c\C-a" 'w3m-switch-buffer)
-    (define-key map "o" 'w3m-history)
-    (define-key map "O" 'w3m-db-history)
-    (define-key map "p" 'w3m-view-previous-page)
-    (define-key map "P" 'undecided) ;; reserved for print-this-buffer.
-    (define-key map "q" 'w3m-close-window)
-    (define-key map "Q" 'w3m-quit)
-    (define-key map "r" 'w3m-redisplay-this-page)
-    (define-key map "R" 'w3m-reload-this-page)
-    (define-key map "s" 'w3m-search)
-    (define-key map "S" (lambda ()
-			  (interactive)
-			  (let ((current-prefix-arg t))
-			    (call-interactively 'w3m-search))))
-    (define-key map "T" 'w3m-dtree)
-    (define-key map "u" 'w3m-view-parent-page)
-    (define-key map "v" 'w3m-bookmark-view)
-    (define-key map "W" 'w3m-weather)
-    (define-key map "y" 'w3m-print-this-url)
-    (define-key map "=" 'w3m-view-header)
-    (define-key map "\\" 'w3m-view-source)
-    (define-key map "?" 'describe-mode)
-    (define-key map ">" 'w3m-scroll-left)
-    (define-key map "<" 'w3m-scroll-right)
-    (define-key map [(shift right)] 'w3m-shift-left)
-    (define-key map [(shift left)] 'w3m-shift-right)
-    (define-key map "\M-l" 'w3m-horizontal-recenter)
-    (define-key map "\C-a" 'w3m-beginning-of-line)
-    (define-key map "\C-e" 'w3m-end-of-line)
-    (define-key map "." 'beginning-of-buffer)
-    (define-key map "^" 'w3m-view-parent-page)
-    (define-key map "]" 'w3m-next-form)
-    (define-key map "[" 'w3m-previous-form)
-    (define-key map "}" 'w3m-next-image)
-    (define-key map "{" 'w3m-previous-image)
-    (define-key map "C" (make-sparse-keymap))
-    (define-key map "Ct" 'w3m-redisplay-with-content-type)
-    (define-key map "Cc" 'w3m-redisplay-with-charset)
-    (define-key map "CC" 'w3m-redisplay-and-reset)
-    (define-key map "\C-c\C-b" 'report-emacs-w3m-bug)
-    (define-key map "\C-c\C-c" 'w3m-submit-form)
-    (define-key map "\C-c\C-k" 'w3m-process-stop)
-    (setq w3m-info-like-map map)))
-
 (defun w3m-alive-p ()
   "When w3m is running, return that buffer.  Otherwise return nil."
   (catch 'alive
@@ -5277,12 +5013,6 @@
     (set-window-buffer (selected-window) (other-buffer))
     (w3m-select-buffer-close-window)))
 
-(unless w3m-mode-map
-  (setq w3m-mode-map
-	(if (eq w3m-key-binding 'info)
-	    w3m-info-like-map
-	  w3m-lynx-like-map)))
-
 (defun w3m-clean-hook-options ()
   "Remove old stuffs from hook options to avoid redundant function calls."
   (dolist (elem '((w3m-mode-hook w3m-setup-header-line
@@ -7082,10 +6812,254 @@
 		 (not w3m-minor-mode)))
     (run-hooks 'w3m-minor-mode-hook)))
 
+(defun w3m-change-keymap (&optional style)
+  "Initialize `w3m-mode-map' in the specified STYLE."
+  (interactive
+   (let ((value)
+	 (default (and (boundp 'w3m-key-binding)
+		       (symbol-value 'w3m-key-binding)))
+	 (classes '(("info" . info)
+		    ("lynx" . nil))))
+     (setq default (or (car (rassq default classes)) "lynx")
+	   value (completing-read (format "Keymap Style (default %s): "
+					  default)
+				  classes nil t))
+     (list (cdr (assoc (if (string= value "") default value) classes)))))
+  (let ((map (make-keymap)))
+    (suppress-keymap map)
+    (cond
+     (;; Generate Info like map.
+      (eq style 'info)
+      (define-key map [backspace] 'w3m-scroll-down-or-previous-url)
+      (define-key map [delete] 'w3m-scroll-down-or-previous-url)
+      (define-key map "\C-?" 'w3m-scroll-down-or-previous-url)
+      (if (featurep 'xemacs)
+	  (define-key map [(shift space)] 'w3m-scroll-down-or-previous-url)
+	;; Note: It does not have an effect on Emacs 19.
+	(define-key map [?\S-\ ] 'w3m-scroll-down-or-previous-url))
+      (define-key map "\t" 'w3m-next-anchor)
+      (define-key map [tab] 'w3m-next-anchor)
+      (define-key map [(shift tab)] 'w3m-previous-anchor)
+      (define-key map [(shift iso-lefttab)] 'w3m-previous-anchor)
+      (define-key map "\M-\t" 'w3m-previous-anchor)
+      (define-key map "\C-m" 'w3m-view-this-url)
+      (define-key map [(shift return)] 'w3m-view-this-url-new-session)
+      (define-key map [(shift kp-enter)] 'w3m-view-this-url-new-session)
+      (if (featurep 'xemacs)
+	  (progn
+	    (define-key map [(button2)] 'w3m-mouse-view-this-url)
+	    (define-key map [(shift button2)]
+	      'w3m-mouse-view-this-url-new-session))
+	(define-key map [mouse-2] 'w3m-mouse-view-this-url)
+	(define-key map [S-mouse-2] 'w3m-mouse-view-this-url-new-session))
+      (define-key map "\C-c\C-@" 'w3m-history-store-position)
+      (define-key map [?\C-c?\C- ] 'w3m-history-store-position)
+      (define-key map "\C-c\C-v" 'w3m-history-restore-position)
+      (define-key map " " 'w3m-scroll-up-or-next-url)
+      (define-key map "a" 'w3m-bookmark-add-current-url)
+      (define-key map "\M-a" 'w3m-bookmark-add-this-url)
+      (define-key map "+" 'w3m-antenna-add-current-url)
+      (define-key map "A" 'w3m-antenna)
+      (define-key map "b" 'w3m-scroll-down-or-previous-url)
+      (define-key map "c" 'w3m-print-this-url)
+      (define-key map "!" 'w3m-redisplay-with-content-type)
+      (define-key map "d" 'w3m-download)
+      (define-key map "D" 'w3m-download-this-url)
+      (define-key map "e" 'w3m-edit-current-url)
+      (define-key map "E" 'w3m-edit-this-url)
+      (define-key map "f" 'undefined) ;; reserved.
+      (define-key map "g" 'w3m-goto-url)
+      (define-key map "\M-g" 'goto-line)
+      (define-key map "G" 'w3m-goto-url-new-session)
+      (define-key map "h" 'describe-mode)
+      (define-key map "H" 'w3m-gohome)
+      (define-key map "i" (if (w3m-display-graphic-p)
+			      'w3m-toggle-inline-image
+			    'w3m-view-image))
+      (define-key map "I" 'w3m-toggle-inline-images)
+      (when (w3m-display-graphic-p)
+	(define-key map "\M-[" 'w3m-zoom-out-image)
+	(define-key map "\M-]" 'w3m-zoom-in-image))
+      (define-key map "\M-i" 'w3m-save-image)
+      (define-key map "l" 'w3m-view-previous-page)
+      (define-key map "\C-l" 'recenter)
+      (define-key map [(control L)] 'w3m-reload-this-page)
+      (define-key map "M" 'w3m-view-url-with-external-browser)
+      (define-key map "n" 'w3m-view-next-page)
+      (define-key map "N" 'w3m-namazu)
+      (define-key map "\M-n" 'w3m-copy-buffer)
+      (define-key map "\M-k" 'w3m-cookie)
+      (define-key map "\C-c\C-t" 'w3m-copy-buffer)
+      (define-key map "\C-c\C-p" 'w3m-previous-buffer)
+      (define-key map "\C-c\C-n" 'w3m-next-buffer)
+      (define-key map "\C-c\C-w" 'w3m-delete-buffer)
+      (define-key map "\C-c\M-w" 'w3m-delete-other-buffers)
+      (define-key map "\C-c\C-s" 'w3m-select-buffer)
+      (define-key map "\C-c\C-a" 'w3m-switch-buffer)
+      (define-key map "o" 'w3m-history)
+      (define-key map "O" 'w3m-db-history)
+      (define-key map "p" 'w3m-view-previous-page)
+      (define-key map "P" 'undecided) ;; reserved for print-this-buffer.
+      (define-key map "q" 'w3m-close-window)
+      (define-key map "Q" 'w3m-quit)
+      (define-key map "r" 'w3m-redisplay-this-page)
+      (define-key map "R" 'w3m-reload-this-page)
+      (define-key map "s" 'w3m-search)
+      (define-key map "S" (lambda ()
+			    (interactive)
+			    (let ((current-prefix-arg t))
+			      (call-interactively 'w3m-search))))
+      (define-key map "T" 'w3m-dtree)
+      (define-key map "u" 'w3m-view-parent-page)
+      (define-key map "v" 'w3m-bookmark-view)
+      (define-key map "W" 'w3m-weather)
+      (define-key map "y" 'w3m-print-this-url)
+      (define-key map "=" 'w3m-view-header)
+      (define-key map "\\" 'w3m-view-source)
+      (define-key map "?" 'describe-mode)
+      (define-key map ">" 'w3m-scroll-left)
+      (define-key map "<" 'w3m-scroll-right)
+      (define-key map [(shift right)] 'w3m-shift-left)
+      (define-key map [(shift left)] 'w3m-shift-right)
+      (define-key map "\M-l" 'w3m-horizontal-recenter)
+      (define-key map "\C-a" 'w3m-beginning-of-line)
+      (define-key map "\C-e" 'w3m-end-of-line)
+      (define-key map "." 'beginning-of-buffer)
+      (define-key map "^" 'w3m-view-parent-page)
+      (define-key map "]" 'w3m-next-form)
+      (define-key map "[" 'w3m-previous-form)
+      (define-key map "}" 'w3m-next-image)
+      (define-key map "{" 'w3m-previous-image)
+      (define-key map "C" (make-sparse-keymap))
+      (define-key map "Ct" 'w3m-redisplay-with-content-type)
+      (define-key map "Cc" 'w3m-redisplay-with-charset)
+      (define-key map "CC" 'w3m-redisplay-and-reset)
+      (define-key map "\C-c\C-b" 'report-emacs-w3m-bug)
+      (define-key map "\C-c\C-c" 'w3m-submit-form)
+      (define-key map "\C-c\C-k" 'w3m-process-stop))
+     (t ;; Generate Lynx like map
+      (define-key map " " 'w3m-scroll-up-or-next-url)
+      (define-key map "b" 'w3m-scroll-down-or-previous-url)
+      (define-key map [backspace] 'w3m-scroll-down-or-previous-url)
+      (define-key map [delete] 'w3m-scroll-down-or-previous-url)
+      (if (featurep 'xemacs)
+	  (define-key map [(shift space)] 'w3m-scroll-down-or-previous-url)
+	;; Note: It does not have an effect on Emacs 19.
+	(define-key map [?\S-\ ] 'w3m-scroll-down-or-previous-url))
+      (define-key map "h" 'backward-char)
+      (define-key map "j" 'next-line)
+      (define-key map "k" 'previous-line)
+      (define-key map "l" 'forward-char)
+      (define-key map "J" (lambda () (interactive) (scroll-up 1)))
+      (define-key map "K" (lambda () (interactive) (scroll-down 1)))
+      (define-key map "\M-g" 'goto-line)
+      (define-key map "\C-?" 'w3m-scroll-down-or-previous-url)
+      (define-key map "\t" 'w3m-next-anchor)
+      (define-key map [tab] 'w3m-next-anchor)
+      (define-key map [(shift tab)] 'w3m-previous-anchor)
+      (define-key map [(shift iso-lefttab)] 'w3m-previous-anchor)
+      (define-key map [down] 'w3m-next-anchor)
+      (define-key map "\M-\t" 'w3m-previous-anchor)
+      (define-key map [up] 'w3m-previous-anchor)
+      (define-key map "\C-m" 'w3m-view-this-url)
+      (define-key map [(shift return)] 'w3m-view-this-url-new-session)
+      (define-key map [(shift kp-enter)] 'w3m-view-this-url-new-session)
+      (define-key map [right] 'w3m-view-this-url)
+      (if (featurep 'xemacs)
+	  (progn
+	    (define-key map [(button2)] 'w3m-mouse-view-this-url)
+	    (define-key map [(shift button2)]
+	      'w3m-mouse-view-this-url-new-session))
+	(define-key map [mouse-2] 'w3m-mouse-view-this-url)
+	(define-key map [S-mouse-2] 'w3m-mouse-view-this-url-new-session))
+      (define-key map "\C-c\C-@" 'w3m-history-store-position)
+      (if (featurep 'xemacs)
+	  (define-key map [?\C-c (control space)] 'w3m-history-store-position)
+	;; `C- ' doesn't mean `C-SPC' in XEmacs.
+	(define-key map [?\C-c ?\C-\ ] 'w3m-history-store-position))
+      (define-key map "\C-c\C-v" 'w3m-history-restore-position)
+      (define-key map [left] 'w3m-view-previous-page)
+      (define-key map "B" 'w3m-view-previous-page)
+      (define-key map "N" 'w3m-view-next-page)
+      (define-key map "^" 'w3m-view-parent-page)
+      (define-key map "d" 'w3m-download-this-url)
+      (define-key map "u" 'w3m-print-this-url)
+      (define-key map "I" 'w3m-view-image)
+      (define-key map "\M-i" 'w3m-save-image)
+      (define-key map "c" 'w3m-print-current-url)
+      (define-key map "M" 'w3m-view-url-with-external-browser)
+      (define-key map "G" 'w3m-goto-url-new-session)
+      (define-key map "g" 'w3m-goto-url)
+      (define-key map "T" 'w3m-toggle-inline-images)
+      (define-key map "t" 'w3m-toggle-inline-image)
+      (when (w3m-display-graphic-p)
+	(define-key map "\M-[" 'w3m-zoom-out-image)
+	(define-key map "\M-]" 'w3m-zoom-in-image))
+      (define-key map "U" 'w3m-goto-url)
+      (define-key map "V" 'w3m-goto-url)
+      (define-key map "v" 'w3m-bookmark-view)
+      (define-key map "q" 'w3m-close-window)
+      (define-key map "Q" 'w3m-quit)
+      (define-key map "\M-n" 'w3m-copy-buffer)
+      (define-key map "\C-c\C-t" 'w3m-copy-buffer)
+      (define-key map "\C-c\C-p" 'w3m-previous-buffer)
+      (define-key map "\C-c\C-n" 'w3m-next-buffer)
+      (define-key map "\C-c\C-w" 'w3m-delete-buffer)
+      (define-key map "\C-c\M-w" 'w3m-delete-other-buffers)
+      (define-key map "\C-c\C-s" 'w3m-select-buffer)
+      (define-key map "\C-c\C-a" 'w3m-switch-buffer)
+      (define-key map "r" 'w3m-redisplay-this-page)
+      (define-key map "R" 'w3m-reload-this-page)
+      (define-key map "?" 'describe-mode)
+      (define-key map "\M-a" 'w3m-bookmark-add-this-url)
+      (define-key map "\M-k" 'w3m-cookie)
+      (define-key map "a" 'w3m-bookmark-add-current-url)
+      (define-key map "+" 'w3m-antenna-add-current-url)
+      (define-key map "]" 'w3m-next-form)
+      (define-key map "[" 'w3m-previous-form)
+      (define-key map "}" 'w3m-next-image)
+      (define-key map "{" 'w3m-previous-image)
+      (define-key map "H" 'w3m-gohome)
+      (define-key map "A" 'w3m-antenna)
+      (define-key map "W" 'w3m-weather)
+      (define-key map "S" 'w3m-search)
+      (define-key map "D" 'w3m-dtree)
+      (define-key map ">" 'w3m-scroll-left)
+      (define-key map "<" 'w3m-scroll-right)
+      (define-key map "." 'w3m-shift-left)
+      (define-key map "," 'w3m-shift-right)
+      (define-key map "\M-l" 'w3m-horizontal-recenter)
+      (define-key map "\C-a" 'w3m-beginning-of-line)
+      (define-key map "\C-e" 'w3m-end-of-line)
+      (define-key map "\\" 'w3m-view-source)
+      (define-key map "=" 'w3m-view-header)
+      (define-key map "s" 'w3m-history)
+      (define-key map "E" 'w3m-edit-current-url)
+      (define-key map "e" 'w3m-edit-this-url)
+      (define-key map "C" (make-sparse-keymap))
+      (define-key map "Ct" 'w3m-redisplay-with-content-type)
+      (define-key map "Cc" 'w3m-redisplay-with-charset)
+      (define-key map "CC" 'w3m-redisplay-and-reset)
+      (define-key map "\C-c\C-b" 'report-emacs-w3m-bug)
+      (define-key map "\C-c\C-c" 'w3m-submit-form)
+      (define-key map "\C-c\C-k" 'w3m-process-stop)))
+    (setq w3m-mode-map map
+	  w3m-minor-mode-map (w3m-make-minor-mode-keymap)))
+  (save-current-buffer
+    (dolist (buffer (buffer-list))
+      (set-buffer buffer)
+      (if (eq major-mode 'w3m-mode)
+	  (ignore-errors
+	    (use-local-map w3m-mode-map)
+	    (w3m-setup-toolbar)
+	    (w3m-setup-menu))))))
+
 
 (provide 'w3m)
 
 (unless noninteractive
+  (w3m-change-keymap
+   (and (boundp 'w3m-key-binding) (symbol-value 'w3m-key-binding)))
   (if (string-match "\\.el\\'" w3m-init-file)
       (or (load (concat w3m-init-file "c") t t t)
 	  (load w3m-init-file t t t))