PageRenderTime 115ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/demos/paredit20-paredit22.html

http://github.com/yinwang0/ydiff
HTML | 4349 lines | 4174 code | 175 blank | 0 comment | 0 complexity | d6a9659e22027ebee2791801859a1238 MD5 | raw file
Possible License(s): GPL-3.0
  1. <html>
  2. <head>
  3. <META http-equiv="Content-Type" content="text/html; charset=utf-8">
  4. <LINK href="diff-s.css" rel="stylesheet" type="text/css">
  5. <script type="text/javascript" src="nav-div.js"></script>
  6. </head>
  7. <body>
  8. <div id="left" class="src">
  9. <pre>
  10. <a id='leftstart' tid='rightstart'></a>
  11. <span class='d'>;;; -*- Mode: Emacs-Lisp; outline-regexp: &quot; \n;;;;+&quot; -*-
  12. </span>
  13. <span class='d'>;;;;;; Paredit: Parenthesis-Editing Minor Mode
  14. </span><span class='d'>;;;;;; Version 20
  15. </span>
  16. <span class='d'>;;; This code is written by Taylor R. Campbell (except where explicitly
  17. </span><span class='d'>;;; noted) and placed in the Public Domain. All warranties are
  18. </span><span class='d'>;;; disclaimed.
  19. </span>
  20. <span class='d'>;;; Add this to your .emacs after adding paredit.el to /path/to/elisp/:
  21. </span><span class='d'>;;;
  22. </span><span class='d'>;;; (add-to-list &#39;load-path &quot;/path/to/elisp/&quot;)
  23. </span><span class='d'>;;; (autoload &#39;paredit-mode &quot;paredit&quot;
  24. </span><span class='d'>;;; &quot;Minor mode for pseudo-structurally editing Lisp code.&quot;
  25. </span><span class='d'>;;; t)
  26. </span><span class='d'>;;; (add-hook &#39;...-mode-hook (lambda () (paredit-mode +1)))
  27. </span><span class='d'>;;;
  28. </span><span class='d'>;;; Usually the ... will be lisp or scheme or both. Alternatively, you
  29. </span><span class='d'>;;; can manually toggle this mode with M-x paredit-mode. Customization
  30. </span><span class='d'>;;; of paredit can be accomplished with `eval-after-load&#39;:
  31. </span><span class='d'>;;;
  32. </span><span class='d'>;;; (eval-after-load &#39;paredit
  33. </span><span class='d'>;;; &#39;(progn ...redefine keys, &c....))
  34. </span><a id='4627' tid='4628' class='u'>;;;
  35. </a><span class='d'>;;; This should run in GNU Emacs 21 or later and XEmacs 21.5 or later.
  36. </span><span class='d'>;;; It is highly unlikely to work in earlier versions of GNU Emacs, and
  37. </span><span class='d'>;;; it may have obscure problems in earlier versions of XEmacs due to
  38. </span><span class='d'>;;; the way its syntax parser reports conditions, as a result of which
  39. </span><span class='d'>;;; the code that uses the syntax parser must mask *all* error
  40. </span><span class='d'>;;; conditions, not just those generated by the syntax parser.
  41. </span>
  42. <span class='d'>;;; This mode changes the keybindings for a number of simple keys,
  43. </span><span class='d'>;;; notably (, ), &quot;, \, and ;. The bracket keys (round or square) are
  44. </span><span class='d'>;;; defined to insert parenthesis pairs and move past the close,
  45. </span><span class='d'>;;; respectively; the double-quote key is multiplexed to do both, and
  46. </span><span class='d'>;;; also insert an escape if within a string; backslashes prompt the
  47. </span><span class='d'>;;; user for the next character to input, because a lone backslash can
  48. </span><span class='d'>;;; break structure inadvertently; and semicolons ensure that they do
  49. </span><span class='d'>;;; not accidentally comment valid structure. (Use M-; to comment an
  50. </span><span class='d'>;;; expression.) These all have their ordinary behaviour when inside
  51. </span><span class='d'>;;; comments, and, outside comments, if truly necessary, you can insert
  52. </span><span class='d'>;;; them literally with C-q.
  53. </span><span class='d'>;;;
  54. </span><span class='d'>;;; These keybindings are set up for my preference. One particular
  55. </span><span class='d'>;;; preference which I&#39;ve seen vary greatly from person to person is
  56. </span><span class='d'>;;; whether the command to move past a closing delimiter ought to
  57. </span><span class='d'>;;; insert a newline. Since I find this behaviour to be more common
  58. </span><span class='d'>;;; than that which inserts no newline, I have ) bound to it, and the
  59. </span><span class='d'>;;; more involved M-) to perform the less common action. This bothers
  60. </span><span class='d'>;;; some users, though, and they prefer the other way around. This
  61. </span><span class='d'>;;; code, which you can use `eval-after-load&#39; to put in your .emacs,
  62. </span><span class='d'>;;; will exchange the bindings:
  63. </span><span class='d'>;;;
  64. </span><span class='d'>;;; (define-key paredit-mode-map (kbd &quot;)&quot;)
  65. </span><span class='d'>;;; &#39;paredit-close-parenthesis)
  66. </span><span class='d'>;;; (define-key paredit-mode-map (kbd &quot;M-)&quot;)
  67. </span><span class='d'>;;; &#39;paredit-close-parenthesis-and-newline)
  68. </span><a id='4629' tid='4630' class='u'>;;;
  69. </a><span class='d'>;;; Paredit also changes the bindings of keys for deleting and killing,
  70. </span><span class='d'>;;; so that they will not destroy any S-expression structure by killing
  71. </span><span class='d'>;;; or deleting only one side of a bracket or quote pair. If the point
  72. </span><span class='d'>;;; is on a closing bracket, DEL will move left over it; if it is on an
  73. </span><span class='d'>;;; opening bracket, C-d will move right over it. Only if the point is
  74. </span><span class='d'>;;; between a pair of brackets will C-d or DEL delete them, and in that
  75. </span><span class='d'>;;; case it will delete both simultaneously. M-d and M-DEL kill words,
  76. </span><span class='d'>;;; but skip over any S-expression structure. C-k kills from the start
  77. </span><span class='d'>;;; of the line, either to the line&#39;s end, if it contains only balanced
  78. </span><span class='d'>;;; expressions; to the first closing bracket, if the point is within a
  79. </span><span class='d'>;;; form that ends on the line; or up to the end of the last expression
  80. </span><span class='d'>;;; that starts on the line after the point.
  81. </span><a id='4631' tid='4632' class='u'>;;;
  82. </a><span class='d'>;;; Automatic reindentation is performed as locally as possible, to
  83. </span><span class='d'>;;; ensure that Emacs does not interfere with custom indentation used
  84. </span><span class='d'>;;; elsewhere in some S-expression. It is performed only by the
  85. </span><span class='d'>;;; advanced S-expression frobnication commands, and only on the forms
  86. </span><span class='d'>;;; that were immediately operated upon (& their subforms).
  87. </span><a id='4633' tid='4634' class='u'>;;;
  88. </a><span class='d'>;;; This code is written for clarity, not efficiency. S-expressions
  89. </span><span class='d'>;;; are frequently walked over redundantly. If you have problems with
  90. </span><span class='d'>;;; some of the commands taking too long to execute, tell me, but first
  91. </span><span class='d'>;;; make sure that what you&#39;re doing is reasonable: it is stylistically
  92. </span><span class='d'>;;; bad to have huge, long, hideously nested code anyway.
  93. </span><span class='d'>;;;
  94. </span><span class='d'>;;; Questions, bug reports, comments, feature suggestions, &c., can be
  95. </span><span class='d'>;;; addressed to the author via mail on the host mumble.net to campbell
  96. </span><span class='d'>;;; or via IRC on irc.freenode.net in the #paredit channel under the
  97. </span><span class='d'>;;; nickname Riastradh.
  98. </span>
  99. <span class='d'>;;; This assumes Unix-style LF line endings.
  100. </span>
  101. <span class='d'>(defconst paredit-version 20)</span>
  102. (<a id='667' tid='668' class='m'>eval-and-compile</a>
  103. (<a id='653' tid='654' class='m'>defun</a> <a id='655' tid='656' class='m'>paredit-xemacs-p</a> ()
  104. <span class='d'>;; No idea I got this definition from. Edward O&#39;Connor (hober on
  105. </span> <span class='d'>;; IRC) suggested the current definition.
  106. </span> <a id='657' tid='658' class='m'>;; (and (boundp &#39;running-xemacs)
  107. </a> <a id='659' tid='660' class='m'>;; running-xemacs)
  108. </a> (<a id='661' tid='662' class='m'>featurep</a> <a id='663' tid='664' class='m'>&#39;</a><a id='665' tid='666' class='m'>xemacs</a>))
  109. (<a id='613' tid='614' class='m'>defun</a> <a id='615' tid='616' class='m'>paredit-gnu-emacs-p</a> ()
  110. (<a id='617' tid='618' class='m'>not</a> (<a id='619' tid='620' class='m'>paredit-xemacs-p</a>)))
  111. (<a id='669' tid='670' class='m'>defmacro</a> <a id='671' tid='672' class='m'>xcond</a> (<a id='673' tid='674' class='m'>&rest</a> <a id='675' tid='676' class='m'>clauses</a>)
  112. <a id='677' tid='678' class='m'>&quot;Exhaustive COND.
  113. Signal an error if no clause matches.&quot;</a>
  114. <a id='679' tid='680' class='m'>`</a>(<a id='681' tid='682' class='m'>cond</a> <a id='683' tid='684' class='m'>,</a><a id='685' tid='686' class='m'>@clauses</a>
  115. (<a id='687' tid='688' class='m'>t</a> (<a id='689' tid='690' class='m'>error</a> <a id='691' tid='692' class='m'>&quot;XCOND lost.&quot;</a>))))
  116. (<a id='693' tid='694' class='m'>defalias</a> <a id='695' tid='696' class='m'>&#39;</a><a id='697' tid='698' class='m'>paredit-warn</a> (<a id='699' tid='700' class='m'>if</a> (<a id='701' tid='702' class='m'>fboundp</a> <a id='703' tid='704' class='m'>&#39;</a><a id='705' tid='706' class='m'>warn</a>) <a id='707' tid='708' class='m'>&#39;</a><a id='709' tid='710' class='m'>warn</a> <a id='711' tid='712' class='m'>&#39;</a><a id='713' tid='714' class='m'>message</a>))
  117. (<a id='621' tid='622' class='m'>defvar</a> <a id='623' tid='624' class='m'>paredit-sexp-error-type</a>
  118. (<a id='625' tid='626' class='m'>with-temp-buffer</a>
  119. (<a id='627' tid='628' class='m'>insert</a> <a id='629' tid='630' class='m'>&quot;(&quot;</a>)
  120. (<a id='631' tid='632' class='m'>condition-case</a> <a id='633' tid='634' class='m'>condition</a>
  121. (<a id='635' tid='636' class='m'>backward-sexp</a>)
  122. (<a id='637' tid='638' class='m'>error</a> (<span class='d'>if</span> (<a id='639' tid='640' class='m'>eq</a> (<a id='641' tid='642' class='m'>car</a> <a id='643' tid='644' class='m'>condition</a>) <a id='645' tid='646' class='m'>&#39;</a><a id='647' tid='648' class='m'>error</a>)
  123. <span class='d'>(paredit-warn &quot;%s%s%s%s&quot;
  124. &quot;Paredit is unable to discriminate&quot;
  125. &quot; S-expression parse errors from&quot;
  126. &quot; other errors. &quot;
  127. &quot; This may cause obscure problems. &quot;
  128. &quot; Please upgrade Emacs.&quot;)</span>)
  129. (<a id='649' tid='650' class='m'>car</a> <a id='651' tid='652' class='m'>condition</a>)))))
  130. (<a id='715' tid='716' class='m'>defmacro</a> <a id='717' tid='718' class='m'>paredit-handle-sexp-errors</a> (<a id='719' tid='720' class='m'>body</a> <a id='721' tid='722' class='m'>&rest</a> <a id='723' tid='724' class='m'>handler</a>)
  131. <a id='725' tid='726' class='m'>`</a>(<a id='727' tid='728' class='m'>condition-case</a> ()
  132. <a id='729' tid='730' class='m'>,</a><a id='731' tid='732' class='m'>body</a>
  133. (<a id='733' tid='734' class='m'>,</a><a id='735' tid='736' class='m'>paredit-sexp-error-type</a> <a id='737' tid='738' class='m'>,</a><a id='739' tid='740' class='m'>@handler</a>)))
  134. (<a id='741' tid='742' class='m'>put</a> <a id='743' tid='744' class='m'>&#39;</a><a id='745' tid='746' class='m'>paredit-handle-sexp-errors</a> <a id='747' tid='748' class='m'>&#39;</a><a id='749' tid='750' class='m'>lisp-indent-function</a> <a id='751' tid='752' class='m'>1</a>)
  135. (<a id='753' tid='754' class='m'>defmacro</a> <a id='755' tid='756' class='m'>paredit-ignore-sexp-errors</a> (<a id='757' tid='758' class='m'>&rest</a> <a id='759' tid='760' class='m'>body</a>)
  136. <a id='761' tid='762' class='m'>`</a>(<a id='763' tid='764' class='m'>paredit-handle-sexp-errors</a> (<a id='765' tid='766' class='m'>progn</a> <a id='767' tid='768' class='m'>,</a><a id='769' tid='770' class='m'>@body</a>)
  137. <a id='771' tid='772' class='m'>nil</a>))
  138. (<a id='773' tid='774' class='m'>put</a> <a id='775' tid='776' class='m'>&#39;</a><a id='777' tid='778' class='m'>paredit-ignore-sexp-errors</a> <a id='779' tid='780' class='m'>&#39;</a><a id='781' tid='782' class='m'>lisp-indent-function</a> <a id='783' tid='784' class='m'>0</a>)
  139. <a id='785' tid='786' class='m'>nil</a>)
  140. <span class='d'>;;;; Minor Mode Definition
  141. </span>
  142. (<a id='4189' tid='4190' class='u'>defvar</a> <a id='4191' tid='4192' class='u'>paredit-mode-map</a> (<a id='4193' tid='4194' class='u'>make-sparse-keymap</a>)
  143. <a id='4195' tid='4196' class='u'>&quot;Keymap for the paredit minor mode.&quot;</a>)
  144. (<a id='4119' tid='4120' class='u'>define-minor-mode</a> <a id='4121' tid='4122' class='u'>paredit-mode</a>
  145. <span class='d'>&quot;Minor mode for pseudo-structurally editing Lisp code.
  146. \\&lt;paredit-mode-map&gt;&quot;</span>
  147. <a id='4123' tid='4124' class='u'>:lighter</a> <a id='4125' tid='4126' class='u'>&quot; Paredit&quot;</a>
  148. <a id='4127' tid='4128' class='u'>;; If we&#39;re enabling paredit-mode, the prefix to this code that
  149. </a> <a id='4129' tid='4130' class='u'>;; DEFINE-MINOR-MODE inserts will have already set PAREDIT-MODE to
  150. </a> <a id='4131' tid='4132' class='u'>;; true. If this is the case, then first check the parentheses, and
  151. </a> <a id='4133' tid='4134' class='u'>;; if there are any imbalanced ones we must inhibit the activation of
  152. </a> <a id='4135' tid='4136' class='u'>;; paredit mode. We skip the check, though, if the user supplied a
  153. </a> <a id='4137' tid='4138' class='u'>;; prefix argument interactively.
  154. </a> (<a id='4139' tid='4140' class='u'>if</a> (<a id='4141' tid='4142' class='u'>and</a> <a id='4143' tid='4144' class='u'>paredit-mode</a>
  155. (<a id='4145' tid='4146' class='u'>not</a> <a id='4147' tid='4148' class='u'>current-prefix-arg</a>))
  156. (<a id='4149' tid='4150' class='u'>if</a> (<a id='4151' tid='4152' class='u'>not</a> (<a id='4153' tid='4154' class='u'>fboundp</a> <a id='4155' tid='4156' class='u'>&#39;</a><a id='4157' tid='4158' class='u'>check-parens</a>))
  157. (<a id='4159' tid='4160' class='u'>paredit-warn</a> <a id='4161' tid='4162' class='u'>&quot;`check-parens&#39; is not defined; %s&quot;</a>
  158. <a id='4163' tid='4164' class='u'>&quot;be careful of malformed S-expressions.&quot;</a>)
  159. (<a id='4165' tid='4166' class='u'>condition-case</a> <a id='4167' tid='4168' class='u'>condition</a>
  160. (<a id='4169' tid='4170' class='u'>check-parens</a>)
  161. (<a id='4171' tid='4172' class='u'>error</a> (<a id='4173' tid='4174' class='u'>setq</a> <a id='4175' tid='4176' class='u'>paredit-mode</a> <a id='4177' tid='4178' class='u'>nil</a>)
  162. (<a id='4179' tid='4180' class='u'>signal</a> (<a id='4181' tid='4182' class='u'>car</a> <a id='4183' tid='4184' class='u'>condition</a>) (<a id='4185' tid='4186' class='u'>cdr</a> <a id='4187' tid='4188' class='u'>condition</a>)))))))
  163. <span class='d'>;;; Old functions from when there was a different mode for emacs -nw.
  164. </span>
  165. (<a id='1527' tid='1528' class='u'>defun</a> <a id='1529' tid='1530' class='u'>enable-paredit-mode</a> ()
  166. <span class='d'>&quot;Turn on pseudo-structural editing of Lisp code.
  167. Deprecated: use `paredit-mode&#39; instead.&quot;</span>
  168. (<a id='1531' tid='1532' class='u'>interactive</a>)
  169. (<a id='1533' tid='1534' class='u'>paredit-mode</a> <a id='1535' tid='1536' class='u'>+1</a>))
  170. (<a id='1517' tid='1518' class='u'>defun</a> <a id='1519' tid='1520' class='u'>disable-paredit-mode</a> ()
  171. <span class='d'>&quot;Turn off pseudo-structural editing of Lisp code.
  172. Deprecated: use `paredit-mode&#39; instead.&quot;</span>
  173. (<a id='1521' tid='1522' class='u'>interactive</a>)
  174. (<a id='1523' tid='1524' class='u'>paredit-mode</a> <a id='1525' tid='1526' class='u'>-1</a>))
  175. (<a id='1957' tid='1958' class='u'>defvar</a> <a id='1959' tid='1960' class='u'>paredit-backward-delete-key</a>
  176. (<a id='1961' tid='1962' class='u'>xcond</a> ((<a id='1963' tid='1964' class='u'>paredit-xemacs-p</a>) <a id='1965' tid='1966' class='u'>&quot;BS&quot;</a>)
  177. ((<a id='1967' tid='1968' class='u'>paredit-gnu-emacs-p</a>) <a id='1969' tid='1970' class='u'>&quot;DEL&quot;</a>)))
  178. (<a id='2595' tid='2596' class='u'>defvar</a> <a id='2597' tid='2598' class='u'>paredit-forward-delete-keys</a>
  179. (<a id='2599' tid='2600' class='u'>xcond</a> ((<a id='2601' tid='2602' class='u'>paredit-xemacs-p</a>) <a id='2603' tid='2604' class='u'>&#39;</a>(<a id='2605' tid='2606' class='u'>&quot;DEL&quot;</a>))
  180. ((<a id='2607' tid='2608' class='u'>paredit-gnu-emacs-p</a>) <a id='2609' tid='2610' class='u'>&#39;</a>(<a id='2611' tid='2612' class='u'>&quot;&lt;delete&gt;&quot;</a> <a id='2613' tid='2614' class='u'>&quot;&lt;deletechar&gt;&quot;</a>))))
  181. <span class='d'>;;;; Paredit Keys
  182. </span>
  183. <span class='d'>;;; Separating the definition and initialization of this variable
  184. </span><span class='d'>;;; simplifies the development of paredit, since re-evaluating DEFVAR
  185. </span><span class='d'>;;; forms doesn&#39;t actually do anything.
  186. </span>
  187. (<a id='2199' tid='2200' class='u'>defvar</a> <a id='2201' tid='2202' class='u'>paredit-commands</a> <a id='2203' tid='2204' class='u'>nil</a>
  188. <a id='2205' tid='2206' class='u'>&quot;List of paredit commands with their keys and examples.&quot;</a>)
  189. <span class='d'>;;; Each specifier is of the form:
  190. </span><span class='d'>;;; (key[s] function (example-input example-output) ...)
  191. </span><span class='d'>;;; where key[s] is either a single string suitable for passing to KBD
  192. </span><span class='d'>;;; or a list of such strings. Entries in this list may also just be
  193. </span><span class='d'>;;; strings, in which case they are headings for the next entries.
  194. </span>
  195. (<a id='787' tid='788' class='m'>progn</a> (<a id='789' tid='790' class='m'>setq</a> <a id='791' tid='792' class='m'>paredit-commands</a>
  196. <a id='793' tid='794' class='m'>`</a>(
  197. <span class='d'>&quot;Basic Insertion Commands&quot;</span>
  198. <span class='d'>(&quot;(&quot; paredit-open-parenthesis
  199. (&quot;(a b |c d)&quot;
  200. &quot;(a b (|) c d)&quot;)
  201. (&quot;(foo \&quot;bar |baz\&quot; quux)&quot;
  202. &quot;(foo \&quot;bar (|baz\&quot; quux)&quot;))</span>
  203. <span class='d'>(&quot;)&quot; paredit-close-parenthesis-and-newline
  204. (&quot;(defun f (x| ))&quot;
  205. &quot;(defun f (x)\n |)&quot;)
  206. (&quot;; (Foo.|&quot;
  207. &quot;; (Foo.)|&quot;))</span>
  208. <span class='d'>(&quot;M-)&quot; paredit-close-parenthesis
  209. (&quot;(a b |c )&quot; &quot;(a b c)|&quot;)
  210. (&quot;; Hello,| world!&quot;
  211. &quot;; Hello,)| world!&quot;))</span>
  212. <span class='d'>(&quot;[&quot; paredit-open-bracket
  213. (&quot;(a b |c d)&quot;
  214. &quot;(a b [|] c d)&quot;)
  215. (&quot;(foo \&quot;bar |baz\&quot; quux)&quot;
  216. &quot;(foo \&quot;bar [baz\&quot; quux)&quot;))</span>
  217. <span class='d'>(&quot;]&quot; paredit-close-bracket
  218. (&quot;(define-key keymap [frob| ] &#39;frobnicate)&quot;
  219. &quot;(define-key keymap [frob]| &#39;frobnicate)&quot;)
  220. (&quot;; [Bar.|&quot;
  221. &quot;; [Bar.]|&quot;))</span>
  222. (<a id='795' tid='796' class='m'>&quot;\&quot;&quot;</a> <a id='797' tid='798' class='m'>paredit-doublequote</a>
  223. (<a id='799' tid='800' class='m'>&quot;(frob grovel |full lexical)&quot;</a>
  224. <a id='801' tid='802' class='m'>&quot;(frob grovel \&quot;|\&quot; full lexical)&quot;</a>)
  225. (<a id='803' tid='804' class='m'>&quot;(foo \&quot;bar |baz\&quot; quux)&quot;</a>
  226. <a id='805' tid='806' class='m'>&quot;(foo \&quot;bar \\\&quot;|baz\&quot; quux)&quot;</a>))
  227. (<a id='495' tid='496' class='m'>&quot;M-\&quot;&quot;</a> <a id='497' tid='498' class='m'>paredit-meta-doublequote</a>
  228. (<a id='499' tid='500' class='m'>&quot;(foo \&quot;bar |baz\&quot; quux)&quot;</a>
  229. <a id='501' tid='502' class='m'>&quot;(foo \&quot;bar baz\&quot;\n |quux)&quot;</a>)
  230. (<a id='503' tid='504' class='m'>&quot;(foo |(bar #\\x \&quot;baz \\\\ quux\&quot;) zot)&quot;</a>
  231. <a id='505' tid='506' class='m'>,</a>(<a id='507' tid='508' class='m'>concat</a> <a id='509' tid='510' class='m'>&quot;(foo \&quot;|(bar #\\\\x \\\&quot;baz \\\\&quot;</a>
  232. <a id='511' tid='512' class='m'>&quot;\\\\ quux\\\&quot;)\&quot; zot)&quot;</a>)))
  233. (<a id='393' tid='394' class='m'>&quot;\\&quot;</a> <a id='395' tid='396' class='m'>paredit-backslash</a>
  234. (<a id='397' tid='398' class='m'>&quot;(string #|)\n ; Escaping character... (x)&quot;</a>
  235. <a id='399' tid='400' class='m'>&quot;(string #\\x|)&quot;</a>)
  236. (<a id='401' tid='402' class='m'>&quot;\&quot;foo|bar\&quot;\n ; Escaping character... (\&quot;)&quot;</a>
  237. <a id='403' tid='404' class='m'>&quot;\&quot;foo\\\&quot;|bar\&quot;&quot;</a>))
  238. <span class='d'>(&quot;;&quot; paredit-semicolon
  239. (&quot;|(frob grovel)&quot;
  240. &quot;;|\n(frob grovel)&quot;)
  241. (&quot;(frob grovel) |&quot;
  242. &quot;(frob grovel) ;|&quot;))</span>
  243. (<a id='305' tid='306' class='m'>&quot;M-;&quot;</a> <a id='307' tid='308' class='m'>paredit-comment-dwim</a>
  244. (<a id='309' tid='310' class='m'>&quot;(foo |bar) ; baz&quot;</a>
  245. <a id='311' tid='312' class='m'>&quot;(foo bar) ; |baz&quot;</a>)
  246. (<a id='313' tid='314' class='m'>&quot;(frob grovel)|&quot;</a>
  247. <a id='315' tid='316' class='m'>&quot;(frob grovel) ;|&quot;</a>)
  248. (<a id='317' tid='318' class='m'>&quot; (foo bar)\n|\n (baz quux)&quot;</a>
  249. <a id='319' tid='320' class='m'>&quot; (foo bar)\n ;; |\n (baz quux)&quot;</a>)
  250. (<a id='321' tid='322' class='m'>&quot; (foo bar) |(baz quux)&quot;</a>
  251. <a id='323' tid='324' class='m'>&quot; (foo bar)\n ;; |\n (baz quux)&quot;</a>)
  252. (<a id='325' tid='326' class='m'>&quot;|(defun hello-world ...)&quot;</a>
  253. <a id='327' tid='328' class='m'>&quot;;;; |\n(defun hello-world ...)&quot;</a>))
  254. (<a id='261' tid='262' class='m'>&quot;C-j&quot;</a> <a id='263' tid='264' class='m'>paredit-newline</a>
  255. (<a id='265' tid='266' class='m'>&quot;(let ((n (frobbotz))) |(display (+ n 1)\nport))&quot;</a>
  256. <a id='267' tid='268' class='m'>,</a>(<a id='269' tid='270' class='m'>concat</a> <a id='271' tid='272' class='m'>&quot;(let ((n (frobbotz)))&quot;</a>
  257. <a id='273' tid='274' class='m'>&quot;\n |(display (+ n 1)&quot;</a>
  258. <a id='275' tid='276' class='m'>&quot;\n port))&quot;</a>)))
  259. <span class='d'>&quot;Deleting & Killing&quot;</span>
  260. ((<a id='217' tid='218' class='m'>&quot;C-d&quot;</a> <a id='219' tid='220' class='m'>,</a><a id='221' tid='222' class='m'>@paredit-forward-delete-keys</a>)
  261. <a id='223' tid='224' class='m'>paredit-forward-delete</a>
  262. (<a id='225' tid='226' class='m'>&quot;(quu|x \&quot;zot\&quot;)&quot;</a> <a id='227' tid='228' class='m'>&quot;(quu| \&quot;zot\&quot;)&quot;</a>)
  263. (<a id='229' tid='230' class='m'>&quot;(quux |\&quot;zot\&quot;)&quot;</a>
  264. <a id='231' tid='232' class='m'>&quot;(quux \&quot;|zot\&quot;)&quot;</a>
  265. <a id='233' tid='234' class='m'>&quot;(quux \&quot;|ot\&quot;)&quot;</a>)
  266. (<a id='235' tid='236' class='m'>&quot;(foo (|) bar)&quot;</a> <a id='237' tid='238' class='m'>&quot;(foo | bar)&quot;</a>)
  267. (<a id='239' tid='240' class='m'>&quot;|(foo bar)&quot;</a> <a id='241' tid='242' class='m'>&quot;(|foo bar)&quot;</a>))
  268. (<a id='193' tid='194' class='m'>,</a><a id='195' tid='196' class='m'>paredit-backward-delete-key</a>
  269. <a id='197' tid='198' class='m'>paredit-backward-delete</a>
  270. (<a id='199' tid='200' class='m'>&quot;(\&quot;zot\&quot; q|uux)&quot;</a> <a id='201' tid='202' class='m'>&quot;(\&quot;zot\&quot; |uux)&quot;</a>)
  271. (<a id='203' tid='204' class='m'>&quot;(\&quot;zot\&quot;| quux)&quot;</a>
  272. <a id='205' tid='206' class='m'>&quot;(\&quot;zot|\&quot; quux)&quot;</a>
  273. <a id='207' tid='208' class='m'>&quot;(\&quot;zo|\&quot; quux)&quot;</a>)
  274. (<a id='209' tid='210' class='m'>&quot;(foo (|) bar)&quot;</a> <a id='211' tid='212' class='m'>&quot;(foo | bar)&quot;</a>)
  275. (<a id='213' tid='214' class='m'>&quot;(foo bar)|&quot;</a> <a id='215' tid='216' class='m'>&quot;(foo bar|)&quot;</a>))
  276. (<a id='173' tid='174' class='m'>&quot;C-k&quot;</a> <a id='175' tid='176' class='m'>paredit-kill</a>
  277. (<a id='177' tid='178' class='m'>&quot;(foo bar)| ; Useless comment!&quot;</a>
  278. <a id='179' tid='180' class='m'>&quot;(foo bar)|&quot;</a>)
  279. (<a id='181' tid='182' class='m'>&quot;(|foo bar) ; Useful comment!&quot;</a>
  280. <a id='183' tid='184' class='m'>&quot;(|) ; Useful comment!&quot;</a>)
  281. (<a id='185' tid='186' class='m'>&quot;|(foo bar) ; Useless line!&quot;</a>
  282. <a id='187' tid='188' class='m'>&quot;|&quot;</a>)
  283. (<a id='189' tid='190' class='m'>&quot;(foo \&quot;|bar baz\&quot;\n quux)&quot;</a>
  284. <a id='191' tid='192' class='m'>&quot;(foo \&quot;|\&quot;\n quux)&quot;</a>))
  285. (<a id='155' tid='156' class='m'>&quot;M-d&quot;</a> <a id='157' tid='158' class='m'>paredit-forward-kill-word</a>
  286. (<a id='159' tid='160' class='m'>&quot;|(foo bar) ; baz&quot;</a>
  287. <a id='161' tid='162' class='m'>&quot;(| bar) ; baz&quot;</a>
  288. <a id='163' tid='164' class='m'>&quot;(|) ; baz&quot;</a>
  289. <a id='165' tid='166' class='m'>&quot;() ;|&quot;</a>)
  290. (<a id='167' tid='168' class='m'>&quot;;;;| Frobnicate\n(defun frobnicate ...)&quot;</a>
  291. <a id='169' tid='170' class='m'>&quot;;;;|\n(defun frobnicate ...)&quot;</a>
  292. <a id='171' tid='172' class='m'>&quot;;;;\n(| frobnicate ...)&quot;</a>))
  293. (<a id='135' tid='136' class='m'>,</a>(<a id='137' tid='138' class='m'>concat</a> <a id='139' tid='140' class='m'>&quot;M-&quot;</a> <a id='141' tid='142' class='m'>paredit-backward-delete-key</a>)
  294. <a id='143' tid='144' class='m'>paredit-backward-kill-word</a>
  295. (<a id='145' tid='146' class='m'>&quot;(foo bar) ; baz\n(quux)|&quot;</a>
  296. <a id='147' tid='148' class='m'>&quot;(foo bar) ; baz\n(|)&quot;</a>
  297. <a id='149' tid='150' class='m'>&quot;(foo bar) ; |\n()&quot;</a>
  298. <a id='151' tid='152' class='m'>&quot;(foo |) ; \n()&quot;</a>
  299. <a id='153' tid='154' class='m'>&quot;(|) ; \n()&quot;</a>))
  300. <span class='d'>&quot;Movement & Navigation&quot;</span>
  301. (<a id='123' tid='124' class='m'>&quot;C-M-f&quot;</a> <a id='125' tid='126' class='m'>paredit-forward</a>
  302. (<a id='127' tid='128' class='m'>&quot;(foo |(bar baz) quux)&quot;</a>
  303. <a id='129' tid='130' class='m'>&quot;(foo (bar baz)| quux)&quot;</a>)
  304. (<a id='131' tid='132' class='m'>&quot;(foo (bar)|)&quot;</a>
  305. <a id='133' tid='134' class='m'>&quot;(foo (bar))|&quot;</a>))
  306. (<a id='111' tid='112' class='m'>&quot;C-M-b&quot;</a> <a id='113' tid='114' class='m'>paredit-backward</a>
  307. (<a id='115' tid='116' class='m'>&quot;(foo (bar baz)| quux)&quot;</a>
  308. <a id='117' tid='118' class='m'>&quot;(foo |(bar baz) quux)&quot;</a>)
  309. (<a id='119' tid='120' class='m'>&quot;(|(foo) bar)&quot;</a>
  310. <a id='121' tid='122' class='m'>&quot;|((foo) bar)&quot;</a>))
  311. <span class='d'>;;;(&quot;C-M-u&quot; backward-up-list) ; These two are built-in.
  312. </span><span class='d'>;;;(&quot;C-M-d&quot; down-list)
  313. </span> <span class='d'>(&quot;C-M-p&quot; backward-down-list)</span> <span class='d'>; Built-in, these are FORWARD-
  314. </span> <span class='d'>(&quot;C-M-n&quot; up-list)</span> <span class='d'>; & BACKWARD-LIST, which have
  315. </span> <span class='d'>; no need given C-M-f & C-M-b.
  316. </span>
  317. <span class='d'>&quot;Depth-Changing Commands&quot;</span>
  318. <span class='d'>(&quot;M-(&quot; paredit-wrap-sexp
  319. (&quot;(foo |bar baz)&quot;
  320. &quot;(foo (|bar) baz)&quot;))</span>
  321. <span class='d'>(&quot;M-s&quot; paredit-splice-sexp
  322. (&quot;(foo (bar| baz) quux)&quot;
  323. &quot;(foo bar| baz quux)&quot;))</span>
  324. ((<a id='101' tid='102' class='m'>&quot;M-&lt;up&gt;&quot;</a> <a id='103' tid='104' class='m'>&quot;ESC &lt;up&gt;&quot;</a>)
  325. <a id='105' tid='106' class='m'>paredit-splice-sexp-killing-backward</a>
  326. (<a id='107' tid='108' class='m'>&quot;(foo (let ((x 5)) |(sqrt n)) bar)&quot;</a>
  327. <a id='109' tid='110' class='m'>&quot;(foo (sqrt n) bar)&quot;</a>))
  328. ((<a id='91' tid='92' class='m'>&quot;M-&lt;down&gt;&quot;</a> <a id='93' tid='94' class='m'>&quot;ESC &lt;down&gt;&quot;</a>)
  329. <a id='95' tid='96' class='m'>paredit-splice-sexp-killing-forward</a>
  330. (<a id='97' tid='98' class='m'>&quot;(a (b c| d e) f)&quot;</a>
  331. <a id='99' tid='100' class='m'>&quot;(a b c f)&quot;</a>))
  332. (<a id='81' tid='82' class='m'>&quot;M-r&quot;</a> <a id='83' tid='84' class='m'>paredit-raise-sexp</a>
  333. (<a id='85' tid='86' class='m'>&quot;(dynamic-wind in (lambda () |body) out)&quot;</a>
  334. <a id='87' tid='88' class='m'>&quot;(dynamic-wind in |body out)&quot;</a>
  335. <a id='89' tid='90' class='m'>&quot;|body&quot;</a>))
  336. <span class='d'>&quot;Barfage & Slurpage&quot;</span>
  337. ((<a id='67' tid='68' class='m'>&quot;C-)&quot;</a> <a id='69' tid='70' class='m'>&quot;C-&lt;right&gt;&quot;</a>)
  338. <a id='71' tid='72' class='m'>paredit-forward-slurp-sexp</a>
  339. (<a id='73' tid='74' class='m'>&quot;(foo (bar |baz) quux zot)&quot;</a>
  340. <a id='75' tid='76' class='m'>&quot;(foo (bar |baz quux) zot)&quot;</a>)
  341. (<a id='77' tid='78' class='m'>&quot;(a b ((c| d)) e f)&quot;</a>
  342. <a id='79' tid='80' class='m'>&quot;(a b ((c| d) e) f)&quot;</a>))
  343. ((<a id='57' tid='58' class='m'>&quot;C-}&quot;</a> <a id='59' tid='60' class='m'>&quot;C-&lt;left&gt;&quot;</a>)
  344. <a id='61' tid='62' class='m'>paredit-forward-barf-sexp</a>
  345. (<a id='63' tid='64' class='m'>&quot;(foo (bar |baz quux) zot)&quot;</a>
  346. <a id='65' tid='66' class='m'>&quot;(foo (bar |baz) quux zot)&quot;</a>))
  347. ((<a id='41' tid='42' class='m'>&quot;C-(&quot;</a> <a id='43' tid='44' class='m'>&quot;C-M-&lt;left&gt;&quot;</a> <a id='45' tid='46' class='m'>&quot;ESC C-&lt;left&gt;&quot;</a>)
  348. <a id='47' tid='48' class='m'>paredit-backward-slurp-sexp</a>
  349. (<a id='49' tid='50' class='m'>&quot;(foo bar (baz| quux) zot)&quot;</a>
  350. <a id='51' tid='52' class='m'>&quot;(foo (bar baz| quux) zot)&quot;</a>)
  351. (<a id='53' tid='54' class='m'>&quot;(a b ((c| d)) e f)&quot;</a>
  352. <a id='55' tid='56' class='m'>&quot;(a (b (c| d)) e f)&quot;</a>))
  353. ((<a id='29' tid='30' class='m'>&quot;C-{&quot;</a> <a id='31' tid='32' class='m'>&quot;C-M-&lt;right&gt;&quot;</a> <a id='33' tid='34' class='m'>&quot;ESC C-&lt;right&gt;&quot;</a>)
  354. <a id='35' tid='36' class='m'>paredit-backward-barf-sexp</a>
  355. (<a id='37' tid='38' class='m'>&quot;(foo (bar baz |quux) zot)&quot;</a>
  356. <a id='39' tid='40' class='m'>&quot;(foo bar (baz |quux) zot)&quot;</a>))
  357. <span class='d'>&quot;Miscellaneous Commands&quot;</span>
  358. (<a id='17' tid='18' class='m'>&quot;M-S&quot;</a> <a id='19' tid='20' class='m'>paredit-split-sexp</a>
  359. (<a id='21' tid='22' class='m'>&quot;(hello| world)&quot;</a>
  360. <a id='23' tid='24' class='m'>&quot;(hello)| (world)&quot;</a>)
  361. (<a id='25' tid='26' class='m'>&quot;\&quot;Hello, |world!\&quot;&quot;</a>
  362. <a id='27' tid='28' class='m'>&quot;\&quot;Hello, \&quot;| \&quot;world!\&quot;&quot;</a>))
  363. (<a id='1' tid='2' class='m'>&quot;M-J&quot;</a> <a id='3' tid='4' class='m'>paredit-join-sexps</a>
  364. (<a id='5' tid='6' class='m'>&quot;(hello)| (world)&quot;</a>
  365. <a id='7' tid='8' class='m'>&quot;(hello| world)&quot;</a>)
  366. (<a id='9' tid='10' class='m'>&quot;\&quot;Hello, \&quot;| \&quot;world!\&quot;&quot;</a>
  367. <a id='11' tid='12' class='m'>&quot;\&quot;Hello, |world!\&quot;&quot;</a>)
  368. (<a id='13' tid='14' class='m'>&quot;hello-\n| world&quot;</a>
  369. <a id='15' tid='16' class='m'>&quot;hello-|world&quot;</a>))
  370. <span class='d'>(&quot;C-c C-M-l&quot; paredit-recentre-on-sexp)</span>
  371. ))
  372. <a id='807' tid='808' class='m'>nil</a>) <span class='d'>; end of PROGN
  373. </span>
  374. <span class='d'>;;;;; Command Examples
  375. </span>
  376. (<a id='4635' tid='4636' class='u'>eval-and-compile</a>
  377. (<a id='4637' tid='4638' class='u'>defmacro</a> <a id='4639' tid='4640' class='u'>paredit-do-commands</a> (<a id='4641' tid='4642' class='u'>vars</a> <a id='4643' tid='4644' class='u'>string-case</a> <a id='4645' tid='4646' class='u'>&rest</a> <a id='4647' tid='4648' class='u'>body</a>)
  378. (<a id='4649' tid='4650' class='u'>let</a> ((<a id='4651' tid='4652' class='u'>spec</a> (<a id='4653' tid='4654' class='u'>nth</a> <a id='4655' tid='4656' class='u'>0</a> <a id='4657' tid='4658' class='u'>vars</a>))
  379. (<a id='4659' tid='4660' class='u'>keys</a> (<a id='4661' tid='4662' class='u'>nth</a> <a id='4663' tid='4664' class='u'>1</a> <a id='4665' tid='4666' class='u'>vars</a>))
  380. (<a id='4667' tid='4668' class='u'>fn</a> (<a id='4669' tid='4670' class='u'>nth</a> <a id='4671' tid='4672' class='u'>2</a> <a id='4673' tid='4674' class='u'>vars</a>))
  381. (<a id='4675' tid='4676' class='u'>examples</a> (<a id='4677' tid='4678' class='u'>nth</a> <a id='4679' tid='4680' class='u'>3</a> <a id='4681' tid='4682' class='u'>vars</a>)))
  382. <a id='4683' tid='4684' class='u'>`</a>(<a id='4685' tid='4686' class='u'>dolist</a> (<a id='4687' tid='4688' class='u'>,</a><a id='4689' tid='4690' class='u'>spec</a> <a id='4691' tid='4692' class='u'>paredit-commands</a>)
  383. (<a id='4693' tid='4694' class='u'>if</a> (<a id='4695' tid='4696' class='u'>stringp</a> <a id='4697' tid='4698' class='u'>,</a><a id='4699' tid='4700' class='u'>spec</a>)
  384. <a id='4701' tid='4702' class='u'>,</a><a id='4703' tid='4704' class='u'>string-case</a>
  385. (<a id='4705' tid='4706' class='u'>let</a> ((<a id='4707' tid='4708' class='u'>,</a><a id='4709' tid='4710' class='u'>keys</a> (<a id='4711' tid='4712' class='u'>let</a> ((<a id='4713' tid='4714' class='u'>k</a> (<a id='4715' tid='4716' class='u'>car</a> <a id='4717' tid='4718' class='u'>,</a><a id='4719' tid='4720' class='u'>spec</a>)))
  386. (<a id='4721' tid='4722' class='u'>cond</a> ((<a id='4723' tid='4724' class='u'>stringp</a> <a id='4725' tid='4726' class='u'>k</a>) (<a id='4727' tid='4728' class='u'>list</a> <a id='4729' tid='4730' class='u'>k</a>))
  387. ((<a id='4731' tid='4732' class='u'>listp</a> <a id='4733' tid='4734' class='u'>k</a>) <a id='4735' tid='4736' class='u'>k</a>)
  388. (<a id='4737' tid='4738' class='u'>t</a> (<a id='4739' tid='4740' class='u'>error</a> <a id='4741' tid='4742' class='u'>&quot;Invalid paredit command %s.&quot;</a>
  389. <a id='4743' tid='4744' class='u'>,</a><a id='4745' tid='4746' class='u'>spec</a>)))))
  390. (<a id='4747' tid='4748' class='u'>,</a><a id='4749' tid='4750' class='u'>fn</a> (<a id='4751' tid='4752' class='u'>cadr</a> <a id='4753' tid='4754' class='u'>,</a><a id='4755' tid='4756' class='u'>spec</a>))
  391. (<a id='4757' tid='4758' class='u'>,</a><a id='4759' tid='4760' class='u'>examples</a> (<a id='4761' tid='4762' class='u'>cddr</a> <a id='4763' tid='4764' class='u'>,</a><a id='4765' tid='4766' class='u'>spec</a>)))
  392. <a id='4767' tid='4768' class='u'>,</a><a id='4769' tid='4770' class='u'>@body</a>)))))
  393. (<a id='4771' tid='4772' class='u'>put</a> <a id='4773' tid='4774' class='u'>&#39;</a><a id='4775' tid='4776' class='u'>paredit-do-commands</a> <a id='4777' tid='4778' class='u'>&#39;</a><a id='4779' tid='4780' class='u'>lisp-indent-function</a> <a id='4781' tid='4782' class='u'>2</a>))
  394. (<a id='2247' tid='2248' class='u'>defun</a> <a id='2249' tid='2250' class='u'>paredit-define-keys</a> ()
  395. (<a id='2251' tid='2252' class='u'>paredit-do-commands</a> (<a id='2253' tid='2254' class='u'>spec</a> <a id='2255' tid='2256' class='u'>keys</a> <a id='2257' tid='2258' class='u'>fn</a> <a id='2259' tid='2260' class='u'>examples</a>)
  396. <a id='2261' tid='2262' class='u'>nil</a> <a id='2263' tid='2264' class='u'>; string case
  397. </a> (<a id='2265' tid='2266' class='u'>dolist</a> (<a id='2267' tid='2268' class='u'>key</a> <a id='2269' tid='2270' class='u'>keys</a>)
  398. (<a id='2271' tid='2272' class='u'>define-key</a> <a id='2273' tid='2274' class='u'>paredit-mode-map</a> (<a id='2275' tid='2276' class='u'>read-kbd-macro</a> <a id='2277' tid='2278' class='u'>key</a>) <a id='2279' tid='2280' class='u'>fn</a>))))
  399. (<a id='3105' tid='3106' class='u'>defun</a> <a id='3107' tid='3108' class='u'>paredit-function-documentation</a> (<a id='3109' tid='3110' class='u'>fn</a>)
  400. (<a id='3111' tid='3112' class='u'>let</a> ((<a id='3113' tid='3114' class='u'>original-doc</a> (<a id='3115' tid='3116' class='u'>get</a> <a id='3117' tid='3118' class='u'>fn</a> <a id='3119' tid='3120' class='u'>&#39;</a><a id='3121' tid='3122' class='u'>paredit-original-documentation</a>))
  401. (<a id='3123' tid='3124' class='u'>doc</a> (<a id='3125' tid='3126' class='u'>documentation</a> <a id='3127' tid='3128' class='u'>fn</a> <a id='3129' tid='3130' class='u'>&#39;</a><a id='3131' tid='3132' class='u'>function-documentation</a>)))
  402. (<a id='3133' tid='3134' class='u'>or</a> <a id='3135' tid='3136' class='u'>original-doc</a>
  403. (<a id='3137' tid='3138' class='u'>progn</a> (<a id='3139' tid='3140' class='u'>put</a> <a id='3141' tid='3142' class='u'>fn</a> <a id='3143' tid='3144' class='u'>&#39;</a><a id='3145' tid='3146' class='u'>paredit-original-documentation</a> <a id='3147' tid='3148' class='u'>doc</a>)
  404. <a id='3149' tid='3150' class='u'>doc</a>))))
  405. (<a id='1603' tid='1604' class='u'>defun</a> <a id='1605' tid='1606' class='u'>paredit-annotate-mode-with-examples</a> ()
  406. (<a id='1607' tid='1608' class='u'>let</a> ((<a id='1609' tid='1610' class='u'>contents</a>
  407. (<a id='1611' tid='1612' class='u'>list</a> (<a id='1613' tid='1614' class='u'>paredit-function-documentation</a> <a id='1615' tid='1616' class='u'>&#39;</a><a id='1617' tid='1618' class='u'>paredit-mode</a>))))
  408. (<a id='1619' tid='1620' class='u'>paredit-do-commands</a> (<a id='1621' tid='1622' class='u'>spec</a> <a id='1623' tid='1624' class='u'>keys</a> <a id='1625' tid='1626' class='u'>fn</a> <a id='1627' tid='1628' class='u'>examples</a>)
  409. (<a id='1629' tid='1630' class='u'>push</a> (<a id='1631' tid='1632' class='u'>concat</a> <a id='1633' tid='1634' class='u'>&quot;\n \n&quot;</a> <a id='1635' tid='1636' class='u'>spec</a> <a id='1637' tid='1638' class='u'>&quot;\n&quot;</a>)
  410. <a id='1639' tid='1640' class='u'>contents</a>)
  411. (<a id='1641' tid='1642' class='u'>let</a> ((<a id='1643' tid='1644' class='u'>name</a> (<a id='1645' tid='1646' class='u'>symbol-name</a> <a id='1647' tid='1648' class='u'>fn</a>)))
  412. (<a id='1649' tid='1650' class='u'>if</a> (<a id='1651' tid='1652' class='u'>string-match</a> (<a id='1653' tid='1654' class='u'>symbol-name</a> <a id='1655' tid='1656' class='u'>&#39;</a><a id='1657' tid='1658' class='u'>paredit-</a>) <a id='1659' tid='1660' class='u'>name</a>)
  413. (<a id='1661' tid='1662' class='u'>push</a> (<a id='1663' tid='1664' class='u'>concat</a> <a id='1665' tid='1666' class='u'>&quot;\n\n\\[&quot;</a> <a id='1667' tid='1668' class='u'>name</a> <a id='1669' tid='1670' class='u'>&quot;]\t&quot;</a> <a id='1671' tid='1672' class='u'>name</a>
  414. (<a id='1673' tid='1674' class='u'>if</a> <a id='1675' tid='1676' class='u'>examples</a>
  415. (<a id='1677' tid='1678' class='u'>mapconcat</a> (<a id='1679' tid='1680' class='u'>lambda</a> (<a id='1681' tid='1682' class='u'>example</a>)
  416. (<a id='1683' tid='1684' class='u'>concat</a>
  417. <a id='1685' tid='1686' class='u'>&quot;\n&quot;</a>
  418. (<a id='1687' tid='1688' class='u'>mapconcat</a> <a id='1689' tid='1690' class='u'>&#39;</a><a id='1691' tid='1692' class='u'>identity</a>
  419. <a id='1693' tid='1694' class='u'>example</a>
  420. <a id='1695' tid='1696' class='u'>&quot;\n ---&gt;\n&quot;</a>)
  421. <a id='1697' tid='1698' class='u'>&quot;\n&quot;</a>))
  422. <a id='1699' tid='1700' class='u'>examples</a>
  423. <a id='1701' tid='1702' class='u'>&quot;&quot;</a>)
  424. <a id='1703' tid='1704' class='u'>&quot;\n (no examples)\n&quot;</a>))
  425. <a id='1705' tid='1706' class='u'>contents</a>))))
  426. (<a id='1707' tid='1708' class='u'>put</a> <a id='1709' tid='1710' class='u'>&#39;</a><a id='1711' tid='1712' class='u'>paredit-mode</a> <a id='1713' tid='1714' class='u'>&#39;</a><a id='1715' tid='1716' class='u'>function-documentation</a>
  427. (<a id='1717' tid='1718' class='u'>apply</a> <a id='1719' tid='1720' class='u'>&#39;</a><a id='1721' tid='1722' class='u'>concat</a> (<a id='1723' tid='1724' class='u'>reverse</a> <a id='1725' tid='1726' class='u'>contents</a>))))
  428. <a id='1727' tid='1728' class='u'>;; PUT returns the huge string we just constructed, which we don&#39;t
  429. </a> <a id='1729' tid='1730' class='u'>;; want it to return.
  430. </a> <a id='1731' tid='1732' class='u'>nil</a>)
  431. (<a id='1537' tid='1538' class='u'>defun</a> <a id='1539' tid='1540' class='u'>paredit-annotate-functions-with-examples</a> ()
  432. (<a id='1541' tid='1542' class='u'>paredit-do-commands</a> (<a id='1543' tid='1544' class='u'>spec</a> <a id='1545' tid='1546' class='u'>keys</a> <a id='1547' tid='1548' class='u'>fn</a> <a id='1549' tid='1550' class='u'>examples</a>)
  433. <a id='1551' tid='1552' class='u'>nil</a> <a id='1553' tid='1554' class='u'>; string case
  434. </a> (<a id='1555' tid='1556' class='u'>put</a> <a id='1557' tid='1558' class='u'>fn</a> <a id='1559' tid='1560' class='u'>&#39;</a><a id='1561' tid='1562' class='u'>function-documentation</a>
  435. (<a id='1563' tid='1564' class='u'>concat</a> (<a id='1565' tid='1566' class='u'>paredit-function-documentation</a> <a id='1567' tid='1568' class='u'>fn</a>)
  436. <a id='1569' tid='1570' class='u'>&quot;\n\n\\&lt;paredit-mode-map&gt;\\[&quot;</a> (<a id='1571' tid='1572' class='u'>symbol-name</a> <a id='1573' tid='1574' class='u'>fn</a>) <a id='1575' tid='1576' class='u'>&quot;]\n&quot;</a>
  437. (<a id='1577' tid='1578' class='u'>mapconcat</a> (<a id='1579' tid='1580' class='u'>lambda</a> (<a id='1581' tid='1582' class='u'>example</a>)
  438. (<a id='1583' tid='1584' class='u'>concat</a> <a id='1585' tid='1586' class='u'>&quot;\n&quot;</a>
  439. (<a id='1587' tid='1588' class='u'>mapconcat</a> <a id='1589' tid='1590' class='u'>&#39;</a><a id='1591' tid='1592' class='u'>identity</a>
  440. <a id='1593' tid='1594' class='u'>example</a>
  441. <a id='1595' tid='1596' class='u'>&quot;\n -&gt;\n&quot;</a>)
  442. <a id='1597' tid='1598' class='u'>&quot;\n&quot;</a>))
  443. <a id='1599' tid='1600' class='u'>examples</a>
  444. <a id='1601' tid='1602' class='u'>&quot;&quot;</a>)))))
  445. <a id='4783' tid='4784' class='u'>;;;;; HTML Examples
  446. </a>
  447. (<a id='3325' tid='3326' class='u'>defun</a> <a id='3327' tid='3328' class='u'>paredit-insert-html-examples</a> ()
  448. <a id='3329' tid='3330' class='u'>&quot;Insert HTML for a paredit quick reference table.&quot;</a>
  449. (<a id='3331' tid='3332' class='u'>interactive</a>)
  450. (<a id='3333' tid='3334' class='u'>let</a> ((<a id='3335' tid='3336' class='u'>insert-lines</a> (<a id='3337' tid='3338' class='u'>lambda</a> (<a id='3339' tid='3340' class='u'>&rest</a> <a id='3341' tid='3342' class='u'>lines</a>)
  451. (<a id='3343' tid='3344' class='u'>mapc</a> (<a id='3345' tid='3346' class='u'>lambda</a> (<a id='3347' tid='3348' class='u'>line</a>) (<a id='3349' tid='3350' class='u'>insert</a> <a id='3351' tid='3352' class='u'>line</a>) (<a id='3353' tid='3354' class='u'>newline</a>))
  452. <a id='3355' tid='3356' class='u'>lines</a>)))
  453. (<a id='3357' tid='3358' class='u'>html-keys</a> (<a id='3359' tid='3360' class='u'>lambda</a> (<a id='3361' tid='3362' class='u'>keys</a>)
  454. (<a id='3363' tid='3364' class='u'>mapconcat</a> <a id='3365' tid='3366' class='u'>&#39;</a><a id='3367' tid='3368' class='u'>paredit-html-quote</a> <a id='3369' tid='3370' class='u'>keys</a> <a id='3371' tid='3372' class='u'>&quot;, &quot;</a>)))
  455. (<a id='3373' tid='3374' class='u'>html-example</a>
  456. (<a id='3375' tid='3376' class='u'>lambda</a> (<a id='3377' tid='3378' class='u'>example</a>)
  457. (<a id='3379' tid='3380' class='u'>concat</a> <a id='3381' tid='3382' class='u'>&quot;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;pre&gt;&quot;</a>
  458. (<a id='3383' tid='3384' class='u'>mapconcat</a> <a id='3385' tid='3386' class='u'>&#39;</a><a id='3387' tid='3388' class='u'>paredit-html-quote</a>
  459. <a id='3389' tid='3390' class='u'>example</a>
  460. (<a id='3391' tid='3392' class='u'>concat</a> <a id='3393' tid='3394' class='u'>&quot;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&quot;</a>
  461. <a id='3395' tid='3396' class='u'>&quot;&nbsp;&nbsp;&nbsp;&nbsp;---&gt;&quot;</a>
  462. <a id='3397' tid='3398' class='u'>&quot;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;pre&gt;&quot;</a>))
  463. <a id='3399' tid='3400' class='u'>&quot;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;</a>)))
  464. (<a id='3401' tid='3402' class='u'>firstp</a> <a id='3403' tid='3404' class='u'>t</a>))
  465. (<a id='3405' tid='3406' class='u'>paredit-do-commands</a> (<a id='3407' tid='3408' class='u'>spec</a> <a id='3409' tid='3410' class='u'>keys</a> <a id='3411' tid='3412' class='u'>fn</a> <a id='3413' tid='3414' class='u'>examples</a>)
  466. (<a id='3415' tid='3416' class='u'>progn</a> (<a id='3417' tid='3418' class='u'>if</a> (<a id='3419' tid='3420' class='u'>not</a> <a id='3421' tid='3422' class='u'>firstp</a>)
  467. (<a id='3423' tid='3424' class='u'>insert</a> <a id='3425' tid='3426' class='u'>&quot;&lt;/table&gt;\n&quot;</a>)
  468. (<a id='3427' tid='3428' class='u'>setq</a> <a id='3429' tid='3430' class='u'>firstp</a> <a id='3431' tid='3432' class='u'>nil</a>))
  469. (<a id='3433' tid='3434' class='u'>funcall</a> <a id='3435' tid='3436' class='u'>insert-lines</a>
  470. (<a id='3437' tid='3438' class='u'>concat</a> <a id='3439' tid='3440' class='u'>&quot;&lt;h3&gt;&quot;</a> <a id='3441' tid='3442' class='u'>spec</a> <a id='3443' tid='3444' class='u'>&quot;&lt;/h3&gt;&quot;</a>)
  471. <a id='3445' tid='3446' class='u'>&quot;&lt;table border=\&quot;1\&quot; cellpadding=\&quot;1\&quot;&gt;&quot;</a>
  472. <a id='3447' tid='3448' class='u'>&quot; &lt;tr&gt;&quot;</a>
  473. <a id='3449' tid='3450' class='u'>&quot; &lt;th&gt;Command&lt;/th&gt;&quot;</a>
  474. <a id='3451' tid='3452' class='u'>&quot; &lt;th&gt;Keys&lt;/th&gt;&quot;</a>
  475. <a id='3453' tid='3454' class='u'>&quot; &lt;th&gt;Examples&lt;/th&gt;&quot;</a>
  476. <a id='3455' tid='3456' class='u'>&quot; &lt;/tr&gt;&quot;</a>))
  477. (<a id='3457' tid='3458' class='u'>let</a> ((<a id='3459' tid='3460' class='u'>name</a> (<a id='3461' tid='3462' class='u'>symbol-name</a> <a id='3463' tid='3464' class='u'>fn</a>)))
  478. (<a id='3465' tid='3466' class='u'>if</a> (<a id='3467' tid='3468' class='u'>string-match</a> (<a id='3469' tid='3470' class='u'>symbol-name</a> <a id='3471' tid='3472' class='u'>&#39;</a><a id='3473' tid='3474' class='u'>paredit-</a>) <a id='3475' tid='3476' class='u'>name</a>)
  479. (<a id='3477' tid='3478' class='u'>funcall</a> <a id='3479' tid='3480' class='u'>insert-lines</a>
  480. <a id='3481' tid='3482' class='u'>&quot; &lt;tr&gt;&quot;</a>
  481. (<a id='3483' tid='3484' class='u'>concat</a> <a id='3485' tid='3486' class='u'>&quot; &lt;td&gt;&lt;tt&gt;&quot;</a> <a id='3487' tid='3488' class='u'>name</a> <a id='3489' tid='3490' class='u'>&quot;&lt;/tt&gt;&lt;/td&gt;&quot;</a>)
  482. (<a id='3491' tid='3492' class='u'>concat</a> <a id='3493' tid='3494' class='u'>&quot; &lt;td align=\&quot;center\&quot;&gt;&quot;</a>
  483. (<a id='3495' tid='3496' class='u'>funcall</a> <a id='3497' tid='3498' class='u'>html-keys</a> <a id='3499' tid='3500' class='u'>keys</a>)
  484. <a id='3501' tid='3502' class='u'>&quot;&lt;/td&gt;&quot;</a>)
  485. (<a id='3503' tid='3504' class='u'>concat</a> <a id='3505' tid='3506' class='u'>&quot; &lt;td&gt;&quot;</a>
  486. (<a id='3507' tid='3508' class='u'>if</a> <a id='3509' tid='3510' class='u'>examples</a>
  487. (<a id='3511' tid='3512' class='u'>mapconcat</a> <a id='3513' tid='3514' class='u'>html-example</a> <a id='3515' tid='3516' class='u'>examples</a>
  488. <a id='3517' tid='3518' class='u'>&quot;&lt;hr&gt;&quot;</a>)
  489. <a id='3519' tid='3520' class='u'>&quot;(no examples)&quot;</a>)
  490. <a id='3521' tid='3522' class='u'>&quot;&lt;/td&gt;&quot;</a>)
  491. <a id='3523' tid='3524' class='u'>&quot; &lt;/tr&gt;&quot;</a>)))))
  492. (<a id='3525' tid='3526' class='u'>insert</a> <a id='3527' tid='3528' class='u'>&quot;&lt;/table&gt;\n&quot;</a>))
  493. (<a id='3151' tid='3152' class='u'>defun</a> <a id='3153' tid='3154' class='u'>paredit-html-quote</a> (<a id='3155' tid='3156' class='u'>string</a>)
  494. (<a id='3157' tid='3158' class='u'>with-temp-buffer</a>
  495. (<a id='3159' tid='3160' class='u'>dotimes</a> (<a id='3161' tid='3162' class='u'>i</a> (<a id='3163' tid='3164' class='u'>length</a> <a id='3165' tid='3166' class='u'>string</a>))
  496. (<a id='3167' tid='3168' class='u'>insert</a> (<a id='3169' tid='3170' class='u'>let</a> ((<a id='3171' tid='3172' class='u'>c</a> (<a id='3173' tid='3174' class='u'>elt</a> <a id='3175' tid='3176' class='u'>string</a> <a id='3177' tid='3178' class='u'>i</a>)))
  497. (<a id='3179' tid='3180' class='u'>cond</a> ((<a id='3181' tid='3182' class='u'>eq</a> <a id='3183' tid='3184' class='u'>c</a> <a id='3185' tid='3186' class='u'>?\&lt;</a>) <a id='3187' tid='3188' class='u'>&quot;&lt;&quot;</a>)
  498. ((<a id='3189' tid='3190' class='u'>eq</a> <a id='3191' tid='3192' class='u'>c</a> <a id='3193' tid='3194' class='u'>?\&gt;</a>) <a id='3195' tid='3196' class='u'>&quot;&gt;&quot;</a>)
  499. ((<a id='3197' tid='3198' class='u'>eq</a> <a id='3199' tid='3200' class='u'>c</a> <a id='3201' tid='3202' class='u'>?\&</a>) <a id='3203' tid='3204' class='u'>&quot;&amp;&quot;</a>)
  500. ((<a id='3205' tid='3206' class='u'>eq</a> <a id='3207' tid='3208' class='u'>c</a> <a id='3209' tid='3210' class='u'>?\&#39;</a>) <a id='3211' tid='3212' class='u'>&quot;&apos;&quot;</a>)
  501. ((<a id='3213' tid='3214' class='u'>eq</a> <a id='3215' tid='3216' class='u'>c</a> <a id='3217' tid='3218' class='u'>?\&quot;</a>) <a id='3219' tid='3220' class='u'>&quot;&quot;&quot;</a>)
  502. (<a id='3221' tid='3222' class='u'>t</a> <a id='3223' tid='3224' class='u'>c</a>)))))
  503. (<a id='3225' tid='3226' class='u'>buffer-string</a>)))
  504. <a id='4785' tid='4786' class='u'>;;;; Delimiter Insertion
  505. </a>
  506. (<a id='827' tid='828' class='m'>eval-and-compile</a>
  507. (<a id='809' tid='810' class='m'>defun</a> <a id='811' tid='812' class='m'>paredit-conc-name</a> (<a id='813' tid='814' class='m'>&rest</a> <a id='815' tid='816' class='m'>strings</a>)
  508. (<a id='817' tid='818' class='m'>intern</a> (<a id='819' tid='820' class='m'>apply</a> <a id='821' tid='822' class='m'>&#39;</a><a id='823' tid='824' class='m'>concat</a> <a id='825' tid='826' class='m'>strings</a>)))
  509. (<a id='829' tid='830' class='m'>defmacro</a> <a id='831' tid='832' class='m'>define-paredit-pair</a> (<a id='833' tid='834' class='m'>open</a> <a id='835' tid='836' class='m'>close</a> <a id='837' tid='838' class='m'>name</a>)
  510. <a id='839' tid='840' class='m'>`</a>(<span class='d'>progn</span>
  511. (<a id='841' tid='842' class='m'>defun</a> <a id='843' tid='844' class='m'>,</a>(<a id='845' tid='846' class='m'>paredit-conc-name</a> <a id='847' tid='848' class='m'>&quot;paredit-open-&quot;</a> <a id='849' tid='850' class='m'>name</a>) (<a id='851' tid='852' class='m'>&optional</a> <a id='853' tid='854' class='m'>n</a>)
  512. <a id='855' tid='856' class='m'>,</a>(<a id='857' tid='858' class='m'>concat</a> <a id='859' tid='860' class='m'>&quot;Insert a balanced &quot;</a> <a id='861' tid='862' class='m'>name</a> <a id='863' tid='864' class='m'>&quot; pair.
  513. With a prefix argument N, put the closing &quot;</a> <a id='865' tid='866' class='m'>name</a> <a id='867' tid='868' class='m'>&quot; after N
  514. S-expressions forward.
  515. If the region is active, `transient-mark-mode&#39; is enabled, and the
  516. region&#39;s start and end fall in the same parenthesis depth, insert a
  517. &quot;</a> <a id='869' tid='870' class='m'>name</a> <a id='871' tid='872' class='m'>&quot; pair around the region.
  518. If in a string or a comment, insert a single &quot;</a> <a id='873' tid='874' class='m'>name</a> <a id='875' tid='876' class='m'>&quot;.
  519. If in a character literal, do nothing. This prevents changing what was
  520. in the character literal to a meaningful delimiter unintentionally.&quot;</a>)
  521. (<a id='877' tid='878' class='m'>interactive</a> <a id='879' tid='880' class='m'>&quot;P&quot;</a>)
  522. (<a id='881' tid='882' class='m'>cond</a> ((<a id='883' tid='884' class='m'>or</a> (<a id='885' tid='886' class='m'>paredit-in-string-p</a>)
  523. (<a id='887' tid='888' class='m'>paredit-in-comment-p</a>))
  524. (<a id='889' tid='890' class='m'>insert</a> <a id='891' tid='892' class='m'>,</a><a id='893' tid='894' class='m'>open</a>))
  525. ((<a id='895' tid='896' class='m'>not</a> (<a id='897' tid='898' class='m'>paredit-in-char-p</a>))
  526. (<a id='899' tid='900' class='m'>paredit-insert-pair</a> <a id='901' tid='902' class='m'>n</a> <a id='903' tid='904' class='m'>,</a><a id='905' tid='906' class='m'>open</a> <a id='907' tid='908' class='m'>,</a><a id='909' tid='910' class='m'>close</a> <a id='911' tid='912' class='m'>&#39;</a><a id='913' tid='914' class='m'>goto-char</a>))))
  527. (<a id='513' tid='514' class='m'>defun</a> <a id='515' tid='516' class='m'>,</a>(<a id='517' tid='518' class='m'>paredit-conc-name</a> <a id='519' tid='520' class='m'>&quot;paredit-close-&quot;</a> <a id='521' tid='522' class='m'>name</a>) ()
  528. <a id='523' tid='524' class='m'>,</a>(<a id='525' tid='526' class='m'>concat</a> <a id='527' tid='528' class='m'>&quot;Move past one closing delimiter and reindent.
  529. \(Agnostic to the specific closing delimiter.)
  530. If in a string or comment, insert a single closing &quot;</a> <a id='529' tid='530' class='m'>name</a> <a id='531' tid='532' class='m'>&quot;.
  531. If in a character literal, do nothing. This prevents changing what was
  532. in the character literal to a meaningful delimiter unintentionally.&quot;</a>)
  533. (<a id='533' tid='534' class='m'>interactive</a>)
  534. (<a id='535' tid='536' class='m'>paredit-move-past-close</a> <a id='537' tid='538' class='m'>,</a><a id='539' tid='540' class='m'>close</a>))
  535. (<a id='405' tid='406' class='m'>defun</a> <a id='407' tid='408' class='m'>,</a>(<a id='409' tid='410' class='m'>paredit-conc-name</a> <a id='411' tid='412' class='m'>&quot;paredit-close-&quot;</a> <a id='413' tid='414' class='m'>name</a> <a id='415' tid='416' class='m'>&quot;-and-newline&quot;</a>) ()
  536. <a id='417' tid='418' class='m'>,</a>(<a id='419' tid='420' class='m'>concat</a> <a id='421' tid='422' class='m'>&quot;Move past one closing delimiter, add a newline,&quot;</a>
  537. <a id='423' tid='424' class='m'>&quot; and reindent.
  538. If there was a margin comment after the closing delimiter, preserve it
  539. on the same line.&quot;</a>)
  540. (<a id='425' tid='426' class='m'>interactive</a>)
  541. (<a id='427' tid='428' class='m'>paredit-move-past-close-and-newline</a> <a id='429' tid='430' class='m'>,</a><a id='431' tid='432' class='m'>close</a>)))))
  542. <span class='d'>(define-paredit-pair ?\( ?\) &quot;parenthesis&quot;)</span>
  543. <span class='d'>(define-paredit-pair ?\[ ?\] &quot;bracket&quot;)</span>
  544. <span class='d'>(define-paredit-pair ?\{ ?\} &quot;brace&quot;)</span>
  545. <span class='d'>(define-paredit-pair ?\&lt; ?\&gt; &quot;brocket&quot;)</span>
  546. (<a id='4197' tid='4198' class='u'>defun</a> <a id='4199' tid='4200' class='u'>paredit-move-past-close</a> (<a id='4201' tid='4202' class='u'>close</a>)
  547. (<span class='d'>cond</span> ((<a id='915' tid='916' class='m'>or</a> (<a id='917' tid='918' class='m'>paredit-in-string-p</a>)
  548. (<a id='919' tid='920' class='m'>paredit-in-comment-p</a>))
  549. (<a id='921' tid='922' class='m'>insert</a> <a id='923' tid='924' class='m'>close</a>))
  550. <span class='d'>((not (paredit-in-char-p))
  551. (paredit-move-past-close-and-reindent)
  552. (paredit-blink-paren-match nil))</span>))
  553. (<a id='4203' tid='4204' class='u'>defun</a> <a id='4205' tid='4206' class='u'>paredit-move-past-close-and-newline</a> (<a id='4207' tid='4208' class='u'>close</a>)
  554. (<span class='d'>cond</span> <span class='d'>((or (paredit-in-string-p)
  555. (paredit-in-comment-p))
  556. (insert close))</span>
  557. (<span class='d'>t</span> <span class='d'>(if (paredit-in-char-p) (forward-char))</span>
  558. <span class='d'>(paredit-move-past-close-and-reindent)</span>
  559. (<a id='925' tid='926' class='m'>let</a> ((<a id='927' tid='928' class='m'>comment.point</a> (<a id='929' tid='930' class='m'>paredit-find-comment-on-line</a>)))
  560. (<a id='931' tid='932' class='m'>newline</a>)
  561. (<a id='933' tid='934' class='m'>if</a> <a id='935' tid='936' class='m'>comment.point</a>
  562. (<a id='937' tid='938' class='m'>save-excursion</a>
  563. (<a id='939' tid='940' class='m'>forward-line</a> <a id='941' tid='942' class='m'>-1</a>)
  564. (<a id='943' tid='944' class='m'>end-of-line</a>)
  565. (<a id='945' tid='946' class='m'>indent-to</a> (<a id='947' tid='948' class='m'>cdr</a> <a id='949' tid='950' class='m'>comment.point</a>))
  566. (<a id='951' tid='952' class='m'>insert</a> (<a id='953' tid='954' class='m'>car</a> <a id='955' tid='956' class='m'>comment.point</a>)))))
  567. <span class='d'>(lisp-indent-line)</span>
  568. <span class='d'>(paredit-ignore-sexp-errors (indent-sexp))</span>
  569. <span class='d'>(paredit-blink-paren-match t)</span>)))
  570. (<a id='2429' tid='2430' class='u'>defun</a> <a id='2431' tid='2432' class='u'>paredit-find-comment-on-line</a> ()
  571. <span class='d'>&quot;Find a margin comment on the current line.
  572. If such a comment exists, delete the comment (including all leading
  573. whitespace) and return a cons whose car is the comment as a string
  574. and whose cdr is the point of the comment&#39;s initial semicolon,
  575. relative to the start of the line.&quot;</span>
  576. (<span class='d'>save-excursion</span>
  577. (<span class='d'>catch</span> <span class='d'>&#39;</span><span class='d'>return</span>
  578. (<span class='d'>while</span> <span class='d'>t</span>
  579. (<span class='d'>if</span> <span class='d'>(search-forward &quot;;&quot; (point-at-eol) t)</span>
  580. (<span class='d'>if</span> <span class='d'>(not (or (paredit-in-string-p)
  581. (paredit-in-char-p)))</span>
  582. (<a id='957' tid='958' class='m'>let*</a> ((<a id='959' tid='960' class='m'>start</a> (<a id='961' tid='962' class='m'>progn</a> (<a id='963' tid='964' class='m'>backward-char</a>) <span class='d'>;before semicolon
  583. </span> (<a id='965' tid='966' class='m'>point</a>)))
  584. (<a id='967' tid='968' class='m'>comment</a> (<a id='969' tid='970' class='m'>buffer-substring</a> <a id='971' tid='972' class='m'>start</a>
  585. (<a id='973' tid='974' class='m'>point-at-eol</a>))))
  586. (<a id='975' tid='976' class='m'>paredit-skip-whitespace</a> <a id='977' tid='978' class='m'>nil</a> (<a id='979' tid='980' class='m'>point-at-bol</a>))
  587. (<a id='981' tid='982' class='m'>delete-region</a> (<a id='983' tid='984' class='m'>point</a>) (<a id='985' tid='986' class='m'>point-at-eol</a>))
  588. (<span class='d'>throw</span> <span class='d'>&#39;</span><span class='d'>return</span>
  589. (<a id='987' tid='988' class='m'>cons</a> <a id='989' tid='990' class='m'>comment</a> (<a id='991' tid='992' class='m'>-</a> <a id='993' tid='994' class='m'>start</a> (<a id='995' tid='996' class='m'>point-at-bol</a>))))))
  590. <span class='d'>(throw &#39;return nil)</span>)))))
  591. (<a id='3529' tid='3530' class='u'>defun</a> <a id='3531' tid='3532' class='u'>paredit-insert-pair</a> (<a id='3533' tid='3534' class='u'>n</a> <a id='3535' tid='3536' class='u'>open</a> <a id='3537' tid='3538' class='u'>close</a> <a id='3539' tid='3540' class='u'>forward</a>)
  592. (<a id='3541' tid='3542' class='u'>let*</a> ((<a id='3543' tid='3544' class='u'>regionp</a> (<a id='3545' tid='3546' class='u'>and</a> (<a id='3547' tid='3548' class='u'>paredit-region-active-p</a>)
  593. (<a id='3549' tid='3550' class='u'>paredit-region-safe-for-insert-p</a>)))
  594. (<a id='3551' tid='3552' class='u'>end</a> (<a id='3553' tid='3554' class='u'>and</a> <a id='3555' tid='3556' class='u'>regionp</a>
  595. (<a id='3557' tid='3558' class='u'>not</a> <a id='3559' tid='3560' class='u'>n</a>)
  596. (<a id='3561' tid='3562' class='u'>prog1</a> (<a id='3563' tid='3564' class='u'>region-end</a>)
  597. (<a id='3565' tid='3566' class='u'>goto-char</a> (<a id='3567' tid='3568' class='u'>region-beginning</a>))))))
  598. (<a id='3569' tid='3570' class='u'>let</a> ((<a id='3571' tid='3572' class='u'>spacep</a> (<a id='3573' tid='3574' class='u'>paredit-space-for-delimiter-p</a> <a id='3575' tid='3576' class='u'>nil</a> <a id='3577' tid='3578' class='u'>open</a>)))
  599. (<a id='3579' tid='3580' class='u'>if</a> <a id='3581' tid='3582' class='u'>spacep</a> (<a id='3583' tid='3584' class='u'>insert</a> <a id='3585' tid='3586' class='u'>&quot; &quot;</a>))
  600. (<a id='3587' tid='3588' class='u'>insert</a> <a id='3589' tid='3590' class='u'>open</a>)
  601. (<a id='3591' tid='3592' class='u'>save-excursion</a>
  602. <a id='3593' tid='3594' class='u'>;; Move past the desired region.
  603. </a> (<a id='3595' tid='3596' class='u'>cond</a> (<a id='3597' tid='3598' class='u'>n</a> (<a id='3599' tid='3600' class='u'>funcall</a> <a id='3601' tid='3602' class='u'>forward</a>
  604. (<a id='3603' tid='3604' class='u'>save-excursion</a>
  605. (<a id='3605' tid='3606' class='u'>forward-sexp</a> (<a id='3607' tid='3608' class='u'>prefix-numeric-value</a> <a id='3609' tid='3610' class='u'>n</a>))
  606. (<a id='3611' tid='3612' class='u'>point</a>))))
  607. (<a id='3613' tid='3614' class='u'>regionp</a> (<a id='3615' tid='3616' class='u'>funcall</a> <a id='3617' tid='3618' class='u'>forward</a> (<a id='3619' tid='3620' class='u'>+</a> <a id='3621' tid='3622' class='u'>end</a> (<a id='3623' tid='3624' class='u'>if</a> <a id='3625' tid='3626' class='u'>spacep</a> <a id='3627' tid='3628' class='u'>2</a> <a id='3629' tid='3630' class='u'>1</a>)))))
  608. (<a id='3631' tid='3632' class='u'>insert</a> <a id='3633' tid='3634' class='u'>close</a>)
  609. (<a id='3635' tid='3636' class='u'>if</a> (<a id='3637' tid='3638' class='u'>paredit-space-for-delimiter-p</a> <a id='3639' tid='3640' class='u'>t</a> <a id='3641' tid='3642' class='u'>close</a>)
  610. (<a id='3643' tid='3644' class='u'>insert</a> <a id='3645' tid='3646' class='u'>&quot; &quot;</a>))))))
  611. (<a id='4329' tid='4330' class='u'>defun</a> <a id='4331' tid='4332' class='u'>paredit-region-safe-for-insert-p</a> ()
  612. (<a id='4333' tid='4334' class='u'>save-excursion</a>
  613. (<a id='4335' tid='4336' class='u'>let</a> ((<a id='4337' tid='4338' class='u'>beginning</a> (<a id='4339' tid='4340' class='u'>region-beginning</a>))
  614. (<a id='4341' tid='4342' class='u'>end</a> (<a id='4343' tid='4344' class='u'>region-end</a>)))
  615. (<a id='4345' tid='4346' class='u'>goto-char</a> <a id='4347' tid='4348' class='u'>beginning</a>)
  616. (<a id='4349' tid='4350' class='u'>let*</a> ((<a id='4351' tid='4352' class='u'>beginning-state</a> (<a id='4353' tid='4354' class='u'>paredit-current-parse-state</a>))
  617. (<a id='4355' tid='4356' class='u'>end-state</a> (<a id='4357' tid='4358' class='u'>parse-partial-sexp</a> <a id='4359' tid='4360' class='u'>beginning</a> <a id='4361' tid='4362' class='u'>end</a>
  618. <a id='4363' tid='4364' class='u'>nil</a> <a id='4365' tid='4366' class='u'>nil</a> <a id='4367' tid='4368' class='u'>beginning-state</a>)))
  619. (<a id='4369' tid='4370' class='u'>and</a> (<a id='4371' tid='4372' class='u'>=</a> (<a id='4373' tid='4374' class='u'>nth</a> <a id='4375' tid='4376' class='u'>0</a> <a id='4377' tid='4378' class='u'>beginning-state</a>) <a id='4379' tid='4380' class='u'>; 0. depth in parens
  620. </a> (<a id='4381' tid='4382' class='u'>nth</a> <a id='4383' tid='4384' class='u'>0</a> <a id='4385' tid='4386' class='u'>end-state</a>))
  621. (<a id='4387' tid='4388' class='u'>eq</a> (<a id='4389' tid='4390' class='u'>nth</a> <a id='4391' tid='4392' class='u'>3</a> <a id='4393' tid='4394' class='u'>beginning-state</a>) <a id='4395' tid='4396' class='u'>; 3. non-nil if inside a
  622. </a> (<a id='4397' tid='4398' class='u'>nth</a> <a id='4399' tid='4400' class='u'>3</a> <a id='4401' tid='4402' class='u'>end-state</a>)) <a id='4403' tid='4404' class='u'>; string
  623. </a> (<a id='4405' tid='4406' class='u'>eq</a> (<a id='4407' tid='4408' class='u'>nth</a> <a id='4409' tid='4410' class='u'>4</a> <a id='4411' tid='4412' class='u'>beginning-state</a>) <a id='4413' tid='4414' class='u'>; 4. comment status, yada
  624. </a> (<a id='4415' tid='4416' class='u'>nth</a> <a id='4417' tid='4418' class='u'>4</a> <a id='4419' tid='4420' class='u'>end-state</a>))
  625. (<a id='4421' tid='4422' class='u'>eq</a> (<a id='4423' tid='4424' class='u'>nth</a> <a id='4425' tid='4426' class='u'>5</a> <a id='4427' tid='4428' class='u'>beginning-state</a>) <a id='4429' tid='4430' class='u'>; 5. t if following char
  626. </a> (<a id='4431' tid='4432' class='u'>nth</a> <a id='4433' tid='4434' class='u'>5</a> <a id='4435' tid='4436' class='u'>end-state</a>))))))) <span class='d'>; quote
  627. </span>
  628. (<a id='4477' tid='4478' class='u'>defun</a> <a id='4479' tid='4480' class='u'>paredit-space-for-delimiter-p</a> (<a id='4481' tid='4482' class='u'>endp</a> <a id='4483' tid='4484' class='u'>delimiter</a>)
  629. <a id='4485' tid='4486' class='u'>;; If at the buffer limit, don&#39;t insert a space. If there is a word,
  630. </a> <a id='4487' tid='4488' class='u'>;; symbol, other quote, or non-matching parenthesis delimiter (i.e. a
  631. </a> <a id='4489' tid='4490' class='u'>;; close when want an open the string or an open when we want to
  632. </a> <a id='4491' tid='4492' class='u'>;; close the string), do insert a space.
  633. </a> (<span class='d'>and</span> (<a id='997' tid='998' class='m'>not</a> (<a id='999' tid='1000' class='m'>if</a> <a id='1001' tid='1002' class='m'>endp</a> (<a id='1003' tid='1004' class='m'>eobp</a>) (<a id='1005' tid='1006' class='m'>bobp</a>)))
  634. (<a id='433' tid='434' class='m'>memq</a> (<a id='541' tid='542' class='m'>char-syntax</a> (<a id='543' tid='544' class='m'>if</a> <a id='545' tid='546' class='m'>endp</a>
  635. (<a id='547' tid='548' class='m'>char-after</a>)
  636. (<a id='549' tid='550' class='m'>char-before</a>)))
  637. (<span class='d'>list</span> <span class='d'>?w</span> <span class='d'>?_</span> <span class='d'>?\&quot;</span>
  638. (<a id='435' tid='436' class='m'>let</a> ((<a id='437' tid='438' class='m'>matching</a> (<a id='439' tid='440' class='m'>matching-paren</a> <a id='441' tid='442' class='m'>delimiter</a>)))
  639. (<a id='443' tid='444' class='m'>and</a> <a id='445' tid='446' class='m'>matching</a> (<a id='447' tid='448' class='m'>char-syntax</a> <a id='449' tid='450' class='m'>matching</a>)))))))
  640. (<a id='4209' tid='4210' class='u'>defun</a> <a id='4211' tid='4212' class='u'>paredit-move-past-close-and-reindent</a> <span class='d'>()</span>
  641. (<span class='d'>let</span> <span class='d'>((orig (point)))</span>
  642. <span class='d'>(up-list)</span>
  643. (<a id='1007' tid='1008' class='m'>if</a> (<a id='1009' tid='1010' class='m'>catch</a> <a id='1011' tid='1012' class='m'>&#39;</a><a id='1013' tid='1014' class='m'>return</a> <a id='1015' tid='1016' class='m'>; This CATCH returns T if it
  644. </a> (<a id='1017' tid='1018' class='m'>while</a> <a id='1019' tid='1020' class='m'>t</a> <a id='1021' tid='1022' class='m'>; should delete leading spaces
  645. </a> (<a id='1023' tid='1024' class='m'>save-excursion</a> <a id='1025' tid='1026' class='m'>; and NIL if not.
  646. </a> (<a id='1027' tid='1028' class='m'>let</a> ((<a id='1029' tid='1030' class='m'>before-paren</a> (<a id='1031' tid='1032' class='m'>1-</a> (<a id='1033' tid='1034' class='m'>point</a>))))
  647. (<a id='1035' tid='1036' class='m'>back-to-indentation</a>)
  648. (<a id='1037' tid='1038' class='m'>cond</a> ((<a id='1039' tid='1040' class='m'>not</a> (<a id='1041' tid='1042' class='m'>eq</a> (<a id='1043' tid='1044' class='m'>point</a>) <a id='1045' tid='1046' class='m'>before-paren</a>))
  649. <a id='1047' tid='1048' class='m'>;; Can&#39;t call PAREDIT-DELETE-LEADING-WHITESPACE
  650. </a> <a id='1049' tid='1050' class='m'>;; here -- we must return from SAVE-EXCURSION
  651. </a> <a id='1051' tid='1052' class='m'>;; first.
  652. </a> (<a id='1053' tid='1054' class='m'>throw</a> <a id='1055' tid='1056' class='m'>&#39;</a><a id='1057' tid='1058' class='m'>return</a> <a id='1059' tid='1060' class='m'>t</a>))
  653. ((<a id='1061' tid='1062' class='m'>save-excursion</a> (<a id='1063' tid='1064' class='m'>forward-line</a> <a id='1065' tid='1066' class='m'>-1</a>)
  654. (<a id='1067' tid='1068' class='m'>end-of-line</a>)
  655. (<a id='1069' tid='1070' class='m'>paredit-in-comment-p</a>))
  656. <span class='d'>;; Moving the closing parenthesis any further
  657. </span> <a id='1071' tid='1072' class='m'>;; would put it into a comment, so we just
  658. </a> <span class='d'>;; indent the closing parenthesis where it is
  659. </span> <span class='d'>;; and abort the loop, telling its continuation
  660. </span> <span class='d'>;; that no leading whitespace should be deleted.
  661. </span> (<a id='1073' tid='1074' class='m'>lisp-indent-line</a>)
  662. (<a id='1075' tid='1076' class='m'>throw</a> <a id='1077' tid='1078' class='m'>&#39;</a><a id='1079' tid='1080' class='m'>return</a> <a id='1081' tid='1082' class='m'>nil</a>))
  663. (<a id='1083' tid='1084' class='m'>t</a> (<a id='1085' tid='1086' class='m'>delete-indentation</a>)))))))
  664. (<a id='1087' tid='1088' class='m'>paredit-delete-leading-whitespace</a>))))
  665. (<a id='2281' tid='2282' class='u'>defun</a> <a id='2283' tid='2284' class='u'>paredit-delete-leading-whitespace</a> ()
  666. <span class='d'>;; This assumes that we&#39;re on the closing parenthesis already.
  667. </span> (<a id='2285' tid='2286' class='u'>save-excursion</a>
  668. (<a id='2287' tid='2288' class='u'>backward-char</a>)
  669. (<a id='2289' tid='2290' class='u'>while</a> (<a id='2291' tid='2292' class='u'>let</a> ((<a id='2293' tid='2294' class='u'>syn</a> (<a id='2295' tid='2296' class='u'>char-syntax</a> (<a id='2297' tid='2298' class='u'>char-before</a>))))
  670. (<a id='2299' tid='2300' class='u'>and</a> (<a id='2301' tid='2302' class='u'>or</a> (<a id='2303' tid='2304' class='u'>eq</a> <a id='2305' tid='2306' class='u'>syn</a> <a id='2307' tid='2308' class='u'>?\ </a>) (<a id='2309' tid='2310' class='u'>eq</a> <a id='2311' tid='2312' class='u'>syn</a> <a id='2313' tid='2314' class='u'>?-</a>)) <a id='2315' tid='2316' class='u'>; whitespace syntax
  671. </a> <a id='2317' tid='2318' class='u'>;; The above line is a perfect example of why the
  672. </a> <a id='2319' tid='2320' class='u'>;; following test is necessary.
  673. </a> (<a id='2321' tid='2322' class='u'>not</a> (<a id='2323' tid='2324' class='u'>paredit-in-char-p</a> (<a id='2325' tid='2326' class='u'>1-</a> (<a id='2327' tid='2328' class='u'>point</a>))))))
  674. (<a id='2329' tid='2330' class='u'>backward-delete-char</a> <a id='2331' tid='2332' class='u'>1</a>))))
  675. (<a id='2159' tid='2160' class='u'>defun</a> <a id='2161' tid='2162' class='u'>paredit-blink-paren-match</a> (<a id='2163' tid='2164' class='u'>another-line-p</a>)
  676. (<a id='2165' tid='2166' class='u'>if</a> (<a id='2167' tid='2168' class='u'>and</a> <a id='2169' tid='2170' class='u'>blink-matching-paren</a>
  677. (<a id='2171' tid='2172' class='u'>or</a> (<a id='2173' tid='2174' class='u'>not</a> <a id='2175' tid='2176' class='u'>show-paren-mode</a>) <a id='2177' tid='2178' class='u'>another-line-p</a>))
  678. (<a id='2179' tid='2180' class='u'>paredit-ignore-sexp-errors</a>
  679. (<a id='2181' tid='2182' class='u'>save-excursion</a>
  680. (<a id='2183' tid='2184' class='u'>backward-sexp</a>)
  681. (<a id='2185' tid='2186' class='u'>forward-sexp</a>)
  682. <a id='2187' tid='2188' class='u'>;; SHOW-PAREN-MODE inhibits any blinking, so we disable it
  683. </a> <a id='2189' tid='2190' class='u'>;; locally here.
  684. </a> (<a id='2191' tid='2192' class='u'>let</a> ((<a id='2193' tid='2194' class='u'>show-paren-mode</a> <a id='2195' tid='2196' class='u'>nil</a>))
  685. (<a id='2197' tid='2198' class='u'>blink-matching-open</a>))))))
  686. (<a id='2333' tid='2334' class='u'>defun</a> <a id='2335' tid='2336' class='u'>paredit-doublequote</a> (<a id='2337' tid='2338' class='u'>&optional</a> <a id='2339' tid='2340' class='u'>n</a>)
  687. <a id='2341' tid='2342' class='u'>&quot;Insert a pair of double-quotes.
  688. With a prefix argument N, wrap the following N S-expressions in
  689. double-quotes, escaping intermediate characters if necessary.
  690. If the region is active, `transient-mark-mode&#39; is enabled, and the
  691. region&#39;s start and end fall in the same parenthesis depth, insert a
  692. pair of double-quotes around the region, again escaping intermediate
  693. characters if necessary.
  694. Inside a comment, insert a literal double-quote.
  695. At the end of a string, move past the closing double-quote.
  696. In the middle of a string, insert a backslash-escaped double-quote.
  697. If in a character literal, do nothing. This prevents accidentally
  698. changing a what was in the character literal to become a meaningful
  699. delimiter unintentionally.&quot;</a>
  700. (<a id='2343' tid='2344' class='u'>interactive</a> <a id='2345' tid='2346' class='u'>&quot;P&quot;</a>)
  701. (<a id='2347' tid='2348' class='u'>cond</a> ((<a id='2349' tid='2350' class='u'>paredit-in-string-p</a>)
  702. (<a id='2351' tid='2352' class='u'>if</a> (<a id='2353' tid='2354' class='u'>eq</a> (<a id='2355' tid='2356' class='u'>cdr</a> (<a id='2357' tid='2358' class='u'>paredit-string-start+end-points</a>))
  703. (<a id='2359' tid='2360' class='u'>point</a>))
  704. (<a id='2361' tid='2362' class='u'>forward-char</a>) <a id='2363' tid='2364' class='u'>; We&#39;re on the closing quote.
  705. </a> (<a id='2365' tid='2366' class='u'>insert</a> <a id='2367' tid='2368' class='u'>?\\</a> <a id='2369' tid='2370' class='u'>?\&quot;</a> )))
  706. ((<a id='2371' tid='2372' class='u'>paredit-in-comment-p</a>)
  707. (<a id='2373' tid='2374' class='u'>insert</a> <a id='2375' tid='2376' class='u'>?\&quot;</a> ))
  708. ((<a id='2377' tid='2378' class='u'>not</a> (<a id='2379' tid='2380' class='u'>paredit-in-char-p</a>))
  709. (<a id='2381' tid='2382' class='u'>paredit-insert-pair</a> <a id='2383' tid='2384' class='u'>n</a> <a id='2385' tid='2386' class='u'>?\&quot;</a> <a id='2387' tid='2388' class='u'>?\&quot;</a> <a id='2389' tid='2390' class='u'>&#39;</a><a id='2391' tid='2392' class='u'>paredit-forward-for-quote</a>))))
  710. (<a id='4063' tid='4064' class='u'>defun</a> <a id='4065' tid='4066' class='u'>paredit-meta-doublequote</a> (<a id='4067' tid='4068' class='u'>&optional</a> <a id='4069' tid='4070' class='u'>n</a>)
  711. <a id='4071' tid='4072' class='u'>&quot;Move to the end of the string, insert a newline, and indent.
  712. If not in a string, act as `paredit-doublequote&#39;; if no prefix argument
  713. is specified and the region is not active or `transient-mark-mode&#39; is
  714. disabled, the default is to wrap one S-expression, however, not
  715. zero.&quot;</a>
  716. (<a id='4073' tid='4074' class='u'>interactive</a> <a id='4075' tid='4076' class='u'>&quot;P&quot;</a>)
  717. (<a id='4077' tid='4078' class='u'>if</a> (<a id='4079' tid='4080' class='u'>not</a> (<a id='4081' tid='4082' class='u'>paredit-in-string-p</a>))
  718. (<a id='4083' tid='4084' class='u'>paredit-doublequote</a> (<a id='4085' tid='4086' class='u'>or</a> <a id='4087' tid='4088' class='u'>n</a>
  719. (<a id='4089' tid='4090' class='u'>and</a> (<a id='4091' tid='4092' class='u'>not</a> (<a id='4093' tid='4094' class='u'>paredit-region-active-p</a>))
  720. <a id='4095' tid='4096' class='u'>1</a>)))
  721. (<a id='4097' tid='4098' class='u'>let</a> ((<a id='4099' tid='4100' class='u'>start+end</a> (<a id='4101' tid='4102' class='u'>paredit-string-start+end-points</a>)))
  722. (<a id='4103' tid='4104' class='u'>goto-char</a> (<a id='4105' tid='4106' class='u'>1+</a> (<a id='4107' tid='4108' class='u'>cdr</a> <a id='4109' tid='4110' class='u'>start+end</a>)))
  723. (<a id='4111' tid='4112' class='u'>newline</a>)
  724. (<a id='4113' tid='4114' class='u'>lisp-indent-line</a>)
  725. (<a id='4115' tid='4116' class='u'>paredit-ignore-sexp-errors</a> (<a id='4117' tid='4118' class='u'>indent-sexp</a>)))))
  726. (<a id='2615' tid='2616' class='u'>defun</a> <a id='2617' tid='2618' class='u'>paredit-forward-for-quote</a> (<a id='2619' tid='2620' class='u'>end</a>)
  727. (<a id='2621' tid='2622' class='u'>let</a> ((<a id='2623' tid='2624' class='u'>state</a> (<a id='2625' tid='2626' class='u'>paredit-current-parse-state</a>)))
  728. (<a id='2627' tid='2628' class='u'>while</a> (<a id='2629' tid='2630' class='u'>&lt;</a> (<a id='2631' tid='2632' class='u'>point</a>) <a id='2633' tid='2634' class='u'>end</a>)
  729. (<a id='2635' tid='2636' class='u'>let</a> ((<a id='2637' tid='2638' class='u'>new-state</a> (<a id='2639' tid='2640' class='u'>parse-partial-sexp</a> (<a id='2641' tid='2642' class='u'>point</a>) (<a id='2643' tid='2644' class='u'>1+</a> (<a id='2645' tid='2646' class='u'>point</a>))
  730. <a id='2647' tid='2648' class='u'>nil</a> <a id='2649' tid='2650' class='u'>nil</a> <a id='2651' tid='2652' class='u'>state</a>)))
  731. (<a id='2653' tid='2654' class='u'>if</a> (<a id='2655' tid='2656' class='u'>paredit-in-string-p</a> <a id='2657' tid='2658' class='u'>new-state</a>)
  732. (<a id='2659' tid='2660' class='u'>if</a> (<a id='2661' tid='2662' class='u'>not</a> (<a id='2663' tid='2664' class='u'>paredit-in-string-escape-p</a>))
  733. (<a id='2665' tid='2666' class='u'>setq</a> <a id='2667' tid='2668' class='u'>state</a> <a id='2669' tid='2670' class='u'>new-state</a>)
  734. <a id='2671' tid='2672' class='u'>;; Escape character: turn it into an escaped escape
  735. </a> <a id='2673' tid='2674' class='u'>;; character by appending another backslash.
  736. </a> (<a id='2675' tid='2676' class='u'>insert</a> <a id='2677' tid='2678' class='u'>?\\</a> )
  737. <a id='2679' tid='2680' class='u'>;; Now the point is after both escapes, and we want to
  738. </a> <a id='2681' tid='2682' class='u'>;; rescan from before the first one to after the second
  739. </a> <a id='2683' tid='2684' class='u'>;; one.
  740. </a> (<a id='2685' tid='2686' class='u'>setq</a> <a id='2687' tid='2688' class='u'>state</a>
  741. (<a id='2689' tid='2690' class='u'>parse-partial-sexp</a> (<a id='2691' tid='2692' class='u'>-</a> (<a id='2693' tid='2694' class='u'>point</a>) <a id='2695' tid='2696' class='u'>2</a>) (<a id='2697' tid='2698' class='u'>point</a>)
  742. <a id='2699' tid='2700' class='u'>nil</a> <a id='2701' tid='2702' class='u'>nil</a> <a id='2703' tid='2704' class='u'>state</a>))
  743. <a id='2705' tid='2706' class='u'>;; Advance the end point, since we just inserted a new
  744. </a> <a id='2707' tid='2708' class='u'>;; character.
  745. </a> (<a id='2709' tid='2710' class='u'>setq</a> <a id='2711' tid='2712' class='u'>end</a> (<a id='2713' tid='2714' class='u'>1+</a> <a id='2715' tid='2716' class='u'>end</a>)))
  746. <a id='2717' tid='2718' class='u'>;; String: escape by inserting a backslash before the quote.
  747. </a> (<a id='2719' tid='2720' class='u'>backward-char</a>)
  748. (<a id='2721' tid='2722' class='u'>insert</a> <a id='2723' tid='2724' class='u'>?\\</a> )
  749. <a id='2725' tid='2726' class='u'>;; The point is now between the escape and the quote, and we
  750. </a> <a id='2727' tid='2728' class='u'>;; want to rescan from before the escape to after the quote.
  751. </a> (<a id='2729' tid='2730' class='u'>setq</a> <a id='2731' tid='2732' class='u'>state</a>
  752. (<a id='2733' tid='2734' class='u'>parse-partial-sexp</a> (<a id='2735' tid='2736' class='u'>1-</a> (<a id='2737' tid='2738' class='u'>point</a>)) (<a id='2739' tid='2740' class='u'>1+</a> (<a id='2741' tid='2742' class='u'>point</a>))
  753. <a id='2743' tid='2744' class='u'>nil</a> <a id='2745' tid='2746' class='u'>nil</a> <a id='2747' tid='2748' class='u'>state</a>))
  754. <a id='2749' tid='2750' class='u'>;; Advance the end point for the same reason as above.
  755. </a> (<a id='2751' tid='2752' class='u'>setq</a> <a id='2753' tid='2754' class='u'>end</a> (<a id='2755' tid='2756' class='u'>1+</a> <a id='2757' tid='2758' class='u'>end</a>)))))))
  756. <span class='d'>;;;; Escape Insertion
  757. </span>
  758. (<a id='1733' tid='1734' class='u'>defun</a> <a id='1735' tid='1736' class='u'>paredit-backslash</a> ()
  759. <a id='1737' tid='1738' class='u'>&quot;Insert a backslash followed by a character to escape.&quot;</a>
  760. (<a id='1739' tid='1740' class='u'>interactive</a>)
  761. (<a id='1741' tid='1742' class='u'>insert</a> <a id='1743' tid='1744' class='u'>?\\</a> )
  762. <a id='1745' tid='1746' class='u'>;; This funny conditional is necessary because PAREDIT-IN-COMMENT-P
  763. </a> <a id='1747' tid='1748' class='u'>;; assumes that PAREDIT-IN-STRING-P already returned false; otherwise
  764. </a> <a id='1749' tid='1750' class='u'>;; it may give erroneous answers.
  765. </a> (<a id='1751' tid='1752' class='u'>if</a> (<a id='1753' tid='1754' class='u'>or</a> (<a id='1755' tid='1756' class='u'>paredit-in-string-p</a>)
  766. (<a id='1757' tid='1758' class='u'>not</a> (<a id='1759' tid='1760' class='u'>paredit-in-comment-p</a>)))
  767. (<a id='1761' tid='1762' class='u'>let</a> ((<a id='1763' tid='1764' class='u'>delp</a> <a id='1765' tid='1766' class='u'>t</a>))
  768. (<a id='1767' tid='1768' class='u'>unwind-protect</a> (<a id='1769' tid='1770' class='u'>setq</a> <a id='1771' tid='1772' class='u'>delp</a>
  769. (<a id='1773' tid='1774' class='u'>call-interactively</a> <a id='1775' tid='1776' class='u'>&#39;</a><a id='1777' tid='1778' class='u'>paredit-escape</a>))
  770. <a id='1779' tid='1780' class='u'>;; We need this in an UNWIND-PROTECT so that the backlash is
  771. </a> <a id='1781' tid='1782' class='u'>;; left in there *only* if PAREDIT-ESCAPE return NIL normally
  772. </a> <a id='1783' tid='1784' class='u'>;; -- in any other case, such as the user hitting C-g or an
  773. </a> <a id='1785' tid='1786' class='u'>;; error occurring, we must delete the backslash to avoid
  774. </a> <a id='1787' tid='1788' class='u'>;; leaving a dangling escape. (This control structure is a
  775. </a> <a id='1789' tid='1790' class='u'>;; crock.)
  776. </a> (<a id='1791' tid='1792' class='u'>if</a> <a id='1793' tid='1794' class='u'>delp</a> (<a id='1795' tid='1796' class='u'>backward-delete-char</a> <a id='1797' tid='1798' class='u'>1</a>))))))
  777. <span class='d'>;;; This auxiliary interactive function returns true if the backslash
  778. </span><span class='d'>;;; should be deleted and false if not.
  779. </span>
  780. (<a id='2393' tid='2394' class='u'>defun</a> <a id='2395' tid='2396' class='u'>paredit-escape</a> (<a id='2397' tid='2398' class='u'>char</a>)
  781. <a id='2399' tid='2400' class='u'>;; I&#39;m too lazy to figure out how to do this without a separate
  782. </a> <a id='2401' tid='2402' class='u'>;; interactive function.
  783. </a> (<a id='2403' tid='2404' class='u'>interactive</a> <a id='2405' tid='2406' class='u'>&quot;cEscaping character...&quot;</a>)
  784. (<a id='2407' tid='2408' class='u'>if</a> (<a id='2409' tid='2410' class='u'>eq</a> <a id='2411' tid='2412' class='u'>char</a> <a id='2413' tid='2414' class='u'>127</a>) <a id='2415' tid='2416' class='u'>; The backslash was a typo, so
  785. </a> <a id='2417' tid='2418' class='u'>t</a> <a id='2419' tid='2420' class='u'>; the luser wants to delete it.
  786. </a> (<a id='2421' tid='2422' class='u'>insert</a> <a id='2423' tid='2424' class='u'>char</a>) <a id='2425' tid='2426' class='u'>; (Is there a better way to
  787. </a> <a id='2427' tid='2428' class='u'>nil</a>)) <span class='d'>; express the rubout char?
  788. </span> <span class='d'>; ?\^? works, but ugh...)
  789. </span>
  790. <span class='d'>;;; The placement of this function in this file is totally random.
  791. </span>
  792. (<a id='4213' tid='4214' class='u'>defun</a> <a id='4215' tid='4216' class='u'>paredit-newline</a> ()
  793. <span class='d'>&quot;Insert a newline and indent it.
  794. This is like `newline-and-indent&#39;, but it not only indents the line
  795. that the point is on but also the S-expression following the point,
  796. if there is one.
  797. Move forward one character first if on an escaped character.
  798. If in a string, just insert a literal newline.&quot;</span>
  799. (<a id='4217' tid='4218' class='u'>interactive</a>)
  800. <span class='d'>(if (paredit-in-string-p)
  801. (newline)
  802. (if (and (not (paredit-in-comment-p)) (paredit-in-char-p))
  803. (forward-char))
  804. (newline-and-indent)
  805. ;; Indent the following S-expression, but don&#39;t signal an error if
  806. ;; there&#39;s only a closing parenthesis after the point.
  807. (paredit-ignore-sexp-errors (indent-sexp)))</span>)
  808. <span class='d'>;;;; Comment Insertion
  809. </span>
  810. (<a id='4437' tid='4438' class='u'>defun</a> <a id='4439' tid='4440' class='u'>paredit-semicolon</a> (<a id='4441' tid='4442' class='u'>&optional</a> <a id='4443' tid='4444' class='u'>n</a>)
  811. <span class='d'>&quot;Insert a semicolon, moving any code after the point to a new line.
  812. If in a string, comment, or character literal, insert just a literal
  813. semicolon, and do not move anything to the next line.
  814. With a prefix argument N, insert N semicolons.&quot;</span>
  815. <span class='d'>(interactive &quot;P&quot;)</span>
  816. (<span class='d'>if</span> (<span class='d'>not</span> (<span class='d'>or</span> <span class='d'>(paredit-in-string-p)</span>
  817. <span class='d'>(paredit-in-comment-p)</span>
  818. <span class='d'>(paredit-in-char-p)</span>
  819. <span class='d'>;; No more code on the line after the point.
  820. </span> (<a id='243' tid='244' class='m'>save-excursion</a>
  821. (<a id='245' tid='246' class='m'>paredit-skip-whitespace</a> <a id='247' tid='248' class='m'>t</a> (<a id='249' tid='250' class='m'>point-at-eol</a>))
  822. (<a id='251' tid='252' class='m'>or</a> (<a id='253' tid='254' class='m'>eolp</a>)
  823. <span class='d'>;; Let the user prefix semicolons to existing
  824. </span> <span class='d'>;; comments.
  825. </span> (<a id='255' tid='256' class='m'>eq</a> (<a id='257' tid='258' class='m'>char-after</a>) <a id='259' tid='260' class='m'>?\;</a>)))))
  826. <span class='d'>;; Don&#39;t use NEWLINE-AND-INDENT, because that will delete all of
  827. </span> <span class='d'>;; the horizontal whitespace first, but we just want to move the
  828. </span> <span class='d'>;; code following the point onto the next line while preserving
  829. </span> <span class='d'>;; the point on this line.
  830. </span> <span class='d'>;++ Why indent only the line?
  831. </span> <span class='d'>(save-excursion (newline) (lisp-indent-line))</span>)
  832. <span class='d'>(insert (make-string (if n (prefix-numeric-value n) 1)
  833. ?\; ))</span>)
  834. (<a id='2207' tid='2208' class='u'>defun</a> <a id='2209' tid='2210' class='u'>paredit-comment-dwim</a> <span class='d'>(&optional arg)</span>
  835. <a id='2211' tid='2212' class='u'>&quot;Call the Lisp comment command you want (Do What I Mean).
  836. This is like `comment-dwim&#39;, but it is specialized for Lisp editing.
  837. If transient mark mode is enabled and the mark is active, comment or
  838. uncomment the selected region, depending on whether it was entirely
  839. commented not not already.
  840. If there is already a comment on the current line, with no prefix
  841. argument, indent to that comment; with a prefix argument, kill that
  842. comment.
  843. Otherwise, insert a comment appropriate for the context and ensure that
  844. any code following the comment is moved to the next line.
  845. At the top level, where indentation is calculated to be at column 0,
  846. insert a triple-semicolon comment; within code, where the indentation
  847. is calculated to be non-zero, and on the line there is either no code
  848. at all or code after the point, insert a double-semicolon comment;
  849. and if the point is after all code on the line, insert a single-
  850. semicolon margin comment at `comment-column&#39;.&quot;</a>
  851. (<a id='2213' tid='2214' class='u'>interactive</a> <a id='2215' tid='2216' class='u'>&quot;*P&quot;</a>)
  852. <span class='d'>(require &#39;newcomment)</span>
  853. <span class='d'>(comment-normalize-vars)</span>
  854. <span class='d'>(cond ((paredit-region-active-p)
  855. (comment-or-uncomment-region (region-beginning)
  856. (region-end)
  857. arg))
  858. ((paredit-comment-on-line-p)
  859. (if arg
  860. (comment-kill (if (integerp arg) arg nil))
  861. (comment-indent)))
  862. (t (paredit-insert-comment)))</span>)
  863. (<a id='2217' tid='2218' class='u'>defun</a> <a id='2219' tid='2220' class='u'>paredit-comment-on-line-p</a> ()
  864. (<a id='1089' tid='1090' class='m'>save-excursion</a>
  865. (<a id='1091' tid='1092' class='m'>beginning-of-line</a>)
  866. (<a id='1093' tid='1094' class='m'>let</a> ((<a id='1095' tid='1096' class='m'>comment-p</a> <a id='1097' tid='1098' class='m'>nil</a>))
  867. <a id='1099' tid='1100' class='m'>;; Search forward for a comment beginning. If there is one, set
  868. </a> <a id='1101' tid='1102' class='m'>;; COMMENT-P to true; if not, it will be nil.
  869. </a> (<a id='1103' tid='1104' class='m'>while</a> (<span class='d'>progn</span> <span class='d'>(setq comment-p
  870. (search-forward &quot;;&quot; (point-at-eol)
  871. ;; t -&gt; no error
  872. t))</span>
  873. (<a id='1105' tid='1106' class='m'>and</a> <a id='1107' tid='1108' class='m'>comment-p</a>
  874. (<a id='1109' tid='1110' class='m'>or</a> (<a id='1111' tid='1112' class='m'>paredit-in-string-p</a>)
  875. (<a id='1113' tid='1114' class='m'>paredit-in-char-p</a> (<a id='1115' tid='1116' class='m'>1-</a> (<a id='1117' tid='1118' class='m'>point</a>))))))
  876. (<a id='1119' tid='1120' class='m'>forward-char</a>))
  877. <a id='1121' tid='1122' class='m'>comment-p</a>)))
  878. (<a id='3321' tid='3322' class='u'>defun</a> <a id='3323' tid='3324' class='u'>paredit-insert-comment</a> ()
  879. (<a id='1123' tid='1124' class='m'>let</a> ((<a id='1125' tid='1126' class='m'>code-after-p</a>
  880. (<a id='1127' tid='1128' class='m'>save-excursion</a> (<a id='1129' tid='1130' class='m'>paredit-skip-whitespace</a> <a id='1131' tid='1132' class='m'>t</a> (<a id='1133' tid='1134' class='m'>point-at-eol</a>))
  881. (<a id='1135' tid='1136' class='m'>not</a> (<a id='1137' tid='1138' class='m'>eolp</a>))))
  882. (<a id='1139' tid='1140' class='m'>code-before-p</a>
  883. (<a id='1141' tid='1142' class='m'>save-excursion</a> (<a id='1143' tid='1144' class='m'>paredit-skip-whitespace</a> <a id='1145' tid='1146' class='m'>nil</a> (<a id='1147' tid='1148' class='m'>point-at-bol</a>))
  884. (<a id='1149' tid='1150' class='m'>not</a> (<a id='1151' tid='1152' class='m'>bolp</a>)))))
  885. (<span class='d'>if</span> (<a id='1153' tid='1154' class='m'>and</a> (<a id='1155' tid='1156' class='m'>bolp</a>)
  886. <span class='d'>;; We have to use EQ 0 here and not ZEROP because ZEROP
  887. </span> <span class='d'>;; signals an error if its argument is non-numeric, but
  888. </span> <span class='d'>;; CALCULATE-LISP-INDENT may return nil.
  889. </span> (<span class='d'>eq</span> (<a id='1157' tid='1158' class='m'>let</a> ((<a id='1159' tid='1160' class='m'>indent</a> (<a id='1161' tid='1162' class='m'>calculate-lisp-indent</a>)))
  890. (<a id='1163' tid='1164' class='m'>if</a> (<a id='1165' tid='1166' class='m'>consp</a> <a id='1167' tid='1168' class='m'>indent</a>)
  891. (<a id='1169' tid='1170' class='m'>car</a> <a id='1171' tid='1172' class='m'>indent</a>)
  892. <a id='1173' tid='1174' class='m'>indent</a>))
  893. <span class='d'>0</span>))
  894. <span class='d'>;; Top-level comment
  895. </span> <span class='d'>(progn (if code-after-p (save-excursion (newline)))
  896. (insert &quot;;;; &quot;))</span>
  897. <span class='d'>(if code-after-p
  898. ;; Code comment
  899. (progn (if code-before-p
  900. ;++ Why NEWLINE-AND-INDENT here and not just
  901. ;++ NEWLINE, or PAREDIT-NEWLINE?
  902. (newline-and-indent))
  903. (lisp-indent-line)
  904. (insert &quot;;; &quot;)
  905. ;; Move the following code. (NEWLINE-AND-INDENT will
  906. ;; delete whitespace after the comment, though, so use
  907. ;; NEWLINE & LISP-INDENT-LINE manually here.)
  908. (save-excursion (newline)
  909. (lisp-indent-line)))
  910. ;; Margin comment
  911. (progn (indent-to comment-column
  912. 1) ; 1 -&gt; force one leading space
  913. (insert ?\; )))</span>)))
  914. <span class='d'>;;;; Character Deletion
  915. </span>
  916. (<a id='2503' tid='2504' class='u'>defun</a> <a id='2505' tid='2506' class='u'>paredit-forward-delete</a> <span class='d'>(&optional arg)</span>
  917. <span class='d'>&quot;Delete a character forward or move forward over a delimiter.
  918. If on an opening S-expression delimiter, move forward into the
  919. S-expression.
  920. If on a closing S-expression delimiter, refuse to delete unless the
  921. S-expression is empty, in which case delete the whole S-expression.
  922. With a prefix argument, simply delete a character forward, without
  923. regard for delimiter balancing.&quot;</span>
  924. (<a id='2507' tid='2508' class='u'>interactive</a> <a id='2509' tid='2510' class='u'>&quot;P&quot;</a>)
  925. (<span class='d'>cond</span> <span class='d'>((or arg (eobp))
  926. (delete-char 1))</span>
  927. <span class='d'>((paredit-in-string-p)
  928. (paredit-forward-delete-in-string))</span>
  929. <span class='d'>((paredit-in-comment-p)
  930. ;++ What to do here? This could move a partial S-expression
  931. ;++ into a comment and thereby invalidate the file&#39;s form,
  932. ;++ or move random text out of a comment.
  933. (delete-char 1))</span>
  934. ((<a id='1175' tid='1176' class='m'>paredit-in-char-p</a>) <a id='1177' tid='1178' class='m'>; Escape -- delete both chars.
  935. </a> (<a id='1179' tid='1180' class='m'>backward-delete-char</a> <a id='1181' tid='1182' class='m'>1</a>)
  936. (<a id='1183' tid='1184' class='m'>delete-char</a> <a id='1185' tid='1186' class='m'>1</a>))
  937. ((<a id='551' tid='552' class='m'>eq</a> (<a id='553' tid='554' class='m'>char-after</a>) <a id='555' tid='556' class='m'>?\\</a> ) <a id='557' tid='558' class='m'>; ditto
  938. </a> (<a id='559' tid='560' class='m'>delete-char</a> <a id='561' tid='562' class='m'>2</a>))
  939. ((<a id='451' tid='452' class='m'>let</a> ((<a id='453' tid='454' class='m'>syn</a> (<a id='455' tid='456' class='m'>char-syntax</a> (<a id='457' tid='458' class='m'>char-after</a>))))
  940. (<a id='459' tid='460' class='m'>or</a> (<a id='461' tid='462' class='m'>eq</a> <a id='463' tid='464' class='m'>syn</a> <a id='465' tid='466' class='m'>?\(</a> )
  941. (<a id='467' tid='468' class='m'>eq</a> <a id='469' tid='470' class='m'>syn</a> <a id='471' tid='472' class='m'>?\&quot;</a> )))
  942. <span class='d'>(forward-char)</span>)
  943. ((<a id='329' tid='330' class='m'>and</a> (<a id='331' tid='332' class='m'>not</a> (<a id='333' tid='334' class='m'>paredit-in-char-p</a> (<a id='335' tid='336' class='m'>1-</a> (<a id='337' tid='338' class='m'>point</a>))))
  944. (<a id='339' tid='340' class='m'>eq</a> (<a id='341' tid='342' class='m'>char-syntax</a> (<a id='343' tid='344' class='m'>char-after</a>)) <a id='345' tid='346' class='m'>?\)</a> )
  945. (<a id='347' tid='348' class='m'>eq</a> (<a id='349' tid='350' class='m'>char-before</a>) (<a id='351' tid='352' class='m'>matching-paren</a> (<a id='353' tid='354' class='m'>char-after</a>))))
  946. (<a id='355' tid='356' class='m'>backward-delete-char</a> <a id='357' tid='358' class='m'>1</a>) <a id='359' tid='360' class='m'>; Empty list -- delete both
  947. </a> (<a id='361' tid='362' class='m'>delete-char</a> <a id='363' tid='364' class='m'>1</a>)) <span class='d'>; delimiters.
  948. </span> <span class='d'>;; Just delete a single character, if it&#39;s not a closing
  949. </span> <span class='d'>;; parenthesis. (The character literal case is already
  950. </span> <span class='d'>;; handled by now.)
  951. </span> ((<a id='277' tid='278' class='m'>not</a> (<a id='279' tid='280' class='m'>eq</a> (<a id='281' tid='282' class='m'>char-syntax</a> (<a id='283' tid='284' class='m'>char-after</a>)) <a id='285' tid='286' class='m'>?\)</a> ))
  952. (<a id='287' tid='288' class='m'>delete-char</a> <a id='289' tid='290' class='m'>1</a>))))
  953. (<a id='2511' tid='2512' class='u'>defun</a> <a id='2513' tid='2514' class='u'>paredit-forward-delete-in-string</a> ()
  954. (<a id='2515' tid='2516' class='u'>let</a> ((<a id='2517' tid='2518' class='u'>start+end</a> (<a id='2519' tid='2520' class='u'>paredit-string-start+end-points</a>)))
  955. (<a id='2521' tid='2522' class='u'>cond</a> ((<a id='2523' tid='2524' class='u'>not</a> (<a id='2525' tid='2526' class='u'>eq</a> (<a id='2527' tid='2528' class='u'>point</a>) (<a id='2529' tid='2530' class='u'>cdr</a> <a id='2531' tid='2532' class='u'>start+end</a>)))
  956. <a id='2533' tid='2534' class='u'>;; If it&#39;s not the close-quote, it&#39;s safe to delete. But
  957. </a> <a id='2535' tid='2536' class='u'>;; first handle the case that we&#39;re in a string escape.
  958. </a> (<a id='2537' tid='2538' class='u'>cond</a> ((<a id='2539' tid='2540' class='u'>paredit-in-string-escape-p</a>)
  959. <a id='2541' tid='2542' class='u'>;; We&#39;re right after the backslash, so backward
  960. </a> <a id='2543' tid='2544' class='u'>;; delete it before deleting the escaped character.
  961. </a> (<a id='2545' tid='2546' class='u'>backward-delete-char</a> <a id='2547' tid='2548' class='u'>1</a>))
  962. ((<a id='2549' tid='2550' class='u'>eq</a> (<a id='2551' tid='2552' class='u'>char-after</a>) <a id='2553' tid='2554' class='u'>?\\</a> )
  963. <a id='2555' tid='2556' class='u'>;; If we&#39;re not in a string escape, but we are on a
  964. </a> <a id='2557' tid='2558' class='u'>;; backslash, it must start the escape for the next
  965. </a> <a id='2559' tid='2560' class='u'>;; character, so delete the backslash before deleting
  966. </a> <a id='2561' tid='2562' class='u'>;; the next character.
  967. </a> (<a id='2563' tid='2564' class='u'>delete-char</a> <a id='2565' tid='2566' class='u'>1</a>)))
  968. (<a id='2567' tid='2568' class='u'>delete-char</a> <a id='2569' tid='2570' class='u'>1</a>))
  969. ((<a id='2571' tid='2572' class='u'>eq</a> (<a id='2573' tid='2574' class='u'>1-</a> (<a id='2575' tid='2576' class='u'>point</a>)) (<a id='2577' tid='2578' class='u'>car</a> <a id='2579' tid='2580' class='u'>start+end</a>))
  970. <a id='2581' tid='2582' class='u'>;; If it is the close-quote, delete only if we&#39;re also right
  971. </a> <a id='2583' tid='2584' class='u'>;; past the open-quote (i.e. it&#39;s empty), and then delete
  972. </a> <a id='2585' tid='2586' class='u'>;; both quotes. Otherwise we refuse to delete it.
  973. </a> (<a id='2587' tid='2588' class='u'>backward-delete-char</a> <a id='2589' tid='2590' class='u'>1</a>)
  974. (<a id='2591' tid='2592' class='u'>delete-char</a> <a id='2593' tid='2594' class='u'>1</a>)))))
  975. (<a id='1867' tid='1868' class='u'>defun</a> <a id='1869' tid='1870' class='u'>paredit-backward-delete</a> <span class='d'>(&optional arg)</span>
  976. <span class='d'>&quot;Delete a character backward or move backward over a delimiter.
  977. If on a closing S-expression delimiter, move backward into the
  978. S-expression.
  979. If on an opening S-expression delimiter, refuse to delete unless the
  980. S-expression is empty, in which case delete the whole S-expression.
  981. With a prefix argument, simply delete a character backward, without
  982. regard for delimiter balancing.&quot;</span>
  983. (<a id='1871' tid='1872' class='u'>interactive</a> <a id='1873' tid='1874' class='u'>&quot;P&quot;</a>)
  984. (<span class='d'>cond</span> <span class='d'>((or arg (bobp))
  985. (backward-delete-char 1))</span> <span class='d'>;++ should this untabify?
  986. </span> <span class='d'>((paredit-in-string-p)
  987. (paredit-backward-delete-in-string))</span>
  988. <span class='d'>((paredit-in-comment-p)
  989. (backward-delete-char 1))</span>
  990. ((<a id='1187' tid='1188' class='m'>paredit-in-char-p</a>) <a id='1189' tid='1190' class='m'>; Escape -- delete both chars.
  991. </a> (<a id='1191' tid='1192' class='m'>backward-delete-char</a> <a id='1193' tid='1194' class='m'>1</a>)
  992. (<a id='1195' tid='1196' class='m'>delete-char</a> <a id='1197' tid='1198' class='m'>1</a>))
  993. ((<a id='563' tid='564' class='m'>paredit-in-char-p</a> (<a id='565' tid='566' class='m'>1-</a> (<a id='567' tid='568' class='m'>point</a>)))
  994. (<a id='569' tid='570' class='m'>backward-delete-char</a> <a id='571' tid='572' class='m'>2</a>)) <span class='d'>; ditto
  995. </span> ((<a id='473' tid='474' class='m'>let</a> ((<a id='475' tid='476' class='m'>syn</a> (<a id='477' tid='478' class='m'>char-syntax</a> (<a id='479' tid='480' class='m'>char-before</a>))))
  996. (<a id='481' tid='482' class='m'>or</a> (<a id='483' tid='484' class='m'>eq</a> <a id='485' tid='486' class='m'>syn</a> <a id='487' tid='488' class='m'>?\)</a> )
  997. (<a id='489' tid='490' class='m'>eq</a> <a id='491' tid='492' class='m'>syn</a> <a id='493' tid='494' class='m'>?\&quot;</a> )))
  998. <span class='d'>(backward-char)</span>)
  999. ((<a id='365' tid='366' class='m'>and</a> (<a id='367' tid='368' class='m'>eq</a> (<a id='369' tid='370' class='m'>char-syntax</a> (<a id='371' tid='372' class='m'>char-before</a>)) <a id='373' tid='374' class='m'>?\(</a> )
  1000. (<a id='375' tid='376' class='m'>eq</a> (<a id='377' tid='378' class='m'>char-after</a>) (<a id='379' tid='380' class='m'>matching-paren</a> (<a id='381' tid='382' class='m'>char-before</a>))))
  1001. (<a id='383' tid='384' class='m'>backward-delete-char</a> <a id='385' tid='386' class='m'>1</a>) <a id='387' tid='388' class='m'>; Empty list -- delete both
  1002. </a> (<a id='389' tid='390' class='m'>delete-char</a> <a id='391' tid='392' class='m'>1</a>)) <span class='d'>; delimiters.
  1003. </span> <span class='d'>;; Delete it, unless it&#39;s an opening parenthesis. The case
  1004. </span> <span class='d'>;; of character literals is already handled by now.
  1005. </span> ((<a id='291' tid='292' class='m'>not</a> (<a id='293' tid='294' class='m'>eq</a> (<a id='295' tid='296' class='m'>char-syntax</a> (<a id='297' tid='298' class='m'>char-before</a>)) <a id='299' tid='300' class='m'>?\(</a> ))
  1006. (<a id='301' tid='302' class='m'>backward-delete-char-untabify</a> <a id='303' tid='304' class='m'>1</a>))))
  1007. (<a id='1875' tid='1876' class='u'>defun</a> <a id='1877' tid='1878' class='u'>paredit-backward-delete-in-string</a> ()
  1008. (<a id='1879' tid='1880' class='u'>let</a> ((<a id='1881' tid='1882' class='u'>start+end</a> (<a id='1883' tid='1884' class='u'>paredit-string-start+end-points</a>)))
  1009. (<a id='1885' tid='1886' class='u'>cond</a> ((<a id='1887' tid='1888' class='u'>not</a> (<a id='1889' tid='1890' class='u'>eq</a> (<a id='1891' tid='1892' class='u'>1-</a> (<a id='1893' tid='1894' class='u'>point</a>)) (<a id='1895' tid='1896' class='u'>car</a> <a id='1897' tid='1898' class='u'>start+end</a>)))
  1010. <a id='1899' tid='1900' class='u'>;; If it&#39;s not the open-quote, it&#39;s safe to delete.
  1011. </a> (<a id='1901' tid='1902' class='u'>if</a> (<a id='1903' tid='1904' class='u'>paredit-in-string-escape-p</a>)
  1012. <a id='1905' tid='1906' class='u'>;; If we&#39;re on a string escape, since we&#39;re about to
  1013. </a> <a id='1907' tid='1908' class='u'>;; delete the backslash, we must first delete the
  1014. </a> <a id='1909' tid='1910' class='u'>;; escaped char.
  1015. </a> (<a id='1911' tid='1912' class='u'>delete-char</a> <a id='1913' tid='1914' class='u'>1</a>))
  1016. (<a id='1915' tid='1916' class='u'>backward-delete-char</a> <a id='1917' tid='1918' class='u'>1</a>)
  1017. (<a id='1919' tid='1920' class='u'>if</a> (<a id='1921' tid='1922' class='u'>paredit-in-string-escape-p</a>)
  1018. <a id='1923' tid='1924' class='u'>;; If, after deleting a character, we find ourselves in
  1019. </a> <a id='1925' tid='1926' class='u'>;; a string escape, we must have deleted the escaped
  1020. </a> <a id='1927' tid='1928' class='u'>;; character, and the backslash is behind the point, so
  1021. </a> <a id='1929' tid='1930' class='u'>;; backward delete it.
  1022. </a> (<a id='1931' tid='1932' class='u'>backward-delete-char</a> <a id='1933' tid='1934' class='u'>1</a>)))
  1023. ((<a id='1935' tid='1936' class='u'>eq</a> (<a id='1937' tid='1938' class='u'>point</a>) (<a id='1939' tid='1940' class='u'>cdr</a> <a id='1941' tid='1942' class='u'>start+end</a>))
  1024. <a id='1943' tid='1944' class='u'>;; If it is the open-quote, delete only if we&#39;re also right
  1025. </a> <a id='1945' tid='1946' class='u'>;; past the close-quote (i.e. it&#39;s empty), and then delete
  1026. </a> <a id='1947' tid='1948' class='u'>;; both quotes. Otherwise we refuse to delete it.
  1027. </a> (<a id='1949' tid='1950' class='u'>backward-delete-char</a> <a id='1951' tid='1952' class='u'>1</a>)
  1028. (<a id='1953' tid='1954' class='u'>delete-char</a> <a id='1955' tid='1956' class='u'>1</a>)))))
  1029. <span class='d'>;;;; Killing
  1030. </span>
  1031. (<a id='3657' tid='3658' class='u'>defun</a> <a id='3659' tid='3660' class='u'>paredit-kill</a> <span class='d'>(&optional arg)</span>
  1032. <span class='d'>&quot;Kill a line as if with `kill-line&#39;, but respecting delimiters.
  1033. In a string, act exactly as `kill-line&#39; but do not kill past the
  1034. closing string delimiter.
  1035. On a line with no S-expressions on it starting after the point or
  1036. within a comment, act exactly as `kill-line&#39;.
  1037. Otherwise, kill all S-expressions that start after the point.&quot;</span>
  1038. (<a id='3661' tid='3662' class='u'>interactive</a> <a id='3663' tid='3664' class='u'>&quot;P&quot;</a>)
  1039. <span class='d'>(cond (arg (kill-line))
  1040. ((paredit-in-string-p)
  1041. (paredit-kill-line-in-string))
  1042. ((or (paredit-in-comment-p)
  1043. (save-excursion
  1044. (paredit-skip-whitespace t (point-at-eol))
  1045. (or (eq (char-after) ?\; )
  1046. (eolp))))
  1047. ;** Be careful about trailing backslashes.
  1048. (kill-line))
  1049. (t (paredit-kill-sexps-on-line)))</span>)
  1050. (<a id='3665' tid='3666' class='u'>defun</a> <a id='3667' tid='3668' class='u'>paredit-kill-line-in-string</a> ()
  1051. (<span class='d'>if</span> (<a id='1199' tid='1200' class='m'>save-excursion</a> (<a id='1201' tid='1202' class='m'>paredit-skip-whitespace</a> <a id='1203' tid='1204' class='m'>t</a> (<a id='1205' tid='1206' class='m'>point-at-eol</a>))
  1052. (<a id='1207' tid='1208' class='m'>eolp</a>))
  1053. <span class='d'>(kill-line)</span>
  1054. <span class='d'>(save-excursion
  1055. ;; Be careful not to split an escape sequence.
  1056. (if (paredit-in-string-escape-p)
  1057. (backward-char))
  1058. (let ((beginning (point)))
  1059. (while (not (or (eolp)
  1060. (eq (char-after) ?\&quot; )))
  1061. (forward-char)
  1062. ;; Skip past escaped characters.
  1063. (if (eq (char-before) ?\\ )
  1064. (forward-char)))
  1065. (kill-region beginning (point))))</span>))
  1066. (<a id='3669' tid='3670' class='u'>defun</a> <a id='3671' tid='3672' class='u'>paredit-kill-sexps-on-line</a> ()
  1067. (<a id='3673' tid='3674' class='u'>if</a> (<a id='3675' tid='3676' class='u'>paredit-in-char-p</a>) <a id='3677' tid='3678' class='u'>; Move past the \ and prefix.
  1068. </a> (<a id='3679' tid='3680' class='u'>backward-char</a> <a id='3681' tid='3682' class='u'>2</a>)) <a id='3683' tid='3684' class='u'>; (# in Scheme/CL, ? in elisp)
  1069. </a> (<a id='3685' tid='3686' class='u'>let</a> ((<a id='3687' tid='3688' class='u'>beginning</a> (<a id='3689' tid='3690' class='u'>point</a>))
  1070. (<a id='3691' tid='3692' class='u'>eol</a> (<a id='3693' tid='3694' class='u'>point-at-eol</a>)))
  1071. (<a id='3695' tid='3696' class='u'>let</a> ((<a id='3697' tid='3698' class='u'>end-of-list-p</a> (<a id='3699' tid='3700' class='u'>paredit-forward-sexps-to-kill</a> <a id='3701' tid='3702' class='u'>beginning</a> <a id='3703' tid='3704' class='u'>eol</a>)))
  1072. <a id='3705' tid='3706' class='u'>;; If we got to the end of the list and it&#39;s on the same line,
  1073. </a> <a id='3707' tid='3708' class='u'>;; move backward past the closing delimiter before killing. (This
  1074. </a> <a id='3709' tid='3710' class='u'>;; allows something like killing the whitespace in ( ).)
  1075. </a> (<a id='3711' tid='3712' class='u'>if</a> <a id='3713' tid='3714' class='u'>end-of-list-p</a> (<a id='3715' tid='3716' class='u'>progn</a> (<a id='3717' tid='3718' class='u'>up-list</a>) (<a id='3719' tid='3720' class='u'>backward-char</a>)))
  1076. (<a id='3721' tid='3722' class='u'>if</a> <a id='3723' tid='3724' class='u'>kill-whole-line</a>
  1077. (<a id='3725' tid='3726' class='u'>paredit-kill-sexps-on-whole-line</a> <a id='3727' tid='3728' class='u'>beginning</a>)
  1078. (<a id='3729' tid='3730' class='u'>kill-region</a> <a id='3731' tid='3732' class='u'>beginning</a>
  1079. <a id='3733' tid='3734' class='u'>;; If all of the S-expressions were on one line,
  1080. </a> <a id='3735' tid='3736' class='u'>;; i.e. we&#39;re still on that line after moving past
  1081. </a> <a id='3737' tid='3738' class='u'>;; the last one, kill the whole line, including
  1082. </a> <a id='3739' tid='3740' class='u'>;; any comments; otherwise just kill to the end of
  1083. </a> <a id='3741' tid='3742' class='u'>;; the last S-expression we found. Be sure,
  1084. </a> <a id='3743' tid='3744' class='u'>;; though, not to kill any closing parentheses.
  1085. </a> (<a id='3745' tid='3746' class='u'>if</a> (<a id='3747' tid='3748' class='u'>and</a> (<a id='3749' tid='3750' class='u'>not</a> <a id='3751' tid='3752' class='u'>end-of-list-p</a>)
  1086. (<a id='3753' tid='3754' class='u'>eq</a> (<a id='3755' tid='3756' class='u'>point-at-eol</a>) <a id='3757' tid='3758' class='u'>eol</a>))
  1087. <a id='3759' tid='3760' class='u'>eol</a>
  1088. (<a id='3761' tid='3762' class='u'>point</a>)))))))
  1089. <span class='d'>;;; Please do not try to understand this code unless you have a VERY
  1090. </span><span class='d'>;;; good reason to do so. I gave up trying to figure it out well
  1091. </span><span class='d'>;;; enough to explain it, long ago.
  1092. </span>
  1093. (<a id='2889' tid='2890' class='u'>defun</a> <a id='2891' tid='2892' class='u'>paredit-forward-sexps-to-kill</a> (<a id='2893' tid='2894' class='u'>beginning</a> <a id='2895' tid='2896' class='u'>eol</a>)
  1094. (<a id='2897' tid='2898' class='u'>let</a> ((<a id='2899' tid='2900' class='u'>end-of-list-p</a> <a id='2901' tid='2902' class='u'>nil</a>)
  1095. (<a id='2903' tid='2904' class='u'>firstp</a> <a id='2905' tid='2906' class='u'>t</a>))
  1096. <a id='2907' tid='2908' class='u'>;; Move to the end of the last S-expression that started on this
  1097. </a> <a id='2909' tid='2910' class='u'>;; line, or to the closing delimiter if the last S-expression in
  1098. </a> <a id='2911' tid='2912' class='u'>;; this list is on the line.
  1099. </a> (<a id='2913' tid='2914' class='u'>catch</a> <a id='2915' tid='2916' class='u'>&#39;</a><a id='2917' tid='2918' class='u'>return</a>
  1100. (<a id='2919' tid='2920' class='u'>while</a> <a id='2921' tid='2922' class='u'>t</a>
  1101. <a id='2923' tid='2924' class='u'>;; This and the `kill-whole-line&#39; business below fix a bug that
  1102. </a> <a id='2925' tid='2926' class='u'>;; inhibited any S-expression at the very end of the buffer
  1103. </a> <a id='2927' tid='2928' class='u'>;; (with no trailing newline) from being deleted. It&#39;s a
  1104. </a> <a id='2929' tid='2930' class='u'>;; bizarre fix that I ought to document at some point, but I am
  1105. </a> <a id='2931' tid='2932' class='u'>;; too busy at the moment to do so.
  1106. </a> (<a id='2933' tid='2934' class='u'>if</a> (<a id='2935' tid='2936' class='u'>and</a> <a id='2937' tid='2938' class='u'>kill-whole-line</a> (<a id='2939' tid='2940' class='u'>eobp</a>)) (<a id='2941' tid='2942' class='u'>throw</a> <a id='2943' tid='2944' class='u'>&#39;</a><a id='2945' tid='2946' class='u'>return</a> <a id='2947' tid='2948' class='u'>nil</a>))
  1107. (<a id='2949' tid='2950' class='u'>save-excursion</a>
  1108. (<a id='2951' tid='2952' class='u'>paredit-handle-sexp-errors</a> (<a id='2953' tid='2954' class='u'>forward-sexp</a>)
  1109. (<a id='2955' tid='2956' class='u'>up-list</a>)
  1110. (<a id='2957' tid='2958' class='u'>setq</a> <a id='2959' tid='2960' class='u'>end-of-list-p</a> (<a id='2961' tid='2962' class='u'>eq</a> (<a id='2963' tid='2964' class='u'>point-at-eol</a>) <a id='2965' tid='2966' class='u'>eol</a>))
  1111. (<a id='2967' tid='2968' class='u'>throw</a> <a id='2969' tid='2970' class='u'>&#39;</a><a id='2971' tid='2972' class='u'>return</a> <a id='2973' tid='2974' class='u'>nil</a>))
  1112. (<a id='2975' tid='2976' class='u'>if</a> (<a id='2977' tid='2978' class='u'>or</a> (<a id='2979' tid='2980' class='u'>and</a> (<a id='2981' tid='2982' class='u'>not</a> <a id='2983' tid='2984' class='u'>firstp</a>)
  1113. (<a id='2985' tid='2986' class='u'>not</a> <a id='2987' tid='2988' class='u'>kill-whole-line</a>)
  1114. (<a id='2989' tid='2990' class='u'>eobp</a>))
  1115. (<a id='2991' tid='2992' class='u'>paredit-handle-sexp-errors</a>
  1116. (<a id='2993' tid='2994' class='u'>progn</a> (<a id='2995' tid='2996' class='u'>backward-sexp</a>) <a id='2997' tid='2998' class='u'>nil</a>)
  1117. <a id='2999' tid='3000' class='u'>t</a>)
  1118. (<a id='3001' tid='3002' class='u'>not</a> (<a id='3003' tid='3004' class='u'>eq</a> (<a id='3005' tid='3006' class='u'>point-at-eol</a>) <a id='3007' tid='3008' class='u'>eol</a>)))
  1119. (<a id='3009' tid='3010' class='u'>throw</a> <a id='3011' tid='3012' class='u'>&#39;</a><a id='3013' tid='3014' class='u'>return</a> <a id='3015' tid='3016' class='u'>nil</a>)))
  1120. (<a id='3017' tid='3018' class='u'>forward-sexp</a>)
  1121. (<a id='3019' tid='3020' class='u'>if</a> (<a id='3021' tid='3022' class='u'>and</a> <a id='3023' tid='3024' class='u'>firstp</a>
  1122. (<a id='3025' tid='3026' class='u'>not</a> <a id='3027' tid='3028' class='u'>kill-whole-line</a>)
  1123. (<a id='3029' tid='3030' class='u'>eobp</a>))
  1124. (<a id='3031' tid='3032' class='u'>throw</a> <a id='3033' tid='3034' class='u'>&#39;</a><a id='3035' tid='3036' class='u'>return</a> <a id='3037' tid='3038' class='u'>nil</a>))
  1125. (<a id='3039' tid='3040' class='u'>setq</a> <a id='3041' tid='3042' class='u'>firstp</a> <a id='3043' tid='3044' class='u'>nil</a>)))
  1126. <a id='3045' tid='3046' class='u'>end-of-list-p</a>))
  1127. (<a id='3763' tid='3764' class='u'>defun</a> <a id='3765' tid='3766' class='u'>paredit-kill-sexps-on-whole-line</a> (<a id='3767' tid='3768' class='u'>beginning</a>)
  1128. (<a id='3769' tid='3770' class='u'>kill-region</a> <a id='3771' tid='3772' class='u'>beginning</a>
  1129. (<a id='3773' tid='3774' class='u'>or</a> (<a id='3775' tid='3776' class='u'>save-excursion</a> <a id='3777' tid='3778' class='u'>; Delete trailing indentation...
  1130. </a> (<a id='3779' tid='3780' class='u'>paredit-skip-whitespace</a> <a id='3781' tid='3782' class='u'>t</a>)
  1131. (<a id='3783' tid='3784' class='u'>and</a> (<a id='3785' tid='3786' class='u'>not</a> (<a id='3787' tid='3788' class='u'>eq</a> (<a id='3789' tid='3790' class='u'>char-after</a>) <a id='3791' tid='3792' class='u'>?\;</a> ))
  1132. (<a id='3793' tid='3794' class='u'>point</a>)))
  1133. <a id='3795' tid='3796' class='u'>;; ...or just use the point past the newline, if
  1134. </a> <a id='3797' tid='3798' class='u'>;; we encounter a comment.
  1135. </a> (<a id='3799' tid='3800' class='u'>point-at-eol</a>)))
  1136. (<a id='3801' tid='3802' class='u'>cond</a> ((<a id='3803' tid='3804' class='u'>save-excursion</a> (<a id='3805' tid='3806' class='u'>paredit-skip-whitespace</a> <a id='3807' tid='3808' class='u'>nil</a> (<a id='3809' tid='3810' class='u'>point-at-bol</a>))
  1137. (<a id='3811' tid='3812' class='u'>bolp</a>))
  1138. <a id='3813' tid='3814' class='u'>;; Nothing but indentation before the point, so indent it.
  1139. </a> (<a id='3815' tid='3816' class='u'>lisp-indent-line</a>))
  1140. ((<a id='3817' tid='3818' class='u'>eobp</a>) <a id='3819' tid='3820' class='u'>nil</a>) <a id='3821' tid='3822' class='u'>; Protect the CHAR-SYNTAX below against NIL.
  1141. </a> <a id='3823' tid='3824' class='u'>;; Insert a space to avoid invalid joining if necessary.
  1142. </a> ((<a id='3825' tid='3826' class='u'>let</a> ((<a id='3827' tid='3828' class='u'>syn-before</a> (<a id='3829' tid='3830' class='u'>char-syntax</a> (<a id='3831' tid='3832' class='u'>char-before</a>)))
  1143. (<a id='3833' tid='3834' class='u'>syn-after</a> (<a id='3835' tid='3836' class='u'>char-syntax</a> (<a id='3837' tid='3838' class='u'>char-after</a>))))
  1144. (<a id='3839' tid='3840' class='u'>or</a> (<a id='3841' tid='3842' class='u'>and</a> (<a id='3843' tid='3844' class='u'>eq</a> <a id='3845' tid='3846' class='u'>syn-before</a> <a id='3847' tid='3848' class='u'>?\)</a> ) <a id='3849' tid='3850' class='u'>; Separate opposing
  1145. </a> (<a id='3851' tid='3852' class='u'>eq</a> <a id='3853' tid='3854' class='u'>syn-after</a> <a id='3855' tid='3856' class='u'>?\(</a> )) <a id='3857' tid='3858' class='u'>; parentheses,
  1146. </a> (<a id='3859' tid='3860' class='u'>and</a> (<a id='3861' tid='3862' class='u'>eq</a> <a id='3863' tid='3864' class='u'>syn-before</a> <a id='3865' tid='3866' class='u'>?\&quot;</a> ) <a id='3867' tid='3868' class='u'>; string delimiter
  1147. </a> (<a id='3869' tid='3870' class='u'>eq</a> <a id='3871' tid='3872' class='u'>syn-after</a> <a id='3873' tid='3874' class='u'>?\&quot;</a> )) <a id='3875' tid='3876' class='u'>; pairs,
  1148. </a> (<a id='3877' tid='3878' class='u'>and</a> (<a id='3879' tid='3880' class='u'>memq</a> <a id='3881' tid='3882' class='u'>syn-before</a> <a id='3883' tid='3884' class='u'>&#39;</a>(<a id='3885' tid='3886' class='u'>?_</a> <a id='3887' tid='3888' class='u'>?w</a>)) <a id='3889' tid='3890' class='u'>; or word or symbol
  1149. </a> (<a id='3891' tid='3892' class='u'>memq</a> <a id='3893' tid='3894' class='u'>syn-after</a> <a id='3895' tid='3896' class='u'>&#39;</a>(<a id='3897' tid='3898' class='u'>?_</a> <a id='3899' tid='3900' class='u'>?w</a>))))) <a id='3901' tid='3902' class='u'>; constituents.
  1150. </a> (<a id='3903' tid='3904' class='u'>insert</a> <a id='3905' tid='3906' class='u'>&quot; &quot;</a>))))
  1151. <span class='d'>;;;;; Killing Words
  1152. </span>
  1153. <span class='d'>;;; This is tricky and asymmetrical because backward parsing is
  1154. </span><span class='d'>;;; extraordinarily difficult or impossible, so we have to implement
  1155. </span><span class='d'>;;; killing in both directions by parsing forward.
  1156. </span>
  1157. (<a id='2759' tid='2760' class='u'>defun</a> <a id='2761' tid='2762' class='u'>paredit-forward-kill-word</a> ()
  1158. <a id='2763' tid='2764' class='u'>&quot;Kill a word forward, skipping over intervening delimiters.&quot;</a>
  1159. (<a id='2765' tid='2766' class='u'>interactive</a>)
  1160. (<a id='2767' tid='2768' class='u'>let</a> ((<a id='2769' tid='2770' class='u'>beginning</a> (<a id='2771' tid='2772' class='u'>point</a>)))
  1161. (<a id='2773' tid='2774' class='u'>skip-syntax-forward</a> <a id='2775' tid='2776' class='u'>&quot; -&quot;</a>)
  1162. (<a id='2777' tid='2778' class='u'>let*</a> ((<a id='2779' tid='2780' class='u'>parse-state</a> (<a id='2781' tid='2782' class='u'>paredit-current-parse-state</a>))
  1163. (<a id='2783' tid='2784' class='u'>state</a> (<a id='2785' tid='2786' class='u'>paredit-kill-word-state</a> <a id='2787' tid='2788' class='u'>parse-state</a> <a id='2789' tid='2790' class='u'>&#39;</a><a id='2791' tid='2792' class='u'>char-after</a>)))
  1164. (<a id='2793' tid='2794' class='u'>while</a> (<a id='2795' tid='2796' class='u'>not</a> (<a id='2797' tid='2798' class='u'>or</a> (<a id='2799' tid='2800' class='u'>eobp</a>)
  1165. (<a id='2801' tid='2802' class='u'>eq</a> <a id='2803' tid='2804' class='u'>?w</a> (<a id='2805' tid='2806' class='u'>char-syntax</a> (<a id='2807' tid='2808' class='u'>char-after</a>)))))
  1166. (<a id='2809' tid='2810' class='u'>setq</a> <a id='2811' tid='2812' class='u'>parse-state</a>
  1167. (<a id='2813' tid='2814' class='u'>progn</a> (<a id='2815' tid='2816' class='u'>forward-char</a> <a id='2817' tid='2818' class='u'>1</a>) (<a id='2819' tid='2820' class='u'>paredit-current-parse-state</a>))
  1168. <a id='2821' tid='2822' class='u'>;; (parse-partial-sexp (point) (1+ (point))
  1169. </a><a id='2823' tid='2824' class='u'>;; nil nil parse-state)
  1170. </a> )
  1171. (<a id='2825' tid='2826' class='u'>let*</a> ((<a id='2827' tid='2828' class='u'>old-state</a> <a id='2829' tid='2830' class='u'>state</a>)
  1172. (<a id='2831' tid='2832' class='u'>new-state</a>
  1173. (<a id='2833' tid='2834' class='u'>paredit-kill-word-state</a> <a id='2835' tid='2836' class='u'>parse-state</a> <a id='2837' tid='2838' class='u'>&#39;</a><a id='2839' tid='2840' class='u'>char-after</a>)))
  1174. (<a id='2841' tid='2842' class='u'>cond</a> ((<a id='2843' tid='2844' class='u'>not</a> (<a id='2845' tid='2846' class='u'>eq</a> <a id='2847' tid='2848' class='u'>old-state</a> <a id='2849' tid='2850' class='u'>new-state</a>))
  1175. (<a id='2851' tid='2852' class='u'>setq</a> <a id='2853' tid='2854' class='u'>parse-state</a>
  1176. (<a id='2855' tid='2856' class='u'>paredit-kill-word-hack</a> <a id='2857' tid='2858' class='u'>old-state</a>
  1177. <a id='2859' tid='2860' class='u'>new-state</a>
  1178. <a id='2861' tid='2862' class='u'>parse-state</a>))
  1179. (<a id='2863' tid='2864' class='u'>setq</a> <a id='2865' tid='2866' class='u'>state</a>
  1180. (<a id='2867' tid='2868' class='u'>paredit-kill-word-state</a> <a id='2869' tid='2870' class='u'>parse-state</a>
  1181. <a id='2871' tid='2872' class='u'>&#39;</a><a id='2873' tid='2874' class='u'>char-after</a>))
  1182. (<a id='2875' tid='2876' class='u'>setq</a> <a id='2877' tid='2878' class='u'>beginning</a> (<a id='2879' tid='2880' class='u'>point</a>)))))))
  1183. (<a id='2881' tid='2882' class='u'>goto-char</a> <a id='2883' tid='2884' class='u'>beginning</a>)
  1184. (<a id='2885' tid='2886' class='u'>kill-word</a> <a id='2887' tid='2888' class='u'>1</a>)))
  1185. (<a id='1971' tid='1972' class='u'>defun</a> <a id='1973' tid='1974' class='u'>paredit-backward-kill-word</a> ()
  1186. <a id='1975' tid='1976' class='u'>&quot;Kill a word backward, skipping over any intervening delimiters.&quot;</a>
  1187. (<a id='1977' tid='1978' class='u'>interactive</a>)
  1188. (<a id='1979' tid='1980' class='u'>if</a> (<a id='1981' tid='1982' class='u'>not</a> (<a id='1983' tid='1984' class='u'>or</a> (<a id='1985' tid='1986' class='u'>bobp</a>)
  1189. (<a id='1987' tid='1988' class='u'>eq</a> (<a id='1989' tid='1990' class='u'>char-syntax</a> (<a id='1991' tid='1992' class='u'>char-before</a>)) <a id='1993' tid='1994' class='u'>?w</a>)))
  1190. (<a id='1995' tid='1996' class='u'>let</a> ((<a id='1997' tid='1998' class='u'>end</a> (<a id='1999' tid='2000' class='u'>point</a>)))
  1191. (<a id='2001' tid='2002' class='u'>backward-word</a> <a id='2003' tid='2004' class='u'>1</a>)
  1192. (<a id='2005' tid='2006' class='u'>forward-word</a> <a id='2007' tid='2008' class='u'>1</a>)
  1193. (<a id='2009' tid='2010' class='u'>goto-char</a> (<a id='2011' tid='2012' class='u'>min</a> <a id='2013' tid='2014' class='u'>end</a> (<a id='2015' tid='2016' class='u'>point</a>)))
  1194. (<a id='2017' tid='2018' class='u'>let*</a> ((<a id='2019' tid='2020' class='u'>parse-state</a> (<a id='2021' tid='2022' class='u'>paredit-current-parse-state</a>))
  1195. (<a id='2023' tid='2024' class='u'>state</a>
  1196. (<a id='2025' tid='2026' class='u'>paredit-kill-word-state</a> <a id='2027' tid='2028' class='u'>parse-state</a> <a id='2029' tid='2030' class='u'>&#39;</a><a id='2031' tid='2032' class='u'>char-before</a>)))
  1197. (<a id='2033' tid='2034' class='u'>while</a> (<a id='2035' tid='2036' class='u'>and</a> (<a id='2037' tid='2038' class='u'>&lt;</a> (<a id='2039' tid='2040' class='u'>point</a>) <a id='2041' tid='2042' class='u'>end</a>)
  1198. (<a id='2043' tid='2044' class='u'>progn</a>
  1199. (<a id='2045' tid='2046' class='u'>setq</a> <a id='2047' tid='2048' class='u'>parse-state</a>
  1200. (<a id='2049' tid='2050' class='u'>parse-partial-sexp</a> (<a id='2051' tid='2052' class='u'>point</a>) (<a id='2053' tid='2054' class='u'>1+</a> (<a id='2055' tid='2056' class='u'>point</a>))
  1201. <a id='2057' tid='2058' class='u'>nil</a> <a id='2059' tid='2060' class='u'>nil</a> <a id='2061' tid='2062' class='u'>parse-state</a>))
  1202. (<a id='2063' tid='2064' class='u'>or</a> (<a id='2065' tid='2066' class='u'>eq</a> <a id='2067' tid='2068' class='u'>state</a>
  1203. (<a id='2069' tid='2070' class='u'>paredit-kill-word-state</a> <a id='2071' tid='2072' class='u'>parse-state</a>
  1204. <a id='2073' tid='2074' class='u'>&#39;</a><a id='2075' tid='2076' class='u'>char-before</a>))
  1205. (<a id='2077' tid='2078' class='u'>progn</a> (<a id='2079' tid='2080' class='u'>backward-char</a> <a id='2081' tid='2082' class='u'>1</a>) <a id='2083' tid='2084' class='u'>nil</a>)))))
  1206. (<a id='2085' tid='2086' class='u'>if</a> (<a id='2087' tid='2088' class='u'>and</a> (<a id='2089' tid='2090' class='u'>eq</a> <a id='2091' tid='2092' class='u'>state</a> <a id='2093' tid='2094' class='u'>&#39;</a><a id='2095' tid='2096' class='u'>comment</a>)
  1207. (<a id='2097' tid='2098' class='u'>eq</a> <a id='2099' tid='2100' class='u'>?\#</a> (<a id='2101' tid='2102' class='u'>char-after</a> (<a id='2103' tid='2104' class='u'>point</a>)))
  1208. (<a id='2105' tid='2106' class='u'>eq</a> <a id='2107' tid='2108' class='u'>?\|</a> (<a id='2109' tid='2110' class='u'>char-before</a> (<a id='2111' tid='2112' class='u'>point</a>))))
  1209. (<a id='2113' tid='2114' class='u'>backward-char</a> <a id='2115' tid='2116' class='u'>1</a>)))))
  1210. (<a id='2117' tid='2118' class='u'>backward-kill-word</a> <a id='2119' tid='2120' class='u'>1</a>))
  1211. <span class='d'>;;; Word-Killing Auxiliaries
  1212. </span>
  1213. (<a id='4013' tid='4014' class='u'>defun</a> <a id='4015' tid='4016' class='u'>paredit-kill-word-state</a> (<a id='4017' tid='4018' class='u'>parse-state</a> <a id='4019' tid='4020' class='u'>adjacent-char-fn</a>)
  1214. (<a id='4021' tid='4022' class='u'>cond</a> ((<a id='4023' tid='4024' class='u'>paredit-in-comment-p</a> <a id='4025' tid='4026' class='u'>parse-state</a>) <a id='4027' tid='4028' class='u'>&#39;</a><a id='4029' tid='4030' class='u'>comment</a>)
  1215. ((<a id='4031' tid='4032' class='u'>paredit-in-string-p</a> <a id='4033' tid='4034' class='u'>parse-state</a>) <a id='4035' tid='4036' class='u'>&#39;</a><a id='4037' tid='4038' class='u'>string</a>)
  1216. ((<a id='4039' tid='4040' class='u'>memq</a> (<a id='4041' tid='4042' class='u'>char-syntax</a> (<a id='4043' tid='4044' class='u'>funcall</a> <a id='4045' tid='4046' class='u'>adjacent-char-fn</a>))
  1217. <a id='4047' tid='4048' class='u'>&#39;</a>(<a id='4049' tid='4050' class='u'>?\(</a> <a id='4051' tid='4052' class='u'>?\)</a> ))
  1218. <a id='4053' tid='4054' class='u'>&#39;</a><a id='4055' tid='4056' class='u'>delimiter</a>)
  1219. (<a id='4057' tid='4058' class='u'>t</a> <a id='4059' tid='4060' class='u'>&#39;</a><a id='4061' tid='4062' class='u'>other</a>)))
  1220. <span class='d'>;;; This optionally advances the point past any comment delimiters that
  1221. </span><span class='d'>;;; should probably not be touched, based on the last state change and
  1222. </span><span class='d'>;;; the characters around the point. It returns a new parse state,
  1223. </span><span class='d'>;;; starting from the PARSE-STATE parameter.
  1224. </span>
  1225. (<a id='3911' tid='3912' class='u'>defun</a> <a id='3913' tid='3914' class='u'>paredit-kill-word-hack</a> (<a id='3915' tid='3916' class='u'>old-state</a> <a id='3917' tid='3918' class='u'>new-state</a> <a id='3919' tid='3920' class='u'>parse-state</a>)
  1226. (<a id='3921' tid='3922' class='u'>cond</a> ((<a id='3923' tid='3924' class='u'>and</a> (<a id='3925' tid='3926' class='u'>not</a> (<a id='3927' tid='3928' class='u'>eq</a> <a id='3929' tid='3930' class='u'>old-state</a> <a id='3931' tid='3932' class='u'>&#39;</a><a id='3933' tid='3934' class='u'>comment</a>))
  1227. (<a id='3935' tid='3936' class='u'>not</a> (<a id='3937' tid='3938' class='u'>eq</a> <a id='3939' tid='3940' class='u'>new-state</a> <a id='3941' tid='3942' class='u'>&#39;</a><a id='3943' tid='3944' class='u'>comment</a>))
  1228. (<a id='3945' tid='3946' class='u'>not</a> (<a id='3947' tid='3948' class='u'>paredit-in-string-escape-p</a>))
  1229. (<a id='3949' tid='3950' class='u'>eq</a> <a id='3951' tid='3952' class='u'>?\#</a> (<a id='3953' tid='3954' class='u'>char-before</a>))
  1230. (<a id='3955' tid='3956' class='u'>eq</a> <a id='3957' tid='3958' class='u'>?\|</a> (<a id='3959' tid='3960' class='u'>char-after</a>)))
  1231. (<a id='3961' tid='3962' class='u'>forward-char</a> <a id='3963' tid='3964' class='u'>1</a>)
  1232. (<a id='3965' tid='3966' class='u'>paredit-current-parse-state</a>)
  1233. <a id='3967' tid='3968' class='u'>;; (parse-partial-sexp (point) (1+ (point))
  1234. </a><a id='3969' tid='3970' class='u'>;; nil nil parse-state)
  1235. </a> )
  1236. ((<a id='3971' tid='3972' class='u'>and</a> (<a id='3973' tid='3974' class='u'>not</a> (<a id='3975' tid='3976' class='u'>eq</a> <a id='3977' tid='3978' class='u'>old-state</a> <a id='3979' tid='3980' class='u'>&#39;</a><a id='3981' tid='3982' class='u'>comment</a>))
  1237. (<a id='3983' tid='3984' class='u'>eq</a> <a id='3985' tid='3986' class='u'>new-state</a> <a id='3987' tid='3988' class='u'>&#39;</a><a id='3989' tid='3990' class='u'>comment</a>)
  1238. (<a id='3991' tid='3992' class='u'>eq</a> <a id='3993' tid='3994' class='u'>?\;</a> (<a id='3995' tid='3996' class='u'>char-before</a>)))
  1239. (<a id='3997' tid='3998' class='u'>skip-chars-forward</a> <a id='3999' tid='4000' class='u'>&quot;;&quot;</a>)
  1240. (<a id='4001' tid='4002' class='u'>paredit-current-parse-state</a>)
  1241. <a id='4003' tid='4004' class='u'>;; (parse-partial-sexp (point) (save-excursion
  1242. </a><a id='4005' tid='4006' class='u'>;; (skip-chars-forward &quot;;&quot;))
  1243. </a><a id='4007' tid='4008' class='u'>;; nil nil parse-state)
  1244. </a> )
  1245. (<a id='4009' tid='4010' class='u'>t</a> <a id='4011' tid='4012' class='u'>parse-state</a>)))
  1246. <span class='d'>;;;; Cursor and Screen Movement
  1247. </span>
  1248. (<a id='4787' tid='4788' class='u'>eval-and-compile</a>
  1249. (<a id='4825' tid='4826' class='u'>defmacro</a> <a id='4827' tid='4828' class='u'>defun-saving-mark</a> (<a id='4829' tid='4830' class='u'>name</a> <a id='4831' tid='4832' class='u'>bvl</a> <a id='4833' tid='4834' class='u'>doc</a> <a id='4835' tid='4836' class='u'>&rest</a> <a id='4837' tid='4838' class='u'>body</a>)
  1250. <a id='4839' tid='4840' class='u'>`</a>(<a id='4789' tid='4790' class='u'>defun</a> <a id='4791' tid='4792' class='u'>,</a><a id='4793' tid='4794' class='u'>name</a> <a id='4795' tid='4796' class='u'>,</a><a id='4797' tid='4798' class='u'>bvl</a>
  1251. <a id='4799' tid='4800' class='u'>,</a><a id='4801' tid='4802' class='u'>doc</a>
  1252. <a id='4803' tid='4804' class='u'>,</a>(<a id='4805' tid='4806' class='u'>xcond</a> ((<a id='4807' tid='4808' class='u'>paredit-xemacs-p</a>)
  1253. <a id='4809' tid='4810' class='u'>&#39;</a>(<a id='4811' tid='4812' class='u'>interactive</a> <a id='4813' tid='4814' class='u'>&quot;_&quot;</a>))
  1254. ((<a id='4815' tid='4816' class='u'>paredit-gnu-emacs-p</a>)
  1255. <a id='4817' tid='4818' class='u'>&#39;</a>(<a id='4819' tid='4820' class='u'>interactive</a>)))
  1256. <a id='4821' tid='4822' class='u'>,</a><a id='4823' tid='4824' class='u'>@body</a>)))
  1257. (<a id='4841' tid='4842' class='u'>defun-saving-mark</a> <a id='4843' tid='4844' class='u'>paredit-forward</a> ()
  1258. <a id='4845' tid='4846' class='u'>&quot;Move forward an S-expression, or up an S-expression forward.
  1259. If there are no more S-expressions in this one before the closing
  1260. delimiter, move past that closing delimiter; otherwise, move forward
  1261. past the S-expression following the point.&quot;</a>
  1262. (<a id='4847' tid='4848' class='u'>paredit-handle-sexp-errors</a>
  1263. (<a id='4849' tid='4850' class='u'>forward-sexp</a>)
  1264. <a id='4851' tid='4852' class='u'>;++ Is it necessary to use UP-LIST and not just FORWARD-CHAR?
  1265. </a> (<a id='4853' tid='4854' class='u'>if</a> (<a id='4855' tid='4856' class='u'>paredit-in-string-p</a>) (<a id='4857' tid='4858' class='u'>forward-char</a>) (<a id='4859' tid='4860' class='u'>up-list</a>))))
  1266. (<a id='4861' tid='4862' class='u'>defun-saving-mark</a> <a id='4863' tid='4864' class='u'>paredit-backward</a> ()
  1267. <a id='4865' tid='4866' class='u'>&quot;Move backward an S-expression, or up an S-expression backward.
  1268. If there are no more S-expressions in this one before the opening
  1269. delimiter, move past that opening delimiter backward; otherwise, move
  1270. move backward past the S-expression preceding the point.&quot;</a>
  1271. (<a id='4867' tid='4868' class='u'>paredit-handle-sexp-errors</a>
  1272. (<a id='4869' tid='4870' class='u'>backward-sexp</a>)
  1273. (<a id='4871' tid='4872' class='u'>if</a> (<a id='4873' tid='4874' class='u'>paredit-in-string-p</a>) (<a id='4875' tid='4876' class='u'>backward-char</a>) (<a id='4877' tid='4878' class='u'>backward-up-list</a>))))
  1274. <a id='4879' tid='4880' class='u'>;;; Why is this not in lisp.el?
  1275. </a>
  1276. (<a id='1493' tid='1494' class='u'>defun</a> <a id='1495' tid='1496' class='u'>backward-down-list</a> (<a id='1497' tid='1498' class='u'>&optional</a> <a id='1499' tid='1500' class='u'>arg</a>)
  1277. <a id='1501' tid='1502' class='u'>&quot;Move backward and descend into one level of parentheses.
  1278. With ARG, do this that many times.
  1279. A negative argument means move forward but still descend a level.&quot;</a>
  1280. (<a id='1503' tid='1504' class='u'>interactive</a> <a id='1505' tid='1506' class='u'>&quot;p&quot;</a>)
  1281. (<a id='1507' tid='1508' class='u'>down-list</a> (<a id='1509' tid='1510' class='u'>-</a> (<a id='1511' tid='1512' class='u'>or</a> <a id='1513' tid='1514' class='u'>arg</a> <a id='1515' tid='1516' class='u'>1</a>))))
  1282. <a id='4881' tid='4882' class='u'>;;; Thanks to Marco Baringer for suggesting & writing this function.
  1283. </a>
  1284. (<a id='4263' tid='4264' class='u'>defun</a> <a id='4265' tid='4266' class='u'>paredit-recentre-on-sexp</a> (<a id='4267' tid='4268' class='u'>&optional</a> <a id='4269' tid='4270' class='u'>n</a>)
  1285. <a id='4271' tid='4272' class='u'>&quot;Recentre the screen on the S-expression following the point.
  1286. With a prefix argument N, encompass all N S-expressions forward.&quot;</a>
  1287. (<a id='4273' tid='4274' class='u'>interactive</a> <a id='4275' tid='4276' class='u'>&quot;P&quot;</a>)
  1288. (<a id='4277' tid='4278' class='u'>save-excursion</a>
  1289. (<a id='4279' tid='4280' class='u'>forward-sexp</a> <a id='4281' tid='4282' class='u'>n</a>)
  1290. (<a id='4283' tid='4284' class='u'>let</a> ((<a id='4285' tid='4286' class='u'>end-point</a> (<a id='4287' tid='4288' class='u'>point</a>)))
  1291. (<a id='4289' tid='4290' class='u'>backward-sexp</a> <a id='4291' tid='4292' class='u'>n</a>)
  1292. (<a id='4293' tid='4294' class='u'>let*</a> ((<a id='4295' tid='4296' class='u'>start-point</a> (<a id='4297' tid='4298' class='u'>point</a>))
  1293. (<a id='4299' tid='4300' class='u'>start-line</a> (<a id='4301' tid='4302' class='u'>count-lines</a> (<a id='4303' tid='4304' class='u'>point-min</a>) (<a id='4305' tid='4306' class='u'>point</a>)))
  1294. (<a id='4307' tid='4308' class='u'>lines-on-sexps</a> (<a id='4309' tid='4310' class='u'>count-lines</a> <a id='4311' tid='4312' class='u'>start-point</a> <a id='4313' tid='4314' class='u'>end-point</a>)))
  1295. (<a id='4315' tid='4316' class='u'>goto-line</a> (<a id='4317' tid='4318' class='u'>+</a> <a id='4319' tid='4320' class='u'>start-line</a> (<a id='4321' tid='4322' class='u'>/</a> <a id='4323' tid='4324' class='u'>lines-on-sexps</a> <a id='4325' tid='4326' class='u'>2</a>)))
  1296. (<a id='4327' tid='4328' class='u'>recenter</a>)))))
  1297. <span class='d'>;;;; Depth-Changing Commands: Wrapping, Splicing, & Raising
  1298. </span>
  1299. (<a id='4613' tid='4614' class='u'>defun</a> <a id='4615' tid='4616' class='u'>paredit-wrap-sexp</a> <span class='d'>(&optional n)</span>
  1300. <span class='d'>&quot;Wrap the following S-expression in a list.
  1301. If a prefix argument N is given, wrap N S-expressions.
  1302. Automatically indent the newly wrapped S-expression.
  1303. As a special case, if the point is at the end of a list, simply insert
  1304. a pair of parentheses, rather than insert a lone opening parenthesis
  1305. and then signal an error, in the interest of preserving structure.&quot;</span>
  1306. (<a id='4617' tid='4618' class='u'>interactive</a> <a id='4619' tid='4620' class='u'>&quot;P&quot;</a>)
  1307. <span class='d'>(paredit-handle-sexp-errors
  1308. (paredit-insert-pair (or n
  1309. (and (not (paredit-region-active-p))
  1310. 1))
  1311. ?\( ?\)
  1312. &#39;goto-char)
  1313. (insert ?\) )
  1314. (backward-char))</span>
  1315. (<a id='4621' tid='4622' class='u'>save-excursion</a> (<a id='4623' tid='4624' class='u'>backward-up-list</a>) (<a id='4625' tid='4626' class='u'>indent-sexp</a>)))
  1316. <span class='d'>;;; Thanks to Marco Baringer for the suggestion of a prefix argument
  1317. </span><span class='d'>;;; for PAREDIT-SPLICE-SEXP. (I, Taylor R. Campbell, however, still
  1318. </span><span class='d'>;;; implemented it, in case any of you lawyer-folk get confused by the
  1319. </span><span class='d'>;;; remark in the top of the file about explicitly noting code written
  1320. </span><span class='d'>;;; by other people.)
  1321. </span>
  1322. (<a id='4493' tid='4494' class='u'>defun</a> <a id='4495' tid='4496' class='u'>paredit-splice-sexp</a> <span class='d'>(&optional arg)</span>
  1323. <span class='d'>&quot;Splice the list that the point is on by removing its delimiters.
  1324. With a prefix argument as in `C-u&#39;, kill all S-expressions backward in
  1325. the current list before splicing all S-expressions forward into the
  1326. enclosing list.
  1327. With two prefix arguments as in `C-u C-u&#39;, kill all S-expressions
  1328. forward in the current list before splicing all S-expressions
  1329. backward into the enclosing list.
  1330. With a numerical prefix argument N, kill N S-expressions backward in
  1331. the current list before splicing the remaining S-expressions into the
  1332. enclosing list. If N is negative, kill forward.
  1333. This always creates a new entry on the kill ring.&quot;</span>
  1334. (<a id='4497' tid='4498' class='u'>interactive</a> <a id='4499' tid='4500' class='u'>&quot;P&quot;</a>)
  1335. <span class='d'>(save-excursion
  1336. (paredit-kill-surrounding-sexps-for-splice arg)
  1337. (backward-up-list) ; Go up to the beginning...
  1338. (save-excursion
  1339. (forward-sexp) ; Go forward an expression, to
  1340. (backward-delete-char 1)) ; delete the end delimiter.
  1341. (delete-char 1) ; ...to delete the open char.
  1342. (paredit-ignore-sexp-errors
  1343. (backward-up-list) ; Reindent, now that the
  1344. (indent-sexp)))</span>) <span class='d'>; structure has changed.
  1345. </span>
  1346. (<a id='3907' tid='3908' class='u'>defun</a> <a id='3909' tid='3910' class='u'>paredit-kill-surrounding-sexps-for-splice</a> <span class='d'>(arg)</span>
  1347. (<span class='d'>cond</span> <span class='d'>((paredit-in-string-p) (error &quot;Splicing illegal in strings.&quot;))</span>
  1348. <span class='d'>((or (not arg) (eq arg 0)) nil)</span>
  1349. <span class='d'>((or (numberp arg) (eq arg &#39;-))
  1350. ;; Kill ARG S-expressions before/after the point by saving
  1351. ;; the point, moving across them, and killing the region.
  1352. (let* ((arg (if (eq arg &#39;-) -1 arg))
  1353. (saved (paredit-point-at-sexp-boundary (- arg))))
  1354. (paredit-ignore-sexp-errors (backward-sexp arg))
  1355. (kill-region-new saved (point))))</span>
  1356. (<span class='d'>(consp arg)</span>
  1357. (<span class='d'>let</span> <span class='d'>((v (car arg)))</span>
  1358. (<a id='1209' tid='1210' class='m'>if</a> (<a id='1211' tid='1212' class='m'>=</a> <a id='1213' tid='1214' class='m'>v</a> <a id='1215' tid='1216' class='m'>4</a>) <span class='d'>; one prefix argument
  1359. </span> <a id='1217' tid='1218' class='m'>;; Move backward until we hit the open paren; then
  1360. </a> <a id='1219' tid='1220' class='m'>;; kill that selected region.
  1361. </a> (<span class='d'>let</span> <span class='d'>((end (paredit-point-at-sexp-start)))</span>
  1362. (<a id='1221' tid='1222' class='m'>paredit-ignore-sexp-errors</a>
  1363. (<a id='1223' tid='1224' class='m'>while</a> (<a id='1225' tid='1226' class='m'>not</a> (<a id='1227' tid='1228' class='m'>bobp</a>))
  1364. (<a id='1229' tid='1230' class='m'>backward-sexp</a>)))
  1365. <span class='d'>(kill-region-new (point) end)</span>)
  1366. <a id='1231' tid='1232' class='m'>;; Move forward until we hit the close paren; then
  1367. </a> <a id='1233' tid='1234' class='m'>;; kill that selected region.
  1368. </a> (<span class='d'>let</span> <span class='d'>((beginning (paredit-point-at-sexp-end)))</span>
  1369. (<a id='1235' tid='1236' class='m'>paredit-ignore-sexp-errors</a>
  1370. (<a id='1237' tid='1238' class='m'>while</a> (<a id='1239' tid='1240' class='m'>not</a> (<a id='1241' tid='1242' class='m'>eobp</a>))
  1371. (<a id='1243' tid='1244' class='m'>forward-sexp</a>)))
  1372. <span class='d'>(kill-region-new beginning (point))</span>))))
  1373. <span class='d'>(t (error &quot;Bizarre prefix argument: %s&quot; arg))</span>))
  1374. (<a id='4501' tid='4502' class='u'>defun</a> <a id='4503' tid='4504' class='u'>paredit-splice-sexp-killing-backward</a> (<a id='4505' tid='4506' class='u'>&optional</a> <a id='4507' tid='4508' class='u'>n</a>)
  1375. <a id='4509' tid='4510' class='u'>&quot;Splice the list the point is on by removing its delimiters, and
  1376. also kill all S-expressions before the point in the current list.
  1377. With a prefix argument N, kill only the preceding N S-expressions.&quot;</a>
  1378. (<a id='4511' tid='4512' class='u'>interactive</a> <a id='4513' tid='4514' class='u'>&quot;P&quot;</a>)
  1379. (<a id='4515' tid='4516' class='u'>paredit-splice-sexp</a> (<a id='4517' tid='4518' class='u'>if</a> <a id='4519' tid='4520' class='u'>n</a>
  1380. (<a id='4521' tid='4522' class='u'>prefix-numeric-value</a> <a id='4523' tid='4524' class='u'>n</a>)
  1381. <a id='4525' tid='4526' class='u'>&#39;</a>(<a id='4527' tid='4528' class='u'>4</a>))))
  1382. (<a id='4529' tid='4530' class='u'>defun</a> <a id='4531' tid='4532' class='u'>paredit-splice-sexp-killing-forward</a> (<a id='4533' tid='4534' class='u'>&optional</a> <a id='4535' tid='4536' class='u'>n</a>)
  1383. <a id='4537' tid='4538' class='u'>&quot;Splice the list the point is on by removing its delimiters, and
  1384. also kill all S-expressions after the point in the current list.
  1385. With a prefix argument N, kill only the following N S-expressions.&quot;</a>
  1386. (<a id='4539' tid='4540' class='u'>interactive</a> <a id='4541' tid='4542' class='u'>&quot;P&quot;</a>)
  1387. (<a id='4543' tid='4544' class='u'>paredit-splice-sexp</a> (<a id='4545' tid='4546' class='u'>if</a> <a id='4547' tid='4548' class='u'>n</a>
  1388. (<a id='4549' tid='4550' class='u'>-</a> (<a id='4551' tid='4552' class='u'>prefix-numeric-value</a> <a id='4553' tid='4554' class='u'>n</a>))
  1389. <a id='4555' tid='4556' class='u'>&#39;</a>(<a id='4557' tid='4558' class='u'>16</a>))))
  1390. (<a id='4259' tid='4260' class='u'>defun</a> <a id='4261' tid='4262' class='u'>paredit-raise-sexp</a> <span class='d'>(&optional n)</span>
  1391. <span class='d'>&quot;Raise the following S-expression in a tree, deleting its siblings.
  1392. With a prefix argument N, raise the following N S-expressions. If N
  1393. is negative, raise the preceding N S-expressions.&quot;</span>
  1394. <span class='d'>(interactive &quot;p&quot;)</span>
  1395. <span class='d'>;; Select the S-expressions we want to raise in a buffer substring.
  1396. </span> <span class='d'>(let* ((bound (save-excursion (forward-sexp n) (point)))
  1397. (sexps (save-excursion ;++ Is this necessary?
  1398. (if (and n (&lt; n 0))
  1399. (buffer-substring bound
  1400. (paredit-point-at-sexp-end))
  1401. (buffer-substring (paredit-point-at-sexp-start)
  1402. bound)))))
  1403. ;; Move up to the list we&#39;re raising those S-expressions out of and
  1404. ;; delete it.
  1405. (backward-up-list)
  1406. (delete-region (point) (save-excursion (forward-sexp) (point)))
  1407. (save-excursion (insert sexps)) ; Insert & reindent the sexps.
  1408. (save-excursion (let ((n (abs (or n 1))))
  1409. (while (&gt; n 0)
  1410. (paredit-forward-and-indent)
  1411. (setq n (1- n))))))</span>)
  1412. <a id='4883' tid='4884' class='u'>;;;; Slurpage & Barfage
  1413. </a>
  1414. (<a id='3097' tid='3098' class='u'>defun</a> <a id='3099' tid='3100' class='u'>paredit-forward-slurp-sexp</a> ()
  1415. <a id='3101' tid='3102' class='u'>&quot;Add the S-expression following the current list into that list
  1416. by moving the closing delimiter.
  1417. Automatically reindent the newly slurped S-expression with respect to
  1418. its new enclosing form.
  1419. If in a string, move the opening double-quote forward by one
  1420. S-expression and escape any intervening characters as necessary,
  1421. without altering any indentation or formatting.&quot;</a>
  1422. (<a id='3103' tid='3104' class='u'>interactive</a>)
  1423. <span class='d'>(save-excursion
  1424. (cond ((or (paredit-in-comment-p)
  1425. (paredit-in-char-p))
  1426. (error &quot;Invalid context for slurpage&quot;))
  1427. ((paredit-in-string-p)
  1428. (paredit-forward-slurp-into-string))
  1429. (t
  1430. (paredit-forward-slurp-into-list))))</span>)
  1431. (<a id='3047' tid='3048' class='u'>defun</a> <a id='3049' tid='3050' class='u'>paredit-forward-slurp-into-list</a> ()
  1432. (<a id='3051' tid='3052' class='u'>up-list</a>) <a id='3053' tid='3054' class='u'>; Up to the end of the list to
  1433. </a> (<a id='1245' tid='1246' class='m'>let</a> ((<a id='1247' tid='1248' class='m'>close</a> (<a id='1249' tid='1250' class='m'>char-before</a>))) <a id='1251' tid='1252' class='m'>; save and delete the closing
  1434. </a> (<a id='1253' tid='1254' class='m'>backward-delete-char</a> <a id='1255' tid='1256' class='m'>1</a>) <a id='1257' tid='1258' class='m'>; delimiter.
  1435. </a> (<a id='1259' tid='1260' class='m'>catch</a> <a id='1261' tid='1262' class='m'>&#39;</a><a id='1263' tid='1264' class='m'>return</a> <a id='1265' tid='1266' class='m'>; Go to the end of the desired
  1436. </a> (<a id='1267' tid='1268' class='m'>while</a> <a id='1269' tid='1270' class='m'>t</a> <a id='1271' tid='1272' class='m'>; S-expression, going up a
  1437. </a> (<span class='d'>paredit-handle-sexp-errors</span> <span class='d'>; list if it&#39;s not in this,
  1438. </span> (<a id='1273' tid='1274' class='m'>progn</a> (<a id='1275' tid='1276' class='m'>paredit-forward-and-indent</a>)
  1439. (<a id='1277' tid='1278' class='m'>throw</a> <a id='1279' tid='1280' class='m'>&#39;</a><a id='1281' tid='1282' class='m'>return</a> <a id='1283' tid='1284' class='m'>nil</a>))
  1440. <span class='d'>(up-list)</span>)))
  1441. (<a id='1285' tid='1286' class='m'>insert</a> <a id='1287' tid='1288' class='m'>close</a>))) <a id='4885' tid='4886' class='u'>; to insert that delimiter.
  1442. </a>
  1443. (<a id='3055' tid='3056' class='u'>defun</a> <a id='3057' tid='3058' class='u'>paredit-forward-slurp-into-string</a> ()
  1444. (<a id='3059' tid='3060' class='u'>goto-char</a> (<a id='3061' tid='3062' class='u'>1+</a> (<a id='3063' tid='3064' class='u'>cdr</a> (<a id='3065' tid='3066' class='u'>paredit-string-start+end-points</a>))))
  1445. <a id='3067' tid='3068' class='u'>;; Signal any errors that we might get first, before mucking with the
  1446. </a> <a id='3069' tid='3070' class='u'>;; buffer&#39;s contents.
  1447. </a> (<a id='3071' tid='3072' class='u'>save-excursion</a> (<a id='3073' tid='3074' class='u'>forward-sexp</a>))
  1448. (<a id='3075' tid='3076' class='u'>let</a> ((<a id='3077' tid='3078' class='u'>close</a> (<a id='3079' tid='3080' class='u'>char-before</a>)))
  1449. (<a id='3081' tid='3082' class='u'>backward-delete-char</a> <a id='3083' tid='3084' class='u'>1</a>)
  1450. (<a id='3085' tid='3086' class='u'>paredit-forward-for-quote</a> (<a id='3087' tid='3088' class='u'>save-excursion</a> (<a id='3089' tid='3090' class='u'>forward-sexp</a>) (<a id='3091' tid='3092' class='u'>point</a>)))
  1451. (<a id='3093' tid='3094' class='u'>insert</a> <a id='3095' tid='3096' class='u'>close</a>)))
  1452. (<a id='2437' tid='2438' class='u'>defun</a> <a id='2439' tid='2440' class='u'>paredit-forward-barf-sexp</a> ()
  1453. <a id='2441' tid='2442' class='u'>&quot;Remove the last S-expression in the current list from that list
  1454. by moving the closing delimiter.
  1455. Automatically reindent the newly barfed S-expression with respect to
  1456. its new enclosing form.&quot;</a>
  1457. (<a id='2443' tid='2444' class='u'>interactive</a>)
  1458. (<a id='2445' tid='2446' class='u'>save-excursion</a>
  1459. (<a id='2447' tid='2448' class='u'>up-list</a>) <a id='2449' tid='2450' class='u'>; Up to the end of the list to
  1460. </a> (<a id='2451' tid='2452' class='u'>let</a> ((<a id='2453' tid='2454' class='u'>close</a> (<a id='2455' tid='2456' class='u'>char-before</a>))) <a id='2457' tid='2458' class='u'>; save and delete the closing
  1461. </a> (<a id='2459' tid='2460' class='u'>backward-delete-char</a> <a id='2461' tid='2462' class='u'>1</a>) <a id='2463' tid='2464' class='u'>; delimiter.
  1462. </a> (<a id='2465' tid='2466' class='u'>paredit-ignore-sexp-errors</a> <a id='2467' tid='2468' class='u'>; Go back to where we want to
  1463. </a> (<a id='2469' tid='2470' class='u'>backward-sexp</a>)) <a id='2471' tid='2472' class='u'>; insert the delimiter.
  1464. </a> (<a id='2473' tid='2474' class='u'>paredit-skip-whitespace</a> <a id='2475' tid='2476' class='u'>nil</a>) <a id='2477' tid='2478' class='u'>; Skip leading whitespace.
  1465. </a> (<a id='2479' tid='2480' class='u'>cond</a> ((<a id='2481' tid='2482' class='u'>bobp</a>)
  1466. (<a id='2483' tid='2484' class='u'>error</a> <a id='2485' tid='2486' class='u'>&quot;Barfing all subexpressions with no open-paren?&quot;</a>))
  1467. ((<a id='2487' tid='2488' class='u'>paredit-in-comment-p</a>) <a id='2489' tid='2490' class='u'>; Don&#39;t put the close-paren in
  1468. </a> (<a id='2491' tid='2492' class='u'>newline-and-indent</a>))) <a id='2493' tid='2494' class='u'>; a comment.
  1469. </a> (<a id='2495' tid='2496' class='u'>insert</a> <a id='2497' tid='2498' class='u'>close</a>))
  1470. <a id='2499' tid='2500' class='u'>;; Reindent all of the newly barfed S-expressions.
  1471. </a> (<a id='2501' tid='2502' class='u'>paredit-forward-and-indent</a>)))
  1472. (<a id='2151' tid='2152' class='u'>defun</a> <a id='2153' tid='2154' class='u'>paredit-backward-slurp-sexp</a> ()
  1473. <a id='2155' tid='2156' class='u'>&quot;Add the S-expression preceding the current list into that list
  1474. by moving the closing delimiter.
  1475. Automatically reindent the whole form into which new S-expression was
  1476. slurped.
  1477. If in a string, move the opening double-quote backward by one
  1478. S-expression and escape any intervening characters as necessary,
  1479. without altering any indentation or formatting.&quot;</a>
  1480. (<a id='2157' tid='2158' class='u'>interactive</a>)
  1481. <span class='d'>(save-excursion
  1482. (cond ((or (paredit-in-comment-p)
  1483. (paredit-in-char-p))
  1484. (error &quot;Invalid context for slurpage&quot;))
  1485. ((paredit-in-string-p)
  1486. (paredit-backward-slurp-into-string))
  1487. (t
  1488. (paredit-backward-slurp-into-list))))</span>)
  1489. (<a id='2121' tid='2122' class='u'>defun</a> <a id='2123' tid='2124' class='u'>paredit-backward-slurp-into-list</a> ()
  1490. (<a id='2125' tid='2126' class='u'>backward-up-list</a>)
  1491. (<a id='1289' tid='1290' class='m'>let</a> ((<a id='1291' tid='1292' class='m'>open</a> (<a id='1293' tid='1294' class='m'>char-after</a>)))
  1492. (<a id='1295' tid='1296' class='m'>delete-char</a> <a id='1297' tid='1298' class='m'>1</a>)
  1493. (<a id='1299' tid='1300' class='m'>catch</a> <a id='1301' tid='1302' class='m'>&#39;</a><a id='1303' tid='1304' class='m'>return</a>
  1494. (<a id='1305' tid='1306' class='m'>while</a> <a id='1307' tid='1308' class='m'>t</a>
  1495. (<span class='d'>paredit-handle-sexp-errors</span>
  1496. (<a id='1309' tid='1310' class='m'>progn</a> (<a id='1311' tid='1312' class='m'>backward-sexp</a>)
  1497. (<a id='1313' tid='1314' class='m'>throw</a> <a id='1315' tid='1316' class='m'>&#39;</a><a id='1317' tid='1318' class='m'>return</a> <a id='1319' tid='1320' class='m'>nil</a>))
  1498. <span class='d'>(backward-up-list)</span>)))
  1499. (<a id='1321' tid='1322' class='m'>insert</a> <a id='1323' tid='1324' class='m'>open</a>))
  1500. <span class='d'>;; Reindent the line at the beginning of wherever we inserted the
  1501. </span> <span class='d'>;; opening parenthesis, and then indent the whole S-expression.
  1502. </span> (<a id='2127' tid='2128' class='u'>backward-up-list</a>)
  1503. (<a id='2129' tid='2130' class='u'>lisp-indent-line</a>)
  1504. (<a id='2131' tid='2132' class='u'>indent-sexp</a>))
  1505. (<a id='2133' tid='2134' class='u'>defun</a> <a id='2135' tid='2136' class='u'>paredit-backward-slurp-into-string</a> ()
  1506. (<a id='2137' tid='2138' class='u'>goto-char</a> (<a id='2139' tid='2140' class='u'>car</a> (<a id='2141' tid='2142' class='u'>paredit-string-start+end-points</a>)))
  1507. <a id='2143' tid='2144' class='u'>;; Signal any errors that we might get first, before mucking with the
  1508. </a> <a id='2145' tid='2146' class='u'>;; buffer&#39;s contents.
  1509. </a> (<a id='2147' tid='2148' class='u'>save-excursion</a> (<a id='2149' tid='2150' class='u'>backward-sexp</a>))
  1510. <span class='d'>(let ((open (char-after))
  1511. (target (point)))
  1512. (message &quot;open = %S&quot; open)
  1513. (delete-char 1)
  1514. (backward-sexp)
  1515. (insert open)
  1516. (paredit-forward-for-quote target))</span>)
  1517. (<a id='1799' tid='1800' class='u'>defun</a> <a id='1801' tid='1802' class='u'>paredit-backward-barf-sexp</a> ()
  1518. <a id='1803' tid='1804' class='u'>&quot;Remove the first S-expression in the current list from that list
  1519. by moving the closing delimiter.
  1520. Automatically reindent the barfed S-expression and the form from which
  1521. it was barfed.&quot;</a>
  1522. (<a id='1805' tid='1806' class='u'>interactive</a>)
  1523. (<a id='1807' tid='1808' class='u'>save-excursion</a>
  1524. (<a id='1809' tid='1810' class='u'>backward-up-list</a>)
  1525. (<a id='1811' tid='1812' class='u'>let</a> ((<a id='1813' tid='1814' class='u'>open</a> (<a id='1815' tid='1816' class='u'>char-after</a>)))
  1526. (<a id='1817' tid='1818' class='u'>delete-char</a> <a id='1819' tid='1820' class='u'>1</a>)
  1527. (<a id='1821' tid='1822' class='u'>paredit-ignore-sexp-errors</a>
  1528. (<a id='1823' tid='1824' class='u'>paredit-forward-and-indent</a>))
  1529. (<a id='1825' tid='1826' class='u'>while</a> (<a id='1827' tid='1828' class='u'>progn</a> (<a id='1829' tid='1830' class='u'>paredit-skip-whitespace</a> <a id='1831' tid='1832' class='u'>t</a>)
  1530. (<a id='1833' tid='1834' class='u'>eq</a> (<a id='1835' tid='1836' class='u'>char-after</a>) <a id='1837' tid='1838' class='u'>?\;</a> ))
  1531. (<a id='1839' tid='1840' class='u'>forward-line</a> <a id='1841' tid='1842' class='u'>1</a>))
  1532. (<a id='1843' tid='1844' class='u'>if</a> (<a id='1845' tid='1846' class='u'>eobp</a>)
  1533. (<a id='1847' tid='1848' class='u'>error</a>
  1534. <a id='1849' tid='1850' class='u'>&quot;Barfing all subexpressions with no close-paren?&quot;</a>))
  1535. <a id='1851' tid='1852' class='u'>;** Don&#39;t use `insert&#39; here. Consider, e.g., barfing from
  1536. </a> <a id='1853' tid='1854' class='u'>;** (foo|)
  1537. </a> <a id='1855' tid='1856' class='u'>;** and how `save-excursion&#39; works.
  1538. </a> (<a id='1857' tid='1858' class='u'>insert-before-markers</a> <a id='1859' tid='1860' class='u'>open</a>))
  1539. (<a id='1861' tid='1862' class='u'>backward-up-list</a>)
  1540. (<a id='1863' tid='1864' class='u'>lisp-indent-line</a>)
  1541. (<a id='1865' tid='1866' class='u'>indent-sexp</a>)))
  1542. <a id='4887' tid='4888' class='u'>;;;; Splitting & Joining
  1543. </a>
  1544. (<a id='4559' tid='4560' class='u'>defun</a> <a id='4561' tid='4562' class='u'>paredit-split-sexp</a> ()
  1545. <a id='4563' tid='4564' class='u'>&quot;Split the list or string the point is on into two.&quot;</a>
  1546. (<a id='4565' tid='4566' class='u'>interactive</a>)
  1547. (<span class='d'>cond</span> ((<a id='1325' tid='1326' class='m'>paredit-in-string-p</a>)
  1548. (<a id='1327' tid='1328' class='m'>insert</a> <a id='1329' tid='1330' class='m'>&quot;\&quot;&quot;</a>)
  1549. (<a id='1331' tid='1332' class='m'>save-excursion</a> (<a id='1333' tid='1334' class='m'>insert</a> <a id='1335' tid='1336' class='m'>&quot; \&quot;&quot;</a>)))
  1550. <span class='d'>((or (paredit-in-comment-p)
  1551. (paredit-in-char-p))
  1552. (error &quot;Invalid context for `paredit-split-sexp&#39;&quot;))</span>
  1553. (<a id='573' tid='574' class='m'>t</a> (<a id='575' tid='576' class='m'>let</a> ((<a id='577' tid='578' class='m'>open</a> (<a id='579' tid='580' class='m'>save-excursion</a> (<a id='581' tid='582' class='m'>backward-up-list</a>)
  1554. (<a id='583' tid='584' class='m'>char-after</a>)))
  1555. (<a id='585' tid='586' class='m'>close</a> (<a id='587' tid='588' class='m'>save-excursion</a> (<a id='589' tid='590' class='m'>up-list</a>)
  1556. (<a id='591' tid='592' class='m'>char-before</a>))))
  1557. (<a id='593' tid='594' class='m'>delete-horizontal-space</a>)
  1558. (<a id='595' tid='596' class='m'>insert</a> <a id='597' tid='598' class='m'>close</a>)
  1559. (<a id='599' tid='600' class='m'>save-excursion</a> (<a id='601' tid='602' class='m'>insert</a> <a id='603' tid='604' class='m'>?\ </a>)
  1560. (<a id='605' tid='606' class='m'>insert</a> <a id='607' tid='608' class='m'>open</a>)
  1561. (<a id='609' tid='610' class='m'>backward-char</a>)
  1562. (<a id='611' tid='612' class='m'>indent-sexp</a>))))))
  1563. (<a id='3647' tid='3648' class='u'>defun</a> <a id='3649' tid='3650' class='u'>paredit-join-sexps</a> ()
  1564. <a id='3651' tid='3652' class='u'>&quot;Join the S-expressions adjacent on either side of the point.
  1565. Both must be lists, strings, or atoms; error if there is a mismatch.&quot;</a>
  1566. (<a id='3653' tid='3654' class='u'>interactive</a>)
  1567. <a id='3655' tid='3656' class='u'>;++ How ought this to handle comments intervening symbols or strings?
  1568. </a> (<a id='1337' tid='1338' class='m'>save-excursion</a>
  1569. (<span class='d'>if</span> <span class='d'>(or (paredit-in-comment-p)
  1570. (paredit-in-string-p)
  1571. (paredit-in-char-p))</span>
  1572. <span class='d'>(error &quot;Invalid context in which to join S-expressions.&quot;)</span>
  1573. (<span class='d'>let</span> <span class='d'>((left-point (save-excursion (paredit-point-at-sexp-end)))
  1574. (right-point (save-excursion
  1575. (paredit-point-at-sexp-start))))</span>
  1576. (<a id='1339' tid='1340' class='m'>let</a> ((<a id='1341' tid='1342' class='m'>left-char</a> (<a id='1343' tid='1344' class='m'>char-before</a> <a id='1345' tid='1346' class='m'>left-point</a>))
  1577. (<a id='1347' tid='1348' class='m'>right-char</a> (<a id='1349' tid='1350' class='m'>char-after</a> <a id='1351' tid='1352' class='m'>right-point</a>)))
  1578. (<a id='1353' tid='1354' class='m'>let</a> ((<a id='1355' tid='1356' class='m'>left-syntax</a> (<a id='1357' tid='1358' class='m'>char-syntax</a> <a id='1359' tid='1360' class='m'>left-char</a>))
  1579. (<a id='1361' tid='1362' class='m'>right-syntax</a> (<a id='1363' tid='1364' class='m'>char-syntax</a> <a id='1365' tid='1366' class='m'>right-char</a>)))
  1580. (<a id='1367' tid='1368' class='m'>cond</a> ((<a id='1369' tid='1370' class='m'>&gt;=</a> <a id='1371' tid='1372' class='m'>left-point</a> <a id='1373' tid='1374' class='m'>right-point</a>)
  1581. (<a id='1375' tid='1376' class='m'>error</a> <a id='1377' tid='1378' class='m'>&quot;Can&#39;t join a datum with itself.&quot;</a>))
  1582. ((<a id='1379' tid='1380' class='m'>and</a> (<a id='1381' tid='1382' class='m'>eq</a> <a id='1383' tid='1384' class='m'>left-syntax</a> <a id='1385' tid='1386' class='m'>?\)</a> )
  1583. (<a id='1387' tid='1388' class='m'>eq</a> <a id='1389' tid='1390' class='m'>right-syntax</a> <a id='1391' tid='1392' class='m'>?\(</a> )
  1584. (<a id='1393' tid='1394' class='m'>eq</a> <a id='1395' tid='1396' class='m'>left-char</a> (<a id='1397' tid='1398' class='m'>matching-paren</a> <a id='1399' tid='1400' class='m'>right-char</a>))
  1585. (<a id='1401' tid='1402' class='m'>eq</a> <a id='1403' tid='1404' class='m'>right-char</a> (<a id='1405' tid='1406' class='m'>matching-paren</a> <a id='1407' tid='1408' class='m'>left-char</a>)))
  1586. <a id='1409' tid='1410' class='m'>;; Leave intermediate formatting alone.
  1587. </a> (<a id='1411' tid='1412' class='m'>goto-char</a> <a id='1413' tid='1414' class='m'>right-point</a>)
  1588. (<a id='1415' tid='1416' class='m'>delete-char</a> <a id='1417' tid='1418' class='m'>1</a>)
  1589. (<a id='1419' tid='1420' class='m'>goto-char</a> <a id='1421' tid='1422' class='m'>left-point</a>)
  1590. (<a id='1423' tid='1424' class='m'>backward-delete-char</a> <a id='1425' tid='1426' class='m'>1</a>)
  1591. (<a id='1427' tid='1428' class='m'>backward-up-list</a>)
  1592. (<a id='1429' tid='1430' class='m'>indent-sexp</a>))
  1593. ((<a id='1431' tid='1432' class='m'>and</a> (<a id='1433' tid='1434' class='m'>eq</a> <a id='1435' tid='1436' class='m'>left-syntax</a> <a id='1437' tid='1438' class='m'>?\&quot;</a> )
  1594. (<a id='1439' tid='1440' class='m'>eq</a> <a id='1441' tid='1442' class='m'>right-syntax</a> <a id='1443' tid='1444' class='m'>?\&quot;</a> ))
  1595. <a id='1445' tid='1446' class='m'>;; Delete any intermediate formatting.
  1596. </a> (<a id='1447' tid='1448' class='m'>delete-region</a> (<a id='1449' tid='1450' class='m'>1-</a> <a id='1451' tid='1452' class='m'>left-point</a>)
  1597. (<a id='1453' tid='1454' class='m'>1+</a> <a id='1455' tid='1456' class='m'>right-point</a>)))
  1598. ((<a id='1457' tid='1458' class='m'>and</a> (<a id='1459' tid='1460' class='m'>memq</a> <a id='1461' tid='1462' class='m'>left-syntax</a> <a id='1463' tid='1464' class='m'>&#39;</a>(<a id='1465' tid='1466' class='m'>?w</a> <a id='1467' tid='1468' class='m'>?_</a>)) <a id='1469' tid='1470' class='m'>; Word or symbol
  1599. </a> (<a id='1471' tid='1472' class='m'>memq</a> <a id='1473' tid='1474' class='m'>right-syntax</a> <a id='1475' tid='1476' class='m'>&#39;</a>(<a id='1477' tid='1478' class='m'>?w</a> <a id='1479' tid='1480' class='m'>?_</a>)))
  1600. (<a id='1481' tid='1482' class='m'>delete-region</a> <a id='1483' tid='1484' class='m'>left-point</a> <a id='1485' tid='1486' class='m'>right-point</a>))
  1601. (<a id='1487' tid='1488' class='m'>t</a>
  1602. (<a id='1489' tid='1490' class='m'>error</a> <a id='1491' tid='1492' class='m'>&quot;Mismatched S-expressions to join.&quot;</a>)))))))))
  1603. <span class='d'>;;;; Utilities
  1604. </span>
  1605. (<a id='3261' tid='3262' class='u'>defun</a> <a id='3263' tid='3264' class='u'>paredit-in-string-escape-p</a> ()
  1606. <a id='3265' tid='3266' class='u'>&quot;True if the point is on a character escape of a string.
  1607. This is true only if the character is preceded by an odd number of
  1608. backslashes.
  1609. This assumes that `paredit-in-string-p&#39; has already returned true.&quot;</a>
  1610. (<a id='3267' tid='3268' class='u'>let</a> ((<a id='3269' tid='3270' class='u'>oddp</a> <a id='3271' tid='3272' class='u'>nil</a>))
  1611. (<a id='3273' tid='3274' class='u'>save-excursion</a>
  1612. (<a id='3275' tid='3276' class='u'>while</a> (<a id='3277' tid='3278' class='u'>eq</a> (<a id='3279' tid='3280' class='u'>char-before</a>) <a id='3281' tid='3282' class='u'>?\\</a> )
  1613. (<a id='3283' tid='3284' class='u'>setq</a> <a id='3285' tid='3286' class='u'>oddp</a> (<a id='3287' tid='3288' class='u'>not</a> <a id='3289' tid='3290' class='u'>oddp</a>))
  1614. (<a id='3291' tid='3292' class='u'>backward-char</a>)))
  1615. <a id='3293' tid='3294' class='u'>oddp</a>))
  1616. (<a id='3227' tid='3228' class='u'>defun</a> <a id='3229' tid='3230' class='u'>paredit-in-char-p</a> <span class='d'>(&optional arg)</span>
  1617. <a id='3231' tid='3232' class='u'>&quot;True if the point is immediately after a character literal.
  1618. A preceding escape character, not preceded by another escape character,
  1619. is considered a character literal prefix. (This works for elisp,
  1620. Common Lisp, and Scheme.)
  1621. Assumes that `paredit-in-string-p&#39; is false, so that it need not handle
  1622. long sequences of preceding backslashes in string escapes. (This
  1623. assumes some other leading character token -- ? in elisp, # in Scheme
  1624. and Common Lisp.)&quot;</a>
  1625. <span class='d'>(let ((arg (or arg (point))))
  1626. (and (eq (char-before arg) ?\\ )
  1627. (not (eq (char-before (1- arg)) ?\\ ))))</span>)
  1628. (<a id='2433' tid='2434' class='u'>defun</a> <a id='2435' tid='2436' class='u'>paredit-forward-and-indent</a> ()
  1629. <span class='d'>&quot;Move forward an S-expression, indenting it fully.
  1630. Indent with `lisp-indent-line&#39; and then `indent-sexp&#39;.&quot;</span>
  1631. <span class='d'>(forward-sexp)</span> <span class='d'>; Go forward, and then find the
  1632. </span> <span class='d'>(save-excursion ; beginning of this next
  1633. (backward-sexp) ; S-expression.
  1634. (lisp-indent-line) ; Indent its opening line, and
  1635. (indent-sexp))</span>) <span class='d'>; the rest of it.
  1636. </span>
  1637. (<a id='4445' tid='4446' class='u'>defun</a> <a id='4447' tid='4448' class='u'>paredit-skip-whitespace</a> (<a id='4449' tid='4450' class='u'>trailing-p</a> <a id='4451' tid='4452' class='u'>&optional</a> <a id='4453' tid='4454' class='u'>limit</a>)
  1638. <a id='4455' tid='4456' class='u'>&quot;Skip past any whitespace, or until the point LIMIT is reached.
  1639. If TRAILING-P is nil, skip leading whitespace; otherwise, skip trailing
  1640. whitespace.&quot;</a>
  1641. (<a id='4457' tid='4458' class='u'>funcall</a> (<a id='4459' tid='4460' class='u'>if</a> <a id='4461' tid='4462' class='u'>trailing-p</a> <a id='4463' tid='4464' class='u'>&#39;</a><a id='4465' tid='4466' class='u'>skip-chars-forward</a> <a id='4467' tid='4468' class='u'>&#39;</a><a id='4469' tid='4470' class='u'>skip-chars-backward</a>)
  1642. <a id='4471' tid='4472' class='u'>&quot; \t\n &quot;</a> <a id='4473' tid='4474' class='u'>; This should skip using the syntax table, but LF
  1643. </a> <a id='4475' tid='4476' class='u'>limit</a>)) <span class='d'>; is a comment end, not newline, in Lisp mode.
  1644. </span>
  1645. (<a id='4889' tid='4890' class='u'>defalias</a> <a id='4891' tid='4892' class='u'>&#39;</a><a id='4893' tid='4894' class='u'>paredit-region-active-p</a>
  1646. (<a id='4895' tid='4896' class='u'>xcond</a> ((<a id='4897' tid='4898' class='u'>paredit-xemacs-p</a>) <a id='4899' tid='4900' class='u'>&#39;</a><a id='4901' tid='4902' class='u'>region-active-p</a>)
  1647. ((<a id='4903' tid='4904' class='u'>paredit-gnu-emacs-p</a>)
  1648. (<a id='4905' tid='4906' class='u'>lambda</a> ()
  1649. (<a id='4907' tid='4908' class='u'>and</a> <a id='4909' tid='4910' class='u'>mark-active</a> <a id='4911' tid='4912' class='u'>transient-mark-mode</a>)))))
  1650. <span class='d'>(defun kill-region-new (start end)
  1651. &quot;Kill the region between START and END.
  1652. Do not append to any current kill, and
  1653. do not let the next kill append to this one.&quot;
  1654. (interactive &quot;r&quot;) ;Eh, why not?
  1655. ;; KILL-REGION sets THIS-COMMAND to tell the next kill that the last
  1656. ;; command was a kill. It also checks LAST-COMMAND to see whether it
  1657. ;; should append. If we bind these locally, any modifications to
  1658. ;; THIS-COMMAND will be masked, and it will not see LAST-COMMAND to
  1659. ;; indicate that it should append.
  1660. (let ((this-command nil)
  1661. (last-command nil))
  1662. (kill-region start end)))</span>
  1663. <a id='4913' tid='4914' class='u'>;;;;; S-expression Parsing Utilities
  1664. </a>
  1665. <a id='4915' tid='4916' class='u'>;++ These routines redundantly traverse S-expressions a great deal.
  1666. </a><a id='4917' tid='4918' class='u'>;++ If performance issues arise, this whole section will probably have
  1667. </a><a id='4919' tid='4920' class='u'>;++ to be refactored to preserve the state longer, like paredit.scm
  1668. </a><a id='4921' tid='4922' class='u'>;++ does, rather than to traverse the definition N times for every key
  1669. </a><a id='4923' tid='4924' class='u'>;++ stroke as it presently does.
  1670. </a>
  1671. (<a id='2221' tid='2222' class='u'>defun</a> <a id='2223' tid='2224' class='u'>paredit-current-parse-state</a> ()
  1672. <a id='2225' tid='2226' class='u'>&quot;Return parse state of point from beginning of defun.&quot;</a>
  1673. (<a id='2227' tid='2228' class='u'>let</a> ((<a id='2229' tid='2230' class='u'>point</a> (<a id='2231' tid='2232' class='u'>point</a>)))
  1674. (<a id='2233' tid='2234' class='u'>beginning-of-defun</a>)
  1675. <a id='2235' tid='2236' class='u'>;; Calling PARSE-PARTIAL-SEXP will advance the point to its second
  1676. </a> <a id='2237' tid='2238' class='u'>;; argument (unless parsing stops due to an error, but we assume it
  1677. </a> <a id='2239' tid='2240' class='u'>;; won&#39;t in paredit-mode).
  1678. </a> (<a id='2241' tid='2242' class='u'>parse-partial-sexp</a> (<a id='2243' tid='2244' class='u'>point</a>) <a id='2245' tid='2246' class='u'>point</a>)))
  1679. (<a id='3295' tid='3296' class='u'>defun</a> <a id='3297' tid='3298' class='u'>paredit-in-string-p</a> (<a id='3299' tid='3300' class='u'>&optional</a> <a id='3301' tid='3302' class='u'>state</a>)
  1680. <a id='3303' tid='3304' class='u'>&quot;True if the parse state is within a double-quote-delimited string.
  1681. If no parse state is supplied, compute one from the beginning of the
  1682. defun to the point.&quot;</a>
  1683. <a id='3305' tid='3306' class='u'>;; 3. non-nil if inside a string (the terminator character, really)
  1684. </a> (<a id='3307' tid='3308' class='u'>and</a> (<a id='3309' tid='3310' class='u'>nth</a> <a id='3311' tid='3312' class='u'>3</a> (<a id='3313' tid='3314' class='u'>or</a> <a id='3315' tid='3316' class='u'>state</a> (<a id='3317' tid='3318' class='u'>paredit-current-parse-state</a>)))
  1685. <a id='3319' tid='3320' class='u'>t</a>))
  1686. (<a id='4567' tid='4568' class='u'>defun</a> <a id='4569' tid='4570' class='u'>paredit-string-start+end-points</a> (<a id='4571' tid='4572' class='u'>&optional</a> <a id='4573' tid='4574' class='u'>state</a>)
  1687. <a id='4575' tid='4576' class='u'>&quot;Return a cons of the points of open and close quotes of the string.
  1688. The string is determined from the parse state STATE, or the parse state
  1689. from the beginning of the defun to the point.
  1690. This assumes that `paredit-in-string-p&#39; has already returned true, i.e.
  1691. that the point is already within a string.&quot;</a>
  1692. (<a id='4577' tid='4578' class='u'>save-excursion</a>
  1693. <a id='4579' tid='4580' class='u'>;; 8. character address of start of comment or string; nil if not
  1694. </a> <a id='4581' tid='4582' class='u'>;; in one
  1695. </a> (<a id='4583' tid='4584' class='u'>let</a> ((<a id='4585' tid='4586' class='u'>start</a> (<a id='4587' tid='4588' class='u'>nth</a> <a id='4589' tid='4590' class='u'>8</a> (<a id='4591' tid='4592' class='u'>or</a> <a id='4593' tid='4594' class='u'>state</a> (<a id='4595' tid='4596' class='u'>paredit-current-parse-state</a>)))))
  1696. (<a id='4597' tid='4598' class='u'>goto-char</a> <a id='4599' tid='4600' class='u'>start</a>)
  1697. (<a id='4601' tid='4602' class='u'>forward-sexp</a> <a id='4603' tid='4604' class='u'>1</a>)
  1698. (<a id='4605' tid='4606' class='u'>cons</a> <a id='4607' tid='4608' class='u'>start</a> (<a id='4609' tid='4610' class='u'>1-</a> (<a id='4611' tid='4612' class='u'>point</a>))))))
  1699. (<a id='3233' tid='3234' class='u'>defun</a> <a id='3235' tid='3236' class='u'>paredit-in-comment-p</a> (<a id='3237' tid='3238' class='u'>&optional</a> <a id='3239' tid='3240' class='u'>state</a>)
  1700. <a id='3241' tid='3242' class='u'>&quot;True if parse state STATE is within a comment.
  1701. If no parse state is supplied, compute one from the beginning of the
  1702. defun to the point.&quot;</a>
  1703. <a id='3243' tid='3244' class='u'>;; 4. nil if outside a comment, t if inside a non-nestable comment,
  1704. </a> <a id='3245' tid='3246' class='u'>;; else an integer (the current comment nesting)
  1705. </a> (<a id='3247' tid='3248' class='u'>and</a> (<a id='3249' tid='3250' class='u'>nth</a> <a id='3251' tid='3252' class='u'>4</a> (<a id='3253' tid='3254' class='u'>or</a> <a id='3255' tid='3256' class='u'>state</a> (<a id='3257' tid='3258' class='u'>paredit-current-parse-state</a>)))
  1706. <a id='3259' tid='3260' class='u'>t</a>))
  1707. (<a id='4219' tid='4220' class='u'>defun</a> <a id='4221' tid='4222' class='u'>paredit-point-at-sexp-boundary</a> (<a id='4223' tid='4224' class='u'>n</a>)
  1708. (<a id='4225' tid='4226' class='u'>cond</a> ((<a id='4227' tid='4228' class='u'>&lt;</a> <a id='4229' tid='4230' class='u'>n</a> <a id='4231' tid='4232' class='u'>0</a>) (<a id='4233' tid='4234' class='u'>paredit-point-at-sexp-start</a>))
  1709. ((<a id='4235' tid='4236' class='u'>=</a> <a id='4237' tid='4238' class='u'>n</a> <a id='4239' tid='4240' class='u'>0</a>) (<a id='4241' tid='4242' class='u'>point</a>))
  1710. ((<a id='4243' tid='4244' class='u'>&gt;</a> <a id='4245' tid='4246' class='u'>n</a> <a id='4247' tid='4248' class='u'>0</a>) (<a id='4249' tid='4250' class='u'>paredit-point-at-sexp-end</a>))))
  1711. (<a id='4255' tid='4256' class='u'>defun</a> <a id='4257' tid='4258' class='u'>paredit-point-at-sexp-start</a> ()
  1712. <span class='d'>(forward-sexp)</span>
  1713. <span class='d'>(backward-sexp)</span>
  1714. <span class='d'>(point)</span>)
  1715. (<a id='4251' tid='4252' class='u'>defun</a> <a id='4253' tid='4254' class='u'>paredit-point-at-sexp-end</a> ()
  1716. <span class='d'>(backward-sexp)</span>
  1717. <span class='d'>(forward-sexp)</span>
  1718. <span class='d'>(point)</span>)
  1719. <a id='4925' tid='4926' class='u'>;;;; Initialization
  1720. </a>
  1721. (<a id='4927' tid='4928' class='u'>paredit-define-keys</a>)
  1722. (<a id='4929' tid='4930' class='u'>paredit-annotate-mode-with-examples</a>)
  1723. (<a id='4931' tid='4932' class='u'>paredit-annotate-functions-with-examples</a>)
  1724. (<a id='4933' tid='4934' class='u'>provide</a> <a id='4935' tid='4936' class='u'>&#39;</a><a id='4937' tid='4938' class='u'>paredit</a>)
  1725. </pre>
  1726. </div>
  1727. <div id="right" class="src">
  1728. <pre>
  1729. <a id='rightstart' tid='leftstart'></a>
  1730. <span class='i'>;;; paredit.el --- minor mode for editing parentheses -*- Mode: Emacs-Lisp -*-
  1731. </span>
  1732. <span class='i'>;; Copyright (C) 2005--2010 Taylor R. Campbell
  1733. </span>
  1734. <span class='i'>;; Author: Taylor R. Campbell
  1735. </span><span class='i'>;; Version: 22
  1736. </span><span class='i'>;; Created: 2005-07-31
  1737. </span><span class='i'>;; Keywords: lisp
  1738. </span>
  1739. <span class='i'>;; Paredit is free software: you can redistribute it and/or modify it
  1740. </span><span class='i'>;; under the terms of the GNU General Public License as published by
  1741. </span><span class='i'>;; the Free Software Foundation, either version 3 of the License, or
  1742. </span><span class='i'>;; (at your option) any later version.
  1743. </span><span class='i'>;;
  1744. </span><span class='i'>;; Paredit is distributed in the hope that it will be useful, but
  1745. </span><span class='i'>;; WITHOUT ANY WARRANTY; without even the implied warranty of
  1746. </span><span class='i'>;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1747. </span><span class='i'>;; GNU General Public License for more details.
  1748. </span><span class='i'>;;
  1749. </span><span class='i'>;; You should have received a copy of the GNU General Public License
  1750. </span><span class='i'>;; along with paredit. If not, see &lt;http://www.gnu.org/licenses/&gt;.
  1751. </span>
  1752. <span class='i'>;;; This file is permanently stored at
  1753. </span><span class='i'>;;; &lt;http://mumble.net/~campbell/emacs/paredit-22.el&gt;.
  1754. </span><a id='4628' tid='4627' class='u'>;;;
  1755. </a><span class='i'>;;; The currently released version of paredit is available at
  1756. </span><span class='i'>;;; &lt;http://mumble.net/~campbell/emacs/paredit.el&gt;.
  1757. </span><span class='i'>;;;
  1758. </span><span class='i'>;;; The latest beta version of paredit is available at
  1759. </span><span class='i'>;;; &lt;http://mumble.net/~campbell/emacs/paredit-beta.el&gt;.
  1760. </span><span class='i'>;;;
  1761. </span><span class='i'>;;; Release notes are available at
  1762. </span><span class='i'>;;; &lt;http://mumble.net/~campbell/emacs/paredit.release&gt;.
  1763. </span>
  1764. <span class='i'>;;; Install paredit by placing `paredit.el&#39; in `/path/to/elisp&#39;, a
  1765. </span><span class='i'>;;; directory of your choice, and adding to your .emacs file:
  1766. </span><span class='i'>;;;
  1767. </span><span class='i'>;;; (add-to-list &#39;load-path &quot;/path/to/elisp&quot;)
  1768. </span><span class='i'>;;; (autoload &#39;enable-paredit-mode &quot;paredit&quot;
  1769. </span><span class='i'>;;; &quot;Turn on pseudo-structural editing of Lisp code.&quot;
  1770. </span><span class='i'>;;; t)
  1771. </span><span class='i'>;;;
  1772. </span><span class='i'>;;; Enable Paredit Mode on the fly with `M-x enable-paredit-mode RET&#39;,
  1773. </span><span class='i'>;;; or always enable it in a major mode `M&#39; (e.g., `lisp&#39;) with:
  1774. </span><span class='i'>;;;
  1775. </span><span class='i'>;;; (add-hook M-mode-hook &#39;enable-paredit-mode)
  1776. </span><span class='i'>;;;
  1777. </span><span class='i'>;;; Customize paredit using `eval-after-load&#39;:
  1778. </span><span class='i'>;;;
  1779. </span><span class='i'>;;; (eval-after-load &#39;paredit
  1780. </span><span class='i'>;;; &#39;(progn ...redefine keys, &c....))
  1781. </span><span class='i'>;;;
  1782. </span><span class='i'>;;; Paredit should run in GNU Emacs 21 or later and XEmacs 21.5 or
  1783. </span><span class='i'>;;; later. Paredit is highly unlikely to work in earlier versions of
  1784. </span><span class='i'>;;; GNU Emacs, and it may have obscure problems in earlier versions of
  1785. </span><span class='i'>;;; XEmacs due to the way its syntax parser reports conditions, as a
  1786. </span><span class='i'>;;; result of which the code that uses the syntax parser must mask all
  1787. </span><span class='i'>;;; error conditions, not just those generated by the syntax parser.
  1788. </span><a id='4630' tid='4629' class='u'>;;;
  1789. </a><span class='i'>;;; Questions, bug reports, comments, feature suggestions, &c., may be
  1790. </span><span class='i'>;;; addressed via email to the author&#39;s surname at mumble.net or via
  1791. </span><span class='i'>;;; IRC to the user named Riastradh on irc.freenode.net in the #paredit
  1792. </span><span class='i'>;;; channel.
  1793. </span><span class='i'>;;;
  1794. </span><span class='i'>;;; Please contact the author rather than forking your own versions, to
  1795. </span><span class='i'>;;; prevent the dissemination of random variants floating about the
  1796. </span><span class='i'>;;; internet unbeknownst to the author. Laziness is not an excuse:
  1797. </span><span class='i'>;;; your laziness costs me confusion and time trying to support
  1798. </span><span class='i'>;;; paredit, so if you fork paredit, you make the world a worse place.
  1799. </span><span class='i'>;;;
  1800. </span><span class='i'>;;; *** WARNING *** IMPORTANT *** DO NOT SUBMIT BUGS BEFORE READING ***
  1801. </span><a id='4632' tid='4631' class='u'>;;;
  1802. </a><span class='i'>;;; If you plan to submit a bug report, where some sequence of keys in
  1803. </span><span class='i'>;;; Paredit Mode, or some sequence of paredit commands, doesn&#39;t do what
  1804. </span><span class='i'>;;; you wanted, then it is helpful to isolate an example in a very
  1805. </span><span class='i'>;;; small buffer, and it is **ABSOLUTELY**ESSENTIAL** that you supply,
  1806. </span><span class='i'>;;; along with the sequence of keys or commands,
  1807. </span><a id='4634' tid='4633' class='u'>;;;
  1808. </a><span class='i'>;;; (1) the version of Emacs,
  1809. </span><span class='i'>;;; (2) the version of paredit.el[*], and
  1810. </span><span class='i'>;;; (3) the **COMPLETE** state of the buffer used to reproduce the
  1811. </span><span class='i'>;;; problem, including major mode, minor modes, local key
  1812. </span><span class='i'>;;; bindings, entire contents of the buffer, leading line breaks
  1813. </span><span class='i'>;;; or spaces, &c.
  1814. </span><span class='i'>;;;
  1815. </span><span class='i'>;;; It is often extremely difficult to reproduce problems, especially
  1816. </span><span class='i'>;;; with commands such as `paredit-kill&#39;. If you do not supply **ALL**
  1817. </span><span class='i'>;;; of this information, then it is highly probable that I cannot
  1818. </span><span class='i'>;;; reproduce your problem no matter how hard I try, and the effect of
  1819. </span><span class='i'>;;; submitting a bug without this information is only to waste your
  1820. </span><span class='i'>;;; time and mine. So, please, include all of the above information.
  1821. </span><span class='i'>;;;
  1822. </span><span class='i'>;;; [*] If you are using a beta version of paredit, be sure that you
  1823. </span><span class='i'>;;; are using the *latest* edition of the beta version, available
  1824. </span><span class='i'>;;; at &lt;http://mumble.net/~campbell/emacs/paredit-beta.el&gt;. If you
  1825. </span><span class='i'>;;; are not using a beta version, then upgrade either to that or to
  1826. </span><span class='i'>;;; the latest release version; I cannot support older versions,
  1827. </span><span class='i'>;;; and I can&#39;t fathom any reason why you might be using them. So
  1828. </span><span class='i'>;;; the answer to item (2) should be either `release&#39; or `beta&#39;.
  1829. </span>
  1830. <span class='i'>;;; The paredit minor mode, Paredit Mode, binds a number of simple
  1831. </span><span class='i'>;;; keys, notably `(&#39;, `)&#39;, `&quot;&#39;, and `\&#39;, to commands that more
  1832. </span><span class='i'>;;; carefully insert S-expression structures in the buffer. The
  1833. </span><span class='i'>;;; parenthesis delimiter keys (round or square) are defined to insert
  1834. </span><span class='i'>;;; parenthesis pairs and move past the closing delimiter,
  1835. </span><span class='i'>;;; respectively; the double-quote key is multiplexed to do both, and
  1836. </span><span class='i'>;;; also to insert an escape if within a string; and backslashes prompt
  1837. </span><span class='i'>;;; the user for the next character to input, because a lone backslash
  1838. </span><span class='i'>;;; can break structure inadvertently. These all have their ordinary
  1839. </span><span class='i'>;;; behaviour when inside comments, and, outside comments, if truly
  1840. </span><span class='i'>;;; necessary, you can insert them literally with `C-q&#39;.
  1841. </span><span class='i'>;;;
  1842. </span><span class='i'>;;; The key bindings are designed so that when typing new code in
  1843. </span><span class='i'>;;; Paredit Mode, you can generally use exactly the same keystrokes as
  1844. </span><span class='i'>;;; you would have used without Paredit Mode. Earlier versions of
  1845. </span><span class='i'>;;; paredit.el did not conform to this, because Paredit Mode bound `)&#39;
  1846. </span><span class='i'>;;; to a command that would insert a newline. Now `)&#39; is bound to a
  1847. </span><span class='i'>;;; command that does not insert a newline, and `M-)&#39; is bound to the
  1848. </span><span class='i'>;;; command that inserts a newline. To revert to the former behaviour,
  1849. </span><span class='i'>;;; add the following forms to an `eval-after-load&#39; form for paredit.el
  1850. </span><span class='i'>;;; in your .emacs file:
  1851. </span><span class='i'>;;;
  1852. </span><span class='i'>;;; (define-key paredit-mode-map (kbd &quot;)&quot;)
  1853. </span><span class='i'>;;; &#39;paredit-close-round-and-newline)
  1854. </span><span class='i'>;;; (define-key paredit-mode-map (kbd &quot;M-)&quot;)
  1855. </span><span class='i'>;;; &#39;paredit-close-round)
  1856. </span><span class='i'>;;;
  1857. </span><span class='i'>;;; Paredit Mode also binds the usual keys for deleting and killing, so
  1858. </span><span class='i'>;;; that they will not destroy any S-expression structure by killing or
  1859. </span><span class='i'>;;; deleting only one side of a parenthesis or quote pair. If the
  1860. </span><span class='i'>;;; point is on a closing delimiter, `DEL&#39; will move left over it; if
  1861. </span><span class='i'>;;; it is on an opening delimiter, `C-d&#39; will move right over it. Only
  1862. </span><span class='i'>;;; if the point is between a pair of delimiters will `C-d&#39; or `DEL&#39;
  1863. </span><span class='i'>;;; delete them, and in that case it will delete both simultaneously.
  1864. </span><span class='i'>;;; `M-d&#39; and `M-DEL&#39; kill words, but skip over any S-expression
  1865. </span><span class='i'>;;; structure. `C-k&#39; kills from the start of the line, either to the
  1866. </span><span class='i'>;;; line&#39;s end, if it contains only balanced expressions; to the first
  1867. </span><span class='i'>;;; closing delimiter, if the point is within a form that ends on the
  1868. </span><span class='i'>;;; line; or up to the end of the last expression that starts on the
  1869. </span><span class='i'>;;; line after the point.
  1870. </span><span class='i'>;;;
  1871. </span><span class='i'>;;; The behaviour of the commands for deleting and killing can be
  1872. </span><span class='i'>;;; overridden by passing a `C-u&#39; prefix argument: `C-u DEL&#39; will
  1873. </span><span class='i'>;;; delete a character backward, `C-u C-d&#39; will delete a character
  1874. </span><span class='i'>;;; forward, and `C-u C-k&#39; will kill text from the point to the end of
  1875. </span><span class='i'>;;; the line, irrespective of the S-expression structure in the buffer.
  1876. </span><span class='i'>;;; This can be used to fix mistakes in a buffer, but should generally
  1877. </span><span class='i'>;;; be avoided.
  1878. </span><span class='i'>;;;
  1879. </span><span class='i'>;;; Paredit performs automatic reindentation as locally as possible, to
  1880. </span><span class='i'>;;; avoid interfering with custom indentation used elsewhere in some
  1881. </span><span class='i'>;;; S-expression. Only the advanced S-expression manipulation commands
  1882. </span><span class='i'>;;; automatically reindent, and only the forms that were immediately
  1883. </span><span class='i'>;;; operated upon (and their subforms).
  1884. </span><span class='i'>;;;
  1885. </span><span class='i'>;;; This code is written for clarity, not efficiency. It frequently
  1886. </span><span class='i'>;;; walks over S-expressions redundantly. If you have problems with
  1887. </span><span class='i'>;;; the time it takes to execute some of the commands, let me know, but
  1888. </span><span class='i'>;;; first be sure that what you&#39;re doing is reasonable: it is
  1889. </span><span class='i'>;;; preferable to avoid immense S-expressions in code anyway.
  1890. </span>
  1891. <span class='i'>;;; This assumes Unix-style LF line endings.
  1892. </span>
  1893. <span class='i'>(defconst paredit-version 22)</span>
  1894. <span class='i'>(defconst paredit-beta-p nil)</span>
  1895. (<a id='668' tid='667' class='m'>eval-and-compile</a>
  1896. (<a id='654' tid='653' class='m'>defun</a> <a id='656' tid='655' class='m'>paredit-xemacs-p</a> ()
  1897. <span class='i'>;; No idea where I got this definition from. Edward O&#39;Connor
  1898. </span> <span class='i'>;; (hober in #emacs) suggested the current definition.
  1899. </span> <a id='658' tid='657' class='m'>;; (and (boundp &#39;running-xemacs)
  1900. </a> <a id='660' tid='659' class='m'>;; running-xemacs)
  1901. </a> (<a id='662' tid='661' class='m'>featurep</a> <a id='664' tid='663' class='m'>&#39;</a><a id='666' tid='665' class='m'>xemacs</a>))
  1902. (<a id='614' tid='613' class='m'>defun</a> <a id='616' tid='615' class='m'>paredit-gnu-emacs-p</a> ()
  1903. <span class='i'>;++ This could probably be improved.
  1904. </span> (<a id='618' tid='617' class='m'>not</a> (<a id='620' tid='619' class='m'>paredit-xemacs-p</a>)))
  1905. (<a id='670' tid='669' class='m'>defmacro</a> <a id='672' tid='671' class='m'>xcond</a> (<a id='674' tid='673' class='m'>&rest</a> <a id='676' tid='675' class='m'>clauses</a>)
  1906. <a id='678' tid='677' class='m'>&quot;Exhaustive COND.
  1907. Signal an error if no clause matches.&quot;</a>
  1908. <a id='680' tid='679' class='m'>`</a>(<a id='682' tid='681' class='m'>cond</a> <a id='684' tid='683' class='m'>,</a><a id='686' tid='685' class='m'>@clauses</a>
  1909. (<a id='688' tid='687' class='m'>t</a> (<a id='690' tid='689' class='m'>error</a> <a id='692' tid='691' class='m'>&quot;XCOND lost.&quot;</a>))))
  1910. (<a id='694' tid='693' class='m'>defalias</a> <a id='696' tid='695' class='m'>&#39;</a><a id='698' tid='697' class='m'>paredit-warn</a> (<a id='700' tid='699' class='m'>if</a> (<a id='702' tid='701' class='m'>fboundp</a> <a id='704' tid='703' class='m'>&#39;</a><a id='706' tid='705' class='m'>warn</a>) <a id='708' tid='707' class='m'>&#39;</a><a id='710' tid='709' class='m'>warn</a> <a id='712' tid='711' class='m'>&#39;</a><a id='714' tid='713' class='m'>message</a>))
  1911. (<a id='622' tid='621' class='m'>defvar</a> <a id='624' tid='623' class='m'>paredit-sexp-error-type</a>
  1912. (<a id='626' tid='625' class='m'>with-temp-buffer</a>
  1913. (<a id='628' tid='627' class='m'>insert</a> <a id='630' tid='629' class='m'>&quot;(&quot;</a>)
  1914. (<a id='632' tid='631' class='m'>condition-case</a> <a id='634' tid='633' class='m'>condition</a>
  1915. (<a id='636' tid='635' class='m'>backward-sexp</a>)
  1916. (<a id='638' tid='637' class='m'>error</a> (<span class='i'>if</span> (<a id='640' tid='639' class='m'>eq</a> (<a id='642' tid='641' class='m'>car</a> <a id='644' tid='643' class='m'>condition</a>) <a id='646' tid='645' class='m'>&#39;</a><a id='648' tid='647' class='m'>error</a>)
  1917. <span class='i'>(paredit-warn &quot;%s%s%s%s%s&quot;
  1918. &quot;Paredit is unable to discriminate&quot;
  1919. &quot; S-expression parse errors from&quot;
  1920. &quot; other errors. &quot;
  1921. &quot; This may cause obscure problems. &quot;
  1922. &quot; Please upgrade Emacs.&quot;)</span>)
  1923. (<a id='650' tid='649' class='m'>car</a> <a id='652' tid='651' class='m'>condition</a>)))))
  1924. (<a id='716' tid='715' class='m'>defmacro</a> <a id='718' tid='717' class='m'>paredit-handle-sexp-errors</a> (<a id='720' tid='719' class='m'>body</a> <a id='722' tid='721' class='m'>&rest</a> <a id='724' tid='723' class='m'>handler</a>)
  1925. <a id='726' tid='725' class='m'>`</a>(<a id='728' tid='727' class='m'>condition-case</a> ()
  1926. <a id='730' tid='729' class='m'>,</a><a id='732' tid='731' class='m'>body</a>
  1927. (<a id='734' tid='733' class='m'>,</a><a id='736' tid='735' class='m'>paredit-sexp-error-type</a> <a id='738' tid='737' class='m'>,</a><a id='740' tid='739' class='m'>@handler</a>)))
  1928. (<a id='742' tid='741' class='m'>put</a> <a id='744' tid='743' class='m'>&#39;</a><a id='746' tid='745' class='m'>paredit-handle-sexp-errors</a> <a id='748' tid='747' class='m'>&#39;</a><a id='750' tid='749' class='m'>lisp-indent-function</a> <a id='752' tid='751' class='m'>1</a>)
  1929. (<a id='754' tid='753' class='m'>defmacro</a> <a id='756' tid='755' class='m'>paredit-ignore-sexp-errors</a> (<a id='758' tid='757' class='m'>&rest</a> <a id='760' tid='759' class='m'>body</a>)
  1930. <a id='762' tid='761' class='m'>`</a>(<a id='764' tid='763' class='m'>paredit-handle-sexp-errors</a> (<a id='766' tid='765' class='m'>progn</a> <a id='768' tid='767' class='m'>,</a><a id='770' tid='769' class='m'>@body</a>)
  1931. <a id='772' tid='771' class='m'>nil</a>))
  1932. (<a id='774' tid='773' class='m'>put</a> <a id='776' tid='775' class='m'>&#39;</a><a id='778' tid='777' class='m'>paredit-ignore-sexp-errors</a> <a id='780' tid='779' class='m'>&#39;</a><a id='782' tid='781' class='m'>lisp-indent-function</a> <a id='784' tid='783' class='m'>0</a>)
  1933. <a id='786' tid='785' class='m'>nil</a>)
  1934. <span class='i'>;;;; Minor Mode Definition
  1935. </span>
  1936. (<a id='4190' tid='4189' class='u'>defvar</a> <a id='4192' tid='4191' class='u'>paredit-mode-map</a> (<a id='4194' tid='4193' class='u'>make-sparse-keymap</a>)
  1937. <a id='4196' tid='4195' class='u'>&quot;Keymap for the paredit minor mode.&quot;</a>)
  1938. <span class='i'>;;;###autoload
  1939. </span>(<a id='4120' tid='4119' class='u'>define-minor-mode</a> <a id='4122' tid='4121' class='u'>paredit-mode</a>
  1940. <span class='i'>&quot;Minor mode for pseudo-structurally editing Lisp code.
  1941. With a prefix argument, enable Paredit Mode even if there are
  1942. imbalanced parentheses in the buffer.
  1943. Paredit behaves badly if parentheses are imbalanced, so exercise
  1944. caution when forcing Paredit Mode to be enabled, and consider
  1945. fixing imbalanced parentheses instead.
  1946. \\&lt;paredit-mode-map&gt;&quot;</span>
  1947. <a id='4124' tid='4123' class='u'>:lighter</a> <a id='4126' tid='4125' class='u'>&quot; Paredit&quot;</a>
  1948. <a id='4128' tid='4127' class='u'>;; If we&#39;re enabling paredit-mode, the prefix to this code that
  1949. </a> <a id='4130' tid='4129' class='u'>;; DEFINE-MINOR-MODE inserts will have already set PAREDIT-MODE to
  1950. </a> <a id='4132' tid='4131' class='u'>;; true. If this is the case, then first check the parentheses, and
  1951. </a> <a id='4134' tid='4133' class='u'>;; if there are any imbalanced ones we must inhibit the activation of
  1952. </a> <a id='4136' tid='4135' class='u'>;; paredit mode. We skip the check, though, if the user supplied a
  1953. </a> <a id='4138' tid='4137' class='u'>;; prefix argument interactively.
  1954. </a> (<a id='4140' tid='4139' class='u'>if</a> (<a id='4142' tid='4141' class='u'>and</a> <a id='4144' tid='4143' class='u'>paredit-mode</a>
  1955. (<a id='4146' tid='4145' class='u'>not</a> <a id='4148' tid='4147' class='u'>current-prefix-arg</a>))
  1956. (<a id='4150' tid='4149' class='u'>if</a> (<a id='4152' tid='4151' class='u'>not</a> (<a id='4154' tid='4153' class='u'>fboundp</a> <a id='4156' tid='4155' class='u'>&#39;</a><a id='4158' tid='4157' class='u'>check-parens</a>))
  1957. (<a id='4160' tid='4159' class='u'>paredit-warn</a> <a id='4162' tid='4161' class='u'>&quot;`check-parens&#39; is not defined; %s&quot;</a>
  1958. <a id='4164' tid='4163' class='u'>&quot;be careful of malformed S-expressions.&quot;</a>)
  1959. (<a id='4166' tid='4165' class='u'>condition-case</a> <a id='4168' tid='4167' class='u'>condition</a>
  1960. (<a id='4170' tid='4169' class='u'>check-parens</a>)
  1961. (<a id='4172' tid='4171' class='u'>error</a> (<a id='4174' tid='4173' class='u'>setq</a> <a id='4176' tid='4175' class='u'>paredit-mode</a> <a id='4178' tid='4177' class='u'>nil</a>)
  1962. (<a id='4180' tid='4179' class='u'>signal</a> (<a id='4182' tid='4181' class='u'>car</a> <a id='4184' tid='4183' class='u'>condition</a>) (<a id='4186' tid='4185' class='u'>cdr</a> <a id='4188' tid='4187' class='u'>condition</a>)))))))
  1963. (<a id='1528' tid='1527' class='u'>defun</a> <a id='1530' tid='1529' class='u'>enable-paredit-mode</a> ()
  1964. <span class='i'>&quot;Turn on pseudo-structural editing of Lisp code.&quot;</span>
  1965. (<a id='1532' tid='1531' class='u'>interactive</a>)
  1966. (<a id='1534' tid='1533' class='u'>paredit-mode</a> <a id='1536' tid='1535' class='u'>+1</a>))
  1967. (<a id='1518' tid='1517' class='u'>defun</a> <a id='1520' tid='1519' class='u'>disable-paredit-mode</a> ()
  1968. <span class='i'>&quot;Turn off pseudo-structural editing of Lisp code.&quot;</span>
  1969. (<a id='1522' tid='1521' class='u'>interactive</a>)
  1970. (<a id='1524' tid='1523' class='u'>paredit-mode</a> <a id='1526' tid='1525' class='u'>-1</a>))
  1971. (<a id='1958' tid='1957' class='u'>defvar</a> <a id='1960' tid='1959' class='u'>paredit-backward-delete-key</a>
  1972. (<a id='1962' tid='1961' class='u'>xcond</a> ((<a id='1964' tid='1963' class='u'>paredit-xemacs-p</a>) <a id='1966' tid='1965' class='u'>&quot;BS&quot;</a>)
  1973. ((<a id='1968' tid='1967' class='u'>paredit-gnu-emacs-p</a>) <a id='1970' tid='1969' class='u'>&quot;DEL&quot;</a>)))
  1974. (<a id='2596' tid='2595' class='u'>defvar</a> <a id='2598' tid='2597' class='u'>paredit-forward-delete-keys</a>
  1975. (<a id='2600' tid='2599' class='u'>xcond</a> ((<a id='2602' tid='2601' class='u'>paredit-xemacs-p</a>) <a id='2604' tid='2603' class='u'>&#39;</a>(<a id='2606' tid='2605' class='u'>&quot;DEL&quot;</a>))
  1976. ((<a id='2608' tid='2607' class='u'>paredit-gnu-emacs-p</a>) <a id='2610' tid='2609' class='u'>&#39;</a>(<a id='2612' tid='2611' class='u'>&quot;&lt;delete&gt;&quot;</a> <a id='2614' tid='2613' class='u'>&quot;&lt;deletechar&gt;&quot;</a>))))
  1977. <span class='i'>;;;; Paredit Keys
  1978. </span>
  1979. <span class='i'>;;; Separating the definition and initialization of this variable
  1980. </span><span class='i'>;;; simplifies the development of paredit, since re-evaluating DEFVAR
  1981. </span><span class='i'>;;; forms doesn&#39;t actually do anything.
  1982. </span>
  1983. (<a id='2200' tid='2199' class='u'>defvar</a> <a id='2202' tid='2201' class='u'>paredit-commands</a> <a id='2204' tid='2203' class='u'>nil</a>
  1984. <a id='2206' tid='2205' class='u'>&quot;List of paredit commands with their keys and examples.&quot;</a>)
  1985. <span class='i'>;;; Each specifier is of the form:
  1986. </span><span class='i'>;;; (key[s] function (example-input example-output) ...)
  1987. </span><span class='i'>;;; where key[s] is either a single string suitable for passing to KBD
  1988. </span><span class='i'>;;; or a list of such strings. Entries in this list may also just be
  1989. </span><span class='i'>;;; strings, in which case they are headings for the next entries.
  1990. </span>
  1991. (<a id='788' tid='787' class='m'>progn</a> (<a id='790' tid='789' class='m'>setq</a> <a id='792' tid='791' class='m'>paredit-commands</a>
  1992. <a id='794' tid='793' class='m'>`</a>(
  1993. <span class='i'>&quot;Basic Insertion Commands&quot;</span>
  1994. <span class='i'>(&quot;(&quot; paredit-open-round
  1995. (&quot;(a b |c d)&quot;
  1996. &quot;(a b (|) c d)&quot;)
  1997. (&quot;(foo \&quot;bar |baz\&quot; quux)&quot;
  1998. &quot;(foo \&quot;bar (|baz\&quot; quux)&quot;))</span>
  1999. <span class='i'>(&quot;)&quot; paredit-close-round
  2000. (&quot;(a b |c )&quot; &quot;(a b c)|&quot;)
  2001. (&quot;; Hello,| world!&quot;
  2002. &quot;; Hello,)| world!&quot;))</span>
  2003. <span class='i'>(&quot;M-)&quot; paredit-close-round-and-newline
  2004. (&quot;(defun f (x| ))&quot;
  2005. &quot;(defun f (x)\n |)&quot;)
  2006. (&quot;; (Foo.|&quot;
  2007. &quot;; (Foo.)|&quot;))</span>
  2008. <span class='i'>(&quot;[&quot; paredit-open-square
  2009. (&quot;(a b |c d)&quot;
  2010. &quot;(a b [|] c d)&quot;)
  2011. (&quot;(foo \&quot;bar |baz\&quot; quux)&quot;
  2012. &quot;(foo \&quot;bar [baz\&quot; quux)&quot;))</span>
  2013. <span class='i'>(&quot;]&quot; paredit-close-square
  2014. (&quot;(define-key keymap [frob| ] &#39;frobnicate)&quot;
  2015. &quot;(define-key keymap [frob]| &#39;frobnicate)&quot;)
  2016. (&quot;; [Bar.|&quot;
  2017. &quot;; [Bar.]|&quot;))</span>
  2018. (<a id='796' tid='795' class='m'>&quot;\&quot;&quot;</a> <a id='798' tid='797' class='m'>paredit-doublequote</a>
  2019. (<a id='800' tid='799' class='m'>&quot;(frob grovel |full lexical)&quot;</a>
  2020. <a id='802' tid='801' class='m'>&quot;(frob grovel \&quot;|\&quot; full lexical)&quot;</a>)
  2021. (<a id='804' tid='803' class='m'>&quot;(foo \&quot;bar |baz\&quot; quux)&quot;</a>
  2022. <a id='806' tid='805' class='m'>&quot;(foo \&quot;bar \\\&quot;|baz\&quot; quux)&quot;</a>))
  2023. (<a id='496' tid='495' class='m'>&quot;M-\&quot;&quot;</a> <a id='498' tid='497' class='m'>paredit-meta-doublequote</a>
  2024. (<a id='500' tid='499' class='m'>&quot;(foo \&quot;bar |baz\&quot; quux)&quot;</a>
  2025. <a id='502' tid='501' class='m'>&quot;(foo \&quot;bar baz\&quot;\n |quux)&quot;</a>)
  2026. (<a id='504' tid='503' class='m'>&quot;(foo |(bar #\\x \&quot;baz \\\\ quux\&quot;) zot)&quot;</a>
  2027. <a id='506' tid='505' class='m'>,</a>(<a id='508' tid='507' class='m'>concat</a> <a id='510' tid='509' class='m'>&quot;(foo \&quot;|(bar #\\\\x \\\&quot;baz \\\\&quot;</a>
  2028. <a id='512' tid='511' class='m'>&quot;\\\\ quux\\\&quot;)\&quot; zot)&quot;</a>)))
  2029. (<a id='394' tid='393' class='m'>&quot;\\&quot;</a> <a id='396' tid='395' class='m'>paredit-backslash</a>
  2030. (<a id='398' tid='397' class='m'>&quot;(string #|)\n ; Escaping character... (x)&quot;</a>
  2031. <a id='400' tid='399' class='m'>&quot;(string #\\x|)&quot;</a>)
  2032. (<a id='402' tid='401' class='m'>&quot;\&quot;foo|bar\&quot;\n ; Escaping character... (\&quot;)&quot;</a>
  2033. <a id='404' tid='403' class='m'>&quot;\&quot;foo\\\&quot;|bar\&quot;&quot;</a>))
  2034. <span class='i'>(&quot;;&quot; paredit-semicolon
  2035. (&quot;|(frob grovel)&quot;
  2036. &quot;;|(frob grovel)&quot;)
  2037. (&quot;(frob |grovel)&quot;
  2038. &quot;(frob ;grovel\n)&quot;)
  2039. (&quot;(frob |grovel (bloit\n zargh))&quot;
  2040. &quot;(frob ;|grovel\n (bloit\n zargh))&quot;)
  2041. (&quot;(frob grovel) |&quot;
  2042. &quot;(frob grovel) ;|&quot;))</span>
  2043. (<a id='306' tid='305' class='m'>&quot;M-;&quot;</a> <a id='308' tid='307' class='m'>paredit-comment-dwim</a>
  2044. (<a id='310' tid='309' class='m'>&quot;(foo |bar) ; baz&quot;</a>
  2045. <a id='312' tid='311' class='m'>&quot;(foo bar) ; |baz&quot;</a>)
  2046. (<a id='314' tid='313' class='m'>&quot;(frob grovel)|&quot;</a>
  2047. <a id='316' tid='315' class='m'>&quot;(frob grovel) ;|&quot;</a>)
  2048. (<a id='318' tid='317' class='m'>&quot; (foo bar)\n|\n (baz quux)&quot;</a>
  2049. <a id='320' tid='319' class='m'>&quot; (foo bar)\n ;; |\n (baz quux)&quot;</a>)
  2050. (<a id='322' tid='321' class='m'>&quot; (foo bar) |(baz quux)&quot;</a>
  2051. <a id='324' tid='323' class='m'>&quot; (foo bar)\n ;; |\n (baz quux)&quot;</a>)
  2052. (<a id='326' tid='325' class='m'>&quot;|(defun hello-world ...)&quot;</a>
  2053. <a id='328' tid='327' class='m'>&quot;;;; |\n(defun hello-world ...)&quot;</a>))
  2054. (<a id='262' tid='261' class='m'>&quot;C-j&quot;</a> <a id='264' tid='263' class='m'>paredit-newline</a>
  2055. (<a id='266' tid='265' class='m'>&quot;(let ((n (frobbotz))) |(display (+ n 1)\nport))&quot;</a>
  2056. <a id='268' tid='267' class='m'>,</a>(<a id='270' tid='269' class='m'>concat</a> <a id='272' tid='271' class='m'>&quot;(let ((n (frobbotz)))&quot;</a>
  2057. <a id='274' tid='273' class='m'>&quot;\n |(display (+ n 1)&quot;</a>
  2058. <a id='276' tid='275' class='m'>&quot;\n port))&quot;</a>)))
  2059. <span class='i'>&quot;Deleting & Killing&quot;</span>
  2060. ((<a id='218' tid='217' class='m'>&quot;C-d&quot;</a> <a id='220' tid='219' class='m'>,</a><a id='222' tid='221' class='m'>@paredit-forward-delete-keys</a>)
  2061. <a id='224' tid='223' class='m'>paredit-forward-delete</a>
  2062. (<a id='226' tid='225' class='m'>&quot;(quu|x \&quot;zot\&quot;)&quot;</a> <a id='228' tid='227' class='m'>&quot;(quu| \&quot;zot\&quot;)&quot;</a>)
  2063. (<a id='230' tid='229' class='m'>&quot;(quux |\&quot;zot\&quot;)&quot;</a>
  2064. <a id='232' tid='231' class='m'>&quot;(quux \&quot;|zot\&quot;)&quot;</a>
  2065. <a id='234' tid='233' class='m'>&quot;(quux \&quot;|ot\&quot;)&quot;</a>)
  2066. (<a id='236' tid='235' class='m'>&quot;(foo (|) bar)&quot;</a> <a id='238' tid='237' class='m'>&quot;(foo | bar)&quot;</a>)
  2067. (<a id='240' tid='239' class='m'>&quot;|(foo bar)&quot;</a> <a id='242' tid='241' class='m'>&quot;(|foo bar)&quot;</a>))
  2068. (<a id='194' tid='193' class='m'>,</a><a id='196' tid='195' class='m'>paredit-backward-delete-key</a>
  2069. <a id='198' tid='197' class='m'>paredit-backward-delete</a>
  2070. (<a id='200' tid='199' class='m'>&quot;(\&quot;zot\&quot; q|uux)&quot;</a> <a id='202' tid='201' class='m'>&quot;(\&quot;zot\&quot; |uux)&quot;</a>)
  2071. (<a id='204' tid='203' class='m'>&quot;(\&quot;zot\&quot;| quux)&quot;</a>
  2072. <a id='206' tid='205' class='m'>&quot;(\&quot;zot|\&quot; quux)&quot;</a>
  2073. <a id='208' tid='207' class='m'>&quot;(\&quot;zo|\&quot; quux)&quot;</a>)
  2074. (<a id='210' tid='209' class='m'>&quot;(foo (|) bar)&quot;</a> <a id='212' tid='211' class='m'>&quot;(foo | bar)&quot;</a>)
  2075. (<a id='214' tid='213' class='m'>&quot;(foo bar)|&quot;</a> <a id='216' tid='215' class='m'>&quot;(foo bar|)&quot;</a>))
  2076. (<a id='174' tid='173' class='m'>&quot;C-k&quot;</a> <a id='176' tid='175' class='m'>paredit-kill</a>
  2077. (<a id='178' tid='177' class='m'>&quot;(foo bar)| ; Useless comment!&quot;</a>
  2078. <a id='180' tid='179' class='m'>&quot;(foo bar)|&quot;</a>)
  2079. (<a id='182' tid='181' class='m'>&quot;(|foo bar) ; Useful comment!&quot;</a>
  2080. <a id='184' tid='183' class='m'>&quot;(|) ; Useful comment!&quot;</a>)
  2081. (<a id='186' tid='185' class='m'>&quot;|(foo bar) ; Useless line!&quot;</a>
  2082. <a id='188' tid='187' class='m'>&quot;|&quot;</a>)
  2083. (<a id='190' tid='189' class='m'>&quot;(foo \&quot;|bar baz\&quot;\n quux)&quot;</a>
  2084. <a id='192' tid='191' class='m'>&quot;(foo \&quot;|\&quot;\n quux)&quot;</a>))
  2085. (<a id='156' tid='155' class='m'>&quot;M-d&quot;</a> <a id='158' tid='157' class='m'>paredit-forward-kill-word</a>
  2086. (<a id='160' tid='159' class='m'>&quot;|(foo bar) ; baz&quot;</a>
  2087. <a id='162' tid='161' class='m'>&quot;(| bar) ; baz&quot;</a>
  2088. <a id='164' tid='163' class='m'>&quot;(|) ; baz&quot;</a>
  2089. <a id='166' tid='165' class='m'>&quot;() ;|&quot;</a>)
  2090. (<a id='168' tid='167' class='m'>&quot;;;;| Frobnicate\n(defun frobnicate ...)&quot;</a>
  2091. <a id='170' tid='169' class='m'>&quot;;;;|\n(defun frobnicate ...)&quot;</a>
  2092. <a id='172' tid='171' class='m'>&quot;;;;\n(| frobnicate ...)&quot;</a>))
  2093. (<a id='136' tid='135' class='m'>,</a>(<a id='138' tid='137' class='m'>concat</a> <a id='140' tid='139' class='m'>&quot;M-&quot;</a> <a id='142' tid='141' class='m'>paredit-backward-delete-key</a>)
  2094. <a id='144' tid='143' class='m'>paredit-backward-kill-word</a>
  2095. (<a id='146' tid='145' class='m'>&quot;(foo bar) ; baz\n(quux)|&quot;</a>
  2096. <a id='148' tid='147' class='m'>&quot;(foo bar) ; baz\n(|)&quot;</a>
  2097. <a id='150' tid='149' class='m'>&quot;(foo bar) ; |\n()&quot;</a>
  2098. <a id='152' tid='151' class='m'>&quot;(foo |) ; \n()&quot;</a>
  2099. <a id='154' tid='153' class='m'>&quot;(|) ; \n()&quot;</a>))
  2100. <span class='i'>&quot;Movement & Navigation&quot;</span>
  2101. (<a id='124' tid='123' class='m'>&quot;C-M-f&quot;</a> <a id='126' tid='125' class='m'>paredit-forward</a>
  2102. (<a id='128' tid='127' class='m'>&quot;(foo |(bar baz) quux)&quot;</a>
  2103. <a id='130' tid='129' class='m'>&quot;(foo (bar baz)| quux)&quot;</a>)
  2104. (<a id='132' tid='131' class='m'>&quot;(foo (bar)|)&quot;</a>
  2105. <a id='134' tid='133' class='m'>&quot;(foo (bar))|&quot;</a>))
  2106. (<a id='112' tid='111' class='m'>&quot;C-M-b&quot;</a> <a id='114' tid='113' class='m'>paredit-backward</a>
  2107. (<a id='116' tid='115' class='m'>&quot;(foo (bar baz)| quux)&quot;</a>
  2108. <a id='118' tid='117' class='m'>&quot;(foo |(bar baz) quux)&quot;</a>)
  2109. (<a id='120' tid='119' class='m'>&quot;(|(foo) bar)&quot;</a>
  2110. <a id='122' tid='121' class='m'>&quot;|((foo) bar)&quot;</a>))
  2111. <span class='i'>(&quot;C-M-u&quot; paredit-backward-up)</span>
  2112. <span class='i'>(&quot;C-M-d&quot; paredit-forward-down)</span>
  2113. <span class='i'>(&quot;C-M-p&quot; paredit-backward-down)</span> <span class='i'>; Built-in, these are FORWARD-
  2114. </span> <span class='i'>(&quot;C-M-n&quot; paredit-forward-up)</span> <span class='i'>; & BACKWARD-LIST, which have
  2115. </span> <span class='i'>; no need given C-M-f & C-M-b.
  2116. </span>
  2117. <span class='i'>&quot;Depth-Changing Commands&quot;</span>
  2118. <span class='i'>(&quot;M-(&quot; paredit-wrap-round
  2119. (&quot;(foo |bar baz)&quot;
  2120. &quot;(foo (|bar) baz)&quot;))</span>
  2121. <span class='i'>(&quot;M-s&quot; paredit-splice-sexp
  2122. (&quot;(foo (bar| baz) quux)&quot;
  2123. &quot;(foo bar| baz quux)&quot;))</span>
  2124. ((<a id='102' tid='101' class='m'>&quot;M-&lt;up&gt;&quot;</a> <a id='104' tid='103' class='m'>&quot;ESC &lt;up&gt;&quot;</a>)
  2125. <a id='106' tid='105' class='m'>paredit-splice-sexp-killing-backward</a>
  2126. (<a id='108' tid='107' class='m'>&quot;(foo (let ((x 5)) |(sqrt n)) bar)&quot;</a>
  2127. <a id='110' tid='109' class='m'>&quot;(foo (sqrt n) bar)&quot;</a>))
  2128. ((<a id='92' tid='91' class='m'>&quot;M-&lt;down&gt;&quot;</a> <a id='94' tid='93' class='m'>&quot;ESC &lt;down&gt;&quot;</a>)
  2129. <a id='96' tid='95' class='m'>paredit-splice-sexp-killing-forward</a>
  2130. (<a id='98' tid='97' class='m'>&quot;(a (b c| d e) f)&quot;</a>
  2131. <a id='100' tid='99' class='m'>&quot;(a b c f)&quot;</a>))
  2132. (<a id='82' tid='81' class='m'>&quot;M-r&quot;</a> <a id='84' tid='83' class='m'>paredit-raise-sexp</a>
  2133. (<a id='86' tid='85' class='m'>&quot;(dynamic-wind in (lambda () |body) out)&quot;</a>
  2134. <a id='88' tid='87' class='m'>&quot;(dynamic-wind in |body out)&quot;</a>
  2135. <a id='90' tid='89' class='m'>&quot;|body&quot;</a>))
  2136. <span class='i'>&quot;Barfage & Slurpage&quot;</span>
  2137. ((<a id='68' tid='67' class='m'>&quot;C-)&quot;</a> <a id='70' tid='69' class='m'>&quot;C-&lt;right&gt;&quot;</a>)
  2138. <a id='72' tid='71' class='m'>paredit-forward-slurp-sexp</a>
  2139. (<a id='74' tid='73' class='m'>&quot;(foo (bar |baz) quux zot)&quot;</a>
  2140. <a id='76' tid='75' class='m'>&quot;(foo (bar |baz quux) zot)&quot;</a>)
  2141. (<a id='78' tid='77' class='m'>&quot;(a b ((c| d)) e f)&quot;</a>
  2142. <a id='80' tid='79' class='m'>&quot;(a b ((c| d) e) f)&quot;</a>))
  2143. ((<a id='58' tid='57' class='m'>&quot;C-}&quot;</a> <a id='60' tid='59' class='m'>&quot;C-&lt;left&gt;&quot;</a>)
  2144. <a id='62' tid='61' class='m'>paredit-forward-barf-sexp</a>
  2145. (<a id='64' tid='63' class='m'>&quot;(foo (bar |baz quux) zot)&quot;</a>
  2146. <a id='66' tid='65' class='m'>&quot;(foo (bar |baz) quux zot)&quot;</a>))
  2147. ((<a id='42' tid='41' class='m'>&quot;C-(&quot;</a> <a id='44' tid='43' class='m'>&quot;C-M-&lt;left&gt;&quot;</a> <a id='46' tid='45' class='m'>&quot;ESC C-&lt;left&gt;&quot;</a>)
  2148. <a id='48' tid='47' class='m'>paredit-backward-slurp-sexp</a>
  2149. (<a id='50' tid='49' class='m'>&quot;(foo bar (baz| quux) zot)&quot;</a>
  2150. <a id='52' tid='51' class='m'>&quot;(foo (bar baz| quux) zot)&quot;</a>)
  2151. (<a id='54' tid='53' class='m'>&quot;(a b ((c| d)) e f)&quot;</a>
  2152. <a id='56' tid='55' class='m'>&quot;(a (b (c| d)) e f)&quot;</a>))
  2153. ((<a id='30' tid='29' class='m'>&quot;C-{&quot;</a> <a id='32' tid='31' class='m'>&quot;C-M-&lt;right&gt;&quot;</a> <a id='34' tid='33' class='m'>&quot;ESC C-&lt;right&gt;&quot;</a>)
  2154. <a id='36' tid='35' class='m'>paredit-backward-barf-sexp</a>
  2155. (<a id='38' tid='37' class='m'>&quot;(foo (bar baz |quux) zot)&quot;</a>
  2156. <a id='40' tid='39' class='m'>&quot;(foo bar (baz |quux) zot)&quot;</a>))
  2157. <span class='i'>&quot;Miscellaneous Commands&quot;</span>
  2158. (<a id='18' tid='17' class='m'>&quot;M-S&quot;</a> <a id='20' tid='19' class='m'>paredit-split-sexp</a>
  2159. (<a id='22' tid='21' class='m'>&quot;(hello| world)&quot;</a>
  2160. <a id='24' tid='23' class='m'>&quot;(hello)| (world)&quot;</a>)
  2161. (<a id='26' tid='25' class='m'>&quot;\&quot;Hello, |world!\&quot;&quot;</a>
  2162. <a id='28' tid='27' class='m'>&quot;\&quot;Hello, \&quot;| \&quot;world!\&quot;&quot;</a>))
  2163. (<a id='2' tid='1' class='m'>&quot;M-J&quot;</a> <a id='4' tid='3' class='m'>paredit-join-sexps</a>
  2164. (<a id='6' tid='5' class='m'>&quot;(hello)| (world)&quot;</a>
  2165. <a id='8' tid='7' class='m'>&quot;(hello| world)&quot;</a>)
  2166. (<a id='10' tid='9' class='m'>&quot;\&quot;Hello, \&quot;| \&quot;world!\&quot;&quot;</a>
  2167. <a id='12' tid='11' class='m'>&quot;\&quot;Hello, |world!\&quot;&quot;</a>)
  2168. (<a id='14' tid='13' class='m'>&quot;hello-\n| world&quot;</a>
  2169. <a id='16' tid='15' class='m'>&quot;hello-|world&quot;</a>))
  2170. <span class='i'>(&quot;C-c C-M-l&quot; paredit-recentre-on-sexp)</span>
  2171. <span class='i'>(&quot;M-q&quot; paredit-reindent-defun)</span>
  2172. ))
  2173. <a id='808' tid='807' class='m'>nil</a>) <span class='i'>; end of PROGN
  2174. </span>
  2175. <span class='i'>;;;;; Command Examples
  2176. </span>
  2177. (<a id='4636' tid='4635' class='u'>eval-and-compile</a>
  2178. (<a id='4638' tid='4637' class='u'>defmacro</a> <a id='4640' tid='4639' class='u'>paredit-do-commands</a> (<a id='4642' tid='4641' class='u'>vars</a> <a id='4644' tid='4643' class='u'>string-case</a> <a id='4646' tid='4645' class='u'>&rest</a> <a id='4648' tid='4647' class='u'>body</a>)
  2179. (<a id='4650' tid='4649' class='u'>let</a> ((<a id='4652' tid='4651' class='u'>spec</a> (<a id='4654' tid='4653' class='u'>nth</a> <a id='4656' tid='4655' class='u'>0</a> <a id='4658' tid='4657' class='u'>vars</a>))
  2180. (<a id='4660' tid='4659' class='u'>keys</a> (<a id='4662' tid='4661' class='u'>nth</a> <a id='4664' tid='4663' class='u'>1</a> <a id='4666' tid='4665' class='u'>vars</a>))
  2181. (<a id='4668' tid='4667' class='u'>fn</a> (<a id='4670' tid='4669' class='u'>nth</a> <a id='4672' tid='4671' class='u'>2</a> <a id='4674' tid='4673' class='u'>vars</a>))
  2182. (<a id='4676' tid='4675' class='u'>examples</a> (<a id='4678' tid='4677' class='u'>nth</a> <a id='4680' tid='4679' class='u'>3</a> <a id='4682' tid='4681' class='u'>vars</a>)))
  2183. <a id='4684' tid='4683' class='u'>`</a>(<a id='4686' tid='4685' class='u'>dolist</a> (<a id='4688' tid='4687' class='u'>,</a><a id='4690' tid='4689' class='u'>spec</a> <a id='4692' tid='4691' class='u'>paredit-commands</a>)
  2184. (<a id='4694' tid='4693' class='u'>if</a> (<a id='4696' tid='4695' class='u'>stringp</a> <a id='4698' tid='4697' class='u'>,</a><a id='4700' tid='4699' class='u'>spec</a>)
  2185. <a id='4702' tid='4701' class='u'>,</a><a id='4704' tid='4703' class='u'>string-case</a>
  2186. (<a id='4706' tid='4705' class='u'>let</a> ((<a id='4708' tid='4707' class='u'>,</a><a id='4710' tid='4709' class='u'>keys</a> (<a id='4712' tid='4711' class='u'>let</a> ((<a id='4714' tid='4713' class='u'>k</a> (<a id='4716' tid='4715' class='u'>car</a> <a id='4718' tid='4717' class='u'>,</a><a id='4720' tid='4719' class='u'>spec</a>)))
  2187. (<a id='4722' tid='4721' class='u'>cond</a> ((<a id='4724' tid='4723' class='u'>stringp</a> <a id='4726' tid='4725' class='u'>k</a>) (<a id='4728' tid='4727' class='u'>list</a> <a id='4730' tid='4729' class='u'>k</a>))
  2188. ((<a id='4732' tid='4731' class='u'>listp</a> <a id='4734' tid='4733' class='u'>k</a>) <a id='4736' tid='4735' class='u'>k</a>)
  2189. (<a id='4738' tid='4737' class='u'>t</a> (<a id='4740' tid='4739' class='u'>error</a> <a id='4742' tid='4741' class='u'>&quot;Invalid paredit command %s.&quot;</a>
  2190. <a id='4744' tid='4743' class='u'>,</a><a id='4746' tid='4745' class='u'>spec</a>)))))
  2191. (<a id='4748' tid='4747' class='u'>,</a><a id='4750' tid='4749' class='u'>fn</a> (<a id='4752' tid='4751' class='u'>cadr</a> <a id='4754' tid='4753' class='u'>,</a><a id='4756' tid='4755' class='u'>spec</a>))
  2192. (<a id='4758' tid='4757' class='u'>,</a><a id='4760' tid='4759' class='u'>examples</a> (<a id='4762' tid='4761' class='u'>cddr</a> <a id='4764' tid='4763' class='u'>,</a><a id='4766' tid='4765' class='u'>spec</a>)))
  2193. <a id='4768' tid='4767' class='u'>,</a><a id='4770' tid='4769' class='u'>@body</a>)))))
  2194. (<a id='4772' tid='4771' class='u'>put</a> <a id='4774' tid='4773' class='u'>&#39;</a><a id='4776' tid='4775' class='u'>paredit-do-commands</a> <a id='4778' tid='4777' class='u'>&#39;</a><a id='4780' tid='4779' class='u'>lisp-indent-function</a> <a id='4782' tid='4781' class='u'>2</a>))
  2195. (<a id='2248' tid='2247' class='u'>defun</a> <a id='2250' tid='2249' class='u'>paredit-define-keys</a> ()
  2196. (<a id='2252' tid='2251' class='u'>paredit-do-commands</a> (<a id='2254' tid='2253' class='u'>spec</a> <a id='2256' tid='2255' class='u'>keys</a> <a id='2258' tid='2257' class='u'>fn</a> <a id='2260' tid='2259' class='u'>examples</a>)
  2197. <a id='2262' tid='2261' class='u'>nil</a> <a id='2264' tid='2263' class='u'>; string case
  2198. </a> (<a id='2266' tid='2265' class='u'>dolist</a> (<a id='2268' tid='2267' class='u'>key</a> <a id='2270' tid='2269' class='u'>keys</a>)
  2199. (<a id='2272' tid='2271' class='u'>define-key</a> <a id='2274' tid='2273' class='u'>paredit-mode-map</a> (<a id='2276' tid='2275' class='u'>read-kbd-macro</a> <a id='2278' tid='2277' class='u'>key</a>) <a id='2280' tid='2279' class='u'>fn</a>))))
  2200. (<a id='3106' tid='3105' class='u'>defun</a> <a id='3108' tid='3107' class='u'>paredit-function-documentation</a> (<a id='3110' tid='3109' class='u'>fn</a>)
  2201. (<a id='3112' tid='3111' class='u'>let</a> ((<a id='3114' tid='3113' class='u'>original-doc</a> (<a id='3116' tid='3115' class='u'>get</a> <a id='3118' tid='3117' class='u'>fn</a> <a id='3120' tid='3119' class='u'>&#39;</a><a id='3122' tid='3121' class='u'>paredit-original-documentation</a>))
  2202. (<a id='3124' tid='3123' class='u'>doc</a> (<a id='3126' tid='3125' class='u'>documentation</a> <a id='3128' tid='3127' class='u'>fn</a> <a id='3130' tid='3129' class='u'>&#39;</a><a id='3132' tid='3131' class='u'>function-documentation</a>)))
  2203. (<a id='3134' tid='3133' class='u'>or</a> <a id='3136' tid='3135' class='u'>original-doc</a>
  2204. (<a id='3138' tid='3137' class='u'>progn</a> (<a id='3140' tid='3139' class='u'>put</a> <a id='3142' tid='3141' class='u'>fn</a> <a id='3144' tid='3143' class='u'>&#39;</a><a id='3146' tid='3145' class='u'>paredit-original-documentation</a> <a id='3148' tid='3147' class='u'>doc</a>)
  2205. <a id='3150' tid='3149' class='u'>doc</a>))))
  2206. (<a id='1604' tid='1603' class='u'>defun</a> <a id='1606' tid='1605' class='u'>paredit-annotate-mode-with-examples</a> ()
  2207. (<a id='1608' tid='1607' class='u'>let</a> ((<a id='1610' tid='1609' class='u'>contents</a>
  2208. (<a id='1612' tid='1611' class='u'>list</a> (<a id='1614' tid='1613' class='u'>paredit-function-documentation</a> <a id='1616' tid='1615' class='u'>&#39;</a><a id='1618' tid='1617' class='u'>paredit-mode</a>))))
  2209. (<a id='1620' tid='1619' class='u'>paredit-do-commands</a> (<a id='1622' tid='1621' class='u'>spec</a> <a id='1624' tid='1623' class='u'>keys</a> <a id='1626' tid='1625' class='u'>fn</a> <a id='1628' tid='1627' class='u'>examples</a>)
  2210. (<a id='1630' tid='1629' class='u'>push</a> (<a id='1632' tid='1631' class='u'>concat</a> <a id='1634' tid='1633' class='u'>&quot;\n \n&quot;</a> <a id='1636' tid='1635' class='u'>spec</a> <a id='1638' tid='1637' class='u'>&quot;\n&quot;</a>)
  2211. <a id='1640' tid='1639' class='u'>contents</a>)
  2212. (<a id='1642' tid='1641' class='u'>let</a> ((<a id='1644' tid='1643' class='u'>name</a> (<a id='1646' tid='1645' class='u'>symbol-name</a> <a id='1648' tid='1647' class='u'>fn</a>)))
  2213. (<a id='1650' tid='1649' class='u'>if</a> (<a id='1652' tid='1651' class='u'>string-match</a> (<a id='1654' tid='1653' class='u'>symbol-name</a> <a id='1656' tid='1655' class='u'>&#39;</a><a id='1658' tid='1657' class='u'>paredit-</a>) <a id='1660' tid='1659' class='u'>name</a>)
  2214. (<a id='1662' tid='1661' class='u'>push</a> (<a id='1664' tid='1663' class='u'>concat</a> <a id='1666' tid='1665' class='u'>&quot;\n\n\\[&quot;</a> <a id='1668' tid='1667' class='u'>name</a> <a id='1670' tid='1669' class='u'>&quot;]\t&quot;</a> <a id='1672' tid='1671' class='u'>name</a>
  2215. (<a id='1674' tid='1673' class='u'>if</a> <a id='1676' tid='1675' class='u'>examples</a>
  2216. (<a id='1678' tid='1677' class='u'>mapconcat</a> (<a id='1680' tid='1679' class='u'>lambda</a> (<a id='1682' tid='1681' class='u'>example</a>)
  2217. (<a id='1684' tid='1683' class='u'>concat</a>
  2218. <a id='1686' tid='1685' class='u'>&quot;\n&quot;</a>
  2219. (<a id='1688' tid='1687' class='u'>mapconcat</a> <a id='1690' tid='1689' class='u'>&#39;</a><a id='1692' tid='1691' class='u'>identity</a>
  2220. <a id='1694' tid='1693' class='u'>example</a>
  2221. <a id='1696' tid='1695' class='u'>&quot;\n ---&gt;\n&quot;</a>)
  2222. <a id='1698' tid='1697' class='u'>&quot;\n&quot;</a>))
  2223. <a id='1700' tid='1699' class='u'>examples</a>
  2224. <a id='1702' tid='1701' class='u'>&quot;&quot;</a>)
  2225. <a id='1704' tid='1703' class='u'>&quot;\n (no examples)\n&quot;</a>))
  2226. <a id='1706' tid='1705' class='u'>contents</a>))))
  2227. (<a id='1708' tid='1707' class='u'>put</a> <a id='1710' tid='1709' class='u'>&#39;</a><a id='1712' tid='1711' class='u'>paredit-mode</a> <a id='1714' tid='1713' class='u'>&#39;</a><a id='1716' tid='1715' class='u'>function-documentation</a>
  2228. (<a id='1718' tid='1717' class='u'>apply</a> <a id='1720' tid='1719' class='u'>&#39;</a><a id='1722' tid='1721' class='u'>concat</a> (<a id='1724' tid='1723' class='u'>reverse</a> <a id='1726' tid='1725' class='u'>contents</a>))))
  2229. <a id='1728' tid='1727' class='u'>;; PUT returns the huge string we just constructed, which we don&#39;t
  2230. </a> <a id='1730' tid='1729' class='u'>;; want it to return.
  2231. </a> <a id='1732' tid='1731' class='u'>nil</a>)
  2232. (<a id='1538' tid='1537' class='u'>defun</a> <a id='1540' tid='1539' class='u'>paredit-annotate-functions-with-examples</a> ()
  2233. (<a id='1542' tid='1541' class='u'>paredit-do-commands</a> (<a id='1544' tid='1543' class='u'>spec</a> <a id='1546' tid='1545' class='u'>keys</a> <a id='1548' tid='1547' class='u'>fn</a> <a id='1550' tid='1549' class='u'>examples</a>)
  2234. <a id='1552' tid='1551' class='u'>nil</a> <a id='1554' tid='1553' class='u'>; string case
  2235. </a> (<a id='1556' tid='1555' class='u'>put</a> <a id='1558' tid='1557' class='u'>fn</a> <a id='1560' tid='1559' class='u'>&#39;</a><a id='1562' tid='1561' class='u'>function-documentation</a>
  2236. (<a id='1564' tid='1563' class='u'>concat</a> (<a id='1566' tid='1565' class='u'>paredit-function-documentation</a> <a id='1568' tid='1567' class='u'>fn</a>)
  2237. <a id='1570' tid='1569' class='u'>&quot;\n\n\\&lt;paredit-mode-map&gt;\\[&quot;</a> (<a id='1572' tid='1571' class='u'>symbol-name</a> <a id='1574' tid='1573' class='u'>fn</a>) <a id='1576' tid='1575' class='u'>&quot;]\n&quot;</a>
  2238. (<a id='1578' tid='1577' class='u'>mapconcat</a> (<a id='1580' tid='1579' class='u'>lambda</a> (<a id='1582' tid='1581' class='u'>example</a>)
  2239. (<a id='1584' tid='1583' class='u'>concat</a> <a id='1586' tid='1585' class='u'>&quot;\n&quot;</a>
  2240. (<a id='1588' tid='1587' class='u'>mapconcat</a> <a id='1590' tid='1589' class='u'>&#39;</a><a id='1592' tid='1591' class='u'>identity</a>
  2241. <a id='1594' tid='1593' class='u'>example</a>
  2242. <a id='1596' tid='1595' class='u'>&quot;\n -&gt;\n&quot;</a>)
  2243. <a id='1598' tid='1597' class='u'>&quot;\n&quot;</a>))
  2244. <a id='1600' tid='1599' class='u'>examples</a>
  2245. <a id='1602' tid='1601' class='u'>&quot;&quot;</a>)))))
  2246. <a id='4784' tid='4783' class='u'>;;;;; HTML Examples
  2247. </a>
  2248. (<a id='3326' tid='3325' class='u'>defun</a> <a id='3328' tid='3327' class='u'>paredit-insert-html-examples</a> ()
  2249. <a id='3330' tid='3329' class='u'>&quot;Insert HTML for a paredit quick reference table.&quot;</a>
  2250. (<a id='3332' tid='3331' class='u'>interactive</a>)
  2251. (<a id='3334' tid='3333' class='u'>let</a> ((<a id='3336' tid='3335' class='u'>insert-lines</a>
  2252. (<a id='3338' tid='3337' class='u'>lambda</a> (<a id='3340' tid='3339' class='u'>&rest</a> <a id='3342' tid='3341' class='u'>lines</a>)
  2253. (<a id='3344' tid='3343' class='u'>mapc</a> (<a id='3346' tid='3345' class='u'>lambda</a> (<a id='3348' tid='3347' class='u'>line</a>) (<a id='3350' tid='3349' class='u'>insert</a> <a id='3352' tid='3351' class='u'>line</a>) (<a id='3354' tid='3353' class='u'>newline</a>))
  2254. <a id='3356' tid='3355' class='u'>lines</a>)))
  2255. (<a id='3358' tid='3357' class='u'>html-keys</a>
  2256. (<a id='3360' tid='3359' class='u'>lambda</a> (<a id='3362' tid='3361' class='u'>keys</a>)
  2257. (<a id='3364' tid='3363' class='u'>mapconcat</a> <a id='3366' tid='3365' class='u'>&#39;</a><a id='3368' tid='3367' class='u'>paredit-html-quote</a> <a id='3370' tid='3369' class='u'>keys</a> <a id='3372' tid='3371' class='u'>&quot;, &quot;</a>)))
  2258. (<a id='3374' tid='3373' class='u'>html-example</a>
  2259. (<a id='3376' tid='3375' class='u'>lambda</a> (<a id='3378' tid='3377' class='u'>example</a>)
  2260. (<a id='3380' tid='3379' class='u'>concat</a> <a id='3382' tid='3381' class='u'>&quot;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;pre&gt;&quot;</a>
  2261. (<a id='3384' tid='3383' class='u'>mapconcat</a> <a id='3386' tid='3385' class='u'>&#39;</a><a id='3388' tid='3387' class='u'>paredit-html-quote</a>
  2262. <a id='3390' tid='3389' class='u'>example</a>
  2263. (<a id='3392' tid='3391' class='u'>concat</a> <a id='3394' tid='3393' class='u'>&quot;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&quot;</a>
  2264. <a id='3396' tid='3395' class='u'>&quot;&nbsp;&nbsp;&nbsp;&nbsp;---&gt;&quot;</a>
  2265. <a id='3398' tid='3397' class='u'>&quot;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;pre&gt;&quot;</a>))
  2266. <a id='3400' tid='3399' class='u'>&quot;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;</a>)))
  2267. (<a id='3402' tid='3401' class='u'>firstp</a> <a id='3404' tid='3403' class='u'>t</a>))
  2268. (<a id='3406' tid='3405' class='u'>paredit-do-commands</a> (<a id='3408' tid='3407' class='u'>spec</a> <a id='3410' tid='3409' class='u'>keys</a> <a id='3412' tid='3411' class='u'>fn</a> <a id='3414' tid='3413' class='u'>examples</a>)
  2269. (<a id='3416' tid='3415' class='u'>progn</a> (<a id='3418' tid='3417' class='u'>if</a> (<a id='3420' tid='3419' class='u'>not</a> <a id='3422' tid='3421' class='u'>firstp</a>)
  2270. (<a id='3424' tid='3423' class='u'>insert</a> <a id='3426' tid='3425' class='u'>&quot;&lt;/table&gt;\n&quot;</a>)
  2271. (<a id='3428' tid='3427' class='u'>setq</a> <a id='3430' tid='3429' class='u'>firstp</a> <a id='3432' tid='3431' class='u'>nil</a>))
  2272. (<a id='3434' tid='3433' class='u'>funcall</a> <a id='3436' tid='3435' class='u'>insert-lines</a>
  2273. (<a id='3438' tid='3437' class='u'>concat</a> <a id='3440' tid='3439' class='u'>&quot;&lt;h3&gt;&quot;</a> <a id='3442' tid='3441' class='u'>spec</a> <a id='3444' tid='3443' class='u'>&quot;&lt;/h3&gt;&quot;</a>)
  2274. <a id='3446' tid='3445' class='u'>&quot;&lt;table border=\&quot;1\&quot; cellpadding=\&quot;1\&quot;&gt;&quot;</a>
  2275. <a id='3448' tid='3447' class='u'>&quot; &lt;tr&gt;&quot;</a>
  2276. <a id='3450' tid='3449' class='u'>&quot; &lt;th&gt;Command&lt;/th&gt;&quot;</a>
  2277. <a id='3452' tid='3451' class='u'>&quot; &lt;th&gt;Keys&lt;/th&gt;&quot;</a>
  2278. <a id='3454' tid='3453' class='u'>&quot; &lt;th&gt;Examples&lt;/th&gt;&quot;</a>
  2279. <a id='3456' tid='3455' class='u'>&quot; &lt;/tr&gt;&quot;</a>))
  2280. (<a id='3458' tid='3457' class='u'>let</a> ((<a id='3460' tid='3459' class='u'>name</a> (<a id='3462' tid='3461' class='u'>symbol-name</a> <a id='3464' tid='3463' class='u'>fn</a>)))
  2281. (<a id='3466' tid='3465' class='u'>if</a> (<a id='3468' tid='3467' class='u'>string-match</a> (<a id='3470' tid='3469' class='u'>symbol-name</a> <a id='3472' tid='3471' class='u'>&#39;</a><a id='3474' tid='3473' class='u'>paredit-</a>) <a id='3476' tid='3475' class='u'>name</a>)
  2282. (<a id='3478' tid='3477' class='u'>funcall</a> <a id='3480' tid='3479' class='u'>insert-lines</a>
  2283. <a id='3482' tid='3481' class='u'>&quot; &lt;tr&gt;&quot;</a>
  2284. (<a id='3484' tid='3483' class='u'>concat</a> <a id='3486' tid='3485' class='u'>&quot; &lt;td&gt;&lt;tt&gt;&quot;</a> <a id='3488' tid='3487' class='u'>name</a> <a id='3490' tid='3489' class='u'>&quot;&lt;/tt&gt;&lt;/td&gt;&quot;</a>)
  2285. (<a id='3492' tid='3491' class='u'>concat</a> <a id='3494' tid='3493' class='u'>&quot; &lt;td align=\&quot;center\&quot;&gt;&quot;</a>
  2286. (<a id='3496' tid='3495' class='u'>funcall</a> <a id='3498' tid='3497' class='u'>html-keys</a> <a id='3500' tid='3499' class='u'>keys</a>)
  2287. <a id='3502' tid='3501' class='u'>&quot;&lt;/td&gt;&quot;</a>)
  2288. (<a id='3504' tid='3503' class='u'>concat</a> <a id='3506' tid='3505' class='u'>&quot; &lt;td&gt;&quot;</a>
  2289. (<a id='3508' tid='3507' class='u'>if</a> <a id='3510' tid='3509' class='u'>examples</a>
  2290. (<a id='3512' tid='3511' class='u'>mapconcat</a> <a id='3514' tid='3513' class='u'>html-example</a> <a id='3516' tid='3515' class='u'>examples</a>
  2291. <a id='3518' tid='3517' class='u'>&quot;&lt;hr&gt;&quot;</a>)
  2292. <a id='3520' tid='3519' class='u'>&quot;(no examples)&quot;</a>)
  2293. <a id='3522' tid='3521' class='u'>&quot;&lt;/td&gt;&quot;</a>)
  2294. <a id='3524' tid='3523' class='u'>&quot; &lt;/tr&gt;&quot;</a>)))))
  2295. (<a id='3526' tid='3525' class='u'>insert</a> <a id='3528' tid='3527' class='u'>&quot;&lt;/table&gt;\n&quot;</a>))
  2296. (<a id='3152' tid='3151' class='u'>defun</a> <a id='3154' tid='3153' class='u'>paredit-html-quote</a> (<a id='3156' tid='3155' class='u'>string</a>)
  2297. (<a id='3158' tid='3157' class='u'>with-temp-buffer</a>
  2298. (<a id='3160' tid='3159' class='u'>dotimes</a> (<a id='3162' tid='3161' class='u'>i</a> (<a id='3164' tid='3163' class='u'>length</a> <a id='3166' tid='3165' class='u'>string</a>))
  2299. (<a id='3168' tid='3167' class='u'>insert</a> (<a id='3170' tid='3169' class='u'>let</a> ((<a id='3172' tid='3171' class='u'>c</a> (<a id='3174' tid='3173' class='u'>elt</a> <a id='3176' tid='3175' class='u'>string</a> <a id='3178' tid='3177' class='u'>i</a>)))
  2300. (<a id='3180' tid='3179' class='u'>cond</a> ((<a id='3182' tid='3181' class='u'>eq</a> <a id='3184' tid='3183' class='u'>c</a> <a id='3186' tid='3185' class='u'>?\&lt;</a>) <a id='3188' tid='3187' class='u'>&quot;&lt;&quot;</a>)
  2301. ((<a id='3190' tid='3189' class='u'>eq</a> <a id='3192' tid='3191' class='u'>c</a> <a id='3194' tid='3193' class='u'>?\&gt;</a>) <a id='3196' tid='3195' class='u'>&quot;&gt;&quot;</a>)
  2302. ((<a id='3198' tid='3197' class='u'>eq</a> <a id='3200' tid='3199' class='u'>c</a> <a id='3202' tid='3201' class='u'>?\&</a>) <a id='3204' tid='3203' class='u'>&quot;&amp;&quot;</a>)
  2303. ((<a id='3206' tid='3205' class='u'>eq</a> <a id='3208' tid='3207' class='u'>c</a> <a id='3210' tid='3209' class='u'>?\&#39;</a>) <a id='3212' tid='3211' class='u'>&quot;&apos;&quot;</a>)
  2304. ((<a id='3214' tid='3213' class='u'>eq</a> <a id='3216' tid='3215' class='u'>c</a> <a id='3218' tid='3217' class='u'>?\&quot;</a>) <a id='3220' tid='3219' class='u'>&quot;&quot;&quot;</a>)
  2305. (<a id='3222' tid='3221' class='u'>t</a> <a id='3224' tid='3223' class='u'>c</a>)))))
  2306. (<a id='3226' tid='3225' class='u'>buffer-string</a>)))
  2307. <a id='4786' tid='4785' class='u'>;;;; Delimiter Insertion
  2308. </a>
  2309. (<a id='828' tid='827' class='m'>eval-and-compile</a>
  2310. (<a id='810' tid='809' class='m'>defun</a> <a id='812' tid='811' class='m'>paredit-conc-name</a> (<a id='814' tid='813' class='m'>&rest</a> <a id='816' tid='815' class='m'>strings</a>)
  2311. (<a id='818' tid='817' class='m'>intern</a> (<a id='820' tid='819' class='m'>apply</a> <a id='822' tid='821' class='m'>&#39;</a><a id='824' tid='823' class='m'>concat</a> <a id='826' tid='825' class='m'>strings</a>)))
  2312. (<a id='830' tid='829' class='m'>defmacro</a> <a id='832' tid='831' class='m'>define-paredit-pair</a> (<a id='834' tid='833' class='m'>open</a> <a id='836' tid='835' class='m'>close</a> <a id='838' tid='837' class='m'>name</a>)
  2313. <a id='840' tid='839' class='m'>`</a>(<span class='i'>progn</span>
  2314. (<a id='842' tid='841' class='m'>defun</a> <a id='844' tid='843' class='m'>,</a>(<a id='846' tid='845' class='m'>paredit-conc-name</a> <a id='848' tid='847' class='m'>&quot;paredit-open-&quot;</a> <a id='850' tid='849' class='m'>name</a>) (<a id='852' tid='851' class='m'>&optional</a> <a id='854' tid='853' class='m'>n</a>)
  2315. <a id='856' tid='855' class='m'>,</a>(<a id='858' tid='857' class='m'>concat</a> <a id='860' tid='859' class='m'>&quot;Insert a balanced &quot;</a> <a id='862' tid='861' class='m'>name</a> <a id='864' tid='863' class='m'>&quot; pair.
  2316. With a prefix argument N, put the closing &quot;</a> <a id='866' tid='865' class='m'>name</a> <a id='868' tid='867' class='m'>&quot; after N
  2317. S-expressions forward.
  2318. If the region is active, `transient-mark-mode&#39; is enabled, and the
  2319. region&#39;s start and end fall in the same parenthesis depth, insert a
  2320. &quot;</a> <a id='870' tid='869' class='m'>name</a> <a id='872' tid='871' class='m'>&quot; pair around the region.
  2321. If in a string or a comment, insert a single &quot;</a> <a id='874' tid='873' class='m'>name</a> <a id='876' tid='875' class='m'>&quot;.
  2322. If in a character literal, do nothing. This prevents changing what was
  2323. in the character literal to a meaningful delimiter unintentionally.&quot;</a>)
  2324. (<a id='878' tid='877' class='m'>interactive</a> <a id='880' tid='879' class='m'>&quot;P&quot;</a>)
  2325. (<a id='882' tid='881' class='m'>cond</a> ((<a id='884' tid='883' class='m'>or</a> (<a id='886' tid='885' class='m'>paredit-in-string-p</a>)
  2326. (<a id='888' tid='887' class='m'>paredit-in-comment-p</a>))
  2327. (<a id='890' tid='889' class='m'>insert</a> <a id='892' tid='891' class='m'>,</a><a id='894' tid='893' class='m'>open</a>))
  2328. ((<a id='896' tid='895' class='m'>not</a> (<a id='898' tid='897' class='m'>paredit-in-char-p</a>))
  2329. (<a id='900' tid='899' class='m'>paredit-insert-pair</a> <a id='902' tid='901' class='m'>n</a> <a id='904' tid='903' class='m'>,</a><a id='906' tid='905' class='m'>open</a> <a id='908' tid='907' class='m'>,</a><a id='910' tid='909' class='m'>close</a> <a id='912' tid='911' class='m'>&#39;</a><a id='914' tid='913' class='m'>goto-char</a>))))
  2330. (<a id='514' tid='513' class='m'>defun</a> <a id='516' tid='515' class='m'>,</a>(<a id='518' tid='517' class='m'>paredit-conc-name</a> <a id='520' tid='519' class='m'>&quot;paredit-close-&quot;</a> <a id='522' tid='521' class='m'>name</a>) ()
  2331. <a id='524' tid='523' class='m'>,</a>(<a id='526' tid='525' class='m'>concat</a> <a id='528' tid='527' class='m'>&quot;Move past one closing delimiter and reindent.
  2332. \(Agnostic to the specific closing delimiter.)
  2333. If in a string or comment, insert a single closing &quot;</a> <a id='530' tid='529' class='m'>name</a> <a id='532' tid='531' class='m'>&quot;.
  2334. If in a character literal, do nothing. This prevents changing what was
  2335. in the character literal to a meaningful delimiter unintentionally.&quot;</a>)
  2336. (<a id='534' tid='533' class='m'>interactive</a>)
  2337. (<a id='536' tid='535' class='m'>paredit-move-past-close</a> <a id='538' tid='537' class='m'>,</a><a id='540' tid='539' class='m'>close</a>))
  2338. (<a id='406' tid='405' class='m'>defun</a> <a id='408' tid='407' class='m'>,</a>(<a id='410' tid='409' class='m'>paredit-conc-name</a> <a id='412' tid='411' class='m'>&quot;paredit-close-&quot;</a> <a id='414' tid='413' class='m'>name</a> <a id='416' tid='415' class='m'>&quot;-and-newline&quot;</a>) ()
  2339. <a id='418' tid='417' class='m'>,</a>(<a id='420' tid='419' class='m'>concat</a> <a id='422' tid='421' class='m'>&quot;Move past one closing delimiter, add a newline,&quot;</a>
  2340. <a id='424' tid='423' class='m'>&quot; and reindent.
  2341. If there was a margin comment after the closing delimiter, preserve it
  2342. on the same line.&quot;</a>)
  2343. (<a id='426' tid='425' class='m'>interactive</a>)
  2344. (<a id='428' tid='427' class='m'>paredit-move-past-close-and-newline</a> <a id='430' tid='429' class='m'>,</a><a id='432' tid='431' class='m'>close</a>))
  2345. <span class='i'>(defun ,(paredit-conc-name &quot;paredit-wrap-&quot; name)
  2346. (&optional argument)
  2347. ,(concat &quot;Wrap the following S-expression.
  2348. See `paredit-wrap-sexp&#39; for more details.&quot;)
  2349. (interactive &quot;P&quot;)
  2350. (paredit-wrap-sexp argument ,open ,close))</span>
  2351. <span class='i'>(add-to-list &#39;paredit-wrap-commands
  2352. &#39;,(paredit-conc-name &quot;paredit-wrap-&quot; name))</span>)))
  2353. <span class='i'>(defvar paredit-wrap-commands &#39;(paredit-wrap-sexp)
  2354. &quot;List of paredit commands that wrap S-expressions.
  2355. Used by `paredit-yank-pop&#39;; for internal paredit use only.&quot;)</span>
  2356. <span class='i'>(define-paredit-pair ?\( ?\) &quot;round&quot;)</span>
  2357. <span class='i'>(define-paredit-pair ?\[ ?\] &quot;square&quot;)</span>
  2358. <span class='i'>(define-paredit-pair ?\{ ?\} &quot;curly&quot;)</span>
  2359. <span class='i'>(define-paredit-pair ?\&lt; ?\&gt; &quot;angled&quot;)</span>
  2360. <span class='i'>;;; Aliases for the old names.
  2361. </span>
  2362. <span class='i'>(defalias &#39;paredit-open-parenthesis &#39;paredit-open-round)</span>
  2363. <span class='i'>(defalias &#39;paredit-close-parenthesis &#39;paredit-close-round)</span>
  2364. <span class='i'>(defalias &#39;paredit-close-parenthesis-and-newline
  2365. &#39;paredit-close-round-and-newline)</span>
  2366. <span class='i'>(defalias &#39;paredit-open-bracket &#39;paredit-open-square)</span>
  2367. <span class='i'>(defalias &#39;paredit-close-bracket &#39;paredit-close-square)</span>
  2368. <span class='i'>(defalias &#39;paredit-close-bracket-and-newline
  2369. &#39;paredit-close-square-and-newline)</span>
  2370. (<a id='4198' tid='4197' class='u'>defun</a> <a id='4200' tid='4199' class='u'>paredit-move-past-close</a> (<a id='4202' tid='4201' class='u'>close</a>)
  2371. (<span class='i'>cond</span> ((<a id='916' tid='915' class='m'>or</a> (<a id='918' tid='917' class='m'>paredit-in-string-p</a>)
  2372. (<a id='920' tid='919' class='m'>paredit-in-comment-p</a>))
  2373. (<a id='922' tid='921' class='m'>insert</a> <a id='924' tid='923' class='m'>close</a>))
  2374. <span class='i'>((not (paredit-in-char-p))
  2375. (paredit-move-past-close-and-reindent close)
  2376. (paredit-blink-paren-match nil))</span>))
  2377. (<a id='4204' tid='4203' class='u'>defun</a> <a id='4206' tid='4205' class='u'>paredit-move-past-close-and-newline</a> (<a id='4208' tid='4207' class='u'>close</a>)
  2378. (<span class='i'>if</span> <span class='i'>(or (paredit-in-string-p)
  2379. (paredit-in-comment-p))</span>
  2380. <span class='i'>(insert close)</span>
  2381. <span class='i'>(if (paredit-in-char-p) (forward-char))</span>
  2382. <span class='i'>(paredit-move-past-close-and-reindent close)</span>
  2383. (<a id='926' tid='925' class='m'>let</a> ((<a id='928' tid='927' class='m'>comment.point</a> (<a id='930' tid='929' class='m'>paredit-find-comment-on-line</a>)))
  2384. (<a id='932' tid='931' class='m'>newline</a>)
  2385. (<a id='934' tid='933' class='m'>if</a> <a id='936' tid='935' class='m'>comment.point</a>
  2386. (<a id='938' tid='937' class='m'>save-excursion</a>
  2387. (<a id='940' tid='939' class='m'>forward-line</a> <a id='942' tid='941' class='m'>-1</a>)
  2388. (<a id='944' tid='943' class='m'>end-of-line</a>)
  2389. (<a id='946' tid='945' class='m'>indent-to</a> (<a id='948' tid='947' class='m'>cdr</a> <a id='950' tid='949' class='m'>comment.point</a>))
  2390. (<a id='952' tid='951' class='m'>insert</a> (<a id='954' tid='953' class='m'>car</a> <a id='956' tid='955' class='m'>comment.point</a>)))))
  2391. <span class='i'>(lisp-indent-line)</span>
  2392. <span class='i'>(paredit-ignore-sexp-errors (indent-sexp))</span>
  2393. <span class='i'>(paredit-blink-paren-match t)</span>))
  2394. (<a id='2430' tid='2429' class='u'>defun</a> <a id='2432' tid='2431' class='u'>paredit-find-comment-on-line</a> ()
  2395. <span class='i'>&quot;Find a margin comment on the current line.
  2396. Return nil if there is no such comment or if there is anything but
  2397. whitespace until such a comment.
  2398. If such a comment exists, delete the comment (including all leading
  2399. whitespace) and return a cons whose car is the comment as a string
  2400. and whose cdr is the point of the comment&#39;s initial semicolon,
  2401. relative to the start of the line.&quot;</span>
  2402. (<span class='i'>save-excursion</span>
  2403. <span class='i'>(paredit-skip-whitespace t (point-at-eol))</span>
  2404. (<span class='i'>and</span> <span class='i'>(eq ?\; (char-after))</span>
  2405. <span class='i'>(not (eq ?\; (char-after (1+ (point)))))</span>
  2406. <span class='i'>(not (or (paredit-in-string-p)
  2407. (paredit-in-char-p)))</span>
  2408. (<a id='958' tid='957' class='m'>let*</a> ((<a id='960' tid='959' class='m'>start</a> <span class='i'>;Move to before the semicolon.
  2409. </span> (<a id='962' tid='961' class='m'>progn</a> (<a id='964' tid='963' class='m'>backward-char</a>) (<a id='966' tid='965' class='m'>point</a>)))
  2410. (<a id='968' tid='967' class='m'>comment</a>
  2411. (<a id='970' tid='969' class='m'>buffer-substring</a> <a id='972' tid='971' class='m'>start</a> (<a id='974' tid='973' class='m'>point-at-eol</a>))))
  2412. (<a id='976' tid='975' class='m'>paredit-skip-whitespace</a> <a id='978' tid='977' class='m'>nil</a> (<a id='980' tid='979' class='m'>point-at-bol</a>))
  2413. (<a id='982' tid='981' class='m'>delete-region</a> (<a id='984' tid='983' class='m'>point</a>) (<a id='986' tid='985' class='m'>point-at-eol</a>))
  2414. (<a id='988' tid='987' class='m'>cons</a> <a id='990' tid='989' class='m'>comment</a> (<a id='992' tid='991' class='m'>-</a> <a id='994' tid='993' class='m'>start</a> (<a id='996' tid='995' class='m'>point-at-bol</a>)))))))
  2415. (<a id='3530' tid='3529' class='u'>defun</a> <a id='3532' tid='3531' class='u'>paredit-insert-pair</a> (<a id='3534' tid='3533' class='u'>n</a> <a id='3536' tid='3535' class='u'>open</a> <a id='3538' tid='3537' class='u'>close</a> <a id='3540' tid='3539' class='u'>forward</a>)
  2416. (<a id='3542' tid='3541' class='u'>let*</a> ((<a id='3544' tid='3543' class='u'>regionp</a>
  2417. (<a id='3546' tid='3545' class='u'>and</a> (<a id='3548' tid='3547' class='u'>paredit-region-active-p</a>)
  2418. (<a id='3550' tid='3549' class='u'>paredit-region-safe-for-insert-p</a>)))
  2419. (<a id='3552' tid='3551' class='u'>end</a>
  2420. (<a id='3554' tid='3553' class='u'>and</a> <a id='3556' tid='3555' class='u'>regionp</a>
  2421. (<a id='3558' tid='3557' class='u'>not</a> <a id='3560' tid='3559' class='u'>n</a>)
  2422. (<a id='3562' tid='3561' class='u'>prog1</a> (<a id='3564' tid='3563' class='u'>region-end</a>) (<a id='3566' tid='3565' class='u'>goto-char</a> (<a id='3568' tid='3567' class='u'>region-beginning</a>))))))
  2423. (<a id='3570' tid='3569' class='u'>let</a> ((<a id='3572' tid='3571' class='u'>spacep</a> (<a id='3574' tid='3573' class='u'>paredit-space-for-delimiter-p</a> <a id='3576' tid='3575' class='u'>nil</a> <a id='3578' tid='3577' class='u'>open</a>)))
  2424. (<a id='3580' tid='3579' class='u'>if</a> <a id='3582' tid='3581' class='u'>spacep</a> (<a id='3584' tid='3583' class='u'>insert</a> <a id='3586' tid='3585' class='u'>&quot; &quot;</a>))
  2425. (<a id='3588' tid='3587' class='u'>insert</a> <a id='3590' tid='3589' class='u'>open</a>)
  2426. (<a id='3592' tid='3591' class='u'>save-excursion</a>
  2427. <a id='3594' tid='3593' class='u'>;; Move past the desired region.
  2428. </a> (<a id='3596' tid='3595' class='u'>cond</a> (<a id='3598' tid='3597' class='u'>n</a> (<a id='3600' tid='3599' class='u'>funcall</a> <a id='3602' tid='3601' class='u'>forward</a>
  2429. (<a id='3604' tid='3603' class='u'>save-excursion</a>
  2430. (<a id='3606' tid='3605' class='u'>forward-sexp</a> (<a id='3608' tid='3607' class='u'>prefix-numeric-value</a> <a id='3610' tid='3609' class='u'>n</a>))
  2431. (<a id='3612' tid='3611' class='u'>point</a>))))
  2432. (<a id='3614' tid='3613' class='u'>regionp</a> (<a id='3616' tid='3615' class='u'>funcall</a> <a id='3618' tid='3617' class='u'>forward</a> (<a id='3620' tid='3619' class='u'>+</a> <a id='3622' tid='3621' class='u'>end</a> (<a id='3624' tid='3623' class='u'>if</a> <a id='3626' tid='3625' class='u'>spacep</a> <a id='3628' tid='3627' class='u'>2</a> <a id='3630' tid='3629' class='u'>1</a>)))))
  2433. (<a id='3632' tid='3631' class='u'>insert</a> <a id='3634' tid='3633' class='u'>close</a>)
  2434. (<a id='3636' tid='3635' class='u'>if</a> (<a id='3638' tid='3637' class='u'>paredit-space-for-delimiter-p</a> <a id='3640' tid='3639' class='u'>t</a> <a id='3642' tid='3641' class='u'>close</a>)
  2435. (<a id='3644' tid='3643' class='u'>insert</a> <a id='3646' tid='3645' class='u'>&quot; &quot;</a>))))))
  2436. (<a id='4330' tid='4329' class='u'>defun</a> <a id='4332' tid='4331' class='u'>paredit-region-safe-for-insert-p</a> ()
  2437. (<a id='4334' tid='4333' class='u'>save-excursion</a>
  2438. (<a id='4336' tid='4335' class='u'>let</a> ((<a id='4338' tid='4337' class='u'>beginning</a> (<a id='4340' tid='4339' class='u'>region-beginning</a>))
  2439. (<a id='4342' tid='4341' class='u'>end</a> (<a id='4344' tid='4343' class='u'>region-end</a>)))
  2440. (<a id='4346' tid='4345' class='u'>goto-char</a> <a id='4348' tid='4347' class='u'>beginning</a>)
  2441. (<a id='4350' tid='4349' class='u'>let*</a> ((<a id='4352' tid='4351' class='u'>beginning-state</a> (<a id='4354' tid='4353' class='u'>paredit-current-parse-state</a>))
  2442. (<a id='4356' tid='4355' class='u'>end-state</a>
  2443. (<a id='4358' tid='4357' class='u'>parse-partial-sexp</a> <a id='4360' tid='4359' class='u'>beginning</a> <a id='4362' tid='4361' class='u'>end</a> <a id='4364' tid='4363' class='u'>nil</a> <a id='4366' tid='4365' class='u'>nil</a> <a id='4368' tid='4367' class='u'>beginning-state</a>)))
  2444. (<a id='4370' tid='4369' class='u'>and</a> (<a id='4372' tid='4371' class='u'>=</a> (<a id='4374' tid='4373' class='u'>nth</a> <a id='4376' tid='4375' class='u'>0</a> <a id='4378' tid='4377' class='u'>beginning-state</a>) <a id='4380' tid='4379' class='u'>; 0. depth in parens
  2445. </a> (<a id='4382' tid='4381' class='u'>nth</a> <a id='4384' tid='4383' class='u'>0</a> <a id='4386' tid='4385' class='u'>end-state</a>))
  2446. (<a id='4388' tid='4387' class='u'>eq</a> (<a id='4390' tid='4389' class='u'>nth</a> <a id='4392' tid='4391' class='u'>3</a> <a id='4394' tid='4393' class='u'>beginning-state</a>) <a id='4396' tid='4395' class='u'>; 3. non-nil if inside a
  2447. </a> (<a id='4398' tid='4397' class='u'>nth</a> <a id='4400' tid='4399' class='u'>3</a> <a id='4402' tid='4401' class='u'>end-state</a>)) <a id='4404' tid='4403' class='u'>; string
  2448. </a> (<a id='4406' tid='4405' class='u'>eq</a> (<a id='4408' tid='4407' class='u'>nth</a> <a id='4410' tid='4409' class='u'>4</a> <a id='4412' tid='4411' class='u'>beginning-state</a>) <a id='4414' tid='4413' class='u'>; 4. comment status, yada
  2449. </a> (<a id='4416' tid='4415' class='u'>nth</a> <a id='4418' tid='4417' class='u'>4</a> <a id='4420' tid='4419' class='u'>end-state</a>))
  2450. (<a id='4422' tid='4421' class='u'>eq</a> (<a id='4424' tid='4423' class='u'>nth</a> <a id='4426' tid='4425' class='u'>5</a> <a id='4428' tid='4427' class='u'>beginning-state</a>) <a id='4430' tid='4429' class='u'>; 5. t if following char
  2451. </a> (<a id='4432' tid='4431' class='u'>nth</a> <a id='4434' tid='4433' class='u'>5</a> <a id='4436' tid='4435' class='u'>end-state</a>))))))) <span class='i'>; quote
  2452. </span>
  2453. <span class='i'>(defvar paredit-space-for-delimiter-predicates nil
  2454. &quot;List of predicates for whether to put space by delimiter at point.
  2455. Each predicate is a function that is is applied to two arguments, ENDP
  2456. and DELIMITER, and that returns a boolean saying whether to put a
  2457. space next to the delimiter -- before the delimiter if ENDP is false,
  2458. after the delimiter if ENDP is true.
  2459. If any predicate returns false, no space is inserted: every predicate
  2460. has veto power.
  2461. Each predicate may assume that the point is not at the beginning of the
  2462. buffer, if ENDP is false, or at the end of the buffer, if ENDP is
  2463. true; and that the point is not preceded, if ENDP is false, or
  2464. followed, if ENDP is true, by a word or symbol constituent, a quote,
  2465. or the delimiter matching DELIMITER.
  2466. Each predicate should examine only text before the point, if ENDP is
  2467. false, or only text after the point, if ENDP is true.&quot;)</span>
  2468. (<a id='4478' tid='4477' class='u'>defun</a> <a id='4480' tid='4479' class='u'>paredit-space-for-delimiter-p</a> (<a id='4482' tid='4481' class='u'>endp</a> <a id='4484' tid='4483' class='u'>delimiter</a>)
  2469. <a id='4486' tid='4485' class='u'>;; If at the buffer limit, don&#39;t insert a space. If there is a word,
  2470. </a> <a id='4488' tid='4487' class='u'>;; symbol, other quote, or non-matching parenthesis delimiter (i.e. a
  2471. </a> <a id='4490' tid='4489' class='u'>;; close when want an open the string or an open when we want to
  2472. </a> <a id='4492' tid='4491' class='u'>;; close the string), do insert a space.
  2473. </a> (<span class='i'>and</span> (<a id='998' tid='997' class='m'>not</a> (<a id='1000' tid='999' class='m'>if</a> <a id='1002' tid='1001' class='m'>endp</a> (<a id='1004' tid='1003' class='m'>eobp</a>) (<a id='1006' tid='1005' class='m'>bobp</a>)))
  2474. (<a id='434' tid='433' class='m'>memq</a> (<a id='542' tid='541' class='m'>char-syntax</a> (<a id='544' tid='543' class='m'>if</a> <a id='546' tid='545' class='m'>endp</a> (<a id='548' tid='547' class='m'>char-after</a>) (<a id='550' tid='549' class='m'>char-before</a>)))
  2475. (<span class='i'>list</span> <span class='i'>?w</span> <span class='i'>?_</span> <span class='i'>?\&quot;</span>
  2476. (<a id='436' tid='435' class='m'>let</a> ((<a id='438' tid='437' class='m'>matching</a> (<a id='440' tid='439' class='m'>matching-paren</a> <a id='442' tid='441' class='m'>delimiter</a>)))
  2477. (<a id='444' tid='443' class='m'>and</a> <a id='446' tid='445' class='m'>matching</a> (<a id='448' tid='447' class='m'>char-syntax</a> <a id='450' tid='449' class='m'>matching</a>)))
  2478. <span class='i'>(and (not endp)
  2479. (eq ?\&quot; (char-syntax delimiter))
  2480. ?\) )</span>))
  2481. <span class='i'>(catch &#39;exit
  2482. (dolist (predicate paredit-space-for-delimiter-predicates)
  2483. (if (not (funcall predicate endp delimiter))
  2484. (throw &#39;exit nil)))
  2485. t)</span>))
  2486. (<a id='4210' tid='4209' class='u'>defun</a> <a id='4212' tid='4211' class='u'>paredit-move-past-close-and-reindent</a> <span class='i'>(close)</span>
  2487. <span class='i'>(let ((open (paredit-missing-close)))
  2488. (if open
  2489. (if (eq close (matching-paren open))
  2490. (save-excursion
  2491. (message &quot;Missing closing delimiter: %c&quot; close)
  2492. (insert close))
  2493. (error &quot;Mismatched missing closing delimiter: %c ... %c&quot;
  2494. open close))))</span>
  2495. <span class='i'>(up-list)</span>
  2496. (<a id='1008' tid='1007' class='m'>if</a> (<a id='1010' tid='1009' class='m'>catch</a> <a id='1012' tid='1011' class='m'>&#39;</a><a id='1014' tid='1013' class='m'>return</a> <a id='1016' tid='1015' class='m'>; This CATCH returns T if it
  2497. </a> (<a id='1018' tid='1017' class='m'>while</a> <a id='1020' tid='1019' class='m'>t</a> <a id='1022' tid='1021' class='m'>; should delete leading spaces
  2498. </a> (<a id='1024' tid='1023' class='m'>save-excursion</a> <a id='1026' tid='1025' class='m'>; and NIL if not.
  2499. </a> (<a id='1028' tid='1027' class='m'>let</a> ((<a id='1030' tid='1029' class='m'>before-paren</a> (<a id='1032' tid='1031' class='m'>1-</a> (<a id='1034' tid='1033' class='m'>point</a>))))
  2500. (<a id='1036' tid='1035' class='m'>back-to-indentation</a>)
  2501. (<a id='1038' tid='1037' class='m'>cond</a> ((<a id='1040' tid='1039' class='m'>not</a> (<a id='1042' tid='1041' class='m'>eq</a> (<a id='1044' tid='1043' class='m'>point</a>) <a id='1046' tid='1045' class='m'>before-paren</a>))
  2502. <a id='1048' tid='1047' class='m'>;; Can&#39;t call PAREDIT-DELETE-LEADING-WHITESPACE
  2503. </a> <a id='1050' tid='1049' class='m'>;; here -- we must return from SAVE-EXCURSION
  2504. </a> <a id='1052' tid='1051' class='m'>;; first.
  2505. </a> (<a id='1054' tid='1053' class='m'>throw</a> <a id='1056' tid='1055' class='m'>&#39;</a><a id='1058' tid='1057' class='m'>return</a> <a id='1060' tid='1059' class='m'>t</a>))
  2506. ((<a id='1062' tid='1061' class='m'>save-excursion</a> (<a id='1064' tid='1063' class='m'>forward-line</a> <a id='1066' tid='1065' class='m'>-1</a>)
  2507. (<a id='1068' tid='1067' class='m'>end-of-line</a>)
  2508. (<a id='1070' tid='1069' class='m'>paredit-in-comment-p</a>))
  2509. <span class='i'>;; Moving the closing delimiter any further
  2510. </span> <a id='1072' tid='1071' class='m'>;; would put it into a comment, so we just
  2511. </a> <span class='i'>;; indent the closing delimiter where it is and
  2512. </span> <span class='i'>;; abort the loop, telling its continuation that
  2513. </span> <span class='i'>;; no leading whitespace should be deleted.
  2514. </span> (<a id='1074' tid='1073' class='m'>lisp-indent-line</a>)
  2515. (<a id='1076' tid='1075' class='m'>throw</a> <a id='1078' tid='1077' class='m'>&#39;</a><a id='1080' tid='1079' class='m'>return</a> <a id='1082' tid='1081' class='m'>nil</a>))
  2516. (<a id='1084' tid='1083' class='m'>t</a> (<a id='1086' tid='1085' class='m'>delete-indentation</a>)))))))
  2517. (<a id='1088' tid='1087' class='m'>paredit-delete-leading-whitespace</a>)))
  2518. <span class='i'>(defun paredit-missing-close ()
  2519. (save-excursion
  2520. (paredit-handle-sexp-errors (backward-up-list)
  2521. (error &quot;Not inside a list.&quot;))
  2522. (let ((open (char-after)))
  2523. (paredit-handle-sexp-errors (progn (forward-sexp) nil)
  2524. open))))</span>
  2525. (<a id='2282' tid='2281' class='u'>defun</a> <a id='2284' tid='2283' class='u'>paredit-delete-leading-whitespace</a> ()
  2526. <span class='i'>;; This assumes that we&#39;re on the closing delimiter already.
  2527. </span> (<a id='2286' tid='2285' class='u'>save-excursion</a>
  2528. (<a id='2288' tid='2287' class='u'>backward-char</a>)
  2529. (<a id='2290' tid='2289' class='u'>while</a> (<a id='2292' tid='2291' class='u'>let</a> ((<a id='2294' tid='2293' class='u'>syn</a> (<a id='2296' tid='2295' class='u'>char-syntax</a> (<a id='2298' tid='2297' class='u'>char-before</a>))))
  2530. (<a id='2300' tid='2299' class='u'>and</a> (<a id='2302' tid='2301' class='u'>or</a> (<a id='2304' tid='2303' class='u'>eq</a> <a id='2306' tid='2305' class='u'>syn</a> <a id='2308' tid='2307' class='u'>?\ </a>) (<a id='2310' tid='2309' class='u'>eq</a> <a id='2312' tid='2311' class='u'>syn</a> <a id='2314' tid='2313' class='u'>?-</a>)) <a id='2316' tid='2315' class='u'>; whitespace syntax
  2531. </a> <a id='2318' tid='2317' class='u'>;; The above line is a perfect example of why the
  2532. </a> <a id='2320' tid='2319' class='u'>;; following test is necessary.
  2533. </a> (<a id='2322' tid='2321' class='u'>not</a> (<a id='2324' tid='2323' class='u'>paredit-in-char-p</a> (<a id='2326' tid='2325' class='u'>1-</a> (<a id='2328' tid='2327' class='u'>point</a>))))))
  2534. (<a id='2330' tid='2329' class='u'>backward-delete-char</a> <a id='2332' tid='2331' class='u'>1</a>))))
  2535. (<a id='2160' tid='2159' class='u'>defun</a> <a id='2162' tid='2161' class='u'>paredit-blink-paren-match</a> (<a id='2164' tid='2163' class='u'>another-line-p</a>)
  2536. (<a id='2166' tid='2165' class='u'>if</a> (<a id='2168' tid='2167' class='u'>and</a> <a id='2170' tid='2169' class='u'>blink-matching-paren</a>
  2537. (<a id='2172' tid='2171' class='u'>or</a> (<a id='2174' tid='2173' class='u'>not</a> <a id='2176' tid='2175' class='u'>show-paren-mode</a>) <a id='2178' tid='2177' class='u'>another-line-p</a>))
  2538. (<a id='2180' tid='2179' class='u'>paredit-ignore-sexp-errors</a>
  2539. (<a id='2182' tid='2181' class='u'>save-excursion</a>
  2540. (<a id='2184' tid='2183' class='u'>backward-sexp</a>)
  2541. (<a id='2186' tid='2185' class='u'>forward-sexp</a>)
  2542. <a id='2188' tid='2187' class='u'>;; SHOW-PAREN-MODE inhibits any blinking, so we disable it
  2543. </a> <a id='2190' tid='2189' class='u'>;; locally here.
  2544. </a> (<a id='2192' tid='2191' class='u'>let</a> ((<a id='2194' tid='2193' class='u'>show-paren-mode</a> <a id='2196' tid='2195' class='u'>nil</a>))
  2545. (<a id='2198' tid='2197' class='u'>blink-matching-open</a>))))))
  2546. (<a id='2334' tid='2333' class='u'>defun</a> <a id='2336' tid='2335' class='u'>paredit-doublequote</a> (<a id='2338' tid='2337' class='u'>&optional</a> <a id='2340' tid='2339' class='u'>n</a>)
  2547. <a id='2342' tid='2341' class='u'>&quot;Insert a pair of double-quotes.
  2548. With a prefix argument N, wrap the following N S-expressions in
  2549. double-quotes, escaping intermediate characters if necessary.
  2550. If the region is active, `transient-mark-mode&#39; is enabled, and the
  2551. region&#39;s start and end fall in the same parenthesis depth, insert a
  2552. pair of double-quotes around the region, again escaping intermediate
  2553. characters if necessary.
  2554. Inside a comment, insert a literal double-quote.
  2555. At the end of a string, move past the closing double-quote.
  2556. In the middle of a string, insert a backslash-escaped double-quote.
  2557. If in a character literal, do nothing. This prevents accidentally
  2558. changing a what was in the character literal to become a meaningful
  2559. delimiter unintentionally.&quot;</a>
  2560. (<a id='2344' tid='2343' class='u'>interactive</a> <a id='2346' tid='2345' class='u'>&quot;P&quot;</a>)
  2561. (<a id='2348' tid='2347' class='u'>cond</a> ((<a id='2350' tid='2349' class='u'>paredit-in-string-p</a>)
  2562. (<a id='2352' tid='2351' class='u'>if</a> (<a id='2354' tid='2353' class='u'>eq</a> (<a id='2356' tid='2355' class='u'>cdr</a> (<a id='2358' tid='2357' class='u'>paredit-string-start+end-points</a>))
  2563. (<a id='2360' tid='2359' class='u'>point</a>))
  2564. (<a id='2362' tid='2361' class='u'>forward-char</a>) <a id='2364' tid='2363' class='u'>; We&#39;re on the closing quote.
  2565. </a> (<a id='2366' tid='2365' class='u'>insert</a> <a id='2368' tid='2367' class='u'>?\\</a> <a id='2370' tid='2369' class='u'>?\&quot;</a> )))
  2566. ((<a id='2372' tid='2371' class='u'>paredit-in-comment-p</a>)
  2567. (<a id='2374' tid='2373' class='u'>insert</a> <a id='2376' tid='2375' class='u'>?\&quot;</a> ))
  2568. ((<a id='2378' tid='2377' class='u'>not</a> (<a id='2380' tid='2379' class='u'>paredit-in-char-p</a>))
  2569. (<a id='2382' tid='2381' class='u'>paredit-insert-pair</a> <a id='2384' tid='2383' class='u'>n</a> <a id='2386' tid='2385' class='u'>?\&quot;</a> <a id='2388' tid='2387' class='u'>?\&quot;</a> <a id='2390' tid='2389' class='u'>&#39;</a><a id='2392' tid='2391' class='u'>paredit-forward-for-quote</a>))))
  2570. (<a id='4064' tid='4063' class='u'>defun</a> <a id='4066' tid='4065' class='u'>paredit-meta-doublequote</a> (<a id='4068' tid='4067' class='u'>&optional</a> <a id='4070' tid='4069' class='u'>n</a>)
  2571. <a id='4072' tid='4071' class='u'>&quot;Move to the end of the string, insert a newline, and indent.
  2572. If not in a string, act as `paredit-doublequote&#39;; if no prefix argument
  2573. is specified and the region is not active or `transient-mark-mode&#39; is
  2574. disabled, the default is to wrap one S-expression, however, not
  2575. zero.&quot;</a>
  2576. (<a id='4074' tid='4073' class='u'>interactive</a> <a id='4076' tid='4075' class='u'>&quot;P&quot;</a>)
  2577. (<a id='4078' tid='4077' class='u'>if</a> (<a id='4080' tid='4079' class='u'>not</a> (<a id='4082' tid='4081' class='u'>paredit-in-string-p</a>))
  2578. (<a id='4084' tid='4083' class='u'>paredit-doublequote</a> (<a id='4086' tid='4085' class='u'>or</a> <a id='4088' tid='4087' class='u'>n</a>
  2579. (<a id='4090' tid='4089' class='u'>and</a> (<a id='4092' tid='4091' class='u'>not</a> (<a id='4094' tid='4093' class='u'>paredit-region-active-p</a>))
  2580. <a id='4096' tid='4095' class='u'>1</a>)))
  2581. (<a id='4098' tid='4097' class='u'>let</a> ((<a id='4100' tid='4099' class='u'>start+end</a> (<a id='4102' tid='4101' class='u'>paredit-string-start+end-points</a>)))
  2582. (<a id='4104' tid='4103' class='u'>goto-char</a> (<a id='4106' tid='4105' class='u'>1+</a> (<a id='4108' tid='4107' class='u'>cdr</a> <a id='4110' tid='4109' class='u'>start+end</a>)))
  2583. (<a id='4112' tid='4111' class='u'>newline</a>)
  2584. (<a id='4114' tid='4113' class='u'>lisp-indent-line</a>)
  2585. (<a id='4116' tid='4115' class='u'>paredit-ignore-sexp-errors</a> (<a id='4118' tid='4117' class='u'>indent-sexp</a>)))))
  2586. (<a id='2616' tid='2615' class='u'>defun</a> <a id='2618' tid='2617' class='u'>paredit-forward-for-quote</a> (<a id='2620' tid='2619' class='u'>end</a>)
  2587. (<a id='2622' tid='2621' class='u'>let</a> ((<a id='2624' tid='2623' class='u'>state</a> (<a id='2626' tid='2625' class='u'>paredit-current-parse-state</a>)))
  2588. (<a id='2628' tid='2627' class='u'>while</a> (<a id='2630' tid='2629' class='u'>&lt;</a> (<a id='2632' tid='2631' class='u'>point</a>) <a id='2634' tid='2633' class='u'>end</a>)
  2589. (<a id='2636' tid='2635' class='u'>let</a> ((<a id='2638' tid='2637' class='u'>new-state</a> (<a id='2640' tid='2639' class='u'>parse-partial-sexp</a> (<a id='2642' tid='2641' class='u'>point</a>) (<a id='2644' tid='2643' class='u'>1+</a> (<a id='2646' tid='2645' class='u'>point</a>))
  2590. <a id='2648' tid='2647' class='u'>nil</a> <a id='2650' tid='2649' class='u'>nil</a> <a id='2652' tid='2651' class='u'>state</a>)))
  2591. (<a id='2654' tid='2653' class='u'>if</a> (<a id='2656' tid='2655' class='u'>paredit-in-string-p</a> <a id='2658' tid='2657' class='u'>new-state</a>)
  2592. (<a id='2660' tid='2659' class='u'>if</a> (<a id='2662' tid='2661' class='u'>not</a> (<a id='2664' tid='2663' class='u'>paredit-in-string-escape-p</a>))
  2593. (<a id='2666' tid='2665' class='u'>setq</a> <a id='2668' tid='2667' class='u'>state</a> <a id='2670' tid='2669' class='u'>new-state</a>)
  2594. <a id='2672' tid='2671' class='u'>;; Escape character: turn it into an escaped escape
  2595. </a> <a id='2674' tid='2673' class='u'>;; character by appending another backslash.
  2596. </a> (<a id='2676' tid='2675' class='u'>insert</a> <a id='2678' tid='2677' class='u'>?\\</a> )
  2597. <a id='2680' tid='2679' class='u'>;; Now the point is after both escapes, and we want to
  2598. </a> <a id='2682' tid='2681' class='u'>;; rescan from before the first one to after the second
  2599. </a> <a id='2684' tid='2683' class='u'>;; one.
  2600. </a> (<a id='2686' tid='2685' class='u'>setq</a> <a id='2688' tid='2687' class='u'>state</a>
  2601. (<a id='2690' tid='2689' class='u'>parse-partial-sexp</a> (<a id='2692' tid='2691' class='u'>-</a> (<a id='2694' tid='2693' class='u'>point</a>) <a id='2696' tid='2695' class='u'>2</a>) (<a id='2698' tid='2697' class='u'>point</a>)
  2602. <a id='2700' tid='2699' class='u'>nil</a> <a id='2702' tid='2701' class='u'>nil</a> <a id='2704' tid='2703' class='u'>state</a>))
  2603. <a id='2706' tid='2705' class='u'>;; Advance the end point, since we just inserted a new
  2604. </a> <a id='2708' tid='2707' class='u'>;; character.
  2605. </a> (<a id='2710' tid='2709' class='u'>setq</a> <a id='2712' tid='2711' class='u'>end</a> (<a id='2714' tid='2713' class='u'>1+</a> <a id='2716' tid='2715' class='u'>end</a>)))
  2606. <a id='2718' tid='2717' class='u'>;; String: escape by inserting a backslash before the quote.
  2607. </a> (<a id='2720' tid='2719' class='u'>backward-char</a>)
  2608. (<a id='2722' tid='2721' class='u'>insert</a> <a id='2724' tid='2723' class='u'>?\\</a> )
  2609. <a id='2726' tid='2725' class='u'>;; The point is now between the escape and the quote, and we
  2610. </a> <a id='2728' tid='2727' class='u'>;; want to rescan from before the escape to after the quote.
  2611. </a> (<a id='2730' tid='2729' class='u'>setq</a> <a id='2732' tid='2731' class='u'>state</a>
  2612. (<a id='2734' tid='2733' class='u'>parse-partial-sexp</a> (<a id='2736' tid='2735' class='u'>1-</a> (<a id='2738' tid='2737' class='u'>point</a>)) (<a id='2740' tid='2739' class='u'>1+</a> (<a id='2742' tid='2741' class='u'>point</a>))
  2613. <a id='2744' tid='2743' class='u'>nil</a> <a id='2746' tid='2745' class='u'>nil</a> <a id='2748' tid='2747' class='u'>state</a>))
  2614. <a id='2750' tid='2749' class='u'>;; Advance the end point for the same reason as above.
  2615. </a> (<a id='2752' tid='2751' class='u'>setq</a> <a id='2754' tid='2753' class='u'>end</a> (<a id='2756' tid='2755' class='u'>1+</a> <a id='2758' tid='2757' class='u'>end</a>)))))))
  2616. <span class='i'>;;;; Escape Insertion
  2617. </span>
  2618. (<a id='1734' tid='1733' class='u'>defun</a> <a id='1736' tid='1735' class='u'>paredit-backslash</a> ()
  2619. <a id='1738' tid='1737' class='u'>&quot;Insert a backslash followed by a character to escape.&quot;</a>
  2620. (<a id='1740' tid='1739' class='u'>interactive</a>)
  2621. (<a id='1742' tid='1741' class='u'>insert</a> <a id='1744' tid='1743' class='u'>?\\</a> )
  2622. <a id='1746' tid='1745' class='u'>;; This funny conditional is necessary because PAREDIT-IN-COMMENT-P
  2623. </a> <a id='1748' tid='1747' class='u'>;; assumes that PAREDIT-IN-STRING-P already returned false; otherwise
  2624. </a> <a id='1750' tid='1749' class='u'>;; it may give erroneous answers.
  2625. </a> (<a id='1752' tid='1751' class='u'>if</a> (<a id='1754' tid='1753' class='u'>or</a> (<a id='1756' tid='1755' class='u'>paredit-in-string-p</a>)
  2626. (<a id='1758' tid='1757' class='u'>not</a> (<a id='1760' tid='1759' class='u'>paredit-in-comment-p</a>)))
  2627. (<a id='1762' tid='1761' class='u'>let</a> ((<a id='1764' tid='1763' class='u'>delp</a> <a id='1766' tid='1765' class='u'>t</a>))
  2628. (<a id='1768' tid='1767' class='u'>unwind-protect</a> (<a id='1770' tid='1769' class='u'>setq</a> <a id='1772' tid='1771' class='u'>delp</a>
  2629. (<a id='1774' tid='1773' class='u'>call-interactively</a> <a id='1776' tid='1775' class='u'>&#39;</a><a id='1778' tid='1777' class='u'>paredit-escape</a>))
  2630. <a id='1780' tid='1779' class='u'>;; We need this in an UNWIND-PROTECT so that the backlash is
  2631. </a> <a id='1782' tid='1781' class='u'>;; left in there *only* if PAREDIT-ESCAPE return NIL normally
  2632. </a> <a id='1784' tid='1783' class='u'>;; -- in any other case, such as the user hitting C-g or an
  2633. </a> <a id='1786' tid='1785' class='u'>;; error occurring, we must delete the backslash to avoid
  2634. </a> <a id='1788' tid='1787' class='u'>;; leaving a dangling escape. (This control structure is a
  2635. </a> <a id='1790' tid='1789' class='u'>;; crock.)
  2636. </a> (<a id='1792' tid='1791' class='u'>if</a> <a id='1794' tid='1793' class='u'>delp</a> (<a id='1796' tid='1795' class='u'>backward-delete-char</a> <a id='1798' tid='1797' class='u'>1</a>))))))
  2637. <span class='i'>;;; This auxiliary interactive function returns true if the backslash
  2638. </span><span class='i'>;;; should be deleted and false if not.
  2639. </span>
  2640. (<a id='2394' tid='2393' class='u'>defun</a> <a id='2396' tid='2395' class='u'>paredit-escape</a> (<a id='2398' tid='2397' class='u'>char</a>)
  2641. <a id='2400' tid='2399' class='u'>;; I&#39;m too lazy to figure out how to do this without a separate
  2642. </a> <a id='2402' tid='2401' class='u'>;; interactive function.
  2643. </a> (<a id='2404' tid='2403' class='u'>interactive</a> <a id='2406' tid='2405' class='u'>&quot;cEscaping character...&quot;</a>)
  2644. (<a id='2408' tid='2407' class='u'>if</a> (<a id='2410' tid='2409' class='u'>eq</a> <a id='2412' tid='2411' class='u'>char</a> <a id='2414' tid='2413' class='u'>127</a>) <a id='2416' tid='2415' class='u'>; The backslash was a typo, so
  2645. </a> <a id='2418' tid='2417' class='u'>t</a> <a id='2420' tid='2419' class='u'>; the luser wants to delete it.
  2646. </a> (<a id='2422' tid='2421' class='u'>insert</a> <a id='2424' tid='2423' class='u'>char</a>) <a id='2426' tid='2425' class='u'>; (Is there a better way to
  2647. </a> <a id='2428' tid='2427' class='u'>nil</a>)) <span class='i'>; express the rubout char?
  2648. </span> <span class='i'>; ?\^? works, but ugh...)
  2649. </span>
  2650. (<a id='4214' tid='4213' class='u'>defun</a> <a id='4216' tid='4215' class='u'>paredit-newline</a> ()
  2651. <span class='i'>&quot;Insert a newline and indent it.
  2652. This is like `newline-and-indent&#39;, but it not only indents the line
  2653. that the point is on but also the S-expression following the point,
  2654. if there is one.
  2655. Move forward one character first if on an escaped character.
  2656. If in a string, just insert a literal newline.
  2657. If in a comment and if followed by invalid structure, call
  2658. `indent-new-comment-line&#39; to keep the invalid structure in a
  2659. comment.&quot;</span>
  2660. (<a id='4218' tid='4217' class='u'>interactive</a>)
  2661. <span class='i'>(cond ((paredit-in-string-p)
  2662. (newline))
  2663. ((paredit-in-comment-p)
  2664. (if (paredit-region-ok-p (point) (point-at-eol))
  2665. (progn (newline-and-indent) (indent-sexp))
  2666. (indent-new-comment-line)))
  2667. (t
  2668. (if (paredit-in-char-p)
  2669. (forward-char))
  2670. (newline-and-indent)
  2671. ;; Indent the following S-expression, but don&#39;t signal an
  2672. ;; error if there&#39;s only a closing delimiter after the point.
  2673. (paredit-ignore-sexp-errors (indent-sexp))))</span>)
  2674. <span class='i'>(defun paredit-reindent-defun (&optional argument)
  2675. &quot;Reindent the definition that the point is on.
  2676. If the point is in a string or a comment, fill the paragraph instead,
  2677. and with a prefix argument, justify as well.&quot;
  2678. (interactive &quot;P&quot;)
  2679. (if (or (paredit-in-string-p)
  2680. (paredit-in-comment-p))
  2681. (fill-paragraph argument)
  2682. (save-excursion
  2683. (end-of-defun)
  2684. (beginning-of-defun)
  2685. (indent-sexp))))</span>
  2686. <span class='i'>;;;; Comment Insertion
  2687. </span>
  2688. (<a id='4438' tid='4437' class='u'>defun</a> <a id='4440' tid='4439' class='u'>paredit-semicolon</a> (<a id='4442' tid='4441' class='u'>&optional</a> <a id='4444' tid='4443' class='u'>n</a>)
  2689. <span class='i'>&quot;Insert a semicolon.
  2690. With a prefix argument N, insert N semicolons.
  2691. If in a string, do just that and nothing else.
  2692. If in a character literal, move to the beginning of the character
  2693. literal before inserting the semicolon.
  2694. If the enclosing list ends on the line after the point, break the line
  2695. after the last S-expression following the point.
  2696. If a list begins on the line after the point but ends on a different
  2697. line, break the line after the last S-expression following the point
  2698. before the list.&quot;</span>
  2699. <span class='i'>(interactive &quot;p&quot;)</span>
  2700. <span class='i'>(if (or (paredit-in-string-p) (paredit-in-comment-p))
  2701. (insert (make-string (or n 1) ?\; ))
  2702. (if (paredit-in-char-p)
  2703. (backward-char 2))
  2704. (let ((line-break-point (paredit-semicolon-find-line-break-point)))
  2705. (if line-break-point
  2706. (paredit-semicolon-with-line-break line-break-point (or n 1))
  2707. (insert (make-string (or n 1) ?\; )))))</span>)
  2708. <span class='i'>(defun paredit-semicolon-find-line-break-point ()
  2709. (let ((line-break-point nil)
  2710. (eol (point-at-eol)))
  2711. (and (save-excursion
  2712. (paredit-handle-sexp-errors
  2713. (progn
  2714. (while
  2715. (progn
  2716. (setq line-break-point (point))
  2717. (forward-sexp)
  2718. (and (eq eol (point-at-eol))
  2719. (not (eobp)))))
  2720. (backward-sexp)
  2721. (eq eol (point-at-eol)))
  2722. ;; If we hit the end of an expression, but the closing
  2723. ;; delimiter is on another line, don&#39;t break the line.
  2724. (save-excursion
  2725. (paredit-skip-whitespace t (point-at-eol))
  2726. (not (or (eolp) (eq (char-after) ?\; ))))))
  2727. line-break-point)))</span>
  2728. <span class='i'>(defun paredit-semicolon-with-line-break (line-break-point n)
  2729. (let ((line-break-marker (make-marker)))
  2730. (set-marker line-break-marker line-break-point)
  2731. (set-marker-insertion-type line-break-marker t)
  2732. (insert (make-string (or n 1) ?\; ))
  2733. (save-excursion
  2734. (goto-char line-break-marker)
  2735. (set-marker line-break-marker nil)
  2736. (newline)
  2737. (lisp-indent-line)
  2738. ;; This step is redundant if we are inside a list, but even if we
  2739. ;; are at the top level, we want at least to indent whatever we
  2740. ;; bumped off the line.
  2741. (paredit-ignore-sexp-errors (indent-sexp))
  2742. (paredit-indent-sexps))))</span>
  2743. <span class='i'>;;; This is all a horrible, horrible hack, primarily for GNU Emacs 21,
  2744. </span><span class='i'>;;; in which there is no `comment-or-uncomment-region&#39;.
  2745. </span>
  2746. <span class='i'>(autoload &#39;comment-forward &quot;newcomment&quot;)</span>
  2747. <span class='i'>(autoload &#39;comment-normalize-vars &quot;newcomment&quot;)</span>
  2748. <span class='i'>(autoload &#39;comment-region &quot;newcomment&quot;)</span>
  2749. <span class='i'>(autoload &#39;comment-search-forward &quot;newcomment&quot;)</span>
  2750. <span class='i'>(autoload &#39;uncomment-region &quot;newcomment&quot;)</span>
  2751. <span class='i'>(defun paredit-initialize-comment-dwim ()
  2752. (require &#39;newcomment)
  2753. (if (not (fboundp &#39;comment-or-uncomment-region))
  2754. (defalias &#39;comment-or-uncomment-region
  2755. (lambda (beginning end &optional argument)
  2756. (interactive &quot;*r\nP&quot;)
  2757. (if (save-excursion (goto-char beginning)
  2758. (comment-forward (point-max))
  2759. (&lt;= end (point)))
  2760. (uncomment-region beginning end argument)
  2761. (comment-region beginning end argument)))))
  2762. (defalias &#39;paredit-initialize-comment-dwim &#39;comment-normalize-vars)
  2763. (comment-normalize-vars))</span>
  2764. (<a id='2208' tid='2207' class='u'>defun</a> <a id='2210' tid='2209' class='u'>paredit-comment-dwim</a> <span class='i'>(&optional argument)</span>
  2765. <a id='2212' tid='2211' class='u'>&quot;Call the Lisp comment command you want (Do What I Mean).
  2766. This is like `comment-dwim&#39;, but it is specialized for Lisp editing.
  2767. If transient mark mode is enabled and the mark is active, comment or
  2768. uncomment the selected region, depending on whether it was entirely
  2769. commented not not already.
  2770. If there is already a comment on the current line, with no prefix
  2771. argument, indent to that comment; with a prefix argument, kill that
  2772. comment.
  2773. Otherwise, insert a comment appropriate for the context and ensure that
  2774. any code following the comment is moved to the next line.
  2775. At the top level, where indentation is calculated to be at column 0,
  2776. insert a triple-semicolon comment; within code, where the indentation
  2777. is calculated to be non-zero, and on the line there is either no code
  2778. at all or code after the point, insert a double-semicolon comment;
  2779. and if the point is after all code on the line, insert a single-
  2780. semicolon margin comment at `comment-column&#39;.&quot;</a>
  2781. (<a id='2214' tid='2213' class='u'>interactive</a> <a id='2216' tid='2215' class='u'>&quot;*P&quot;</a>)
  2782. <span class='i'>(paredit-initialize-comment-dwim)</span>
  2783. <span class='i'>(cond ((paredit-region-active-p)
  2784. (comment-or-uncomment-region (region-beginning)
  2785. (region-end)
  2786. argument))
  2787. ((paredit-comment-on-line-p)
  2788. (if argument
  2789. (comment-kill (if (integerp argument) argument nil))
  2790. (comment-indent)))
  2791. (t (paredit-insert-comment)))</span>)
  2792. (<a id='2218' tid='2217' class='u'>defun</a> <a id='2220' tid='2219' class='u'>paredit-comment-on-line-p</a> ()
  2793. <span class='i'>&quot;True if there is a comment on the line following point.
  2794. This is expected to be called only in `paredit-comment-dwim&#39;; do not
  2795. call it elsewhere.&quot;</span>
  2796. (<a id='1090' tid='1089' class='m'>save-excursion</a>
  2797. (<a id='1092' tid='1091' class='m'>beginning-of-line</a>)
  2798. (<a id='1094' tid='1093' class='m'>let</a> ((<a id='1096' tid='1095' class='m'>comment-p</a> <a id='1098' tid='1097' class='m'>nil</a>))
  2799. <a id='1100' tid='1099' class='m'>;; Search forward for a comment beginning. If there is one, set
  2800. </a> <a id='1102' tid='1101' class='m'>;; COMMENT-P to true; if not, it will be nil.
  2801. </a> (<a id='1104' tid='1103' class='m'>while</a> (<span class='i'>progn</span>
  2802. <span class='i'>(setq comment-p ;t -&gt; no error
  2803. (comment-search-forward (point-at-eol) t))</span>
  2804. (<a id='1106' tid='1105' class='m'>and</a> <a id='1108' tid='1107' class='m'>comment-p</a>
  2805. (<a id='1110' tid='1109' class='m'>or</a> (<a id='1112' tid='1111' class='m'>paredit-in-string-p</a>)
  2806. (<a id='1114' tid='1113' class='m'>paredit-in-char-p</a> (<a id='1116' tid='1115' class='m'>1-</a> (<a id='1118' tid='1117' class='m'>point</a>))))))
  2807. (<a id='1120' tid='1119' class='m'>forward-char</a>))
  2808. <a id='1122' tid='1121' class='m'>comment-p</a>)))
  2809. (<a id='3322' tid='3321' class='u'>defun</a> <a id='3324' tid='3323' class='u'>paredit-insert-comment</a> ()
  2810. (<a id='1124' tid='1123' class='m'>let</a> ((<a id='1126' tid='1125' class='m'>code-after-p</a>
  2811. (<a id='1128' tid='1127' class='m'>save-excursion</a> (<a id='1130' tid='1129' class='m'>paredit-skip-whitespace</a> <a id='1132' tid='1131' class='m'>t</a> (<a id='1134' tid='1133' class='m'>point-at-eol</a>))
  2812. (<a id='1136' tid='1135' class='m'>not</a> (<a id='1138' tid='1137' class='m'>eolp</a>))))
  2813. (<a id='1140' tid='1139' class='m'>code-before-p</a>
  2814. (<a id='1142' tid='1141' class='m'>save-excursion</a> (<a id='1144' tid='1143' class='m'>paredit-skip-whitespace</a> <a id='1146' tid='1145' class='m'>nil</a> (<a id='1148' tid='1147' class='m'>point-at-bol</a>))
  2815. (<a id='1150' tid='1149' class='m'>not</a> (<a id='1152' tid='1151' class='m'>bolp</a>)))))
  2816. (<span class='i'>cond</span> ((<a id='1154' tid='1153' class='m'>and</a> (<a id='1156' tid='1155' class='m'>bolp</a>)
  2817. (<span class='i'>let</span> ((<span class='i'>indent</span>
  2818. (<a id='1158' tid='1157' class='m'>let</a> ((<a id='1160' tid='1159' class='m'>indent</a> (<a id='1162' tid='1161' class='m'>calculate-lisp-indent</a>)))
  2819. (<a id='1164' tid='1163' class='m'>if</a> (<a id='1166' tid='1165' class='m'>consp</a> <a id='1168' tid='1167' class='m'>indent</a>) (<a id='1170' tid='1169' class='m'>car</a> <a id='1172' tid='1171' class='m'>indent</a>) <a id='1174' tid='1173' class='m'>indent</a>))))
  2820. <span class='i'>(and indent (zerop indent))</span>))
  2821. <span class='i'>;; Top-level comment
  2822. </span> <span class='i'>(if code-after-p (save-excursion (newline)))</span>
  2823. <span class='i'>(insert &quot;;;; &quot;)</span>)
  2824. <span class='i'>((or code-after-p (not code-before-p))
  2825. ;; Code comment
  2826. (if code-before-p (newline))
  2827. (lisp-indent-line)
  2828. (insert &quot;;; &quot;)
  2829. (if code-after-p
  2830. (save-excursion
  2831. (newline)
  2832. (lisp-indent-line)
  2833. (paredit-indent-sexps))))</span>
  2834. <span class='i'>(t
  2835. ;; Margin comment
  2836. (indent-to comment-column 1) ; 1 -&gt; force one leading space
  2837. (insert ?\; ))</span>)))
  2838. <span class='i'>;;;; Character Deletion
  2839. </span>
  2840. (<a id='2504' tid='2503' class='u'>defun</a> <a id='2506' tid='2505' class='u'>paredit-forward-delete</a> <span class='i'>(&optional argument)</span>
  2841. <span class='i'>&quot;Delete a character forward or move forward over a delimiter.
  2842. If on an opening S-expression delimiter, move forward into the
  2843. S-expression.
  2844. If on a closing S-expression delimiter, refuse to delete unless the
  2845. S-expression is empty, in which case delete the whole S-expression.
  2846. With a numeric prefix argument N, delete N characters forward.
  2847. With a `C-u&#39; prefix argument, simply delete a character forward,
  2848. without regard for delimiter balancing.&quot;</span>
  2849. (<a id='2508' tid='2507' class='u'>interactive</a> <a id='2510' tid='2509' class='u'>&quot;P&quot;</a>)
  2850. (<span class='i'>cond</span> <span class='i'>((or (consp argument) (eobp))
  2851. (delete-char 1))</span>
  2852. <span class='i'>((integerp argument)
  2853. (if (&lt; argument 0)
  2854. (paredit-backward-delete argument)
  2855. (while (&gt; argument 0)
  2856. (paredit-forward-delete)
  2857. (setq argument (- argument 1)))))</span>
  2858. <span class='i'>((paredit-in-string-p)
  2859. (paredit-forward-delete-in-string))</span>
  2860. <span class='i'>((paredit-in-comment-p)
  2861. ;++ What to do here? This could move a partial S-expression
  2862. ;++ into a comment and thereby invalidate the file&#39;s form,
  2863. ;++ or move random text out of a comment.
  2864. (delete-char 1))</span>
  2865. ((<a id='1176' tid='1175' class='m'>paredit-in-char-p</a>) <a id='1178' tid='1177' class='m'>; Escape -- delete both chars.
  2866. </a> (<a id='1180' tid='1179' class='m'>backward-delete-char</a> <a id='1182' tid='1181' class='m'>1</a>)
  2867. (<a id='1184' tid='1183' class='m'>delete-char</a> <a id='1186' tid='1185' class='m'>1</a>))
  2868. ((<a id='552' tid='551' class='m'>eq</a> (<a id='554' tid='553' class='m'>char-after</a>) <a id='556' tid='555' class='m'>?\\</a> ) <a id='558' tid='557' class='m'>; ditto
  2869. </a> (<a id='560' tid='559' class='m'>delete-char</a> <a id='562' tid='561' class='m'>2</a>))
  2870. ((<a id='452' tid='451' class='m'>let</a> ((<a id='454' tid='453' class='m'>syn</a> (<a id='456' tid='455' class='m'>char-syntax</a> (<a id='458' tid='457' class='m'>char-after</a>))))
  2871. (<a id='460' tid='459' class='m'>or</a> (<a id='462' tid='461' class='m'>eq</a> <a id='464' tid='463' class='m'>syn</a> <a id='466' tid='465' class='m'>?\(</a> )
  2872. (<a id='468' tid='467' class='m'>eq</a> <a id='470' tid='469' class='m'>syn</a> <a id='472' tid='471' class='m'>?\&quot;</a> )))
  2873. <span class='i'>(if (save-excursion
  2874. (paredit-handle-sexp-errors (progn (forward-sexp) t)
  2875. nil))
  2876. (forward-char)
  2877. (message &quot;Deleting spurious opening delimiter.&quot;)
  2878. (delete-char 1))</span>)
  2879. ((<a id='330' tid='329' class='m'>and</a> (<a id='332' tid='331' class='m'>not</a> (<a id='334' tid='333' class='m'>paredit-in-char-p</a> (<a id='336' tid='335' class='m'>1-</a> (<a id='338' tid='337' class='m'>point</a>))))
  2880. (<a id='340' tid='339' class='m'>eq</a> (<a id='342' tid='341' class='m'>char-syntax</a> (<a id='344' tid='343' class='m'>char-after</a>)) <a id='346' tid='345' class='m'>?\)</a> )
  2881. (<a id='348' tid='347' class='m'>eq</a> (<a id='350' tid='349' class='m'>char-before</a>) (<a id='352' tid='351' class='m'>matching-paren</a> (<a id='354' tid='353' class='m'>char-after</a>))))
  2882. (<a id='356' tid='355' class='m'>backward-delete-char</a> <a id='358' tid='357' class='m'>1</a>) <a id='360' tid='359' class='m'>; Empty list -- delete both
  2883. </a> (<a id='362' tid='361' class='m'>delete-char</a> <a id='364' tid='363' class='m'>1</a>)) <span class='i'>; delimiters.
  2884. </span> <span class='i'>;; Just delete a single character, if it&#39;s not a closing
  2885. </span> <span class='i'>;; delimiter. (The character literal case is already handled
  2886. </span> <span class='i'>;; by now.)
  2887. </span> ((<a id='278' tid='277' class='m'>not</a> (<a id='280' tid='279' class='m'>eq</a> (<a id='282' tid='281' class='m'>char-syntax</a> (<a id='284' tid='283' class='m'>char-after</a>)) <a id='286' tid='285' class='m'>?\)</a> ))
  2888. (<a id='288' tid='287' class='m'>delete-char</a> <a id='290' tid='289' class='m'>1</a>))))
  2889. (<a id='2512' tid='2511' class='u'>defun</a> <a id='2514' tid='2513' class='u'>paredit-forward-delete-in-string</a> ()
  2890. (<a id='2516' tid='2515' class='u'>let</a> ((<a id='2518' tid='2517' class='u'>start+end</a> (<a id='2520' tid='2519' class='u'>paredit-string-start+end-points</a>)))
  2891. (<a id='2522' tid='2521' class='u'>cond</a> ((<a id='2524' tid='2523' class='u'>not</a> (<a id='2526' tid='2525' class='u'>eq</a> (<a id='2528' tid='2527' class='u'>point</a>) (<a id='2530' tid='2529' class='u'>cdr</a> <a id='2532' tid='2531' class='u'>start+end</a>)))
  2892. <a id='2534' tid='2533' class='u'>;; If it&#39;s not the close-quote, it&#39;s safe to delete. But
  2893. </a> <a id='2536' tid='2535' class='u'>;; first handle the case that we&#39;re in a string escape.
  2894. </a> (<a id='2538' tid='2537' class='u'>cond</a> ((<a id='2540' tid='2539' class='u'>paredit-in-string-escape-p</a>)
  2895. <a id='2542' tid='2541' class='u'>;; We&#39;re right after the backslash, so backward
  2896. </a> <a id='2544' tid='2543' class='u'>;; delete it before deleting the escaped character.
  2897. </a> (<a id='2546' tid='2545' class='u'>backward-delete-char</a> <a id='2548' tid='2547' class='u'>1</a>))
  2898. ((<a id='2550' tid='2549' class='u'>eq</a> (<a id='2552' tid='2551' class='u'>char-after</a>) <a id='2554' tid='2553' class='u'>?\\</a> )
  2899. <a id='2556' tid='2555' class='u'>;; If we&#39;re not in a string escape, but we are on a
  2900. </a> <a id='2558' tid='2557' class='u'>;; backslash, it must start the escape for the next
  2901. </a> <a id='2560' tid='2559' class='u'>;; character, so delete the backslash before deleting
  2902. </a> <a id='2562' tid='2561' class='u'>;; the next character.
  2903. </a> (<a id='2564' tid='2563' class='u'>delete-char</a> <a id='2566' tid='2565' class='u'>1</a>)))
  2904. (<a id='2568' tid='2567' class='u'>delete-char</a> <a id='2570' tid='2569' class='u'>1</a>))
  2905. ((<a id='2572' tid='2571' class='u'>eq</a> (<a id='2574' tid='2573' class='u'>1-</a> (<a id='2576' tid='2575' class='u'>point</a>)) (<a id='2578' tid='2577' class='u'>car</a> <a id='2580' tid='2579' class='u'>start+end</a>))
  2906. <a id='2582' tid='2581' class='u'>;; If it is the close-quote, delete only if we&#39;re also right
  2907. </a> <a id='2584' tid='2583' class='u'>;; past the open-quote (i.e. it&#39;s empty), and then delete
  2908. </a> <a id='2586' tid='2585' class='u'>;; both quotes. Otherwise we refuse to delete it.
  2909. </a> (<a id='2588' tid='2587' class='u'>backward-delete-char</a> <a id='2590' tid='2589' class='u'>1</a>)
  2910. (<a id='2592' tid='2591' class='u'>delete-char</a> <a id='2594' tid='2593' class='u'>1</a>)))))
  2911. (<a id='1868' tid='1867' class='u'>defun</a> <a id='1870' tid='1869' class='u'>paredit-backward-delete</a> <span class='i'>(&optional argument)</span>
  2912. <span class='i'>&quot;Delete a character backward or move backward over a delimiter.
  2913. If on a closing S-expression delimiter, move backward into the
  2914. S-expression.
  2915. If on an opening S-expression delimiter, refuse to delete unless the
  2916. S-expression is empty, in which case delete the whole S-expression.
  2917. With a numeric prefix argument N, delete N characters backward.
  2918. With a `C-u&#39; prefix argument, simply delete a character backward,
  2919. without regard for delimiter balancing.&quot;</span>
  2920. (<a id='1872' tid='1871' class='u'>interactive</a> <a id='1874' tid='1873' class='u'>&quot;P&quot;</a>)
  2921. (<span class='i'>cond</span> <span class='i'>((or (consp argument) (bobp))
  2922. ;++ Should this untabify?
  2923. (backward-delete-char 1))</span>
  2924. <span class='i'>((integerp argument)
  2925. (if (&lt; argument 0)
  2926. (paredit-forward-delete (- 0 argument))
  2927. (while (&gt; argument 0)
  2928. (paredit-backward-delete)
  2929. (setq argument (- argument 1)))))</span>
  2930. <span class='i'>((paredit-in-string-p)
  2931. (paredit-backward-delete-in-string))</span>
  2932. <span class='i'>((paredit-in-comment-p)
  2933. (backward-delete-char 1))</span>
  2934. ((<a id='1188' tid='1187' class='m'>paredit-in-char-p</a>) <a id='1190' tid='1189' class='m'>; Escape -- delete both chars.
  2935. </a> (<a id='1192' tid='1191' class='m'>backward-delete-char</a> <a id='1194' tid='1193' class='m'>1</a>)
  2936. (<a id='1196' tid='1195' class='m'>delete-char</a> <a id='1198' tid='1197' class='m'>1</a>))
  2937. ((<a id='564' tid='563' class='m'>paredit-in-char-p</a> (<a id='566' tid='565' class='m'>1-</a> (<a id='568' tid='567' class='m'>point</a>)))
  2938. (<a id='570' tid='569' class='m'>backward-delete-char</a> <a id='572' tid='571' class='m'>2</a>)) <span class='i'>; ditto
  2939. </span> ((<a id='474' tid='473' class='m'>let</a> ((<a id='476' tid='475' class='m'>syn</a> (<a id='478' tid='477' class='m'>char-syntax</a> (<a id='480' tid='479' class='m'>char-before</a>))))
  2940. (<a id='482' tid='481' class='m'>or</a> (<a id='484' tid='483' class='m'>eq</a> <a id='486' tid='485' class='m'>syn</a> <a id='488' tid='487' class='m'>?\)</a> )
  2941. (<a id='490' tid='489' class='m'>eq</a> <a id='492' tid='491' class='m'>syn</a> <a id='494' tid='493' class='m'>?\&quot;</a> )))
  2942. <span class='i'>(if (save-excursion
  2943. (paredit-handle-sexp-errors (progn (backward-sexp) t)
  2944. nil))
  2945. (backward-char)
  2946. (message &quot;Deleting spurious closing delimiter.&quot;)
  2947. (backward-delete-char 1))</span>)
  2948. ((<a id='366' tid='365' class='m'>and</a> (<a id='368' tid='367' class='m'>eq</a> (<a id='370' tid='369' class='m'>char-syntax</a> (<a id='372' tid='371' class='m'>char-before</a>)) <a id='374' tid='373' class='m'>?\(</a> )
  2949. (<a id='376' tid='375' class='m'>eq</a> (<a id='378' tid='377' class='m'>char-after</a>) (<a id='380' tid='379' class='m'>matching-paren</a> (<a id='382' tid='381' class='m'>char-before</a>))))
  2950. (<a id='384' tid='383' class='m'>backward-delete-char</a> <a id='386' tid='385' class='m'>1</a>) <a id='388' tid='387' class='m'>; Empty list -- delete both
  2951. </a> (<a id='390' tid='389' class='m'>delete-char</a> <a id='392' tid='391' class='m'>1</a>)) <span class='i'>; delimiters.
  2952. </span> <span class='i'>;; Delete it, unless it&#39;s an opening delimiter. The case of
  2953. </span> <span class='i'>;; character literals is already handled by now.
  2954. </span> ((<a id='292' tid='291' class='m'>not</a> (<a id='294' tid='293' class='m'>eq</a> (<a id='296' tid='295' class='m'>char-syntax</a> (<a id='298' tid='297' class='m'>char-before</a>)) <a id='300' tid='299' class='m'>?\(</a> ))
  2955. (<a id='302' tid='301' class='m'>backward-delete-char-untabify</a> <a id='304' tid='303' class='m'>1</a>))))
  2956. (<a id='1876' tid='1875' class='u'>defun</a> <a id='1878' tid='1877' class='u'>paredit-backward-delete-in-string</a> ()
  2957. (<a id='1880' tid='1879' class='u'>let</a> ((<a id='1882' tid='1881' class='u'>start+end</a> (<a id='1884' tid='1883' class='u'>paredit-string-start+end-points</a>)))
  2958. (<a id='1886' tid='1885' class='u'>cond</a> ((<a id='1888' tid='1887' class='u'>not</a> (<a id='1890' tid='1889' class='u'>eq</a> (<a id='1892' tid='1891' class='u'>1-</a> (<a id='1894' tid='1893' class='u'>point</a>)) (<a id='1896' tid='1895' class='u'>car</a> <a id='1898' tid='1897' class='u'>start+end</a>)))
  2959. <a id='1900' tid='1899' class='u'>;; If it&#39;s not the open-quote, it&#39;s safe to delete.
  2960. </a> (<a id='1902' tid='1901' class='u'>if</a> (<a id='1904' tid='1903' class='u'>paredit-in-string-escape-p</a>)
  2961. <a id='1906' tid='1905' class='u'>;; If we&#39;re on a string escape, since we&#39;re about to
  2962. </a> <a id='1908' tid='1907' class='u'>;; delete the backslash, we must first delete the
  2963. </a> <a id='1910' tid='1909' class='u'>;; escaped char.
  2964. </a> (<a id='1912' tid='1911' class='u'>delete-char</a> <a id='1914' tid='1913' class='u'>1</a>))
  2965. (<a id='1916' tid='1915' class='u'>backward-delete-char</a> <a id='1918' tid='1917' class='u'>1</a>)
  2966. (<a id='1920' tid='1919' class='u'>if</a> (<a id='1922' tid='1921' class='u'>paredit-in-string-escape-p</a>)
  2967. <a id='1924' tid='1923' class='u'>;; If, after deleting a character, we find ourselves in
  2968. </a> <a id='1926' tid='1925' class='u'>;; a string escape, we must have deleted the escaped
  2969. </a> <a id='1928' tid='1927' class='u'>;; character, and the backslash is behind the point, so
  2970. </a> <a id='1930' tid='1929' class='u'>;; backward delete it.
  2971. </a> (<a id='1932' tid='1931' class='u'>backward-delete-char</a> <a id='1934' tid='1933' class='u'>1</a>)))
  2972. ((<a id='1936' tid='1935' class='u'>eq</a> (<a id='1938' tid='1937' class='u'>point</a>) (<a id='1940' tid='1939' class='u'>cdr</a> <a id='1942' tid='1941' class='u'>start+end</a>))
  2973. <a id='1944' tid='1943' class='u'>;; If it is the open-quote, delete only if we&#39;re also right
  2974. </a> <a id='1946' tid='1945' class='u'>;; past the close-quote (i.e. it&#39;s empty), and then delete
  2975. </a> <a id='1948' tid='1947' class='u'>;; both quotes. Otherwise we refuse to delete it.
  2976. </a> (<a id='1950' tid='1949' class='u'>backward-delete-char</a> <a id='1952' tid='1951' class='u'>1</a>)
  2977. (<a id='1954' tid='1953' class='u'>delete-char</a> <a id='1956' tid='1955' class='u'>1</a>)))))
  2978. <span class='i'>;;;; Killing
  2979. </span>
  2980. (<a id='3658' tid='3657' class='u'>defun</a> <a id='3660' tid='3659' class='u'>paredit-kill</a> <span class='i'>(&optional argument)</span>
  2981. <span class='i'>&quot;Kill a line as if with `kill-line&#39;, but respecting delimiters.
  2982. In a string, act exactly as `kill-line&#39; but do not kill past the
  2983. closing string delimiter.
  2984. On a line with no S-expressions on it starting after the point or
  2985. within a comment, act exactly as `kill-line&#39;.
  2986. Otherwise, kill all S-expressions that start after the point.
  2987. With a `C-u&#39; prefix argument, just do the standard `kill-line&#39;.
  2988. With a numeric prefix argument N, do `kill-line&#39; that many times.&quot;</span>
  2989. (<a id='3662' tid='3661' class='u'>interactive</a> <a id='3664' tid='3663' class='u'>&quot;P&quot;</a>)
  2990. (<span class='i'>cond</span> <span class='i'>(argument
  2991. (kill-line (if (integerp argument) argument 1)))</span>
  2992. <span class='i'>((paredit-in-string-p)
  2993. (paredit-kill-line-in-string))</span>
  2994. <span class='i'>((paredit-in-comment-p)
  2995. (kill-line))</span>
  2996. ((<a id='244' tid='243' class='m'>save-excursion</a> (<a id='246' tid='245' class='m'>paredit-skip-whitespace</a> <a id='248' tid='247' class='m'>t</a> (<a id='250' tid='249' class='m'>point-at-eol</a>))
  2997. (<a id='252' tid='251' class='m'>or</a> (<a id='254' tid='253' class='m'>eolp</a>) (<a id='256' tid='255' class='m'>eq</a> (<a id='258' tid='257' class='m'>char-after</a>) <a id='260' tid='259' class='m'>?\;</a> )))
  2998. <span class='i'>;** Be careful about trailing backslashes.
  2999. </span> <span class='i'>(if (paredit-in-char-p)
  3000. (backward-char))</span>
  3001. <span class='i'>(kill-line)</span>)
  3002. <span class='i'>(t (paredit-kill-sexps-on-line))</span>))
  3003. (<a id='3666' tid='3665' class='u'>defun</a> <a id='3668' tid='3667' class='u'>paredit-kill-line-in-string</a> ()
  3004. (<span class='i'>if</span> (<a id='1200' tid='1199' class='m'>save-excursion</a> (<a id='1202' tid='1201' class='m'>paredit-skip-whitespace</a> <a id='1204' tid='1203' class='m'>t</a> (<a id='1206' tid='1205' class='m'>point-at-eol</a>))
  3005. (<a id='1208' tid='1207' class='m'>eolp</a>))
  3006. <span class='i'>(kill-line)</span>
  3007. <span class='i'>(save-excursion
  3008. ;; Be careful not to split an escape sequence.
  3009. (if (paredit-in-string-escape-p)
  3010. (backward-char))
  3011. (kill-region (point)
  3012. (min (point-at-eol)
  3013. (cdr (paredit-string-start+end-points)))))</span>))
  3014. (<a id='3670' tid='3669' class='u'>defun</a> <a id='3672' tid='3671' class='u'>paredit-kill-sexps-on-line</a> ()
  3015. (<a id='3674' tid='3673' class='u'>if</a> (<a id='3676' tid='3675' class='u'>paredit-in-char-p</a>) <a id='3678' tid='3677' class='u'>; Move past the \ and prefix.
  3016. </a> (<a id='3680' tid='3679' class='u'>backward-char</a> <a id='3682' tid='3681' class='u'>2</a>)) <a id='3684' tid='3683' class='u'>; (# in Scheme/CL, ? in elisp)
  3017. </a> (<a id='3686' tid='3685' class='u'>let</a> ((<a id='3688' tid='3687' class='u'>beginning</a> (<a id='3690' tid='3689' class='u'>point</a>))
  3018. (<a id='3692' tid='3691' class='u'>eol</a> (<a id='3694' tid='3693' class='u'>point-at-eol</a>)))
  3019. (<a id='3696' tid='3695' class='u'>let</a> ((<a id='3698' tid='3697' class='u'>end-of-list-p</a> (<a id='3700' tid='3699' class='u'>paredit-forward-sexps-to-kill</a> <a id='3702' tid='3701' class='u'>beginning</a> <a id='3704' tid='3703' class='u'>eol</a>)))
  3020. <a id='3706' tid='3705' class='u'>;; If we got to the end of the list and it&#39;s on the same line,
  3021. </a> <a id='3708' tid='3707' class='u'>;; move backward past the closing delimiter before killing. (This
  3022. </a> <a id='3710' tid='3709' class='u'>;; allows something like killing the whitespace in ( ).)
  3023. </a> (<a id='3712' tid='3711' class='u'>if</a> <a id='3714' tid='3713' class='u'>end-of-list-p</a> (<a id='3716' tid='3715' class='u'>progn</a> (<a id='3718' tid='3717' class='u'>up-list</a>) (<a id='3720' tid='3719' class='u'>backward-char</a>)))
  3024. (<a id='3722' tid='3721' class='u'>if</a> <a id='3724' tid='3723' class='u'>kill-whole-line</a>
  3025. (<a id='3726' tid='3725' class='u'>paredit-kill-sexps-on-whole-line</a> <a id='3728' tid='3727' class='u'>beginning</a>)
  3026. (<a id='3730' tid='3729' class='u'>kill-region</a> <a id='3732' tid='3731' class='u'>beginning</a>
  3027. <a id='3734' tid='3733' class='u'>;; If all of the S-expressions were on one line,
  3028. </a> <a id='3736' tid='3735' class='u'>;; i.e. we&#39;re still on that line after moving past
  3029. </a> <a id='3738' tid='3737' class='u'>;; the last one, kill the whole line, including
  3030. </a> <a id='3740' tid='3739' class='u'>;; any comments; otherwise just kill to the end of
  3031. </a> <a id='3742' tid='3741' class='u'>;; the last S-expression we found. Be sure,
  3032. </a> <a id='3744' tid='3743' class='u'>;; though, not to kill any closing parentheses.
  3033. </a> (<a id='3746' tid='3745' class='u'>if</a> (<a id='3748' tid='3747' class='u'>and</a> (<a id='3750' tid='3749' class='u'>not</a> <a id='3752' tid='3751' class='u'>end-of-list-p</a>)
  3034. (<a id='3754' tid='3753' class='u'>eq</a> (<a id='3756' tid='3755' class='u'>point-at-eol</a>) <a id='3758' tid='3757' class='u'>eol</a>))
  3035. <a id='3760' tid='3759' class='u'>eol</a>
  3036. (<a id='3762' tid='3761' class='u'>point</a>)))))))
  3037. <span class='i'>;;; Please do not try to understand this code unless you have a VERY
  3038. </span><span class='i'>;;; good reason to do so. I gave up trying to figure it out well
  3039. </span><span class='i'>;;; enough to explain it, long ago.
  3040. </span>
  3041. (<a id='2890' tid='2889' class='u'>defun</a> <a id='2892' tid='2891' class='u'>paredit-forward-sexps-to-kill</a> (<a id='2894' tid='2893' class='u'>beginning</a> <a id='2896' tid='2895' class='u'>eol</a>)
  3042. (<a id='2898' tid='2897' class='u'>let</a> ((<a id='2900' tid='2899' class='u'>end-of-list-p</a> <a id='2902' tid='2901' class='u'>nil</a>)
  3043. (<a id='2904' tid='2903' class='u'>firstp</a> <a id='2906' tid='2905' class='u'>t</a>))
  3044. <a id='2908' tid='2907' class='u'>;; Move to the end of the last S-expression that started on this
  3045. </a> <a id='2910' tid='2909' class='u'>;; line, or to the closing delimiter if the last S-expression in
  3046. </a> <a id='2912' tid='2911' class='u'>;; this list is on the line.
  3047. </a> (<a id='2914' tid='2913' class='u'>catch</a> <a id='2916' tid='2915' class='u'>&#39;</a><a id='2918' tid='2917' class='u'>return</a>
  3048. (<a id='2920' tid='2919' class='u'>while</a> <a id='2922' tid='2921' class='u'>t</a>
  3049. <a id='2924' tid='2923' class='u'>;; This and the `kill-whole-line&#39; business below fix a bug that
  3050. </a> <a id='2926' tid='2925' class='u'>;; inhibited any S-expression at the very end of the buffer
  3051. </a> <a id='2928' tid='2927' class='u'>;; (with no trailing newline) from being deleted. It&#39;s a
  3052. </a> <a id='2930' tid='2929' class='u'>;; bizarre fix that I ought to document at some point, but I am
  3053. </a> <a id='2932' tid='2931' class='u'>;; too busy at the moment to do so.
  3054. </a> (<a id='2934' tid='2933' class='u'>if</a> (<a id='2936' tid='2935' class='u'>and</a> <a id='2938' tid='2937' class='u'>kill-whole-line</a> (<a id='2940' tid='2939' class='u'>eobp</a>)) (<a id='2942' tid='2941' class='u'>throw</a> <a id='2944' tid='2943' class='u'>&#39;</a><a id='2946' tid='2945' class='u'>return</a> <a id='2948' tid='2947' class='u'>nil</a>))
  3055. (<a id='2950' tid='2949' class='u'>save-excursion</a>
  3056. (<a id='2952' tid='2951' class='u'>paredit-handle-sexp-errors</a> (<a id='2954' tid='2953' class='u'>forward-sexp</a>)
  3057. (<a id='2956' tid='2955' class='u'>up-list</a>)
  3058. (<a id='2958' tid='2957' class='u'>setq</a> <a id='2960' tid='2959' class='u'>end-of-list-p</a> (<a id='2962' tid='2961' class='u'>eq</a> (<a id='2964' tid='2963' class='u'>point-at-eol</a>) <a id='2966' tid='2965' class='u'>eol</a>))
  3059. (<a id='2968' tid='2967' class='u'>throw</a> <a id='2970' tid='2969' class='u'>&#39;</a><a id='2972' tid='2971' class='u'>return</a> <a id='2974' tid='2973' class='u'>nil</a>))
  3060. (<a id='2976' tid='2975' class='u'>if</a> (<a id='2978' tid='2977' class='u'>or</a> (<a id='2980' tid='2979' class='u'>and</a> (<a id='2982' tid='2981' class='u'>not</a> <a id='2984' tid='2983' class='u'>firstp</a>)
  3061. (<a id='2986' tid='2985' class='u'>not</a> <a id='2988' tid='2987' class='u'>kill-whole-line</a>)
  3062. (<a id='2990' tid='2989' class='u'>eobp</a>))
  3063. (<a id='2992' tid='2991' class='u'>paredit-handle-sexp-errors</a>
  3064. (<a id='2994' tid='2993' class='u'>progn</a> (<a id='2996' tid='2995' class='u'>backward-sexp</a>) <a id='2998' tid='2997' class='u'>nil</a>)
  3065. <a id='3000' tid='2999' class='u'>t</a>)
  3066. (<a id='3002' tid='3001' class='u'>not</a> (<a id='3004' tid='3003' class='u'>eq</a> (<a id='3006' tid='3005' class='u'>point-at-eol</a>) <a id='3008' tid='3007' class='u'>eol</a>)))
  3067. (<a id='3010' tid='3009' class='u'>throw</a> <a id='3012' tid='3011' class='u'>&#39;</a><a id='3014' tid='3013' class='u'>return</a> <a id='3016' tid='3015' class='u'>nil</a>)))
  3068. (<a id='3018' tid='3017' class='u'>forward-sexp</a>)
  3069. (<a id='3020' tid='3019' class='u'>if</a> (<a id='3022' tid='3021' class='u'>and</a> <a id='3024' tid='3023' class='u'>firstp</a>
  3070. (<a id='3026' tid='3025' class='u'>not</a> <a id='3028' tid='3027' class='u'>kill-whole-line</a>)
  3071. (<a id='3030' tid='3029' class='u'>eobp</a>))
  3072. (<a id='3032' tid='3031' class='u'>throw</a> <a id='3034' tid='3033' class='u'>&#39;</a><a id='3036' tid='3035' class='u'>return</a> <a id='3038' tid='3037' class='u'>nil</a>))
  3073. (<a id='3040' tid='3039' class='u'>setq</a> <a id='3042' tid='3041' class='u'>firstp</a> <a id='3044' tid='3043' class='u'>nil</a>)))
  3074. <a id='3046' tid='3045' class='u'>end-of-list-p</a>))
  3075. (<a id='3764' tid='3763' class='u'>defun</a> <a id='3766' tid='3765' class='u'>paredit-kill-sexps-on-whole-line</a> (<a id='3768' tid='3767' class='u'>beginning</a>)
  3076. (<a id='3770' tid='3769' class='u'>kill-region</a> <a id='3772' tid='3771' class='u'>beginning</a>
  3077. (<a id='3774' tid='3773' class='u'>or</a> (<a id='3776' tid='3775' class='u'>save-excursion</a> <a id='3778' tid='3777' class='u'>; Delete trailing indentation...
  3078. </a> (<a id='3780' tid='3779' class='u'>paredit-skip-whitespace</a> <a id='3782' tid='3781' class='u'>t</a>)
  3079. (<a id='3784' tid='3783' class='u'>and</a> (<a id='3786' tid='3785' class='u'>not</a> (<a id='3788' tid='3787' class='u'>eq</a> (<a id='3790' tid='3789' class='u'>char-after</a>) <a id='3792' tid='3791' class='u'>?\;</a> ))
  3080. (<a id='3794' tid='3793' class='u'>point</a>)))
  3081. <a id='3796' tid='3795' class='u'>;; ...or just use the point past the newline, if
  3082. </a> <a id='3798' tid='3797' class='u'>;; we encounter a comment.
  3083. </a> (<a id='3800' tid='3799' class='u'>point-at-eol</a>)))
  3084. (<a id='3802' tid='3801' class='u'>cond</a> ((<a id='3804' tid='3803' class='u'>save-excursion</a> (<a id='3806' tid='3805' class='u'>paredit-skip-whitespace</a> <a id='3808' tid='3807' class='u'>nil</a> (<a id='3810' tid='3809' class='u'>point-at-bol</a>))
  3085. (<a id='3812' tid='3811' class='u'>bolp</a>))
  3086. <a id='3814' tid='3813' class='u'>;; Nothing but indentation before the point, so indent it.
  3087. </a> (<a id='3816' tid='3815' class='u'>lisp-indent-line</a>))
  3088. ((<a id='3818' tid='3817' class='u'>eobp</a>) <a id='3820' tid='3819' class='u'>nil</a>) <a id='3822' tid='3821' class='u'>; Protect the CHAR-SYNTAX below against NIL.
  3089. </a> <a id='3824' tid='3823' class='u'>;; Insert a space to avoid invalid joining if necessary.
  3090. </a> ((<a id='3826' tid='3825' class='u'>let</a> ((<a id='3828' tid='3827' class='u'>syn-before</a> (<a id='3830' tid='3829' class='u'>char-syntax</a> (<a id='3832' tid='3831' class='u'>char-before</a>)))
  3091. (<a id='3834' tid='3833' class='u'>syn-after</a> (<a id='3836' tid='3835' class='u'>char-syntax</a> (<a id='3838' tid='3837' class='u'>char-after</a>))))
  3092. (<a id='3840' tid='3839' class='u'>or</a> (<a id='3842' tid='3841' class='u'>and</a> (<a id='3844' tid='3843' class='u'>eq</a> <a id='3846' tid='3845' class='u'>syn-before</a> <a id='3848' tid='3847' class='u'>?\)</a> ) <a id='3850' tid='3849' class='u'>; Separate opposing
  3093. </a> (<a id='3852' tid='3851' class='u'>eq</a> <a id='3854' tid='3853' class='u'>syn-after</a> <a id='3856' tid='3855' class='u'>?\(</a> )) <a id='3858' tid='3857' class='u'>; parentheses,
  3094. </a> (<a id='3860' tid='3859' class='u'>and</a> (<a id='3862' tid='3861' class='u'>eq</a> <a id='3864' tid='3863' class='u'>syn-before</a> <a id='3866' tid='3865' class='u'>?\&quot;</a> ) <a id='3868' tid='3867' class='u'>; string delimiter
  3095. </a> (<a id='3870' tid='3869' class='u'>eq</a> <a id='3872' tid='3871' class='u'>syn-after</a> <a id='3874' tid='3873' class='u'>?\&quot;</a> )) <a id='3876' tid='3875' class='u'>; pairs,
  3096. </a> (<a id='3878' tid='3877' class='u'>and</a> (<a id='3880' tid='3879' class='u'>memq</a> <a id='3882' tid='3881' class='u'>syn-before</a> <a id='3884' tid='3883' class='u'>&#39;</a>(<a id='3886' tid='3885' class='u'>?_</a> <a id='3888' tid='3887' class='u'>?w</a>)) <a id='3890' tid='3889' class='u'>; or word or symbol
  3097. </a> (<a id='3892' tid='3891' class='u'>memq</a> <a id='3894' tid='3893' class='u'>syn-after</a> <a id='3896' tid='3895' class='u'>&#39;</a>(<a id='3898' tid='3897' class='u'>?_</a> <a id='3900' tid='3899' class='u'>?w</a>))))) <a id='3902' tid='3901' class='u'>; constituents.
  3098. </a> (<a id='3904' tid='3903' class='u'>insert</a> <a id='3906' tid='3905' class='u'>&quot; &quot;</a>))))
  3099. <span class='i'>;;;;; Killing Words
  3100. </span>
  3101. <span class='i'>;;; This is tricky and asymmetrical because backward parsing is
  3102. </span><span class='i'>;;; extraordinarily difficult or impossible, so we have to implement
  3103. </span><span class='i'>;;; killing in both directions by parsing forward.
  3104. </span>
  3105. (<a id='2760' tid='2759' class='u'>defun</a> <a id='2762' tid='2761' class='u'>paredit-forward-kill-word</a> ()
  3106. <a id='2764' tid='2763' class='u'>&quot;Kill a word forward, skipping over intervening delimiters.&quot;</a>
  3107. (<a id='2766' tid='2765' class='u'>interactive</a>)
  3108. (<a id='2768' tid='2767' class='u'>let</a> ((<a id='2770' tid='2769' class='u'>beginning</a> (<a id='2772' tid='2771' class='u'>point</a>)))
  3109. (<a id='2774' tid='2773' class='u'>skip-syntax-forward</a> <a id='2776' tid='2775' class='u'>&quot; -&quot;</a>)
  3110. (<a id='2778' tid='2777' class='u'>let*</a> ((<a id='2780' tid='2779' class='u'>parse-state</a> (<a id='2782' tid='2781' class='u'>paredit-current-parse-state</a>))
  3111. (<a id='2784' tid='2783' class='u'>state</a> (<a id='2786' tid='2785' class='u'>paredit-kill-word-state</a> <a id='2788' tid='2787' class='u'>parse-state</a> <a id='2790' tid='2789' class='u'>&#39;</a><a id='2792' tid='2791' class='u'>char-after</a>)))
  3112. (<a id='2794' tid='2793' class='u'>while</a> (<a id='2796' tid='2795' class='u'>not</a> (<a id='2798' tid='2797' class='u'>or</a> (<a id='2800' tid='2799' class='u'>eobp</a>)
  3113. (<a id='2802' tid='2801' class='u'>eq</a> <a id='2804' tid='2803' class='u'>?w</a> (<a id='2806' tid='2805' class='u'>char-syntax</a> (<a id='2808' tid='2807' class='u'>char-after</a>)))))
  3114. (<a id='2810' tid='2809' class='u'>setq</a> <a id='2812' tid='2811' class='u'>parse-state</a>
  3115. (<a id='2814' tid='2813' class='u'>progn</a> (<a id='2816' tid='2815' class='u'>forward-char</a> <a id='2818' tid='2817' class='u'>1</a>) (<a id='2820' tid='2819' class='u'>paredit-current-parse-state</a>))
  3116. <a id='2822' tid='2821' class='u'>;; (parse-partial-sexp (point) (1+ (point))
  3117. </a><a id='2824' tid='2823' class='u'>;; nil nil parse-state)
  3118. </a> )
  3119. (<a id='2826' tid='2825' class='u'>let*</a> ((<a id='2828' tid='2827' class='u'>old-state</a> <a id='2830' tid='2829' class='u'>state</a>)
  3120. (<a id='2832' tid='2831' class='u'>new-state</a>
  3121. (<a id='2834' tid='2833' class='u'>paredit-kill-word-state</a> <a id='2836' tid='2835' class='u'>parse-state</a> <a id='2838' tid='2837' class='u'>&#39;</a><a id='2840' tid='2839' class='u'>char-after</a>)))
  3122. (<a id='2842' tid='2841' class='u'>cond</a> ((<a id='2844' tid='2843' class='u'>not</a> (<a id='2846' tid='2845' class='u'>eq</a> <a id='2848' tid='2847' class='u'>old-state</a> <a id='2850' tid='2849' class='u'>new-state</a>))
  3123. (<a id='2852' tid='2851' class='u'>setq</a> <a id='2854' tid='2853' class='u'>parse-state</a>
  3124. (<a id='2856' tid='2855' class='u'>paredit-kill-word-hack</a> <a id='2858' tid='2857' class='u'>old-state</a>
  3125. <a id='2860' tid='2859' class='u'>new-state</a>
  3126. <a id='2862' tid='2861' class='u'>parse-state</a>))
  3127. (<a id='2864' tid='2863' class='u'>setq</a> <a id='2866' tid='2865' class='u'>state</a>
  3128. (<a id='2868' tid='2867' class='u'>paredit-kill-word-state</a> <a id='2870' tid='2869' class='u'>parse-state</a>
  3129. <a id='2872' tid='2871' class='u'>&#39;</a><a id='2874' tid='2873' class='u'>char-after</a>))
  3130. (<a id='2876' tid='2875' class='u'>setq</a> <a id='2878' tid='2877' class='u'>beginning</a> (<a id='2880' tid='2879' class='u'>point</a>)))))))
  3131. (<a id='2882' tid='2881' class='u'>goto-char</a> <a id='2884' tid='2883' class='u'>beginning</a>)
  3132. (<a id='2886' tid='2885' class='u'>kill-word</a> <a id='2888' tid='2887' class='u'>1</a>)))
  3133. (<a id='1972' tid='1971' class='u'>defun</a> <a id='1974' tid='1973' class='u'>paredit-backward-kill-word</a> ()
  3134. <a id='1976' tid='1975' class='u'>&quot;Kill a word backward, skipping over any intervening delimiters.&quot;</a>
  3135. (<a id='1978' tid='1977' class='u'>interactive</a>)
  3136. (<a id='1980' tid='1979' class='u'>if</a> (<a id='1982' tid='1981' class='u'>not</a> (<a id='1984' tid='1983' class='u'>or</a> (<a id='1986' tid='1985' class='u'>bobp</a>)
  3137. (<a id='1988' tid='1987' class='u'>eq</a> (<a id='1990' tid='1989' class='u'>char-syntax</a> (<a id='1992' tid='1991' class='u'>char-before</a>)) <a id='1994' tid='1993' class='u'>?w</a>)))
  3138. (<a id='1996' tid='1995' class='u'>let</a> ((<a id='1998' tid='1997' class='u'>end</a> (<a id='2000' tid='1999' class='u'>point</a>)))
  3139. (<a id='2002' tid='2001' class='u'>backward-word</a> <a id='2004' tid='2003' class='u'>1</a>)
  3140. (<a id='2006' tid='2005' class='u'>forward-word</a> <a id='2008' tid='2007' class='u'>1</a>)
  3141. (<a id='2010' tid='2009' class='u'>goto-char</a> (<a id='2012' tid='2011' class='u'>min</a> <a id='2014' tid='2013' class='u'>end</a> (<a id='2016' tid='2015' class='u'>point</a>)))
  3142. (<a id='2018' tid='2017' class='u'>let*</a> ((<a id='2020' tid='2019' class='u'>parse-state</a> (<a id='2022' tid='2021' class='u'>paredit-current-parse-state</a>))
  3143. (<a id='2024' tid='2023' class='u'>state</a>
  3144. (<a id='2026' tid='2025' class='u'>paredit-kill-word-state</a> <a id='2028' tid='2027' class='u'>parse-state</a> <a id='2030' tid='2029' class='u'>&#39;</a><a id='2032' tid='2031' class='u'>char-before</a>)))
  3145. (<a id='2034' tid='2033' class='u'>while</a> (<a id='2036' tid='2035' class='u'>and</a> (<a id='2038' tid='2037' class='u'>&lt;</a> (<a id='2040' tid='2039' class='u'>point</a>) <a id='2042' tid='2041' class='u'>end</a>)
  3146. (<a id='2044' tid='2043' class='u'>progn</a>
  3147. (<a id='2046' tid='2045' class='u'>setq</a> <a id='2048' tid='2047' class='u'>parse-state</a>
  3148. (<a id='2050' tid='2049' class='u'>parse-partial-sexp</a> (<a id='2052' tid='2051' class='u'>point</a>) (<a id='2054' tid='2053' class='u'>1+</a> (<a id='2056' tid='2055' class='u'>point</a>))
  3149. <a id='2058' tid='2057' class='u'>nil</a> <a id='2060' tid='2059' class='u'>nil</a> <a id='2062' tid='2061' class='u'>parse-state</a>))
  3150. (<a id='2064' tid='2063' class='u'>or</a> (<a id='2066' tid='2065' class='u'>eq</a> <a id='2068' tid='2067' class='u'>state</a>
  3151. (<a id='2070' tid='2069' class='u'>paredit-kill-word-state</a> <a id='2072' tid='2071' class='u'>parse-state</a>
  3152. <a id='2074' tid='2073' class='u'>&#39;</a><a id='2076' tid='2075' class='u'>char-before</a>))
  3153. (<a id='2078' tid='2077' class='u'>progn</a> (<a id='2080' tid='2079' class='u'>backward-char</a> <a id='2082' tid='2081' class='u'>1</a>) <a id='2084' tid='2083' class='u'>nil</a>)))))
  3154. (<a id='2086' tid='2085' class='u'>if</a> (<a id='2088' tid='2087' class='u'>and</a> (<a id='2090' tid='2089' class='u'>eq</a> <a id='2092' tid='2091' class='u'>state</a> <a id='2094' tid='2093' class='u'>&#39;</a><a id='2096' tid='2095' class='u'>comment</a>)
  3155. (<a id='2098' tid='2097' class='u'>eq</a> <a id='2100' tid='2099' class='u'>?\#</a> (<a id='2102' tid='2101' class='u'>char-after</a> (<a id='2104' tid='2103' class='u'>point</a>)))
  3156. (<a id='2106' tid='2105' class='u'>eq</a> <a id='2108' tid='2107' class='u'>?\|</a> (<a id='2110' tid='2109' class='u'>char-before</a> (<a id='2112' tid='2111' class='u'>point</a>))))
  3157. (<a id='2114' tid='2113' class='u'>backward-char</a> <a id='2116' tid='2115' class='u'>1</a>)))))
  3158. (<a id='2118' tid='2117' class='u'>backward-kill-word</a> <a id='2120' tid='2119' class='u'>1</a>))
  3159. <span class='i'>;;;;;; Word-Killing Auxiliaries
  3160. </span>
  3161. (<a id='4014' tid='4013' class='u'>defun</a> <a id='4016' tid='4015' class='u'>paredit-kill-word-state</a> (<a id='4018' tid='4017' class='u'>parse-state</a> <a id='4020' tid='4019' class='u'>adjacent-char-fn</a>)
  3162. (<a id='4022' tid='4021' class='u'>cond</a> ((<a id='4024' tid='4023' class='u'>paredit-in-comment-p</a> <a id='4026' tid='4025' class='u'>parse-state</a>) <a id='4028' tid='4027' class='u'>&#39;</a><a id='4030' tid='4029' class='u'>comment</a>)
  3163. ((<a id='4032' tid='4031' class='u'>paredit-in-string-p</a> <a id='4034' tid='4033' class='u'>parse-state</a>) <a id='4036' tid='4035' class='u'>&#39;</a><a id='4038' tid='4037' class='u'>string</a>)
  3164. ((<a id='4040' tid='4039' class='u'>memq</a> (<a id='4042' tid='4041' class='u'>char-syntax</a> (<a id='4044' tid='4043' class='u'>funcall</a> <a id='4046' tid='4045' class='u'>adjacent-char-fn</a>))
  3165. <a id='4048' tid='4047' class='u'>&#39;</a>(<a id='4050' tid='4049' class='u'>?\(</a> <a id='4052' tid='4051' class='u'>?\)</a> ))
  3166. <a id='4054' tid='4053' class='u'>&#39;</a><a id='4056' tid='4055' class='u'>delimiter</a>)
  3167. (<a id='4058' tid='4057' class='u'>t</a> <a id='4060' tid='4059' class='u'>&#39;</a><a id='4062' tid='4061' class='u'>other</a>)))
  3168. <span class='i'>;;; This optionally advances the point past any comment delimiters that
  3169. </span><span class='i'>;;; should probably not be touched, based on the last state change and
  3170. </span><span class='i'>;;; the characters around the point. It returns a new parse state,
  3171. </span><span class='i'>;;; starting from the PARSE-STATE parameter.
  3172. </span>
  3173. (<a id='3912' tid='3911' class='u'>defun</a> <a id='3914' tid='3913' class='u'>paredit-kill-word-hack</a> (<a id='3916' tid='3915' class='u'>old-state</a> <a id='3918' tid='3917' class='u'>new-state</a> <a id='3920' tid='3919' class='u'>parse-state</a>)
  3174. (<a id='3922' tid='3921' class='u'>cond</a> ((<a id='3924' tid='3923' class='u'>and</a> (<a id='3926' tid='3925' class='u'>not</a> (<a id='3928' tid='3927' class='u'>eq</a> <a id='3930' tid='3929' class='u'>old-state</a> <a id='3932' tid='3931' class='u'>&#39;</a><a id='3934' tid='3933' class='u'>comment</a>))
  3175. (<a id='3936' tid='3935' class='u'>not</a> (<a id='3938' tid='3937' class='u'>eq</a> <a id='3940' tid='3939' class='u'>new-state</a> <a id='3942' tid='3941' class='u'>&#39;</a><a id='3944' tid='3943' class='u'>comment</a>))
  3176. (<a id='3946' tid='3945' class='u'>not</a> (<a id='3948' tid='3947' class='u'>paredit-in-string-escape-p</a>))
  3177. (<a id='3950' tid='3949' class='u'>eq</a> <a id='3952' tid='3951' class='u'>?\#</a> (<a id='3954' tid='3953' class='u'>char-before</a>))
  3178. (<a id='3956' tid='3955' class='u'>eq</a> <a id='3958' tid='3957' class='u'>?\|</a> (<a id='3960' tid='3959' class='u'>char-after</a>)))
  3179. (<a id='3962' tid='3961' class='u'>forward-char</a> <a id='3964' tid='3963' class='u'>1</a>)
  3180. (<a id='3966' tid='3965' class='u'>paredit-current-parse-state</a>)
  3181. <a id='3968' tid='3967' class='u'>;; (parse-partial-sexp (point) (1+ (point))
  3182. </a><a id='3970' tid='3969' class='u'>;; nil nil parse-state)
  3183. </a> )
  3184. ((<a id='3972' tid='3971' class='u'>and</a> (<a id='3974' tid='3973' class='u'>not</a> (<a id='3976' tid='3975' class='u'>eq</a> <a id='3978' tid='3977' class='u'>old-state</a> <a id='3980' tid='3979' class='u'>&#39;</a><a id='3982' tid='3981' class='u'>comment</a>))
  3185. (<a id='3984' tid='3983' class='u'>eq</a> <a id='3986' tid='3985' class='u'>new-state</a> <a id='3988' tid='3987' class='u'>&#39;</a><a id='3990' tid='3989' class='u'>comment</a>)
  3186. (<a id='3992' tid='3991' class='u'>eq</a> <a id='3994' tid='3993' class='u'>?\;</a> (<a id='3996' tid='3995' class='u'>char-before</a>)))
  3187. (<a id='3998' tid='3997' class='u'>skip-chars-forward</a> <a id='4000' tid='3999' class='u'>&quot;;&quot;</a>)
  3188. (<a id='4002' tid='4001' class='u'>paredit-current-parse-state</a>)
  3189. <a id='4004' tid='4003' class='u'>;; (parse-partial-sexp (point) (save-excursion
  3190. </a><a id='4006' tid='4005' class='u'>;; (skip-chars-forward &quot;;&quot;))
  3191. </a><a id='4008' tid='4007' class='u'>;; nil nil parse-state)
  3192. </a> )
  3193. (<a id='4010' tid='4009' class='u'>t</a> <a id='4012' tid='4011' class='u'>parse-state</a>)))
  3194. <span class='i'>(defun paredit-copy-as-kill ()
  3195. &quot;Save in the kill ring the region that `paredit-kill&#39; would kill.&quot;
  3196. (interactive)
  3197. (cond ((paredit-in-string-p)
  3198. (paredit-copy-as-kill-in-string))
  3199. ((paredit-in-comment-p)
  3200. (copy-region-as-kill (point) (point-at-eol)))
  3201. ((save-excursion (paredit-skip-whitespace t (point-at-eol))
  3202. (or (eolp) (eq (char-after) ?\; )))
  3203. ;** Be careful about trailing backslashes.
  3204. (save-excursion
  3205. (if (paredit-in-char-p)
  3206. (backward-char))
  3207. (copy-region-as-kill (point) (point-at-eol))))
  3208. (t (paredit-copy-sexps-as-kill))))</span>
  3209. <span class='i'>(defun paredit-copy-as-kill-in-string ()
  3210. (save-excursion
  3211. (if (paredit-in-string-escape-p)
  3212. (backward-char))
  3213. (copy-region-as-kill (point)
  3214. (min (point-at-eol)
  3215. (cdr (paredit-string-start+end-points))))))</span>
  3216. <span class='i'>(defun paredit-copy-sexps-as-kill ()
  3217. (save-excursion
  3218. (if (paredit-in-char-p)
  3219. (backward-char 2))
  3220. (let ((beginning (point))
  3221. (eol (point-at-eol)))
  3222. (let ((end-of-list-p (paredit-forward-sexps-to-kill beginning eol)))
  3223. (if end-of-list-p (progn (up-list) (backward-char)))
  3224. (copy-region-as-kill beginning
  3225. (cond (kill-whole-line
  3226. (or (save-excursion
  3227. (paredit-skip-whitespace t)
  3228. (and (not (eq (char-after) ?\; ))
  3229. (point)))
  3230. (point-at-eol)))
  3231. ((and (not end-of-list-p)
  3232. (eq (point-at-eol) eol))
  3233. eol)
  3234. (t
  3235. (point))))))))</span>
  3236. <span class='i'>;;;; Safe Region Killing/Copying
  3237. </span>
  3238. <span class='i'>;;; This is an experiment. It&#39;s not enough: `paredit-kill-ring-save&#39;
  3239. </span><span class='i'>;;; is always safe; it&#39;s `yank&#39; that&#39;s not safe, but even trickier to
  3240. </span><span class='i'>;;; implement than `paredit-kill-region&#39;. Also, the heuristics for
  3241. </span><span class='i'>;;; `paredit-kill-region&#39; are slightly too conservative -- they will
  3242. </span><span class='i'>;;; sometimes reject killing regions that would be safe to kill.
  3243. </span><span class='i'>;;; (Consider, e,g., a region that starts in a comment and ends in the
  3244. </span><span class='i'>;;; middle of a symbol at the end of a line: that&#39;s safe to kill, but
  3245. </span><span class='i'>;;; `paredit-kill-region&#39; won&#39;t allow it.) I don&#39;t know whether they
  3246. </span><span class='i'>;;; are too liberal: I haven&#39;t constructed a region that is unsafe to
  3247. </span><span class='i'>;;; kill but which `paredit-kill-region&#39; will kill, but I haven&#39;t ruled
  3248. </span><span class='i'>;;; out the possibility either.
  3249. </span>
  3250. <span class='i'>(defun paredit-kill-ring-save (beginning end)
  3251. &quot;Save the balanced region, but don&#39;t kill it, like `kill-ring-save&#39;.
  3252. If the text of the region is imbalanced, signal an error instead.
  3253. With a prefix argument, disregard any imbalance.&quot;
  3254. (interactive &quot;r&quot;)
  3255. (if (not current-prefix-arg)
  3256. (paredit-check-region beginning end))
  3257. (setq this-command &#39;kill-ring-save)
  3258. (kill-ring-save beginning end))</span>
  3259. <span class='i'>(defun paredit-kill-region (beginning end &optional yank-handler)
  3260. &quot;Kill balanced text between point and mark, like `kill-region&#39;.
  3261. If that text is imbalanced, signal an error instead.&quot;
  3262. (interactive &quot;r&quot;)
  3263. (if (and beginning end)
  3264. ;; Check that region begins and ends in a sufficiently similar
  3265. ;; state, so that deleting it will leave the buffer balanced.
  3266. (save-excursion
  3267. (goto-char beginning)
  3268. (let* ((state (paredit-current-parse-state))
  3269. (state* (parse-partial-sexp beginning end nil nil state)))
  3270. (paredit-check-region-state state state*))))
  3271. (setq this-command &#39;kill-region)
  3272. (kill-region beginning end yank-handler))</span>
  3273. <span class='i'>(defun paredit-check-region-state (beginning-state end-state)
  3274. (paredit-check-region-state-depth beginning-state end-state)
  3275. (paredit-check-region-state-string beginning-state end-state)
  3276. (paredit-check-region-state-comment beginning-state end-state)
  3277. (paredit-check-region-state-char-quote beginning-state end-state))</span>
  3278. <span class='i'>(defun paredit-check-region-state-depth (beginning-state end-state)
  3279. (let ((beginning-depth (nth 0 beginning-state))
  3280. (end-depth (nth 0 end-state)))
  3281. (if (not (= beginning-depth end-depth))
  3282. (error &quot;Mismatched parenthesis depth: %S at start, %S at end.&quot;
  3283. beginning-depth
  3284. end-depth))))</span>
  3285. <span class='i'>(defun paredit-check-region-state-string (beginning-state end-state)
  3286. (let ((beginning-string-p (nth 3 beginning-state))
  3287. (end-string-p (nth 3 end-state)))
  3288. (if (not (eq beginning-string-p end-string-p))
  3289. (error &quot;Mismatched string state: start %sin string, end %sin string.&quot;
  3290. (if beginning-string-p &quot;&quot; &quot;not &quot;)
  3291. (if end-string-p &quot;&quot; &quot;not &quot;)))))</span>
  3292. <span class='i'>(defun paredit-check-region-state-comment (beginning-state end-state)
  3293. (let ((beginning-comment-state (nth 4 beginning-state))
  3294. (end-comment-state (nth 4 end-state)))
  3295. (if (not (or (eq beginning-comment-state end-comment-state)
  3296. (and (eq beginning-comment-state nil)
  3297. (eq end-comment-state t)
  3298. (eolp))))
  3299. (error &quot;Mismatched comment state: %s&quot;
  3300. (cond ((and (integerp beginning-comment-state)
  3301. (integerp end-comment-state))
  3302. (format &quot;depth %S at start, depth %S at end.&quot;
  3303. beginning-comment-state
  3304. end-comment-state))
  3305. ((integerp beginning-comment-state)
  3306. &quot;start in nested comment, end otherwise.&quot;)
  3307. ((integerp end-comment-state)
  3308. &quot;end in nested comment, start otherwise.&quot;)
  3309. (beginning-comment-state
  3310. &quot;start in comment, end not in comment.&quot;)
  3311. (end-comment-state
  3312. &quot;end in comment, start not in comment.&quot;)
  3313. (t
  3314. (format &quot;start %S, end %S.&quot;
  3315. beginning-comment-state
  3316. end-comment-state)))))))</span>
  3317. <span class='i'>(defun paredit-check-region-state-char-quote (beginning-state end-state)
  3318. (let ((beginning-char-quote (nth 5 beginning-state))
  3319. (end-char-quote (nth 5 end-state)))
  3320. (if (not (eq beginning-char-quote end-char-quote))
  3321. (let ((phrase &quot;character quotation&quot;))
  3322. (error &quot;Mismatched %s: start %sin %s, end %sin %s.&quot;
  3323. phrase
  3324. (if beginning-char-quote &quot;&quot; &quot;not &quot;)
  3325. phrase
  3326. (if end-char-quote &quot;&quot; &quot;not &quot;)
  3327. phrase)))))</span>
  3328. <span class='i'>;;;; Cursor and Screen Movement
  3329. </span>
  3330. (<a id='4788' tid='4787' class='u'>eval-and-compile</a>
  3331. (<a id='4826' tid='4825' class='u'>defmacro</a> <a id='4828' tid='4827' class='u'>defun-saving-mark</a> (<a id='4830' tid='4829' class='u'>name</a> <a id='4832' tid='4831' class='u'>bvl</a> <a id='4834' tid='4833' class='u'>doc</a> <a id='4836' tid='4835' class='u'>&rest</a> <a id='4838' tid='4837' class='u'>body</a>)
  3332. <a id='4840' tid='4839' class='u'>`</a>(<a id='4790' tid='4789' class='u'>defun</a> <a id='4792' tid='4791' class='u'>,</a><a id='4794' tid='4793' class='u'>name</a> <a id='4796' tid='4795' class='u'>,</a><a id='4798' tid='4797' class='u'>bvl</a>
  3333. <a id='4800' tid='4799' class='u'>,</a><a id='4802' tid='4801' class='u'>doc</a>
  3334. <a id='4804' tid='4803' class='u'>,</a>(<a id='4806' tid='4805' class='u'>xcond</a> ((<a id='4808' tid='4807' class='u'>paredit-xemacs-p</a>)
  3335. <a id='4810' tid='4809' class='u'>&#39;</a>(<a id='4812' tid='4811' class='u'>interactive</a> <a id='4814' tid='4813' class='u'>&quot;_&quot;</a>))
  3336. ((<a id='4816' tid='4815' class='u'>paredit-gnu-emacs-p</a>)
  3337. <a id='4818' tid='4817' class='u'>&#39;</a>(<a id='4820' tid='4819' class='u'>interactive</a>)))
  3338. <a id='4822' tid='4821' class='u'>,</a><a id='4824' tid='4823' class='u'>@body</a>)))
  3339. (<a id='4842' tid='4841' class='u'>defun-saving-mark</a> <a id='4844' tid='4843' class='u'>paredit-forward</a> ()
  3340. <a id='4846' tid='4845' class='u'>&quot;Move forward an S-expression, or up an S-expression forward.
  3341. If there are no more S-expressions in this one before the closing
  3342. delimiter, move past that closing delimiter; otherwise, move forward
  3343. past the S-expression following the point.&quot;</a>
  3344. (<a id='4848' tid='4847' class='u'>paredit-handle-sexp-errors</a>
  3345. (<a id='4850' tid='4849' class='u'>forward-sexp</a>)
  3346. <a id='4852' tid='4851' class='u'>;++ Is it necessary to use UP-LIST and not just FORWARD-CHAR?
  3347. </a> (<a id='4854' tid='4853' class='u'>if</a> (<a id='4856' tid='4855' class='u'>paredit-in-string-p</a>) (<a id='4858' tid='4857' class='u'>forward-char</a>) (<a id='4860' tid='4859' class='u'>up-list</a>))))
  3348. (<a id='4862' tid='4861' class='u'>defun-saving-mark</a> <a id='4864' tid='4863' class='u'>paredit-backward</a> ()
  3349. <a id='4866' tid='4865' class='u'>&quot;Move backward an S-expression, or up an S-expression backward.
  3350. If there are no more S-expressions in this one before the opening
  3351. delimiter, move past that opening delimiter backward; otherwise, move
  3352. move backward past the S-expression preceding the point.&quot;</a>
  3353. (<a id='4868' tid='4867' class='u'>paredit-handle-sexp-errors</a>
  3354. (<a id='4870' tid='4869' class='u'>backward-sexp</a>)
  3355. (<a id='4872' tid='4871' class='u'>if</a> (<a id='4874' tid='4873' class='u'>paredit-in-string-p</a>) (<a id='4876' tid='4875' class='u'>backward-char</a>) (<a id='4878' tid='4877' class='u'>backward-up-list</a>))))
  3356. <a id='4880' tid='4879' class='u'>;;; Why is this not in lisp.el?
  3357. </a>
  3358. (<a id='1494' tid='1493' class='u'>defun</a> <a id='1496' tid='1495' class='u'>backward-down-list</a> (<a id='1498' tid='1497' class='u'>&optional</a> <a id='1500' tid='1499' class='u'>arg</a>)
  3359. <a id='1502' tid='1501' class='u'>&quot;Move backward and descend into one level of parentheses.
  3360. With ARG, do this that many times.
  3361. A negative argument means move forward but still descend a level.&quot;</a>
  3362. (<a id='1504' tid='1503' class='u'>interactive</a> <a id='1506' tid='1505' class='u'>&quot;p&quot;</a>)
  3363. (<a id='1508' tid='1507' class='u'>down-list</a> (<a id='1510' tid='1509' class='u'>-</a> (<a id='1512' tid='1511' class='u'>or</a> <a id='1514' tid='1513' class='u'>arg</a> <a id='1516' tid='1515' class='u'>1</a>))))
  3364. <a id='4882' tid='4881' class='u'>;;; Thanks to Marco Baringer for suggesting & writing this function.
  3365. </a>
  3366. (<a id='4264' tid='4263' class='u'>defun</a> <a id='4266' tid='4265' class='u'>paredit-recentre-on-sexp</a> (<a id='4268' tid='4267' class='u'>&optional</a> <a id='4270' tid='4269' class='u'>n</a>)
  3367. <a id='4272' tid='4271' class='u'>&quot;Recentre the screen on the S-expression following the point.
  3368. With a prefix argument N, encompass all N S-expressions forward.&quot;</a>
  3369. (<a id='4274' tid='4273' class='u'>interactive</a> <a id='4276' tid='4275' class='u'>&quot;P&quot;</a>)
  3370. (<a id='4278' tid='4277' class='u'>save-excursion</a>
  3371. (<a id='4280' tid='4279' class='u'>forward-sexp</a> <a id='4282' tid='4281' class='u'>n</a>)
  3372. (<a id='4284' tid='4283' class='u'>let</a> ((<a id='4286' tid='4285' class='u'>end-point</a> (<a id='4288' tid='4287' class='u'>point</a>)))
  3373. (<a id='4290' tid='4289' class='u'>backward-sexp</a> <a id='4292' tid='4291' class='u'>n</a>)
  3374. (<a id='4294' tid='4293' class='u'>let*</a> ((<a id='4296' tid='4295' class='u'>start-point</a> (<a id='4298' tid='4297' class='u'>point</a>))
  3375. (<a id='4300' tid='4299' class='u'>start-line</a> (<a id='4302' tid='4301' class='u'>count-lines</a> (<a id='4304' tid='4303' class='u'>point-min</a>) (<a id='4306' tid='4305' class='u'>point</a>)))
  3376. (<a id='4308' tid='4307' class='u'>lines-on-sexps</a> (<a id='4310' tid='4309' class='u'>count-lines</a> <a id='4312' tid='4311' class='u'>start-point</a> <a id='4314' tid='4313' class='u'>end-point</a>)))
  3377. (<a id='4316' tid='4315' class='u'>goto-line</a> (<a id='4318' tid='4317' class='u'>+</a> <a id='4320' tid='4319' class='u'>start-line</a> (<a id='4322' tid='4321' class='u'>/</a> <a id='4324' tid='4323' class='u'>lines-on-sexps</a> <a id='4326' tid='4325' class='u'>2</a>)))
  3378. (<a id='4328' tid='4327' class='u'>recenter</a>)))))
  3379. <span class='i'>(defun paredit-focus-on-defun ()
  3380. &quot;Moves display to the top of the definition at point.&quot;
  3381. (interactive)
  3382. (beginning-of-defun)
  3383. (recenter 0))</span>
  3384. <span class='i'>;;;; Generalized Upward/Downward Motion
  3385. </span>
  3386. <span class='i'>(defun paredit-up/down (n vertical-direction)
  3387. (let ((horizontal-direction (if (&lt; 0 n) +1 -1)))
  3388. (while (/= n 0)
  3389. (goto-char
  3390. (paredit-next-up/down-point horizontal-direction vertical-direction))
  3391. (setq n (- n horizontal-direction)))))</span>
  3392. <span class='i'>(defun paredit-next-up/down-point (horizontal-direction vertical-direction)
  3393. (let ((state (paredit-current-parse-state))
  3394. (scan-lists
  3395. (lambda ()
  3396. (scan-lists (point) horizontal-direction vertical-direction))))
  3397. (cond ((paredit-in-string-p state)
  3398. (let ((start+end (paredit-string-start+end-points state)))
  3399. (if (&lt; 0 vertical-direction)
  3400. (if (&lt; 0 horizontal-direction)
  3401. (+ 1 (cdr start+end))
  3402. (car start+end))
  3403. ;; We could let the user try to descend into lists
  3404. ;; within the string, but that would be asymmetric
  3405. ;; with the up case, which rises out of the whole
  3406. ;; string and not just out of a list within the
  3407. ;; string, so this case will just be an error.
  3408. (error &quot;Can&#39;t descend further into string.&quot;))))
  3409. ((&lt; 0 vertical-direction)
  3410. ;; When moving up, just try to rise up out of the list.
  3411. (or (funcall scan-lists)
  3412. (buffer-end horizontal-direction)))
  3413. ((&lt; vertical-direction 0)
  3414. ;; When moving down, look for a string closer than a list,
  3415. ;; and use that if we find it.
  3416. (let* ((list-start
  3417. (paredit-handle-sexp-errors (funcall scan-lists) nil))
  3418. (string-start
  3419. (paredit-find-next-string-start horizontal-direction
  3420. list-start)))
  3421. (if (and string-start list-start)
  3422. (if (&lt; 0 horizontal-direction)
  3423. (min string-start list-start)
  3424. (max string-start list-start))
  3425. (or string-start
  3426. ;; Scan again: this is a kludgey way to report the
  3427. ;; error if there really was one.
  3428. (funcall scan-lists)
  3429. (buffer-end horizontal-direction)))))
  3430. (t
  3431. (error &quot;Vertical direction must be nonzero in `%s&#39;.&quot;
  3432. &#39;paredit-up/down)))))</span>
  3433. <span class='i'>(defun paredit-find-next-string-start (horizontal-direction limit)
  3434. (let ((next-char (if (&lt; 0 horizontal-direction) &#39;char-after &#39;char-before))
  3435. (pastp (if (&lt; 0 horizontal-direction) &#39;&lt; &#39;&gt;)))
  3436. (paredit-handle-sexp-errors
  3437. (save-excursion
  3438. (catch &#39;exit
  3439. (while t
  3440. (if (and limit (funcall pastp (point) limit))
  3441. (throw &#39;exit nil))
  3442. (forward-sexp horizontal-direction)
  3443. (save-excursion
  3444. (backward-sexp horizontal-direction)
  3445. (if (eq ?\&quot; (char-syntax (funcall next-char)))
  3446. (throw &#39;exit (+ (point) horizontal-direction)))))))
  3447. nil)))</span>
  3448. <span class='i'>(defun paredit-forward-down (&optional argument)
  3449. &quot;Move forward down into a list.
  3450. With a positive argument, move forward down that many levels.
  3451. With a negative argument, move backward down that many levels.&quot;
  3452. (interactive &quot;p&quot;)
  3453. (paredit-up/down (or argument +1) -1))</span>
  3454. <span class='i'>(defun paredit-backward-up (&optional argument)
  3455. &quot;Move backward up out of the enclosing list.
  3456. With a positive argument, move backward up that many levels.
  3457. With a negative argument, move forward up that many levels.
  3458. If in a string initially, that counts as one level.&quot;
  3459. (interactive &quot;p&quot;)
  3460. (paredit-up/down (- 0 (or argument +1)) +1))</span>
  3461. <span class='i'>(defun paredit-forward-up (&optional argument)
  3462. &quot;Move forward up out of the enclosing list.
  3463. With a positive argument, move forward up that many levels.
  3464. With a negative argument, move backward up that many levels.
  3465. If in a string initially, that counts as one level.&quot;
  3466. (interactive &quot;p&quot;)
  3467. (paredit-up/down (or argument +1) +1))</span>
  3468. <span class='i'>(defun paredit-backward-down (&optional argument)
  3469. &quot;Move backward down into a list.
  3470. With a positive argument, move backward down that many levels.
  3471. With a negative argument, move forward down that many levels.&quot;
  3472. (interactive &quot;p&quot;)
  3473. (paredit-up/down (- 0 (or argument +1)) -1))</span>
  3474. <span class='i'>;;;; Depth-Changing Commands: Wrapping, Splicing, & Raising
  3475. </span>
  3476. (<a id='4614' tid='4613' class='u'>defun</a> <a id='4616' tid='4615' class='u'>paredit-wrap-sexp</a> <span class='i'>(&optional argument open close)</span>
  3477. <span class='i'>&quot;Wrap the following S-expression.
  3478. If a `C-u&#39; prefix argument is given, wrap all S-expressions following
  3479. the point until the end of the buffer or of the enclosing list.
  3480. If a numeric prefix argument N is given, wrap N S-expressions.
  3481. Automatically indent the newly wrapped S-expression.
  3482. As a special case, if the point is at the end of a list, simply insert
  3483. a parenthesis pair, rather than inserting a lone opening delimiter
  3484. and then signalling an error, in the interest of preserving
  3485. structure.
  3486. By default OPEN and CLOSE are round delimiters.&quot;</span>
  3487. (<a id='4618' tid='4617' class='u'>interactive</a> <a id='4620' tid='4619' class='u'>&quot;P&quot;</a>)
  3488. <span class='i'>(paredit-lose-if-not-in-sexp &#39;paredit-wrap-sexp)</span>
  3489. <span class='i'>(let ((open (or open ?\( ))
  3490. (close (or close ?\) )))
  3491. (paredit-handle-sexp-errors
  3492. ((lambda (n) (paredit-insert-pair n open close &#39;goto-char))
  3493. (cond ((integerp argument) argument)
  3494. ((consp argument) (paredit-count-sexps-forward))
  3495. ((paredit-region-active-p) nil)
  3496. (t 1)))
  3497. (insert close)
  3498. (backward-char)))</span>
  3499. (<a id='4622' tid='4621' class='u'>save-excursion</a> (<a id='4624' tid='4623' class='u'>backward-up-list</a>) (<a id='4626' tid='4625' class='u'>indent-sexp</a>)))
  3500. <span class='i'>(defun paredit-count-sexps-forward ()
  3501. (save-excursion
  3502. (let ((n 0))
  3503. (paredit-ignore-sexp-errors
  3504. (while (not (eobp))
  3505. (forward-sexp)
  3506. (setq n (+ n 1))))
  3507. n)))</span>
  3508. <span class='i'>(defun paredit-yank-pop (&optional argument)
  3509. &quot;Replace just-yanked text with the next item in the kill ring.
  3510. If this command follows a `yank&#39;, just run `yank-pop&#39;.
  3511. If this command follows a `paredit-wrap-sexp&#39;, or any other paredit
  3512. wrapping command (see `paredit-wrap-commands&#39;), run `yank&#39; and
  3513. reindent the enclosing S-expression.
  3514. If this command is repeated, run `yank-pop&#39; and reindent the enclosing
  3515. S-expression.
  3516. The argument is passed on to `yank&#39; or `yank-pop&#39;; see their
  3517. documentation for details.&quot;
  3518. (interactive &quot;*p&quot;)
  3519. (cond ((eq last-command &#39;yank)
  3520. (yank-pop argument))
  3521. ((memq last-command paredit-wrap-commands)
  3522. (yank argument)
  3523. ;; `yank&#39; futzes with `this-command&#39;.
  3524. (setq this-command &#39;paredit-yank-pop)
  3525. (save-excursion (backward-up-list) (indent-sexp)))
  3526. ((eq last-command &#39;paredit-yank-pop)
  3527. ;; Pretend we just did a `yank&#39;, so that we can use
  3528. ;; `yank-pop&#39; without duplicating its definition.
  3529. (setq last-command &#39;yank)
  3530. (yank-pop argument)
  3531. ;; Return to our original state.
  3532. (setq last-command &#39;paredit-yank-pop)
  3533. (setq this-command &#39;paredit-yank-pop)
  3534. (save-excursion (backward-up-list) (indent-sexp)))
  3535. (t (error &quot;Last command was not a yank or a wrap: %s&quot; last-command))))</span>
  3536. <span class='i'>;;; Thanks to Marco Baringer for the suggestion of a prefix argument
  3537. </span><span class='i'>;;; for PAREDIT-SPLICE-SEXP. (I, Taylor R. Campbell, however, still
  3538. </span><span class='i'>;;; implemented it, in case any of you lawyer-folk get confused by the
  3539. </span><span class='i'>;;; remark in the top of the file about explicitly noting code written
  3540. </span><span class='i'>;;; by other people.)
  3541. </span>
  3542. (<a id='4494' tid='4493' class='u'>defun</a> <a id='4496' tid='4495' class='u'>paredit-splice-sexp</a> <span class='i'>(&optional argument)</span>
  3543. <span class='i'>&quot;Splice the list that the point is on by removing its delimiters.
  3544. With a prefix argument as in `C-u&#39;, kill all S-expressions backward in
  3545. the current list before splicing all S-expressions forward into the
  3546. enclosing list.
  3547. With two prefix arguments as in `C-u C-u&#39;, kill all S-expressions
  3548. forward in the current list before splicing all S-expressions
  3549. backward into the enclosing list.
  3550. With a numerical prefix argument N, kill N S-expressions backward in
  3551. the current list before splicing the remaining S-expressions into the
  3552. enclosing list. If N is negative, kill forward.
  3553. Inside a string, unescape all backslashes, or signal an error if doing
  3554. so would invalidate the buffer&#39;s structure.&quot;</span>
  3555. (<a id='4498' tid='4497' class='u'>interactive</a> <a id='4500' tid='4499' class='u'>&quot;P&quot;</a>)
  3556. <span class='i'>(if (paredit-in-string-p)
  3557. (paredit-splice-string argument)
  3558. (save-excursion
  3559. (paredit-kill-surrounding-sexps-for-splice argument)
  3560. (let ((end (point)))
  3561. (backward-up-list) ; Go up to the beginning...
  3562. (save-excursion
  3563. (forward-char 1) ; (Skip over leading whitespace
  3564. (paredit-skip-whitespace t end)
  3565. (setq end (point))) ; for the `delete-region&#39;.)
  3566. (let ((indent-start nil) (indent-end nil))
  3567. (save-excursion
  3568. (setq indent-start (point))
  3569. (forward-sexp) ; Go forward an expression, to
  3570. (backward-delete-char 1) ; delete the end delimiter.
  3571. (setq indent-end (point)))
  3572. (delete-region (point) end) ; ...to delete the open char.
  3573. ;; Reindent only the region we preserved.
  3574. (indent-region indent-start indent-end)))))</span>)
  3575. (<a id='3908' tid='3907' class='u'>defun</a> <a id='3910' tid='3909' class='u'>paredit-kill-surrounding-sexps-for-splice</a> <span class='i'>(argument)</span>
  3576. (<span class='i'>cond</span> <span class='i'>((or (paredit-in-string-p)
  3577. (paredit-in-comment-p))
  3578. (error &quot;Invalid context for splicing S-expressions.&quot;))</span>
  3579. <span class='i'>((or (not argument) (eq argument 0)) nil)</span>
  3580. <span class='i'>((or (numberp argument) (eq argument &#39;-))
  3581. ;; Kill S-expressions before/after the point by saving the
  3582. ;; point, moving across them, and killing the region.
  3583. (let* ((argument (if (eq argument &#39;-) -1 argument))
  3584. (saved (paredit-point-at-sexp-boundary (- argument))))
  3585. (goto-char saved)
  3586. (paredit-ignore-sexp-errors (backward-sexp argument))
  3587. (paredit-hack-kill-region saved (point))))</span>
  3588. (<span class='i'>(consp argument)</span>
  3589. (<span class='i'>let</span> <span class='i'>((v (car argument)))</span>
  3590. (<a id='1210' tid='1209' class='m'>if</a> (<a id='1212' tid='1211' class='m'>=</a> <a id='1214' tid='1213' class='m'>v</a> <a id='1216' tid='1215' class='m'>4</a>) <span class='i'>;One `C-u&#39;.
  3591. </span> <a id='1218' tid='1217' class='m'>;; Move backward until we hit the open paren; then
  3592. </a> <a id='1220' tid='1219' class='m'>;; kill that selected region.
  3593. </a> (<span class='i'>let</span> <span class='i'>((end (point)))</span>
  3594. (<a id='1222' tid='1221' class='m'>paredit-ignore-sexp-errors</a>
  3595. (<a id='1224' tid='1223' class='m'>while</a> (<a id='1226' tid='1225' class='m'>not</a> (<a id='1228' tid='1227' class='m'>bobp</a>))
  3596. (<a id='1230' tid='1229' class='m'>backward-sexp</a>)))
  3597. <span class='i'>(paredit-hack-kill-region (point) end)</span>)
  3598. <a id='1232' tid='1231' class='m'>;; Move forward until we hit the close paren; then
  3599. </a> <a id='1234' tid='1233' class='m'>;; kill that selected region.
  3600. </a> (<span class='i'>let</span> <span class='i'>((beginning (point)))</span>
  3601. (<a id='1236' tid='1235' class='m'>paredit-ignore-sexp-errors</a>
  3602. (<a id='1238' tid='1237' class='m'>while</a> (<a id='1240' tid='1239' class='m'>not</a> (<a id='1242' tid='1241' class='m'>eobp</a>))
  3603. (<a id='1244' tid='1243' class='m'>forward-sexp</a>)))
  3604. <span class='i'>(paredit-hack-kill-region beginning (point))</span>))))
  3605. <span class='i'>(t (error &quot;Bizarre prefix argument `%s&#39;.&quot; argument))</span>))
  3606. (<a id='4502' tid='4501' class='u'>defun</a> <a id='4504' tid='4503' class='u'>paredit-splice-sexp-killing-backward</a> (<a id='4506' tid='4505' class='u'>&optional</a> <a id='4508' tid='4507' class='u'>n</a>)
  3607. <a id='4510' tid='4509' class='u'>&quot;Splice the list the point is on by removing its delimiters, and
  3608. also kill all S-expressions before the point in the current list.
  3609. With a prefix argument N, kill only the preceding N S-expressions.&quot;</a>
  3610. (<a id='4512' tid='4511' class='u'>interactive</a> <a id='4514' tid='4513' class='u'>&quot;P&quot;</a>)
  3611. (<a id='4516' tid='4515' class='u'>paredit-splice-sexp</a> (<a id='4518' tid='4517' class='u'>if</a> <a id='4520' tid='4519' class='u'>n</a>
  3612. (<a id='4522' tid='4521' class='u'>prefix-numeric-value</a> <a id='4524' tid='4523' class='u'>n</a>)
  3613. <a id='4526' tid='4525' class='u'>&#39;</a>(<a id='4528' tid='4527' class='u'>4</a>))))
  3614. (<a id='4530' tid='4529' class='u'>defun</a> <a id='4532' tid='4531' class='u'>paredit-splice-sexp-killing-forward</a> (<a id='4534' tid='4533' class='u'>&optional</a> <a id='4536' tid='4535' class='u'>n</a>)
  3615. <a id='4538' tid='4537' class='u'>&quot;Splice the list the point is on by removing its delimiters, and
  3616. also kill all S-expressions after the point in the current list.
  3617. With a prefix argument N, kill only the following N S-expressions.&quot;</a>
  3618. (<a id='4540' tid='4539' class='u'>interactive</a> <a id='4542' tid='4541' class='u'>&quot;P&quot;</a>)
  3619. (<a id='4544' tid='4543' class='u'>paredit-splice-sexp</a> (<a id='4546' tid='4545' class='u'>if</a> <a id='4548' tid='4547' class='u'>n</a>
  3620. (<a id='4550' tid='4549' class='u'>-</a> (<a id='4552' tid='4551' class='u'>prefix-numeric-value</a> <a id='4554' tid='4553' class='u'>n</a>))
  3621. <a id='4556' tid='4555' class='u'>&#39;</a>(<a id='4558' tid='4557' class='u'>16</a>))))
  3622. (<a id='4260' tid='4259' class='u'>defun</a> <a id='4262' tid='4261' class='u'>paredit-raise-sexp</a> <span class='i'>(&optional argument)</span>
  3623. <span class='i'>&quot;Raise the following S-expression in a tree, deleting its siblings.
  3624. With a prefix argument N, raise the following N S-expressions. If N
  3625. is negative, raise the preceding N S-expressions.
  3626. If the point is on an S-expression, such as a string or a symbol, not
  3627. between them, that S-expression is considered to follow the point.&quot;</span>
  3628. <span class='i'>(interactive &quot;P&quot;)</span>
  3629. <span class='i'>(save-excursion
  3630. (cond ((paredit-in-string-p)
  3631. (goto-char (car (paredit-string-start+end-points))))
  3632. ((paredit-in-char-p)
  3633. (backward-sexp))
  3634. ((paredit-in-comment-p)
  3635. (error &quot;No S-expression to raise in comment.&quot;)))
  3636. ;; Select the S-expressions we want to raise in a buffer substring.
  3637. (let* ((n (prefix-numeric-value argument))
  3638. (bound (scan-sexps (point) n))
  3639. (sexps
  3640. (if (&lt; n 0)
  3641. (buffer-substring bound (paredit-point-at-sexp-end))
  3642. (buffer-substring (paredit-point-at-sexp-start) bound))))
  3643. ;; Move up to the list we&#39;re raising those S-expressions out of and
  3644. ;; delete it.
  3645. (backward-up-list)
  3646. (delete-region (point) (scan-sexps (point) 1))
  3647. (let* ((indent-start (point))
  3648. (indent-end (save-excursion (insert sexps) (point))))
  3649. (indent-region indent-start indent-end))))</span>)
  3650. <span class='i'>(defun paredit-convolute-sexp (&optional n)
  3651. &quot;Convolute S-expressions.
  3652. Save the S-expressions preceding point and delete them.
  3653. Splice the S-expressions following point.
  3654. Wrap the enclosing list in a new list prefixed by the saved text.
  3655. With a prefix argument N, move up N lists before wrapping.&quot;
  3656. (interactive &quot;p&quot;)
  3657. (paredit-lose-if-not-in-sexp &#39;paredit-convolute-sexp)
  3658. (let (open close) ;++ Is this a good idea?
  3659. (let ((prefix
  3660. (let ((end (point)))
  3661. (paredit-ignore-sexp-errors
  3662. (while (not (bobp)) (backward-sexp)))
  3663. (prog1 (buffer-substring (point) end)
  3664. (backward-up-list)
  3665. (save-excursion (forward-sexp)
  3666. (setq close (char-before))
  3667. (backward-delete-char 1))
  3668. (setq open (char-after))
  3669. (delete-region (point) end)))))
  3670. (backward-up-list n)
  3671. (paredit-insert-pair 1 open close &#39;goto-char)
  3672. (insert prefix)
  3673. (backward-up-list)
  3674. (paredit-ignore-sexp-errors (indent-sexp)))))</span>
  3675. <span class='i'>(defun paredit-splice-string (argument)
  3676. (let ((original-point (point))
  3677. (start+end (paredit-string-start+end-points)))
  3678. (let ((start (car start+end))
  3679. (end (cdr start+end)))
  3680. ;; START and END both lie before the respective quote
  3681. ;; characters, which we want to delete; thus we increment START
  3682. ;; by one to extract the string, and we increment END by one to
  3683. ;; delete the string.
  3684. (let* ((escaped-string
  3685. (cond ((not (consp argument))
  3686. (buffer-substring (1+ start) end))
  3687. ((= 4 (car argument))
  3688. (buffer-substring original-point end))
  3689. (t
  3690. (buffer-substring (1+ start) original-point))))
  3691. (unescaped-string
  3692. (paredit-unescape-string escaped-string)))
  3693. (if (not unescaped-string)
  3694. (error &quot;Unspliceable string.&quot;)
  3695. (save-excursion
  3696. (goto-char start)
  3697. (delete-region start (1+ end))
  3698. (insert unescaped-string))
  3699. (if (not (and (consp argument)
  3700. (= 4 (car argument))))
  3701. (goto-char (- original-point 1))))))))</span>
  3702. <span class='i'>(defun paredit-unescape-string (string)
  3703. (with-temp-buffer
  3704. (insert string)
  3705. (goto-char (point-min))
  3706. (while (and (not (eobp))
  3707. ;; nil -&gt; no bound; t -&gt; no errors.
  3708. (search-forward &quot;\\&quot; nil t))
  3709. (delete-char -1)
  3710. (forward-char))
  3711. (condition-case condition
  3712. (progn (check-parens) (buffer-string))
  3713. (error nil))))</span>
  3714. <a id='4884' tid='4883' class='u'>;;;; Slurpage & Barfage
  3715. </a>
  3716. (<a id='3098' tid='3097' class='u'>defun</a> <a id='3100' tid='3099' class='u'>paredit-forward-slurp-sexp</a> ()
  3717. <a id='3102' tid='3101' class='u'>&quot;Add the S-expression following the current list into that list
  3718. by moving the closing delimiter.
  3719. Automatically reindent the newly slurped S-expression with respect to
  3720. its new enclosing form.
  3721. If in a string, move the opening double-quote forward by one
  3722. S-expression and escape any intervening characters as necessary,
  3723. without altering any indentation or formatting.&quot;</a>
  3724. (<a id='3104' tid='3103' class='u'>interactive</a>)
  3725. <span class='i'>(save-excursion
  3726. (cond ((or (paredit-in-comment-p)
  3727. (paredit-in-char-p))
  3728. (error &quot;Invalid context for slurping S-expressions.&quot;))
  3729. ((paredit-in-string-p)
  3730. (paredit-forward-slurp-into-string))
  3731. (t
  3732. (paredit-forward-slurp-into-list))))</span>)
  3733. (<a id='3048' tid='3047' class='u'>defun</a> <a id='3050' tid='3049' class='u'>paredit-forward-slurp-into-list</a> ()
  3734. (<a id='3052' tid='3051' class='u'>up-list</a>) <a id='3054' tid='3053' class='u'>; Up to the end of the list to
  3735. </a> (<a id='1246' tid='1245' class='m'>let</a> ((<a id='1248' tid='1247' class='m'>close</a> (<a id='1250' tid='1249' class='m'>char-before</a>))) <a id='1252' tid='1251' class='m'>; save and delete the closing
  3736. </a> (<a id='1254' tid='1253' class='m'>backward-delete-char</a> <a id='1256' tid='1255' class='m'>1</a>) <a id='1258' tid='1257' class='m'>; delimiter.
  3737. </a> (<a id='1260' tid='1259' class='m'>catch</a> <a id='1262' tid='1261' class='m'>&#39;</a><a id='1264' tid='1263' class='m'>return</a> <a id='1266' tid='1265' class='m'>; Go to the end of the desired
  3738. </a> (<a id='1268' tid='1267' class='m'>while</a> <a id='1270' tid='1269' class='m'>t</a> <a id='1272' tid='1271' class='m'>; S-expression, going up a
  3739. </a> (<span class='i'>paredit-handle-sexp-errors</span> <span class='i'>; list if it&#39;s not in this,
  3740. </span> (<a id='1274' tid='1273' class='m'>progn</a> (<a id='1276' tid='1275' class='m'>paredit-forward-and-indent</a>)
  3741. (<a id='1278' tid='1277' class='m'>throw</a> <a id='1280' tid='1279' class='m'>&#39;</a><a id='1282' tid='1281' class='m'>return</a> <a id='1284' tid='1283' class='m'>nil</a>))
  3742. <span class='i'>(up-list)</span>
  3743. <span class='i'>(setq close ; adjusting for mixed
  3744. (prog1 (char-before) ; delimiters as necessary,
  3745. (backward-delete-char 1)
  3746. (insert close)))</span>)))
  3747. (<a id='1286' tid='1285' class='m'>insert</a> <a id='1288' tid='1287' class='m'>close</a>))) <a id='4886' tid='4885' class='u'>; to insert that delimiter.
  3748. </a>
  3749. (<a id='3056' tid='3055' class='u'>defun</a> <a id='3058' tid='3057' class='u'>paredit-forward-slurp-into-string</a> ()
  3750. (<a id='3060' tid='3059' class='u'>goto-char</a> (<a id='3062' tid='3061' class='u'>1+</a> (<a id='3064' tid='3063' class='u'>cdr</a> (<a id='3066' tid='3065' class='u'>paredit-string-start+end-points</a>))))
  3751. <a id='3068' tid='3067' class='u'>;; Signal any errors that we might get first, before mucking with the
  3752. </a> <a id='3070' tid='3069' class='u'>;; buffer&#39;s contents.
  3753. </a> (<a id='3072' tid='3071' class='u'>save-excursion</a> (<a id='3074' tid='3073' class='u'>forward-sexp</a>))
  3754. (<a id='3076' tid='3075' class='u'>let</a> ((<a id='3078' tid='3077' class='u'>close</a> (<a id='3080' tid='3079' class='u'>char-before</a>)))
  3755. (<a id='3082' tid='3081' class='u'>backward-delete-char</a> <a id='3084' tid='3083' class='u'>1</a>)
  3756. (<a id='3086' tid='3085' class='u'>paredit-forward-for-quote</a> (<a id='3088' tid='3087' class='u'>save-excursion</a> (<a id='3090' tid='3089' class='u'>forward-sexp</a>) (<a id='3092' tid='3091' class='u'>point</a>)))
  3757. (<a id='3094' tid='3093' class='u'>insert</a> <a id='3096' tid='3095' class='u'>close</a>)))
  3758. (<a id='2438' tid='2437' class='u'>defun</a> <a id='2440' tid='2439' class='u'>paredit-forward-barf-sexp</a> ()
  3759. <a id='2442' tid='2441' class='u'>&quot;Remove the last S-expression in the current list from that list
  3760. by moving the closing delimiter.
  3761. Automatically reindent the newly barfed S-expression with respect to
  3762. its new enclosing form.&quot;</a>
  3763. (<a id='2444' tid='2443' class='u'>interactive</a>)
  3764. <span class='i'>(paredit-lose-if-not-in-sexp &#39;paredit-forward-barf-sexp)</span>
  3765. (<a id='2446' tid='2445' class='u'>save-excursion</a>
  3766. (<a id='2448' tid='2447' class='u'>up-list</a>) <a id='2450' tid='2449' class='u'>; Up to the end of the list to
  3767. </a> (<a id='2452' tid='2451' class='u'>let</a> ((<a id='2454' tid='2453' class='u'>close</a> (<a id='2456' tid='2455' class='u'>char-before</a>))) <a id='2458' tid='2457' class='u'>; save and delete the closing
  3768. </a> (<a id='2460' tid='2459' class='u'>backward-delete-char</a> <a id='2462' tid='2461' class='u'>1</a>) <a id='2464' tid='2463' class='u'>; delimiter.
  3769. </a> (<a id='2466' tid='2465' class='u'>paredit-ignore-sexp-errors</a> <a id='2468' tid='2467' class='u'>; Go back to where we want to
  3770. </a> (<a id='2470' tid='2469' class='u'>backward-sexp</a>)) <a id='2472' tid='2471' class='u'>; insert the delimiter.
  3771. </a> (<a id='2474' tid='2473' class='u'>paredit-skip-whitespace</a> <a id='2476' tid='2475' class='u'>nil</a>) <a id='2478' tid='2477' class='u'>; Skip leading whitespace.
  3772. </a> (<a id='2480' tid='2479' class='u'>cond</a> ((<a id='2482' tid='2481' class='u'>bobp</a>)
  3773. (<a id='2484' tid='2483' class='u'>error</a> <a id='2486' tid='2485' class='u'>&quot;Barfing all subexpressions with no open-paren?&quot;</a>))
  3774. ((<a id='2488' tid='2487' class='u'>paredit-in-comment-p</a>) <a id='2490' tid='2489' class='u'>; Don&#39;t put the close-paren in
  3775. </a> (<a id='2492' tid='2491' class='u'>newline-and-indent</a>))) <a id='2494' tid='2493' class='u'>; a comment.
  3776. </a> (<a id='2496' tid='2495' class='u'>insert</a> <a id='2498' tid='2497' class='u'>close</a>))
  3777. <a id='2500' tid='2499' class='u'>;; Reindent all of the newly barfed S-expressions.
  3778. </a> (<a id='2502' tid='2501' class='u'>paredit-forward-and-indent</a>)))
  3779. (<a id='2152' tid='2151' class='u'>defun</a> <a id='2154' tid='2153' class='u'>paredit-backward-slurp-sexp</a> ()
  3780. <a id='2156' tid='2155' class='u'>&quot;Add the S-expression preceding the current list into that list
  3781. by moving the closing delimiter.
  3782. Automatically reindent the whole form into which new S-expression was
  3783. slurped.
  3784. If in a string, move the opening double-quote backward by one
  3785. S-expression and escape any intervening characters as necessary,
  3786. without altering any indentation or formatting.&quot;</a>
  3787. (<a id='2158' tid='2157' class='u'>interactive</a>)
  3788. <span class='i'>(save-excursion
  3789. (cond ((or (paredit-in-comment-p)
  3790. (paredit-in-char-p))
  3791. (error &quot;Invalid context for slurping S-expressions.&quot;))
  3792. ((paredit-in-string-p)
  3793. (paredit-backward-slurp-into-string))
  3794. (t
  3795. (paredit-backward-slurp-into-list))))</span>)
  3796. (<a id='2122' tid='2121' class='u'>defun</a> <a id='2124' tid='2123' class='u'>paredit-backward-slurp-into-list</a> ()
  3797. (<a id='2126' tid='2125' class='u'>backward-up-list</a>)
  3798. (<a id='1290' tid='1289' class='m'>let</a> ((<a id='1292' tid='1291' class='m'>open</a> (<a id='1294' tid='1293' class='m'>char-after</a>)))
  3799. (<a id='1296' tid='1295' class='m'>delete-char</a> <a id='1298' tid='1297' class='m'>1</a>)
  3800. (<a id='1300' tid='1299' class='m'>catch</a> <a id='1302' tid='1301' class='m'>&#39;</a><a id='1304' tid='1303' class='m'>return</a>
  3801. (<a id='1306' tid='1305' class='m'>while</a> <a id='1308' tid='1307' class='m'>t</a>
  3802. (<span class='i'>paredit-handle-sexp-errors</span>
  3803. (<a id='1310' tid='1309' class='m'>progn</a> (<a id='1312' tid='1311' class='m'>backward-sexp</a>) (<a id='1314' tid='1313' class='m'>throw</a> <a id='1316' tid='1315' class='m'>&#39;</a><a id='1318' tid='1317' class='m'>return</a> <a id='1320' tid='1319' class='m'>nil</a>))
  3804. <span class='i'>(backward-up-list)</span>
  3805. <span class='i'>(setq open
  3806. (prog1 (char-after)
  3807. (save-excursion (insert open) (delete-char 1))))</span>)))
  3808. (<a id='1322' tid='1321' class='m'>insert</a> <a id='1324' tid='1323' class='m'>open</a>))
  3809. <span class='i'>;; Reindent the line at the beginning of wherever we inserted the
  3810. </span> <span class='i'>;; opening delimiter, and then indent the whole S-expression.
  3811. </span> (<a id='2128' tid='2127' class='u'>backward-up-list</a>)
  3812. (<a id='2130' tid='2129' class='u'>lisp-indent-line</a>)
  3813. (<a id='2132' tid='2131' class='u'>indent-sexp</a>))
  3814. (<a id='2134' tid='2133' class='u'>defun</a> <a id='2136' tid='2135' class='u'>paredit-backward-slurp-into-string</a> ()
  3815. (<a id='2138' tid='2137' class='u'>goto-char</a> (<a id='2140' tid='2139' class='u'>car</a> (<a id='2142' tid='2141' class='u'>paredit-string-start+end-points</a>)))
  3816. <a id='2144' tid='2143' class='u'>;; Signal any errors that we might get first, before mucking with the
  3817. </a> <a id='2146' tid='2145' class='u'>;; buffer&#39;s contents.
  3818. </a> (<a id='2148' tid='2147' class='u'>save-excursion</a> (<a id='2150' tid='2149' class='u'>backward-sexp</a>))
  3819. <span class='i'>(let ((open (char-after))
  3820. (target (point)))
  3821. (delete-char 1)
  3822. (backward-sexp)
  3823. (insert open)
  3824. (paredit-forward-for-quote target))</span>)
  3825. (<a id='1800' tid='1799' class='u'>defun</a> <a id='1802' tid='1801' class='u'>paredit-backward-barf-sexp</a> ()
  3826. <a id='1804' tid='1803' class='u'>&quot;Remove the first S-expression in the current list from that list
  3827. by moving the closing delimiter.
  3828. Automatically reindent the barfed S-expression and the form from which
  3829. it was barfed.&quot;</a>
  3830. (<a id='1806' tid='1805' class='u'>interactive</a>)
  3831. <span class='i'>(paredit-lose-if-not-in-sexp &#39;paredit-backward-barf-sexp)</span>
  3832. (<a id='1808' tid='1807' class='u'>save-excursion</a>
  3833. (<a id='1810' tid='1809' class='u'>backward-up-list</a>)
  3834. (<a id='1812' tid='1811' class='u'>let</a> ((<a id='1814' tid='1813' class='u'>open</a> (<a id='1816' tid='1815' class='u'>char-after</a>)))
  3835. (<a id='1818' tid='1817' class='u'>delete-char</a> <a id='1820' tid='1819' class='u'>1</a>)
  3836. (<a id='1822' tid='1821' class='u'>paredit-ignore-sexp-errors</a>
  3837. (<a id='1824' tid='1823' class='u'>paredit-forward-and-indent</a>))
  3838. (<a id='1826' tid='1825' class='u'>while</a> (<a id='1828' tid='1827' class='u'>progn</a> (<a id='1830' tid='1829' class='u'>paredit-skip-whitespace</a> <a id='1832' tid='1831' class='u'>t</a>)
  3839. (<a id='1834' tid='1833' class='u'>eq</a> (<a id='1836' tid='1835' class='u'>char-after</a>) <a id='1838' tid='1837' class='u'>?\;</a> ))
  3840. (<a id='1840' tid='1839' class='u'>forward-line</a> <a id='1842' tid='1841' class='u'>1</a>))
  3841. (<a id='1844' tid='1843' class='u'>if</a> (<a id='1846' tid='1845' class='u'>eobp</a>)
  3842. (<a id='1848' tid='1847' class='u'>error</a> <a id='1850' tid='1849' class='u'>&quot;Barfing all subexpressions with no close-paren?&quot;</a>))
  3843. <a id='1852' tid='1851' class='u'>;** Don&#39;t use `insert&#39; here. Consider, e.g., barfing from
  3844. </a> <a id='1854' tid='1853' class='u'>;** (foo|)
  3845. </a> <a id='1856' tid='1855' class='u'>;** and how `save-excursion&#39; works.
  3846. </a> (<a id='1858' tid='1857' class='u'>insert-before-markers</a> <a id='1860' tid='1859' class='u'>open</a>))
  3847. (<a id='1862' tid='1861' class='u'>backward-up-list</a>)
  3848. (<a id='1864' tid='1863' class='u'>lisp-indent-line</a>)
  3849. (<a id='1866' tid='1865' class='u'>indent-sexp</a>)))
  3850. <a id='4888' tid='4887' class='u'>;;;; Splitting & Joining
  3851. </a>
  3852. (<a id='4560' tid='4559' class='u'>defun</a> <a id='4562' tid='4561' class='u'>paredit-split-sexp</a> ()
  3853. <a id='4564' tid='4563' class='u'>&quot;Split the list or string the point is on into two.&quot;</a>
  3854. (<a id='4566' tid='4565' class='u'>interactive</a>)
  3855. (<span class='i'>cond</span> ((<a id='1326' tid='1325' class='m'>paredit-in-string-p</a>)
  3856. (<a id='1328' tid='1327' class='m'>insert</a> <a id='1330' tid='1329' class='m'>&quot;\&quot;&quot;</a>)
  3857. (<a id='1332' tid='1331' class='m'>save-excursion</a> (<a id='1334' tid='1333' class='m'>insert</a> <a id='1336' tid='1335' class='m'>&quot; \&quot;&quot;</a>)))
  3858. <span class='i'>((or (paredit-in-comment-p)
  3859. (paredit-in-char-p))
  3860. (error &quot;Invalid context for splitting S-expression.&quot;))</span>
  3861. (<a id='574' tid='573' class='m'>t</a> (<a id='576' tid='575' class='m'>let</a> ((<a id='578' tid='577' class='m'>open</a> (<a id='580' tid='579' class='m'>save-excursion</a> (<a id='582' tid='581' class='m'>backward-up-list</a>)
  3862. (<a id='584' tid='583' class='m'>char-after</a>)))
  3863. (<a id='586' tid='585' class='m'>close</a> (<a id='588' tid='587' class='m'>save-excursion</a> (<a id='590' tid='589' class='m'>up-list</a>)
  3864. (<a id='592' tid='591' class='m'>char-before</a>))))
  3865. (<a id='594' tid='593' class='m'>delete-horizontal-space</a>)
  3866. (<a id='596' tid='595' class='m'>insert</a> <a id='598' tid='597' class='m'>close</a>)
  3867. (<a id='600' tid='599' class='m'>save-excursion</a> (<a id='602' tid='601' class='m'>insert</a> <a id='604' tid='603' class='m'>?\ </a>)
  3868. (<a id='606' tid='605' class='m'>insert</a> <a id='608' tid='607' class='m'>open</a>)
  3869. (<a id='610' tid='609' class='m'>backward-char</a>)
  3870. (<a id='612' tid='611' class='m'>indent-sexp</a>))))))
  3871. (<a id='3648' tid='3647' class='u'>defun</a> <a id='3650' tid='3649' class='u'>paredit-join-sexps</a> ()
  3872. <a id='3652' tid='3651' class='u'>&quot;Join the S-expressions adjacent on either side of the point.
  3873. Both must be lists, strings, or atoms; error if there is a mismatch.&quot;</a>
  3874. (<a id='3654' tid='3653' class='u'>interactive</a>)
  3875. <a id='3656' tid='3655' class='u'>;++ How ought this to handle comments intervening symbols or strings?
  3876. </a> (<a id='1338' tid='1337' class='m'>save-excursion</a>
  3877. (<span class='i'>if</span> <span class='i'>(or (paredit-in-comment-p)
  3878. (paredit-in-string-p)
  3879. (paredit-in-char-p))</span>
  3880. <span class='i'>(error &quot;Invalid context for joining S-expressions.&quot;)</span>
  3881. (<span class='i'>let</span> <span class='i'>((left-point (paredit-point-at-sexp-end))
  3882. (right-point (paredit-point-at-sexp-start)))</span>
  3883. (<a id='1340' tid='1339' class='m'>let</a> ((<a id='1342' tid='1341' class='m'>left-char</a> (<a id='1344' tid='1343' class='m'>char-before</a> <a id='1346' tid='1345' class='m'>left-point</a>))
  3884. (<a id='1348' tid='1347' class='m'>right-char</a> (<a id='1350' tid='1349' class='m'>char-after</a> <a id='1352' tid='1351' class='m'>right-point</a>)))
  3885. (<a id='1354' tid='1353' class='m'>let</a> ((<a id='1356' tid='1355' class='m'>left-syntax</a> (<a id='1358' tid='1357' class='m'>char-syntax</a> <a id='1360' tid='1359' class='m'>left-char</a>))
  3886. (<a id='1362' tid='1361' class='m'>right-syntax</a> (<a id='1364' tid='1363' class='m'>char-syntax</a> <a id='1366' tid='1365' class='m'>right-char</a>)))
  3887. (<a id='1368' tid='1367' class='m'>cond</a> ((<a id='1370' tid='1369' class='m'>&gt;=</a> <a id='1372' tid='1371' class='m'>left-point</a> <a id='1374' tid='1373' class='m'>right-point</a>)
  3888. (<a id='1376' tid='1375' class='m'>error</a> <a id='1378' tid='1377' class='m'>&quot;Can&#39;t join a datum with itself.&quot;</a>))
  3889. ((<a id='1380' tid='1379' class='m'>and</a> (<a id='1382' tid='1381' class='m'>eq</a> <a id='1384' tid='1383' class='m'>left-syntax</a> <a id='1386' tid='1385' class='m'>?\)</a> )
  3890. (<a id='1388' tid='1387' class='m'>eq</a> <a id='1390' tid='1389' class='m'>right-syntax</a> <a id='1392' tid='1391' class='m'>?\(</a> )
  3891. (<a id='1394' tid='1393' class='m'>eq</a> <a id='1396' tid='1395' class='m'>left-char</a> (<a id='1398' tid='1397' class='m'>matching-paren</a> <a id='1400' tid='1399' class='m'>right-char</a>))
  3892. (<a id='1402' tid='1401' class='m'>eq</a> <a id='1404' tid='1403' class='m'>right-char</a> (<a id='1406' tid='1405' class='m'>matching-paren</a> <a id='1408' tid='1407' class='m'>left-char</a>)))
  3893. <a id='1410' tid='1409' class='m'>;; Leave intermediate formatting alone.
  3894. </a> (<a id='1412' tid='1411' class='m'>goto-char</a> <a id='1414' tid='1413' class='m'>right-point</a>)
  3895. (<a id='1416' tid='1415' class='m'>delete-char</a> <a id='1418' tid='1417' class='m'>1</a>)
  3896. (<a id='1420' tid='1419' class='m'>goto-char</a> <a id='1422' tid='1421' class='m'>left-point</a>)
  3897. (<a id='1424' tid='1423' class='m'>backward-delete-char</a> <a id='1426' tid='1425' class='m'>1</a>)
  3898. (<a id='1428' tid='1427' class='m'>backward-up-list</a>)
  3899. (<a id='1430' tid='1429' class='m'>indent-sexp</a>))
  3900. ((<a id='1432' tid='1431' class='m'>and</a> (<a id='1434' tid='1433' class='m'>eq</a> <a id='1436' tid='1435' class='m'>left-syntax</a> <a id='1438' tid='1437' class='m'>?\&quot;</a> )
  3901. (<a id='1440' tid='1439' class='m'>eq</a> <a id='1442' tid='1441' class='m'>right-syntax</a> <a id='1444' tid='1443' class='m'>?\&quot;</a> ))
  3902. <a id='1446' tid='1445' class='m'>;; Delete any intermediate formatting.
  3903. </a> (<a id='1448' tid='1447' class='m'>delete-region</a> (<a id='1450' tid='1449' class='m'>1-</a> <a id='1452' tid='1451' class='m'>left-point</a>)
  3904. (<a id='1454' tid='1453' class='m'>1+</a> <a id='1456' tid='1455' class='m'>right-point</a>)))
  3905. ((<a id='1458' tid='1457' class='m'>and</a> (<a id='1460' tid='1459' class='m'>memq</a> <a id='1462' tid='1461' class='m'>left-syntax</a> <a id='1464' tid='1463' class='m'>&#39;</a>(<a id='1466' tid='1465' class='m'>?w</a> <a id='1468' tid='1467' class='m'>?_</a>)) <a id='1470' tid='1469' class='m'>; Word or symbol
  3906. </a> (<a id='1472' tid='1471' class='m'>memq</a> <a id='1474' tid='1473' class='m'>right-syntax</a> <a id='1476' tid='1475' class='m'>&#39;</a>(<a id='1478' tid='1477' class='m'>?w</a> <a id='1480' tid='1479' class='m'>?_</a>)))
  3907. (<a id='1482' tid='1481' class='m'>delete-region</a> <a id='1484' tid='1483' class='m'>left-point</a> <a id='1486' tid='1485' class='m'>right-point</a>))
  3908. (<a id='1488' tid='1487' class='m'>t</a>
  3909. (<a id='1490' tid='1489' class='m'>error</a> <a id='1492' tid='1491' class='m'>&quot;Mismatched S-expressions to join.&quot;</a>)))))))))
  3910. <span class='i'>;;;; Variations on the Lurid Theme
  3911. </span>
  3912. <span class='i'>;;; I haven&#39;t the imagination to concoct clever names for these.
  3913. </span>
  3914. <span class='i'>(defun paredit-add-to-previous-list ()
  3915. &quot;Add the S-expression following point to the list preceding point.&quot;
  3916. (interactive)
  3917. (paredit-lose-if-not-in-sexp &#39;paredit-add-to-previous-list)
  3918. (save-excursion
  3919. (backward-down-list)
  3920. (paredit-forward-slurp-sexp)))</span>
  3921. <span class='i'>(defun paredit-add-to-next-list ()
  3922. &quot;Add the S-expression preceding point to the list following point.
  3923. If no S-expression precedes point, move up the tree until one does.&quot;
  3924. (interactive)
  3925. (paredit-lose-if-not-in-sexp &#39;paredit-add-to-next-list)
  3926. (save-excursion
  3927. (down-list)
  3928. (paredit-backward-slurp-sexp)))</span>
  3929. <span class='i'>(defun paredit-join-with-previous-list ()
  3930. &quot;Join the list the point is on with the previous list in the buffer.&quot;
  3931. (interactive)
  3932. (paredit-lose-if-not-in-sexp &#39;paredit-join-with-previous-list)
  3933. (save-excursion
  3934. (while (paredit-handle-sexp-errors (save-excursion (backward-sexp) nil)
  3935. (backward-up-list)
  3936. t))
  3937. (paredit-join-sexps)))</span>
  3938. <span class='i'>(defun paredit-join-with-next-list ()
  3939. &quot;Join the list the point is on with the next list in the buffer.&quot;
  3940. (interactive)
  3941. (paredit-lose-if-not-in-sexp &#39;paredit-join-with-next-list)
  3942. (save-excursion
  3943. (while (paredit-handle-sexp-errors (save-excursion (forward-sexp) nil)
  3944. (up-list)
  3945. t))
  3946. (paredit-join-sexps)))</span>
  3947. <span class='i'>;;;; Utilities
  3948. </span>
  3949. (<a id='3262' tid='3261' class='u'>defun</a> <a id='3264' tid='3263' class='u'>paredit-in-string-escape-p</a> ()
  3950. <a id='3266' tid='3265' class='u'>&quot;True if the point is on a character escape of a string.
  3951. This is true only if the character is preceded by an odd number of
  3952. backslashes.
  3953. This assumes that `paredit-in-string-p&#39; has already returned true.&quot;</a>
  3954. (<a id='3268' tid='3267' class='u'>let</a> ((<a id='3270' tid='3269' class='u'>oddp</a> <a id='3272' tid='3271' class='u'>nil</a>))
  3955. (<a id='3274' tid='3273' class='u'>save-excursion</a>
  3956. (<a id='3276' tid='3275' class='u'>while</a> (<a id='3278' tid='3277' class='u'>eq</a> (<a id='3280' tid='3279' class='u'>char-before</a>) <a id='3282' tid='3281' class='u'>?\\</a> )
  3957. (<a id='3284' tid='3283' class='u'>setq</a> <a id='3286' tid='3285' class='u'>oddp</a> (<a id='3288' tid='3287' class='u'>not</a> <a id='3290' tid='3289' class='u'>oddp</a>))
  3958. (<a id='3292' tid='3291' class='u'>backward-char</a>)))
  3959. <a id='3294' tid='3293' class='u'>oddp</a>))
  3960. (<a id='3228' tid='3227' class='u'>defun</a> <a id='3230' tid='3229' class='u'>paredit-in-char-p</a> <span class='i'>(&optional argument)</span>
  3961. <a id='3232' tid='3231' class='u'>&quot;True if the point is immediately after a character literal.
  3962. A preceding escape character, not preceded by another escape character,
  3963. is considered a character literal prefix. (This works for elisp,
  3964. Common Lisp, and Scheme.)
  3965. Assumes that `paredit-in-string-p&#39; is false, so that it need not handle
  3966. long sequences of preceding backslashes in string escapes. (This
  3967. assumes some other leading character token -- ? in elisp, # in Scheme
  3968. and Common Lisp.)&quot;</a>
  3969. <span class='i'>(let ((argument (or argument (point))))
  3970. (and (eq (char-before argument) ?\\ )
  3971. (not (eq (char-before (1- argument)) ?\\ ))))</span>)
  3972. <span class='i'>(defun paredit-indent-sexps ()
  3973. &quot;If in a list, indent all following S-expressions in the list.&quot;
  3974. (let ((start (point))
  3975. (end (paredit-handle-sexp-errors (progn (up-list) (point)) nil)))
  3976. (if end
  3977. (indent-region start end))))</span>
  3978. (<a id='2434' tid='2433' class='u'>defun</a> <a id='2436' tid='2435' class='u'>paredit-forward-and-indent</a> ()
  3979. <span class='i'>&quot;Move forward an S-expression, indenting it with `indent-region&#39;.&quot;</span>
  3980. <span class='i'>(let ((start (point)))
  3981. (forward-sexp)
  3982. (indent-region start (point)))</span>)
  3983. (<a id='4446' tid='4445' class='u'>defun</a> <a id='4448' tid='4447' class='u'>paredit-skip-whitespace</a> (<a id='4450' tid='4449' class='u'>trailing-p</a> <a id='4452' tid='4451' class='u'>&optional</a> <a id='4454' tid='4453' class='u'>limit</a>)
  3984. <a id='4456' tid='4455' class='u'>&quot;Skip past any whitespace, or until the point LIMIT is reached.
  3985. If TRAILING-P is nil, skip leading whitespace; otherwise, skip trailing
  3986. whitespace.&quot;</a>
  3987. (<a id='4458' tid='4457' class='u'>funcall</a> (<a id='4460' tid='4459' class='u'>if</a> <a id='4462' tid='4461' class='u'>trailing-p</a> <a id='4464' tid='4463' class='u'>&#39;</a><a id='4466' tid='4465' class='u'>skip-chars-forward</a> <a id='4468' tid='4467' class='u'>&#39;</a><a id='4470' tid='4469' class='u'>skip-chars-backward</a>)
  3988. <a id='4472' tid='4471' class='u'>&quot; \t\n &quot;</a> <a id='4474' tid='4473' class='u'>; This should skip using the syntax table, but LF
  3989. </a> <a id='4476' tid='4475' class='u'>limit</a>)) <span class='i'>; is a comment end, not newline, in Lisp mode.
  3990. </span>
  3991. (<a id='4890' tid='4889' class='u'>defalias</a> <a id='4892' tid='4891' class='u'>&#39;</a><a id='4894' tid='4893' class='u'>paredit-region-active-p</a>
  3992. (<a id='4896' tid='4895' class='u'>xcond</a> ((<a id='4898' tid='4897' class='u'>paredit-xemacs-p</a>) <a id='4900' tid='4899' class='u'>&#39;</a><a id='4902' tid='4901' class='u'>region-active-p</a>)
  3993. ((<a id='4904' tid='4903' class='u'>paredit-gnu-emacs-p</a>)
  3994. (<a id='4906' tid='4905' class='u'>lambda</a> ()
  3995. (<a id='4908' tid='4907' class='u'>and</a> <a id='4910' tid='4909' class='u'>mark-active</a> <a id='4912' tid='4911' class='u'>transient-mark-mode</a>)))))
  3996. <span class='i'>(defun paredit-hack-kill-region (start end)
  3997. &quot;Kill the region between START and END.
  3998. Do not append to any current kill, and
  3999. do not let the next kill append to this one.&quot;
  4000. (interactive &quot;r&quot;) ;Eh, why not?
  4001. ;; KILL-REGION sets THIS-COMMAND to tell the next kill that the last
  4002. ;; command was a kill. It also checks LAST-COMMAND to see whether it
  4003. ;; should append. If we bind these locally, any modifications to
  4004. ;; THIS-COMMAND will be masked, and it will not see LAST-COMMAND to
  4005. ;; indicate that it should append.
  4006. (let ((this-command nil)
  4007. (last-command nil))
  4008. (kill-region start end)))</span>
  4009. <a id='4914' tid='4913' class='u'>;;;;; S-expression Parsing Utilities
  4010. </a>
  4011. <a id='4916' tid='4915' class='u'>;++ These routines redundantly traverse S-expressions a great deal.
  4012. </a><a id='4918' tid='4917' class='u'>;++ If performance issues arise, this whole section will probably have
  4013. </a><a id='4920' tid='4919' class='u'>;++ to be refactored to preserve the state longer, like paredit.scm
  4014. </a><a id='4922' tid='4921' class='u'>;++ does, rather than to traverse the definition N times for every key
  4015. </a><a id='4924' tid='4923' class='u'>;++ stroke as it presently does.
  4016. </a>
  4017. (<a id='2222' tid='2221' class='u'>defun</a> <a id='2224' tid='2223' class='u'>paredit-current-parse-state</a> ()
  4018. <a id='2226' tid='2225' class='u'>&quot;Return parse state of point from beginning of defun.&quot;</a>
  4019. (<a id='2228' tid='2227' class='u'>let</a> ((<a id='2230' tid='2229' class='u'>point</a> (<a id='2232' tid='2231' class='u'>point</a>)))
  4020. (<a id='2234' tid='2233' class='u'>beginning-of-defun</a>)
  4021. <a id='2236' tid='2235' class='u'>;; Calling PARSE-PARTIAL-SEXP will advance the point to its second
  4022. </a> <a id='2238' tid='2237' class='u'>;; argument (unless parsing stops due to an error, but we assume it
  4023. </a> <a id='2240' tid='2239' class='u'>;; won&#39;t in paredit-mode).
  4024. </a> (<a id='2242' tid='2241' class='u'>parse-partial-sexp</a> (<a id='2244' tid='2243' class='u'>point</a>) <a id='2246' tid='2245' class='u'>point</a>)))
  4025. (<a id='3296' tid='3295' class='u'>defun</a> <a id='3298' tid='3297' class='u'>paredit-in-string-p</a> (<a id='3300' tid='3299' class='u'>&optional</a> <a id='3302' tid='3301' class='u'>state</a>)
  4026. <a id='3304' tid='3303' class='u'>&quot;True if the parse state is within a double-quote-delimited string.
  4027. If no parse state is supplied, compute one from the beginning of the
  4028. defun to the point.&quot;</a>
  4029. <a id='3306' tid='3305' class='u'>;; 3. non-nil if inside a string (the terminator character, really)
  4030. </a> (<a id='3308' tid='3307' class='u'>and</a> (<a id='3310' tid='3309' class='u'>nth</a> <a id='3312' tid='3311' class='u'>3</a> (<a id='3314' tid='3313' class='u'>or</a> <a id='3316' tid='3315' class='u'>state</a> (<a id='3318' tid='3317' class='u'>paredit-current-parse-state</a>)))
  4031. <a id='3320' tid='3319' class='u'>t</a>))
  4032. (<a id='4568' tid='4567' class='u'>defun</a> <a id='4570' tid='4569' class='u'>paredit-string-start+end-points</a> (<a id='4572' tid='4571' class='u'>&optional</a> <a id='4574' tid='4573' class='u'>state</a>)
  4033. <a id='4576' tid='4575' class='u'>&quot;Return a cons of the points of open and close quotes of the string.
  4034. The string is determined from the parse state STATE, or the parse state
  4035. from the beginning of the defun to the point.
  4036. This assumes that `paredit-in-string-p&#39; has already returned true, i.e.
  4037. that the point is already within a string.&quot;</a>
  4038. (<a id='4578' tid='4577' class='u'>save-excursion</a>
  4039. <a id='4580' tid='4579' class='u'>;; 8. character address of start of comment or string; nil if not
  4040. </a> <a id='4582' tid='4581' class='u'>;; in one
  4041. </a> (<a id='4584' tid='4583' class='u'>let</a> ((<a id='4586' tid='4585' class='u'>start</a> (<a id='4588' tid='4587' class='u'>nth</a> <a id='4590' tid='4589' class='u'>8</a> (<a id='4592' tid='4591' class='u'>or</a> <a id='4594' tid='4593' class='u'>state</a> (<a id='4596' tid='4595' class='u'>paredit-current-parse-state</a>)))))
  4042. (<a id='4598' tid='4597' class='u'>goto-char</a> <a id='4600' tid='4599' class='u'>start</a>)
  4043. (<a id='4602' tid='4601' class='u'>forward-sexp</a> <a id='4604' tid='4603' class='u'>1</a>)
  4044. (<a id='4606' tid='4605' class='u'>cons</a> <a id='4608' tid='4607' class='u'>start</a> (<a id='4610' tid='4609' class='u'>1-</a> (<a id='4612' tid='4611' class='u'>point</a>))))))
  4045. (<a id='3234' tid='3233' class='u'>defun</a> <a id='3236' tid='3235' class='u'>paredit-in-comment-p</a> (<a id='3238' tid='3237' class='u'>&optional</a> <a id='3240' tid='3239' class='u'>state</a>)
  4046. <a id='3242' tid='3241' class='u'>&quot;True if parse state STATE is within a comment.
  4047. If no parse state is supplied, compute one from the beginning of the
  4048. defun to the point.&quot;</a>
  4049. <a id='3244' tid='3243' class='u'>;; 4. nil if outside a comment, t if inside a non-nestable comment,
  4050. </a> <a id='3246' tid='3245' class='u'>;; else an integer (the current comment nesting)
  4051. </a> (<a id='3248' tid='3247' class='u'>and</a> (<a id='3250' tid='3249' class='u'>nth</a> <a id='3252' tid='3251' class='u'>4</a> (<a id='3254' tid='3253' class='u'>or</a> <a id='3256' tid='3255' class='u'>state</a> (<a id='3258' tid='3257' class='u'>paredit-current-parse-state</a>)))
  4052. <a id='3260' tid='3259' class='u'>t</a>))
  4053. (<a id='4220' tid='4219' class='u'>defun</a> <a id='4222' tid='4221' class='u'>paredit-point-at-sexp-boundary</a> (<a id='4224' tid='4223' class='u'>n</a>)
  4054. (<a id='4226' tid='4225' class='u'>cond</a> ((<a id='4228' tid='4227' class='u'>&lt;</a> <a id='4230' tid='4229' class='u'>n</a> <a id='4232' tid='4231' class='u'>0</a>) (<a id='4234' tid='4233' class='u'>paredit-point-at-sexp-start</a>))
  4055. ((<a id='4236' tid='4235' class='u'>=</a> <a id='4238' tid='4237' class='u'>n</a> <a id='4240' tid='4239' class='u'>0</a>) (<a id='4242' tid='4241' class='u'>point</a>))
  4056. ((<a id='4244' tid='4243' class='u'>&gt;</a> <a id='4246' tid='4245' class='u'>n</a> <a id='4248' tid='4247' class='u'>0</a>) (<a id='4250' tid='4249' class='u'>paredit-point-at-sexp-end</a>))))
  4057. (<a id='4256' tid='4255' class='u'>defun</a> <a id='4258' tid='4257' class='u'>paredit-point-at-sexp-start</a> ()
  4058. <span class='i'>(save-excursion
  4059. (forward-sexp)
  4060. (backward-sexp)
  4061. (point))</span>)
  4062. (<a id='4252' tid='4251' class='u'>defun</a> <a id='4254' tid='4253' class='u'>paredit-point-at-sexp-end</a> ()
  4063. <span class='i'>(save-excursion
  4064. (backward-sexp)
  4065. (forward-sexp)
  4066. (point))</span>)
  4067. <span class='i'>(defun paredit-lose-if-not-in-sexp (command)
  4068. (if (or (paredit-in-string-p)
  4069. (paredit-in-comment-p)
  4070. (paredit-in-char-p))
  4071. (error &quot;Invalid context for command `%s&#39;.&quot; command)))</span>
  4072. <span class='i'>(defun paredit-check-region (start end)
  4073. (save-restriction
  4074. (narrow-to-region start end)
  4075. (if (fboundp &#39;check-parens)
  4076. (check-parens)
  4077. (save-excursion
  4078. (goto-char (point-min))
  4079. (while (not (eobp))
  4080. (forward-sexp))))))</span>
  4081. <span class='i'>(defun paredit-region-ok-p (start end)
  4082. (paredit-handle-sexp-errors
  4083. (progn
  4084. (save-restriction
  4085. (narrow-to-region start end)
  4086. ;; Can&#39;t use `check-parens&#39; here -- it signals the wrong kind
  4087. ;; of errors.
  4088. (save-excursion
  4089. (goto-char (point-min))
  4090. (while (not (eobp))
  4091. (forward-sexp))))
  4092. t)
  4093. nil))</span>
  4094. <a id='4926' tid='4925' class='u'>;;;; Initialization
  4095. </a>
  4096. (<a id='4928' tid='4927' class='u'>paredit-define-keys</a>)
  4097. (<a id='4930' tid='4929' class='u'>paredit-annotate-mode-with-examples</a>)
  4098. (<a id='4932' tid='4931' class='u'>paredit-annotate-functions-with-examples</a>)
  4099. (<a id='4934' tid='4933' class='u'>provide</a> <a id='4936' tid='4935' class='u'>&#39;</a><a id='4938' tid='4937' class='u'>paredit</a>)
  4100. <span class='i'>;;; Local Variables:
  4101. </span><span class='i'>;;; outline-regexp: &quot; \n;;;;+&quot;
  4102. </span><span class='i'>;;; End:
  4103. </span>
  4104. <span class='i'>;;; paredit.el ends here
  4105. </span>
  4106. </pre>
  4107. </div>
  4108. </body>
  4109. </html>