PageRenderTime 59ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/doc/users-guide/source-edit.xml

#
XML | 670 lines | 534 code | 131 blank | 5 comment | 0 complexity | bb9fbad93af0445e0326462dde0f00a2 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <chapter id="source-edit">
  3. <title>Editing Source Code</title>
  4. <!-- jEdit buffer-local properties: -->
  5. <!-- :tabSize=1:indentSize=1:noTabs=true:wrap=soft:maxLineLen=80: -->
  6. <!-- :xml.root=users-guide.xml: -->
  7. <section id="modes">
  8. <title>Edit Modes</title>
  9. <para>An <firstterm>edit mode</firstterm> specifies syntax highlighting
  10. rules, auto indent behavior, and various other customizations for
  11. editing a certain file type. This section only covers using existing
  12. edit modes; information about writing your own can be found in <xref
  13. linkend="writing-modes-part" />.</para>
  14. <para>When a file is opened, jEdit first checks the file name against a
  15. list of known patterns. For example, files whose names end with
  16. <filename>.c</filename> are opened with C mode, and files named
  17. <filename>Makefile</filename> are opened with Makefile mode. If a
  18. suitable match based on file name cannot be found, jEdit checks the
  19. first line of the file. For example, files whose first line is
  20. <filename>#!/bin/sh</filename> are opened with shell script mode.</para>
  21. <section id="mode-selection">
  22. <title>Mode Selection</title>
  23. <para>File name and first line matching is done using glob patterns
  24. similar to those used in Unix shells. Glob patterns associated with
  25. edit modes can be changed in the <guibutton>Editing</guibutton> pane
  26. of the <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global
  27. Options</guimenuitem> dialog box. Note that the glob patterns must
  28. match the file name or first line exactly; so to match files whose
  29. first line contains <literal>begin</literal>, you must use a first
  30. line glob of <literal>*begin*</literal>. See <xref
  31. linkend="globs" /> for a description of glob pattern syntax.</para>
  32. <para>The default edit mode for files which do not match any pattern
  33. can be set in the <guibutton>Editing</guibutton> pane as
  34. well.</para>
  35. <para>The edit mode can be specified manually as well. The current
  36. buffer's edit mode can be set on a one-time basis in the
  37. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Buffer
  38. Options</guimenuitem> dialog box; see <xref
  39. linkend="buffer-opts" />. To set a buffer's edit mode for future
  40. editing sessions, place the following in one of the first or last 10
  41. lines of the buffer, where <replaceable>edit mode</replaceable> is
  42. the name of the desired edit mode:</para>
  43. <screen>:mode=<replaceable>edit mode</replaceable>:</screen>
  44. </section>
  45. <section id="syntax-hilite">
  46. <title>Syntax Highlighting</title>
  47. <para>Syntax highlighting is the display of programming language
  48. tokens using different fonts and colors. This makes code easier to
  49. follow and errors such as misplaced quotes easier to spot. All edit
  50. modes except for the plain text mode perform some kind of syntax
  51. highlighting.</para>
  52. <para>The colors and styles used to highlight syntax tokens can be
  53. changed in the <guibutton>Syntax Highlighting</guibutton> pane of
  54. the <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global
  55. Options</guimenuitem> dialog box; see <xref
  56. linkend="syntax-hilite-pane" />.</para>
  57. </section>
  58. </section>
  59. <section id="indent">
  60. <title>Tabbing and Indentation</title>
  61. <para>jEdit makes a distinction between the <firstterm>tab
  62. width</firstterm>, which is is used when displaying hard tab characters,
  63. and the <firstterm>indent width</firstterm>, which is used when a level
  64. of indent is to be added or removed, for example by mode-specific auto
  65. indent routines. Both can be changed in one of several ways:</para>
  66. <itemizedlist>
  67. <listitem>
  68. <para>On a global or mode-specific basis in the
  69. <guibutton>Editing</guibutton> pane of the the
  70. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global
  71. Options</guimenuitem> dialog box. See <xref
  72. linkend="editing-pane" />.</para>
  73. </listitem>
  74. <listitem>
  75. <para>In the current buffer for the duration of the editing
  76. session in the
  77. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Buffer
  78. Options</guimenuitem> dialog box. See <xref
  79. linkend="buffer-opts" />.</para>
  80. </listitem>
  81. <listitem>
  82. <para>In the current buffer for future editing sessions by
  83. placing the following in one of the first or last 10 lines of
  84. the buffer, where <replaceable>n</replaceable> is the desired
  85. tab width, and <replaceable>m</replaceable> is the desired
  86. indent width:</para>
  87. <screen>:tabSize=<replaceable>n</replaceable>:indentSize=<replaceable>m</replaceable>:</screen>
  88. </listitem>
  89. </itemizedlist>
  90. <para><guimenu>Edit</guimenu>&gt;<guisubmenu>Indent</guisubmenu>&gt;<guisubmenu>Shift
  91. Indent Left</guisubmenu> (shortcut: <keycap>S+TAB</keycap> or
  92. <keycap>A+LEFT</keycap>) removes one level of indent from each selected
  93. line, or the current line if there is no selection.</para>
  94. <para><guimenu>Edit</guimenu>&gt;<guisubmenu>Indent</guisubmenu>&gt;<guisubmenu>Shift
  95. Indent Right</guisubmenu> (shortcut: <keycap>A+RIGHT</keycap>) adds one
  96. level of indent to each selected line, or the current line if there is
  97. no selection. Pressing <keycap>Tab</keycap> while a multi-line selection
  98. is active has the same effect.</para>
  99. <para><guimenu>Edit</guimenu>&gt;<guisubmenu>Indent</guisubmenu>&gt;<guimenuitem>Remove
  100. Trailing Whitespace</guimenuitem> (shortcut: <keycap>C+e r</keycap>)
  101. removes all whitespace from the end of each selected line, or the
  102. current line if there is no selection.</para>
  103. <section id="soft-tabs">
  104. <title>Soft Tabs</title>
  105. <para>Files containing hard tab characters may look less than ideal
  106. if the default tab size is changed, so some people prefer using
  107. multiple space characters instead of hard tabs to indent
  108. code.</para>
  109. <para>This feature is known as <firstterm>soft tabs</firstterm>.
  110. Soft tabs can be enabled or disabled in one of several ways:</para>
  111. <itemizedlist>
  112. <listitem>
  113. <para>On a global or mode-specific basis in the
  114. <guibutton>Editing</guibutton> pane of the
  115. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global
  116. Options</guimenuitem> dialog box. See <xref
  117. linkend="editing-pane" />.</para>
  118. </listitem>
  119. <listitem>
  120. <para>In the current buffer for the duration of the editing
  121. session in the
  122. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Buffer
  123. Options</guimenuitem> dialog box. See <xref
  124. linkend="buffer-opts" />.</para>
  125. </listitem>
  126. <listitem>
  127. <para>In the current buffer for future editing sessions by
  128. placing the following in one of the first or last 10 lines
  129. of the buffer, where <replaceable>flag</replaceable> is
  130. either <quote>true</quote> or <quote>false</quote>:</para>
  131. <screen>:noTabs=<replaceable>flag</replaceable>:</screen>
  132. </listitem>
  133. </itemizedlist>
  134. <para>Changing the soft tabs setting has no effect on existing tab
  135. characters; it only affects subsequently-inserted tabs.</para>
  136. <para><guimenu>Edit</guimenu>&gt;<guisubmenu>Indent</guisubmenu>&gt;<guimenuitem>Spaces
  137. to Tabs</guimenuitem> converts soft tabs to hard tabs in the current
  138. selection, or the entire buffer if nothing is selected.</para>
  139. <para><guimenu>Edit</guimenu>&gt;<guisubmenu>Indent</guisubmenu>&gt;<guimenuitem>Tabs
  140. to Spaces</guimenuitem> converts hard tabs to soft tabs in the
  141. current selection, or the entire buffer if nothing is
  142. selected.</para>
  143. </section>
  144. <section id="elastic-tabstops">
  145. <title>Elastic Tabstops</title>
  146. <para>Elastic tabstops are an alternative way to handle tabstops.
  147. Elastic tabstops differ from traditional fixed tabstops because
  148. columns in lines above and below the "cell" that is being
  149. changed are always kept aligned. As the width of text before a tab
  150. character changes, the tabstops on adjacent lines are also
  151. changed to fit the widest piece of text in that column. It provides
  152. certain explicit benefits like it saves time
  153. spent on arranging the code and works seemlessly with variable width
  154. fonts.But at the same time it can make the code look unorganized
  155. on editors that do not support elastic tabstops.</para>
  156. <para>This feature is known as <firstterm>elastic tabstops</firstterm>.
  157. Elastic tabstops can be enabled or disabled in one of several ways:</para>
  158. <itemizedlist>
  159. <listitem>
  160. <para>On a global or mode-specific basis in the
  161. <guibutton>Editing</guibutton> pane of the
  162. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global
  163. Options</guimenuitem> dialog box. See <xref
  164. linkend="editing-pane" />.</para>
  165. </listitem>
  166. <listitem>
  167. <para>In the current buffer for the duration of the editing
  168. session in the
  169. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Buffer
  170. Options</guimenuitem> dialog box. See <xref
  171. linkend="buffer-opts" />.</para>
  172. </listitem>
  173. <listitem>
  174. <para>In the current buffer for future editing sessions by
  175. placing the following in one of the first or last 10 lines
  176. of the buffer, where <replaceable>flag</replaceable> is
  177. either <quote>true</quote> or <quote>false</quote>:</para>
  178. <screen>:elasticTabstops=<replaceable>flag</replaceable>:</screen>
  179. </listitem>
  180. </itemizedlist>
  181. <para>Note that this feature does not work with <firstterm>soft tabs</firstterm>.
  182. where tabs are emulated as spaces</para>
  183. </section>
  184. <section id="autoindent">
  185. <title>Automatic Indent</title>
  186. <para>The auto indent feature inserts the appropriate number of tabs
  187. or spaces at the beginning of a line by looking at program
  188. structure.</para>
  189. <para>In the default configuration, pressing <keycap>ENTER</keycap>
  190. will create a new line with the appropriate amount of indent
  191. automatically, and pressing <keycap>TAB</keycap> at the beginning
  192. of, or inside the leading whitespace of a line will insert the
  193. appropriate amount of indentation. Pressing it again will insert a
  194. tab character.</para>
  195. <para>The behavior of the <keycap>ENTER</keycap> and
  196. <keycap>TAB</keycap> keys can be configured in the
  197. <guibutton>Shortcuts</guibutton> pane of the
  198. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global
  199. Options</guimenuitem> dialog. box, just as with any other key. The
  200. <keycap>ENTER</keycap> key can be bound to one of the following, or
  201. indeed any other command or macro:</para>
  202. <itemizedlist>
  203. <listitem>
  204. <para><guimenuitem>Insert Newline</guimenuitem>.</para>
  205. </listitem>
  206. <listitem>
  207. <para><guimenuitem>Insert Newline and Indent</guimenuitem>,
  208. which is the default.</para>
  209. </listitem>
  210. </itemizedlist>
  211. <para>The <keycap>TAB</keycap> can be bound to one of the following,
  212. or again, any other command or macro:</para>
  213. <itemizedlist>
  214. <listitem>
  215. <para><guimenuitem>Insert Tab</guimenuitem>.</para>
  216. </listitem>
  217. <listitem>
  218. <para><guimenuitem>Insert Tab or Indent</guimenuitem>, which
  219. is the default.</para>
  220. </listitem>
  221. <listitem>
  222. <para><guimenuitem>Indent Selected
  223. Lines</guimenuitem>.</para>
  224. </listitem>
  225. </itemizedlist>
  226. <para>See <xref linkend="shortcuts-pane" /> for details.</para>
  227. <para>Auto indent behavior is mode-specific. In most edit modes, the
  228. indent of the previous line is simply copied over. However, in
  229. C-like languages (C, C++, Java, JavaScript), curly brackets and
  230. language statements are taken into account and indent is added and
  231. removed as necessary.</para>
  232. <para><guimenu>Edit</guimenu>&gt;<guisubmenu>Indent</guisubmenu>&gt;<guisubmenu>Indent
  233. Selected Lines</guisubmenu> (shortcut: <keycap>C+i</keycap>) indents
  234. all selected lines, or the current line if there is no
  235. selection.</para>
  236. <para>To insert a literal tab or newline without performing
  237. indentation, prefix the tab or newline with <keycap>C+e v</keycap>.
  238. For example, to create a new line without any indentation, type
  239. <keycap>C+e v ENTER</keycap>.</para>
  240. </section>
  241. </section>
  242. <section id="commenting">
  243. <title>Commenting Out Code</title>
  244. <para>Most programming and markup languages support the notion of
  245. <quote>comments</quote>, or regions of code which are ignored by the
  246. compiler/interpreter. jEdit has commands which make inserting comments
  247. more convenient.</para>
  248. <para>Comment strings are mode-specific, and some in some modes such as
  249. HTML different parts of a buffer can have different comment strings. For
  250. example, in HTML files, different comment strings are used for HTML text
  251. and inline JavaScript.</para>
  252. <para><guimenu>Edit</guimenu>&gt;<guisubmenu>Source
  253. Code</guisubmenu>&gt;<guimenuitem>Range Comment</guimenuitem> (shortcut:
  254. <keycap>C+e C+c</keycap>) encloses the selection with comment start and
  255. end strings, for example <literal>/*</literal> and <literal>*/</literal>
  256. in Java mode.</para>
  257. <para><guimenu>Edit</guimenu>&gt;<guisubmenu>Source
  258. Code</guisubmenu>&gt;<guimenuitem>Line Comment</guimenuitem> (shortcut:
  259. <keycap>C+e C+k</keycap>) inserts the line comment string, for example
  260. <literal>//</literal> in Java mode, at the start of each selected
  261. line.</para>
  262. </section>
  263. <section id="bracket-matching">
  264. <title>Bracket Matching</title>
  265. <para>Misplaced and unmatched brackets are one of the most common syntax
  266. errors encountered when writing code. jEdit has several features to make
  267. brackets easier to deal with.</para>
  268. <para>Positioning the caret immediately after a bracket will highlight
  269. the corresponding closing or opening bracket (assuming it is visible),
  270. and draw a scope indicator in the gutter. If the highlighted bracket is
  271. not visible, the text of the matching line will be shown in the status
  272. bar. If the matching line consists of only whitespace and the bracket
  273. itself, the <emphasis>previous line</emphasis> is shown instead. This
  274. feature is very useful when your code is indented as follows, with
  275. braces on their own lines:</para>
  276. <programlisting>public void someMethod()
  277. {
  278. if(isOK)
  279. {
  280. doSomething();
  281. }
  282. }</programlisting>
  283. <para>Invoking
  284. <guimenu>Edit</guimenu>&gt;<guisubmenu>Source</guisubmenu>&gt;<guimenuitem>Go
  285. to Matching Bracket</guimenuitem> (shortcut: <keycap>C+]</keycap>) or
  286. clicking the scope indicator in the gutter moves the caret to the
  287. matching bracket.</para>
  288. <para><guimenu>Edit</guimenu>&gt;<guisubmenu>Source</guisubmenu>&gt;<guimenuitem>Select
  289. Code Block</guimenuitem> (shortcut: <keycap>C+[</keycap>) selects all
  290. text between the closest two brackets surrounding the caret.</para>
  291. <para>Holding down <keycap>Control</keycap> while clicking the scope
  292. indicator in the gutter or a bracket in the text area will select all
  293. text between the two matching brackets.</para>
  294. <para><guimenu>Edit</guimenu>&gt;<guisubmenu>Source</guisubmenu>&gt;<guimenuitem>Go
  295. to Previous Bracket</guimenuitem> (shortcut: <keycap>C+e C+[</keycap>)
  296. moves the caret to the previous opening bracket.</para>
  297. <para><guimenu>Edit</guimenu>&gt;<guisubmenu>Source</guisubmenu>&gt;<guimenuitem>Go
  298. to Next Bracket</guimenuitem> (shortcut: <keycap>C+e C+]</keycap>) moves
  299. the caret to the next closing bracket.</para>
  300. <para>Bracket highlighting in the text area and bracket scope display in
  301. the gutter can be customized in the <guibutton>Text Area</guibutton> and
  302. <guibutton>Gutter</guibutton> panes of the
  303. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global
  304. Options</guimenuitem> dialog box; see <xref
  305. linkend="global-opts" />.</para>
  306. <tip>
  307. <para>jEdit's bracket matching algorithm only checks syntax tokens
  308. with the same type as the original bracket, so for example unmatched
  309. brackets inside string literals and comments will be skipped when
  310. matching brackets that are part of program syntax.</para>
  311. </tip>
  312. </section>
  313. <section id="abbrevs">
  314. <title>Abbreviations</title>
  315. <para>Abbreviations are invoked by typing a couple of letters and then
  316. issuing the <guimenu>Edit</guimenu>&gt;<guimenuitem>Expand
  317. Abbreviation</guimenuitem> (keyboard shortcut: <keycap>C+;</keycap>),
  318. which takes the word before the caret as the abbreviation name. If that
  319. particular abbreviation was not yet set, a dialog will pop up, and you
  320. can enter the text to insert before and after the caret. After the
  321. abbreviation is created, it can be viewed or edited from the
  322. <guibutton>Abbreviations</guibutton> pane of the
  323. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global
  324. Options</guimenuitem> dialog box; see <xref
  325. linkend="abbrevs-pane" />.</para>
  326. <para>Using abbreviations reduces the time spent typing long but
  327. commonly used strings. For example, in Java mode, the abbreviation
  328. <quote>sout</quote> is defined to expand to
  329. <quote>System.out.println()</quote>, so to insert
  330. <quote>System.out.println()</quote> in a Java buffer, you only need to
  331. type <quote>sout</quote> followed by <keycap>C+;</keycap>. An
  332. abbreviation can either be global, in which case it can be used in all
  333. edit modes, or specific to a single mode.</para>
  334. <para>The Java, VHDL. XML and XSL edit modes include some pre-defined
  335. abbreviations you might find useful. Other modes do not have any
  336. abbreviations defined by default.</para>
  337. <para></para>
  338. <para>Automatic abbreviation expansion can be enabled in the
  339. <guibutton>Abbreviations</guibutton> pane of the
  340. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global
  341. Options</guimenuitem> dialog box. If enabled, pressing the space bar
  342. after entering an abbreviation will automatically expand it.</para>
  343. <para>If automatic expansion is enabled, a space can be inserted without
  344. expanding the word before the caret by pressing <keycombo>
  345. <keycap>Control</keycap>
  346. <keycap>E</keycap>
  347. </keycombo> <keycap>V</keycap> <keycap>Space</keycap>.</para>
  348. <section id="positional-params">
  349. <title>Positional Parameters</title>
  350. <para>Positional parameters are an advanced feature that make
  351. abbreviations much more useful. The best way to describe them is
  352. with an example.</para>
  353. <para>Java mode defines an abbreviation <quote>F</quote> that is set
  354. to expand to the following:</para>
  355. <programlisting>for(int $1 = 0; $1 &lt; $2; $1++)</programlisting>
  356. <para>Expanding <literal>F#j#array.length#</literal> will insert the
  357. following text into the buffer:</para>
  358. <programlisting>for(int j = 0; j &lt; array.length; j++)</programlisting>
  359. <para>Expansions can contain up to nine positional parameters. Note
  360. that a trailing hash character (<quote>#</quote>) must be entered
  361. when expanding an abbreviation with parameters.</para>
  362. <para>If you do not specify the correct number of positional
  363. parameters when expanding an abbreviation, any missing parameters
  364. will be blank in the expansion, and extra parameters will be
  365. ignored. A status bar message will be shown stating the required
  366. number of parameters.</para>
  367. </section>
  368. </section>
  369. <section id="folding">
  370. <title>Folding</title>
  371. <para>Program source code and other structured text files can be thought
  372. of as containing a hierarchy of sections, which themselves might contain
  373. sub-sections. The folding feature lets you selectively hide and show
  374. these sections, replacing hidden ones with a single line that serves as
  375. an <quote>overview</quote> of that section. Folding is disabled by
  376. default. To enable it, you must choose one of the available folding
  377. modes.</para>
  378. <para><quote>Indent</quote> mode creates folds based on a line's leading
  379. whitespace; the more leading whitespace a block of text has, the further
  380. down it is in the hierarchy. For example:</para>
  381. <screen>This is a section
  382. This is a sub-section
  383. This is another sub-section
  384. This is a sub-sub-section
  385. Another top-level section</screen>
  386. <para><quote>Explicit</quote> mode folds away blocks of text surrounded
  387. with <quote>{{{</quote> and <quote>}}}</quote>. For example:</para>
  388. <screen>{{{ The first line of a fold.
  389. When this fold is collapsed, only the above line will be visible.
  390. {{{ A sub-section.
  391. With text inside it.
  392. }}}
  393. {{{ Another sub-section.
  394. }}}
  395. }}}</screen>
  396. <para>Both modes have distinct advantages and disadvantages; indent
  397. folding requires no changes to be made to a buffer's text and does a
  398. decent job with most program source. Explicit folding requires
  399. <quote>fold markers</quote> to be inserted into the text, but is more
  400. flexible in exactly what to fold away.</para>
  401. <para>Some plugins might add additional folding modes; see <xref
  402. linkend="using-plugins" /> for information about plugins.</para>
  403. <para>Folding can be enabled in one of several ways:</para>
  404. <itemizedlist>
  405. <listitem>
  406. <para>On a global or mode-specific basis in the
  407. <guibutton>Editing</guibutton> pane of the
  408. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global
  409. Options</guimenuitem> dialog box. See <xref
  410. linkend="editing-pane" />.</para>
  411. </listitem>
  412. <listitem>
  413. <para>In the current buffer for the duration of the editing
  414. session in the
  415. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Buffer
  416. Options</guimenuitem> dialog box. See <xref
  417. linkend="buffer-opts" />.</para>
  418. </listitem>
  419. <listitem>
  420. <para>In the current buffer for future editing sessions by
  421. placing the following in the first or last 10 lines of a buffer,
  422. where <replaceable>mode</replaceable> is either
  423. <quote>indent</quote>, <quote>explicit</quote>, or the name of a
  424. plugin folding mode:</para>
  425. <screen>:folding=<replaceable>mode</replaceable>:</screen>
  426. </listitem>
  427. </itemizedlist>
  428. <warning>
  429. <para>When using indent folding, portions of the buffer may become
  430. inaccessible if you change the leading indent of the first line of a
  431. collapsed fold. If you experience this, you can use the
  432. <guimenuitem>Expand All Folds</guimenuitem> command to make the text
  433. visible again.</para>
  434. </warning>
  435. <section>
  436. <title>Collapsing and Expanding Folds</title>
  437. <para>The first line of each fold has a triangle drawn next to it in
  438. the gutter (see <xref linkend="overview" /> for more information
  439. about the gutter). The triangle points toward the line when the fold
  440. is collapsed, and downward when the fold is expanded. Clicking the
  441. triangle collapses and expands the fold. To expand all sub-folds as
  442. well, hold down the <keycap>Shift</keycap> while clicking.</para>
  443. <para>The first line of a collapsed fold is drawn with a background
  444. color that depends on the fold level, and the number of lines in the
  445. fold is shown to the right of the line's text.</para>
  446. <para>Folds can also be collapsed and expanded using menu item
  447. commands and keyboard shortcuts.</para>
  448. <para><guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Collapse
  449. Fold</guimenuitem> (shortcut: <keycap>A+BACK_SPACE</keycap>)
  450. collapses the fold containing the caret.</para>
  451. <para><guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Expand Fold
  452. One Level</guimenuitem> (shortcut: <keycap>A+ENTER</keycap>) expands
  453. the fold containing the caret. Nested folds will remain collapsed,
  454. and the caret will be positioned on the first nested fold (if
  455. any).</para>
  456. <para><guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Expand Fold
  457. Fully</guimenuitem> (shortcut: <keycap>AS+ENTER</keycap>) expands
  458. the fold containing the caret, also expanding any nested
  459. folds.</para>
  460. <para><guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Collapse All
  461. Folds</guimenuitem> (shortcut: <keycap>C+e c</keycap>) collapses all
  462. folds in the buffer.</para>
  463. <para><guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Expand All
  464. Folds</guimenuitem> (shortcut: <keycap>C+e x</keycap>) expands all
  465. folds in the buffer.</para>
  466. </section>
  467. <section>
  468. <title>Navigating Around With Folds</title>
  469. <para><guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Go to Parent
  470. Fold</guimenuitem> (shortcut: <keycap>C+e u</keycap>) moves the
  471. caret to the fold containing the one at the caret position.</para>
  472. <para><guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Go to
  473. Previous Fold</guimenuitem> (shortcut: <keycap>A+UP</keycap>) moves
  474. the caret to the fold immediately before the caret position.</para>
  475. <para><guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Go to Next
  476. Fold</guimenuitem> (shortcut: <keycap>A+DOWN</keycap>) moves the
  477. caret to the fold immediately after the caret position.</para>
  478. </section>
  479. <section>
  480. <title>Miscellaneous Folding Commands</title>
  481. <para><guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Add Explicit
  482. Fold</guimenuitem> (shortcut: <keycap>C+e a</keycap>) surrounds the
  483. selection with <quote>{{{</quote> and <quote>}}}</quote>. If the
  484. current buffer's edit mode defines comment strings (see <xref
  485. linkend="commenting" />) the explicit fold markers will
  486. automatically be commented out as well.</para>
  487. <para><guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Select
  488. Fold</guimenuitem> (shortcut: <keycap>C+e s</keycap>) selects all
  489. lines within the fold containing the caret.
  490. <keycap>Control</keycap>-clicking a fold expansion triangle in the
  491. gutter has the same effect.</para>
  492. <para><guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Expand Folds
  493. With Level</guimenuitem> (shortcut: <keycap>C+e ENTER
  494. <replaceable>key</replaceable></keycap>) reads the next character
  495. entered at the keyboard, and expands folds in the buffer with a fold
  496. level less than that specified, while collapsing all others.</para>
  497. <para>Sometimes it is desirable to have files open with folds
  498. initially collapsed. This can be configured as follows:</para>
  499. <itemizedlist>
  500. <listitem>
  501. <para>On a global or mode-specific basis in the
  502. <guibutton>Editing</guibutton> pane of the
  503. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global
  504. Options</guimenuitem> dialog box. See <xref
  505. linkend="editing-pane" />.</para>
  506. </listitem>
  507. <listitem>
  508. <para>In the current buffer for future editing sessions by
  509. placing the following in the first or last 10 lines of a
  510. buffer, where <replaceable>level</replaceable> is the
  511. desired fold level:</para>
  512. <screen>:collapseFolds=<replaceable>level</replaceable>:</screen>
  513. </listitem>
  514. </itemizedlist>
  515. </section>
  516. <section id="narrowing">
  517. <title>Narrowing</title>
  518. <para>The narrowing feature temporarily <quote>narrows</quote> the
  519. display of a buffer to a specified region. Text outside the region
  520. is not shown, but is still present in the buffer. <!-- Both folding and
  521. narrowing are implemented using the same code internally. --></para>
  522. <para>Holding down <keycap>Alt</keycap> while clicking a fold
  523. expansion triangle in the gutter will hide all lines the buffer
  524. except those contained in the clicked fold.</para>
  525. <para><guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Narrow Buffer
  526. to Fold</guimenuitem> (shortcut: <keycap>C+e n n</keycap>) hides all
  527. lines the buffer except those in the fold containing the caret. <!-- When this command is invoked, a message is shown in the
  528. status bar reminding you that you need to invoke
  529. <guimenuitem>Expand All Folds</guimenuitem> to make the rest of the buffer
  530. visible again. --></para>
  531. <para><guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Narrow Buffer
  532. to Selection</guimenuitem> (shortcut: <keycap>C+e n s</keycap>)
  533. hides all lines the buffer except those in the selection.</para>
  534. <para><guisubmenu>Folding</guisubmenu>&gt;<guimenuitem>Expand All
  535. Folds</guimenuitem> (shortcut: <keycap>C+e x</keycap>) shows lines
  536. that were hidden as a result of narrowing.</para>
  537. </section>
  538. </section>
  539. </chapter>