• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.9.5/emacs-92/emacs/lisp/emacs-lisp/

Lines Matching defs:mode

2 ;; (formerly mode-clone.el)
32 ;; (buffer) belongs to a class (major mode), and that class defines
38 ;; use of hooks and a bit of work -- sgml-mode, for example, also runs
39 ;; the hooks for text-mode, and keymaps can inherit from other keymaps
40 ;; -- but generally, each major mode ends up reinventing the wheel.
43 ;; new major mode, the user should need only to name the existing mode
48 ;; `define-derived-mode' allows the user to make a variant of an existing
49 ;; major mode, with its own keymap. The new mode will inherit the key
53 ;; (define-derived-mode hypertext-mode text-mode "Hypertext"
54 ;; "Major mode for hypertext.\n\n\\{hypertext-mode-map}"
57 ;; (define-key hypertext-mode-map [down-mouse-3] 'do-hyper-link)
59 ;; will create a function `hypertext-mode' with its own (sparse)
60 ;; keymap `hypertext-mode-map.' The command M-x hypertext-mode will
63 ;; - run the command (text-mode) to get its default setup
64 ;; - replace the current keymap with 'hypertext-mode-map,' which will
65 ;; inherit from 'text-mode-map'.
67 ;; 'hypertext-mode-syntax-table', which will borrow its defaults
68 ;; from the current text-mode-syntax-table.
70 ;; 'hypertext-mode-abbrev-table', which will borrow its defaults
71 ;; from the current text-mode-abbrev table
72 ;; - change the mode line to read "Hypertext"
73 ;; - assign the value 'hypertext-mode' to the 'major-mode' variable
77 ;; The advantages of this system are threefold. First, text mode is
78 ;; untouched -- if you had added the new keystroke to `text-mode-map,'
82 ;; a derived mode from a derived mode. The commands
84 ;; (define-derived-mode html-mode hypertext-mode "HTML")
87 ;; will add a new major mode for HTML with very little fuss.
89 ;; Note also the function `derived-mode-p' which can tell if the current
90 ;; mode derives from another. In a hypertext-mode, buffer, for example,
91 ;; (derived-mode-p 'text-mode) would return non-nil. This should always
92 ;; be used in place of (eq major-mode 'text-mode).
101 (defsubst derived-mode-hook-name (mode)
102 "Construct a mode-hook name based on a MODE name."
103 (intern (concat (symbol-name mode) "-hook")))
105 (defsubst derived-mode-map-name (mode)
107 (intern (concat (symbol-name mode) "-map")))
109 (defsubst derived-mode-syntax-table-name (mode)
111 (intern (concat (symbol-name mode) "-syntax-table")))
113 (defsubst derived-mode-abbrev-table-name (mode)
115 (intern (concat (symbol-name mode) "-abbrev-table")))
117 ;; PUBLIC: define a new major mode which inherits from an existing one.
120 (defmacro define-derived-mode (child parent name &optional docstring &rest body)
121 "Create a new mode as a variant of an existing mode.
125 CHILD: the name of the command for the derived mode.
126 PARENT: the name of the command for the parent mode (e.g. `text-mode')
132 hooks for the new mode. Do not use `interactive' here.
137 Declare the customization group that corresponds to this mode.
138 The command `customize-mode' uses this.
146 Here is how you could define LaTeX-Thesis mode as a variant of LaTeX mode:
148 (define-derived-mode LaTeX-thesis-mode LaTeX-mode \"LaTeX-Thesis\")
150 You could then make new key bindings for `LaTeX-thesis-mode-map'
151 without changing regular LaTeX mode. In this example, BODY is empty,
154 On a more complicated level, the following command uses `sgml-mode' as
157 (define-derived-mode article-mode sgml-mode \"Article\"
158 \"Major mode for editing technical articles.\"
164 The new mode runs the hook constructed by the function
165 `derived-mode-hook-name'.
177 (when (eq parent 'fundamental-mode) (setq parent nil))
179 (let ((map (derived-mode-map-name child))
180 (syntax (derived-mode-syntax-table-name child))
181 (abbrev (derived-mode-abbrev-table-name child))
184 (hook (derived-mode-hook-name child))
195 (setq docstring (derived-mode-make-docstring
201 ,(format "Hook run when entering %s mode.
218 (put ',child 'derived-mode-parent ',parent)
219 ,(if group `(put ',child 'custom-mode-group ,group))
225 (delay-mode-hooks
228 ; Identify the child mode.
229 (setq major-mode (quote ,child))
230 (setq mode-name ,name)
234 (if (get (quote ,parent) 'mode-class)
235 (put (quote ,child) 'mode-class
236 (get (quote ,parent) 'mode-class)))
240 ;; at the toplevel rather than inside the mode function,
244 ;; than <parent>-mode-map.
260 ;; that do not yet have run-mode-hooks.
261 (if (fboundp 'run-mode-hooks)
262 (run-mode-hooks ',hook)
265 ;; PUBLIC: find the ultimate class of a derived mode.
267 (defun derived-mode-class (mode)
269 A mode's class is the first ancestor which is NOT a derived mode.
270 Use the `derived-mode-parent' property of the symbol to trace backwards.
271 Since major-modes might all derive from `fundamental-mode', this function
273 (while (get mode 'derived-mode-parent)
274 (setq mode (get mode 'derived-mode-parent)))
275 mode)
276 (make-obsolete 'derived-mode-class 'derived-mode-p "22.1")
282 (defun derived-mode-make-docstring (parent child &optional
284 "Construct a docstring for a new mode if none is provided."
286 (let ((map (derived-mode-map-name child))
287 (hook (derived-mode-hook-name child)))
293 (format "Major-mode.
295 (format "Major mode derived from `%s' by `define-derived-mode'.
305 ;; Make sure the docstring mentions the mode's hook.
309 "\n\nThis mode "
311 "\n\nIn addition to any hooks its parent mode "
315 "might have run,\nthis mode "))
320 ;; And don't forget to put the mode's keymap.
331 (defsubst derived-mode-setup-function-name (mode)
333 (intern (concat (symbol-name mode) "-setup")))
337 ;; Utility functions for defining a derived mode.
340 (defun derived-mode-init-mode-variables (mode)
344 the first time the mode is used."
346 (if (boundp (derived-mode-map-name mode))
348 (eval `(defvar ,(derived-mode-map-name mode)
350 ,(format "Keymap for %s." mode)))
351 (put (derived-mode-map-name mode) 'derived-mode-unmerged t))
353 (if (boundp (derived-mode-syntax-table-name mode))
355 (eval `(defvar ,(derived-mode-syntax-table-name mode)
358 ;; derived-mode-merge-syntax-tables.
360 ,(format "Syntax table for %s." mode)))
361 (put (derived-mode-syntax-table-name mode) 'derived-mode-unmerged t))
363 (if (boundp (derived-mode-abbrev-table-name mode))
365 (eval `(defvar ,(derived-mode-abbrev-table-name mode)
367 (define-abbrev-table (derived-mode-abbrev-table-name mode) nil)
369 ,(format "Abbrev table for %s." mode)))))
372 ;; Utility functions for running a derived mode.
374 (defun derived-mode-set-keymap (mode)
376 (let* ((map-name (derived-mode-map-name mode))
380 (get map-name 'derived-mode-unmerged)
381 (derived-mode-merge-keymaps old-map new-map))
382 (put map-name 'derived-mode-unmerged nil)
385 (defun derived-mode-set-syntax-table (mode)
387 (let* ((table-name (derived-mode-syntax-table-name mode))
390 (if (get table-name 'derived-mode-unmerged)
391 (derived-mode-merge-syntax-tables old-table new-table))
392 (put table-name 'derived-mode-unmerged nil)
395 (defun derived-mode-set-abbrev-table (mode)
398 (let* ((table-name (derived-mode-abbrev-table-name mode))
401 (derived-mode-merge-abbrev-tables old-table new-table)
404 (defun derived-mode-run-hooks (mode)
405 "Run the mode hook for MODE."
406 (let ((hooks-name (derived-mode-hook-name mode)))
412 (defun derived-mode-merge-keymaps (old new)
426 (derived-mode-merge-keymaps subold subnew))))
436 (derived-mode-merge-keymaps subold subnew)))
441 (defun derived-mode-merge-syntax-tables (old new)
450 (defun derived-mode-merge-abbrev-tables (old new)