autotype.texi 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. \input texinfo
  2. @c This is an annex of the Emacs manual.
  3. @c Author: Daniel Pfeiffer <Daniel.Pfeiffer@Informatik.START.dbp.de>
  4. @setfilename ../../info/autotype.info
  5. @c @node Autotypist, Picture, Abbrevs, Top
  6. @c @chapter Features for Automatic Typing
  7. @settitle Features for Automatic Typing
  8. @include docstyle.texi
  9. @c @cindex text
  10. @c @cindex selfinserting text
  11. @c @cindex autotypist
  12. @copying
  13. Copyright @copyright{} 1994--1995, 1999, 2001--2017
  14. Free Software Foundation, Inc.
  15. @quotation
  16. Permission is granted to copy, distribute and/or modify this document
  17. under the terms of the GNU Free Documentation License, Version 1.3 or
  18. any later version published by the Free Software Foundation; with no
  19. Invariant Sections, with the Front-Cover Texts being ``A GNU Manual'',
  20. and with the Back-Cover Texts as in (a) below. A copy of the license
  21. is included in the section entitled ``GNU Free Documentation License''.
  22. (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
  23. modify this GNU manual.''
  24. @end quotation
  25. @end copying
  26. @dircategory Emacs misc features
  27. @direntry
  28. * Autotype: (autotype). Convenient features for text that you enter
  29. frequently in Emacs.
  30. @end direntry
  31. @titlepage
  32. @sp 10
  33. @center @titlefont{Autotyping}
  34. @sp 2
  35. @center Convenient features for text that you enter frequently in Emacs
  36. @sp 2
  37. @center Daniel Pfeiffer
  38. @center additions by Dave Love
  39. @page
  40. @vskip 0pt plus 1filll
  41. @insertcopying
  42. @end titlepage
  43. @contents
  44. @node Top
  45. @top Autotyping
  46. Under certain circumstances you will find yourself typing similar things
  47. over and over again. This is especially true of form letters and programming
  48. language constructs. Project-specific header comments, flow-control
  49. constructs or magic numbers are essentially the same every time. Emacs has
  50. various features for doing tedious and repetitive typing chores for you
  51. in addition to the Abbrev features (@pxref{Abbrevs,,, emacs, The GNU Emacs Manual}).
  52. One solution is using skeletons, flexible rules that say what to
  53. insert, and how to do it. Various programming language modes offer some
  54. ready-to-use skeletons, and you can adapt them to suit your needs or
  55. taste, or define new ones.
  56. Another feature is automatic insertion of what you want into empty files,
  57. depending on the file-name or the mode as appropriate. You can have a file or
  58. a skeleton inserted, or you can call a function. Then there is the
  59. possibility to have Un*x interpreter scripts automatically take on a magic
  60. number and be executable as soon as they are saved. Or you can have a
  61. copyright notice's year updated, if necessary, every time you save a
  62. file. Similarly for time stamps in the file.
  63. URLs can be inserted based on a word at point. Flexible templates can
  64. be defined for inserting and navigating between text more generally. A
  65. sort of meta-expansion facility can be used to try a set of alternative
  66. completions and expansions of text at point.
  67. @ifnottex
  68. @insertcopying
  69. @end ifnottex
  70. @menu
  71. * Using Skeletons:: How to insert a skeleton into your text.
  72. * Wrapping Skeletons:: Putting existing text within a skeleton.
  73. * Skeletons as Abbrevs:: An alternative for issuing skeleton commands.
  74. * Skeleton Language:: Making skeleton commands insert what you want.
  75. * Inserting Pairs:: Typing one character and getting another
  76. after point.
  77. * Autoinserting:: Filling up empty files as soon as you visit them.
  78. * Copyrights:: Inserting and updating copyrights.
  79. * Executables:: Turning interpreter scripts into executables.
  80. * Timestamps:: Updating dates and times in modified files.
  81. * QuickURL:: Inserting URLs based on text at point.
  82. * Tempo:: Flexible template insertion.
  83. * Hippie Expand:: Expansion of text trying various methods.
  84. * GNU Free Documentation License:: The license for this documentation.
  85. * Concept Index::
  86. * Command Index::
  87. * Variable Index::
  88. @end menu
  89. @node Using Skeletons
  90. @chapter Using Skeletons
  91. @cindex skeletons
  92. @cindex using skeletons
  93. When you want Emacs to insert a form letter or a typical construct of the
  94. programming language you are using, skeletons are a means of accomplishing
  95. this. Normally skeletons each have a command of their own, that, when called,
  96. will insert the skeleton. These commands can be issued in the usual ways
  97. (@pxref{Commands,,, emacs, The GNU Emacs Manual}). Modes that offer various skeletons will often
  98. bind these to key-sequences on the @kbd{C-c} prefix, as well as having
  99. an @cite{Insert} menu and maybe even predefined abbrevs for them
  100. (@pxref{Skeletons as Abbrevs}).
  101. The simplest kind of skeleton will simply insert some text indented
  102. according to the major mode and leave the cursor at a likely place in the
  103. middle. Interactive skeletons may prompt you for a string that will be part
  104. of the inserted text.
  105. Skeletons may ask for input several times. They even have a looping
  106. mechanism in which you will be asked for input as long as you are willing to
  107. furnish it. An example would be multiple ``else if'' conditions. You can
  108. recognize this situation by a prompt ending in @key{RET}, @kbd{C-g}
  109. or @kbd{C-h}. This
  110. means that entering an empty string will simply assume that you are finished.
  111. Typing quit on the other hand terminates the loop but also the rest of the
  112. skeleton, e.g., an ``else'' clause is skipped. Only a syntactically necessary
  113. termination still gets inserted.
  114. @node Wrapping Skeletons
  115. @chapter Wrapping Skeletons Around Existing Text
  116. @cindex wrapping skeletons
  117. Often you will find yourself with some code that for whatever reason
  118. suddenly becomes conditional. Or you have written a bit of text and want to
  119. put it in the middle of a form letter. Skeletons provide a means for
  120. accomplishing this, and can even, in the case of programming languages,
  121. reindent the wrapped code for you.
  122. Skeleton commands take an optional numeric prefix argument
  123. (@pxref{Arguments,,, emacs, The GNU Emacs Manual}). This is interpreted in two different ways depending
  124. on whether the prefix is positive, i.e., forwards oriented, or negative,
  125. i.e., backwards oriented.
  126. A positive prefix means to wrap the skeleton around that many
  127. following words. This is accomplished by putting the words there where
  128. the point is normally left after that skeleton is inserted (@pxref{Using
  129. Skeletons}). The point (@pxref{Point,,, emacs, The GNU Emacs Manual}) is left at the next
  130. interesting spot in the skeleton instead.
  131. A negative prefix means to do something similar with that many previously
  132. marked interregions (@pxref{Mark,,, emacs, The GNU Emacs Manual}). In the simplest case, if you type
  133. @kbd{M--} just before issuing the skeleton command, that will wrap the
  134. skeleton around the current region, just like a positive argument would have
  135. wrapped it around a number of words.
  136. Smaller negative arguments will wrap that many interregions into successive
  137. interesting spots within the skeleton, again leaving the point at the next one.
  138. We speak about interregions rather than regions here, because we treat them in
  139. the order they appear in the buffer, which coincides with successive regions
  140. only if they were marked in order.
  141. That is, if you marked in alphabetical order the points A B C [] (where []
  142. represents the point) and call a skeleton command with @kbd{M-- 3}, you will
  143. wrap the text from A to B into the first interesting spot of the skeleton, the
  144. text from B to C into the next one, the text from C to the point into the
  145. third one, and leave the point in the fourth one. If there are less marks in
  146. the buffer, or if the skeleton defines less interesting points, the surplus is
  147. ignored.
  148. If, on the other hand, you marked in alphabetical order the points [] A C B,
  149. and call a skeleton command with @kbd{M-- 3}, you will wrap the text from
  150. point to A, then the text from A to C and finally the text from C to B@. This
  151. is done because the regions overlap and Emacs would be helplessly lost if it
  152. tried to follow the order in which you marked these points.
  153. @node Skeletons as Abbrevs
  154. @chapter Skeletons as Abbrev Expansions
  155. @cindex skeletons as abbrevs
  156. Rather than use a key binding for every skeleton command, you can also
  157. define an abbreviation (@pxref{Defining Abbrevs,,, emacs, The GNU Emacs Manual}) that will expand
  158. (@pxref{Expanding Abbrevs,,, emacs, The GNU Emacs Manual}) into the skeleton.
  159. Say you want @samp{ifst} to be an abbreviation for the C language if
  160. statement. You will tell Emacs that @samp{ifst} expands to the empty string
  161. and then calls the skeleton command. In Emacs Lisp you can say something like
  162. @code{(define-abbrev c-mode-abbrev-table "ifst" "" 'c-if)}. Or you can edit
  163. the output from @kbd{M-x list-abbrevs} to make it look like this:
  164. @example
  165. (c-mode-abbrev-table)
  166. "ifst" 0 "" c-if
  167. @end example
  168. @noindent
  169. (Some blank lines of no semantic significance, and other abbrev tables,
  170. have been omitted.)
  171. @node Skeleton Language
  172. @chapter Skeleton Language
  173. @cindex skeleton language
  174. @findex skeleton-insert
  175. Skeletons are an shorthand extension to the Lisp language, where various
  176. atoms directly perform either actions on the current buffer or rudimentary
  177. flow control mechanisms. Skeletons are interpreted by the function
  178. @code{skeleton-insert}.
  179. A skeleton is a list starting with an interactor, which is usually a
  180. prompt-string, or @code{nil} when not needed, but can also be a Lisp
  181. expression for complex read functions or for returning some calculated value.
  182. The rest of the list are any number of elements as described in the following
  183. table:
  184. @table @asis
  185. @item @code{"@var{string}"}, @code{?@var{c}}, @code{?\@var{c}}
  186. @vindex skeleton-transformation
  187. Insert string or character. Literal strings and characters are passed through
  188. @code{skeleton-transformation} when that is non-@code{nil}.
  189. @item @code{?\n}
  190. @c ??? something seems very wrong here.
  191. Insert a newline and align under current line, but not if this is the
  192. last element of a skeleton and the newline would be inserted at end of
  193. line, or this is the first element and the newline would be inserted
  194. at beginning of line. Use newline character @code{?\n} to prevent
  195. alignment. Use @code{"\n"} as the first or last string element of a
  196. skeleton to insert a newline unconditionally.
  197. @item @code{_}
  198. Interesting point. When wrapping skeletons around successive regions, they are
  199. put at these places. Point is left at first @code{_} where nothing is wrapped.
  200. @item @code{>}
  201. Indent line according to major mode. When following element is @code{_}, and
  202. there is a interregion that will be wrapped here, indent that interregion.
  203. @item @code{&}
  204. Logical and. If preceding element moved point, i.e., usually inserted
  205. something, do following element.
  206. @item @code{|}
  207. Logical xor. If preceding element didn't move point, i.e., usually inserted
  208. nothing, do following element.
  209. @item @code{-@var{number}}
  210. Delete preceding number characters. Depends on value of
  211. @code{skeleton-untabify}.
  212. @item @code{()} or @code{nil}
  213. Ignored.
  214. @item @var{lisp-expression}
  215. Evaluated, and the return value is again interpreted as a skeleton element.
  216. @item @code{str}
  217. A special variable that, when evaluated the first time, usually prompts
  218. for input according to the skeleton's interactor. It is then set to the
  219. return value resulting from the interactor. Each subskeleton has its local
  220. copy of this variable.
  221. @item @code{v1}, @code{v2}
  222. Skeleton-local user variables.
  223. @item @code{'@var{expression}}
  224. Evaluate following Lisp expression for its side-effect, but prevent it from
  225. being interpreted as a skeleton element.
  226. @item @var{skeleton}
  227. Subskeletons are inserted recursively, not once, but as often as the user
  228. enters something at the subskeletons interactor. Thus there must be a
  229. @code{str} in the subskeleton. They can also be used non-interactively, when
  230. prompt is a lisp-expression that returns successive list-elements.
  231. @item @code{resume:}
  232. Ignored. Execution resumes here if the user quits during skeleton
  233. interpretation.
  234. @item @code{quit}
  235. A constant which is non-@code{nil} when the @code{resume:} section was entered
  236. because the user quit.
  237. @end table
  238. @findex skeleton-further-elements
  239. Some modes also use other skeleton elements they themselves defined. For
  240. example in shell script mode's skeletons you will find @code{<} which does a
  241. rigid indentation backwards, or in CC mode's skeletons you find the
  242. self-inserting elements @code{@{} and @code{@}}. These are defined by the
  243. buffer-local variable @code{skeleton-further-elements} which is a list of
  244. variables bound while interpreting a skeleton.
  245. @findex define-skeleton
  246. The macro @code{define-skeleton} defines a command for interpreting a
  247. skeleton. The first argument is the command name, the second is a
  248. documentation string, and the rest is an interactor and any number of skeleton
  249. elements together forming a skeleton. This skeleton is assigned to a variable
  250. of the same name as the command and can thus be overridden from your
  251. @file{~/.emacs} file (@pxref{Init File,,, emacs, The GNU Emacs Manual}).
  252. @node Inserting Pairs
  253. @chapter Inserting Matching Pairs of Characters
  254. @cindex inserting pairs
  255. @cindex pairs
  256. Various characters usually appear in pairs. When, for example, you insert
  257. an open parenthesis, no matter whether you are programming or writing prose,
  258. you will surely enter a closing one later. By entering both at the same time
  259. and leaving the cursor in between, Emacs can guarantee you that such
  260. parentheses are always balanced. And if you have a non-qwerty keyboard, where
  261. typing some of the stranger programming language symbols makes you bend your
  262. fingers backwards, this can be quite relieving too.
  263. @findex skeleton-pair-insert-maybe
  264. @vindex skeleton-pair
  265. This is done by binding the first key (@pxref{Rebinding,,, emacs, The GNU Emacs Manual}) of
  266. the pair to @code{skeleton-pair-insert-maybe} instead of
  267. @code{self-insert-command}. The ``maybe'' comes from the fact that
  268. this at-first surprising behavior is initially turned off. To enable
  269. it, you must set @code{skeleton-pair} to some non-@code{nil} value.
  270. And even then, a positive argument (@pxref{Arguments,,, emacs, The GNU Emacs Manual}) will
  271. make this key behave like a self-inserting key
  272. (@pxref{Inserting Text,,, emacs, The GNU Emacs Manual}).
  273. @vindex skeleton-pair-on-word
  274. While this breaks with the stated intention of always balancing pairs, it
  275. turns out that one often doesn't want pairing to occur, when the following
  276. character is part of a word. If you want pairing to occur even then, set
  277. @code{skeleton-pair-on-word} to some non-@code{nil} value.
  278. @vindex skeleton-pair-alist
  279. Pairing is possible for all visible characters. By default the
  280. parenthesis @samp{(}, the square bracket @samp{[}, the brace
  281. @samp{@{} and the pointed bracket @samp{<} all
  282. pair with the symmetrical character, and the grave accent @samp{`}
  283. pairs with the apostrophe @samp{'}. All other characters pair
  284. themselves. This behavior can be modified by the variable
  285. @code{skeleton-pair-alist}. This is in fact an alist of skeletons
  286. (@pxref{Skeleton Language}), with the first part of each sublist
  287. matching the typed character. This is the position of the interactor,
  288. but since pairs don't need the @code{str} element, this is ignored.
  289. Some modes have bound the command @code{skeleton-pair-insert-maybe}
  290. to relevant keys. These modes also configure the pairs as
  291. appropriate. For example, when typing @TeX{} input, you'd expect the
  292. grave accent (@samp{`}) to pair with the apostrophe (@samp{'}), while in Shell
  293. script mode it must pair to itself. They can also inhibit pairing in
  294. certain contexts. For example an escaped character stands for itself.
  295. @node Autoinserting
  296. @chapter Autoinserting Text in Empty Files
  297. @cindex autoinserting
  298. @findex auto-insert
  299. @kbd{M-x auto-insert} will put some predefined text at the beginning of
  300. the buffer. The main application for this function, as its name suggests,
  301. is to have it be called automatically every time an empty, and only an
  302. empty file is visited. This is accomplished by putting @code{(add-hook
  303. 'find-file-hook 'auto-insert)} into your @file{~/.emacs} file
  304. (@pxref{Init File,,, emacs, The GNU Emacs Manual}).
  305. @vindex auto-insert-alist
  306. What gets inserted, if anything, is determined by the variable
  307. @code{auto-insert-alist}. The @sc{car}s of this list are each either
  308. a mode name, making an element applicable when a buffer is in that
  309. mode. Or they can be a string, which is a regexp matched against the
  310. buffer's file name. In that way different kinds of files that have
  311. the same mode in Emacs can be distinguished. The @sc{car}s may also
  312. be cons cells consisting of mode name or regexp as above and an
  313. additional descriptive string.
  314. When a matching element is found, the @sc{cdr} says what to do. It may
  315. be a string, which is a file name, whose contents are to be inserted, if
  316. that file is found in the directory @code{auto-insert-directory} or under a
  317. absolute file name. Or it can be a skeleton (@pxref{Skeleton Language}) to
  318. be inserted.
  319. It can also be a function, which allows doing various things. The function
  320. can simply insert some text, indeed, it can be skeleton command (@pxref{Using
  321. Skeletons}). It can be a lambda function which will for example conditionally
  322. call another function. Or it can even reset the mode for the buffer. If you
  323. want to perform several such actions in order, you use a vector, i.e., several
  324. of the above elements between square brackets (@samp{[@r{@dots{}}]}).
  325. By default C and C++ headers insert a definition of a symbol derived from
  326. the filename to prevent multiple inclusions. C and C++ sources insert an
  327. include of the header. Makefiles insert the file makefile.inc if it exists.
  328. TeX and bibTeX mode files insert the file tex-insert.tex if it exists, while
  329. LaTeX mode files insert a typical @code{\documentclass} frame. Html
  330. files insert a skeleton with the usual frame.
  331. Ada mode files call the Ada header skeleton command. Emacs lisp
  332. source files insert the usual header, with a copyright of your
  333. environment variable @env{$ORGANIZATION} or else the FSF, and prompt
  334. for valid keywords describing the contents. Files in a @file{bin}
  335. directory for which Emacs could determine no specialized mode
  336. (@pxref{Choosing Modes,,, emacs, The GNU Emacs Manual}) are set to Shell script mode.
  337. @findex define-auto-insert
  338. In Lisp (@pxref{Init File,,, emacs, The GNU Emacs Manual}) you can use the function
  339. @code{define-auto-insert} to add to or modify
  340. @code{auto-insert-alist}. See its documentation with @kbd{C-h f
  341. define-auto-insert}.
  342. @vindex auto-insert
  343. The variable @code{auto-insert} says what to do when @code{auto-insert} is
  344. called non-interactively, e.g., when a newly found file is empty (see above):
  345. @table @asis
  346. @item @code{nil}
  347. Do nothing.
  348. @item @code{t}
  349. Insert something if possible, i.e., there is a matching entry in
  350. @code{auto-insert-alist}.
  351. @item other
  352. Insert something if possible, but mark as unmodified.
  353. @end table
  354. @vindex auto-insert-query
  355. The variable @code{auto-insert-query} controls whether to ask about
  356. inserting something. When this is @code{nil}, inserting is only done with
  357. @kbd{M-x auto-insert}. When this is @code{function}, you are queried
  358. whenever @code{auto-insert} is called as a function, such as when Emacs
  359. visits an empty file and you have set the above-mentioned hook. Otherwise
  360. you are always queried.
  361. @vindex auto-insert-prompt
  362. When querying, the variable @code{auto-insert-prompt}'s value is used as a
  363. prompt for a y-or-n-type question. If this includes a @samp{%s} construct,
  364. that is replaced by what caused the insertion rule to be chosen. This is
  365. either a descriptive text, the mode-name of the buffer or the regular
  366. expression that matched the filename.
  367. @node Copyrights
  368. @chapter Inserting and Updating Copyrights
  369. @cindex copyrights
  370. @findex copyright
  371. @kbd{M-x copyright} is a skeleton inserting command, that adds a copyright
  372. notice at the point. The ``by'' part is taken from your environment variable
  373. @env{$ORGANIZATION} or if that isn't set you are prompted for it. If the
  374. buffer has a comment syntax (@pxref{Comments,,, emacs, The GNU Emacs Manual}), this is inserted as a comment.
  375. @findex copyright-update
  376. @vindex copyright-limit
  377. @vindex copyright-current-year
  378. @kbd{M-x copyright-update} looks for a copyright notice in the first
  379. @code{copyright-limit} characters of the buffer and updates it when necessary.
  380. The current year (variable @code{copyright-current-year}) is added to the
  381. existing ones, in the same format as the preceding year, i.e., 1994, '94 or 94.
  382. If a dash-separated year list up to last year is found, that is extended to
  383. current year, else the year is added separated by a comma. Or it replaces
  384. them when this is called with a prefix argument. If a header referring to a
  385. wrong version of the GNU General Public License (@pxref{Copying,,, emacs, The GNU Emacs Manual}) is found,
  386. that is updated too.
  387. An interesting application for this function is to have it be called
  388. automatically every time a file is saved. This is accomplished by
  389. putting @code{(add-hook 'before-save-hook 'copyright-update)} into
  390. your @file{~/.emacs} file (@pxref{Init File,,, emacs, The GNU Emacs Manual}). Alternative,
  391. you can do @kbd{M-x customize-variable @key{RET} before-save-hook
  392. @key{RET}}. @code{copyright-update} is conveniently listed as an
  393. option in the customization buffer.
  394. @vindex copyright-query
  395. The variable @code{copyright-query} controls whether to update the
  396. copyright or whether to ask about it. When this is @code{nil} updating is
  397. only done with @kbd{M-x copyright-update}. When this is @code{function}
  398. you are queried whenever @code{copyright-update} is called as a function,
  399. such as in the @code{before-save-hook} feature mentioned above. Otherwise
  400. you are always queried.
  401. @node Executables
  402. @chapter Making Interpreter Scripts Executable
  403. @cindex executables
  404. @vindex executable-prefix
  405. @vindex executable-chmod
  406. Various interpreter modes such as Shell script mode or AWK mode will
  407. automatically insert or update the buffer's magic number, a special
  408. comment on the first line that makes the @code{exec} systemcall know
  409. how to execute the script. To this end the script is automatically
  410. made executable upon saving, with @code{executable-chmod} as argument
  411. to the system @code{chmod} command. The magic number is prefixed by
  412. the value of @code{executable-prefix}.
  413. @vindex executable-magicless-file-regexp
  414. Any file whose name matches @code{executable-magicless-file-regexp} is not
  415. furnished with a magic number, nor is it made executable. This is mainly
  416. intended for resource files, which are only meant to be read in.
  417. @vindex executable-insert
  418. The variable @code{executable-insert} says what to do when
  419. @code{executable-set-magic} is called non-interactively, e.g., when file has no
  420. or the wrong magic number:
  421. @table @asis
  422. @item @code{nil}
  423. Do nothing.
  424. @item @code{t}
  425. Insert or update magic number.
  426. @item other
  427. Insert or update magic number, but mark as unmodified.
  428. @end table
  429. @findex executable-set-magic
  430. @vindex executable-query
  431. The variable @code{executable-query} controls whether to ask about
  432. inserting or updating the magic number. When this is @code{nil} updating
  433. is only done with @kbd{M-x executable-set-magic}. When this is
  434. @code{function} you are queried whenever @code{executable-set-magic} is
  435. called as a function, such as when Emacs puts a buffer in Shell script
  436. mode. Otherwise you are always queried.
  437. @node Timestamps
  438. @chapter Maintaining Timestamps in Modified Files
  439. @cindex timestamps
  440. @findex time-stamp
  441. @vindex before-save-hook
  442. The @code{time-stamp} command can be used to update automatically a
  443. template in a file with a new time stamp every time you save the file.
  444. Customize the hook @code{before-save-hook} to add the function
  445. @code{time-stamp} to arrange this. It you use Custom to do this,
  446. then @code{time-stamp} is conveniently listed as an option in the
  447. customization buffer.
  448. @vindex time-stamp-active
  449. @findex time-stamp-toggle-active
  450. @vindex time-stamp-format
  451. @vindex time-stamp-time-zone
  452. The time stamp is updated only if the customizable variable
  453. @code{time-stamp-active} is on, which it is by default; the command
  454. @code{time-stamp-toggle-active} can be used to toggle it. The format of
  455. the time stamp is set by the customizable variables
  456. @code{time-stamp-format} and @code{time-stamp-time-zone}.
  457. @vindex time-stamp-line-limit
  458. @vindex time-stamp-start
  459. @vindex time-stamp-end
  460. @vindex time-stamp-count
  461. @vindex time-stamp-inserts-lines
  462. The variables @code{time-stamp-line-limit}, @code{time-stamp-start},
  463. @code{time-stamp-end}, @code{time-stamp-count}, and
  464. @code{time-stamp-inserts-lines} control finding the template. Do not
  465. change these in your init file or you will be incompatible with other
  466. people's files. If you must change them, do so only in the local
  467. variables section of the file itself.
  468. Normally the template must appear in the first 8 lines of a file and
  469. look like one of the following:
  470. @example
  471. Time-stamp: <>
  472. Time-stamp: " "
  473. @end example
  474. The time stamp is written between the brackets or quotes:
  475. @example
  476. Time-stamp: <1998-02-18 10:20:51 gildea>
  477. @end example
  478. @node QuickURL
  479. @chapter QuickURL: Inserting URLs Based on Text at Point
  480. @vindex quickurl-url-file
  481. @findex quickurl
  482. @cindex URLs
  483. @kbd{M-x quickurl} can be used to insert a URL into a buffer based on
  484. the text at point. The URLs are stored in an external file defined by
  485. the variable @code{quickurl-url-file} as a list of either cons cells of
  486. the form @code{(@var{key} . @var{URL})} or
  487. lists of the form @code{(@var{key} @var{URL} @var{comment})}. These
  488. specify that @kbd{M-x quickurl} should insert @var{URL} if the word
  489. @var{key} is at point, for example:
  490. @example
  491. (("FSF" "http://www.fsf.org/" "The Free Software Foundation")
  492. ("emacs" . "http://www.emacs.org/")
  493. ("hagbard" "http://www.hagbard.demon.co.uk" "Hagbard's World"))
  494. @end example
  495. @findex quickurl-add-url
  496. @findex quickurl-list
  497. @kbd{M-x quickurl-add-url} can be used to add a new @var{key}/@var{URL}
  498. pair. @kbd{M-x quickurl-list} provides interactive editing of the URL
  499. list.
  500. @node Tempo
  501. @chapter Tempo: Flexible Template Insertion
  502. @cindex templates
  503. The Tempo package provides a simple way to define powerful templates, or
  504. macros, if you wish. It is mainly intended for, but not limited to,
  505. programmers to be used for creating shortcuts for editing
  506. certain kinds of documents.
  507. @findex tempo-backward-mark
  508. @findex tempo-forward-mark
  509. A template is defined as a list of items to be inserted in the current
  510. buffer at point. Some can be simple strings, while others can control
  511. formatting or define special points of interest in the inserted text.
  512. @kbd{M-x tempo-backward-mark} and @kbd{M-x tempo-forward-mark} can be
  513. used to jump between such points.
  514. More flexible templates can be created by including Lisp symbols, which
  515. will be evaluated as variables, or lists, which will be evaluated
  516. as Lisp expressions. Automatic completion of specified tags to expanded
  517. templates can be provided.
  518. @findex tempo-define-template
  519. See the documentation for @code{tempo-define-template} for the different
  520. items that can be used to define a tempo template with a command for
  521. inserting it.
  522. See the commentary in @file{tempo.el} for more information on using the
  523. Tempo package.
  524. @node Hippie Expand
  525. @chapter ``Hippie'' Expansion
  526. @findex hippie-expand
  527. @kindex M-/
  528. @vindex hippie-expand-try-functions-list
  529. @kbd{M-x hippie-expand} is a single command providing a variety of
  530. completions and expansions. Called repeatedly, it tries all possible
  531. completions in succession.
  532. Which ones to try, and in which order, is determined by the contents of
  533. the customizable option @code{hippie-expand-try-functions-list}. Much
  534. customization of the expansion behavior can be made by changing the
  535. order of, removing, or inserting new functions in this list. Given a
  536. positive numeric argument, @kbd{M-x hippie-expand} jumps directly that
  537. number of functions forward in this list. Given some other argument (a
  538. negative argument or just @kbd{C-u}) it undoes the tried completion.
  539. See the commentary in @file{hippie-exp.el} for more information on the
  540. possibilities.
  541. Typically you would bind @code{hippie-expand} to @kbd{M-/} with
  542. @code{dabbrev-expand}, the standard binding of @kbd{M-/}, providing one
  543. of the expansion possibilities.
  544. @node GNU Free Documentation License
  545. @appendix GNU Free Documentation License
  546. @include doclicense.texi
  547. @node Concept Index
  548. @unnumbered Concept Index
  549. @printindex cp
  550. @node Command Index
  551. @unnumbered Command Index
  552. @printindex fn
  553. @node Variable Index
  554. @unnumbered Variable Index
  555. @printindex vr
  556. @bye