Conditional-Init-Constructs.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Free Software" and "Free Software Needs
  8. Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
  9. and with the Back-Cover Texts as in (a) below.
  10. (a) The FSF's Back-Cover Text is: "You are free to copy and modify
  11. this GNU Manual. Buying copies from GNU Press supports the FSF in
  12. developing GNU and promoting software freedom." -->
  13. <!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>Debugging with GDB: Conditional Init Constructs</title>
  16. <meta name="description" content="Debugging with GDB: Conditional Init Constructs">
  17. <meta name="keywords" content="Debugging with GDB: Conditional Init Constructs">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  22. <link href="index.html#Top" rel="start" title="Top">
  23. <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
  24. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  25. <link href="Readline-Init-File.html#Readline-Init-File" rel="up" title="Readline Init File">
  26. <link href="Sample-Init-File.html#Sample-Init-File" rel="next" title="Sample Init File">
  27. <link href="Readline-Init-File-Syntax.html#Readline-Init-File-Syntax" rel="previous" title="Readline Init File Syntax">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.smallquotation {font-size: smaller}
  32. div.display {margin-left: 3.2em}
  33. div.example {margin-left: 3.2em}
  34. div.indentedblock {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  39. div.smalllisp {margin-left: 3.2em}
  40. kbd {font-style:oblique}
  41. pre.display {font-family: inherit}
  42. pre.format {font-family: inherit}
  43. pre.menu-comment {font-family: serif}
  44. pre.menu-preformatted {font-family: serif}
  45. pre.smalldisplay {font-family: inherit; font-size: smaller}
  46. pre.smallexample {font-size: smaller}
  47. pre.smallformat {font-family: inherit; font-size: smaller}
  48. pre.smalllisp {font-size: smaller}
  49. span.nocodebreak {white-space:nowrap}
  50. span.nolinebreak {white-space:nowrap}
  51. span.roman {font-family:serif; font-weight:normal}
  52. span.sansserif {font-family:sans-serif; font-weight:normal}
  53. ul.no-bullet {list-style: none}
  54. -->
  55. </style>
  56. </head>
  57. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  58. <a name="Conditional-Init-Constructs"></a>
  59. <div class="header">
  60. <p>
  61. Next: <a href="Sample-Init-File.html#Sample-Init-File" accesskey="n" rel="next">Sample Init File</a>, Previous: <a href="Readline-Init-File-Syntax.html#Readline-Init-File-Syntax" accesskey="p" rel="previous">Readline Init File Syntax</a>, Up: <a href="Readline-Init-File.html#Readline-Init-File" accesskey="u" rel="up">Readline Init File</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
  62. </div>
  63. <hr>
  64. <a name="Conditional-Init-Constructs-1"></a>
  65. <h4 class="subsection">32.3.2 Conditional Init Constructs</h4>
  66. <p>Readline implements a facility similar in spirit to the conditional
  67. compilation features of the C preprocessor which allows key
  68. bindings and variable settings to be performed as the result
  69. of tests. There are four parser directives used.
  70. </p>
  71. <dl compact="compact">
  72. <dt><code>$if</code></dt>
  73. <dd><p>The <code>$if</code> construct allows bindings to be made based on the
  74. editing mode, the terminal being used, or the application using
  75. Readline. The text of the test, after any comparison operator,
  76. extends to the end of the line;
  77. unless otherwise noted, no characters are required to isolate it.
  78. </p>
  79. <dl compact="compact">
  80. <dt><code>mode</code></dt>
  81. <dd><p>The <code>mode=</code> form of the <code>$if</code> directive is used to test
  82. whether Readline is in <code>emacs</code> or <code>vi</code> mode.
  83. This may be used in conjunction
  84. with the &lsquo;<samp>set keymap</samp>&rsquo; command, for instance, to set bindings in
  85. the <code>emacs-standard</code> and <code>emacs-ctlx</code> keymaps only if
  86. Readline is starting out in <code>emacs</code> mode.
  87. </p>
  88. </dd>
  89. <dt><code>term</code></dt>
  90. <dd><p>The <code>term=</code> form may be used to include terminal-specific
  91. key bindings, perhaps to bind the key sequences output by the
  92. terminal&rsquo;s function keys. The word on the right side of the
  93. &lsquo;<samp>=</samp>&rsquo; is tested against both the full name of the terminal and
  94. the portion of the terminal name before the first &lsquo;<samp>-</samp>&rsquo;. This
  95. allows <code>sun</code> to match both <code>sun</code> and <code>sun-cmd</code>,
  96. for instance.
  97. </p>
  98. </dd>
  99. <dt><code>version</code></dt>
  100. <dd><p>The <code>version</code> test may be used to perform comparisons against
  101. specific Readline versions.
  102. The <code>version</code> expands to the current Readline version.
  103. The set of comparison operators includes
  104. &lsquo;<samp>=</samp>&rsquo; (and &lsquo;<samp>==</samp>&rsquo;), &lsquo;<samp>!=</samp>&rsquo;, &lsquo;<samp>&lt;=</samp>&rsquo;, &lsquo;<samp>&gt;=</samp>&rsquo;, &lsquo;<samp>&lt;</samp>&rsquo;,
  105. and &lsquo;<samp>&gt;</samp>&rsquo;.
  106. The version number supplied on the right side of the operator consists
  107. of a major version number, an optional decimal point, and an optional
  108. minor version (e.g., &lsquo;<samp>7.1</samp>&rsquo;). If the minor version is omitted, it
  109. is assumed to be &lsquo;<samp>0</samp>&rsquo;.
  110. The operator may be separated from the string <code>version</code> and
  111. from the version number argument by whitespace.
  112. The following example sets a variable if the Readline version being used
  113. is 7.0 or newer:
  114. </p><div class="example">
  115. <pre class="example">$if version &gt;= 7.0
  116. set show-mode-in-prompt on
  117. $endif
  118. </pre></div>
  119. </dd>
  120. <dt><code>application</code></dt>
  121. <dd><p>The <var>application</var> construct is used to include
  122. application-specific settings. Each program using the Readline
  123. library sets the <var>application name</var>, and you can test for
  124. a particular value.
  125. This could be used to bind key sequences to functions useful for
  126. a specific program. For instance, the following command adds a
  127. key sequence that quotes the current or previous word in Bash:
  128. </p><div class="example">
  129. <pre class="example">$if Bash
  130. # Quote the current or previous word
  131. &quot;\C-xq&quot;: &quot;\eb\&quot;\ef\&quot;&quot;
  132. $endif
  133. </pre></div>
  134. </dd>
  135. <dt><code>variable</code></dt>
  136. <dd><p>The <var>variable</var> construct provides simple equality tests for Readline
  137. variables and values.
  138. The permitted comparison operators are &lsquo;<samp>=</samp>&rsquo;, &lsquo;<samp>==</samp>&rsquo;, and &lsquo;<samp>!=</samp>&rsquo;.
  139. The variable name must be separated from the comparison operator by
  140. whitespace; the operator may be separated from the value on the right hand
  141. side by whitespace.
  142. Both string and boolean variables may be tested. Boolean variables must be
  143. tested against the values <var>on</var> and <var>off</var>.
  144. The following example is equivalent to the <code>mode=emacs</code> test described
  145. above:
  146. </p><div class="example">
  147. <pre class="example">$if editing-mode == emacs
  148. set show-mode-in-prompt on
  149. $endif
  150. </pre></div>
  151. </dd>
  152. </dl>
  153. </dd>
  154. <dt><code>$endif</code></dt>
  155. <dd><p>This command, as seen in the previous example, terminates an
  156. <code>$if</code> command.
  157. </p>
  158. </dd>
  159. <dt><code>$else</code></dt>
  160. <dd><p>Commands in this branch of the <code>$if</code> directive are executed if
  161. the test fails.
  162. </p>
  163. </dd>
  164. <dt><code>$include</code></dt>
  165. <dd><p>This directive takes a single filename as an argument and reads commands
  166. and bindings from that file.
  167. For example, the following directive reads from <samp>/etc/inputrc</samp>:
  168. </p><div class="example">
  169. <pre class="example">$include /etc/inputrc
  170. </pre></div>
  171. </dd>
  172. </dl>
  173. <hr>
  174. <div class="header">
  175. <p>
  176. Next: <a href="Sample-Init-File.html#Sample-Init-File" accesskey="n" rel="next">Sample Init File</a>, Previous: <a href="Readline-Init-File-Syntax.html#Readline-Init-File-Syntax" accesskey="p" rel="previous">Readline Init File Syntax</a>, Up: <a href="Readline-Init-File.html#Readline-Init-File" accesskey="u" rel="up">Readline Init File</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
  177. </div>
  178. </body>
  179. </html>