Mercurial > emacs
comparison lispref/modes.texi @ 59942:1f6a9cf44999
(Major Mode Conventions): Mention "system abbrevs".
Mode inheritance applies only when default-major-mode is nil.
Clarifications.
(Example Major Modes): Update Text mode and Lisp mode examples.
(Minor Mode Conventions): Mention define-minor-mode at top.
(Defining Minor Modes): In Hungry example, don't define C-M-DEL.
(Mode Line Format): Update mode line face display info.
(Properties in Mode): Mention effect of risky vars.
(Imenu): Define imenu-add-to-menubar.
(Font Lock Mode): Add descriptions to menu lines.
(Faces for Font Lock): Add font-lock-doc-face.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 06 Feb 2005 10:49:35 +0000 |
parents | f50d20947c20 |
children | 2bc848857427 |
comparison
equal
deleted
inserted
replaced
59941:654691f40a53 | 59942:1f6a9cf44999 |
---|---|
233 Comments,, Options Controlling Comments, emacs, The GNU Emacs Manual}. | 233 Comments,, Options Controlling Comments, emacs, The GNU Emacs Manual}. |
234 | 234 |
235 @item | 235 @item |
236 @cindex abbrev tables in modes | 236 @cindex abbrev tables in modes |
237 The mode may have its own abbrev table or may share one with other | 237 The mode may have its own abbrev table or may share one with other |
238 related modes. If it has its own abbrev table, it should store this in | 238 related modes. If it has its own abbrev table, it should store this |
239 a variable named @code{@var{modename}-mode-abbrev-table}. @xref{Abbrev | 239 in a variable named @code{@var{modename}-mode-abbrev-table}. If the |
240 Tables}. | 240 major mode command defines any abbrevs itself, it should pass @code{t} |
241 for the @var{system-flag} argument to @code{define-abbrev}. | |
242 @xref{Abbrev Tables}. | |
241 | 243 |
242 @item | 244 @item |
243 The mode should specify how to do highlighting for Font Lock mode, by | 245 The mode should specify how to do highlighting for Font Lock mode, by |
244 setting up a buffer-local value for the variable | 246 setting up a buffer-local value for the variable |
245 @code{font-lock-defaults} (@pxref{Font Lock Mode}). | 247 @code{font-lock-defaults} (@pxref{Font Lock Mode}). |
306 @example | 308 @example |
307 (put 'funny-mode 'mode-class 'special) | 309 (put 'funny-mode 'mode-class 'special) |
308 @end example | 310 @end example |
309 | 311 |
310 @noindent | 312 @noindent |
311 This tells Emacs that new buffers created while the current buffer is in | 313 This tells Emacs that new buffers created while the current buffer is |
312 Funny mode should not inherit Funny mode. Modes such as Dired, Rmail, | 314 in Funny mode should not inherit Funny mode, in case |
315 @code{default-major-mode} is @code{nil}. Modes such as Dired, Rmail, | |
313 and Buffer List use this feature. | 316 and Buffer List use this feature. |
314 | 317 |
315 @item | 318 @item |
316 If you want to make the new mode the default for files with certain | 319 If you want to make the new mode the default for files with certain |
317 recognizable names, add an element to @code{auto-mode-alist} to select | 320 recognizable names, add an element to @code{auto-mode-alist} to select |
319 autoload, you should add this element in the same file that calls | 322 autoload, you should add this element in the same file that calls |
320 @code{autoload}. Otherwise, it is sufficient to add the element in the | 323 @code{autoload}. Otherwise, it is sufficient to add the element in the |
321 file that contains the mode definition. @xref{Auto Major Mode}. | 324 file that contains the mode definition. @xref{Auto Major Mode}. |
322 | 325 |
323 @item | 326 @item |
324 In the documentation, you should provide a sample @code{autoload} form | 327 In the comments that document the file, you should provide a sample |
325 and an example of how to add to @code{auto-mode-alist}, that users can | 328 @code{autoload} form and an example of how to add to |
326 include in their init files (@pxref{Init File}). | 329 @code{auto-mode-alist}, that users can include in their init files |
330 (@pxref{Init File}). | |
327 | 331 |
328 @item | 332 @item |
329 @cindex mode loading | 333 @cindex mode loading |
330 The top-level forms in the file defining the mode should be written so | 334 The top-level forms in the file defining the mode should be written so |
331 that they may be evaluated more than once without adverse consequences. | 335 that they may be evaluated more than once without adverse consequences. |
339 Here are excerpts from @file{text-mode.el} that illustrate many of | 343 Here are excerpts from @file{text-mode.el} that illustrate many of |
340 the conventions listed above: | 344 the conventions listed above: |
341 | 345 |
342 @smallexample | 346 @smallexample |
343 @group | 347 @group |
344 ;; @r{Create mode-specific tables.} | 348 ;; @r{Create the syntax table for this mode.} |
345 (defvar text-mode-syntax-table nil | 349 (defvar text-mode-syntax-table |
346 "Syntax table used while in text mode.") | 350 (let ((st (make-syntax-table))) |
347 @end group | 351 (modify-syntax-entry ?\" ". " st) |
348 | 352 (modify-syntax-entry ?\\ ". " st) |
349 @group | 353 ;; We add `p' so that M-c on 'hello' leads to 'Hello' rather than 'hello'. |
350 (if text-mode-syntax-table | 354 (modify-syntax-entry ?' "w p" st) |
351 () ; @r{Do not change the table if it is already set up.} | 355 st) |
352 (setq text-mode-syntax-table (make-syntax-table)) | 356 "Syntax table used while in `text-mode'.") |
353 (modify-syntax-entry ?\" ". " text-mode-syntax-table) | 357 @end group |
354 (modify-syntax-entry ?\\ ". " text-mode-syntax-table) | 358 |
355 (modify-syntax-entry ?' "w " text-mode-syntax-table)) | 359 ;; @r{Create the keymap for this mode.} |
356 @end group | 360 @group |
357 | 361 (defvar text-mode-map |
358 @group | 362 (let ((map (make-sparse-keymap))) |
363 (define-key map "\e\t" 'ispell-complete-word) | |
364 (define-key map "\es" 'center-line) | |
365 (define-key map "\eS" 'center-paragraph) | |
366 map) | |
367 "Keymap for `text-mode'. | |
368 Many other modes, such as `mail-mode', `outline-mode' and `indented-text-mode', | |
369 inherit all the commands defined in this map.") | |
370 @end group | |
371 @end smallexample | |
372 | |
373 Here is how the actual mode command is defined now: | |
374 | |
375 @smallexample | |
376 @group | |
377 (define-derived-mode text-mode nil "Text" | |
378 "Major mode for editing text written for humans to read. | |
379 In this mode, paragraphs are delimited only by blank or white lines. | |
380 You can thus get the full benefit of adaptive filling | |
381 (see the variable `adaptive-fill-mode'). | |
382 \\{text-mode-map} | |
383 Turning on Text mode runs the normal hook `text-mode-hook'." | |
384 @end group | |
385 @group | |
386 (make-local-variable 'text-mode-variant) | |
387 (setq text-mode-variant t) | |
388 ;; @r{These two lines are a feature added recently.} | |
389 (set (make-local-variable 'require-final-newline) | |
390 mode-require-final-newline) | |
391 (set (make-local-variable 'indent-line-function) 'indent-relative)) | |
392 @end group | |
393 @end smallexample | |
394 | |
395 But here is how it was defined formerly, before | |
396 @code{define-derived-mode} existed: | |
397 | |
398 @smallexample | |
399 @group | |
400 ;; @r{This isn't needed nowadays, since @code{define-derived-mode} does it.} | |
359 (defvar text-mode-abbrev-table nil | 401 (defvar text-mode-abbrev-table nil |
360 "Abbrev table used while in text mode.") | 402 "Abbrev table used while in text mode.") |
361 (define-abbrev-table 'text-mode-abbrev-table ()) | 403 (define-abbrev-table 'text-mode-abbrev-table ()) |
362 @end group | 404 @end group |
363 | 405 |
364 @group | |
365 (defvar text-mode-map nil ; @r{Create a mode-specific keymap.} | |
366 "Keymap for Text mode. | |
367 Many other modes, such as Mail mode, Outline mode and Indented Text mode, | |
368 inherit all the commands defined in this map.") | |
369 | |
370 (if text-mode-map | |
371 () ; @r{Do not change the keymap if it is already set up.} | |
372 (setq text-mode-map (make-sparse-keymap)) | |
373 (define-key text-mode-map "\e\t" 'ispell-complete-word) | |
374 (define-key text-mode-map "\t" 'indent-relative) | |
375 (define-key text-mode-map "\es" 'center-line) | |
376 (define-key text-mode-map "\eS" 'center-paragraph)) | |
377 @end group | |
378 @end smallexample | |
379 | |
380 This was formerly the complete major mode function definition for Text mode: | |
381 | |
382 @smallexample | |
383 @group | 406 @group |
384 (defun text-mode () | 407 (defun text-mode () |
385 "Major mode for editing text intended for humans to read... | 408 "Major mode for editing text intended for humans to read... |
386 Special commands: \\@{text-mode-map@} | 409 Special commands: \\@{text-mode-map@} |
387 @end group | 410 @end group |
394 @group | 417 @group |
395 (setq local-abbrev-table text-mode-abbrev-table) | 418 (setq local-abbrev-table text-mode-abbrev-table) |
396 (set-syntax-table text-mode-syntax-table) | 419 (set-syntax-table text-mode-syntax-table) |
397 @end group | 420 @end group |
398 @group | 421 @group |
422 ;; @r{These four lines are absent from the current version} | |
423 ;; @r{not because this is done some other way, but rather} | |
424 ;; @r{because nowadays Text mode uses the normal definition of paragraphs.} | |
399 (make-local-variable 'paragraph-start) | 425 (make-local-variable 'paragraph-start) |
400 (setq paragraph-start (concat "[ \t]*$\\|" page-delimiter)) | 426 (setq paragraph-start (concat "[ \t]*$\\|" page-delimiter)) |
401 (make-local-variable 'paragraph-separate) | 427 (make-local-variable 'paragraph-separate) |
402 (setq paragraph-separate paragraph-start) | 428 (setq paragraph-separate paragraph-start) |
403 (make-local-variable 'indent-line-function) | 429 (make-local-variable 'indent-line-function) |
420 @cindex syntax table example | 446 @cindex syntax table example |
421 @smallexample | 447 @smallexample |
422 @group | 448 @group |
423 ;; @r{Create mode-specific table variables.} | 449 ;; @r{Create mode-specific table variables.} |
424 (defvar lisp-mode-syntax-table nil "") | 450 (defvar lisp-mode-syntax-table nil "") |
425 (defvar emacs-lisp-mode-syntax-table nil "") | |
426 (defvar lisp-mode-abbrev-table nil "") | 451 (defvar lisp-mode-abbrev-table nil "") |
427 @end group | 452 @end group |
428 | 453 |
429 @group | 454 @group |
430 (if (not emacs-lisp-mode-syntax-table) ; @r{Do not change the table} | 455 (defvar emacs-lisp-mode-syntax-table |
431 ; @r{if it is already set.} | 456 (let ((table (make-syntax-table))) |
432 (let ((i 0)) | 457 (let ((i 0)) |
433 (setq emacs-lisp-mode-syntax-table (make-syntax-table)) | 458 @end group |
434 @end group | 459 |
435 | 460 @group |
436 @group | 461 ;; @r{Set syntax of chars up to @samp{0} to say they are} |
437 ;; @r{Set syntax of chars up to 0 to class of chars that are} | |
438 ;; @r{part of symbol names but not words.} | 462 ;; @r{part of symbol names but not words.} |
439 ;; @r{(The number 0 is @code{48} in the @acronym{ASCII} character set.)} | 463 ;; @r{(The digit @samp{0} is @code{48} in the @acronym{ASCII} character set.)} |
440 (while (< i ?0) | 464 (while (< i ?0) |
441 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) | 465 (modify-syntax-entry i "_ " table) |
442 (setq i (1+ i))) | 466 (setq i (1+ i))) |
443 @dots{} | 467 ;; @r{@dots{} similar code follows for other character ranges.} |
444 @end group | 468 @end group |
445 @group | 469 @group |
446 ;; @r{Set the syntax for other characters.} | 470 ;; @r{Then set the syntax codes for characters that are special in Lisp.} |
447 (modify-syntax-entry ? " " emacs-lisp-mode-syntax-table) | 471 (modify-syntax-entry ? " " table) |
448 (modify-syntax-entry ?\t " " emacs-lisp-mode-syntax-table) | 472 (modify-syntax-entry ?\t " " table) |
449 @dots{} | 473 (modify-syntax-entry ?\f " " table) |
450 @end group | 474 (modify-syntax-entry ?\n "> " table) |
451 @group | 475 @end group |
452 (modify-syntax-entry ?\( "() " emacs-lisp-mode-syntax-table) | 476 @group |
453 (modify-syntax-entry ?\) ")( " emacs-lisp-mode-syntax-table) | 477 ;; @r{Give CR the same syntax as newline, for selective-display.} |
454 @dots{})) | 478 (modify-syntax-entry ?\^m "> " table) |
479 (modify-syntax-entry ?\; "< " table) | |
480 (modify-syntax-entry ?` "' " table) | |
481 (modify-syntax-entry ?' "' " table) | |
482 (modify-syntax-entry ?, "' " table) | |
483 @end group | |
484 @end group | |
485 @group | |
486 ;; @r{@dots{}likewise for many other characters@dots{}} | |
487 (modify-syntax-entry ?\( "() " table) | |
488 (modify-syntax-entry ?\) ")( " table) | |
489 (modify-syntax-entry ?\[ "(] " table) | |
490 (modify-syntax-entry ?\] ")[ " table)) | |
491 table)) | |
492 @end group | |
455 ;; @r{Create an abbrev table for lisp-mode.} | 493 ;; @r{Create an abbrev table for lisp-mode.} |
456 (define-abbrev-table 'lisp-mode-abbrev-table ()) | 494 (define-abbrev-table 'lisp-mode-abbrev-table ()) |
457 @end group | 495 @end group |
458 @end smallexample | 496 @end smallexample |
459 | 497 |
462 mode functions: | 500 mode functions: |
463 | 501 |
464 @smallexample | 502 @smallexample |
465 @group | 503 @group |
466 (defun lisp-mode-variables (lisp-syntax) | 504 (defun lisp-mode-variables (lisp-syntax) |
467 (cond (lisp-syntax | 505 (when lisp-syntax |
468 (set-syntax-table lisp-mode-syntax-table))) | 506 (set-syntax-table lisp-mode-syntax-table)) |
469 (setq local-abbrev-table lisp-mode-abbrev-table) | 507 (setq local-abbrev-table lisp-mode-abbrev-table) |
470 @dots{} | 508 @dots{} |
471 @end group | 509 @end group |
472 @end smallexample | 510 @end smallexample |
473 | 511 |
502 @smallexample | 540 @smallexample |
503 @group | 541 @group |
504 (defvar shared-lisp-mode-map () | 542 (defvar shared-lisp-mode-map () |
505 "Keymap for commands shared by all sorts of Lisp modes.") | 543 "Keymap for commands shared by all sorts of Lisp modes.") |
506 | 544 |
545 ;; @r{Putting this @code{if} after the @code{defvar} is an older style.} | |
507 (if shared-lisp-mode-map | 546 (if shared-lisp-mode-map |
508 () | 547 () |
509 (setq shared-lisp-mode-map (make-sparse-keymap)) | 548 (setq shared-lisp-mode-map (make-sparse-keymap)) |
510 (define-key shared-lisp-mode-map "\e\C-q" 'indent-sexp) | 549 (define-key shared-lisp-mode-map "\e\C-q" 'indent-sexp) |
511 (define-key shared-lisp-mode-map "\177" | 550 (define-key shared-lisp-mode-map "\177" |
555 (use-local-map lisp-mode-map) ; @r{Select the mode's keymap.} | 594 (use-local-map lisp-mode-map) ; @r{Select the mode's keymap.} |
556 (setq major-mode 'lisp-mode) ; @r{This is how @code{describe-mode}} | 595 (setq major-mode 'lisp-mode) ; @r{This is how @code{describe-mode}} |
557 ; @r{finds out what to describe.} | 596 ; @r{finds out what to describe.} |
558 (setq mode-name "Lisp") ; @r{This goes into the mode line.} | 597 (setq mode-name "Lisp") ; @r{This goes into the mode line.} |
559 (lisp-mode-variables t) ; @r{This defines various variables.} | 598 (lisp-mode-variables t) ; @r{This defines various variables.} |
599 (make-local-variable 'comment-start-skip) | |
600 (setq comment-start-skip | |
601 "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\)\\(;+\\|#|\\) *") | |
602 (make-local-variable 'font-lock-keywords-case-fold-search) | |
603 (setq font-lock-keywords-case-fold-search t) | |
560 @end group | 604 @end group |
561 @group | 605 @group |
562 (setq imenu-case-fold-search t) | 606 (setq imenu-case-fold-search t) |
563 (set-syntax-table lisp-mode-syntax-table) | 607 (set-syntax-table lisp-mode-syntax-table) |
564 (run-mode-hooks 'lisp-mode-hook)) ; @r{This permits the user to use a} | 608 (run-mode-hooks 'lisp-mode-hook)) ; @r{This permits the user to use a} |
909 modes as well: those regarding the name of the mode initialization | 953 modes as well: those regarding the name of the mode initialization |
910 function, the names of global symbols, and the use of keymaps and | 954 function, the names of global symbols, and the use of keymaps and |
911 other tables. | 955 other tables. |
912 | 956 |
913 In addition, there are several conventions that are specific to | 957 In addition, there are several conventions that are specific to |
914 minor modes. | 958 minor modes. (The easiest way to follow all the conventions is to use |
959 the macro @code{define-minor-mode}; @ref{Defining Minor Modes}.) | |
915 | 960 |
916 @itemize @bullet | 961 @itemize @bullet |
917 @item | 962 @item |
918 @cindex mode variable | 963 @cindex mode variable |
919 Make a variable whose name ends in @samp{-mode} to control the minor | 964 Make a variable whose name ends in @samp{-mode} to control the minor |
999 the first step is to define the mode variable with @code{defcustom}, and | 1044 the first step is to define the mode variable with @code{defcustom}, and |
1000 specify @code{:type boolean}. | 1045 specify @code{:type boolean}. |
1001 | 1046 |
1002 If just setting the variable is not sufficient to enable the mode, you | 1047 If just setting the variable is not sufficient to enable the mode, you |
1003 should also specify a @code{:set} method which enables the mode by | 1048 should also specify a @code{:set} method which enables the mode by |
1004 invoke the mode command. Note in the variable's documentation string that | 1049 invoking the mode command. Note in the variable's documentation string that |
1005 setting the variable other than via Custom may not take effect. | 1050 setting the variable other than via Custom may not take effect. |
1006 | 1051 |
1007 Also mark the definition with an autoload cookie (@pxref{Autoload}), | 1052 Also mark the definition with an autoload cookie (@pxref{Autoload}), |
1008 and specify a @code{:require} so that customizing the variable will load | 1053 and specify a @code{:require} so that customizing the variable will load |
1009 the library that defines the mode. This will copy suitable definitions | 1054 the library that defines the mode. This will copy suitable definitions |
1122 ;; The initial value. | 1167 ;; The initial value. |
1123 nil | 1168 nil |
1124 ;; The indicator for the mode line. | 1169 ;; The indicator for the mode line. |
1125 " Hungry" | 1170 " Hungry" |
1126 ;; The minor mode bindings. | 1171 ;; The minor mode bindings. |
1127 '(("\C-\^?" . hungry-electric-delete) | 1172 '(("\C-\^?" . hungry-electric-delete)) |
1128 ("\C-\M-\^?" | |
1129 . (lambda () | |
1130 (interactive) | |
1131 (hungry-electric-delete t)))) | |
1132 :group 'hunger) | 1173 :group 'hunger) |
1133 @end smallexample | 1174 @end smallexample |
1134 | 1175 |
1135 @noindent | 1176 @noindent |
1136 This defines a minor mode named ``Hungry mode'', a command named | 1177 This defines a minor mode named ``Hungry mode'', a command named |
1137 @code{hungry-mode} to toggle it, a variable named @code{hungry-mode} | 1178 @code{hungry-mode} to toggle it, a variable named @code{hungry-mode} |
1138 which indicates whether the mode is enabled, and a variable named | 1179 which indicates whether the mode is enabled, and a variable named |
1139 @code{hungry-mode-map} which holds the keymap that is active when the | 1180 @code{hungry-mode-map} which holds the keymap that is active when the |
1140 mode is enabled. It initializes the keymap with key bindings for | 1181 mode is enabled. It initializes the keymap with a key binding for |
1141 @kbd{C-@key{DEL}} and @kbd{C-M-@key{DEL}}. It puts the variable | 1182 @kbd{C-@key{DEL}}. It puts the variable @code{hungry-mode} into |
1142 @code{hungry-mode} into custom group @code{hunger}. There are no | 1183 custom group @code{hunger}. There are no @var{body} forms---many |
1143 @var{body} forms---many minor modes don't need any. | 1184 minor modes don't need any. |
1144 | 1185 |
1145 Here's an equivalent way to write it: | 1186 Here's an equivalent way to write it: |
1146 | 1187 |
1147 @smallexample | 1188 @smallexample |
1148 (define-minor-mode hungry-mode | 1189 (define-minor-mode hungry-mode |
1214 | 1255 |
1215 This function also forces recomputation of the menu bar menus | 1256 This function also forces recomputation of the menu bar menus |
1216 and the frame title. | 1257 and the frame title. |
1217 @end defun | 1258 @end defun |
1218 | 1259 |
1219 The mode line is usually displayed in inverse video; see | 1260 The selected window's mode line is usually displayed in a different |
1220 @code{mode-line-inverse-video} in @ref{Inverse Video}. | 1261 color using the face @code{mode-line}. Other windows' mode lines |
1262 appear in the face @code{mode-line-inactive} instead. @xref{Faces}. | |
1221 | 1263 |
1222 A window that is just one line tall does not display either a mode | 1264 A window that is just one line tall does not display either a mode |
1223 line or a header line, even if the variables call for one. A window | 1265 line or a header line, even if the variables call for one. A window |
1224 that is two lines tall cannot display both a mode line and a header | 1266 that is two lines tall cannot display both a mode line and a header |
1225 line at once; if the variables call for both, only the mode line | 1267 line at once; if the variables call for both, only the mode line |
1701 You use the @code{local-map} property to specify a keymap. Like any | 1743 You use the @code{local-map} property to specify a keymap. Like any |
1702 keymap, it can bind character keys and function keys; but that has no | 1744 keymap, it can bind character keys and function keys; but that has no |
1703 effect, since it is impossible to move point into the mode line. This | 1745 effect, since it is impossible to move point into the mode line. This |
1704 keymap can only take real effect for mouse clicks. | 1746 keymap can only take real effect for mouse clicks. |
1705 | 1747 |
1748 When the mode line refers to a variable which does not have a | |
1749 non-@code{nil} @code{risky-local-variable} property, any text | |
1750 properties given or specified within that variable's values are | |
1751 ignored. This is because such properties could otherwise specify | |
1752 functions to be called, and those functions could come from file | |
1753 local variables. | |
1754 | |
1706 @node Header Lines | 1755 @node Header Lines |
1707 @subsection Window Header Lines | 1756 @subsection Window Header Lines |
1708 @cindex header line (of a window) | 1757 @cindex header line (of a window) |
1709 @cindex window header line | 1758 @cindex window header line |
1710 | 1759 |
1768 @dfn{Imenu} is a feature that lets users select a definition or | 1817 @dfn{Imenu} is a feature that lets users select a definition or |
1769 section in the buffer, from a menu which lists all of them, to go | 1818 section in the buffer, from a menu which lists all of them, to go |
1770 directly to that location in the buffer. Imenu works by constructing | 1819 directly to that location in the buffer. Imenu works by constructing |
1771 a buffer index which lists the names and buffer positions of the | 1820 a buffer index which lists the names and buffer positions of the |
1772 definitions, or other named portions of the buffer; then the user can | 1821 definitions, or other named portions of the buffer; then the user can |
1773 choose one of them and move point to it. The user-level commands for | 1822 choose one of them and move point to it. Major modes can add a menu |
1774 using Imenu are described in the Emacs Manual (@pxref{Imenu,, Imenu, | 1823 bar item to use Imenu using @code{imenu-add-to-menubar}. |
1775 emacs, the Emacs Manual}). This section explains how to customize | 1824 |
1776 Imenu's method of finding definitions or buffer portions for a | 1825 @defun imenu-add-to-menubar name |
1777 particular major mode. | 1826 This function defines a local menu bar item named @var{name} |
1827 to run Imenu. | |
1828 @end defun | |
1829 | |
1830 The user-level commands for using Imenu are described in the Emacs | |
1831 Manual (@pxref{Imenu,, Imenu, emacs, the Emacs Manual}). This section | |
1832 explains how to customize Imenu's method of finding definitions or | |
1833 buffer portions for a particular major mode. | |
1778 | 1834 |
1779 The usual and simplest way is to set the variable | 1835 The usual and simplest way is to set the variable |
1780 @code{imenu-generic-expression}: | 1836 @code{imenu-generic-expression}: |
1781 | 1837 |
1782 @defvar imenu-generic-expression | 1838 @defvar imenu-generic-expression |
1965 comments and string constants, and highlights them using | 2021 comments and string constants, and highlights them using |
1966 @code{font-lock-comment-face} and @code{font-lock-string-face} | 2022 @code{font-lock-comment-face} and @code{font-lock-string-face} |
1967 (@pxref{Faces for Font Lock}). Search-based fontification follows. | 2023 (@pxref{Faces for Font Lock}). Search-based fontification follows. |
1968 | 2024 |
1969 @menu | 2025 @menu |
1970 * Font Lock Basics:: | 2026 * Font Lock Basics:: Overview of customizing Font Lock. |
1971 * Search-based Fontification:: | 2027 * Search-based Fontification:: Fontification based on regexps. |
1972 * Other Font Lock Variables:: | 2028 * Other Font Lock Variables:: Additional customization facilities. |
1973 * Levels of Font Lock:: | 2029 * Levels of Font Lock:: Each mode can define alternative levels |
1974 * Precalculated Fontification:: | 2030 so that the user can select more or less. |
1975 * Faces for Font Lock:: | 2031 * Precalculated Fontification:: How Lisp programs that produce the buffer |
1976 * Syntactic Font Lock:: | 2032 contents can also specify how to fontify it. |
2033 * Faces for Font Lock:: Special faces specifically for Font Lock. | |
2034 * Syntactic Font Lock:: Defining character syntax based on context | |
2035 using the Font Lock mechanism. | |
1977 @end menu | 2036 @end menu |
1978 | 2037 |
1979 @node Font Lock Basics | 2038 @node Font Lock Basics |
1980 @subsection Font Lock Basics | 2039 @subsection Font Lock Basics |
1981 | 2040 |
2355 @end itemize | 2414 @end itemize |
2356 | 2415 |
2357 @node Precalculated Fontification | 2416 @node Precalculated Fontification |
2358 @subsection Precalculated Fontification | 2417 @subsection Precalculated Fontification |
2359 | 2418 |
2360 In addition to using @code{font-lock-defaults} for search-based | 2419 In addition to using @code{font-lock-defaults} for search-based |
2361 fontification, you may use the special character property | 2420 fontification, you may use the special character property |
2362 @code{font-lock-face} (@pxref{Special Properties}). This property | 2421 @code{font-lock-face} (@pxref{Special Properties}). This property |
2363 acts just like the explicit @code{face} property, but its activation | 2422 acts just like the explicit @code{face} property, but its activation |
2364 is toggled when the user calls @kbd{M-x font-lock-mode}. Using | 2423 is toggled when the user calls @kbd{M-x font-lock-mode}. Using |
2365 @code{font-lock-face} is especially convenient for special modes | 2424 @code{font-lock-face} is especially convenient for special modes |
2391 | 2450 |
2392 @table @code | 2451 @table @code |
2393 @item font-lock-comment-face | 2452 @item font-lock-comment-face |
2394 @vindex font-lock-comment-face | 2453 @vindex font-lock-comment-face |
2395 Used (typically) for comments. | 2454 Used (typically) for comments. |
2455 | |
2456 @item font-lock-doc-face | |
2457 @vindex font-lock-doc-face | |
2458 Used (typically) for documentation strings in the code. | |
2396 | 2459 |
2397 @item font-lock-string-face | 2460 @item font-lock-string-face |
2398 @vindex font-lock-string-face | 2461 @vindex font-lock-string-face |
2399 Used (typically) for string constants. | 2462 Used (typically) for string constants. |
2400 | 2463 |