diff options
| author | Juanma Barranquero | 2010-04-15 03:12:20 +0200 |
|---|---|---|
| committer | Juanma Barranquero | 2010-04-15 03:12:20 +0200 |
| commit | 528b9ea9fff19090ae08197fd4b7ccd9b26caa47 (patch) | |
| tree | 609cdf87ed150d03998b5aaa853896cbb45348c1 | |
| parent | 5f2b693f1849f30e6ab616df8bb73f1e395fa33d (diff) | |
| download | emacs-528b9ea9fff19090ae08197fd4b7ccd9b26caa47.tar.gz emacs-528b9ea9fff19090ae08197fd4b7ccd9b26caa47.zip | |
Simplify by using `define-derived-mode'.
* info.el (Info-mode):
* calendar/todo-mode.el (todo-mode):
* play/gomoku.el (gomoku-mode): Define with `define-derived-mode'.
(gomoku-mode-map): Move initialization into declaration.
| -rw-r--r-- | lisp/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/calendar/todo-mode.el | 14 | ||||
| -rw-r--r-- | lisp/info.el | 29 | ||||
| -rw-r--r-- | lisp/play/gomoku.el | 121 |
4 files changed, 78 insertions, 94 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 8b743adb1b0..f3fd06f1220 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2010-04-15 Juanma Barranquero <lekktu@gmail.com> | ||
| 2 | |||
| 3 | Simplify by using `define-derived-mode'. | ||
| 4 | * info.el (Info-mode): | ||
| 5 | * calendar/todo-mode.el (todo-mode): | ||
| 6 | * play/gomoku.el (gomoku-mode): Define with `define-derived-mode'. | ||
| 7 | (gomoku-mode-map): Move initialization into declaration. | ||
| 8 | |||
| 1 | 2010-04-14 Michael Albinus <michael.albinus@gmx.de> | 9 | 2010-04-14 Michael Albinus <michael.albinus@gmx.de> |
| 2 | 10 | ||
| 3 | Fix Bug#5840. | 11 | Fix Bug#5840. |
diff --git a/lisp/calendar/todo-mode.el b/lisp/calendar/todo-mode.el index 6e8aac171c1..8fd41163eaf 100644 --- a/lisp/calendar/todo-mode.el +++ b/lisp/calendar/todo-mode.el | |||
| @@ -918,17 +918,9 @@ If INCLUDE-SEP is non-nil, return point after the separator." | |||
| 918 | 918 | ||
| 919 | ;; As calendar reads .todo-do before todo-mode is loaded. | 919 | ;; As calendar reads .todo-do before todo-mode is loaded. |
| 920 | ;;;###autoload | 920 | ;;;###autoload |
| 921 | (defun todo-mode () | 921 | (define-derived-mode todo-mode nil "TODO" |
| 922 | "Major mode for editing TODO lists. | 922 | "Major mode for editing TODO lists." |
| 923 | 923 | (easy-menu-add todo-menu)) | |
| 924 | \\{todo-mode-map}" | ||
| 925 | (interactive) | ||
| 926 | (kill-all-local-variables) | ||
| 927 | (setq major-mode 'todo-mode) | ||
| 928 | (setq mode-name "TODO") | ||
| 929 | (use-local-map todo-mode-map) | ||
| 930 | (easy-menu-add todo-menu) | ||
| 931 | (run-mode-hooks 'todo-mode-hook)) | ||
| 932 | 924 | ||
| 933 | (defvar date) | 925 | (defvar date) |
| 934 | (defvar entry) | 926 | (defvar entry) |
diff --git a/lisp/info.el b/lisp/info.el index df892d499dc..18a11d28777 100644 --- a/lisp/info.el +++ b/lisp/info.el | |||
| @@ -3833,7 +3833,7 @@ With a zero prefix arg, put the name inside a function call to `info'." | |||
| 3833 | 3833 | ||
| 3834 | ;; Autoload cookie needed by desktop.el | 3834 | ;; Autoload cookie needed by desktop.el |
| 3835 | ;;;###autoload | 3835 | ;;;###autoload |
| 3836 | (defun Info-mode () | 3836 | (define-derived-mode Info-mode nil "Info" |
| 3837 | "Info mode provides commands for browsing through the Info documentation tree. | 3837 | "Info mode provides commands for browsing through the Info documentation tree. |
| 3838 | Documentation in Info is divided into \"nodes\", each of which discusses | 3838 | Documentation in Info is divided into \"nodes\", each of which discusses |
| 3839 | one topic and contains references to other nodes which discuss related | 3839 | one topic and contains references to other nodes which discuss related |
| @@ -3895,23 +3895,17 @@ Advanced commands: | |||
| 3895 | \\[clone-buffer] Select a new cloned Info buffer in another window. | 3895 | \\[clone-buffer] Select a new cloned Info buffer in another window. |
| 3896 | \\[universal-argument] \\[info] Move to new Info file with completion. | 3896 | \\[universal-argument] \\[info] Move to new Info file with completion. |
| 3897 | \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>." | 3897 | \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>." |
| 3898 | (kill-all-local-variables) | 3898 | :syntax-table text-mode-syntax-table |
| 3899 | (setq major-mode 'Info-mode) | 3899 | :abbrev-table text-mode-abbrev-table |
| 3900 | (setq mode-name "Info") | ||
| 3901 | (setq tab-width 8) | 3900 | (setq tab-width 8) |
| 3902 | (use-local-map Info-mode-map) | ||
| 3903 | (add-hook 'activate-menubar-hook 'Info-menu-update nil t) | 3901 | (add-hook 'activate-menubar-hook 'Info-menu-update nil t) |
| 3904 | (set-syntax-table text-mode-syntax-table) | ||
| 3905 | (setq local-abbrev-table text-mode-abbrev-table) | ||
| 3906 | (setq case-fold-search t) | 3902 | (setq case-fold-search t) |
| 3907 | (setq buffer-read-only t) | 3903 | (setq buffer-read-only t) |
| 3908 | (make-local-variable 'Info-current-file) | 3904 | (make-local-variable 'Info-current-file) |
| 3909 | (make-local-variable 'Info-current-subfile) | 3905 | (make-local-variable 'Info-current-subfile) |
| 3910 | (make-local-variable 'Info-current-node) | 3906 | (make-local-variable 'Info-current-node) |
| 3911 | (make-local-variable 'Info-tag-table-marker) | 3907 | (set (make-local-variable 'Info-tag-table-marker) (make-marker)) |
| 3912 | (setq Info-tag-table-marker (make-marker)) | 3908 | (set (make-local-variable 'Info-tag-table-buffer) nil) |
| 3913 | (make-local-variable 'Info-tag-table-buffer) | ||
| 3914 | (setq Info-tag-table-buffer nil) | ||
| 3915 | (make-local-variable 'Info-history) | 3909 | (make-local-variable 'Info-history) |
| 3916 | (make-local-variable 'Info-history-forward) | 3910 | (make-local-variable 'Info-history-forward) |
| 3917 | (make-local-variable 'Info-index-alternatives) | 3911 | (make-local-variable 'Info-index-alternatives) |
| @@ -3920,12 +3914,10 @@ Advanced commands: | |||
| 3920 | '(:eval (get-text-property (point-min) 'header-line)))) | 3914 | '(:eval (get-text-property (point-min) 'header-line)))) |
| 3921 | (set (make-local-variable 'tool-bar-map) info-tool-bar-map) | 3915 | (set (make-local-variable 'tool-bar-map) info-tool-bar-map) |
| 3922 | ;; This is for the sake of the invisible text we use handling titles. | 3916 | ;; This is for the sake of the invisible text we use handling titles. |
| 3923 | (make-local-variable 'line-move-ignore-invisible) | 3917 | (set (make-local-variable 'line-move-ignore-invisible) t) |
| 3924 | (setq line-move-ignore-invisible t) | 3918 | (set (make-local-variable 'desktop-save-buffer) |
| 3925 | (make-local-variable 'desktop-save-buffer) | 3919 | 'Info-desktop-buffer-misc-data) |
| 3926 | (make-local-variable 'widen-automatically) | 3920 | (set (make-local-variable 'widen-automatically) nil) |
| 3927 | (setq widen-automatically nil) | ||
| 3928 | (setq desktop-save-buffer 'Info-desktop-buffer-misc-data) | ||
| 3929 | (add-hook 'kill-buffer-hook 'Info-kill-buffer nil t) | 3921 | (add-hook 'kill-buffer-hook 'Info-kill-buffer nil t) |
| 3930 | (add-hook 'clone-buffer-hook 'Info-clone-buffer nil t) | 3922 | (add-hook 'clone-buffer-hook 'Info-clone-buffer nil t) |
| 3931 | (add-hook 'change-major-mode-hook 'font-lock-defontify nil t) | 3923 | (add-hook 'change-major-mode-hook 'font-lock-defontify nil t) |
| @@ -3944,8 +3936,7 @@ Advanced commands: | |||
| 3944 | 'Info-revert-buffer-function) | 3936 | 'Info-revert-buffer-function) |
| 3945 | (Info-set-mode-line) | 3937 | (Info-set-mode-line) |
| 3946 | (set (make-local-variable 'bookmark-make-record-function) | 3938 | (set (make-local-variable 'bookmark-make-record-function) |
| 3947 | 'Info-bookmark-make-record) | 3939 | 'Info-bookmark-make-record)) |
| 3948 | (run-mode-hooks 'Info-mode-hook)) | ||
| 3949 | 3940 | ||
| 3950 | ;; When an Info buffer is killed, make sure the associated tags buffer | 3941 | ;; When an Info buffer is killed, make sure the associated tags buffer |
| 3951 | ;; is killed too. | 3942 | ;; is killed too. |
diff --git a/lisp/play/gomoku.el b/lisp/play/gomoku.el index e18d4bdc292..dbe3317a020 100644 --- a/lisp/play/gomoku.el +++ b/lisp/play/gomoku.el | |||
| @@ -102,59 +102,60 @@ One useful value to include is `turn-on-font-lock' to highlight the pieces." | |||
| 102 | "*Number of lines between the Gomoku board and the top of the window.") | 102 | "*Number of lines between the Gomoku board and the top of the window.") |
| 103 | 103 | ||
| 104 | 104 | ||
| 105 | (defvar gomoku-mode-map nil | 105 | (defvar gomoku-mode-map |
| 106 | (let ((map (make-sparse-keymap))) | ||
| 107 | |||
| 108 | ;; Key bindings for cursor motion. | ||
| 109 | (define-key map "y" 'gomoku-move-nw) ; y | ||
| 110 | (define-key map "u" 'gomoku-move-ne) ; u | ||
| 111 | (define-key map "b" 'gomoku-move-sw) ; b | ||
| 112 | (define-key map "n" 'gomoku-move-se) ; n | ||
| 113 | (define-key map "h" 'backward-char) ; h | ||
| 114 | (define-key map "l" 'forward-char) ; l | ||
| 115 | (define-key map "j" 'gomoku-move-down) ; j | ||
| 116 | (define-key map "k" 'gomoku-move-up) ; k | ||
| 117 | |||
| 118 | (define-key map [kp-7] 'gomoku-move-nw) | ||
| 119 | (define-key map [kp-9] 'gomoku-move-ne) | ||
| 120 | (define-key map [kp-1] 'gomoku-move-sw) | ||
| 121 | (define-key map [kp-3] 'gomoku-move-se) | ||
| 122 | (define-key map [kp-4] 'backward-char) | ||
| 123 | (define-key map [kp-6] 'forward-char) | ||
| 124 | (define-key map [kp-2] 'gomoku-move-down) | ||
| 125 | (define-key map [kp-8] 'gomoku-move-up) | ||
| 126 | |||
| 127 | (define-key map "\C-n" 'gomoku-move-down) ; C-n | ||
| 128 | (define-key map "\C-p" 'gomoku-move-up) ; C-p | ||
| 129 | |||
| 130 | ;; Key bindings for entering Human moves. | ||
| 131 | (define-key map "X" 'gomoku-human-plays) ; X | ||
| 132 | (define-key map "x" 'gomoku-human-plays) ; x | ||
| 133 | (define-key map " " 'gomoku-human-plays) ; SPC | ||
| 134 | (define-key map "\C-m" 'gomoku-human-plays) ; RET | ||
| 135 | (define-key map "\C-c\C-p" 'gomoku-human-plays) ; C-c C-p | ||
| 136 | (define-key map "\C-c\C-b" 'gomoku-human-takes-back) ; C-c C-b | ||
| 137 | (define-key map "\C-c\C-r" 'gomoku-human-resigns) ; C-c C-r | ||
| 138 | (define-key map "\C-c\C-e" 'gomoku-emacs-plays) ; C-c C-e | ||
| 139 | |||
| 140 | (define-key map [kp-enter] 'gomoku-human-plays) | ||
| 141 | (define-key map [insert] 'gomoku-human-plays) | ||
| 142 | (define-key map [down-mouse-1] 'gomoku-click) | ||
| 143 | (define-key map [drag-mouse-1] 'gomoku-click) | ||
| 144 | (define-key map [mouse-1] 'gomoku-click) | ||
| 145 | (define-key map [down-mouse-2] 'gomoku-click) | ||
| 146 | (define-key map [mouse-2] 'gomoku-mouse-play) | ||
| 147 | (define-key map [drag-mouse-2] 'gomoku-mouse-play) | ||
| 148 | |||
| 149 | (define-key map [remap previous-line] 'gomoku-move-up) | ||
| 150 | (define-key map [remap next-line] 'gomoku-move-down) | ||
| 151 | (define-key map [remap move-beginning-of-line] 'gomoku-beginning-of-line) | ||
| 152 | (define-key map [remap move-end-of-line] 'gomoku-end-of-line) | ||
| 153 | (define-key map [remap undo] 'gomoku-human-takes-back) | ||
| 154 | (define-key map [remap advertised-undo] 'gomoku-human-takes-back) | ||
| 155 | map) | ||
| 156 | |||
| 106 | "Local keymap to use in Gomoku mode.") | 157 | "Local keymap to use in Gomoku mode.") |
| 107 | 158 | ||
| 108 | (if gomoku-mode-map nil | ||
| 109 | (setq gomoku-mode-map (make-sparse-keymap)) | ||
| 110 | |||
| 111 | ;; Key bindings for cursor motion. | ||
| 112 | (define-key gomoku-mode-map "y" 'gomoku-move-nw) ; y | ||
| 113 | (define-key gomoku-mode-map "u" 'gomoku-move-ne) ; u | ||
| 114 | (define-key gomoku-mode-map "b" 'gomoku-move-sw) ; b | ||
| 115 | (define-key gomoku-mode-map "n" 'gomoku-move-se) ; n | ||
| 116 | (define-key gomoku-mode-map "h" 'backward-char) ; h | ||
| 117 | (define-key gomoku-mode-map "l" 'forward-char) ; l | ||
| 118 | (define-key gomoku-mode-map "j" 'gomoku-move-down) ; j | ||
| 119 | (define-key gomoku-mode-map "k" 'gomoku-move-up) ; k | ||
| 120 | |||
| 121 | (define-key gomoku-mode-map [kp-7] 'gomoku-move-nw) | ||
| 122 | (define-key gomoku-mode-map [kp-9] 'gomoku-move-ne) | ||
| 123 | (define-key gomoku-mode-map [kp-1] 'gomoku-move-sw) | ||
| 124 | (define-key gomoku-mode-map [kp-3] 'gomoku-move-se) | ||
| 125 | (define-key gomoku-mode-map [kp-4] 'backward-char) | ||
| 126 | (define-key gomoku-mode-map [kp-6] 'forward-char) | ||
| 127 | (define-key gomoku-mode-map [kp-2] 'gomoku-move-down) | ||
| 128 | (define-key gomoku-mode-map [kp-8] 'gomoku-move-up) | ||
| 129 | |||
| 130 | (define-key gomoku-mode-map "\C-n" 'gomoku-move-down) ; C-n | ||
| 131 | (define-key gomoku-mode-map "\C-p" 'gomoku-move-up) ; C-p | ||
| 132 | |||
| 133 | ;; Key bindings for entering Human moves. | ||
| 134 | (define-key gomoku-mode-map "X" 'gomoku-human-plays) ; X | ||
| 135 | (define-key gomoku-mode-map "x" 'gomoku-human-plays) ; x | ||
| 136 | (define-key gomoku-mode-map " " 'gomoku-human-plays) ; SPC | ||
| 137 | (define-key gomoku-mode-map "\C-m" 'gomoku-human-plays) ; RET | ||
| 138 | (define-key gomoku-mode-map "\C-c\C-p" 'gomoku-human-plays) ; C-c C-p | ||
| 139 | (define-key gomoku-mode-map "\C-c\C-b" 'gomoku-human-takes-back) ; C-c C-b | ||
| 140 | (define-key gomoku-mode-map "\C-c\C-r" 'gomoku-human-resigns) ; C-c C-r | ||
| 141 | (define-key gomoku-mode-map "\C-c\C-e" 'gomoku-emacs-plays) ; C-c C-e | ||
| 142 | |||
| 143 | (define-key gomoku-mode-map [kp-enter] 'gomoku-human-plays) | ||
| 144 | (define-key gomoku-mode-map [insert] 'gomoku-human-plays) | ||
| 145 | (define-key gomoku-mode-map [down-mouse-1] 'gomoku-click) | ||
| 146 | (define-key gomoku-mode-map [drag-mouse-1] 'gomoku-click) | ||
| 147 | (define-key gomoku-mode-map [mouse-1] 'gomoku-click) | ||
| 148 | (define-key gomoku-mode-map [down-mouse-2] 'gomoku-click) | ||
| 149 | (define-key gomoku-mode-map [mouse-2] 'gomoku-mouse-play) | ||
| 150 | (define-key gomoku-mode-map [drag-mouse-2] 'gomoku-mouse-play) | ||
| 151 | |||
| 152 | (define-key gomoku-mode-map [remap previous-line] 'gomoku-move-up) | ||
| 153 | (define-key gomoku-mode-map [remap next-line] 'gomoku-move-down) | ||
| 154 | (define-key gomoku-mode-map [remap move-beginning-of-line] 'gomoku-beginning-of-line) | ||
| 155 | (define-key gomoku-mode-map [remap move-end-of-line] 'gomoku-end-of-line) | ||
| 156 | (define-key gomoku-mode-map [remap undo] 'gomoku-human-takes-back) | ||
| 157 | (define-key gomoku-mode-map [remap advertised-undo] 'gomoku-human-takes-back)) | ||
| 158 | 159 | ||
| 159 | (defvar gomoku-emacs-won () | 160 | (defvar gomoku-emacs-won () |
| 160 | "For making font-lock use the winner's face for the line.") | 161 | "For making font-lock use the winner's face for the line.") |
| @@ -182,28 +183,20 @@ One useful value to include is `turn-on-font-lock' to highlight the pieces." | |||
| 182 | ;; allow View Mode to be activated in its buffer. | 183 | ;; allow View Mode to be activated in its buffer. |
| 183 | (put 'gomoku-mode 'mode-class 'special) | 184 | (put 'gomoku-mode 'mode-class 'special) |
| 184 | 185 | ||
| 185 | (defun gomoku-mode () | 186 | (define-derived-mode gomoku-mode nil "Gomoku" |
| 186 | "Major mode for playing Gomoku against Emacs. | 187 | "Major mode for playing Gomoku against Emacs. |
| 187 | You and Emacs play in turn by marking a free square. You mark it with X | 188 | You and Emacs play in turn by marking a free square. You mark it with X |
| 188 | and Emacs marks it with O. The winner is the first to get five contiguous | 189 | and Emacs marks it with O. The winner is the first to get five contiguous |
| 189 | marks horizontally, vertically or in diagonal. | 190 | marks horizontally, vertically or in diagonal. |
| 190 | 191 | \\<gomoku-mode-map> | |
| 191 | You play by moving the cursor over the square you choose and hitting \\[gomoku-human-plays]. | 192 | You play by moving the cursor over the square you choose and hitting \\[gomoku-human-plays]. |
| 192 | 193 | ||
| 193 | Other useful commands: | 194 | Other useful commands:\n |
| 194 | \\{gomoku-mode-map} | 195 | \\{gomoku-mode-map}" |
| 195 | Entry to this mode calls the value of `gomoku-mode-hook' if that value | ||
| 196 | is non-nil." | ||
| 197 | (interactive) | ||
| 198 | (kill-all-local-variables) | ||
| 199 | (setq major-mode 'gomoku-mode | ||
| 200 | mode-name "Gomoku") | ||
| 201 | (gomoku-display-statistics) | 196 | (gomoku-display-statistics) |
| 202 | (use-local-map gomoku-mode-map) | ||
| 203 | (make-local-variable 'font-lock-defaults) | 197 | (make-local-variable 'font-lock-defaults) |
| 204 | (setq font-lock-defaults '(gomoku-font-lock-keywords t)) | 198 | (setq font-lock-defaults '(gomoku-font-lock-keywords t)) |
| 205 | (toggle-read-only t) | 199 | (toggle-read-only t)) |
| 206 | (run-mode-hooks 'gomoku-mode-hook)) | ||
| 207 | 200 | ||
| 208 | ;;; | 201 | ;;; |
| 209 | ;;; THE BOARD. | 202 | ;;; THE BOARD. |