[ < ] [ > ]   [ << ] [Plus haut] [ >> ]         [Top] [Table des matières] [Index] [ ? ]

31.2.1 Left Margin Convention

Emacs assumes by default that any opening delimiter found at the left margin is the start of a top-level definition, or defun. Therefore, don't put an opening delimiter at the left margin unless it should have that significance. For instance, never put an open-parenthesis at the left margin in a Lisp file unless it is the start of a top-level list.

If you don't follow this convention, not only will you have trouble when you explicitly use the commands for motion by defuns; other features that use them will also give you trouble. This includes the indentation commands (voir la section Indentation for Programs) and Font Lock mode (voir la section Font Lock mode).

The most likely problem case is when you want an opening delimiter at the start of a line inside a string. To avoid trouble, put an escape character (‘\’, in C and Emacs Lisp, ‘/’ in some other Lisp dialects) before the opening delimiter. This will not affect the contents of the string, but will prevent that opening delimiter from starting a defun. Here's an example:

 
  (insert "Foo:
\(bar)
")

To help you catch violations of this convention, Font Lock mode highlights confusing opening delimiters (those that ought to be quoted) in bold red.

If you need to override this convention, you can so by setting this user option:

Variable: open-paren-in-column-0-is-defun-start

If this user option is set to t (the default), opening parentheses or braces at column zero always start defuns. When it's nil, defuns are found by searching for parens or braces at the outermost level.

Usually, you shouldn't need to set open-paren-in-column-0-is-defun-start to nil. However, if your buffer contains parentheses or braces in column zero which don't start defuns and this confuses Emacs, it sometimes helps to set the option to nil. Be aware, though, that this will make scrolling and display in large buffers quite sluggish, and that parentheses and braces must be correctly matched throughout the buffer for it to work properly.

In the earliest days, the original Emacs found defuns by moving upward a level of parentheses or braces until there were no more levels to go up. This always required scanning all the way back to the beginning of the buffer, even for a small function. To speed up the operation, we changed Emacs to assume that any opening delimiter at the left margin is the start of a defun. This heuristic is nearly always right, and avoids the need to scan back to the beginning of the buffer. However, now that modern computers are so powerful, this scanning is rarely slow enough to annoy, so we've provided a way to disable the heuristic.


[ < ] [ > ]   [ << ] [Plus haut] [ >> ]         [Top] [Table des matières] [Index] [ ? ]

Ce document a été généré par Eric Reinbold le 23 Février 2009 en utilisant texi2html 1.78.