comparison lispref/modes.texi @ 52744:c81c292a982b

(Major Mode Conventions): Mention third way to set up Imenu. (Imenu): A number of small fixes. Delete documentation of internal variable imenu--index-alist. Document the return value format of imenu-create-index-function functions.
author Lute Kamstra <lute@gnu.org>
date Fri, 03 Oct 2003 11:48:55 +0000
parents 5f70316d2ec5
children d738115b4197
comparison
equal deleted inserted replaced
52743:f093806b2b0d 52744:c81c292a982b
234 @code{font-lock-defaults} (@pxref{Font Lock Mode}). 234 @code{font-lock-defaults} (@pxref{Font Lock Mode}).
235 235
236 @item 236 @item
237 The mode should specify how Imenu should find the definitions or 237 The mode should specify how Imenu should find the definitions or
238 sections of a buffer, by setting up a buffer-local value for the 238 sections of a buffer, by setting up a buffer-local value for the
239 variable @code{imenu-generic-expression} or 239 variable @code{imenu-generic-expression}, for the pair of variables
240 @code{imenu-prev-index-position-function} and
241 @code{imenu-extract-index-name-function}, or for the variable
240 @code{imenu-create-index-function} (@pxref{Imenu}). 242 @code{imenu-create-index-function} (@pxref{Imenu}).
241 243
242 @item 244 @item
243 Use @code{defvar} or @code{defcustom} to set mode-related variables, so 245 Use @code{defvar} or @code{defcustom} to set mode-related variables, so
244 that they are not reinitialized if they already have a value. (Such 246 that they are not reinitialized if they already have a value. (Such
1700 1702
1701 The usual and simplest way is to set the variable 1703 The usual and simplest way is to set the variable
1702 @code{imenu-generic-expression}: 1704 @code{imenu-generic-expression}:
1703 1705
1704 @defvar imenu-generic-expression 1706 @defvar imenu-generic-expression
1705 This variable, if non-@code{nil}, specifies regular expressions for 1707 This variable, if non-@code{nil}, is a list that specifies regular
1706 finding definitions for Imenu. In the simplest case, elements should 1708 expressions for finding definitions for Imenu. Simple elements of
1707 look like this: 1709 @code{imenu-generic-expression} look like this:
1708 1710
1709 @example 1711 @example
1710 (@var{menu-title} @var{regexp} @var{subexp}) 1712 (@var{menu-title} @var{regexp} @var{index})
1711 @end example 1713 @end example
1712 1714
1713 Here, if @var{menu-title} is non-@code{nil}, it says that the matches 1715 Here, if @var{menu-title} is non-@code{nil}, it says that the matches
1714 for this element should go in a submenu of the buffer index; 1716 for this element should go in a submenu of the buffer index;
1715 @var{menu-title} itself specifies the name for the submenu. If 1717 @var{menu-title} itself specifies the name for the submenu. If
1716 @var{menu-title} is @code{nil}, the matches for this element go directly 1718 @var{menu-title} is @code{nil}, the matches for this element go directly
1717 in the top level of the buffer index. 1719 in the top level of the buffer index.
1718 1720
1719 The second item in the list, @var{regexp}, is a regular expression 1721 The second item in the list, @var{regexp}, is a regular expression
1720 (@pxref{Regular Expressions}); anything in the buffer that it matches is 1722 (@pxref{Regular Expressions}); anything in the buffer that it matches
1721 considered a definition, something to mention in the buffer index. The 1723 is considered a definition, something to mention in the buffer index.
1722 third item, @var{subexp}, indicates which subexpression in @var{regexp} 1724 The third item, @var{index}, is a non-negative integer that indicates
1723 matches the definition's name. 1725 which subexpression in @var{regexp} matches the definition's name.
1724 1726
1725 An element can also look like this: 1727 An element can also look like this:
1726 1728
1727 @example 1729 @example
1728 (@var{menu-title} @var{regexp} @var{index} @var{function} @var{arguments}@dots{}) 1730 (@var{menu-title} @var{regexp} @var{index} @var{function} @var{arguments}@dots{})
1729 @end example 1731 @end example
1730 1732
1731 Each match for this element creates a special index item which, if 1733 Like in the previous case, each match for this element creates an
1732 selected by the user, calls @var{function} with arguments consisting of 1734 index item. However, if this index item is selected by the user, it
1733 the item name, the buffer position, and @var{arguments}. 1735 calls @var{function} with arguments consisting of the item name, the
1734 1736 buffer position, and @var{arguments}.
1735 For Emacs Lisp mode, @var{pattern} could look like this: 1737
1738 For Emacs Lisp mode, @code{imenu-generic-expression} could look like
1739 this:
1736 1740
1737 @c should probably use imenu-syntax-alist and \\sw rather than [-A-Za-z0-9+] 1741 @c should probably use imenu-syntax-alist and \\sw rather than [-A-Za-z0-9+]
1738 @example 1742 @example
1739 @group 1743 @group
1740 ((nil "^\\s-*(def\\(un\\|subst\\|macro\\|advice\\)\ 1744 ((nil "^\\s-*(def\\(un\\|subst\\|macro\\|advice\\)\
1754 1758
1755 Setting this variable makes it buffer-local in the current buffer. 1759 Setting this variable makes it buffer-local in the current buffer.
1756 @end defvar 1760 @end defvar
1757 1761
1758 @defvar imenu-case-fold-search 1762 @defvar imenu-case-fold-search
1759 This variable controls whether matching against 1763 This variable controls whether matching against the regular
1760 @var{imenu-generic-expression} is case-sensitive: @code{t}, the default, 1764 expressions in the value of @code{imenu-generic-expression} is
1761 means matching should ignore case. 1765 case-sensitive: @code{t}, the default, means matching should ignore
1766 case.
1762 1767
1763 Setting this variable makes it buffer-local in the current buffer. 1768 Setting this variable makes it buffer-local in the current buffer.
1764 @end defvar 1769 @end defvar
1765 1770
1766 @defvar imenu-syntax-alist 1771 @defvar imenu-syntax-alist
1784 1789
1785 @example 1790 @example
1786 (setq imenu-syntax-alist '(("_$" . "w"))) 1791 (setq imenu-syntax-alist '(("_$" . "w")))
1787 @end example 1792 @end example
1788 1793
1789 The @code{imenu-generic-expression} patterns can then use @samp{\\sw+} 1794 The @code{imenu-generic-expression} regular expressions can then use
1790 instead of @samp{\\(\\sw\\|\\s_\\)+}. Note that this technique may be 1795 @samp{\\sw+} instead of @samp{\\(\\sw\\|\\s_\\)+}. Note that this
1791 inconvenient when the mode needs to limit the initial character 1796 technique may be inconvenient when the mode needs to limit the initial
1792 of a name to a smaller set of characters than are allowed in the rest 1797 character of a name to a smaller set of characters than are allowed in
1793 of a name. 1798 the rest of a name.
1794 1799
1795 Setting this variable makes it buffer-local in the current buffer. 1800 Setting this variable makes it buffer-local in the current buffer.
1796 @end defvar 1801 @end defvar
1797 1802
1798 Another way to customize Imenu for a major mode is to set the 1803 Another way to customize Imenu for a major mode is to set the
1821 1826
1822 The last way to customize Imenu for a major mode is to set the 1827 The last way to customize Imenu for a major mode is to set the
1823 variable @code{imenu-create-index-function}: 1828 variable @code{imenu-create-index-function}:
1824 1829
1825 @defvar imenu-create-index-function 1830 @defvar imenu-create-index-function
1826 This variable specifies the function to use for creating a buffer index. 1831 This variable specifies the function to use for creating a buffer
1827 The function should take no arguments, and return an index for the 1832 index. The function should take no arguments, and return an index
1828 current buffer. It is called within @code{save-excursion}, so where it 1833 alist for the current buffer. It is called within
1829 leaves point makes no difference. 1834 @code{save-excursion}, so where it leaves point makes no difference.
1830 1835
1831 The default value is a function that uses 1836 The index alist can have three types of elements. Simple elements
1832 @code{imenu-generic-expression} to produce the index alist. If you 1837 look like this:
1833 specify a different function, then @code{imenu-generic-expression} is 1838
1834 not used. 1839 @example
1840 (@var{index-name} . @var{index-position})
1841 @end example
1842
1843 Selecting a simple element has the effect of moving to position
1844 @var{index-position} in the buffer. Special elements look like this:
1845
1846 @example
1847 (@var{index-name} @var{index-position} @var{function} @var{arguments}@dots{})
1848 @end example
1849
1850 Selecting a special element performs:
1851
1852 @example
1853 (funcall @var{function}
1854 @var{index-name} @var{index-position} @var{arguments}@dots{})
1855 @end example
1856
1857 A nested sub-alist element looks like this:
1858
1859 @example
1860 (@var{index-name} @var{sub-alist})
1861 @end example
1862
1863 It creates a submenu specified by @var{sub-alist}.
1864
1865 The default value of @code{imenu-create-index-function} is a function
1866 that uses @code{imenu-prev-index-position-function} and
1867 @code{imenu-extract-index-name-function} to produce the index alist.
1868 However, if either of these two variables is @code{nil}, the default
1869 function uses @code{imenu-generic-expression} instead.
1835 1870
1836 Setting this variable makes it buffer-local in the current buffer. 1871 Setting this variable makes it buffer-local in the current buffer.
1837 @end defvar
1838
1839 @defvar imenu-index-alist
1840 This variable holds the index alist for the current buffer.
1841 Setting it makes it buffer-local in the current buffer.
1842
1843 Simple elements in the alist look like @code{(@var{index-name}
1844 . @var{index-position})}. Selecting a simple element has the effect of
1845 moving to position @var{index-position} in the buffer.
1846
1847 Special elements look like @code{(@var{index-name} @var{position}
1848 @var{function} @var{arguments}@dots{})}. Selecting a special element
1849 performs
1850
1851 @example
1852 (funcall @var{function} @var{index-name} @var{position} @var{arguments}@dots{})
1853 @end example
1854
1855 A nested sub-alist element looks like @code{(@var{index-name}
1856 @var{sub-alist})}.
1857 @end defvar 1872 @end defvar
1858 1873
1859 @node Font Lock Mode 1874 @node Font Lock Mode
1860 @section Font Lock Mode 1875 @section Font Lock Mode
1861 @cindex Font Lock Mode 1876 @cindex Font Lock Mode