PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre5/doc/users-guide/source-edit.xml

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