diff options
Diffstat (limited to 'doc/lispref/modes.texi')
-rw-r--r-- | doc/lispref/modes.texi | 97 |
1 files changed, 61 insertions, 36 deletions
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi index d9caeab3bc3..69c022e5253 100644 --- a/doc/lispref/modes.texi +++ b/doc/lispref/modes.texi @@ -59,12 +59,13 @@ runs just before Emacs suspends itself (@pxref{Suspending Emacs}). @cindex abnormal hook If the hook variable's name does not end with @samp{-hook}, that -indicates it is probably an @dfn{abnormal hook}. That means the hook -functions are called with arguments, or their return values are used -in some way. The hook's documentation says how the functions are -called. Any functions added to an abnormal hook must follow the -hook's calling convention. By convention, abnormal hook names end in -@samp{-functions}. +indicates it is probably an @dfn{abnormal hook}. These differ from +normal hooks in two ways: they can be called with one or more +arguments, and their return values can be used in some way. The +hook's documentation says how the functions are called and how their +return values are used. Any functions added to an abnormal hook must +follow the hook's calling convention. By convention, abnormal hook +names end in @samp{-functions}. @cindex single-function hook If the name of the variable ends in @samp{-predicate} or @@ -268,6 +269,18 @@ normal-mode}), but tries to force it not to choose any modes in @var{avoided-modes}, if that argument is non-@code{nil}. @end defun +@defun clean-mode +Changing the major mode clears out most local variables, but it +doesn't remove all artefacts in the buffer (like text properties and +overlays). It's rare to change a buffer from one major mode to +another (except from @code{fundamental-mode} to everything else), so +this is usually not a concern. It can sometimes be convenient (mostly +when debugging a problem in a buffer) to do a ``full reset'' of the +buffer, and that's what the @code{clean-mode} major mode offers. It +will kill all local variables (even the permanently local ones), and +also removes all overlays and text properties. +@end defun + The easiest way to write a major mode is to use the macro @code{define-derived-mode}, which sets up the new mode as a variant of an existing major mode. @xref{Derived Modes}. We recommend using @@ -471,6 +484,22 @@ Each face that the mode defines should, if possible, inherit from an existing Emacs face. @xref{Basic Faces}, and @ref{Faces for Font Lock}. @item +Consider adding a mode-specific menu to the menu bar. This should +preferably include the most important menu-specific settings and +commands that will allow users discovering the main features quickly +and efficiently. + +@item +@cindex context menus, for a major mode +@vindex context-menu-functions +Consider adding mode-specific context menus for the mode, to be used +if and when users activate the @code{context-menu-mode} (@pxref{Menu +Mouse Clicks,,, emacs, The Emacs Manual}). To this end, define a +mode-specific function which builds one or more menus depending on the +location of the @kbd{mouse-3} click in the buffer, and then add that +function to the buffer-local value of @code{context-menu-functions}. + +@item The mode should specify how Imenu should find the definitions or sections of a buffer, by setting up a buffer-local value for the variable @code{imenu-generic-expression}, for the two variables @@ -887,10 +916,8 @@ which in turn may have been changed in a mode hook. Here is a hypothetical example: @example -(defvar hypertext-mode-map - (let ((map (make-sparse-keymap))) - (define-key map [down-mouse-3] 'do-hyper-link) - map)) +(defvar-keymap hypertext-mode-map + "<down-mouse-3>" #'do-hyper-link) (define-derived-mode hypertext-mode text-mode "Hypertext" @@ -1121,10 +1148,11 @@ re-sorting entries. Comparison is done with @code{equal}. @item @var{contents} is a vector with the same number of elements as @code{tabulated-list-format}. Each vector element is either a string, -which is inserted into the buffer as-is, or a list @code{(@var{label} -. @var{properties})}, which means to insert a text button by calling -@code{insert-text-button} with @var{label} and @var{properties} as -arguments (@pxref{Making Buttons}). +which is inserted into the buffer as-is; an image descriptor, which is +used to insert an image (@pxref{Image Descriptors}); or a list +@w{@code{(@var{label} . @var{properties})}}, which means to insert a +text button by calling @code{insert-text-button} with @var{label} and +@var{properties} as arguments (@pxref{Making Buttons}). There should be no newlines in any of these strings. @end itemize @@ -1314,11 +1342,9 @@ the conventions listed above: ;; @r{Create the keymap for this mode.} @group -(defvar text-mode-map - (let ((map (make-sparse-keymap))) - (define-key map "\e\t" 'ispell-complete-word) - @dots{} - map) +(defvar-keymap text-mode-map + "C-M-i" #'ispell-complete-word + @dots{}) "Keymap for `text-mode'. Many other modes, such as `mail-mode', `outline-mode' and `indented-text-mode', inherit all the commands defined in this map.") @@ -1391,13 +1417,11 @@ common. The following code sets up the common commands: @smallexample @group -(defvar lisp-mode-shared-map - (let ((map (make-sparse-keymap))) - (set-keymap-parent map prog-mode-map) - (define-key map "\e\C-q" 'indent-sexp) - (define-key map "\177" 'backward-delete-char-untabify) - map) - "Keymap for commands shared by all sorts of Lisp modes.") +(defvar-keymap lisp-mode-shared-map + :parent prog-mode-map + :doc "Keymap for commands shared by all sorts of Lisp modes." + "C-M-q" #'indent-sexp + "DEL" #'backward-delete-char-untabify) @end group @end smallexample @@ -1406,16 +1430,12 @@ And here is the code to set up the keymap for Lisp mode: @smallexample @group -(defvar lisp-mode-map - (let ((map (make-sparse-keymap)) - (menu-map (make-sparse-keymap "Lisp"))) - (set-keymap-parent map lisp-mode-shared-map) - (define-key map "\e\C-x" 'lisp-eval-defun) - (define-key map "\C-c\C-z" 'run-lisp) - @dots{} - map) - "Keymap for ordinary Lisp mode. -All commands in `lisp-mode-shared-map' are inherited by this map.") +(defvar-keymap lisp-mode-map + :doc "Keymap for ordinary Lisp mode. +All commands in `lisp-mode-shared-map' are inherited by this map." + :parent lisp-mode-shared-map + "C-M-x" #'lisp-eval-defun + "C-c C-z" #'run-lisp) @end group @end smallexample @@ -3299,6 +3319,11 @@ This function tells Font Lock mode to run the Lisp function current buffer. It calls @var{function} before calling the default fontification functions, and gives it two arguments, @var{start} and @var{end}, which specify the region to be fontified or refontified. +If @var{function} performs fontifications, it can return a list of the +form @w{@code{(jit-lock-bounds @var{beg} . @var{end})}}, to indicate +the bounds of the region it actually fontified; JIT font-lock will use +this information to optimize subsequent redisplay cycles and regions +of buffer text it will pass to future calls to @var{function}. The optional argument @var{contextual}, if non-@code{nil}, forces Font Lock mode to always refontify a syntactically relevant part of the |