files.texi 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121
  1. @c This is part of the Emacs manual.
  2. @c Copyright (C) 1985-1987, 1993-1995, 1997, 1999-2017 Free Software
  3. @c Foundation, Inc.
  4. @c See file emacs.texi for copying conditions.
  5. @node Files
  6. @chapter File Handling
  7. @cindex files
  8. The operating system stores data permanently in named @dfn{files}, so
  9. most of the text you edit with Emacs comes from a file and is ultimately
  10. stored in a file.
  11. To edit a file, you must tell Emacs to read the file and prepare a
  12. buffer containing a copy of the file's text. This is called
  13. @dfn{visiting} the file. Editing commands apply directly to text in the
  14. buffer; that is, to the copy inside Emacs. Your changes appear in the
  15. file itself only when you @dfn{save} the buffer back into the file.
  16. In addition to visiting and saving files, Emacs can delete, copy,
  17. rename, and append to files, keep multiple versions of them, and operate
  18. on file directories.
  19. @menu
  20. * File Names:: How to type and edit file-name arguments.
  21. * Visiting:: Visiting a file prepares Emacs to edit the file.
  22. * Saving:: Saving makes your changes permanent.
  23. * Reverting:: Reverting cancels all the changes not saved.
  24. @ifnottex
  25. * Autorevert:: Auto Reverting non-file buffers.
  26. @end ifnottex
  27. * Auto Save:: Auto Save periodically protects against loss of data.
  28. * File Aliases:: Handling multiple names for one file.
  29. * Directories:: Creating, deleting, and listing file directories.
  30. * Comparing Files:: Finding where two files differ.
  31. * Diff Mode:: Mode for editing file differences.
  32. * Copying and Naming:: Copying, naming and renaming files.
  33. * Misc File Ops:: Other things you can do on files.
  34. * Compressed Files:: Accessing compressed files.
  35. * File Archives:: Operating on tar, zip, jar etc. archive files.
  36. * Remote Files:: Accessing files on other machines.
  37. * Quoted File Names:: Quoting special characters in file names.
  38. * File Name Cache:: Completion against a list of files you often use.
  39. * File Conveniences:: Convenience Features for Finding Files.
  40. * Filesets:: Handling sets of files.
  41. @end menu
  42. @node File Names
  43. @section File Names
  44. @cindex file names
  45. @cindex default file name
  46. Many Emacs commands that operate on a file require you to specify
  47. the file name, using the minibuffer (@pxref{Minibuffer File}).
  48. While in the minibuffer, you can use the usual completion and
  49. history commands (@pxref{Minibuffer}). Note that file name completion
  50. ignores file names whose extensions appear in the variable
  51. @code{completion-ignored-extensions} (@pxref{Completion Options}).
  52. Note also that most commands use permissive completion with
  53. confirmation for reading file names: you are allowed to submit a
  54. nonexistent file name, but if you type @key{RET} immediately after
  55. completing up to a nonexistent file name, Emacs prints
  56. @samp{[Confirm]} and you must type a second @key{RET} to confirm.
  57. @xref{Completion Exit}, for details.
  58. @cindex default directory
  59. @vindex default-directory
  60. @vindex insert-default-directory
  61. Each buffer has a @dfn{default directory}, stored in the
  62. buffer-local variable @code{default-directory}. Whenever Emacs reads
  63. a file name using the minibuffer, it usually inserts the default
  64. directory into the minibuffer as the initial contents. You can
  65. inhibit this insertion by changing the variable
  66. @code{insert-default-directory} to @code{nil} (@pxref{Minibuffer
  67. File}). Regardless, Emacs always assumes that any relative file name
  68. is relative to the default directory, e.g., entering a file name
  69. without a directory specifies a file in the default directory.
  70. @findex cd
  71. @findex pwd
  72. When you visit a file, Emacs sets @code{default-directory} in the
  73. visiting buffer to the directory of its file. When you create a new
  74. buffer that is not visiting a file, via a command like @kbd{C-x b},
  75. its default directory is usually copied from the buffer that was
  76. current at the time (@pxref{Select Buffer}). You can use the command
  77. @kbd{M-x pwd} to see the value of @code{default-directory} in the
  78. current buffer. The command @kbd{M-x cd} prompts for a directory
  79. name, and sets the buffer's @code{default-directory} to that directory
  80. (doing this does not change the buffer's file name, if any).
  81. As an example, when you visit the file @file{/u/rms/gnu/gnu.tasks},
  82. the default directory is set to @file{/u/rms/gnu/}. If you invoke a
  83. command that reads a file name, entering just @samp{foo} in the
  84. minibuffer, with a directory omitted, specifies the file
  85. @file{/u/rms/gnu/foo}; entering @samp{../.login} specifies
  86. @file{/u/rms/.login}; and entering @samp{new/foo} specifies
  87. @file{/u/rms/gnu/new/foo}.
  88. When typing a file name into the minibuffer, you can make use of a
  89. couple of shortcuts: a double slash ignores everything before the
  90. second slash in the pair, and @samp{~/} is your home directory.
  91. @xref{Minibuffer File}.
  92. @cindex environment variables in file names
  93. @cindex expansion of environment variables
  94. @cindex @code{$} in file names
  95. @anchor{File Names with $}The character @samp{$} is used to
  96. substitute an environment variable into a file name. The name of the
  97. environment variable consists of all the alphanumeric characters after
  98. the @samp{$}; alternatively, it can be enclosed in braces after the
  99. @samp{$}. For example, if you have used the shell command
  100. @command{export FOO=rms/hacks} to set up an environment variable named
  101. @env{FOO}, then both @file{/u/$FOO/test.c} and
  102. @file{/u/$@{FOO@}/test.c} are abbreviations for
  103. @file{/u/rms/hacks/test.c}. If the environment variable is not
  104. defined, no substitution occurs, so that the character @samp{$} stands
  105. for itself. Note that environment variables affect Emacs only if they
  106. are applied before Emacs is started.
  107. To access a file with @samp{$} in its name, if the @samp{$} causes
  108. expansion, type @samp{$$}. This pair is converted to a single
  109. @samp{$} at the same time that variable substitution is performed for
  110. a single @samp{$}. Alternatively, quote the whole file name with
  111. @samp{/:} (@pxref{Quoted File Names}). File names which begin with a
  112. literal @samp{~} should also be quoted with @samp{/:}.
  113. You can include non-@acronym{ASCII} characters in file names.
  114. @xref{File Name Coding}.
  115. @node Visiting
  116. @section Visiting Files
  117. @cindex visiting files
  118. @cindex open file
  119. @table @kbd
  120. @item C-x C-f
  121. Visit a file (@code{find-file}).
  122. @item C-x C-r
  123. Visit a file for viewing, without allowing changes to it
  124. (@code{find-file-read-only}).
  125. @item C-x C-v
  126. Visit a different file instead of the one visited last
  127. (@code{find-alternate-file}).
  128. @item C-x 4 f
  129. Visit a file, in another window (@code{find-file-other-window}). Don't
  130. alter what is displayed in the selected window.
  131. @item C-x 5 f
  132. Visit a file, in a new frame (@code{find-file-other-frame}). Don't
  133. alter what is displayed in the selected frame.
  134. @item M-x find-file-literally
  135. Visit a file with no conversion of the contents.
  136. @end table
  137. @cindex files, visiting and saving
  138. @cindex saving files
  139. @dfn{Visiting} a file means reading its contents into an Emacs
  140. buffer so you can edit them. Emacs makes a new buffer for each file
  141. that you visit.
  142. @kindex C-x C-f
  143. @findex find-file
  144. To visit a file, type @kbd{C-x C-f} (@code{find-file}) and use the
  145. minibuffer to enter the name of the desired file. While in the
  146. minibuffer, you can abort the command by typing @kbd{C-g}. @xref{File
  147. Names}, for details about entering file names into minibuffers.
  148. If the specified file exists but the system does not allow you to
  149. read it, an error message is displayed in the echo area. Otherwise,
  150. you can tell that @kbd{C-x C-f} has completed successfully by the
  151. appearance of new text on the screen, and by the buffer name shown in
  152. the mode line (@pxref{Mode Line}). Emacs normally constructs the
  153. buffer name from the file name, omitting the directory name. For
  154. example, a file named @file{/usr/rms/emacs.tex} is visited in a buffer
  155. named @samp{emacs.tex}. If there is already a buffer with that name,
  156. Emacs constructs a unique name; the normal method is to add a suffix
  157. based on the directory name (e.g., @samp{<rms>}, @samp{<tmp>},
  158. and so on), but you can select other methods. @xref{Uniquify}.
  159. @cindex creating files
  160. To create a new file, just visit it using the same command, @kbd{C-x
  161. C-f}. Emacs displays @samp{(New file)} in the echo area, but in other
  162. respects behaves as if you had visited an existing empty file.
  163. @cindex modified (buffer)
  164. After visiting a file, the changes you make with editing commands are
  165. made in the Emacs buffer. They do not take effect in the visited
  166. file, until you @dfn{save} the buffer (@pxref{Saving}). If a buffer
  167. contains changes that have not been saved, we say the buffer is
  168. @dfn{modified}. This implies that some changes will be lost if the
  169. buffer is not saved. The mode line displays two stars near the left
  170. margin to indicate that the buffer is modified.
  171. If you visit a file that is already in Emacs, @kbd{C-x C-f} switches
  172. to the existing buffer instead of making another copy. Before doing
  173. so, it checks whether the file has changed since you last visited or
  174. saved it. If the file has changed, Emacs offers to reread it.
  175. @vindex large-file-warning-threshold
  176. @cindex file, warning when size is large
  177. @cindex size of file, warning when visiting
  178. @cindex maximum buffer size exceeded, error message
  179. If you try to visit a file larger than
  180. @code{large-file-warning-threshold} (the default is 10000000, which is
  181. about 10 megabytes), Emacs asks you for confirmation first. You can
  182. answer @kbd{y} to proceed with visiting the file. Note, however, that
  183. Emacs cannot visit files that are larger than the maximum Emacs buffer
  184. size, which is limited by the amount of memory Emacs can allocate and
  185. by the integers that Emacs can represent (@pxref{Buffers}). If you
  186. try, Emacs displays an error message saying that the maximum buffer
  187. size has been exceeded.
  188. @cindex wildcard characters in file names
  189. @vindex find-file-wildcards
  190. If the file name you specify contains shell-style wildcard
  191. characters, Emacs visits all the files that match it. (On
  192. case-insensitive filesystems, Emacs matches the wildcards disregarding
  193. the letter case.) Wildcards include @samp{?}, @samp{*}, and
  194. @samp{[@dots{}]} sequences. To enter the wild card @samp{?} in a file
  195. name in the minibuffer, you need to type @kbd{C-q ?}. @xref{Quoted
  196. File Names}, for information on how to visit a file whose name
  197. actually contains wildcard characters. You can disable the wildcard
  198. feature by customizing @code{find-file-wildcards}.
  199. @kindex C-x C-v
  200. @findex find-alternate-file
  201. If you visit the wrong file unintentionally by typing its name
  202. incorrectly, type @kbd{C-x C-v} (@code{find-alternate-file}) to visit
  203. the file you really wanted. @kbd{C-x C-v} is similar to @kbd{C-x
  204. C-f}, but it kills the current buffer (after first offering to save it
  205. if it is modified). When @kbd{C-x C-v} reads the file name to visit,
  206. it inserts the entire default file name in the buffer, with point just
  207. after the directory part; this is convenient if you made a slight
  208. error in typing the name.
  209. @vindex find-file-run-dired
  210. If you visit a file that is actually a directory, Emacs invokes
  211. Dired, the Emacs directory browser. @xref{Dired}. You can disable
  212. this behavior by setting the variable @code{find-file-run-dired} to
  213. @code{nil}; in that case, it is an error to try to visit a directory.
  214. Files which are actually collections of other files, or @dfn{file
  215. archives}, are visited in special modes which invoke a Dired-like
  216. environment to allow operations on archive members. @xref{File
  217. Archives}, for more about these features.
  218. If you visit a file that the operating system won't let you modify,
  219. or that is marked read-only, Emacs makes the buffer read-only too, so
  220. that you won't go ahead and make changes that you'll have trouble
  221. saving afterward. You can make the buffer writable with @kbd{C-x C-q}
  222. (@code{read-only-mode}). @xref{Misc Buffer}.
  223. @kindex C-x C-r
  224. @findex find-file-read-only
  225. If you want to visit a file as read-only in order to protect
  226. yourself from entering changes accidentally, visit it with the command
  227. @kbd{C-x C-r} (@code{find-file-read-only}) instead of @kbd{C-x C-f}.
  228. @kindex C-x 4 f
  229. @findex find-file-other-window
  230. @kbd{C-x 4 f} (@code{find-file-other-window}) is like @kbd{C-x C-f}
  231. except that the buffer containing the specified file is selected in another
  232. window. The window that was selected before @kbd{C-x 4 f} continues to
  233. show the same buffer it was already showing. If this command is used when
  234. only one window is being displayed, that window is split in two, with one
  235. window showing the same buffer as before, and the other one showing the
  236. newly requested file. @xref{Windows}.
  237. @kindex C-x 5 f
  238. @findex find-file-other-frame
  239. @kbd{C-x 5 f} (@code{find-file-other-frame}) is similar, but opens a
  240. new frame, or selects any existing frame showing the specified file.
  241. @xref{Frames}.
  242. @cindex file selection dialog
  243. On graphical displays, there are two additional methods for visiting
  244. files. Firstly, when Emacs is built with a suitable GUI toolkit,
  245. commands invoked with the mouse (by clicking on the menu bar or tool
  246. bar) use the toolkit's standard file selection dialog instead of
  247. prompting for the file name in the minibuffer. On GNU/Linux and Unix
  248. platforms, Emacs does this when built with GTK, LessTif, and Motif
  249. toolkits; on MS-Windows and Mac, the GUI version does that by default.
  250. For information on how to customize this, see @ref{Dialog Boxes}.
  251. Secondly, Emacs supports drag and drop: dropping a file into an
  252. ordinary Emacs window visits the file using that window. As an
  253. exception, dropping a file into a window displaying a Dired buffer
  254. moves or copies the file into the displayed directory. For details,
  255. see @ref{Drag and Drop}, and @ref{Misc Dired Features}.
  256. On text-mode terminals and on graphical displays when Emacs was
  257. built without a GUI toolkit, you can visit files via the menu-bar
  258. @samp{File} menu, which has a @samp{Visit New File} item.
  259. Each time you visit a file, Emacs automatically scans its contents
  260. to detect what character encoding and end-of-line convention it uses,
  261. and converts these to Emacs's internal encoding and end-of-line
  262. convention within the buffer. When you save the buffer, Emacs
  263. performs the inverse conversion, writing the file to disk with its
  264. original encoding and end-of-line convention. @xref{Coding Systems}.
  265. @findex find-file-literally
  266. If you wish to edit a file as a sequence of @acronym{ASCII}
  267. characters with no special encoding or conversion, use the @kbd{M-x
  268. find-file-literally} command. This visits a file, like @kbd{C-x C-f},
  269. but does not do format conversion (@pxref{Format Conversion,, Format
  270. Conversion, elisp, the Emacs Lisp Reference Manual}), character code
  271. conversion (@pxref{Coding Systems}), or automatic uncompression
  272. (@pxref{Compressed Files}), and does not add a final newline because
  273. of @code{require-final-newline} (@pxref{Customize Save}). If you have
  274. already visited the same file in the usual (non-literal) manner, this
  275. command asks you whether to visit it literally instead.
  276. @vindex find-file-hook
  277. @vindex find-file-not-found-functions
  278. Two special hook variables allow extensions to modify the operation
  279. of visiting files. Visiting a file that does not exist runs the
  280. functions in @code{find-file-not-found-functions}; this variable holds
  281. a list of functions, which are called one by one (with no arguments)
  282. until one of them returns non-@code{nil}. This is not a normal hook,
  283. and the name ends in @samp{-functions} rather than @samp{-hook} to
  284. indicate that fact.
  285. Successful visiting of any file, whether existing or not, calls the
  286. functions in @code{find-file-hook}, with no arguments. This variable
  287. is a normal hook. In the case of a nonexistent file, the
  288. @code{find-file-not-found-functions} are run first. @xref{Hooks}.
  289. There are several ways to specify automatically the major mode for
  290. editing the file (@pxref{Choosing Modes}), and to specify local
  291. variables defined for that file (@pxref{File Variables}).
  292. @node Saving
  293. @section Saving Files
  294. @dfn{Saving} a buffer in Emacs means writing its contents back into the file
  295. that was visited in the buffer.
  296. @menu
  297. * Save Commands:: Commands for saving files.
  298. * Backup:: How Emacs saves the old version of your file.
  299. * Customize Save:: Customizing the saving of files.
  300. * Interlocking:: How Emacs protects against simultaneous editing
  301. of one file by two users.
  302. * Shadowing: File Shadowing. Copying files to ``shadows'' automatically.
  303. * Time Stamps:: Emacs can update time stamps on saved files.
  304. @end menu
  305. @node Save Commands
  306. @subsection Commands for Saving Files
  307. These are the commands that relate to saving and writing files.
  308. @table @kbd
  309. @item C-x C-s
  310. Save the current buffer to its file (@code{save-buffer}).
  311. @item C-x s
  312. Save any or all buffers to their files (@code{save-some-buffers}).
  313. @item M-~
  314. Forget that the current buffer has been changed (@code{not-modified}).
  315. With prefix argument (@kbd{C-u}), mark the current buffer as changed.
  316. @item C-x C-w
  317. Save the current buffer with a specified file name (@code{write-file}).
  318. @item M-x set-visited-file-name
  319. Change the file name under which the current buffer will be saved.
  320. @end table
  321. @kindex C-x C-s
  322. @findex save-buffer
  323. When you wish to save the file and make your changes permanent, type
  324. @kbd{C-x C-s} (@code{save-buffer}). After saving is finished, @kbd{C-x C-s}
  325. displays a message like this:
  326. @example
  327. Wrote /u/rms/gnu/gnu.tasks
  328. @end example
  329. @noindent
  330. If the current buffer is not modified (no changes have been made in it
  331. since the buffer was created or last saved), saving is not really
  332. done, because it would have no effect. Instead, @kbd{C-x C-s}
  333. displays a message like this in the echo area:
  334. @example
  335. (No changes need to be saved)
  336. @end example
  337. With a prefix argument, @kbd{C-u C-x C-s}, Emacs also marks the buffer
  338. to be backed up when the next save is done. @xref{Backup}.
  339. @kindex C-x s
  340. @findex save-some-buffers
  341. The command @kbd{C-x s} (@code{save-some-buffers}) offers to save any
  342. or all modified buffers. It asks you what to do with each buffer. The
  343. possible responses are analogous to those of @code{query-replace}:
  344. @table @kbd
  345. @item y
  346. Save this buffer and ask about the rest of the buffers.
  347. @item n
  348. Don't save this buffer, but ask about the rest of the buffers.
  349. @item !
  350. Save this buffer and all the rest with no more questions.
  351. @c following generates acceptable underfull hbox
  352. @item @key{RET}
  353. Terminate @code{save-some-buffers} without any more saving.
  354. @item .
  355. Save this buffer, then exit @code{save-some-buffers} without even asking
  356. about other buffers.
  357. @item C-r
  358. View the buffer that you are currently being asked about. When you exit
  359. View mode, you get back to @code{save-some-buffers}, which asks the
  360. question again.
  361. @item d
  362. Diff the buffer against its corresponding file, so you can see what
  363. changes you would be saving. This calls the command
  364. @code{diff-buffer-with-file} (@pxref{Comparing Files}).
  365. @item C-h
  366. Display a help message about these options.
  367. @end table
  368. @noindent
  369. @vindex save-some-buffers-default-predicate
  370. You can customize the value of
  371. @code{save-some-buffers-default-predicate} to control which buffers
  372. Emacs will ask about.
  373. @kbd{C-x C-c}, the key sequence to exit Emacs, invokes
  374. @code{save-some-buffers} and therefore asks the same questions.
  375. @kindex M-~
  376. @findex not-modified
  377. If you have changed a buffer but do not wish to save the changes,
  378. you should take some action to prevent it. Otherwise, each time you
  379. use @kbd{C-x s} or @kbd{C-x C-c}, you are liable to save this buffer
  380. by mistake. One thing you can do is type @kbd{M-~}
  381. (@code{not-modified}), which clears out the indication that the buffer
  382. is modified. If you do this, none of the save commands will believe
  383. that the buffer needs to be saved. (@samp{~} is often used as a
  384. mathematical symbol for ``not''; thus @kbd{M-~} is ``not'', metafied.)
  385. Alternatively, you can cancel all the changes made since the file was
  386. visited or saved, by reading the text from the file again. This is
  387. called @dfn{reverting}. @xref{Reverting}. (You could also undo all
  388. the changes by repeating the undo command @kbd{C-x u} until you have
  389. undone all the changes; but reverting is easier.)
  390. @findex set-visited-file-name
  391. @kbd{M-x set-visited-file-name} alters the name of the file that the
  392. current buffer is visiting. It reads the new file name using the
  393. minibuffer. Then it marks the buffer as visiting that file name, and
  394. changes the buffer name correspondingly. @code{set-visited-file-name}
  395. does not save the buffer in the newly visited file; it just alters the
  396. records inside Emacs in case you do save later. It also marks the
  397. buffer as modified so that @kbd{C-x C-s} in that buffer
  398. @emph{will} save.
  399. @kindex C-x C-w
  400. @findex write-file
  401. If you wish to mark the buffer as visiting a different file and save
  402. it right away, use @kbd{C-x C-w} (@code{write-file}). This is
  403. equivalent to @code{set-visited-file-name} followed by @kbd{C-x C-s},
  404. except that @kbd{C-x C-w} asks for confirmation if the file exists.
  405. @kbd{C-x C-s} used on a buffer that is not visiting a file has the
  406. same effect as @kbd{C-x C-w}; that is, it reads a file name, marks the
  407. buffer as visiting that file, and saves it there. The default file
  408. name in a buffer that is not visiting a file is made by combining the
  409. buffer name with the buffer's default directory (@pxref{File Names}).
  410. If the new file name implies a major mode, then @kbd{C-x C-w} switches
  411. to that major mode, in most cases. The command
  412. @code{set-visited-file-name} also does this. @xref{Choosing Modes}.
  413. If Emacs is about to save a file and sees that the date of the latest
  414. version on disk does not match what Emacs last read or wrote, Emacs
  415. notifies you of this fact, because it probably indicates a problem caused
  416. by simultaneous editing and requires your immediate attention.
  417. @xref{Interlocking,, Simultaneous Editing}.
  418. @node Backup
  419. @subsection Backup Files
  420. @cindex backup file
  421. @vindex make-backup-files
  422. @vindex vc-make-backup-files
  423. On most operating systems, rewriting a file automatically destroys all
  424. record of what the file used to contain. Thus, saving a file from Emacs
  425. throws away the old contents of the file---or it would, except that
  426. Emacs carefully copies the old contents to another file, called the
  427. @dfn{backup} file, before actually saving.
  428. Emacs makes a backup for a file only the first time the file is
  429. saved from a buffer. No matter how many times you subsequently save
  430. the file, its backup remains unchanged. However, if you kill the
  431. buffer and then visit the file again, a new backup file will be made.
  432. For most files, the variable @code{make-backup-files} determines
  433. whether to make backup files. On most operating systems, its default
  434. value is @code{t}, so that Emacs does write backup files.
  435. For files managed by a version control system (@pxref{Version
  436. Control}), the variable @code{vc-make-backup-files} determines whether
  437. to make backup files. By default it is @code{nil}, since backup files
  438. are redundant when you store all the previous versions in a version
  439. control system.
  440. @iftex
  441. @xref{General VC Options,,,emacs-xtra, Specialized Emacs Features}.
  442. @end iftex
  443. @ifnottex
  444. @xref{General VC Options}.
  445. @end ifnottex
  446. At your option, Emacs can keep either a single backup for each file,
  447. or make a series of numbered backup files for each file that you edit.
  448. @xref{Backup Names}.
  449. @vindex backup-enable-predicate
  450. @vindex temporary-file-directory
  451. @vindex small-temporary-file-directory
  452. The default value of the @code{backup-enable-predicate} variable
  453. prevents backup files being written for files in the directories used
  454. for temporary files, specified by @code{temporary-file-directory} or
  455. @code{small-temporary-file-directory}.
  456. You can explicitly tell Emacs to make another backup file from a
  457. buffer, even though that buffer has been saved before. If you save
  458. the buffer with @kbd{C-u C-x C-s}, the version thus saved will be made
  459. into a backup file if you save the buffer again. @kbd{C-u C-u C-x
  460. C-s} saves the buffer, but first makes the previous file contents into
  461. a new backup file. @kbd{C-u C-u C-u C-x C-s} does both things: it
  462. makes a backup from the previous contents, and arranges to make
  463. another from the newly saved contents if you save again.
  464. @vindex backup-directory-alist
  465. You can customize the variable @code{backup-directory-alist} to
  466. specify that files matching certain patterns should be backed up in
  467. specific directories. A typical use is to add an element @code{("."
  468. . @var{dir})} to make all backups in the directory with absolute name
  469. @var{dir}. Emacs modifies the backup file names to avoid clashes
  470. between files with the same names originating in different
  471. directories. Alternatively, adding, @code{("." . ".~")} would make
  472. backups in the invisible subdirectory @file{.~} of the original file's
  473. directory. Emacs creates the directory, if necessary, to make the
  474. backup.
  475. @menu
  476. * Names: Backup Names. How backup files are named.
  477. * Deletion: Backup Deletion. Emacs deletes excess numbered backups.
  478. * Copying: Backup Copying. Backups can be made by copying or renaming.
  479. @end menu
  480. @node Backup Names
  481. @subsubsection Single or Numbered Backups
  482. @cindex backup file names
  483. @cindex names of backup files
  484. @cindex @file{~}, in names of backup files
  485. @cindex tilde (@file{~}) at end of backup file name
  486. When Emacs makes a backup file, its name is normally constructed by
  487. appending @samp{~} to the file name being edited; thus, the backup
  488. file for @file{eval.c} would be @file{eval.c~}.
  489. @cindex @file{~/.emacs.d/%backup%~}
  490. If access control stops Emacs from writing backup files under the
  491. usual names, it writes the backup file as @file{~/.emacs.d/%backup%~}.
  492. Only one such file can exist, so only the most recently made such
  493. backup is available.
  494. Emacs can also make @dfn{numbered backup files}. Numbered backup
  495. file names contain @samp{.~}, the number, and another @samp{~} after
  496. the original file name. Thus, the backup files of @file{eval.c} would
  497. be called @file{eval.c.~1~}, @file{eval.c.~2~}, and so on, all the way
  498. through names like @file{eval.c.~259~} and beyond.
  499. @vindex version-control
  500. The variable @code{version-control} determines whether to make
  501. single backup files or multiple numbered backup files. Its possible
  502. values are:
  503. @table @code
  504. @item nil
  505. Make numbered backups for files that have numbered backups already.
  506. Otherwise, make single backups. This is the default.
  507. @item t
  508. Make numbered backups.
  509. @item never
  510. Never make numbered backups; always make single backups.
  511. @end table
  512. @noindent
  513. The usual way to set this variable is globally, through your init file
  514. or the customization buffer. However, you can set
  515. @code{version-control} locally in an individual buffer to control the
  516. making of backups for that buffer's file (@pxref{Locals}). You can
  517. have Emacs set @code{version-control} locally whenever you visit a
  518. given file (@pxref{File Variables}). Some modes, such as Rmail mode,
  519. set this variable.
  520. @cindex @env{VERSION_CONTROL} environment variable
  521. If you set the environment variable @env{VERSION_CONTROL}, to tell
  522. various GNU utilities what to do with backup files, Emacs also obeys the
  523. environment variable by setting the Lisp variable @code{version-control}
  524. accordingly at startup. If the environment variable's value is @samp{t}
  525. or @samp{numbered}, then @code{version-control} becomes @code{t}; if the
  526. value is @samp{nil} or @samp{existing}, then @code{version-control}
  527. becomes @code{nil}; if it is @samp{never} or @samp{simple}, then
  528. @code{version-control} becomes @code{never}.
  529. @vindex make-backup-file-name-function
  530. If you set the variable @code{make-backup-file-name-function} to
  531. a suitable Lisp function, you can override the usual way Emacs
  532. constructs backup file names.
  533. @node Backup Deletion
  534. @subsubsection Automatic Deletion of Backups
  535. To prevent excessive consumption of disk space, Emacs can delete numbered
  536. backup versions automatically. Generally Emacs keeps the first few backups
  537. and the latest few backups, deleting any in between. This happens every
  538. time a new backup is made.
  539. @vindex kept-old-versions
  540. @vindex kept-new-versions
  541. The two variables @code{kept-old-versions} and
  542. @code{kept-new-versions} control this deletion. Their values are,
  543. respectively, the number of oldest (lowest-numbered) backups to keep
  544. and the number of newest (highest-numbered) ones to keep, each time a
  545. new backup is made. The backups in the middle (excluding those oldest
  546. and newest) are the excess middle versions---those backups are
  547. deleted. These variables' values are used when it is time to delete
  548. excess versions, just after a new backup version is made; the newly
  549. made backup is included in the count in @code{kept-new-versions}. By
  550. default, both variables are 2.
  551. @vindex delete-old-versions
  552. If @code{delete-old-versions} is @code{t}, Emacs deletes the excess
  553. backup files silently. If it is @code{nil}, the default, Emacs asks
  554. you whether it should delete the excess backup versions. If it has
  555. any other value, then Emacs never automatically deletes backups.
  556. Dired's @kbd{.} (Period) command can also be used to delete old versions.
  557. @xref{Dired Deletion}.
  558. @node Backup Copying
  559. @subsubsection Copying vs.@: Renaming
  560. Backup files can be made by copying the old file or by renaming it.
  561. This makes a difference when the old file has multiple names (hard
  562. links). If the old file is renamed into the backup file, then the
  563. alternate names become names for the backup file. If the old file is
  564. copied instead, then the alternate names remain names for the file
  565. that you are editing, and the contents accessed by those names will be
  566. the new contents.
  567. The method of making a backup file may also affect the file's owner
  568. and group. If copying is used, these do not change. If renaming is used,
  569. you become the file's owner, and the file's group becomes the default
  570. (different operating systems have different defaults for the group).
  571. @vindex backup-by-copying
  572. @vindex backup-by-copying-when-linked
  573. @vindex backup-by-copying-when-mismatch
  574. @vindex backup-by-copying-when-privileged-mismatch
  575. @cindex file ownership, and backup
  576. @cindex backup, and user-id
  577. The choice of renaming or copying is made as follows:
  578. @itemize
  579. @item
  580. If the variable @code{backup-by-copying} is non-@code{nil} (the
  581. default is @code{nil}), use copying.
  582. @item
  583. Otherwise, if the variable @code{backup-by-copying-when-linked} is
  584. non-@code{nil} (the default is @code{nil}), and the file has multiple
  585. names, use copying.
  586. @item
  587. Otherwise, if the variable @code{backup-by-copying-when-mismatch} is
  588. non-@code{nil} (the default is @code{t}), and renaming would change
  589. the file's owner or group, use copying.
  590. If you change @code{backup-by-copying-when-mismatch} to @code{nil},
  591. Emacs checks the numeric user-id of the file's owner. If this is
  592. higher than @code{backup-by-copying-when-privileged-mismatch}, then it
  593. behaves as though @code{backup-by-copying-when-mismatch} is
  594. non-@code{nil} anyway.
  595. @item
  596. Otherwise, renaming is the default choice.
  597. @end itemize
  598. When a file is managed with a version control system (@pxref{Version
  599. Control}), Emacs does not normally make backups in the usual way for
  600. that file. But check-in and check-out are similar in some ways to
  601. making backups. One unfortunate similarity is that these operations
  602. typically break hard links, disconnecting the file name you visited from
  603. any alternate names for the same file. This has nothing to do with
  604. Emacs---the version control system does it.
  605. @node Customize Save
  606. @subsection Customizing Saving of Files
  607. @vindex require-final-newline
  608. If the value of the variable @code{require-final-newline} is
  609. @code{t}, saving or writing a file silently puts a newline at the end
  610. if there isn't already one there. If the value is @code{visit}, Emacs
  611. adds a newline at the end of any file that doesn't have one, just
  612. after it visits the file. (This marks the buffer as modified, and you
  613. can undo it.) If the value is @code{visit-save}, Emacs adds such
  614. newlines both on visiting and on saving. If the value is @code{nil},
  615. Emacs leaves the end of the file unchanged; any other non-@code{nil}
  616. value means Emacs asks you whether to add a newline. The default is
  617. @code{nil}.
  618. @vindex mode-require-final-newline
  619. Some major modes are designed for specific kinds of files that are
  620. always supposed to end in newlines. Such major modes set the variable
  621. @code{require-final-newline} to the value of
  622. @code{mode-require-final-newline}, which defaults to @code{t}. By
  623. setting the latter variable, you can control how these modes handle
  624. final newlines.
  625. @vindex write-region-inhibit-fsync
  626. Normally, when a program writes a file, the operating system briefly
  627. caches the file's data in main memory before committing the data to
  628. disk. This can greatly improve performance; for example, when running
  629. on laptops, it can avoid a disk spin-up each time a file is written.
  630. However, it risks data loss if the operating system crashes before
  631. committing the cache to disk.
  632. To lessen this risk, Emacs can invoke the @code{fsync} system call
  633. after saving a file. Using @code{fsync} does not eliminate the risk
  634. of data loss, partly because many systems do not implement
  635. @code{fsync} properly, and partly because Emacs's file-saving
  636. procedure typically relies also on directory updates that might not
  637. survive a crash even if @code{fsync} works properly.
  638. The @code{write-region-inhibit-fsync} variable controls whether
  639. Emacs invokes @code{fsync} after saving a file. The variable's
  640. default value is @code{nil} when Emacs is interactive, and @code{t}
  641. when Emacs runs in batch mode.
  642. Emacs never uses @code{fsync} when writing auto-save files, as these
  643. files might lose data anyway.
  644. @node Interlocking
  645. @subsection Protection against Simultaneous Editing
  646. @cindex file dates
  647. @cindex simultaneous editing
  648. Simultaneous editing occurs when two users visit the same file, both
  649. make changes, and then both save them. If nobody is informed that
  650. this is happening, whichever user saves first would later find that
  651. his changes were lost.
  652. On some systems, Emacs notices immediately when the second user starts
  653. to change the file, and issues an immediate warning. On all systems,
  654. Emacs checks when you save the file, and warns if you are about to
  655. overwrite another user's changes. You can prevent loss of the other
  656. user's work by taking the proper corrective action instead of saving the
  657. file.
  658. @findex ask-user-about-lock
  659. @cindex locking files
  660. When you make the first modification in an Emacs buffer that is
  661. visiting a file, Emacs records that the file is @dfn{locked} by you.
  662. (It does this by creating a specially-named symbolic link@footnote{If
  663. your file system does not support symbolic links, a regular file is
  664. used.} with special contents in the same directory.) Emacs removes the lock
  665. when you save the changes. The idea is that the file is locked
  666. whenever an Emacs buffer visiting it has unsaved changes.
  667. @vindex create-lockfiles
  668. You can prevent the creation of lock files by setting the variable
  669. @code{create-lockfiles} to @code{nil}. @strong{Caution:} by
  670. doing so you will lose the benefits that this feature provides.
  671. @cindex collision
  672. If you begin to modify the buffer while the visited file is locked by
  673. someone else, this constitutes a @dfn{collision}. When Emacs detects a
  674. collision, it asks you what to do, by calling the Lisp function
  675. @code{ask-user-about-lock}. You can redefine this function for the sake
  676. of customization. The standard definition of this function asks you a
  677. question and accepts three possible answers:
  678. @table @kbd
  679. @item s
  680. Steal the lock. Whoever was already changing the file loses the lock,
  681. and you gain the lock.
  682. @item p
  683. Proceed. Go ahead and edit the file despite its being locked by someone else.
  684. @item q
  685. Quit. This causes an error (@code{file-locked}), and the buffer
  686. contents remain unchanged---the modification you were trying to make
  687. does not actually take place.
  688. @end table
  689. If Emacs or the operating system crashes, this may leave behind lock
  690. files which are stale, so you may occasionally get warnings about
  691. spurious collisions. When you determine that the collision is
  692. spurious, just use @kbd{p} to tell Emacs to go ahead anyway.
  693. Note that locking works on the basis of a file name; if a file has
  694. multiple names, Emacs does not prevent two users from editing it
  695. simultaneously under different names.
  696. A lock file cannot be written in some circumstances, e.g., if Emacs
  697. lacks the system permissions or cannot create lock files for some
  698. other reason. In these cases, Emacs can still detect the collision
  699. when you try to save a file, by checking the file's last-modification
  700. date. If the file has changed since the last time Emacs visited or
  701. saved it, that implies that changes have been made in some other way,
  702. and will be lost if Emacs proceeds with saving. Emacs then displays a
  703. warning message and asks for confirmation before saving; answer
  704. @kbd{yes} to save, and @kbd{no} or @kbd{C-g} cancel the save.
  705. If you are notified that simultaneous editing has already taken
  706. place, one way to compare the buffer to its file is the @kbd{M-x
  707. diff-buffer-with-file} command. @xref{Comparing Files}.
  708. @node File Shadowing
  709. @subsection Shadowing Files
  710. @cindex shadow files
  711. @cindex file shadows
  712. @findex shadow-initialize
  713. @table @kbd
  714. @item M-x shadow-initialize
  715. Set up file shadowing.
  716. @item M-x shadow-define-literal-group
  717. Declare a single file to be shared between sites.
  718. @item M-x shadow-define-regexp-group
  719. Make all files that match each of a group of files be shared between hosts.
  720. @item M-x shadow-define-cluster @key{RET} @var{name} @key{RET}
  721. Define a shadow file cluster @var{name}.
  722. @item M-x shadow-copy-files
  723. Copy all pending shadow files.
  724. @item M-x shadow-cancel
  725. Cancel the instruction to shadow some files.
  726. @end table
  727. You can arrange to keep identical @dfn{shadow} copies of certain files
  728. in more than one place---possibly on different machines. To do this,
  729. first you must set up a @dfn{shadow file group}, which is a set of
  730. identically-named files shared between a list of sites. The file
  731. group is permanent and applies to further Emacs sessions as well as
  732. the current one. Once the group is set up, every time you exit Emacs,
  733. it will copy the file you edited to the other files in its group. You
  734. can also do the copying without exiting Emacs, by typing @kbd{M-x
  735. shadow-copy-files}.
  736. To set up a shadow file group, use @kbd{M-x
  737. shadow-define-literal-group} or @kbd{M-x shadow-define-regexp-group}.
  738. See their documentation strings for further information.
  739. Before copying a file to its shadows, Emacs asks for confirmation.
  740. You can answer ``no'' to bypass copying of this file, this time. If
  741. you want to cancel the shadowing permanently for a certain file, use
  742. @kbd{M-x shadow-cancel} to eliminate or change the shadow file group.
  743. A @dfn{shadow cluster} is a group of hosts that share directories, so
  744. that copying to or from one of them is sufficient to update the file
  745. on all of them. Each shadow cluster has a name, and specifies the
  746. network address of a primary host (the one we copy files to), and a
  747. regular expression that matches the host names of all the other hosts
  748. in the cluster. You can define a shadow cluster with @kbd{M-x
  749. shadow-define-cluster}.
  750. @node Time Stamps
  751. @subsection Updating Time Stamps Automatically
  752. @cindex time stamps
  753. @cindex modification dates
  754. @cindex locale, date format
  755. You can arrange to put a time stamp in a file, so that it is updated
  756. automatically each time you edit and save the file. The time stamp
  757. must be in the first eight lines of the file, and you should insert it
  758. like this:
  759. @example
  760. Time-stamp: <>
  761. @end example
  762. @noindent
  763. or like this:
  764. @example
  765. Time-stamp: " "
  766. @end example
  767. @findex time-stamp
  768. Then add the function @code{time-stamp} to the hook
  769. @code{before-save-hook} (@pxref{Hooks}). When you save the file, this
  770. function then automatically updates the time stamp with the current
  771. date and time. You can also use the command @kbd{M-x time-stamp} to
  772. update the time stamp manually. By default the time stamp is
  773. formatted according to your locale setting (@pxref{Environment}) and
  774. time zone (@pxref{Time of Day,,, elisp, The Emacs Lisp Reference
  775. Manual}). For customizations, see the Custom group @code{time-stamp}.
  776. @node Reverting
  777. @section Reverting a Buffer
  778. @findex revert-buffer
  779. @cindex drastic changes
  780. @cindex reread a file
  781. If you have made extensive changes to a file-visiting buffer and
  782. then change your mind, you can @dfn{revert} the changes and go back to
  783. the saved version of the file. To do this, type @kbd{M-x
  784. revert-buffer}. Since reverting unintentionally could lose a lot of
  785. work, Emacs asks for confirmation first.
  786. The @code{revert-buffer} command tries to position point in such a
  787. way that, if the file was edited only slightly, you will be at
  788. approximately the same part of the text as before. But if you have
  789. made major changes, point may end up in a totally different location.
  790. Reverting marks the buffer as not modified. It also clears the
  791. buffer's undo history (@pxref{Undo}). Thus, the reversion cannot be
  792. undone---if you change your mind yet again, you can't use the undo
  793. commands to bring the reverted changes back.
  794. Some kinds of buffers that are not associated with files, such as
  795. Dired buffers, can also be reverted. For them, reverting means
  796. recalculating their contents. Buffers created explicitly with
  797. @kbd{C-x b} cannot be reverted; @code{revert-buffer} reports an error
  798. if you try.
  799. @vindex revert-without-query
  800. When you edit a file that changes automatically and frequently---for
  801. example, a log of output from a process that continues to run---it may
  802. be useful for Emacs to revert the file without querying you. To
  803. request this behavior, set the variable @code{revert-without-query} to
  804. a list of regular expressions. When a file name matches one of these
  805. regular expressions, @code{find-file} and @code{revert-buffer} will
  806. revert it automatically if it has changed---provided the buffer itself
  807. is not modified. (If you have edited the text, it would be wrong to
  808. discard your changes.)
  809. @cindex Global Auto-Revert mode
  810. @cindex mode, Global Auto-Revert
  811. @cindex Auto-Revert mode
  812. @cindex mode, Auto-Revert
  813. @findex global-auto-revert-mode
  814. @findex auto-revert-mode
  815. @findex auto-revert-tail-mode
  816. @vindex auto-revert-interval
  817. @vindex auto-revert-remote-files
  818. @vindex auto-revert-verbose
  819. You can also tell Emacs to revert buffers periodically. To do this
  820. for a specific buffer, enable the minor mode Auto-Revert mode by
  821. typing @kbd{M-x auto-revert-mode}. This automatically reverts the
  822. current buffer every five seconds; you can change the interval through
  823. the variable @code{auto-revert-interval}. To do the same for all file
  824. buffers, type @kbd{M-x global-auto-revert-mode} to enable Global
  825. Auto-Revert mode. These minor modes do not check or revert remote
  826. files, because that is usually too slow. This behavior can be changed
  827. by setting the variable @code{auto-revert-remote-files} to non-@code{nil}.
  828. One use of Auto-Revert mode is to ``tail'' a file such as a system
  829. log, so that changes made to that file by other programs are
  830. continuously displayed. To do this, just move the point to the end of
  831. the buffer, and it will stay there as the file contents change.
  832. However, if you are sure that the file will only change by growing at
  833. the end, use Auto-Revert Tail mode instead
  834. (@code{auto-revert-tail-mode}). It is more efficient for this.
  835. Auto-Revert Tail mode works also for remote files.
  836. When a buffer is auto-reverted, a message is generated. This can be
  837. suppressed by setting @code{auto-revert-verbose} to @code{nil}.
  838. @xref{VC Undo}, for commands to revert to earlier versions of files
  839. under version control. @xref{VC Mode Line}, for Auto Revert
  840. peculiarities when visiting files under version control.
  841. @ifnottex
  842. @include arevert-xtra.texi
  843. @end ifnottex
  844. @node Auto Save
  845. @section Auto-Saving: Protection Against Disasters
  846. @cindex Auto Save mode
  847. @cindex mode, Auto Save
  848. @cindex crashes
  849. From time to time, Emacs automatically saves each visited file in a
  850. separate file, without altering the file you actually use. This is
  851. called @dfn{auto-saving}. It prevents you from losing more than a
  852. limited amount of work if the system crashes.
  853. When Emacs determines that it is time for auto-saving, it considers
  854. each buffer, and each is auto-saved if auto-saving is enabled for it
  855. and it has been changed since the last time it was auto-saved. The
  856. message @samp{Auto-saving...} is displayed in the echo area during
  857. auto-saving, if any files are actually auto-saved. Errors occurring
  858. during auto-saving are caught so that they do not interfere with the
  859. execution of commands you have been typing.
  860. @menu
  861. * Files: Auto Save Files. The file where auto-saved changes are
  862. actually made until you save the file.
  863. * Control: Auto Save Control. Controlling when and how often to auto-save.
  864. * Recover:: Recovering text from auto-save files.
  865. @end menu
  866. @node Auto Save Files
  867. @subsection Auto-Save Files
  868. Auto-saving does not normally save in the files that you visited,
  869. because it can be very undesirable to save a change that you did not
  870. want to make permanent. Instead, auto-saving is done in a different
  871. file called the @dfn{auto-save file}, and the visited file is changed
  872. only when you request saving explicitly (such as with @kbd{C-x C-s}).
  873. Normally, the auto-save file name is made by appending @samp{#} to the
  874. front and rear of the visited file name. Thus, a buffer visiting file
  875. @file{foo.c} is auto-saved in a file @file{#foo.c#}. Most buffers that
  876. are not visiting files are auto-saved only if you request it explicitly;
  877. when they are auto-saved, the auto-save file name is made by appending
  878. @samp{#} to the front and rear of buffer name, then
  879. adding digits and letters at the end for uniqueness. For
  880. example, the @file{*mail*} buffer in which you compose messages to be
  881. sent might be auto-saved in a file named @file{#*mail*#704juu}. Auto-save file
  882. names are made this way unless you reprogram parts of Emacs to do
  883. something different (the functions @code{make-auto-save-file-name} and
  884. @code{auto-save-file-name-p}). The file name to be used for auto-saving
  885. in a buffer is calculated when auto-saving is turned on in that buffer.
  886. @cindex auto-save for remote files
  887. @vindex auto-save-file-name-transforms
  888. The variable @code{auto-save-file-name-transforms} allows a degree
  889. of control over the auto-save file name. It lets you specify a series
  890. of regular expressions and replacements to transform the auto save
  891. file name. The default value puts the auto-save files for remote
  892. files (@pxref{Remote Files}) into the temporary file directory on the
  893. local machine.
  894. When you delete a substantial part of the text in a large buffer, auto
  895. save turns off temporarily in that buffer. This is because if you
  896. deleted the text unintentionally, you might find the auto-save file more
  897. useful if it contains the deleted text. To reenable auto-saving after
  898. this happens, save the buffer with @kbd{C-x C-s}, or use @kbd{C-u 1 M-x
  899. auto-save-mode}.
  900. @vindex auto-save-visited-mode
  901. If you want auto-saving to be done in the visited file rather than
  902. in a separate auto-save file, enable the global minor mode
  903. @code{auto-save-visited-mode}. In this mode, auto-saving is identical
  904. to explicit saving. Note that this mode is orthogonal to the
  905. @code{auto-save} mode described above; you can enable both at the same
  906. time. However, if @code{auto-save} mode is active in some buffer and
  907. the obsolete @code{auto-save-visited-file-name} variable is set to a
  908. non-@code{nil} value, that buffer won't be affected by
  909. @code{auto-save-visited-mode}.
  910. You can use the variable @code{auto-save-visited-interval} to
  911. customize the interval between auto-save operations in
  912. @code{auto-save-visited-mode}; by default it's five seconds.
  913. @code{auto-save-interval} and @code{auto-save-timeout} have no effect
  914. on @code{auto-save-visited-mode}. @xref{Auto Save Control}, for
  915. details on these variables.
  916. @vindex delete-auto-save-files
  917. A buffer's auto-save file is deleted when you save the buffer in its
  918. visited file. (You can inhibit this by setting the variable
  919. @code{delete-auto-save-files} to @code{nil}.) Changing the visited
  920. file name with @kbd{C-x C-w} or @code{set-visited-file-name} renames
  921. any auto-save file to go with the new visited name.
  922. @node Auto Save Control
  923. @subsection Controlling Auto-Saving
  924. @vindex auto-save-default
  925. @findex auto-save-mode
  926. Each time you visit a file, auto-saving is turned on for that file's
  927. buffer if the variable @code{auto-save-default} is non-@code{nil} (but
  928. not in batch mode; @pxref{Initial Options}). The default for this
  929. variable is @code{t}, so auto-saving is the usual practice for
  930. file-visiting buffers. To toggle auto-saving in the current buffer,
  931. type @kbd{M-x auto-save-mode}. Auto Save mode acts as a buffer-local
  932. minor mode (@pxref{Minor Modes}).
  933. @vindex auto-save-interval
  934. Emacs auto-saves periodically based on how many characters you have
  935. typed since the last auto-save. The variable
  936. @code{auto-save-interval} specifies how many characters there are
  937. between auto-saves. By default, it is 300. Emacs doesn't accept
  938. values that are too small: if you customize @code{auto-save-interval}
  939. to a value less than 20, Emacs will behave as if the value is 20.
  940. @vindex auto-save-timeout
  941. Auto-saving also takes place when you stop typing for a while. By
  942. default, it does this after 30 seconds of idleness (at this time,
  943. Emacs may also perform garbage collection; @pxref{Garbage
  944. Collection,,, elisp, The Emacs Lisp Reference Manual}). To change
  945. this interval, customize the variable @code{auto-save-timeout}. The
  946. actual time period is longer if the current buffer is long; this is a
  947. heuristic which aims to keep out of your way when you are editing long
  948. buffers, in which auto-save takes an appreciable amount of time.
  949. Auto-saving during idle periods accomplishes two things: first, it
  950. makes sure all your work is saved if you go away from the terminal for
  951. a while; second, it may avoid some auto-saving while you are actually
  952. typing.
  953. @vindex auto-save-visited-interval
  954. When @code{auto-save-visited-mode} is enabled, Emacs will auto-save
  955. file-visiting buffers after five seconds of idle time. You can
  956. customize the variable @code{auto-save-visited-interval} to change the
  957. idle time interval.
  958. Emacs also does auto-saving whenever it gets a fatal error. This
  959. includes killing the Emacs job with a shell command such as @samp{kill
  960. %emacs}, or disconnecting a phone line or network connection.
  961. @findex do-auto-save
  962. You can perform an auto-save explicitly with the command @kbd{M-x
  963. do-auto-save}.
  964. @node Recover
  965. @subsection Recovering Data from Auto-Saves
  966. @findex recover-file
  967. You can use the contents of an auto-save file to recover from a loss
  968. of data with the command @kbd{M-x recover-file @key{RET} @var{file}
  969. @key{RET}}. This visits @var{file} and then (after your confirmation)
  970. restores the contents from its auto-save file @file{#@var{file}#}.
  971. You can then save with @kbd{C-x C-s} to put the recovered text into
  972. @var{file} itself. For example, to recover file @file{foo.c} from its
  973. auto-save file @file{#foo.c#}, do:
  974. @example
  975. M-x recover-file @key{RET} foo.c @key{RET}
  976. yes @key{RET}
  977. C-x C-s
  978. @end example
  979. Before asking for confirmation, @kbd{M-x recover-file} displays a
  980. directory listing describing the specified file and the auto-save file,
  981. so you can compare their sizes and dates. If the auto-save file
  982. is older, @kbd{M-x recover-file} does not offer to read it.
  983. @findex recover-session
  984. If Emacs or the computer crashes, you can recover all the files you
  985. were editing from their auto save files with the command @kbd{M-x
  986. recover-session}. This first shows you a list of recorded interrupted
  987. sessions. Move point to the one you choose, and type @kbd{C-c C-c}.
  988. Then @code{recover-session} asks about each of the files that were
  989. being edited during that session, asking whether to recover that file.
  990. If you answer @kbd{y}, it calls @code{recover-file}, which works in its
  991. normal fashion. It shows the dates of the original file and its
  992. auto-save file, and asks once again whether to recover that file.
  993. When @code{recover-session} is done, the files you've chosen to
  994. recover are present in Emacs buffers. You should then save them. Only
  995. this---saving them---updates the files themselves.
  996. @vindex auto-save-list-file-prefix
  997. Emacs records information about interrupted sessions in files named
  998. @file{.saves-@var{pid}-@var{hostname}} in the directory
  999. @file{~/.emacs.d/auto-save-list/}. This directory is determined by
  1000. the variable @code{auto-save-list-file-prefix}. If you set
  1001. @code{auto-save-list-file-prefix} to @code{nil}, sessions are not
  1002. recorded for recovery.
  1003. @node File Aliases
  1004. @section File Name Aliases
  1005. @cindex symbolic links (visiting)
  1006. @cindex hard links (visiting)
  1007. Symbolic links and hard links both make it possible for several file
  1008. names to refer to the same file. Hard links are alternate names that
  1009. refer directly to the file; all the names are equally valid, and no one
  1010. of them is preferred. By contrast, a symbolic link is a kind of defined
  1011. alias: when @file{foo} is a symbolic link to @file{bar}, you can use
  1012. either name to refer to the file, but @file{bar} is the real name, while
  1013. @file{foo} is just an alias. More complex cases occur when symbolic
  1014. links point to directories.
  1015. @vindex find-file-existing-other-name
  1016. @vindex find-file-suppress-same-file-warnings
  1017. Normally, if you visit a file which Emacs is already visiting under
  1018. a different name, Emacs displays a message in the echo area and uses
  1019. the existing buffer visiting that file. This can happen on systems
  1020. that support hard or symbolic links, or if you use a long file name on
  1021. a system that truncates long file names, or on a case-insensitive file
  1022. system. You can suppress the message by setting the variable
  1023. @code{find-file-suppress-same-file-warnings} to a non-@code{nil}
  1024. value. You can disable this feature entirely by setting the variable
  1025. @code{find-file-existing-other-name} to @code{nil}: then if you visit
  1026. the same file under two different names, you get a separate buffer for
  1027. each file name.
  1028. @vindex find-file-visit-truename
  1029. @cindex truenames of files
  1030. @cindex file truenames
  1031. If the variable @code{find-file-visit-truename} is non-@code{nil},
  1032. then the file name recorded for a buffer is the file's @dfn{truename}
  1033. (made by replacing all symbolic links with their target names), rather
  1034. than the name you specify. Setting @code{find-file-visit-truename} also
  1035. implies the effect of @code{find-file-existing-other-name}.
  1036. @cindex directory name abbreviation
  1037. @vindex directory-abbrev-alist
  1038. Sometimes, a directory is ordinarily accessed through a symbolic
  1039. link, and you may want Emacs to preferentially show its linked
  1040. name. To do this, customize @code{directory-abbrev-alist}. Each
  1041. element in this list should have the form @code{(@var{from}
  1042. . @var{to})}, which means to replace @var{from} with @var{to} whenever
  1043. @var{from} appears in a directory name. The @var{from} string is a
  1044. regular expression (@pxref{Regexps}). It is matched against directory
  1045. names anchored at the first character, and should start with @samp{\`}
  1046. (to support directory names with embedded newlines, which would defeat
  1047. @samp{^}). The @var{to} string should be an ordinary absolute
  1048. directory name pointing to the same directory. Do not use @samp{~} to
  1049. stand for a home directory in the @var{to} string; Emacs performs
  1050. these substitutions separately. Here's an example, from a system on
  1051. which @file{/home/fsf} is normally accessed through a symbolic link
  1052. named @file{/fsf}:
  1053. @example
  1054. (("\\`/home/fsf" . "/fsf"))
  1055. @end example
  1056. @node Directories
  1057. @section File Directories
  1058. @cindex file directory
  1059. @cindex directory listing
  1060. The file system groups files into @dfn{directories}. A @dfn{directory
  1061. listing} is a list of all the files in a directory. Emacs provides
  1062. commands to create and delete directories, and to make directory
  1063. listings in brief format (file names only) and verbose format (sizes,
  1064. dates, and authors included). Emacs also includes a directory browser
  1065. feature called Dired; see @ref{Dired}.
  1066. @table @kbd
  1067. @item C-x C-d @var{dir-or-pattern} @key{RET}
  1068. Display a brief directory listing (@code{list-directory}).
  1069. @item C-u C-x C-d @var{dir-or-pattern} @key{RET}
  1070. Display a verbose directory listing.
  1071. @item M-x make-directory @key{RET} @var{dirname} @key{RET}
  1072. Create a new directory named @var{dirname}.
  1073. @item M-x delete-directory @key{RET} @var{dirname} @key{RET}
  1074. Delete the directory named @var{dirname}. If it isn't empty,
  1075. you will be asked whether you want to delete it recursively.
  1076. @end table
  1077. @findex list-directory
  1078. @kindex C-x C-d
  1079. The command to display a directory listing is @kbd{C-x C-d}
  1080. (@code{list-directory}). It reads using the minibuffer a file name
  1081. which is either a directory to be listed or a wildcard-containing
  1082. pattern for the files to be listed. For example,
  1083. @example
  1084. C-x C-d /u2/emacs/etc @key{RET}
  1085. @end example
  1086. @noindent
  1087. lists all the files in directory @file{/u2/emacs/etc}. Here is an
  1088. example of specifying a file name pattern:
  1089. @example
  1090. C-x C-d /u2/emacs/src/*.c @key{RET}
  1091. @end example
  1092. Normally, @kbd{C-x C-d} displays a brief directory listing containing
  1093. just file names. A numeric argument (regardless of value) tells it to
  1094. make a verbose listing including sizes, dates, and owners (like
  1095. @samp{ls -l}).
  1096. @vindex list-directory-brief-switches
  1097. @vindex list-directory-verbose-switches
  1098. The text of a directory listing is mostly obtained by running
  1099. @code{ls} in an inferior process. Two Emacs variables control the
  1100. switches passed to @code{ls}: @code{list-directory-brief-switches} is
  1101. a string giving the switches to use in brief listings (@code{"-CF"} by
  1102. default), and @code{list-directory-verbose-switches} is a string
  1103. giving the switches to use in a verbose listing (@code{"-l"} by
  1104. default).
  1105. @vindex directory-free-space-program
  1106. @vindex directory-free-space-args
  1107. In verbose directory listings, Emacs adds information about the
  1108. amount of free space on the disk that contains the directory. To do
  1109. this, it runs the program specified by
  1110. @code{directory-free-space-program} with arguments
  1111. @code{directory-free-space-args}.
  1112. The command @kbd{M-x delete-directory} prompts for a directory name
  1113. using the minibuffer, and deletes the directory if it is empty. If
  1114. the directory is not empty, you will be asked whether you want to
  1115. delete it recursively. On systems that have a ``Trash'' (or ``Recycle
  1116. Bin'') feature, you can make this command move the specified directory
  1117. to the Trash instead of deleting it outright, by changing the variable
  1118. @code{delete-by-moving-to-trash} to @code{t}. @xref{Misc File Ops},
  1119. for more information about using the Trash.
  1120. @node Comparing Files
  1121. @section Comparing Files
  1122. @cindex comparing files
  1123. @findex diff
  1124. @vindex diff-switches
  1125. The command @kbd{M-x diff} prompts for two file names, using the
  1126. minibuffer, and displays the differences between the two files in a
  1127. buffer named @file{*diff*}. This works by running the @command{diff}
  1128. program, using options taken from the variable @code{diff-switches}.
  1129. The value of @code{diff-switches} should be a string; the default is
  1130. @code{"-u"} to specify a unified context diff.
  1131. @c Note that the actual name of the info file is diffutils.info,
  1132. @c but it adds a dir entry for diff too.
  1133. @c On older systems, only "info diff" works, not "info diffutils".
  1134. @xref{Top,, Diff, diffutils, Comparing and Merging Files}, for more
  1135. information about the @command{diff} program.
  1136. The output of the @code{diff} command is shown using a major mode
  1137. called Diff mode. @xref{Diff Mode}.
  1138. @findex diff-backup
  1139. The command @kbd{M-x diff-backup} compares a specified file with its
  1140. most recent backup. If you specify the name of a backup file,
  1141. @code{diff-backup} compares it with the source file that it is a
  1142. backup of. In all other respects, this behaves like @kbd{M-x diff}.
  1143. @findex diff-buffer-with-file
  1144. The command @kbd{M-x diff-buffer-with-file} compares a specified
  1145. buffer with its corresponding file. This shows you what changes you
  1146. would make to the file if you save the buffer.
  1147. @findex compare-windows
  1148. The command @kbd{M-x compare-windows} compares the text in the
  1149. current window with that in the window that was the selected window
  1150. before you selected the current one. (For more information about
  1151. windows in Emacs, @ref{Windows}.) Comparison starts at point in each
  1152. window, after pushing each initial point value on the mark ring in its
  1153. respective buffer. Then it moves point forward in each window, one
  1154. character at a time, until it reaches characters that don't match.
  1155. Then the command exits.
  1156. If point in the two windows is followed by non-matching text when
  1157. the command starts, @kbd{M-x compare-windows} tries heuristically to
  1158. advance up to matching text in the two windows, and then exits. So if
  1159. you use @kbd{M-x compare-windows} repeatedly, each time it either
  1160. skips one matching range or finds the start of another.
  1161. @vindex compare-ignore-case
  1162. @vindex compare-ignore-whitespace
  1163. With a numeric argument, @code{compare-windows} ignores changes in
  1164. whitespace. If the variable @code{compare-ignore-case} is
  1165. non-@code{nil}, the comparison ignores differences in case as well.
  1166. If the variable @code{compare-ignore-whitespace} is non-@code{nil},
  1167. @code{compare-windows} normally ignores changes in whitespace, and a
  1168. prefix argument turns that off.
  1169. @cindex Smerge mode
  1170. @findex smerge-mode
  1171. @cindex failed merges
  1172. @cindex merges, failed
  1173. @cindex comparing 3 files (@code{diff3})
  1174. You can use @kbd{M-x smerge-mode} to turn on Smerge mode, a minor
  1175. mode for editing output from the @command{diff3} program. This is
  1176. typically the result of a failed merge from a version control system
  1177. update outside VC, due to conflicting changes to a file. Smerge
  1178. mode provides commands to resolve conflicts by selecting specific
  1179. changes.
  1180. @iftex
  1181. @xref{Emerge,,, emacs-xtra, Specialized Emacs Features},
  1182. @end iftex
  1183. @ifnottex
  1184. @xref{Emerge},
  1185. @end ifnottex
  1186. for the Emerge facility, which provides a powerful interface for
  1187. merging files.
  1188. @node Diff Mode
  1189. @section Diff Mode
  1190. @cindex Diff mode
  1191. @findex diff-mode
  1192. @cindex patches, editing
  1193. Diff mode is a major mode used for the output of @kbd{M-x diff} and
  1194. other similar commands. This kind of output is called a @dfn{patch},
  1195. because it can be passed to the @command{patch} command to
  1196. automatically apply the specified changes. To select Diff mode
  1197. manually, type @kbd{M-x diff-mode}.
  1198. @cindex hunk, diff
  1199. The changes specified in a patch are grouped into @dfn{hunks}, which
  1200. are contiguous chunks of text that contain one or more changed lines.
  1201. Hunks can also include unchanged lines to provide context for the
  1202. changes. Each hunk is preceded by a @dfn{hunk header}, which
  1203. specifies the old and new line numbers at which the hunk occurs. Diff
  1204. mode highlights each hunk header, to distinguish it from the actual
  1205. contents of the hunk.
  1206. @vindex diff-update-on-the-fly
  1207. You can edit a Diff mode buffer like any other buffer. (If it is
  1208. read-only, you need to make it writable first. @xref{Misc Buffer}.)
  1209. Whenever you change a hunk, Diff mode attempts to automatically
  1210. correct the line numbers in the hunk headers, to ensure that the patch
  1211. remains correct. To disable automatic line number correction,
  1212. change the variable @code{diff-update-on-the-fly} to @code{nil}.
  1213. Diff mode treats each hunk as an error message, similar to
  1214. Compilation mode. Thus, you can use commands such as @kbd{C-x `} to
  1215. visit the corresponding source locations. @xref{Compilation Mode}.
  1216. In addition, Diff mode provides the following commands to navigate,
  1217. manipulate and apply parts of patches:
  1218. @table @kbd
  1219. @item M-n
  1220. @findex diff-hunk-next
  1221. Move to the next hunk-start (@code{diff-hunk-next}).
  1222. @findex diff-auto-refine-mode
  1223. @cindex mode, Diff Auto-Refine
  1224. @cindex Diff Auto-Refine mode
  1225. This command has a side effect: it @dfn{refines} the hunk you move to,
  1226. highlighting its changes with better granularity. To disable this
  1227. feature, type @kbd{M-x diff-auto-refine-mode} to toggle off the minor
  1228. mode Diff Auto-Refine mode. To disable Diff Auto Refine mode by
  1229. default, add this to your init file (@pxref{Hooks}):
  1230. @example
  1231. (add-hook 'diff-mode-hook
  1232. (lambda () (diff-auto-refine-mode -1)))
  1233. @end example
  1234. @item M-p
  1235. @findex diff-hunk-prev
  1236. Move to the previous hunk-start (@code{diff-hunk-prev}). Like
  1237. @kbd{M-n}, this has the side-effect of refining the hunk you move to,
  1238. unless you disable Diff Auto-Refine mode.
  1239. @item M-@}
  1240. @findex diff-file-next
  1241. Move to the next file-start, in a multi-file patch
  1242. (@code{diff-file-next}).
  1243. @item M-@{
  1244. @findex diff-file-prev
  1245. Move to the previous file-start, in a multi-file patch
  1246. (@code{diff-file-prev}).
  1247. @item M-k
  1248. @findex diff-hunk-kill
  1249. Kill the hunk at point (@code{diff-hunk-kill}).
  1250. @item M-K
  1251. @findex diff-file-kill
  1252. In a multi-file patch, kill the current file part.
  1253. (@code{diff-file-kill}).
  1254. @item C-c C-a
  1255. @findex diff-apply-hunk
  1256. @cindex patches, applying
  1257. Apply this hunk to its target file (@code{diff-apply-hunk}). With a
  1258. prefix argument of @kbd{C-u}, revert this hunk.
  1259. @item C-c C-b
  1260. @findex diff-refine-hunk
  1261. Highlight the changes of the hunk at point with a finer granularity
  1262. (@code{diff-refine-hunk}). This allows you to see exactly which parts
  1263. of each changed line were actually changed.
  1264. @item C-c C-c
  1265. @findex diff-goto-source
  1266. Go to the source file and line corresponding to this hunk
  1267. (@code{diff-goto-source}).
  1268. @item C-c C-e
  1269. @findex diff-ediff-patch
  1270. Start an Ediff session with the patch (@code{diff-ediff-patch}).
  1271. @xref{Top, Ediff, Ediff, ediff, The Ediff Manual}.
  1272. @item C-c C-n
  1273. @findex diff-restrict-view
  1274. Restrict the view to the current hunk (@code{diff-restrict-view}).
  1275. @xref{Narrowing}. With a prefix argument of @kbd{C-u}, restrict the
  1276. view to the current file of a multiple-file patch. To widen again,
  1277. use @kbd{C-x n w} (@code{widen}).
  1278. @item C-c C-r
  1279. @findex diff-reverse-direction
  1280. Reverse the direction of comparison for the entire buffer
  1281. (@code{diff-reverse-direction}).
  1282. @item C-c C-s
  1283. @findex diff-split-hunk
  1284. Split the hunk at point (@code{diff-split-hunk}). This is for
  1285. manually editing patches, and only works with the @dfn{unified diff
  1286. format} produced by the @option{-u} or @option{--unified} options to
  1287. the @command{diff} program. If you need to split a hunk in the
  1288. @dfn{context diff format} produced by the @option{-c} or
  1289. @option{--context} options to @command{diff}, first convert the buffer
  1290. to the unified diff format with @kbd{C-c C-u}.
  1291. @item C-c C-d
  1292. @findex diff-unified->context
  1293. Convert the entire buffer to the @dfn{context diff format}
  1294. (@code{diff-unified->context}). With a prefix argument, convert only
  1295. the text within the region.
  1296. @item C-c C-u
  1297. @findex diff-context->unified
  1298. Convert the entire buffer to unified diff format
  1299. (@code{diff-context->unified}). With a prefix argument, convert
  1300. unified format to context format. When the mark is active, convert
  1301. only the text within the region.
  1302. @item C-c C-w
  1303. @findex diff-ignore-whitespace-hunk
  1304. Re-diff the current hunk, disregarding changes in whitespace
  1305. (@code{diff-ignore-whitespace-hunk}).
  1306. @item C-x 4 A
  1307. @findex diff-add-change-log-entries-other-window
  1308. @findex add-change-log-entry-other-window@r{, in Diff mode}
  1309. Generate a ChangeLog entry, like @kbd{C-x 4 a} does (@pxref{Change
  1310. Log}), for each one of the hunks
  1311. (@code{diff-add-change-log-entries-other-window}). This creates a
  1312. skeleton of the log of changes that you can later fill with the actual
  1313. descriptions of the changes. @kbd{C-x 4 a} itself in Diff mode
  1314. operates on behalf of the current hunk's file, but gets the function
  1315. name from the patch itself. This is useful for making log entries for
  1316. functions that are deleted by the patch.
  1317. @end table
  1318. @c Trailing whitespace is NOT shown by default.
  1319. @c Emacs's dir-locals file enables this (for some reason).
  1320. @cindex trailing whitespace, in patches
  1321. @findex diff-delete-trailing-whitespace
  1322. Patches sometimes include trailing whitespace on modified lines, as
  1323. an unintentional and undesired change. There are two ways to deal
  1324. with this problem. Firstly, if you enable Whitespace mode in a Diff
  1325. buffer (@pxref{Useless Whitespace}), it automatically highlights
  1326. trailing whitespace in modified lines. Secondly, you can use the
  1327. command @kbd{M-x diff-delete-trailing-whitespace}, which searches for
  1328. trailing whitespace in the lines modified by the patch, and removes
  1329. that whitespace in both the patch and the patched source file(s).
  1330. This command does not save the modifications that it makes, so you can
  1331. decide whether to save the changes (the list of modified files is
  1332. displayed in the echo area). With a prefix argument, it tries to
  1333. modify the original source files rather than the patched source files.
  1334. @node Copying and Naming
  1335. @section Copying, Naming and Renaming Files
  1336. Emacs has several commands for copying, naming, and renaming files.
  1337. All of them read two file names @var{old} and @var{new} using the
  1338. minibuffer, and then copy or adjust a file's name accordingly; they do
  1339. not accept wildcard file names.
  1340. In all these commands, if the argument @var{new} is just a directory
  1341. name, the real new name is in that directory, with the same
  1342. non-directory component as @var{old}. For example, the command
  1343. @c FIXME: '/tmp' should be '/tmp/' because '/tmp'
  1344. @c is not "just a directory name".
  1345. @c And actually the fact that ``directory name'' must end in a slash
  1346. @c is not explained anywhere in this manual. Moreover, it many times
  1347. @c uses ``directory name'' in contexts where the string it alludes to
  1348. @c will clearly _not_ end in a slash
  1349. @w{@kbd{M-x rename-file @key{RET} ~/foo @key{RET} /tmp @key{RET}}}
  1350. renames @file{~/foo} to @file{/tmp/foo}. All these
  1351. commands ask for confirmation when the new file name already exists,
  1352. too.
  1353. @findex copy-file
  1354. @cindex copying files
  1355. @kbd{M-x copy-file} copies the contents of the file @var{old} to the
  1356. file @var{new}.
  1357. @findex copy-directory
  1358. @kbd{M-x copy-directory} copies directories, similar to the
  1359. @command{cp -r} shell command. If @var{new} is an existing directory,
  1360. it creates a copy of the @var{old} directory and puts it in @var{new}.
  1361. If @var{new} is not an existing directory, it copies all the contents
  1362. of @var{old} into a new directory named @var{new}.
  1363. @cindex renaming files
  1364. @findex rename-file
  1365. @kbd{M-x rename-file} renames file @var{old} as @var{new}. If the
  1366. file name @var{new} already exists, you must confirm with @kbd{yes} or
  1367. renaming is not done; this is because renaming causes the old meaning
  1368. of the name @var{new} to be lost. If @var{old} and @var{new} are on
  1369. different file systems, the file @var{old} is copied and deleted.
  1370. @ifnottex
  1371. If a file is under version control (@pxref{Version Control}), you
  1372. should rename it using @w{@kbd{M-x vc-rename-file}} instead of
  1373. @w{@kbd{M-x rename-file}}. @xref{VC Delete/Rename}.
  1374. @end ifnottex
  1375. @findex add-name-to-file
  1376. @cindex hard links (creation)
  1377. @kbd{M-x add-name-to-file} adds an additional name to an existing
  1378. file without removing the old name. The new name is created as a hard
  1379. link to the existing file. The new name must belong on the same file
  1380. system that the file is on. On MS-Windows, this command works only if
  1381. the file resides in an NTFS file system. On MS-DOS, and some remote
  1382. system types, it works by copying the file.
  1383. @findex make-symbolic-link
  1384. @cindex symbolic links (creation)
  1385. @kbd{M-x make-symbolic-link} creates a symbolic link named
  1386. @var{new}, which points at @var{target}. The effect is that future
  1387. attempts to open file @var{new} will refer to whatever file is named
  1388. @var{target} at the time the opening is done, or will get an error if
  1389. the name @var{target} is nonexistent at that time. This command does
  1390. not expand the argument @var{target}, so that it allows you to specify
  1391. a relative name as the target of the link. However, this command
  1392. does expand leading @samp{~} in @var{target} so that you can easily
  1393. specify home directories, and strips leading @samp{/:} so that you can
  1394. specify relative names beginning with literal @samp{~} or @samp{/:}.
  1395. @xref{Quoted File Names}. On MS-Windows, this command works only on
  1396. MS Windows Vista and later. When @var{new} is remote,
  1397. it works depending on the system type.
  1398. @node Misc File Ops
  1399. @section Miscellaneous File Operations
  1400. Emacs has commands for performing many other operations on files.
  1401. All operate on one file; they do not accept wildcard file names.
  1402. @findex delete-file
  1403. @cindex deletion (of files)
  1404. @kbd{M-x delete-file} prompts for a file and deletes it. If you are
  1405. deleting many files in one directory, it may be more convenient to use
  1406. Dired rather than @code{delete-file}. @xref{Dired Deletion}.
  1407. @cindex trash
  1408. @cindex recycle bin
  1409. @kbd{M-x move-file-to-trash} moves a file into the system
  1410. @dfn{Trash} (or @dfn{Recycle Bin}). This is a facility available on
  1411. most operating systems; files that are moved into the Trash can be
  1412. brought back later if you change your mind.
  1413. @vindex delete-by-moving-to-trash
  1414. By default, Emacs deletion commands do @emph{not} use the Trash. To
  1415. use the Trash (when it is available) for common deletion commands,
  1416. change the variable @code{delete-by-moving-to-trash} to @code{t}.
  1417. This affects the commands @kbd{M-x delete-file} and @kbd{M-x
  1418. delete-directory} (@pxref{Directories}), as well as the deletion
  1419. commands in Dired (@pxref{Dired Deletion}). Supplying a prefix
  1420. argument to @kbd{M-x delete-file} or @kbd{M-x delete-directory} makes
  1421. them delete outright, instead of using the Trash, regardless of
  1422. @code{delete-by-moving-to-trash}.
  1423. @ifnottex
  1424. If a file is under version control (@pxref{Version Control}), you
  1425. should delete it using @kbd{M-x vc-delete-file} instead of @kbd{M-x
  1426. delete-file}. @xref{VC Delete/Rename}.
  1427. @end ifnottex
  1428. @kindex C-x i
  1429. @findex insert-file
  1430. @kbd{M-x insert-file} (also @kbd{C-x i}) inserts a copy of the
  1431. contents of the specified file into the current buffer at point,
  1432. leaving point unchanged before the contents. The position after the
  1433. inserted contents is added to the mark ring, without activating the
  1434. mark (@pxref{Mark Ring}).
  1435. @findex insert-file-literally
  1436. @kbd{M-x insert-file-literally} is like @kbd{M-x insert-file},
  1437. except the file is inserted literally: it is treated as a sequence
  1438. of @acronym{ASCII} characters with no special encoding or conversion,
  1439. similar to the @kbd{M-x find-file-literally} command
  1440. (@pxref{Visiting}).
  1441. @findex write-region
  1442. @kbd{M-x write-region} is the inverse of @kbd{M-x insert-file}; it
  1443. copies the contents of the region into the specified file. @kbd{M-x
  1444. append-to-file} adds the text of the region to the end of the
  1445. specified file. @xref{Accumulating Text}. The variable
  1446. @code{write-region-inhibit-fsync} applies to these commands, as well
  1447. as saving files; see @ref{Customize Save}.
  1448. @findex set-file-modes
  1449. @cindex file modes
  1450. @cindex file permissions
  1451. @kbd{M-x set-file-modes} reads a file name followed by a @dfn{file
  1452. mode}, and applies that file mode to the specified file. File modes,
  1453. also called @dfn{file permissions}, determine whether a file can be
  1454. read, written to, or executed, and by whom. This command reads file
  1455. modes using the same symbolic or octal format accepted by the
  1456. @command{chmod} command; for instance, @samp{u+x} means to add
  1457. execution permission for the user who owns the file. It has no effect
  1458. on operating systems that do not support file modes. @code{chmod} is a
  1459. convenience alias for this function.
  1460. @node Compressed Files
  1461. @section Accessing Compressed Files
  1462. @cindex compression
  1463. @cindex uncompression
  1464. @cindex Auto Compression mode
  1465. @cindex mode, Auto Compression
  1466. @pindex gzip
  1467. Emacs automatically uncompresses compressed files when you visit
  1468. them, and automatically recompresses them if you alter them and save
  1469. them. Emacs recognizes compressed files by their file names. File
  1470. names ending in @samp{.gz} indicate a file compressed with
  1471. @code{gzip}. Other endings indicate other compression programs.
  1472. Automatic uncompression and compression apply to all the operations in
  1473. which Emacs uses the contents of a file. This includes visiting it,
  1474. saving it, inserting its contents into a buffer, loading it, and byte
  1475. compiling it.
  1476. @findex auto-compression-mode
  1477. @vindex auto-compression-mode
  1478. To disable this feature, type the command @kbd{M-x
  1479. auto-compression-mode}. You can disable it permanently by
  1480. customizing the variable @code{auto-compression-mode}.
  1481. @node File Archives
  1482. @section File Archives
  1483. @cindex mode, tar
  1484. @cindex Tar mode
  1485. @cindex file archives
  1486. A file whose name ends in @samp{.tar} is normally an @dfn{archive}
  1487. made by the @code{tar} program. Emacs views these files in a special
  1488. mode called Tar mode which provides a Dired-like list of the contents
  1489. (@pxref{Dired}). You can move around through the list just as you
  1490. would in Dired, and visit the subfiles contained in the archive.
  1491. However, not all Dired commands are available in Tar mode.
  1492. If Auto Compression mode is enabled (@pxref{Compressed Files}), then
  1493. Tar mode is used also for compressed archives---files with extensions
  1494. @samp{.tgz}, @code{.tar.Z} and @code{.tar.gz}.
  1495. The keys @kbd{e}, @kbd{f} and @key{RET} all extract a component file
  1496. into its own buffer. You can edit it there, and if you save the
  1497. buffer, the edited version will replace the version in the Tar buffer.
  1498. Clicking with the mouse on the file name in the Tar buffer does
  1499. likewise. @kbd{v} extracts a file into a buffer in View mode
  1500. (@pxref{View Mode}). @kbd{o} extracts the file and displays it in
  1501. another window, so you could edit the file and operate on the archive
  1502. simultaneously.
  1503. The @kbd{I} key adds a new (regular) file to the archive. The file
  1504. is initially empty, but can readily be edited using the commands
  1505. above. The command inserts the new file before the current one, so
  1506. that using it on the topmost line of the Tar buffer makes the new file
  1507. the first one in the archive, and using it at the end of the buffer
  1508. makes it the last one.
  1509. @kbd{d} marks a file for deletion when you later use @kbd{x}, and
  1510. @kbd{u} unmarks a file, as in Dired. @kbd{C} copies a file from the
  1511. archive to disk and @kbd{R} renames a file within the archive.
  1512. @kbd{g} reverts the buffer from the archive on disk. The keys
  1513. @kbd{M}, @kbd{G}, and @kbd{O} change the file's permission bits,
  1514. group, and owner, respectively.
  1515. Saving the Tar buffer writes a new version of the archive to disk with
  1516. the changes you made to the components.
  1517. You don't need the @code{tar} program to use Tar mode---Emacs reads
  1518. the archives directly. However, accessing compressed archives
  1519. requires the appropriate uncompression program.
  1520. @cindex Archive mode
  1521. @cindex mode, archive
  1522. @cindex @code{arc}
  1523. @cindex @code{jar}
  1524. @cindex @code{rar}
  1525. @cindex @code{zip}
  1526. @cindex @code{lzh}
  1527. @cindex @code{zoo}
  1528. @cindex @code{7z}
  1529. @pindex arc
  1530. @pindex jar
  1531. @pindex zip
  1532. @pindex rar
  1533. @pindex lzh
  1534. @pindex zoo
  1535. @pindex 7z
  1536. @cindex Java class archives
  1537. @cindex unzip archives
  1538. A separate but similar Archive mode is used for @code{arc},
  1539. @code{jar}, @code{lzh}, @code{zip}, @code{rar}, @code{7z}, and
  1540. @code{zoo} archives, as well as @code{exe} files that are
  1541. self-extracting executables.
  1542. The key bindings of Archive mode are similar to those in Tar mode,
  1543. with the addition of the @kbd{m} key which marks a file for subsequent
  1544. operations, and @kbd{M-@key{DEL}} which unmarks all the marked files.
  1545. Also, the @kbd{a} key toggles the display of detailed file
  1546. information, for those archive types where it won't fit in a single
  1547. line. Operations such as renaming a subfile, or changing its mode or
  1548. owner, are supported only for some of the archive formats.
  1549. Unlike Tar mode, Archive mode runs the archiving programs to unpack
  1550. and repack archives. However, you don't need these programs to look
  1551. at the archive table of contents, only to extract or manipulate the
  1552. subfiles in the archive. Details of the program names and their
  1553. options can be set in the @samp{Archive} Customize group
  1554. (@pxref{Customization Groups}).
  1555. @node Remote Files
  1556. @section Remote Files
  1557. @cindex Tramp
  1558. @cindex FTP
  1559. @cindex remote file access
  1560. You can refer to files on other machines using a special file name
  1561. syntax:
  1562. @example
  1563. @group
  1564. /@var{method}:@var{host}:@var{filename}
  1565. /@var{method}:@var{user}@@@var{host}:@var{filename}
  1566. /@var{method}:@var{user}@@@var{host}#@var{port}:@var{filename}
  1567. @end group
  1568. @end example
  1569. @noindent
  1570. To carry out this request, Emacs uses a remote-login program such as
  1571. @command{ftp}, @command{ssh}, @command{rlogin}, or @command{telnet}.
  1572. You must always specify in the file name which method to use---for
  1573. example, @file{/ftp:@var{user}@@@var{host}:@var{filename}} uses FTP,
  1574. whereas @file{/ssh:@var{user}@@@var{host}:@var{filename}} uses
  1575. @command{ssh}. When you specify the pseudo method @var{-} in the file
  1576. name, Emacs chooses the method as follows:
  1577. @enumerate
  1578. @item
  1579. If the host name starts with @samp{ftp.} (with dot), Emacs uses FTP.
  1580. @item
  1581. If the user name is @samp{ftp} or @samp{anonymous}, Emacs uses FTP.
  1582. @item
  1583. If the variable @code{tramp-default-method} is set to @samp{ftp},
  1584. Emacs uses FTP.
  1585. @item
  1586. If @command{ssh-agent} is running, Emacs uses @command{scp}.
  1587. @item
  1588. Otherwise, Emacs uses @command{ssh}.
  1589. @end enumerate
  1590. @cindex disabling remote files
  1591. @noindent
  1592. You can entirely turn off the remote file name feature by setting the
  1593. variable @code{tramp-mode} to @code{nil}. You can turn off the
  1594. feature in individual cases by quoting the file name with @samp{/:}
  1595. (@pxref{Quoted File Names}).
  1596. @cindex ange-ftp
  1597. Remote file access through FTP is handled by the Ange-FTP package, which
  1598. is documented in the following. Remote file access through the other
  1599. methods is handled by the Tramp package, which has its own manual.
  1600. @xref{Top, The Tramp Manual,, tramp, The Tramp Manual}.
  1601. @vindex ange-ftp-default-user
  1602. @cindex user name for remote file access
  1603. When the Ange-FTP package is used, Emacs logs in through FTP using
  1604. the name @var{user}, if that is specified in the remote file name. If
  1605. @var{user} is unspecified, Emacs logs in using your user name on the
  1606. local system; but if you set the variable @code{ange-ftp-default-user}
  1607. to a string, that string is used instead. When logging in, Emacs may
  1608. also ask for a password.
  1609. @cindex backups for remote files
  1610. @vindex ange-ftp-make-backup-files
  1611. For performance reasons, Emacs does not make backup files for files
  1612. accessed via FTP by default. To make it do so, change the variable
  1613. @code{ange-ftp-make-backup-files} to a non-@code{nil} value.
  1614. By default, auto-save files for remote files are made in the
  1615. temporary file directory on the local machine, as specified by the
  1616. variable @code{auto-save-file-name-transforms}. @xref{Auto Save
  1617. Files}.
  1618. @cindex anonymous FTP
  1619. @vindex ange-ftp-generate-anonymous-password
  1620. To visit files accessible by anonymous FTP, you use special user
  1621. names @samp{anonymous} or @samp{ftp}. Passwords for these user names
  1622. are handled specially. The variable
  1623. @code{ange-ftp-generate-anonymous-password} controls what happens: if
  1624. the value of this variable is a string, then that string is used as
  1625. the password; if non-@code{nil} (the default), then the value of
  1626. @code{user-mail-address} is used; if @code{nil}, then Emacs prompts
  1627. you for a password as usual (@pxref{Passwords}).
  1628. @cindex firewall, and accessing remote files
  1629. @cindex gateway, and remote file access with @code{ange-ftp}
  1630. @vindex ange-ftp-smart-gateway
  1631. @vindex ange-ftp-gateway-host
  1632. Sometimes you may be unable to access files on a remote machine
  1633. because a @dfn{firewall} in between blocks the connection for security
  1634. reasons. If you can log in on a @dfn{gateway} machine from which the
  1635. target files @emph{are} accessible, and whose FTP server supports
  1636. gatewaying features, you can still use remote file names; all you have
  1637. to do is specify the name of the gateway machine by setting the
  1638. variable @code{ange-ftp-gateway-host}, and set
  1639. @code{ange-ftp-smart-gateway} to @code{t}. Otherwise you may be able
  1640. to make remote file names work, but the procedure is complex. You can
  1641. read the instructions by typing @kbd{M-x finder-commentary @key{RET}
  1642. ange-ftp @key{RET}}.
  1643. @node Quoted File Names
  1644. @section Quoted File Names
  1645. @cindex quoting file names
  1646. @cindex file names, quote special characters
  1647. You can @dfn{quote} an absolute file name to prevent special
  1648. characters and syntax in it from having their special effects.
  1649. The way to do this is to add @samp{/:} at the beginning.
  1650. For example, you can quote a local file name which appears remote, to
  1651. prevent it from being treated as a remote file name. Thus, if you have
  1652. a directory named @file{/foo:} and a file named @file{bar} in it, you
  1653. can refer to that file in Emacs as @samp{/:/foo:/bar}.
  1654. If you want to quote only special characters in the local part of a
  1655. remote file name, you can quote just the local part.
  1656. @samp{/ssh:baz:/:/foo:/bar} refers to the file @file{bar} of directory
  1657. @file{/foo:} on the host @file{baz}.
  1658. @samp{/:} can also prevent @samp{~} from being treated as a special
  1659. character for a user's home directory. For example, @file{/:/tmp/~hack}
  1660. refers to a file whose name is @file{~hack} in directory @file{/tmp}.
  1661. Quoting with @samp{/:} is also a way to enter in the minibuffer a
  1662. file name that contains @samp{$}. In order for this to work, the
  1663. @samp{/:} must be at the beginning of the minibuffer contents. (You
  1664. can also double each @samp{$}; see @ref{File Names with $}.)
  1665. You can also quote wildcard characters with @samp{/:}, for visiting.
  1666. For example, @file{/:/tmp/foo*bar} visits the file
  1667. @file{/tmp/foo*bar}.
  1668. Another method of getting the same result is to enter
  1669. @file{/tmp/foo[*]bar}, which is a wildcard specification that matches
  1670. only @file{/tmp/foo*bar}. However, in many cases there is no need to
  1671. quote the wildcard characters because even unquoted they give the
  1672. right result. For example, if the only file name in @file{/tmp} that
  1673. starts with @samp{foo} and ends with @samp{bar} is @file{foo*bar},
  1674. then specifying @file{/tmp/foo*bar} will visit only
  1675. @file{/tmp/foo*bar}.
  1676. @node File Name Cache
  1677. @section File Name Cache
  1678. @cindex file name caching
  1679. @cindex cache of file names
  1680. @pindex find
  1681. @kindex C-TAB
  1682. @findex file-cache-minibuffer-complete
  1683. You can use the @dfn{file name cache} to make it easy to locate a
  1684. file by name, without having to remember exactly where it is located.
  1685. When typing a file name in the minibuffer, @kbd{C-@key{TAB}}
  1686. (@code{file-cache-minibuffer-complete}) completes it using the file
  1687. name cache. If you repeat @kbd{C-@key{TAB}}, that cycles through the
  1688. possible completions of what you had originally typed. (However, note
  1689. that the @kbd{C-@key{TAB}} character cannot be typed on most text
  1690. terminals.)
  1691. The file name cache does not fill up automatically. Instead, you
  1692. load file names into the cache using these commands:
  1693. @findex file-cache-add-directory
  1694. @table @kbd
  1695. @item M-x file-cache-add-directory @key{RET} @var{directory} @key{RET}
  1696. Add each file name in @var{directory} to the file name cache.
  1697. @item M-x file-cache-add-directory-using-find @key{RET} @var{directory} @key{RET}
  1698. Add each file name in @var{directory} and all of its nested
  1699. subdirectories to the file name cache.
  1700. @item M-x file-cache-add-directory-using-locate @key{RET} @var{directory} @key{RET}
  1701. Add each file name in @var{directory} and all of its nested
  1702. subdirectories to the file name cache, using @command{locate} to find
  1703. them all.
  1704. @item M-x file-cache-add-directory-list @key{RET} @var{variable} @key{RET}
  1705. Add each file name in each directory listed in @var{variable} to the
  1706. file name cache. @var{variable} should be a Lisp variable whose value
  1707. is a list of directory names, like @code{load-path}.
  1708. @item M-x file-cache-clear-cache @key{RET}
  1709. Clear the cache; that is, remove all file names from it.
  1710. @end table
  1711. The file name cache is not persistent: it is kept and maintained
  1712. only for the duration of the Emacs session. You can view the contents
  1713. of the cache with the @code{file-cache-display} command.
  1714. @node File Conveniences
  1715. @section Convenience Features for Finding Files
  1716. In this section, we introduce some convenient facilities for finding
  1717. recently-opened files, reading file names from a buffer, and viewing
  1718. image files.
  1719. @findex recentf-mode
  1720. @vindex recentf-mode
  1721. @findex recentf-save-list
  1722. @findex recentf-edit-list
  1723. If you enable Recentf mode, with @kbd{M-x recentf-mode}, the
  1724. @samp{File} menu includes a submenu containing a list of recently
  1725. opened files. @kbd{M-x recentf-save-list} saves the current
  1726. @code{recent-file-list} to a file, and @kbd{M-x recentf-edit-list}
  1727. edits it.
  1728. @c FIXME partial-completion-mode (complete.el) is obsolete.
  1729. The @kbd{M-x ffap} command generalizes @code{find-file} with more
  1730. powerful heuristic defaults (@pxref{FFAP}), often based on the text at
  1731. point. Partial Completion mode offers other features extending
  1732. @code{find-file}, which can be used with @code{ffap}.
  1733. @xref{Completion Options}.
  1734. @findex image-mode
  1735. @findex image-toggle-display
  1736. @findex image-next-file
  1737. @findex image-previous-file
  1738. @cindex images, viewing
  1739. Visiting image files automatically selects Image mode. In this
  1740. major mode, you can type @kbd{C-c C-c} (@code{image-toggle-display})
  1741. to toggle between displaying the file as an image in the Emacs buffer,
  1742. and displaying its underlying text (or raw byte) representation.
  1743. Additionally you can type @kbd{C-c C-x} (@code{image-toggle-hex-display})
  1744. to toggle between displaying the file as an image in the Emacs buffer,
  1745. and displaying it in hex representation.
  1746. Displaying the file as an image works only if Emacs is compiled with
  1747. support for displaying such images. If the displayed image is wider
  1748. or taller than the frame, the usual point motion keys (@kbd{C-f},
  1749. @kbd{C-p}, and so forth) cause different parts of the image to be
  1750. displayed. You can press @kbd{n} (@code{image-next-file}) and @kbd{p}
  1751. (@code{image-previous-file}) to visit the next image file and the
  1752. previous image file in the same directory, respectively.
  1753. @findex image-toggle-animation
  1754. @findex image-next-frame
  1755. @findex image-previous-frame
  1756. @findex image-goto-frame
  1757. @findex image-increase-speed
  1758. @findex image-decrease-speed
  1759. @findex image-reset-speed
  1760. @findex image-reverse-speed
  1761. @vindex image-animate-loop
  1762. @cindex image animation
  1763. @cindex animated images
  1764. If the image can be animated, the command @key{RET}
  1765. (@code{image-toggle-animation}) starts or stops the animation.
  1766. Animation plays once, unless the option @code{image-animate-loop} is
  1767. non-@code{nil}. With @kbd{f} (@code{image-next-frame}) and @kbd{b}
  1768. (@code{image-previous-frame}) you can step through the individual
  1769. frames. Both commands accept a numeric prefix to step through several
  1770. frames at once. You can go to a specific frame with @kbd{F}
  1771. (@code{image-goto-frame}). Frames are indexed from 1. Typing @kbd{a
  1772. +} (@code{image-increase-speed}) increases the speed of the animation,
  1773. @kbd{a -} (@code{image-decrease-speed}) decreases it, and @kbd{a r}
  1774. (@code{image-reverse-speed}) reverses it. The command @kbd{a 0}
  1775. (@code{image-reset-speed}) resets the speed to the original value.
  1776. @cindex ImageMagick support
  1777. @vindex imagemagick-enabled-types
  1778. @vindex imagemagick-types-inhibit
  1779. If Emacs was compiled with support for the ImageMagick library, it
  1780. can use ImageMagick to render a wide variety of images. The variable
  1781. @code{imagemagick-enabled-types} lists the image types that Emacs may
  1782. render using ImageMagick; each element in the list should be an
  1783. internal ImageMagick name for an image type, as a symbol or an
  1784. equivalent string (e.g., @code{BMP} for @file{.bmp} images). To
  1785. enable ImageMagick for all possible image types, change
  1786. @code{imagemagick-enabled-types} to @code{t}. The variable
  1787. @code{imagemagick-types-inhibit} lists the image types which should
  1788. never be rendered using ImageMagick, regardless of the value of
  1789. @code{imagemagick-enabled-types} (the default list includes types like
  1790. @code{C} and @code{HTML}, which ImageMagick can render as an image
  1791. but Emacs should not). To disable ImageMagick entirely, change
  1792. @code{imagemagick-types-inhibit} to @code{t}.
  1793. @findex thumbs-mode
  1794. @findex mode, thumbs
  1795. The Image-Dired package can also be used to view images as
  1796. thumbnails. @xref{Image-Dired}.
  1797. @node Filesets
  1798. @section Filesets
  1799. @cindex filesets
  1800. @cindex sets of files
  1801. @findex filesets-init
  1802. If you regularly edit a certain group of files, you can define them
  1803. as a @dfn{fileset}. This lets you perform certain operations, such as
  1804. visiting, @code{query-replace}, and shell commands on all the files at
  1805. once. To make use of filesets, you must first add the expression
  1806. @code{(filesets-init)} to your init file (@pxref{Init File}). This
  1807. adds a @samp{Filesets} sub-menu to the menu bar's @samp{File} menu.
  1808. @findex filesets-add-buffer
  1809. @findex filesets-remove-buffer
  1810. The simplest way to define a fileset is by adding files to it one at
  1811. a time. To add a file to fileset @var{name}, visit the file and type
  1812. @kbd{M-x filesets-add-buffer @key{RET} @var{name} @key{RET}}. If
  1813. there is no fileset @var{name}, this creates a new one, which
  1814. initially contains only the current file. The command @kbd{M-x
  1815. filesets-remove-buffer} removes the current file from a fileset.
  1816. You can also edit the list of filesets directly, with @kbd{M-x
  1817. filesets-edit} (or by choosing @samp{Edit Filesets} from the
  1818. @samp{Filesets} menu). The editing is performed in a Customize buffer
  1819. (@pxref{Easy Customization}). Normally, a fileset is a simple list of
  1820. files, but you can also define a fileset as a regular expression
  1821. matching file names. Some examples of these more complicated filesets
  1822. are shown in the Customize buffer. Remember to select @samp{Save for
  1823. future sessions} if you want to use the same filesets in future Emacs
  1824. sessions.
  1825. You can use the command @kbd{M-x filesets-open} to visit all the
  1826. files in a fileset, and @kbd{M-x filesets-close} to close them. Use
  1827. @kbd{M-x filesets-run-cmd} to run a shell command on all the files in
  1828. a fileset. These commands are also available from the @samp{Filesets}
  1829. menu, where each existing fileset is represented by a submenu.
  1830. @xref{Version Control}, for a different concept of filesets:
  1831. groups of files bundled together for version control operations.
  1832. Filesets of that type are unnamed, and do not persist across Emacs
  1833. sessions.