diff options
| -rw-r--r-- | lisp/ChangeLog | 12 | ||||
| -rw-r--r-- | lisp/derived.el | 9 | ||||
| -rw-r--r-- | lisp/emacs-lisp/easy-mmode.el | 86 |
3 files changed, 85 insertions, 22 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 44130b804ad..5d0fb705d06 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,15 @@ | |||
| 1 | 2000-03-21 Stefan Monnier <monnier@cs.yale.edu> | ||
| 2 | |||
| 3 | * derived.el (define-derived-mode): Don't autoload anymore. | ||
| 4 | Prefer the macro-only version provided by easy-mmode.el. | ||
| 5 | |||
| 6 | * emacs-lisp/easy-mmode.el (define-derived-mode): New name for | ||
| 7 | `easy-mmode-define-derived-mode'. | ||
| 8 | Use `combine-run-hooks'. | ||
| 9 | (easy-mmode-define-navigation): New macro. | ||
| 10 | |||
| 11 | * subr.el (combine-run-hooks): New function. | ||
| 12 | |||
| 1 | 2000-03-21 Kenichi HANDA <handa@etl.go.jp> | 13 | 2000-03-21 Kenichi HANDA <handa@etl.go.jp> |
| 2 | 14 | ||
| 3 | * term/x-win.el: Fontsets related initialization is simplified. | 15 | * term/x-win.el: Fontsets related initialization is simplified. |
diff --git a/lisp/derived.el b/lisp/derived.el index 2aa97b9d588..ee3b917b5d7 100644 --- a/lisp/derived.el +++ b/lisp/derived.el | |||
| @@ -25,6 +25,13 @@ | |||
| 25 | 25 | ||
| 26 | ;;; Commentary: | 26 | ;;; Commentary: |
| 27 | 27 | ||
| 28 | ;; Obsolete. | ||
| 29 | ;; Use the `derived-major-mode' provided by easy-mmode.el instead. | ||
| 30 | ;; It is only kept for backward compatibility with byte-compiled files | ||
| 31 | ;; which refer to `derived-mode-init-mode-variables' and other functions. | ||
| 32 | |||
| 33 | |||
| 34 | |||
| 28 | ;; GNU Emacs is already, in a sense, object oriented -- each object | 35 | ;; GNU Emacs is already, in a sense, object oriented -- each object |
| 29 | ;; (buffer) belongs to a class (major mode), and that class defines | 36 | ;; (buffer) belongs to a class (major mode), and that class defines |
| 30 | ;; the relationship between messages (input events) and methods | 37 | ;; the relationship between messages (input events) and methods |
| @@ -95,7 +102,7 @@ | |||
| 95 | 102 | ||
| 96 | ;; PUBLIC: define a new major mode which inherits from an existing one. | 103 | ;; PUBLIC: define a new major mode which inherits from an existing one. |
| 97 | 104 | ||
| 98 | ;;;###autoload | 105 | ;; ;;;###autoload |
| 99 | (defmacro define-derived-mode (child parent name &optional docstring &rest body) | 106 | (defmacro define-derived-mode (child parent name &optional docstring &rest body) |
| 100 | "Create a new mode as a variant of an existing mode. | 107 | "Create a new mode as a variant of an existing mode. |
| 101 | 108 | ||
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index 069430a7aa6..edc0319c417 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el | |||
| @@ -236,9 +236,13 @@ ARGS is a list of additional arguments." | |||
| 236 | 236 | ||
| 237 | 237 | ||
| 238 | 238 | ||
| 239 | ;;; | ||
| 239 | ;;; A "macro-only" reimplementation of define-derived-mode. | 240 | ;;; A "macro-only" reimplementation of define-derived-mode. |
| 241 | ;;; | ||
| 240 | 242 | ||
| 241 | (defmacro easy-mmode-define-derived-mode (child parent name &optional docstring &rest body) | 243 | (defalias 'easy-mmode-define-derived-mode 'define-derived-mode) |
| 244 | ;;;###autoload | ||
| 245 | (defmacro define-derived-mode (child parent name &optional docstring &rest body) | ||
| 242 | "Create a new mode as a variant of an existing mode. | 246 | "Create a new mode as a variant of an existing mode. |
| 243 | 247 | ||
| 244 | The arguments to this command are as follow: | 248 | The arguments to this command are as follow: |
| @@ -312,34 +316,74 @@ its own `%s' just before exiting." | |||
| 312 | ,docstring | 316 | ,docstring |
| 313 | (interactive) | 317 | (interactive) |
| 314 | ; Run the parent. | 318 | ; Run the parent. |
| 315 | (,parent) | 319 | (combine-run-hooks |
| 320 | |||
| 321 | (,parent) | ||
| 316 | ; Identify special modes. | 322 | ; Identify special modes. |
| 317 | (put ',child 'special (get ',parent 'special)) | 323 | (put ',child 'special (get ',parent 'special)) |
| 318 | ; Identify the child mode. | 324 | ; Identify the child mode. |
| 319 | (setq major-mode ',child) | 325 | (setq major-mode ',child) |
| 320 | (setq mode-name ,name) | 326 | (setq mode-name ,name) |
| 321 | ; Set up maps and tables. | 327 | ; Set up maps and tables. |
| 322 | (unless (keymap-parent ,map) | 328 | (unless (keymap-parent ,map) |
| 323 | (set-keymap-parent ,map (current-local-map))) | 329 | (set-keymap-parent ,map (current-local-map))) |
| 324 | (let ((parent (char-table-parent ,syntax))) | 330 | (let ((parent (char-table-parent ,syntax))) |
| 325 | (unless (and parent (not (eq parent (standard-syntax-table)))) | 331 | (unless (and parent (not (eq parent (standard-syntax-table)))) |
| 326 | (set-char-table-parent ,syntax (syntax-table)))) | 332 | (set-char-table-parent ,syntax (syntax-table)))) |
| 327 | (when local-abbrev-table | 333 | (when local-abbrev-table |
| 328 | (mapatoms | 334 | (mapatoms |
| 329 | (lambda (symbol) | 335 | (lambda (symbol) |
| 330 | (or (intern-soft (symbol-name symbol) ,abbrev) | 336 | (or (intern-soft (symbol-name symbol) ,abbrev) |
| 331 | (define-abbrev ,abbrev (symbol-name symbol) | 337 | (define-abbrev ,abbrev (symbol-name symbol) |
| 332 | (symbol-value symbol) (symbol-function symbol)))) | 338 | (symbol-value symbol) (symbol-function symbol)))) |
| 333 | local-abbrev-table)) | 339 | local-abbrev-table)) |
| 334 | 340 | ||
| 335 | (use-local-map ,map) | 341 | (use-local-map ,map) |
| 336 | (set-syntax-table ,syntax) | 342 | (set-syntax-table ,syntax) |
| 337 | (setq local-abbrev-table ,abbrev) | 343 | (setq local-abbrev-table ,abbrev) |
| 338 | ; Splice in the body (if any). | 344 | ; Splice in the body (if any). |
| 339 | ,@body | 345 | ,@body) |
| 340 | ; Run the hooks, if any. | 346 | ; Run the hooks, if any. |
| 341 | (run-hooks ',hook))))) | 347 | (run-hooks ',hook))))) |
| 342 | 348 | ||
| 349 | |||
| 350 | ;;; | ||
| 351 | ;;; easy-mmode-define-navigation | ||
| 352 | ;;; | ||
| 353 | |||
| 354 | (defmacro easy-mmode-define-navigation (base re &optional name endfun) | ||
| 355 | "Define BASE-next and BASE-prev to navigate in the buffer. | ||
| 356 | RE determines the places the commands should move point to. | ||
| 357 | NAME should describe the entities matched by RE and is used to build | ||
| 358 | the docstrings of the two functions. | ||
| 359 | BASE-next also tries to make sure that the whole entry is visible by | ||
| 360 | searching for its end (by calling ENDFUN if provided or by looking for | ||
| 361 | the next entry) and recentering if necessary. | ||
| 362 | ENDFUN should return the end position (with or without moving point)." | ||
| 363 | (let* ((base-name (symbol-name base)) | ||
| 364 | (prev-sym (intern (concat base-name "-prev"))) | ||
| 365 | (next-sym (intern (concat base-name "-next")))) | ||
| 366 | `(progn | ||
| 367 | (defun ,next-sym (&optional count) | ||
| 368 | ,(format "Go to the next COUNT'th %s." (or name base-name)) | ||
| 369 | (interactive) | ||
| 370 | (unless count (setq count 1)) | ||
| 371 | (if (< count 0) (,prev-sym (- count)) | ||
| 372 | (if (looking-at ,re) (incf count)) | ||
| 373 | (or (re-search-forward ,re nil t count) (ding)) | ||
| 374 | (goto-char (match-beginning 0)) | ||
| 375 | (when (eq (current-buffer) (window-buffer (selected-window))) | ||
| 376 | (let ((endpt (or (save-excursion | ||
| 377 | ,(if endfun `(,endfun) | ||
| 378 | `(re-search-forward ,re nil t 2))) | ||
| 379 | (point-max)))) | ||
| 380 | (unless (<= endpt (window-end)) (recenter)))))) | ||
| 381 | (defun ,prev-sym (&optional count) | ||
| 382 | ,(format "Go to the previous COUNT'th %s" (or name base-name)) | ||
| 383 | (interactive) | ||
| 384 | (unless count (setq count 1)) | ||
| 385 | (if (< count 0) (,next-sym (- count)) | ||
| 386 | (or (re-search-backward ,re nil t count) (ding))))))) | ||
| 343 | 387 | ||
| 344 | (provide 'easy-mmode) | 388 | (provide 'easy-mmode) |
| 345 | 389 | ||