misc.texi 119 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954
  1. @c This is part of the Emacs manual.
  2. @c Copyright (C) 1985-1987, 1993-1995, 1997, 2000-2017 Free Software
  3. @c Foundation, Inc.
  4. @c See file emacs.texi for copying conditions.
  5. @iftex
  6. @chapter Miscellaneous Commands
  7. This chapter contains several brief topics that do not fit anywhere
  8. else: reading Usenet news, host and network security,
  9. viewing PDFs and other such documents, web
  10. browsing, running shell commands and shell subprocesses, using a
  11. single shared Emacs for utilities that expect to run an editor as a
  12. subprocess, printing, sorting text, editing binary files, saving an
  13. Emacs session for later resumption, recursive editing level, following
  14. hyperlinks, and various diversions and amusements.
  15. @end iftex
  16. @ifnottex
  17. @raisesections
  18. @end ifnottex
  19. @node Gnus
  20. @section Gnus
  21. @cindex Gnus
  22. @cindex Usenet news
  23. @cindex newsreader
  24. Gnus is an Emacs package primarily designed for reading and posting
  25. Usenet news. It can also be used to read and respond to messages from
  26. a number of other sources---email, remote directories, digests, and so
  27. on. Here we introduce Gnus and describe several basic features.
  28. @ifnottex
  29. For full details, see @ref{Top, Gnus,, gnus, The Gnus Manual}.
  30. @end ifnottex
  31. @iftex
  32. For full details on Gnus, type @kbd{C-h i} and then select the Gnus
  33. manual.
  34. @end iftex
  35. @menu
  36. * Buffers of Gnus:: The group, summary, and article buffers.
  37. * Gnus Startup:: What you should know about starting Gnus.
  38. * Gnus Group Buffer:: A short description of Gnus group commands.
  39. * Gnus Summary Buffer:: A short description of Gnus summary commands.
  40. @end menu
  41. @node Buffers of Gnus
  42. @subsection Gnus Buffers
  43. Gnus uses several buffers to display information and to receive
  44. commands. The three most commonly-used Gnus buffers are the
  45. @dfn{group buffer}, the @dfn{summary buffer} and the @dfn{article
  46. buffer}.
  47. The @dfn{group buffer} contains a list of article sources (e.g.,
  48. newsgroups and email inboxes), which are collectively referred to as
  49. @dfn{groups}. This is the first buffer Gnus displays when it starts
  50. up. It normally displays only the groups to which you subscribe and
  51. that contain unread articles. From this buffer, you can select a
  52. group to read.
  53. The @dfn{summary buffer} lists the articles in a single group,
  54. showing one article per line. By default, it displays each article's
  55. author, subject, and line
  56. @iftex
  57. number.
  58. @end iftex
  59. @ifnottex
  60. number, but this is customizable; @xref{Summary Buffer Format,,, gnus,
  61. The Gnus Manual}.
  62. @end ifnottex
  63. The summary buffer is created when you select a group in the group
  64. buffer, and is killed when you exit the group.
  65. From the summary buffer, you can choose an article to view. The
  66. article is displayed in the @dfn{article buffer}. In normal Gnus
  67. usage, you view this buffer but do not select it---all useful Gnus
  68. commands can be invoked from the summary buffer. But you can select
  69. the article buffer, and execute Gnus commands from it, if you wish.
  70. @node Gnus Startup
  71. @subsection When Gnus Starts Up
  72. @findex gnus
  73. @cindex @file{.newsrc} file
  74. If your system has been set up for reading Usenet news, getting
  75. started with Gnus is easy---just type @kbd{M-x gnus}.
  76. On starting up, Gnus reads your @dfn{news initialization file}: a
  77. file named @file{.newsrc} in your home directory which lists your
  78. Usenet newsgroups and subscriptions (this file is not unique to Gnus;
  79. it is used by many other newsreader programs). It then tries to
  80. contact the system's default news server, which is typically specified
  81. by the @env{NNTPSERVER} environment variable.
  82. If your system does not have a default news server, or if you wish
  83. to use Gnus for reading email, then before invoking @kbd{M-x gnus} you
  84. need to tell Gnus where to get news and/or mail. To do this,
  85. customize the variables @code{gnus-select-method} and/or
  86. @code{gnus-secondary-select-methods}.
  87. @iftex
  88. See the Gnus manual for details.
  89. @end iftex
  90. @ifnottex
  91. @xref{Finding the News,,, gnus, The Gnus Manual}.
  92. @end ifnottex
  93. Once Gnus has started up, it displays the group buffer. By default,
  94. the group buffer shows only a small number of @dfn{subscribed groups}.
  95. Groups with other statuses---@dfn{unsubscribed}, @dfn{killed}, or
  96. @dfn{zombie}---are hidden. The first time you start Gnus, any group
  97. to which you are not subscribed is made into a killed group; any group
  98. that subsequently appears on the news server becomes a zombie group.
  99. To proceed, you must select a group in the group buffer to open the
  100. summary buffer for that group; then, select an article in the summary
  101. buffer to view its article buffer in a separate window. The following
  102. sections explain how to use the group and summary buffers to do this.
  103. To quit Gnus, type @kbd{q} in the group buffer. This automatically
  104. records your group statuses in the files @file{.newsrc} and
  105. @file{.newsrc.eld}, so that they take effect in subsequent Gnus
  106. sessions.
  107. @node Gnus Group Buffer
  108. @subsection Using the Gnus Group Buffer
  109. The following commands are available in the Gnus group buffer:
  110. @table @kbd
  111. @kindex SPC @r{(Gnus Group mode)}
  112. @findex gnus-group-read-group
  113. @item @key{SPC}
  114. Switch to the summary buffer for the group on the current line.
  115. @kindex l @r{(Gnus Group mode)}
  116. @kindex A s @r{(Gnus Group mode)}
  117. @findex gnus-group-list-groups
  118. @item l
  119. @itemx A s
  120. In the group buffer, list only the groups to which you subscribe and
  121. which contain unread articles (this is the default listing).
  122. @kindex L @r{(Gnus Group mode)}
  123. @kindex A u @r{(Gnus Group mode)}
  124. @findex gnus-group-list-all-groups
  125. @item L
  126. @itemx A u
  127. List all subscribed and unsubscribed groups, but not killed or zombie
  128. groups.
  129. @kindex A k @r{(Gnus Group mode)}
  130. @findex gnus-group-list-all-groups
  131. @item A k
  132. List killed groups.
  133. @kindex A z @r{(Gnus Group mode)}
  134. @findex gnus-group-list-all-groups
  135. @item A z
  136. List zombie groups.
  137. @kindex u @r{(Gnus Group mode)}
  138. @findex gnus-group-unsubscribe-current-group
  139. @cindex subscribe groups
  140. @cindex unsubscribe groups
  141. @item u
  142. Toggle the subscription status of the group on the current line
  143. (i.e., turn a subscribed group into an unsubscribed group, or vice
  144. versa). Invoking this on a killed or zombie group turns it into an
  145. unsubscribed group.
  146. @kindex C-k @r{(Gnus Group mode)}
  147. @findex gnus-group-kill-group
  148. @item C-k
  149. Kill the group on the current line. Killed groups are not recorded in
  150. the @file{.newsrc} file, and they are not shown in the @kbd{l} or
  151. @kbd{L} listings.
  152. @kindex DEL @r{(Gnus Group mode)}
  153. @item @key{DEL}
  154. Move point to the previous group containing unread articles.
  155. @kindex n @r{(Gnus Group mode)}
  156. @findex gnus-group-next-unread-group
  157. @findex gnus-summary-next-unread-article
  158. @item n
  159. Move point to the next unread group.
  160. @kindex p @r{(Gnus Group mode)}
  161. @findex gnus-group-prev-unread-group
  162. @findex gnus-summary-prev-unread-article
  163. @item p
  164. Move point to the previous unread group.
  165. @kindex q @r{(Gnus Group mode)}
  166. @findex gnus-group-exit
  167. @item q
  168. Update your Gnus settings, and quit Gnus.
  169. @end table
  170. @node Gnus Summary Buffer
  171. @subsection Using the Gnus Summary Buffer
  172. The following commands are available in the Gnus summary buffer:
  173. @table @kbd
  174. @kindex SPC @r{(Gnus Summary mode)}
  175. @findex gnus-group-read-group
  176. @item @key{SPC}
  177. If there is no article selected, select the article on the current
  178. line and display its article buffer. Otherwise, try scrolling the
  179. selected article buffer in its window; on reaching the end of the
  180. buffer, select the next unread article.
  181. Thus, you can read through all articles by repeatedly typing
  182. @key{SPC}.
  183. @kindex DEL @r{(Gnus Summary mode)}
  184. @findex gnus-summary-prev-page
  185. @item @key{DEL}
  186. Scroll the text of the article backwards.
  187. @kindex n @r{(Gnus Summary mode)}
  188. @findex gnus-group-next-unread-group
  189. @findex gnus-summary-next-unread-article
  190. @item n
  191. Select the next unread article.
  192. @kindex p @r{(Gnus Summary mode)}
  193. @findex gnus-group-prev-unread-group
  194. @findex gnus-summary-prev-unread-article
  195. @item p
  196. Select the previous unread article.
  197. @kindex s @r{(Gnus Summary mode)}
  198. @findex gnus-summary-isearch-article
  199. @item s
  200. Do an incremental search on the selected article buffer, as if you
  201. switched to the buffer and typed @kbd{C-s} (@pxref{Incremental
  202. Search}).
  203. @kindex M-s @r{(Gnus Summary mode)}
  204. @findex gnus-summary-search-article-forward
  205. @item M-s @var{regexp} @key{RET}
  206. Search forward for articles containing a match for @var{regexp}.
  207. @kindex q @r{(Gnus Summary mode)}
  208. @item q
  209. Exit the summary buffer and return to the group buffer.
  210. @end table
  211. @node Host Security
  212. @section Host Security
  213. @cindex security
  214. Emacs runs inside an operating system such as GNU/Linux, and relies on
  215. the operating system to check security constraints such as accesses to
  216. files. The default settings for Emacs are designed for typical use;
  217. they may require some tailoring in environments where security is more
  218. of a concern, or less of a concern, than usual. For example,
  219. file-local variables can be risky, and you can set the variable
  220. @code{enable-local-variables} to @code{:safe} or (even more
  221. conservatively) to @code{nil}; conversely, if your files can all be
  222. trusted and the default checking for these variables is irritating,
  223. you can set @code{enable-local-variables} to @code{:all}. @xref{Safe
  224. File Variables}.
  225. @xref{Security Considerations,,, elisp, The Emacs Lisp Reference
  226. Manual}, for more information about security considerations when using
  227. Emacs as part of a larger application.
  228. @node Network Security
  229. @section Network Security
  230. @cindex network security manager
  231. @cindex NSM
  232. @cindex encryption
  233. @cindex SSL
  234. @cindex TLS
  235. @cindex STARTTLS
  236. Whenever Emacs establishes any network connection, it passes the
  237. established connection to the @dfn{Network Security Manager}
  238. (@acronym{NSM}). @acronym{NSM} is responsible for enforcing the
  239. network security under your control.
  240. @vindex network-security-level
  241. The @code{network-security-level} variable determines the security
  242. level that @acronym{NSM} enforces. If its value is @code{low}, no
  243. security checks are performed.
  244. If this variable is @code{medium} (which is the default), a number of
  245. checks will be performed. If as result @acronym{NSM} determines that
  246. the network connection might not be trustworthy, it will make you
  247. aware of that, and will ask you what to do about the network
  248. connection.
  249. You can decide to register a permanent security exception for an
  250. unverified connection, a temporary exception, or refuse the connection
  251. entirely.
  252. Below is a list of the checks done on the @code{medium} level.
  253. @table @asis
  254. @item unable to verify a @acronym{TLS} certificate
  255. If the connection is a @acronym{TLS}, @acronym{SSL} or
  256. @acronym{STARTTLS} connection, @acronym{NSM} will check whether
  257. the certificate used to establish the identity of the server we're
  258. connecting to can be verified.
  259. While an invalid certificate is often the cause for concern (there
  260. could be a Man-in-the-Middle hijacking your network connection and
  261. stealing your password), there may be valid reasons for going ahead
  262. with the connection anyway. For instance, the server may be using a
  263. self-signed certificate, or the certificate may have expired. It's up
  264. to you to determine whether it's acceptable to continue with the
  265. connection.
  266. @item a self-signed certificate has changed
  267. If you've previously accepted a self-signed certificate, but it has
  268. now changed, that could mean that the server has just changed the
  269. certificate, but it might also mean that the network connection has
  270. been hijacked.
  271. @item previously encrypted connection now unencrypted
  272. If the connection is unencrypted, but it was encrypted in previous
  273. sessions, this might mean that there is a proxy between you and the
  274. server that strips away @acronym{STARTTLS} announcements, leaving the
  275. connection unencrypted. This is usually very suspicious.
  276. @item talking to an unencrypted service when sending a password
  277. When connecting to an @acronym{IMAP} or @acronym{POP3} server, these
  278. should usually be encrypted, because it's common to send passwords
  279. over these connections. Similarly, if you're sending email via
  280. @acronym{SMTP} that requires a password, you usually want that
  281. connection to be encrypted. If the connection isn't encrypted,
  282. @acronym{NSM} will warn you.
  283. @end table
  284. If @code{network-security-level} is @code{high}, the following checks
  285. will be made, in addition to the above:
  286. @table @asis
  287. @item a validated certificate changes the public key
  288. Servers change their keys occasionally, and that is normally nothing
  289. to be concerned about. However, if you are worried that your network
  290. connections are being hijacked by agencies who have access to pliable
  291. Certificate Authorities which issue new certificates for third-party
  292. services, you may want to keep track of these changes.
  293. @item Diffie-Hellman low prime bits
  294. When doing the public key exchange, the number of prime bits
  295. should be high to ensure that the channel can't be eavesdropped on by
  296. third parties. If this number is too low, you will be warned.
  297. @item @acronym{RC4} stream cipher
  298. The @acronym{RC4} stream cipher is believed to be of low quality and
  299. may allow eavesdropping by third parties.
  300. @item @acronym{SSL1}, @acronym{SSL2} and @acronym{SSL3}
  301. The protocols older than @acronym{TLS1.0} are believed to be
  302. vulnerable to a variety of attacks, and you may want to avoid using
  303. these if what you're doing requires higher security.
  304. @end table
  305. Finally, if @code{network-security-level} is @code{paranoid}, you will
  306. also be notified the first time @acronym{NSM} sees any new
  307. certificate. This will allow you to inspect all the certificates from
  308. all the connections that Emacs makes.
  309. The following additional variables can be used to control details of
  310. @acronym{NSM} operation:
  311. @table @code
  312. @item nsm-settings-file
  313. @vindex nsm-settings-file
  314. This is the file where @acronym{NSM} stores details about connections.
  315. It defaults to @file{~/.emacs.d/network-security.data}.
  316. @item nsm-save-host-names
  317. @vindex nsm-save-host-names
  318. By default, host names will not be saved for non-@code{STARTTLS}
  319. connections. Instead a host/port hash is used to identify connections.
  320. This means that one can't casually read the settings file to see what
  321. servers the user has connected to. If this variable is @code{t},
  322. @acronym{NSM} will also save host names in the nsm-settings-file.
  323. @end table
  324. @node Document View
  325. @section Document Viewing
  326. @cindex DVI file
  327. @cindex PDF file
  328. @cindex PS file
  329. @cindex PostScript file
  330. @cindex OpenDocument file
  331. @cindex Microsoft Office file
  332. @cindex DocView mode
  333. @cindex mode, DocView
  334. @cindex document viewer (DocView)
  335. @findex doc-view-mode
  336. DocView mode is a major mode for viewing DVI, PostScript (PS), PDF,
  337. OpenDocument, and Microsoft Office documents. It provides features
  338. such as slicing, zooming, and searching inside documents. It works by
  339. converting the document to a set of images using the @command{gs}
  340. (GhostScript) or @command{mudraw}/@command{pdfdraw} (MuPDF) commands
  341. and other external tools @footnote{For PostScript files, GhostScript
  342. is a hard requirement. For DVI files, @code{dvipdf} or @code{dvipdfm}
  343. is needed. For OpenDocument and Microsoft Office documents, the
  344. @code{unoconv} tool is needed.}, and displaying those images.
  345. @findex doc-view-toggle-display
  346. @findex doc-view-toggle-display
  347. @cindex doc-view-minor-mode
  348. When you visit a document file that can be displayed with DocView
  349. mode, Emacs automatically uses DocView mode @footnote{The needed
  350. external tools for the document type must be available, and Emacs must
  351. be running in a graphical frame and have PNG image support. If any of
  352. these requirements is not fulfilled, Emacs falls back to another major
  353. mode.}. As an exception, when you visit a PostScript file, Emacs
  354. switches to PS mode, a major mode for editing PostScript files as
  355. text; however, it also enables DocView minor mode, so you can type
  356. @kbd{C-c C-c} to view the document with DocView. In either DocView
  357. mode or DocView minor mode, repeating @kbd{C-c C-c}
  358. (@code{doc-view-toggle-display}) toggles between DocView and the
  359. underlying file contents.
  360. @findex doc-view-open-text
  361. When you visit a file which would normally be handled by DocView
  362. mode but some requirement is not met (e.g., you operate in a terminal
  363. frame or emacs has no PNG support), you are queried if you want to
  364. view the document's contents as plain text. If you confirm, the
  365. buffer is put in text mode and DocView minor mode is activated. Thus,
  366. by typing @kbd{C-c C-c} you switch to the fallback mode. With another
  367. @kbd{C-c C-c} you return to DocView mode. The plain text contents can
  368. also be displayed from within DocView mode by typing @kbd{C-c C-t}
  369. (@code{doc-view-open-text}).
  370. You can explicitly enable DocView mode with the command @code{M-x
  371. doc-view-mode}. You can toggle DocView minor mode with @code{M-x
  372. doc-view-minor-mode}.
  373. When DocView mode starts, it displays a welcome screen and begins
  374. formatting the file, page by page. It displays the first page once
  375. that has been formatted.
  376. To kill the DocView buffer, type @kbd{k}
  377. (@code{doc-view-kill-proc-and-buffer}). To bury it, type @kbd{q}
  378. (@code{quit-window}).
  379. @menu
  380. * Navigation: DocView Navigation. Navigating DocView buffers.
  381. * Searching: DocView Searching. Searching inside documents.
  382. * Slicing: DocView Slicing. Specifying which part of a page is displayed.
  383. * Conversion: DocView Conversion. Influencing and triggering conversion.
  384. @end menu
  385. @node DocView Navigation
  386. @subsection DocView Navigation
  387. In DocView mode, you can scroll the current page using the usual
  388. Emacs movement keys: @kbd{C-p}, @kbd{C-n}, @kbd{C-b}, @kbd{C-f}, and
  389. the arrow keys.
  390. @vindex doc-view-continuous
  391. By default, the line-motion keys @kbd{C-p} and @kbd{C-n} stop
  392. scrolling at the beginning and end of the current page, respectively.
  393. However, if you change the variable @code{doc-view-continuous} to a
  394. non-@code{nil} value, then @kbd{C-p} displays the previous page if you
  395. are already at the beginning of the current page, and @kbd{C-n}
  396. displays the next page if you are at the end of the current page.
  397. @findex doc-view-next-page
  398. @findex doc-view-previous-page
  399. @kindex n @r{(DocView mode)}
  400. @kindex p @r{(DocView mode)}
  401. @kindex C-x ] @r{(DocView mode)}
  402. @kindex C-x [ @r{(DocView mode)}
  403. You can also display the next page by typing @kbd{n}, @key{next} or
  404. @kbd{C-x ]} (@code{doc-view-next-page}). To display the previous
  405. page, type @kbd{p}, @key{prior} or @kbd{C-x [}
  406. (@code{doc-view-previous-page}).
  407. @findex doc-view-scroll-up-or-next-page
  408. @findex doc-view-scroll-down-or-previous-page
  409. @kindex SPC @r{(DocView mode)}
  410. @kindex DEL @r{(DocView mode)}
  411. @key{SPC} (@code{doc-view-scroll-up-or-next-page}) is a convenient
  412. way to advance through the document. It scrolls within the current
  413. page or advances to the next. @key{DEL} moves backwards in a similar
  414. way (@code{doc-view-scroll-down-or-previous-page}).
  415. @findex doc-view-first-page
  416. @findex doc-view-last-page
  417. @findex doc-view-goto-page
  418. @kindex M-< @r{(DocView mode)}
  419. @kindex M-> @r{(DocView mode)}
  420. To go to the first page, type @kbd{M-<}
  421. (@code{doc-view-first-page}); to go to the last one, type @kbd{M->}
  422. (@code{doc-view-last-page}). To jump to a page by its number, type
  423. @kbd{M-g M-g} or @kbd{M-g g} (@code{doc-view-goto-page}).
  424. @findex doc-view-enlarge
  425. @findex doc-view-shrink
  426. @vindex doc-view-resolution
  427. @kindex + @r{(DocView mode)}
  428. @kindex - @r{(DocView mode)}
  429. You can enlarge or shrink the document with @kbd{+}
  430. (@code{doc-view-enlarge}) and @kbd{-} (@code{doc-view-shrink}). These
  431. commands work by reconverting the document at the new size. To
  432. specify the default size for DocView, customize the variable
  433. @code{doc-view-resolution}.
  434. @node DocView Searching
  435. @subsection DocView Searching
  436. In DocView mode, you can search the file's text for a regular
  437. expression (@pxref{Regexps}). The interface for searching is inspired
  438. by @code{isearch} (@pxref{Incremental Search}).
  439. @findex doc-view-search
  440. @findex doc-view-search-backward
  441. @findex doc-view-show-tooltip
  442. To begin a search, type @kbd{C-s} (@code{doc-view-search}) or
  443. @kbd{C-r} (@code{doc-view-search-backward}). This reads a regular
  444. expression using a minibuffer, then echoes the number of matches found
  445. within the document. You can move forward and back among the matches
  446. by typing @kbd{C-s} and @kbd{C-r}. DocView mode has no way to show
  447. the match inside the page image; instead, it displays a tooltip (at
  448. the mouse position) listing all matching lines in the current page.
  449. To force display of this tooltip, type @kbd{C-t}
  450. (@code{doc-view-show-tooltip}).
  451. To start a new search, use the search command with a prefix
  452. argument; i.e., @kbd{C-u C-s} for a forward search or @kbd{C-u C-r}
  453. for a backward search.
  454. @node DocView Slicing
  455. @subsection DocView Slicing
  456. Documents often have wide margins for printing. They are annoying
  457. when reading the document on the screen, because they use up screen
  458. space and can cause inconvenient scrolling.
  459. @findex doc-view-set-slice
  460. @findex doc-view-set-slice-using-mouse
  461. With DocView you can hide these margins by selecting a @dfn{slice}
  462. of pages to display. A slice is a rectangle within the page area;
  463. once you specify a slice in DocView, it applies to whichever page you
  464. look at.
  465. To specify the slice numerically, type @kbd{s s}
  466. (@code{doc-view-set-slice}); then enter the top left pixel position
  467. and the slice's width and height.
  468. @c ??? how does this work?
  469. A more convenient graphical way to specify the slice is with @kbd{s
  470. m} (@code{doc-view-set-slice-using-mouse}), where you use the mouse to
  471. select the slice. Simply press and hold the left mouse button at the
  472. upper-left corner of the region you want to have in the slice, then
  473. move the mouse pointer to the lower-right corner and release the
  474. button.
  475. The most convenient way is to set the optimal slice by using
  476. BoundingBox information automatically determined from the document by
  477. typing @kbd{s b} (@code{doc-view-set-slice-from-bounding-box}).
  478. @findex doc-view-reset-slice
  479. To cancel the selected slice, type @kbd{s r}
  480. (@code{doc-view-reset-slice}). Then DocView shows the entire page
  481. including its entire margins.
  482. @node DocView Conversion
  483. @subsection DocView Conversion
  484. @vindex doc-view-cache-directory
  485. @findex doc-view-clear-cache
  486. For efficiency, DocView caches the images produced by @command{gs}.
  487. The name of this directory is given by the variable
  488. @code{doc-view-cache-directory}. You can clear the cache directory by
  489. typing @code{M-x doc-view-clear-cache}.
  490. @findex doc-view-kill-proc
  491. @findex doc-view-kill-proc-and-buffer
  492. To force reconversion of the currently viewed document, type @kbd{r}
  493. or @kbd{g} (@code{revert-buffer}). To kill the converter process
  494. associated with the current buffer, type @kbd{K}
  495. (@code{doc-view-kill-proc}). The command @kbd{k}
  496. (@code{doc-view-kill-proc-and-buffer}) kills the converter process and
  497. the DocView buffer.
  498. @node EWW
  499. @section Web Browsing with EWW
  500. @findex eww
  501. @findex eww-open-file
  502. @dfn{EWW}, the Emacs Web Wowser, is a web browser package for Emacs.
  503. It allows browsing URLs within an Emacs buffer. The command @kbd{M-x
  504. eww} will open a URL or search the web. You can open a file
  505. using the command @kbd{M-x eww-open-file}. You can use EWW as the
  506. web browser for @code{browse-url}, @pxref{Browse-URL}. For full
  507. details, @pxref{Top, EWW,, eww, The Emacs Web Wowser Manual}.
  508. @node Embedded WebKit Widgets
  509. @section Embedded WebKit Widgets
  510. @cindex xwidget
  511. @cindex webkit widgets
  512. @cindex embedded widgets
  513. @findex xwidget-webkit-browse-url
  514. @findex xwidget-webkit-mode
  515. @cindex Xwidget-WebKit mode
  516. If Emacs was compiled with the appropriate support packages, it is
  517. able to show browser widgets in its buffers. The command @kbd{M-x
  518. xwidget-webkit-browse-url} asks for a URL to display in the browser
  519. widget. The URL normally defaults to the URL at or before point, but
  520. if there is an active region (@pxref{Mark}), the default URL comes
  521. from the region instead, after removing any whitespace from it. The
  522. command then creates a new buffer with the embedded browser showing
  523. the specified URL. The buffer is put in the Xwidget-WebKit mode
  524. (similar to Image mode, @pxref{File Conveniences}), which provides
  525. one-key commands for scrolling the widget, changing its size, and
  526. reloading it. Type @w{@kbd{C-h b}} in that buffer to see the key
  527. bindings.
  528. @node Shell
  529. @section Running Shell Commands from Emacs
  530. @cindex subshell
  531. @cindex shell commands
  532. Emacs has commands for passing single command lines to shell
  533. subprocesses, and for running a shell interactively with input and
  534. output to an Emacs buffer, and for running a shell in a terminal
  535. emulator window.
  536. @table @kbd
  537. @item M-! @var{cmd} @key{RET}
  538. Run the shell command @var{cmd} and display the output
  539. (@code{shell-command}).
  540. @item M-| @var{cmd} @key{RET}
  541. Run the shell command @var{cmd} with region contents as input;
  542. optionally replace the region with the output
  543. (@code{shell-command-on-region}).
  544. @item M-& @var{cmd} @key{RET}
  545. Run the shell command @var{cmd} asynchronously, and display the output
  546. (@code{async-shell-command}).
  547. @item M-x shell
  548. Run a subshell with input and output through an Emacs buffer. You can
  549. then give commands interactively.
  550. @item M-x term
  551. Run a subshell with input and output through an Emacs buffer. You can
  552. then give commands interactively. Full terminal emulation is
  553. available.
  554. @end table
  555. @vindex exec-path
  556. Whenever you specify a relative file name for an executable program
  557. (either in the @var{cmd} argument to one of the above commands, or in
  558. other contexts), Emacs searches for the program in the directories
  559. specified by the variable @code{exec-path}. The value of this
  560. variable must be a list of directory names; the default value is
  561. initialized from the environment variable @env{PATH} when Emacs is
  562. started (@pxref{General Variables}).
  563. @kbd{M-x eshell} invokes a shell implemented entirely in Emacs. It
  564. is documented in its own manual.
  565. @ifnottex
  566. @xref{Top,Eshell,Eshell, eshell, Eshell: The Emacs Shell}.
  567. @end ifnottex
  568. @iftex
  569. See the Eshell Info manual, which is distributed with Emacs.
  570. @end iftex
  571. @menu
  572. * Single Shell:: How to run one shell command and return.
  573. * Interactive Shell:: Permanent shell taking input via Emacs.
  574. * Shell Mode:: Special Emacs commands used with permanent shell.
  575. * Shell Prompts:: Two ways to recognize shell prompts.
  576. * History: Shell History. Repeating previous commands in a shell buffer.
  577. * Directory Tracking:: Keeping track when the subshell changes directory.
  578. * Options: Shell Options. Options for customizing Shell mode.
  579. * Terminal emulator:: An Emacs window as a terminal emulator.
  580. * Term Mode:: Special Emacs commands used in Term mode.
  581. * Remote Host:: Connecting to another computer.
  582. * Serial Terminal:: Connecting to a serial port.
  583. @end menu
  584. @node Single Shell
  585. @subsection Single Shell Commands
  586. @kindex M-!
  587. @findex shell-command
  588. @kbd{M-!} (@code{shell-command}) reads a line of text using the
  589. minibuffer and executes it as a shell command, in a subshell made just
  590. for that command. Standard input for the command comes from the null
  591. device. If the shell command produces any output, the output appears
  592. either in the echo area (if it is short), or in an Emacs buffer named
  593. @file{*Shell Command Output*}, displayed in another window (if the
  594. output is long).
  595. For instance, one way to decompress a file named @file{foo.gz} is to
  596. type @kbd{M-! gunzip foo.gz @key{RET}}. That shell command normally
  597. creates the file @file{foo} and produces no terminal output.
  598. A numeric argument to @code{shell-command}, e.g., @kbd{M-1 M-!},
  599. causes it to insert terminal output into the current buffer instead of
  600. a separate buffer. It puts point before the output, and sets the mark
  601. after the output. For instance, @kbd{M-1 M-! gunzip < foo.gz
  602. @key{RET}} would insert the uncompressed form of the file
  603. @file{foo.gz} into the current buffer.
  604. Provided the specified shell command does not end with @samp{&}, it
  605. runs @dfn{synchronously}, and you must wait for it to exit before
  606. continuing to use Emacs. To stop waiting, type @kbd{C-g} to quit;
  607. this sends a @code{SIGINT} signal to terminate the shell command (this
  608. is the same signal that @kbd{C-c} normally generates in the shell).
  609. Emacs then waits until the command actually terminates. If the shell
  610. command doesn't stop (because it ignores the @code{SIGINT} signal),
  611. type @kbd{C-g} again; this sends the command a @code{SIGKILL} signal,
  612. which is impossible to ignore.
  613. @kindex M-&
  614. @findex async-shell-command
  615. A shell command that ends in @samp{&} is executed
  616. @dfn{asynchronously}, and you can continue to use Emacs as it runs.
  617. You can also type @kbd{M-&} (@code{async-shell-command}) to execute a
  618. shell command asynchronously; this is exactly like calling @kbd{M-!}
  619. with a trailing @samp{&}, except that you do not need the @samp{&}.
  620. The default output buffer for asynchronous shell commands is named
  621. @samp{*Async Shell Command*}. Emacs inserts the output into this
  622. buffer as it comes in, whether or not the buffer is visible in a
  623. window.
  624. @vindex async-shell-command-buffer
  625. If you want to run more than one asynchronous shell command at the
  626. same time, they could end up competing for the output buffer. The
  627. option @code{async-shell-command-buffer} specifies what to do about
  628. this; e.g., whether to rename the pre-existing output buffer, or to
  629. use a different buffer for the new command. Consult the variable's
  630. documentation for more possibilities.
  631. @vindex async-shell-command-display-buffer
  632. If you want the output buffer for asynchronous shell commands to be
  633. displayed only when the command generates output, set
  634. @code{async-shell-command-display-buffer} to @code{nil}.
  635. @kindex M-|
  636. @findex shell-command-on-region
  637. @kbd{M-|} (@code{shell-command-on-region}) is like @kbd{M-!}, but
  638. passes the contents of the region as the standard input to the shell
  639. command, instead of no input. With a numeric argument, it deletes the
  640. old region and replaces it with the output from the shell command.
  641. For example, you can use @kbd{M-|} with the @command{gpg} program to
  642. see what keys are in the buffer. If the buffer contains a GnuPG key,
  643. type @kbd{C-x h M-| gpg @key{RET}} to feed the entire buffer contents
  644. to @command{gpg}. This will output the list of keys to the
  645. @file{*Shell Command Output*} buffer.
  646. @vindex shell-file-name
  647. The above commands use the shell specified by the variable
  648. @code{shell-file-name}. Its default value is determined by the
  649. @env{SHELL} environment variable when Emacs is started. If the file
  650. name is relative, Emacs searches the directories listed in
  651. @code{exec-path} (@pxref{Shell}).
  652. To specify a coding system for @kbd{M-!} or @kbd{M-|}, use the command
  653. @kbd{C-x @key{RET} c} immediately beforehand. @xref{Communication Coding}.
  654. @vindex shell-command-default-error-buffer
  655. By default, error output is intermixed with the regular output in
  656. the output buffer. But if you change the value of the variable
  657. @code{shell-command-default-error-buffer} to a string, error output is
  658. inserted into a buffer of that name.
  659. @vindex shell-command-dont-erase-buffer
  660. By default, the output buffer is erased between shell commands.
  661. If you change the value of the variable
  662. @code{shell-command-dont-erase-buffer} to a non-@code{nil} value,
  663. the output buffer is not erased. This variable also controls where to
  664. set the point in the output buffer after the command completes; see the
  665. documentation of the variable for details.
  666. @node Interactive Shell
  667. @subsection Interactive Subshell
  668. @findex shell
  669. To run a subshell interactively, type @kbd{M-x shell}. This creates
  670. (or reuses) a buffer named @file{*shell*}, and runs a shell subprocess
  671. with input coming from and output going to that buffer. That is to
  672. say, any terminal output from the subshell goes into the buffer,
  673. advancing point, and any terminal input for the subshell comes from
  674. text in the buffer. To give input to the subshell, go to the end of
  675. the buffer and type the input, terminated by @key{RET}.
  676. By default, when the subshell is invoked interactively, the
  677. @file{*shell*} buffer is displayed in a new window. This behavior can
  678. be customized via @code{display-buffer-alist} (@pxref{Window Choice}).
  679. While the subshell is waiting or running a command, you can switch
  680. windows or buffers and perform other editing in Emacs. Emacs inserts
  681. the output from the subshell into the Shell buffer whenever it has
  682. time to process it (e.g., while waiting for keyboard input).
  683. @cindex @code{comint-highlight-input} face
  684. @cindex @code{comint-highlight-prompt} face
  685. In the Shell buffer, prompts are displayed with the face
  686. @code{comint-highlight-prompt}, and submitted input lines are
  687. displayed with the face @code{comint-highlight-input}. This makes it
  688. easier to distinguish input lines from the shell output.
  689. @xref{Faces}.
  690. To make multiple subshells, invoke @kbd{M-x shell} with a prefix
  691. argument (e.g., @kbd{C-u M-x shell}). Then the command will read a
  692. buffer name, and create (or reuse) a subshell in that buffer. You can
  693. also rename the @file{*shell*} buffer using @kbd{M-x rename-uniquely},
  694. then create a new @file{*shell*} buffer using plain @kbd{M-x shell}.
  695. Subshells in different buffers run independently and in parallel.
  696. @vindex explicit-shell-file-name
  697. @cindex environment variables for subshells
  698. @cindex @env{ESHELL} environment variable
  699. @cindex @env{SHELL} environment variable
  700. To specify the shell file name used by @kbd{M-x shell}, customize
  701. the variable @code{explicit-shell-file-name}. If this is @code{nil}
  702. (the default), Emacs uses the environment variable @env{ESHELL} if it
  703. exists. Otherwise, it usually uses the variable
  704. @code{shell-file-name} (@pxref{Single Shell}); but if the default
  705. directory is remote (@pxref{Remote Files}), it prompts you for the
  706. shell file name.
  707. Emacs sends the new shell the contents of the file
  708. @file{~/.emacs_@var{shellname}} as input, if it exists, where
  709. @var{shellname} is the name of the file that the shell was loaded
  710. from. For example, if you use bash, the file sent to it is
  711. @file{~/.emacs_bash}. If this file is not found, Emacs tries with
  712. @file{~/.emacs.d/init_@var{shellname}.sh}.
  713. To specify a coding system for the shell, you can use the command
  714. @kbd{C-x @key{RET} c} immediately before @kbd{M-x shell}. You can
  715. also change the coding system for a running subshell by typing
  716. @kbd{C-x @key{RET} p} in the shell buffer. @xref{Communication
  717. Coding}.
  718. @cindex @env{INSIDE_EMACS} environment variable
  719. Emacs sets the environment variable @env{INSIDE_EMACS} in the
  720. subshell to @samp{@var{version},comint}, where @var{version} is the
  721. Emacs version (e.g., @samp{24.1}). Programs can check this variable
  722. to determine whether they are running inside an Emacs subshell.
  723. @node Shell Mode
  724. @subsection Shell Mode
  725. @cindex Shell mode
  726. @cindex mode, Shell
  727. The major mode for Shell buffers is Shell mode. Many of its special
  728. commands are bound to the @kbd{C-c} prefix, and resemble the usual
  729. editing and job control characters present in ordinary shells, except
  730. that you must type @kbd{C-c} first. Here is a list of Shell mode
  731. commands:
  732. @table @kbd
  733. @item @key{RET}
  734. @kindex RET @r{(Shell mode)}
  735. @findex comint-send-input
  736. Send the current line as input to the subshell
  737. (@code{comint-send-input}). Any shell prompt at the beginning of the
  738. line is omitted (@pxref{Shell Prompts}). If point is at the end of
  739. buffer, this is like submitting the command line in an ordinary
  740. interactive shell. However, you can also invoke @key{RET} elsewhere
  741. in the shell buffer to submit the current line as input.
  742. @item @key{TAB}
  743. @kindex TAB @r{(Shell mode)}
  744. @findex completion-at-point
  745. @cindex shell completion
  746. Complete the command name or file name before point in the shell
  747. buffer (@code{completion-at-point}). This uses the usual Emacs
  748. completion rules (@pxref{Completion}), with the completion
  749. alternatives being file names, environment variable names, the shell
  750. command history, and history references (@pxref{History References}).
  751. For options controlling the completion, @pxref{Shell Options}.
  752. @item M-?
  753. @kindex M-? @r{(Shell mode)}
  754. @findex comint-dynamic-list-filename@dots{}
  755. Display temporarily a list of the possible completions of the file
  756. name before point (@code{comint-dynamic-list-filename-completions}).
  757. @item C-d
  758. @kindex C-d @r{(Shell mode)}
  759. @findex comint-delchar-or-maybe-eof
  760. Either delete a character or send @acronym{EOF}
  761. (@code{comint-delchar-or-maybe-eof}). Typed at the end of the shell
  762. buffer, this sends @acronym{EOF} to the subshell. Typed at any other
  763. position in the buffer, this deletes a character as usual.
  764. @item C-c C-a
  765. @kindex C-c C-a @r{(Shell mode)}
  766. @findex comint-bol-or-process-mark
  767. Move to the beginning of the line, but after the prompt if any
  768. (@code{comint-bol-or-process-mark}). If you repeat this command twice
  769. in a row, the second time it moves back to the process mark, which is
  770. the beginning of the input that you have not yet sent to the subshell.
  771. (Normally that is the same place---the end of the prompt on this
  772. line---but after @kbd{C-c @key{SPC}} the process mark may be in a
  773. previous line.)
  774. @item C-c @key{SPC}
  775. Accumulate multiple lines of input, then send them together. This
  776. command inserts a newline before point, but does not send the preceding
  777. text as input to the subshell---at least, not yet. Both lines, the one
  778. before this newline and the one after, will be sent together (along with
  779. the newline that separates them), when you type @key{RET}.
  780. @item C-c C-u
  781. @kindex C-c C-u @r{(Shell mode)}
  782. @findex comint-kill-input
  783. Kill all text pending at end of buffer to be sent as input
  784. (@code{comint-kill-input}). If point is not at end of buffer,
  785. this only kills the part of this text that precedes point.
  786. @item C-c C-w
  787. @kindex C-c C-w @r{(Shell mode)}
  788. Kill a word before point (@code{backward-kill-word}).
  789. @item C-c C-c
  790. @kindex C-c C-c @r{(Shell mode)}
  791. @findex comint-interrupt-subjob
  792. Interrupt the shell or its current subjob if any
  793. (@code{comint-interrupt-subjob}). This command also kills
  794. any shell input pending in the shell buffer and not yet sent.
  795. @item C-c C-z
  796. @kindex C-c C-z @r{(Shell mode)}
  797. @findex comint-stop-subjob
  798. Stop the shell or its current subjob if any (@code{comint-stop-subjob}).
  799. This command also kills any shell input pending in the shell buffer and
  800. not yet sent.
  801. @item C-c C-\
  802. @findex comint-quit-subjob
  803. @kindex C-c C-\ @r{(Shell mode)}
  804. Send quit signal to the shell or its current subjob if any
  805. (@code{comint-quit-subjob}). This command also kills any shell input
  806. pending in the shell buffer and not yet sent.
  807. @item C-c C-o
  808. @kindex C-c C-o @r{(Shell mode)}
  809. @findex comint-delete-output
  810. Delete the last batch of output from a shell command
  811. (@code{comint-delete-output}). This is useful if a shell command spews
  812. out lots of output that just gets in the way.
  813. @item C-c C-s
  814. @kindex C-c C-s @r{(Shell mode)}
  815. @findex comint-write-output
  816. Write the last batch of output from a shell command to a file
  817. (@code{comint-write-output}). With a prefix argument, the file is
  818. appended to instead. Any prompt at the end of the output is not
  819. written.
  820. @item C-c C-r
  821. @itemx C-M-l
  822. @kindex C-c C-r @r{(Shell mode)}
  823. @kindex C-M-l @r{(Shell mode)}
  824. @findex comint-show-output
  825. Scroll to display the beginning of the last batch of output at the top
  826. of the window; also move the cursor there (@code{comint-show-output}).
  827. @item C-c C-e
  828. @kindex C-c C-e @r{(Shell mode)}
  829. @findex comint-show-maximum-output
  830. Scroll to put the end of the buffer at the bottom of the window
  831. (@code{comint-show-maximum-output}).
  832. @item C-c C-f
  833. @kindex C-c C-f @r{(Shell mode)}
  834. @findex shell-forward-command
  835. @vindex shell-command-regexp
  836. Move forward across one shell command, but not beyond the current line
  837. (@code{shell-forward-command}). The variable @code{shell-command-regexp}
  838. specifies how to recognize the end of a command.
  839. @item C-c C-b
  840. @kindex C-c C-b @r{(Shell mode)}
  841. @findex shell-backward-command
  842. Move backward across one shell command, but not beyond the current line
  843. (@code{shell-backward-command}).
  844. @item M-x dirs
  845. Ask the shell for its working directory, and update the Shell buffer's
  846. default directory. @xref{Directory Tracking}.
  847. @item M-x send-invisible @key{RET} @var{text} @key{RET}
  848. @findex send-invisible
  849. Send @var{text} as input to the shell, after reading it without
  850. echoing. This is useful when a shell command runs a program that asks
  851. for a password.
  852. Please note that Emacs will not echo passwords by default. If you
  853. really want them to be echoed, evaluate (@pxref{Lisp Eval}) the
  854. following Lisp expression:
  855. @example
  856. (remove-hook 'comint-output-filter-functions
  857. 'comint-watch-for-password-prompt)
  858. @end example
  859. @item M-x comint-continue-subjob
  860. @findex comint-continue-subjob
  861. Continue the shell process. This is useful if you accidentally suspend
  862. the shell process.@footnote{You should not suspend the shell process.
  863. Suspending a subjob of the shell is a completely different matter---that
  864. is normal practice, but you must use the shell to continue the subjob;
  865. this command won't do it.}
  866. @item M-x comint-strip-ctrl-m
  867. @findex comint-strip-ctrl-m
  868. Discard all control-M characters from the current group of shell output.
  869. The most convenient way to use this command is to make it run
  870. automatically when you get output from the subshell. To do that,
  871. evaluate this Lisp expression:
  872. @example
  873. (add-hook 'comint-output-filter-functions
  874. 'comint-strip-ctrl-m)
  875. @end example
  876. @item M-x comint-truncate-buffer
  877. @findex comint-truncate-buffer
  878. This command truncates the shell buffer to a certain maximum number of
  879. lines, specified by the variable @code{comint-buffer-maximum-size}.
  880. Here's how to do this automatically each time you get output from the
  881. subshell:
  882. @example
  883. (add-hook 'comint-output-filter-functions
  884. 'comint-truncate-buffer)
  885. @end example
  886. @end table
  887. @cindex Comint mode
  888. @cindex mode, Comint
  889. Shell mode is a derivative of Comint mode, a general-purpose mode for
  890. communicating with interactive subprocesses. Most of the features of
  891. Shell mode actually come from Comint mode, as you can see from the
  892. command names listed above. The special features of Shell mode include
  893. the directory tracking feature, and a few user commands.
  894. Other Emacs features that use variants of Comint mode include GUD
  895. (@pxref{Debuggers}) and @kbd{M-x run-lisp} (@pxref{External Lisp}).
  896. @findex comint-run
  897. You can use @kbd{M-x comint-run} to execute any program of your choice
  898. in a subprocess using unmodified Comint mode---without the
  899. specializations of Shell mode.
  900. @node Shell Prompts
  901. @subsection Shell Prompts
  902. @cindex prompt, shell
  903. A prompt is text output by a program to show that it is ready to
  904. accept new user input. Normally, Comint mode (and thus Shell mode)
  905. automatically figures out part of the buffer is a prompt, based on the
  906. output of the subprocess. (Specifically, it assumes that any received
  907. output line which doesn't end with a newline is a prompt.)
  908. Comint mode divides the buffer into two types of @dfn{fields}: input
  909. fields (where user input is typed) and output fields (everywhere
  910. else). Prompts are part of the output fields. Most Emacs motion
  911. commands do not cross field boundaries, unless they move over multiple
  912. lines. For instance, when point is in the input field on a shell
  913. command line, @kbd{C-a} puts point at the beginning of the input
  914. field, after the prompt. Internally, the fields are implemented using
  915. the @code{field} text property (@pxref{Text Properties,,, elisp, the
  916. Emacs Lisp Reference Manual}).
  917. @vindex comint-use-prompt-regexp
  918. @vindex shell-prompt-pattern
  919. If you change the variable @code{comint-use-prompt-regexp} to a
  920. non-@code{nil} value, then Comint mode recognize prompts using a
  921. regular expression (@pxref{Regexps}). In Shell mode, the regular
  922. expression is specified by the variable @code{shell-prompt-pattern}.
  923. The default value of @code{comint-use-prompt-regexp} is @code{nil},
  924. because this method for recognizing prompts is unreliable, but you may
  925. want to set it to a non-@code{nil} value in unusual circumstances. In
  926. that case, Emacs does not divide the Comint buffer into fields, so the
  927. general motion commands behave as they normally do in buffers without
  928. special text properties. However, you can use the paragraph motion
  929. commands to conveniently navigate the buffer (@pxref{Paragraphs}); in
  930. Shell mode, Emacs uses @code{shell-prompt-pattern} as paragraph
  931. boundaries.
  932. @node Shell History
  933. @subsection Shell Command History
  934. Shell buffers support three ways of repeating earlier commands. You
  935. can use keys like those used for the minibuffer history; these work
  936. much as they do in the minibuffer, inserting text from prior commands
  937. while point remains always at the end of the buffer. You can move
  938. through the buffer to previous inputs in their original place, then
  939. resubmit them or copy them to the end. Or you can use a
  940. @samp{!}-style history reference.
  941. @menu
  942. * Ring: Shell Ring. Fetching commands from the history list.
  943. * Copy: Shell History Copying. Moving to a command and then copying it.
  944. * History References:: Expanding @samp{!}-style history references.
  945. @end menu
  946. @node Shell Ring
  947. @subsubsection Shell History Ring
  948. @table @kbd
  949. @findex comint-previous-input
  950. @kindex M-p @r{(Shell mode)}
  951. @item M-p
  952. @itemx C-@key{UP}
  953. Fetch the next earlier old shell command.
  954. @kindex M-n @r{(Shell mode)}
  955. @findex comint-next-input
  956. @item M-n
  957. @itemx C-@key{DOWN}
  958. Fetch the next later old shell command.
  959. @kindex M-r @r{(Shell mode)}
  960. @findex comint-history-isearch-backward-regexp
  961. @item M-r
  962. Begin an incremental regexp search of old shell commands.
  963. @item C-c C-x
  964. @kindex C-c C-x @r{(Shell mode)}
  965. @findex comint-get-next-from-history
  966. Fetch the next subsequent command from the history.
  967. @item C-c .
  968. @kindex C-c . @r{(Shell mode)}
  969. @findex comint-input-previous-argument
  970. Fetch one argument from an old shell command.
  971. @item C-c C-l
  972. @kindex C-c C-l @r{(Shell mode)}
  973. @findex comint-dynamic-list-input-ring
  974. Display the buffer's history of shell commands in another window
  975. (@code{comint-dynamic-list-input-ring}).
  976. @end table
  977. Shell buffers provide a history of previously entered shell
  978. commands. To reuse shell commands from the history, use the editing
  979. commands @kbd{M-p}, @kbd{M-n}, @kbd{M-r} and @kbd{M-s}. These work
  980. just like the minibuffer history commands (@pxref{Minibuffer
  981. History}), except that they operate within the Shell buffer rather
  982. than the minibuffer.
  983. @kbd{M-p} fetches an earlier shell command to the end of the shell
  984. buffer. Successive use of @kbd{M-p} fetches successively earlier
  985. shell commands, each replacing any text that was already present as
  986. potential shell input. @kbd{M-n} does likewise except that it finds
  987. successively more recent shell commands from the buffer.
  988. @kbd{C-@key{UP}} works like @kbd{M-p}, and @kbd{C-@key{DOWN}} like
  989. @kbd{M-n}.
  990. The history search command @kbd{M-r} begins an incremental regular
  991. expression search of previous shell commands. After typing @kbd{M-r},
  992. start typing the desired string or regular expression; the last
  993. matching shell command will be displayed in the current line.
  994. Incremental search commands have their usual effects---for instance,
  995. @kbd{C-s} and @kbd{C-r} search forward and backward for the next match
  996. (@pxref{Incremental Search}). When you find the desired input, type
  997. @key{RET} to terminate the search. This puts the input in the command
  998. line. Any partial input you were composing before navigating the
  999. history list is restored when you go to the beginning or end of the
  1000. history ring.
  1001. Often it is useful to reexecute several successive shell commands that
  1002. were previously executed in sequence. To do this, first find and
  1003. reexecute the first command of the sequence. Then type @kbd{C-c C-x};
  1004. that will fetch the following command---the one that follows the command
  1005. you just repeated. Then type @key{RET} to reexecute this command. You
  1006. can reexecute several successive commands by typing @kbd{C-c C-x
  1007. @key{RET}} over and over.
  1008. The command @kbd{C-c .}@: (@code{comint-input-previous-argument})
  1009. copies an individual argument from a previous command, like
  1010. @kbd{@key{ESC} .} in Bash. The simplest use copies the last argument from the
  1011. previous shell command. With a prefix argument @var{n}, it copies the
  1012. @var{n}th argument instead. Repeating @kbd{C-c .} copies from an
  1013. earlier shell command instead, always using the same value of @var{n}
  1014. (don't give a prefix argument when you repeat the @kbd{C-c .}
  1015. command).
  1016. These commands get the text of previous shell commands from a special
  1017. history list, not from the shell buffer itself. Thus, editing the shell
  1018. buffer, or even killing large parts of it, does not affect the history
  1019. that these commands access.
  1020. @vindex shell-input-ring-file-name
  1021. Some shells store their command histories in files so that you can
  1022. refer to commands from previous shell sessions. Emacs reads
  1023. the command history file for your chosen shell, to initialize its own
  1024. command history. The file name is @file{~/.bash_history} for bash,
  1025. @file{~/.sh_history} for ksh, and @file{~/.history} for other shells.
  1026. @node Shell History Copying
  1027. @subsubsection Shell History Copying
  1028. @table @kbd
  1029. @kindex C-c C-p @r{(Shell mode)}
  1030. @findex comint-previous-prompt
  1031. @item C-c C-p
  1032. Move point to the previous prompt (@code{comint-previous-prompt}).
  1033. @kindex C-c C-n @r{(Shell mode)}
  1034. @findex comint-next-prompt
  1035. @item C-c C-n
  1036. Move point to the following prompt (@code{comint-next-prompt}).
  1037. @kindex C-c RET @r{(Shell mode)}
  1038. @findex comint-copy-old-input
  1039. @item C-c @key{RET}
  1040. Copy the input command at point, inserting the copy at the end of the
  1041. buffer (@code{comint-copy-old-input}). This is useful if you move
  1042. point back to a previous command. After you copy the command, you can
  1043. submit the copy as input with @key{RET}. If you wish, you can edit
  1044. the copy before resubmitting it. If you use this command on an output
  1045. line, it copies that line to the end of the buffer.
  1046. @item mouse-2
  1047. If @code{comint-use-prompt-regexp} is @code{nil} (the default), copy
  1048. the old input command that you click on, inserting the copy at the end
  1049. of the buffer (@code{comint-insert-input}). If
  1050. @code{comint-use-prompt-regexp} is non-@code{nil}, or if the click is
  1051. not over old input, just yank as usual.
  1052. @end table
  1053. Moving to a previous input and then copying it with @kbd{C-c
  1054. @key{RET}} or @kbd{mouse-2} produces the same results---the same
  1055. buffer contents---that you would get by using @kbd{M-p} enough times
  1056. to fetch that previous input from the history list. However, @kbd{C-c
  1057. @key{RET}} copies the text from the buffer, which can be different
  1058. from what is in the history list if you edit the input text in the
  1059. buffer after it has been sent.
  1060. @node History References
  1061. @subsubsection Shell History References
  1062. @cindex history reference
  1063. Various shells including csh and bash support @dfn{history
  1064. references} that begin with @samp{!} and @samp{^}. Shell mode
  1065. recognizes these constructs, and can perform the history substitution
  1066. for you.
  1067. If you insert a history reference and type @key{TAB}, this searches
  1068. the input history for a matching command, performs substitution if
  1069. necessary, and places the result in the buffer in place of the history
  1070. reference. For example, you can fetch the most recent command
  1071. beginning with @samp{mv} with @kbd{! m v @key{TAB}}. You can edit the
  1072. command if you wish, and then resubmit the command to the shell by
  1073. typing @key{RET}.
  1074. @vindex comint-input-autoexpand
  1075. @findex comint-magic-space
  1076. Shell mode can optionally expand history references in the buffer
  1077. when you send them to the shell. To request this, set the variable
  1078. @code{comint-input-autoexpand} to @code{input}. You can make
  1079. @key{SPC} perform history expansion by binding @key{SPC} to the
  1080. command @code{comint-magic-space}.
  1081. Shell mode recognizes history references when they follow a prompt.
  1082. @xref{Shell Prompts}, for how Shell mode recognizes prompts.
  1083. @node Directory Tracking
  1084. @subsection Directory Tracking
  1085. @cindex directory tracking
  1086. @vindex shell-pushd-regexp
  1087. @vindex shell-popd-regexp
  1088. @vindex shell-cd-regexp
  1089. Shell mode keeps track of @samp{cd}, @samp{pushd} and @samp{popd}
  1090. commands given to the subshell, in order to keep the Shell buffer's
  1091. default directory (@pxref{File Names}) the same as the shell's working
  1092. directory. It recognizes these commands by examining lines of input
  1093. that you send.
  1094. If you use aliases for these commands, you can tell Emacs to
  1095. recognize them also, by setting the variables
  1096. @code{shell-pushd-regexp}, @code{shell-popd-regexp}, and
  1097. @code{shell-cd-regexp} to the appropriate regular expressions
  1098. (@pxref{Regexps}). For example, if @code{shell-pushd-regexp} matches
  1099. the beginning of a shell command line, that line is regarded as a
  1100. @code{pushd} command. These commands are recognized only at the
  1101. beginning of a shell command line.
  1102. @findex dirs
  1103. If Emacs gets confused about changes in the working directory of the
  1104. subshell, type @kbd{M-x dirs}. This command asks the shell for its
  1105. working directory and updates the default directory accordingly. It
  1106. works for shells that support the most common command syntax, but may
  1107. not work for unusual shells.
  1108. @findex dirtrack-mode
  1109. @cindex Dirtrack mode
  1110. @cindex mode, Dirtrack
  1111. @vindex dirtrack-list
  1112. You can also use Dirtrack mode, a buffer-local minor mode that
  1113. implements an alternative method of tracking the shell's working
  1114. directory. To use this method, your shell prompt must contain the
  1115. working directory at all times, and you must supply a regular
  1116. expression for recognizing which part of the prompt contains the
  1117. working directory; see the documentation of the variable
  1118. @code{dirtrack-list} for details. To use Dirtrack mode, type @kbd{M-x
  1119. dirtrack-mode} in the Shell buffer, or add @code{dirtrack-mode} to
  1120. @code{shell-mode-hook} (@pxref{Hooks}).
  1121. @node Shell Options
  1122. @subsection Shell Mode Options
  1123. @vindex comint-scroll-to-bottom-on-input
  1124. If the variable @code{comint-scroll-to-bottom-on-input} is
  1125. non-@code{nil}, insertion and yank commands scroll the selected window
  1126. to the bottom before inserting. The default is @code{nil}.
  1127. @vindex comint-scroll-show-maximum-output
  1128. If @code{comint-scroll-show-maximum-output} is non-@code{nil}, then
  1129. arrival of output when point is at the end tries to scroll the last
  1130. line of text to the bottom line of the window, showing as much useful
  1131. text as possible. (This mimics the scrolling behavior of most
  1132. terminals.) The default is @code{t}.
  1133. @vindex comint-move-point-for-output
  1134. By setting @code{comint-move-point-for-output}, you can opt for
  1135. having point jump to the end of the buffer whenever output arrives---no
  1136. matter where in the buffer point was before. If the value is
  1137. @code{this}, point jumps in the selected window. If the value is
  1138. @code{all}, point jumps in each window that shows the Comint buffer. If
  1139. the value is @code{other}, point jumps in all nonselected windows that
  1140. show the current buffer. The default value is @code{nil}, which means
  1141. point does not jump to the end.
  1142. @vindex comint-prompt-read-only
  1143. If you set @code{comint-prompt-read-only}, the prompts in the Comint
  1144. buffer are read-only.
  1145. @vindex comint-input-ignoredups
  1146. The variable @code{comint-input-ignoredups} controls whether successive
  1147. identical inputs are stored in the input history. A non-@code{nil}
  1148. value means to omit an input that is the same as the previous input.
  1149. The default is @code{nil}, which means to store each input even if it is
  1150. equal to the previous input.
  1151. @vindex comint-completion-addsuffix
  1152. @vindex comint-completion-recexact
  1153. @vindex comint-completion-autolist
  1154. Three variables customize file name completion. The variable
  1155. @code{comint-completion-addsuffix} controls whether completion inserts a
  1156. space or a slash to indicate a fully completed file or directory name
  1157. (non-@code{nil} means do insert a space or slash).
  1158. @code{comint-completion-recexact}, if non-@code{nil}, directs @key{TAB}
  1159. to choose the shortest possible completion if the usual Emacs completion
  1160. algorithm cannot add even a single character.
  1161. @code{comint-completion-autolist}, if non-@code{nil}, says to list all
  1162. the possible completions whenever completion is not exact.
  1163. @vindex shell-completion-execonly
  1164. Command completion normally considers only executable files.
  1165. If you set @code{shell-completion-execonly} to @code{nil},
  1166. it considers nonexecutable files as well.
  1167. @vindex shell-completion-fignore
  1168. @vindex comint-completion-fignore
  1169. The variable @code{shell-completion-fignore} specifies a list of file
  1170. name extensions to ignore in Shell mode completion. The default
  1171. setting is @code{nil}, but some users prefer @code{("~" "#" "%")} to
  1172. ignore file names ending in @samp{~}, @samp{#} or @samp{%}. Other
  1173. related Comint modes use the variable @code{comint-completion-fignore}
  1174. instead.
  1175. @findex shell-dynamic-complete-command
  1176. Some implementation details of the shell command completion may also be found
  1177. in the lisp documentation of the @code{shell-dynamic-complete-command}
  1178. function.
  1179. @findex shell-pushd-tohome
  1180. @findex shell-pushd-dextract
  1181. @findex shell-pushd-dunique
  1182. You can configure the behavior of @samp{pushd}. Variables control
  1183. whether @samp{pushd} behaves like @samp{cd} if no argument is given
  1184. (@code{shell-pushd-tohome}), pop rather than rotate with a numeric
  1185. argument (@code{shell-pushd-dextract}), and only add directories to the
  1186. directory stack if they are not already on it
  1187. (@code{shell-pushd-dunique}). The values you choose should match the
  1188. underlying shell, of course.
  1189. @node Terminal emulator
  1190. @subsection Emacs Terminal Emulator
  1191. @findex term
  1192. To run a subshell in a text terminal emulator, use @kbd{M-x term}.
  1193. This creates (or reuses) a buffer named @file{*terminal*}, and runs a
  1194. subshell with input coming from your keyboard, and output going to
  1195. that buffer.
  1196. @cindex line mode @r{(terminal emulator)}
  1197. @cindex char mode @r{(terminal emulator)}
  1198. The terminal emulator uses Term mode, which has two input modes. In
  1199. @dfn{line mode}, Term basically acts like Shell mode (@pxref{Shell
  1200. Mode}). In @dfn{char mode}, each character is sent directly to the
  1201. subshell, as terminal input; the sole exception is the terminal escape
  1202. character, which by default is @kbd{C-c} (@pxref{Term Mode}). Any
  1203. echoing of your input is the responsibility of the subshell; any
  1204. terminal output from the subshell goes into the buffer, advancing
  1205. point.
  1206. Some programs (such as Emacs itself) need to control the appearance
  1207. of the terminal screen in detail. They do this by emitting special
  1208. control codes. Term mode recognizes and handles ANSI-standard
  1209. VT100-style escape sequences, which are accepted by most modern
  1210. terminals, including @command{xterm}. (Hence, you can actually run
  1211. Emacs inside an Emacs Term window.)
  1212. The @code{term} face specifies the default appearance of text
  1213. in the terminal emulator (the default is the same appearance as the
  1214. @code{default} face). When terminal control codes are used to change
  1215. the appearance of text, these are represented in the terminal emulator
  1216. by the faces @code{term-color-black}, @code{term-color-red},
  1217. @code{term-color-green}, @code{term-color-yellow}
  1218. @code{term-color-blue}, @code{term-color-magenta},
  1219. @code{term-color-cyan}, @code{term-color-white},
  1220. @code{term-color-underline}, and @code{term-color-bold}.
  1221. @xref{Faces}.
  1222. You can also Term mode to communicate with a device connected to a
  1223. serial port. @xref{Serial Terminal}.
  1224. The file name used to load the subshell is determined the same way
  1225. as for Shell mode. To make multiple terminal emulators, rename the
  1226. buffer @file{*terminal*} to something different using @kbd{M-x
  1227. rename-uniquely}, just as with Shell mode.
  1228. Unlike Shell mode, Term mode does not track the current directory by
  1229. examining your input. But some shells can tell Term what the current
  1230. directory is. This is done automatically by @code{bash} version 1.15
  1231. and later.
  1232. @node Term Mode
  1233. @subsection Term Mode
  1234. @cindex Term mode
  1235. @cindex mode, Term
  1236. The terminal emulator uses Term mode, which has two input modes. In
  1237. line mode, Term basically acts like Shell mode (@pxref{Shell Mode}).
  1238. In char mode, each character is sent directly to the subshell, except
  1239. for the Term escape character, normally @kbd{C-c}.
  1240. To switch between line and char mode, use these commands:
  1241. @table @kbd
  1242. @kindex C-c C-j @r{(Term mode)}
  1243. @findex term-line-mode
  1244. @item C-c C-j
  1245. Switch to line mode (@code{term-line-mode}). Do nothing if already in
  1246. line mode.
  1247. @kindex C-c C-k @r{(Term mode)}
  1248. @findex term-char-mode
  1249. @item C-c C-k
  1250. Switch to char mode (@code{term-char-mode}). Do nothing if already in
  1251. char mode.
  1252. @end table
  1253. The following commands are only available in char mode:
  1254. @table @kbd
  1255. @item C-c C-c
  1256. Send a literal @kbd{C-c} to the sub-shell.
  1257. @item C-c @var{char}
  1258. This is equivalent to @kbd{C-x @var{char}} in normal Emacs. For
  1259. example, @kbd{C-c o} invokes the global binding of @kbd{C-x o}, which
  1260. is normally @samp{other-window}.
  1261. @end table
  1262. @cindex paging in Term mode
  1263. Term mode has a page-at-a-time feature. When enabled, it makes
  1264. output pause at the end of each screenful:
  1265. @table @kbd
  1266. @kindex C-c C-q @r{(Term mode)}
  1267. @findex term-pager-toggle
  1268. @item C-c C-q
  1269. Toggle the page-at-a-time feature. This command works in both line
  1270. and char modes. When the feature is enabled, the mode-line displays
  1271. the word @samp{page}, and each time Term receives more than a
  1272. screenful of output, it pauses and displays @samp{**MORE**} in the
  1273. mode-line. Type @key{SPC} to display the next screenful of output, or
  1274. @kbd{?} to see your other options. The interface is similar to the
  1275. @code{more} program.
  1276. @end table
  1277. @node Remote Host
  1278. @subsection Remote Host Shell
  1279. @cindex remote host
  1280. @cindex connecting to remote host
  1281. @cindex Telnet
  1282. @cindex Rlogin
  1283. You can login to a remote computer, using whatever commands you
  1284. would from a regular terminal (e.g., using the @code{telnet} or
  1285. @code{rlogin} commands), from a Term window.
  1286. A program that asks you for a password will normally suppress
  1287. echoing of the password, so the password will not show up in the
  1288. buffer. This will happen just as if you were using a real terminal,
  1289. if the buffer is in char mode. If it is in line mode, the password is
  1290. temporarily visible, but will be erased when you hit return. (This
  1291. happens automatically; there is no special password processing.)
  1292. When you log in to a different machine, you need to specify the type
  1293. of terminal you're using, by setting the @env{TERM} environment
  1294. variable in the environment for the remote login command. (If you use
  1295. bash, you do that by writing the variable assignment before the remote
  1296. login command, without a separating comma.) Terminal types
  1297. @samp{ansi} or @samp{vt100} will work on most systems.
  1298. @node Serial Terminal
  1299. @subsection Serial Terminal
  1300. @cindex terminal, serial
  1301. @findex serial-term
  1302. If you have a device connected to a serial port of your computer,
  1303. you can communicate with it by typing @kbd{M-x serial-term}. This
  1304. command asks for a serial port name and speed, and switches to a new
  1305. Term mode buffer. Emacs communicates with the serial device through
  1306. this buffer just like it does with a terminal in ordinary Term mode.
  1307. The speed of the serial port is measured in bits per second. The
  1308. most common speed is 9600 bits per second. You can change the speed
  1309. interactively by clicking on the mode line.
  1310. A serial port can be configured even more by clicking on @samp{8N1} in
  1311. the mode line. By default, a serial port is configured as @samp{8N1},
  1312. which means that each byte consists of 8 data bits, No parity check
  1313. bit, and 1 stopbit.
  1314. If the speed or the configuration is wrong, you cannot communicate
  1315. with your device and will probably only see garbage output in the
  1316. window.
  1317. @node Emacs Server
  1318. @section Using Emacs as a Server
  1319. @pindex emacsclient
  1320. @cindex Emacs as a server
  1321. @cindex server, using Emacs as
  1322. @cindex @env{EDITOR} environment variable
  1323. Various programs can invoke your choice of editor to edit a
  1324. particular piece of text. For instance, version control programs
  1325. invoke an editor to enter version control logs (@pxref{Version
  1326. Control}), and the Unix @command{mail} utility invokes an editor to
  1327. enter a message to send. By convention, your choice of editor is
  1328. specified by the environment variable @env{EDITOR}. If you set
  1329. @env{EDITOR} to @samp{emacs}, Emacs would be invoked, but in an
  1330. inconvenient way---by starting a new Emacs process. This is
  1331. inconvenient because the new Emacs process doesn't share buffers, a
  1332. command history, or other kinds of information with any existing Emacs
  1333. process.
  1334. You can solve this problem by setting up Emacs as an @dfn{edit
  1335. server}, so that it ``listens'' for external edit requests and acts
  1336. accordingly. There are various ways to start an Emacs server:
  1337. @itemize
  1338. @findex server-start
  1339. @item
  1340. Run the command @code{server-start} in an existing Emacs process:
  1341. either type @kbd{M-x server-start}, or put the expression
  1342. @code{(server-start)} in your init file (@pxref{Init File}). The
  1343. existing Emacs process is the server; when you exit Emacs, the server
  1344. dies with the Emacs process.
  1345. @cindex daemon, Emacs
  1346. @item
  1347. Run Emacs as a @dfn{daemon}, using one of the @samp{--daemon} command-line
  1348. options. @xref{Initial Options}. When Emacs is started this way, it
  1349. calls @code{server-start} after initialization and does not open an
  1350. initial frame. It then waits for edit requests from clients.
  1351. @cindex systemd unit file
  1352. @item
  1353. If your operating system uses @command{systemd} to manage startup,
  1354. you can automatically start Emacs in daemon mode when you login
  1355. using the supplied @dfn{systemd unit file}. To activate this:
  1356. @example
  1357. systemctl --user enable emacs
  1358. @end example
  1359. (If your Emacs was installed into a non-standard location, you may
  1360. need to copy the @file{emacs.service} file to a standard directory
  1361. such as @file{~/.config/systemd/user/}.)
  1362. @cindex socket activation, systemd, Emacs
  1363. @item
  1364. An external process can invoke the Emacs server when a connection
  1365. event occurs upon a specified socket and pass the socket to the new
  1366. Emacs server process. An instance of this is the socket functionality
  1367. of @command{systemd}: the @command{systemd} service creates a socket and
  1368. listens for connections on it; when @command{emacsclient} connects to
  1369. it for the first time, @command{systemd} can launch the Emacs server
  1370. and hand over the socket to it for servicing @command{emacsclient}
  1371. connections. A setup to use this functionality could be:
  1372. @file{~/.config/systemd/user/emacs.socket}:
  1373. @example
  1374. [Socket]
  1375. ListenStream=/path/to/.emacs.socket
  1376. [Install]
  1377. WantedBy=sockets.target
  1378. @end example
  1379. (The @file{emacs.service} file described above must also be installed.)
  1380. The @code{ListenStream} path will be the path that Emacs listens for
  1381. connections from @command{emacsclient}; this is a file of your choice.
  1382. @end itemize
  1383. @cindex @env{TEXEDIT} environment variable
  1384. Once an Emacs server is started, you can use a shell
  1385. command called @command{emacsclient} to connect to the Emacs process
  1386. and tell it to visit a file. You can then set the @env{EDITOR}
  1387. environment variable to @samp{emacsclient}, so that external programs
  1388. will use the existing Emacs process for editing.@footnote{Some
  1389. programs use a different environment variable; for example, to make
  1390. @TeX{} use @samp{emacsclient}, set the @env{TEXEDIT} environment
  1391. variable to @samp{emacsclient +%d %s}.}
  1392. @vindex server-name
  1393. You can run multiple Emacs servers on the same machine by giving
  1394. each one a unique @dfn{server name}, using the variable
  1395. @code{server-name}. For example, @kbd{M-x set-variable @key{RET}
  1396. server-name @key{RET} "foo" @key{RET}} sets the server name to
  1397. @samp{foo}. The @code{emacsclient} program can specify a server by
  1398. name, using the @samp{-s} option (@pxref{emacsclient Options}).
  1399. If you want to run multiple Emacs daemons (@pxref{Initial Options}),
  1400. you can give each daemon its own server name like this:
  1401. @example
  1402. emacs --eval "(setq server-name \"foo\")" --daemon
  1403. @end example
  1404. @findex server-eval-at
  1405. If you have defined a server by a unique server name, it is possible
  1406. to connect to the server from another Emacs instance and evaluate Lisp
  1407. expressions on the server, using the @code{server-eval-at} function.
  1408. For instance, @code{(server-eval-at "foo" '(+ 1 2))} evaluates the
  1409. expression @code{(+ 1 2)} on the @samp{foo} server, and returns
  1410. @code{3}. (If there is no server with that name, an error is
  1411. signaled.) Currently, this feature is mainly useful for developers.
  1412. @menu
  1413. * TCP Emacs server:: Listening to a TCP socket.
  1414. * Invoking emacsclient:: Connecting to the Emacs server.
  1415. * emacsclient Options:: Emacs client startup options.
  1416. @end menu
  1417. @node TCP Emacs server
  1418. @subsection TCP Emacs server
  1419. @cindex TCP Emacs server
  1420. @vindex server-use-tcp
  1421. An Emacs server usually listens to connections on a local Unix
  1422. domain socket. Some operating systems, such as MS-Windows, do not
  1423. support local sockets; in that case, the server uses TCP sockets
  1424. instead. In some cases it is useful to have the server listen on a
  1425. TCP socket even if local sockets are supported, e.g., if you need to
  1426. contact the Emacs server from a remote machine. You can set
  1427. @code{server-use-tcp} to non-@code{nil} to have Emacs listen on a TCP
  1428. socket instead of a local socket. This is the default if your OS does
  1429. not support local sockets.
  1430. @vindex server-host
  1431. @vindex server-port
  1432. If the Emacs server is set to use TCP, it will by default listen to
  1433. a random port on the localhost interface. This can be changed to
  1434. another interface and/or a fixed port using the variables
  1435. @code{server-host} and @code{server-port}.
  1436. @vindex server-auth-key
  1437. A TCP socket is not subject to file system permissions. To retain
  1438. some control over which users can talk to an Emacs server over TCP
  1439. sockets, the @command{emacsclient} program must send an authorization
  1440. key to the server. This key is normally randomly generated by the
  1441. Emacs server. This is the recommended mode of operation.
  1442. @findex server-generate-key
  1443. If needed, you can set the authorization key to a static value by
  1444. setting the @code{server-auth-key} variable. The key must consist of
  1445. 64 ASCII printable characters except for space (this means characters
  1446. from @samp{!} to @samp{~}, or from decimal code 33 to 126). You can
  1447. use @kbd{M-x server-generate-key} to get a random key.
  1448. @vindex server-auth-dir
  1449. @cindex server file
  1450. When you start a TCP Emacs server, Emacs creates a @dfn{server file}
  1451. containing the TCP information to be used by @command{emacsclient} to
  1452. connect to the server. The variable @code{server-auth-dir} specifies
  1453. the directory containing the server file; by default, this is
  1454. @file{~/.emacs.d/server/}. In the absence of a local socket with file
  1455. permissions, the permissions of this directory determine which users
  1456. can have their @command{emacsclient} processes talk to the Emacs
  1457. server.
  1458. @vindex EMACS_SERVER_FILE@r{, environment variable}
  1459. To tell @command{emacsclient} to connect to the server over TCP with
  1460. a specific server file, use the @samp{-f} or @samp{--server-file}
  1461. option, or set the @env{EMACS_SERVER_FILE} environment variable
  1462. (@pxref{emacsclient Options}). If @code{server-auth-dir} is set to a
  1463. non-standard value, @command{emacsclient} needs an absolute file name
  1464. to the server file, as the default @code{server-auth-dir} is
  1465. hard-coded in @command{emacsclient} to be used as the directory for
  1466. resolving relative filenames.
  1467. @node Invoking emacsclient
  1468. @subsection Invoking @code{emacsclient}
  1469. @cindex @code{emacsclient} invocation
  1470. The simplest way to use the @command{emacsclient} program is to run
  1471. the shell command @samp{emacsclient @var{file}}, where @var{file} is a
  1472. file name. This connects to an Emacs server, and tells that Emacs
  1473. process to visit @var{file} in one of its existing frames---either a
  1474. graphical frame, or one in a text terminal (@pxref{Frames}). You
  1475. can then select that frame to begin editing.
  1476. If there is no Emacs server, the @command{emacsclient} program halts
  1477. with an error message. If the Emacs process has no existing
  1478. frame---which can happen if it was started as a daemon (@pxref{Emacs
  1479. Server})---then Emacs opens a frame on the terminal in which you
  1480. called @command{emacsclient}.
  1481. You can also force @command{emacsclient} to open a new frame on a
  1482. graphical display, or on a text terminal, using the @samp{-c} and
  1483. @samp{-t} options. @xref{emacsclient Options}.
  1484. If you are running on a single text terminal, you can switch between
  1485. @command{emacsclient}'s shell and the Emacs server using one of two
  1486. methods: (i) run the Emacs server and @command{emacsclient} on
  1487. different virtual terminals, and switch to the Emacs server's virtual
  1488. terminal after calling @command{emacsclient}; or (ii) call
  1489. @command{emacsclient} from within the Emacs server itself, using Shell
  1490. mode (@pxref{Interactive Shell}) or Term mode (@pxref{Term Mode});
  1491. @code{emacsclient} blocks only the subshell under Emacs, and you can
  1492. still use Emacs to edit the file.
  1493. @kindex C-x #
  1494. @findex server-edit
  1495. When you finish editing @var{file} in the Emacs server, type
  1496. @kbd{C-x #} (@code{server-edit}) in its buffer. This saves the file
  1497. and sends a message back to the @command{emacsclient} program, telling
  1498. it to exit. Programs that use @env{EDITOR} usually wait for the
  1499. editor---in this case @command{emacsclient}---to exit before doing
  1500. something else.
  1501. You can also call @command{emacsclient} with multiple file name
  1502. arguments: @samp{emacsclient @var{file1} @var{file2} ...} tells the
  1503. Emacs server to visit @var{file1}, @var{file2}, and so forth. Emacs
  1504. selects the buffer visiting @var{file1}, and buries the other buffers
  1505. at the bottom of the buffer list (@pxref{Buffers}). The
  1506. @command{emacsclient} program exits once all the specified files are
  1507. finished (i.e., once you have typed @kbd{C-x #} in each server
  1508. buffer).
  1509. @vindex server-kill-new-buffers
  1510. @vindex server-temp-file-regexp
  1511. Finishing with a server buffer also kills the buffer, unless it
  1512. already existed in the Emacs session before the server was asked to
  1513. create it. However, if you set @code{server-kill-new-buffers} to
  1514. @code{nil}, then a different criterion is used: finishing with a
  1515. server buffer kills it if the file name matches the regular expression
  1516. @code{server-temp-file-regexp}. This is set up to distinguish certain
  1517. temporary files.
  1518. Each @kbd{C-x #} checks for other pending external requests to edit
  1519. various files, and selects the next such file. You can switch to a
  1520. server buffer manually if you wish; you don't have to arrive at it
  1521. with @kbd{C-x #}. But @kbd{C-x #} is the way to tell
  1522. @command{emacsclient} that you are finished.
  1523. @vindex server-window
  1524. If you set the value of the variable @code{server-window} to a
  1525. window or a frame, @kbd{C-x #} always displays the next server buffer
  1526. in that window or in that frame.
  1527. @node emacsclient Options
  1528. @subsection @code{emacsclient} Options
  1529. @cindex @code{emacsclient} options
  1530. You can pass some optional arguments to the @command{emacsclient}
  1531. program, such as:
  1532. @example
  1533. emacsclient -c +12 @var{file1} +4:3 @var{file2}
  1534. @end example
  1535. @noindent
  1536. The @samp{+@var{line}} or @samp{+@var{line}:@var{column}} arguments
  1537. specify line numbers, or line and column numbers, for the next file
  1538. argument. These behave like the command line arguments for Emacs
  1539. itself. @xref{Action Arguments}.
  1540. The other optional arguments recognized by @command{emacsclient} are
  1541. listed below:
  1542. @table @samp
  1543. @item -a @var{command}
  1544. @itemx --alternate-editor=@var{command}
  1545. Specify a command to run if @code{emacsclient} fails to contact Emacs.
  1546. This is useful when running @code{emacsclient} in a script.
  1547. As a special exception, if @var{command} is the empty string, then
  1548. @code{emacsclient} starts Emacs in daemon mode (as @command{emacs
  1549. --daemon}) and then tries connecting again.
  1550. @cindex @env{ALTERNATE_EDITOR} environment variable
  1551. The environment variable @env{ALTERNATE_EDITOR} has the same effect as
  1552. the @samp{-a} option. If both are present, the latter takes
  1553. precedence.
  1554. @cindex client frame
  1555. @item -c
  1556. @itemx --create-frame
  1557. Create a new graphical @dfn{client frame}, instead of using an
  1558. existing Emacs frame. See below for the special behavior of @kbd{C-x
  1559. C-c} in a client frame. If Emacs cannot create a new graphical frame
  1560. (e.g., if it cannot connect to the X server), it tries to create a
  1561. text terminal client frame, as though you had supplied the @samp{-t}
  1562. option instead.
  1563. On MS-Windows, a single Emacs session cannot display frames on both
  1564. graphical and text terminals, nor on multiple text terminals. Thus,
  1565. if the Emacs server is running on a text terminal, the @samp{-c}
  1566. option, like the @samp{-t} option, creates a new frame in the server's
  1567. current text terminal. @xref{Windows Startup}.
  1568. If you omit a filename argument while supplying the @samp{-c} option,
  1569. the new frame displays the @file{*scratch*} buffer by default. You
  1570. can customize this behavior with the variable @code{initial-buffer-choice}
  1571. (@pxref{Entering Emacs}).
  1572. @item -F @var{alist}
  1573. @itemx --frame-parameters=@var{alist}
  1574. Set the parameters for a newly-created graphical frame
  1575. (@pxref{Frame Parameters}).
  1576. @item -d @var{display}
  1577. @itemx --display=@var{display}
  1578. Tell Emacs to open the given files on the X display @var{display}
  1579. (assuming there is more than one X display available).
  1580. @item -e
  1581. @itemx --eval
  1582. Tell Emacs to evaluate some Emacs Lisp code, instead of visiting some
  1583. files. When this option is given, the arguments to
  1584. @command{emacsclient} are interpreted as a list of expressions to
  1585. evaluate, @emph{not} as a list of files to visit.
  1586. @item -f @var{server-file}
  1587. @itemx --server-file=@var{server-file}
  1588. Specify a server file (@pxref{TCP Emacs server}) for connecting to an
  1589. Emacs server via TCP. Alternatively, you can set the
  1590. @env{EMACS_SERVER_FILE} environment variable to point to the server
  1591. file.
  1592. An Emacs server usually uses a local socket to listen for connections,
  1593. but also supports connections over TCP. To connect to a TCP Emacs
  1594. server, @command{emacsclient} needs to read a @dfn{server file}
  1595. containing the connection details of the Emacs server. The name of
  1596. this file is specified with this option, either as a file name
  1597. relative to @file{~/.emacs.d/server} or as an absolute file name.
  1598. @xref{TCP Emacs server}.
  1599. @item -n
  1600. @itemx --no-wait
  1601. Let @command{emacsclient} exit immediately, instead of waiting until
  1602. all server buffers are finished. You can take as long as you like to
  1603. edit the server buffers within Emacs, and they are @emph{not} killed
  1604. when you type @kbd{C-x #} in them.
  1605. @item --parent-id @var{id}
  1606. Open an @command{emacsclient} frame as a client frame in the parent X
  1607. window with id @var{id}, via the XEmbed protocol. Currently, this
  1608. option is mainly useful for developers.
  1609. @item -q
  1610. @itemx --quiet
  1611. Do not let @command{emacsclient} display messages about waiting for
  1612. Emacs or connecting to remote server sockets.
  1613. @item -u
  1614. @itemx --suppress-output
  1615. Do not let @command{emacsclient} display results returned from the
  1616. server. Mostly useful in combination with @samp{-e} when the
  1617. evaluation performed is for side-effect rather than result.
  1618. @item -s @var{server-name}
  1619. @itemx --socket-name=@var{server-name}
  1620. Connect to the Emacs server named @var{server-name}. The server name
  1621. is given by the variable @code{server-name} on the Emacs server. If
  1622. this option is omitted, @command{emacsclient} connects to the first
  1623. server it finds. (This option is not supported on MS-Windows.)
  1624. @item -t
  1625. @itemx --tty
  1626. @itemx -nw
  1627. Create a new client frame on the current text terminal, instead of
  1628. using an existing Emacs frame. This behaves just like the @samp{-c}
  1629. option, described above, except that it creates a text terminal frame
  1630. (@pxref{Non-Window Terminals}).
  1631. On MS-Windows, @samp{-t} behaves just like @samp{-c} if the Emacs
  1632. server is using the graphical display, but if the Emacs server is
  1633. running on a text terminal, it creates a new frame in the current text
  1634. terminal.
  1635. @item -T @var{tramp-prefix}
  1636. @itemx --tramp-prefix=@var{tramp-prefix}
  1637. Set the prefix to add to filenames for Emacs to locate files on remote
  1638. machines using TRAMP (@pxref{Top, The Tramp Manual,, tramp, The Tramp
  1639. Manual}). This is mostly useful in combination with using the Emacs
  1640. server over TCP (@pxref{TCP Emacs server}). By ssh-forwarding the
  1641. listening port and making the @var{server-file} available on a remote
  1642. machine, programs on the remote machine can use @command{emacsclient}
  1643. as the value for the @env{EDITOR} and similar environment variables,
  1644. but instead of talking to an Emacs server on the remote machine, the
  1645. files will be visited in the local Emacs session using TRAMP.
  1646. @vindex EMACSCLIENT_TRAMP@r{, environment variable}
  1647. Setting the environment variable @env{EMACSCLIENT_TRAMP} has the same
  1648. effect as using the @samp{-T} option. If both are specified, the
  1649. command-line option takes precedence.
  1650. For example, assume two hosts, @samp{local} and @samp{remote}, and
  1651. that the local Emacs listens on tcp port 12345. Assume further that
  1652. @file{/home} is on a shared file system, so that the server file
  1653. @file{~/.emacs.d/server/server} is readable on both hosts.
  1654. @example
  1655. local$ ssh -R12345:localhost:12345 remote
  1656. remote$ export EDITOR="emacsclient \
  1657. --server-file=server \
  1658. --tramp=/ssh:remote:"
  1659. remote$ $EDITOR /tmp/foo.txt #Should open in local emacs.
  1660. @end example
  1661. @end table
  1662. The new graphical or text terminal frames created by the @samp{-c}
  1663. or @samp{-t} options are considered @dfn{client frames}. Any new
  1664. frame that you create from a client frame is also considered a client
  1665. frame. If you type @kbd{C-x C-c} (@code{save-buffers-kill-terminal})
  1666. in a client frame, that command does not kill the Emacs session as it
  1667. normally does (@pxref{Exiting}). Instead, Emacs deletes the client
  1668. frame; furthermore, if the client frame has an @command{emacsclient}
  1669. waiting to regain control (i.e., if you did not supply the @samp{-n}
  1670. option), Emacs deletes all other frames of the same client, and marks
  1671. the client's server buffers as finished, as though you had typed
  1672. @kbd{C-x #} in all of them. If it so happens that there are no
  1673. remaining frames after the client frame(s) are deleted, the Emacs
  1674. session exits.
  1675. As an exception, when Emacs is started as a daemon, all frames are
  1676. considered client frames, and @kbd{C-x C-c} never kills Emacs. To
  1677. kill a daemon session, type @kbd{M-x kill-emacs}.
  1678. Note that the @samp{-t} and @samp{-n} options are contradictory:
  1679. @samp{-t} says to take control of the current text terminal to create
  1680. a new client frame, while @samp{-n} says not to take control of the
  1681. text terminal. If you supply both options, Emacs visits the specified
  1682. files(s) in an existing frame rather than a new client frame, negating
  1683. the effect of @samp{-t}.
  1684. @node Printing
  1685. @section Printing Hard Copies
  1686. @cindex hardcopy
  1687. @cindex printing
  1688. Emacs provides commands for printing hardcopies of either an entire
  1689. buffer or part of one. You can invoke the printing commands directly,
  1690. as detailed below, or using the @samp{File} menu on the menu bar.
  1691. @findex htmlfontify-buffer
  1692. Aside from the commands described in this section, you can also
  1693. print hardcopies from Dired (@pxref{Operating on Files}) and the diary
  1694. (@pxref{Displaying the Diary}). You can also ``print'' an Emacs
  1695. buffer to HTML with the command @kbd{M-x htmlfontify-buffer}, which
  1696. converts the current buffer to a HTML file, replacing Emacs faces with
  1697. CSS-based markup. Furthermore, Org mode allows you to print Org
  1698. files to a variety of formats, such as PDF (@pxref{Org Mode}).
  1699. @table @kbd
  1700. @item M-x print-buffer
  1701. Print hardcopy of current buffer with page headings containing the
  1702. file name and page number.
  1703. @item M-x lpr-buffer
  1704. Print hardcopy of current buffer without page headings.
  1705. @item M-x print-region
  1706. Like @code{print-buffer} but print only the current region.
  1707. @item M-x lpr-region
  1708. Like @code{lpr-buffer} but print only the current region.
  1709. @end table
  1710. @findex print-buffer
  1711. @findex print-region
  1712. @findex lpr-buffer
  1713. @findex lpr-region
  1714. @vindex lpr-switches
  1715. @vindex lpr-commands
  1716. On most operating systems, the above hardcopy commands submit files
  1717. for printing by calling the @command{lpr} program. To change the
  1718. printer program, customize the variable @code{lpr-command}. To
  1719. specify extra switches to give the printer program, customize the list
  1720. variable @code{lpr-switches}. Its value should be a list of option
  1721. strings, each of which should start with @samp{-} (e.g., the option
  1722. string @code{"-w80"} specifies a line width of 80 columns). The
  1723. default is the empty list, @code{nil}.
  1724. @vindex printer-name
  1725. @vindex lpr-printer-switch
  1726. To specify the printer to use, set the variable @code{printer-name}.
  1727. The default, @code{nil}, specifies the default printer. If you set it
  1728. to a printer name (a string), that name is passed to @command{lpr}
  1729. with the @samp{-P} switch; if you are not using @command{lpr}, you
  1730. should specify the switch with @code{lpr-printer-switch}.
  1731. @vindex lpr-headers-switches
  1732. @vindex lpr-add-switches
  1733. The variable @code{lpr-headers-switches} similarly specifies the
  1734. extra switches to use to make page headers. The variable
  1735. @code{lpr-add-switches} controls whether to supply @samp{-T} and
  1736. @samp{-J} options (suitable for @command{lpr}) to the printer program:
  1737. @code{nil} means don't add them (this should be the value if your
  1738. printer program is not compatible with @command{lpr}).
  1739. @menu
  1740. * PostScript:: Printing buffers or regions as PostScript.
  1741. * PostScript Variables:: Customizing the PostScript printing commands.
  1742. * Printing Package:: An optional advanced printing interface.
  1743. @end menu
  1744. @node PostScript
  1745. @subsection PostScript Hardcopy
  1746. These commands convert buffer contents to PostScript,
  1747. either printing it or leaving it in another Emacs buffer.
  1748. @table @kbd
  1749. @item M-x ps-print-buffer
  1750. Print hardcopy of the current buffer in PostScript form.
  1751. @item M-x ps-print-region
  1752. Print hardcopy of the current region in PostScript form.
  1753. @item M-x ps-print-buffer-with-faces
  1754. Print hardcopy of the current buffer in PostScript form, showing the
  1755. faces used in the text by means of PostScript features.
  1756. @item M-x ps-print-region-with-faces
  1757. Print hardcopy of the current region in PostScript form, showing the
  1758. faces used in the text.
  1759. @item M-x ps-spool-buffer
  1760. Generate and spool a PostScript image for the current buffer text.
  1761. @item M-x ps-spool-region
  1762. Generate and spool a PostScript image for the current region.
  1763. @item M-x ps-spool-buffer-with-faces
  1764. Generate and spool a PostScript image for the current buffer, showing the faces used.
  1765. @item M-x ps-spool-region-with-faces
  1766. Generate and spool a PostScript image for the current region, showing the faces used.
  1767. @item M-x ps-despool
  1768. Send the spooled PostScript to the printer.
  1769. @item M-x handwrite
  1770. Generate/print PostScript for the current buffer as if handwritten.
  1771. @end table
  1772. @findex ps-print-region
  1773. @findex ps-print-buffer
  1774. @findex ps-print-region-with-faces
  1775. @findex ps-print-buffer-with-faces
  1776. The @code{ps-print-buffer} and @code{ps-print-region} commands print
  1777. buffer contents in PostScript form. One command prints the entire
  1778. buffer; the other, just the region. The commands
  1779. @code{ps-print-buffer-with-faces} and
  1780. @code{ps-print-region-with-faces} behave similarly, but use PostScript
  1781. features to show the faces (fonts and colors) of the buffer text.
  1782. Interactively, when you use a prefix argument (@kbd{C-u}), the command
  1783. prompts the user for a file name, and saves the PostScript image in that file
  1784. instead of sending it to the printer.
  1785. @findex ps-spool-region
  1786. @findex ps-spool-buffer
  1787. @findex ps-spool-region-with-faces
  1788. @findex ps-spool-buffer-with-faces
  1789. The commands whose names have @samp{spool} instead of @samp{print},
  1790. generate the PostScript output in an Emacs buffer instead of sending
  1791. it to the printer.
  1792. @findex ps-despool
  1793. Use the command @code{ps-despool} to send the spooled images to the
  1794. printer. This command sends the PostScript generated by
  1795. @samp{-spool-} commands (see commands above) to the printer. With a
  1796. prefix argument (@kbd{C-u}), it prompts for a file name, and saves the
  1797. spooled PostScript image in that file instead of sending it to the
  1798. printer.
  1799. @findex handwrite
  1800. @cindex handwriting
  1801. @kbd{M-x handwrite} is more frivolous. It generates a PostScript
  1802. rendition of the current buffer as a cursive handwritten document. It
  1803. can be customized in group @code{handwrite}. This function only
  1804. supports ISO 8859-1 characters.
  1805. @node PostScript Variables
  1806. @subsection Variables for PostScript Hardcopy
  1807. @vindex ps-lpr-command
  1808. @vindex ps-lpr-switches
  1809. @vindex ps-printer-name
  1810. All the PostScript hardcopy commands use the variables
  1811. @code{ps-lpr-command} and @code{ps-lpr-switches} to specify how to print
  1812. the output. @code{ps-lpr-command} specifies the command name to run,
  1813. @code{ps-lpr-switches} specifies command line options to use, and
  1814. @code{ps-printer-name} specifies the printer. If you don't set the
  1815. first two variables yourself, they take their initial values from
  1816. @code{lpr-command} and @code{lpr-switches}. If @code{ps-printer-name}
  1817. is @code{nil}, @code{printer-name} is used.
  1818. @vindex ps-print-header
  1819. The variable @code{ps-print-header} controls whether these commands
  1820. add header lines to each page---set it to @code{nil} to turn headers
  1821. off.
  1822. @cindex color emulation on black-and-white printers
  1823. @vindex ps-print-color-p
  1824. If your printer doesn't support colors, you should turn off color
  1825. processing by setting @code{ps-print-color-p} to @code{nil}. By
  1826. default, if the display supports colors, Emacs produces hardcopy output
  1827. with color information; on black-and-white printers, colors are emulated
  1828. with shades of gray. This might produce illegible output, even if your
  1829. screen colors only use shades of gray.
  1830. Alternatively, you can set @code{ps-print-color-p} to @code{black-white} to
  1831. print colors on black/white printers.
  1832. @vindex ps-use-face-background
  1833. By default, PostScript printing ignores the background colors of the
  1834. faces, unless the variable @code{ps-use-face-background} is
  1835. non-@code{nil}. This is to avoid unwanted interference with the zebra
  1836. stripes and background image/text.
  1837. @vindex ps-paper-type
  1838. @vindex ps-page-dimensions-database
  1839. The variable @code{ps-paper-type} specifies which size of paper to
  1840. format for; legitimate values include @code{a4}, @code{a3},
  1841. @code{a4small}, @code{b4}, @code{b5}, @code{executive}, @code{ledger},
  1842. @code{legal}, @code{letter}, @code{letter-small}, @code{statement},
  1843. @code{tabloid}. The default is @code{letter}. You can define
  1844. additional paper sizes by changing the variable
  1845. @code{ps-page-dimensions-database}.
  1846. @vindex ps-landscape-mode
  1847. The variable @code{ps-landscape-mode} specifies the orientation of
  1848. printing on the page. The default is @code{nil}, which stands for
  1849. portrait mode. Any non-@code{nil} value specifies landscape
  1850. mode.
  1851. @vindex ps-number-of-columns
  1852. The variable @code{ps-number-of-columns} specifies the number of
  1853. columns; it takes effect in both landscape and portrait mode. The
  1854. default is 1.
  1855. @vindex ps-font-family
  1856. @vindex ps-font-size
  1857. @vindex ps-font-info-database
  1858. The variable @code{ps-font-family} specifies which font family to use
  1859. for printing ordinary text. Legitimate values include @code{Courier},
  1860. @code{Helvetica}, @code{NewCenturySchlbk}, @code{Palatino} and
  1861. @code{Times}. The variable @code{ps-font-size} specifies the size of
  1862. the font for ordinary text. It defaults to 8.5 points.
  1863. @vindex ps-multibyte-buffer
  1864. @cindex Intlfonts for PostScript printing
  1865. @cindex fonts for PostScript printing
  1866. Emacs supports more scripts and characters than a typical PostScript
  1867. printer. Thus, some of the characters in your buffer might not be
  1868. printable using the fonts built into your printer. You can augment
  1869. the fonts supplied with the printer with those from the GNU Intlfonts
  1870. package, or you can instruct Emacs to use Intlfonts exclusively. The
  1871. variable @code{ps-multibyte-buffer} controls this: the default value,
  1872. @code{nil}, is appropriate for printing @acronym{ASCII} and Latin-1
  1873. characters; a value of @code{non-latin-printer} is for printers which
  1874. have the fonts for @acronym{ASCII}, Latin-1, Japanese, and Korean
  1875. characters built into them. A value of @code{bdf-font} arranges for
  1876. the BDF fonts from the Intlfonts package to be used for @emph{all}
  1877. characters. Finally, a value of @code{bdf-font-except-latin}
  1878. instructs the printer to use built-in fonts for @acronym{ASCII} and Latin-1
  1879. characters, and Intlfonts BDF fonts for the rest.
  1880. @vindex bdf-directory-list
  1881. To be able to use the BDF fonts, Emacs needs to know where to find
  1882. them. The variable @code{bdf-directory-list} holds the list of
  1883. directories where Emacs should look for the fonts; the default value
  1884. includes a single directory @file{/usr/local/share/emacs/fonts/bdf}.
  1885. Many other customization variables for these commands are defined and
  1886. described in the Lisp files @file{ps-print.el} and @file{ps-mule.el}.
  1887. @node Printing Package
  1888. @subsection Printing Package
  1889. @cindex Printing package
  1890. The basic Emacs facilities for printing hardcopy can be extended
  1891. using the Printing package. This provides an easy-to-use interface
  1892. for choosing what to print, previewing PostScript files before
  1893. printing, and setting various printing options such as print headers,
  1894. landscape or portrait modes, duplex modes, and so forth. On GNU/Linux
  1895. or Unix systems, the Printing package relies on the @file{gs} and
  1896. @file{gv} utilities, which are distributed as part of the GhostScript
  1897. program. On MS-Windows, the @file{gstools} port of Ghostscript can be
  1898. used.
  1899. @findex pr-interface
  1900. To use the Printing package, add @code{(require 'printing)} to your
  1901. init file (@pxref{Init File}), followed by @code{(pr-update-menus)}.
  1902. This function replaces the usual printing commands in the menu bar
  1903. with a @samp{Printing} submenu that contains various printing options.
  1904. You can also type @kbd{M-x pr-interface @key{RET}}; this creates a
  1905. @file{*Printing Interface*} buffer, similar to a customization buffer,
  1906. where you can set the printing options. After selecting what and how
  1907. to print, you start the print job using the @samp{Print} button (click
  1908. @kbd{mouse-2} on it, or move point over it and type @key{RET}). For
  1909. further information on the various options, use the @samp{Interface
  1910. Help} button.
  1911. @node Sorting
  1912. @section Sorting Text
  1913. @cindex sorting
  1914. Emacs provides several commands for sorting text in the buffer. All
  1915. operate on the contents of the region.
  1916. They divide the text of the region into many @dfn{sort records},
  1917. identify a @dfn{sort key} for each record, and then reorder the records
  1918. into the order determined by the sort keys. The records are ordered so
  1919. that their keys are in alphabetical order, or, for numeric sorting, in
  1920. numeric order. In alphabetic sorting, all upper-case letters @samp{A}
  1921. through @samp{Z} come before lower-case @samp{a}, in accordance with the
  1922. @acronym{ASCII} character sequence.
  1923. The various sort commands differ in how they divide the text into sort
  1924. records and in which part of each record is used as the sort key. Most of
  1925. the commands make each line a separate sort record, but some commands use
  1926. paragraphs or pages as sort records. Most of the sort commands use each
  1927. entire sort record as its own sort key, but some use only a portion of the
  1928. record as the sort key.
  1929. @findex sort-lines
  1930. @findex sort-paragraphs
  1931. @findex sort-pages
  1932. @findex sort-fields
  1933. @findex sort-numeric-fields
  1934. @vindex sort-numeric-base
  1935. @table @kbd
  1936. @item M-x sort-lines
  1937. Divide the region into lines, and sort by comparing the entire
  1938. text of a line. A numeric argument means sort into descending order.
  1939. @item M-x sort-paragraphs
  1940. Divide the region into paragraphs, and sort by comparing the entire
  1941. text of a paragraph (except for leading blank lines). A numeric
  1942. argument means sort into descending order.
  1943. @item M-x sort-pages
  1944. Divide the region into pages, and sort by comparing the entire
  1945. text of a page (except for leading blank lines). A numeric
  1946. argument means sort into descending order.
  1947. @item M-x sort-fields
  1948. Divide the region into lines, and sort by comparing the contents of
  1949. one field in each line. Fields are defined as separated by
  1950. whitespace, so the first run of consecutive non-whitespace characters
  1951. in a line constitutes field 1, the second such run constitutes field
  1952. 2, etc.
  1953. Specify which field to sort by with a numeric argument: 1 to sort by
  1954. field 1, etc. A negative argument means count fields from the right
  1955. instead of from the left; thus, minus 1 means sort by the last field.
  1956. If several lines have identical contents in the field being sorted, they
  1957. keep the same relative order that they had in the original buffer.
  1958. @item M-x sort-numeric-fields
  1959. Like @kbd{M-x sort-fields} except the specified field is converted
  1960. to an integer for each line, and the numbers are compared. @samp{10}
  1961. comes before @samp{2} when considered as text, but after it when
  1962. considered as a number. By default, numbers are interpreted according
  1963. to @code{sort-numeric-base}, but numbers beginning with @samp{0x} or
  1964. @samp{0} are interpreted as hexadecimal and octal, respectively.
  1965. @item M-x sort-columns
  1966. Like @kbd{M-x sort-fields} except that the text within each line
  1967. used for comparison comes from a fixed range of columns. With a
  1968. prefix argument, sort in reverse order. See below for more details
  1969. on this command.
  1970. @findex reverse-region
  1971. @item M-x reverse-region
  1972. Reverse the order of the lines in the region. This is useful for
  1973. sorting into descending order by fields, since those sort
  1974. commands do not have a feature for doing that.
  1975. @end table
  1976. For example, if the buffer contains this:
  1977. @smallexample
  1978. On systems where clash detection (locking of files being edited) is
  1979. implemented, Emacs also checks the first time you modify a buffer
  1980. whether the file has changed on disk since it was last visited or
  1981. saved. If it has, you are asked to confirm that you want to change
  1982. the buffer.
  1983. @end smallexample
  1984. @noindent
  1985. applying @kbd{M-x sort-lines} to the entire buffer produces this:
  1986. @smallexample
  1987. On systems where clash detection (locking of files being edited) is
  1988. implemented, Emacs also checks the first time you modify a buffer
  1989. saved. If it has, you are asked to confirm that you want to change
  1990. the buffer.
  1991. whether the file has changed on disk since it was last visited or
  1992. @end smallexample
  1993. @noindent
  1994. where the upper-case @samp{O} sorts before all lower-case letters. If
  1995. you use @kbd{C-u 2 M-x sort-fields} instead, you get this:
  1996. @smallexample
  1997. implemented, Emacs also checks the first time you modify a buffer
  1998. saved. If it has, you are asked to confirm that you want to change
  1999. the buffer.
  2000. On systems where clash detection (locking of files being edited) is
  2001. whether the file has changed on disk since it was last visited or
  2002. @end smallexample
  2003. @noindent
  2004. where the sort keys were @samp{Emacs}, @samp{If}, @samp{buffer},
  2005. @samp{systems} and @samp{the}.
  2006. @findex sort-columns
  2007. @kbd{M-x sort-columns} requires more explanation. You specify the
  2008. columns by putting point at one of the columns and the mark at the other
  2009. column. Because this means you cannot put point or the mark at the
  2010. beginning of the first line of the text you want to sort, this command
  2011. uses an unusual definition of ``region'': all of the line point is in is
  2012. considered part of the region, and so is all of the line the mark is in,
  2013. as well as all the lines in between.
  2014. For example, to sort a table by information found in columns 10 to 15,
  2015. you could put the mark on column 10 in the first line of the table, and
  2016. point on column 15 in the last line of the table, and then run
  2017. @code{sort-columns}. Equivalently, you could run it with the mark on
  2018. column 15 in the first line and point on column 10 in the last line.
  2019. This can be thought of as sorting the rectangle specified by point and
  2020. the mark, except that the text on each line to the left or right of the
  2021. rectangle moves along with the text inside the rectangle.
  2022. @xref{Rectangles}.
  2023. @vindex sort-fold-case
  2024. Many of the sort commands ignore case differences when comparing, if
  2025. @code{sort-fold-case} is non-@code{nil}.
  2026. @c Picture Mode documentation
  2027. @ifnottex
  2028. @include picture-xtra.texi
  2029. @end ifnottex
  2030. @node Editing Binary Files
  2031. @section Editing Binary Files
  2032. @cindex Hexl mode
  2033. @cindex mode, Hexl
  2034. @cindex editing binary files
  2035. @cindex hex editing
  2036. There is a special major mode for editing binary files: Hexl mode. To
  2037. use it, use @kbd{M-x hexl-find-file} instead of @kbd{C-x C-f} to visit
  2038. the file. This command converts the file's contents to hexadecimal and
  2039. lets you edit the translation. When you save the file, it is converted
  2040. automatically back to binary.
  2041. You can also use @kbd{M-x hexl-mode} to translate an existing buffer
  2042. into hex. This is useful if you visit a file normally and then discover
  2043. it is a binary file.
  2044. Ordinary text characters overwrite in Hexl mode. This is to reduce
  2045. the risk of accidentally spoiling the alignment of data in the file.
  2046. There are special commands for insertion. Here is a list of the
  2047. commands of Hexl mode:
  2048. @c I don't think individual index entries for these commands are useful--RMS.
  2049. @table @kbd
  2050. @item C-M-d
  2051. Insert a byte with a code typed in decimal.
  2052. @item C-M-o
  2053. Insert a byte with a code typed in octal.
  2054. @item C-M-x
  2055. Insert a byte with a code typed in hex.
  2056. @item C-x [
  2057. Move to the beginning of a 1k-byte page.
  2058. @item C-x ]
  2059. Move to the end of a 1k-byte page.
  2060. @item M-g
  2061. Move to an address specified in hex.
  2062. @item M-j
  2063. Move to an address specified in decimal.
  2064. @item C-c C-c
  2065. Leave Hexl mode, going back to the major mode this buffer had before you
  2066. invoked @code{hexl-mode}.
  2067. @end table
  2068. @noindent
  2069. Other Hexl commands let you insert strings (sequences) of binary
  2070. bytes, move by @code{short}s or @code{int}s, etc.; type @kbd{C-h a
  2071. hexl-@key{RET}} for details.
  2072. @node Saving Emacs Sessions
  2073. @section Saving Emacs Sessions
  2074. @cindex saving sessions
  2075. @cindex restore session
  2076. @cindex remember editing session
  2077. @cindex reload files
  2078. @cindex desktop
  2079. @vindex desktop-restore-frames
  2080. Use the desktop library to save the state of Emacs from one session
  2081. to another. Once you save the Emacs @dfn{desktop}---the buffers,
  2082. their file names, major modes, buffer positions, and so on---then
  2083. subsequent Emacs sessions reload the saved desktop. By default,
  2084. the desktop also tries to save the frame and window configuration.
  2085. To disable this, set @code{desktop-restore-frames} to @code{nil}.
  2086. (See that variable's documentation for some related options
  2087. that you can customize to fine-tune this behavior.)
  2088. @vindex frameset-filter-alist
  2089. When the desktop restores the frame and window configuration, it
  2090. uses the recorded values of frame parameters, disregarding any
  2091. settings for those parameters you have in your init file (@pxref{Init
  2092. File}). This means that frame parameters such as fonts and faces for
  2093. the restored frames will come from the desktop file, where they were
  2094. saved when you exited your previous Emacs session; any settings for
  2095. those parameters in your init file will be ignored. To disable this,
  2096. customize the value of @code{frameset-filter-alist} to filter out the
  2097. frame parameters you don't want to be restored.
  2098. @findex desktop-save
  2099. @vindex desktop-save-mode
  2100. You can save the desktop manually with the command @kbd{M-x
  2101. desktop-save}. You can also enable automatic saving of the desktop
  2102. when you exit Emacs, and automatic restoration of the last saved
  2103. desktop when Emacs starts: use the Customization buffer (@pxref{Easy
  2104. Customization}) to set @code{desktop-save-mode} to @code{t} for future
  2105. sessions, or add this line in your init file (@pxref{Init File}):
  2106. @example
  2107. (desktop-save-mode 1)
  2108. @end example
  2109. @vindex desktop-auto-save-timeout
  2110. @noindent
  2111. When @code{desktop-save-mode} is active and the desktop file exists,
  2112. Emacs auto-saves it every @code{desktop-auto-save-timeout}
  2113. seconds, if that is non-@code{nil} and non-zero.
  2114. @findex desktop-change-dir
  2115. @findex desktop-revert
  2116. @vindex desktop-path
  2117. If you turn on @code{desktop-save-mode} in your init file, then when
  2118. Emacs starts, it looks for a saved desktop in the current directory.
  2119. (More precisely, it looks in the directories specified by
  2120. @var{desktop-path}, and uses the first desktop it finds.)
  2121. Thus, you can have separate saved desktops in different directories,
  2122. and the starting directory determines which one Emacs reloads. You
  2123. can save the current desktop and reload one saved in another directory
  2124. by typing @kbd{M-x desktop-change-dir}. Typing @kbd{M-x
  2125. desktop-revert} reverts to the desktop previously reloaded.
  2126. Specify the option @samp{--no-desktop} on the command line when you
  2127. don't want it to reload any saved desktop. This turns off
  2128. @code{desktop-save-mode} for the current session. Starting Emacs with
  2129. the @samp{--no-init-file} option also disables desktop reloading,
  2130. since it bypasses the init file, where @code{desktop-save-mode} is
  2131. usually turned on.
  2132. @vindex desktop-restore-eager
  2133. By default, all the buffers in the desktop are restored at one go.
  2134. However, this may be slow if there are a lot of buffers in the
  2135. desktop. You can specify the maximum number of buffers to restore
  2136. immediately with the variable @code{desktop-restore-eager}; the
  2137. remaining buffers are restored lazily, when Emacs is idle.
  2138. @findex desktop-clear
  2139. @vindex desktop-globals-to-clear
  2140. @vindex desktop-clear-preserve-buffers-regexp
  2141. Type @kbd{M-x desktop-clear} to empty the Emacs desktop. This kills
  2142. all buffers except for internal ones, and clears the global variables
  2143. listed in @code{desktop-globals-to-clear}. If you want this to
  2144. preserve certain buffers, customize the variable
  2145. @code{desktop-clear-preserve-buffers-regexp}, whose value is a regular
  2146. expression matching the names of buffers not to kill.
  2147. If you want to save minibuffer history from one session to
  2148. another, use the @code{savehist} library.
  2149. @node Recursive Edit
  2150. @section Recursive Editing Levels
  2151. @cindex recursive editing level
  2152. @cindex editing level, recursive
  2153. A @dfn{recursive edit} is a situation in which you are using Emacs
  2154. commands to perform arbitrary editing while in the middle of another
  2155. Emacs command. For example, when you type @kbd{C-r} inside of a
  2156. @code{query-replace}, you enter a recursive edit in which you can change
  2157. the current buffer. On exiting from the recursive edit, you go back to
  2158. the @code{query-replace}. @xref{Query Replace}.
  2159. @kindex C-M-c
  2160. @findex exit-recursive-edit
  2161. @cindex exiting recursive edit
  2162. @dfn{Exiting} the recursive edit means returning to the unfinished
  2163. command, which continues execution. The command to exit is @kbd{C-M-c}
  2164. (@code{exit-recursive-edit}).
  2165. You can also @dfn{abort} the recursive edit. This is like exiting,
  2166. but also quits the unfinished command immediately. Use the command
  2167. @kbd{C-]} (@code{abort-recursive-edit}) to do this. @xref{Quitting}.
  2168. The mode line shows you when you are in a recursive edit by displaying
  2169. square brackets around the parentheses that always surround the major and
  2170. minor mode names. Every window's mode line shows this in the same way,
  2171. since being in a recursive edit is true of Emacs as a whole rather than
  2172. any particular window or buffer.
  2173. It is possible to be in recursive edits within recursive edits. For
  2174. example, after typing @kbd{C-r} in a @code{query-replace}, you may type a
  2175. command that enters the debugger. This begins a recursive editing level
  2176. for the debugger, within the recursive editing level for @kbd{C-r}.
  2177. Mode lines display a pair of square brackets for each recursive editing
  2178. level currently in progress.
  2179. Exiting the inner recursive edit (such as with the debugger @kbd{c}
  2180. command) resumes the command running in the next level up. When that
  2181. command finishes, you can then use @kbd{C-M-c} to exit another recursive
  2182. editing level, and so on. Exiting applies to the innermost level only.
  2183. Aborting also gets out of only one level of recursive edit; it returns
  2184. immediately to the command level of the previous recursive edit. If you
  2185. wish, you can then abort the next recursive editing level.
  2186. Alternatively, the command @kbd{M-x top-level} aborts all levels of
  2187. recursive edits, returning immediately to the top-level command
  2188. reader. It also exits the minibuffer, if it is active.
  2189. The text being edited inside the recursive edit need not be the same text
  2190. that you were editing at top level. It depends on what the recursive edit
  2191. is for. If the command that invokes the recursive edit selects a different
  2192. buffer first, that is the buffer you will edit recursively. In any case,
  2193. you can switch buffers within the recursive edit in the normal manner (as
  2194. long as the buffer-switching keys have not been rebound). You could
  2195. probably do all the rest of your editing inside the recursive edit,
  2196. visiting files and all. But this could have surprising effects (such as
  2197. stack overflow) from time to time. So remember to exit or abort the
  2198. recursive edit when you no longer need it.
  2199. In general, we try to minimize the use of recursive editing levels in
  2200. GNU Emacs. This is because they constrain you to go back in a
  2201. particular order---from the innermost level toward the top level. When
  2202. possible, we present different activities in separate buffers so that
  2203. you can switch between them as you please. Some commands switch to a
  2204. new major mode which provides a command to switch back. These
  2205. approaches give you more flexibility to go back to unfinished tasks in
  2206. the order you choose.
  2207. @ignore
  2208. @c Apart from edt and viper, this is all obsolete.
  2209. @c (Can't believe we were saying "most other editors" into 2014!)
  2210. @c There seems no point having a node just for those, which both have
  2211. @c their own manuals.
  2212. @node Emulation
  2213. @section Emulation
  2214. @cindex emulating other editors
  2215. @cindex other editors
  2216. @cindex EDT
  2217. @cindex vi
  2218. @cindex WordStar
  2219. GNU Emacs can be programmed to emulate (more or less) most other
  2220. editors. Standard facilities can emulate these:
  2221. @table @asis
  2222. @item CRiSP/Brief (PC editor)
  2223. @findex crisp-mode
  2224. @vindex crisp-override-meta-x
  2225. @findex scroll-all-mode
  2226. @cindex CRiSP mode
  2227. @cindex Brief emulation
  2228. @cindex emulation of Brief
  2229. @cindex mode, CRiSP
  2230. @kbd{M-x crisp-mode} enables key bindings to emulate the CRiSP/Brief
  2231. editor. Note that this rebinds @kbd{M-x} to exit Emacs unless you set
  2232. the variable @code{crisp-override-meta-x}. You can also use the
  2233. command @kbd{M-x scroll-all-mode} or set the variable
  2234. @code{crisp-load-scroll-all} to emulate CRiSP's scroll-all feature
  2235. (scrolling all windows together).
  2236. @item EDT (DEC VMS editor)
  2237. @findex edt-emulation-on
  2238. @findex edt-emulation-off
  2239. Turn on EDT emulation with @kbd{M-x edt-emulation-on}; restore normal
  2240. command bindings with @kbd{M-x edt-emulation-off}.
  2241. Most of the EDT emulation commands are keypad keys, and most standard
  2242. Emacs key bindings are still available. The EDT emulation rebindings
  2243. are done in the global keymap, so there is no problem switching
  2244. buffers or major modes while in EDT emulation.
  2245. @item TPU (DEC VMS editor)
  2246. @findex tpu-edt-on
  2247. @cindex TPU
  2248. @kbd{M-x tpu-edt-on} turns on emulation of the TPU editor emulating EDT.
  2249. @item vi (Berkeley editor)
  2250. @findex viper-mode
  2251. Viper is an emulator for vi. It implements several levels of
  2252. emulation; level 1 is closest to vi itself, while level 5 departs
  2253. somewhat from strict emulation to take advantage of the capabilities of
  2254. Emacs. To invoke Viper, type @kbd{M-x viper-mode}; it will guide you
  2255. the rest of the way and ask for the emulation level. @inforef{Top,
  2256. Viper, viper}.
  2257. @item vi (another emulator)
  2258. @findex vi-mode
  2259. @kbd{M-x vi-mode} enters a major mode that replaces the previously
  2260. established major mode. All of the vi commands that, in real vi, enter
  2261. input mode are programmed instead to return to the previous major
  2262. mode. Thus, ordinary Emacs serves as vi's input mode.
  2263. Because vi emulation works through major modes, it does not work
  2264. to switch buffers during emulation. Return to normal Emacs first.
  2265. If you plan to use vi emulation much, you probably want to bind a key
  2266. to the @code{vi-mode} command.
  2267. @item vi (alternate emulator)
  2268. @findex vip-mode
  2269. @kbd{M-x vip-mode} invokes another vi emulator, said to resemble real vi
  2270. more thoroughly than @kbd{M-x vi-mode}. Input mode in this emulator
  2271. is changed from ordinary Emacs so you can use @key{ESC} to go back to
  2272. emulated vi command mode. To get from emulated vi command mode back to
  2273. ordinary Emacs, type @kbd{C-z}.
  2274. This emulation does not work through major modes, and it is possible
  2275. to switch buffers in various ways within the emulator. It is not
  2276. so necessary to assign a key to the command @code{vip-mode} as
  2277. it is with @code{vi-mode} because terminating insert mode does
  2278. not use it.
  2279. @inforef{Top, VIP, vip}, for full information.
  2280. @item WordStar (old wordprocessor)
  2281. @findex wordstar-mode
  2282. @kbd{M-x wordstar-mode} provides a major mode with WordStar-like
  2283. key bindings.
  2284. @end table
  2285. @end ignore
  2286. @node Hyperlinking
  2287. @section Hyperlinking and Navigation Features
  2288. The following subsections describe convenience features for handling
  2289. URLs and other types of links occurring in Emacs buffer text.
  2290. @menu
  2291. * Browse-URL:: Following URLs.
  2292. * Goto Address mode:: Activating URLs.
  2293. * FFAP:: Finding files etc. at point.
  2294. @end menu
  2295. @node Browse-URL
  2296. @subsection Following URLs
  2297. @cindex World Wide Web
  2298. @cindex Web
  2299. @findex browse-url
  2300. @findex browse-url-at-point
  2301. @findex browse-url-at-mouse
  2302. @cindex Browse-URL
  2303. @cindex URLs
  2304. @table @kbd
  2305. @item M-x browse-url @key{RET} @var{url} @key{RET}
  2306. Load a URL into a Web browser.
  2307. @end table
  2308. The Browse-URL package allows you to easily follow URLs from within
  2309. Emacs. Most URLs are followed by invoking a web browser;
  2310. @samp{mailto:} URLs are followed by invoking the @code{compose-mail}
  2311. Emacs command to send mail to the specified address (@pxref{Sending
  2312. Mail}).
  2313. The command @kbd{M-x browse-url} prompts for a URL, and follows it.
  2314. If point is located near a plausible URL, that URL is offered as the
  2315. default. The Browse-URL package also provides other commands which
  2316. you might like to bind to keys, such as @code{browse-url-at-point} and
  2317. @code{browse-url-at-mouse}.
  2318. @vindex browse-url-mailto-function
  2319. @vindex browse-url-browser-function
  2320. You can customize Browse-URL's behavior via various options in the
  2321. @code{browse-url} Customize group. In particular, the option
  2322. @code{browse-url-mailto-function} lets you define how to follow
  2323. @samp{mailto:} URLs, while @code{browse-url-browser-function} lets you
  2324. define how to follow other types of URLs. For more information, view
  2325. the package commentary by typing @kbd{C-h P browse-url @key{RET}}.
  2326. @node Goto Address mode
  2327. @subsection Activating URLs
  2328. @findex goto-address-mode
  2329. @cindex mode, Goto Address
  2330. @cindex Goto Address mode
  2331. @cindex URLs, activating
  2332. @table @kbd
  2333. @item M-x goto-address-mode
  2334. Activate URLs and e-mail addresses in the current buffer.
  2335. @end table
  2336. @kindex C-c RET @r{(Goto Address mode)}
  2337. @findex goto-address-at-point
  2338. You can make Emacs mark out URLs specially in the current buffer, by
  2339. typing @kbd{M-x goto-address-mode}. When this buffer-local minor mode
  2340. is enabled, it finds all the URLs in the buffer, highlights them, and
  2341. turns them into clickable buttons. You can follow the URL by typing
  2342. @kbd{C-c @key{RET}} (@code{goto-address-at-point}) while point is on
  2343. its text; or by clicking with @kbd{mouse-2}, or by clicking
  2344. @kbd{mouse-1} quickly (@pxref{Mouse References}). Following a URL is
  2345. done by calling @code{browse-url} as a subroutine
  2346. (@pxref{Browse-URL}).
  2347. It can be useful to add @code{goto-address-mode} to mode hooks and
  2348. hooks for displaying an incoming message
  2349. (e.g., @code{rmail-show-message-hook} for Rmail, and
  2350. @code{mh-show-mode-hook} for MH-E). This is not needed for Gnus,
  2351. which has a similar feature of its own.
  2352. @node FFAP
  2353. @subsection Finding Files and URLs at Point
  2354. @findex find-file-at-point
  2355. @findex ffap
  2356. @findex dired-at-point
  2357. @findex ffap-next
  2358. @findex ffap-menu
  2359. @cindex finding file at point
  2360. The FFAP package replaces certain key bindings for finding files,
  2361. such as @kbd{C-x C-f}, with commands that provide more sensitive
  2362. defaults. These commands behave like the ordinary ones when given a
  2363. prefix argument. Otherwise, they get the default file name or URL
  2364. from the text around point. If what is found in the buffer has the
  2365. form of a URL rather than a file name, the commands use
  2366. @code{browse-url} to view it (@pxref{Browse-URL}).
  2367. This feature is useful for following references in mail or news
  2368. buffers, @file{README} files, @file{MANIFEST} files, and so on. For
  2369. more information, view the package commentary by typing @kbd{C-h P
  2370. ffap @key{RET}}.
  2371. @cindex FFAP minor mode
  2372. @findex ffap-mode
  2373. To enable FFAP, type @kbd{M-x ffap-bindings}. This makes the
  2374. following key bindings, and also installs hooks for additional FFAP
  2375. functionality in Rmail, Gnus and VM article buffers.
  2376. @table @kbd
  2377. @item C-x C-f @var{filename} @key{RET}
  2378. @kindex C-x C-f @r{(FFAP)}
  2379. Find @var{filename}, guessing a default from text around point
  2380. (@code{find-file-at-point}).
  2381. @item C-x C-r
  2382. @kindex C-x C-r @r{(FFAP)}
  2383. @code{ffap-read-only}, analogous to @code{find-file-read-only}.
  2384. @item C-x C-v
  2385. @kindex C-x C-v @r{(FFAP)}
  2386. @code{ffap-alternate-file}, analogous to @code{find-alternate-file}.
  2387. @item C-x d @var{directory} @key{RET}
  2388. @kindex C-x d @r{(FFAP)}
  2389. Start Dired on @var{directory}, defaulting to the directory name at
  2390. point (@code{dired-at-point}).
  2391. @item C-x C-d
  2392. @code{ffap-list-directory}, analogous to @code{list-directory}.
  2393. @item C-x 4 f
  2394. @kindex C-x 4 f @r{(FFAP)}
  2395. @code{ffap-other-window}, analogous to @code{find-file-other-window}.
  2396. @item C-x 4 r
  2397. @code{ffap-read-only-other-window}, analogous to
  2398. @code{find-file-read-only-other-window}.
  2399. @item C-x 4 d
  2400. @code{ffap-dired-other-window}, like @code{dired-other-window}.
  2401. @item C-x 5 f
  2402. @kindex C-x 5 f @r{(FFAP)}
  2403. @code{ffap-other-frame}, analogous to @code{find-file-other-frame}.
  2404. @item C-x 5 r
  2405. @code{ffap-read-only-other-frame}, analogous to
  2406. @code{find-file-read-only-other-frame}.
  2407. @item C-x 5 d
  2408. @code{ffap-dired-other-frame}, analogous to @code{dired-other-frame}.
  2409. @item M-x ffap-next
  2410. Search buffer for next file name or URL, then find that file or URL.
  2411. @item S-mouse-3
  2412. @kindex S-mouse-3 @r{(FFAP)}
  2413. @code{ffap-at-mouse} finds the file guessed from text around the position
  2414. of a mouse click.
  2415. @item C-S-mouse-3
  2416. @kindex C-S-mouse-3 @r{(FFAP)}
  2417. Display a menu of files and URLs mentioned in current buffer, then
  2418. find the one you select (@code{ffap-menu}).
  2419. @end table
  2420. @node Amusements
  2421. @section Other Amusements
  2422. @cindex boredom
  2423. @findex animate-birthday-present
  2424. @cindex animate
  2425. The @code{animate} package makes text dance (e.g., @kbd{M-x
  2426. animate-birthday-present}).
  2427. @findex blackbox
  2428. @findex mpuz
  2429. @findex 5x5
  2430. @cindex puzzles
  2431. @kbd{M-x blackbox}, @kbd{M-x mpuz} and @kbd{M-x 5x5} are puzzles.
  2432. @code{blackbox} challenges you to determine the location of objects
  2433. inside a box by tomography. @code{mpuz} displays a multiplication
  2434. puzzle with letters standing for digits in a code that you must
  2435. guess---to guess a value, type a letter and then the digit you think it
  2436. stands for. The aim of @code{5x5} is to fill in all the squares.
  2437. @findex bubbles
  2438. @kbd{M-x bubbles} is a game in which the object is to remove as many
  2439. bubbles as you can in the smallest number of moves.
  2440. @findex decipher
  2441. @cindex ciphers
  2442. @cindex cryptanalysis
  2443. @kbd{M-x decipher} helps you to cryptanalyze a buffer which is
  2444. encrypted in a simple monoalphabetic substitution cipher.
  2445. @findex dissociated-press
  2446. @kbd{M-x dissociated-press} scrambles the text in the current Emacs
  2447. buffer, word by word or character by character, writing its output to
  2448. a buffer named @file{*Dissociation*}. A positive argument tells it to
  2449. operate character by character, and specifies the number of overlap
  2450. characters. A negative argument tells it to operate word by word, and
  2451. specifies the number of overlap words. Dissociated Press produces
  2452. results fairly like those of a Markov chain, but is however, an
  2453. independent, ignoriginal invention; it techniquitously copies several
  2454. consecutive characters from the sample text between random jumps,
  2455. unlike a Markov chain which would jump randomly after each word or
  2456. character. Keep dissociwords out of your documentation, if you want
  2457. it to be well userenced and properbose.
  2458. @findex dunnet
  2459. @kbd{M-x dunnet} runs a text-based adventure game.
  2460. @findex gomoku
  2461. @cindex Go Moku
  2462. If you want a little more personal involvement, try @kbd{M-x gomoku},
  2463. which plays the game Go Moku with you.
  2464. @cindex tower of Hanoi
  2465. @findex hanoi
  2466. If you are a little bit bored, you can try @kbd{M-x hanoi}. If you are
  2467. considerably bored, give it a numeric argument. If you are very, very
  2468. bored, try an argument of 9. Sit back and watch.
  2469. @findex life
  2470. @cindex Life
  2471. @kbd{M-x life} runs Conway's Game of Life cellular automaton.
  2472. @findex landmark
  2473. @cindex landmark game
  2474. @kbd{M-x landmark} runs a relatively non-participatory game in which
  2475. a robot attempts to maneuver towards a tree at the center of the
  2476. window based on unique olfactory cues from each of the four
  2477. directions.
  2478. @findex morse-region
  2479. @findex unmorse-region
  2480. @findex nato-region
  2481. @cindex Morse code
  2482. @cindex --/---/.-./.../.
  2483. @kbd{M-x morse-region} converts the text in the region to Morse
  2484. code; @kbd{M-x unmorse-region} converts it back. @kbd{M-x
  2485. nato-region} converts the text in the region to NATO phonetic
  2486. alphabet; @kbd{M-x denato-region} converts it back.
  2487. @findex pong
  2488. @cindex Pong game
  2489. @findex tetris
  2490. @cindex Tetris
  2491. @findex snake
  2492. @cindex Snake
  2493. @kbd{M-x pong}, @kbd{M-x snake} and @kbd{M-x tetris} are
  2494. implementations of the well-known Pong, Snake and Tetris games.
  2495. @findex solitaire
  2496. @cindex solitaire
  2497. @kbd{M-x solitaire} plays a game of solitaire in which you jump pegs
  2498. across other pegs.
  2499. @findex zone
  2500. The command @kbd{M-x zone} plays games with the display when Emacs
  2501. is idle.
  2502. @findex doctor
  2503. @cindex Eliza
  2504. Finally, if you find yourself frustrated, try describing your
  2505. problems to the famous psychotherapist Eliza. Just do @kbd{M-x
  2506. doctor}. End each input by typing @key{RET} twice.
  2507. @ifnottex
  2508. @lowersections
  2509. @end ifnottex