os.texi 114 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041
  1. @c -*-texinfo-*-
  2. @c This is part of the GNU Emacs Lisp Reference Manual.
  3. @c Copyright (C) 1990-1995, 1998-1999, 2001-2016 Free Software
  4. @c Foundation, Inc.
  5. @c See the file elisp.texi for copying conditions.
  6. @node System Interface
  7. @chapter Operating System Interface
  8. This chapter is about starting and getting out of Emacs, access to
  9. values in the operating system environment, and terminal input, output.
  10. @xref{Building Emacs}, for related information. @xref{Display}, for
  11. additional operating system status information pertaining to the
  12. terminal and the screen.
  13. @menu
  14. * Starting Up:: Customizing Emacs startup processing.
  15. * Getting Out:: How exiting works (permanent or temporary).
  16. * System Environment:: Distinguish the name and kind of system.
  17. * User Identification:: Finding the name and user id of the user.
  18. * Time of Day:: Getting the current time.
  19. * Time Conversion:: Converting a time from numeric form to
  20. calendrical data and vice versa.
  21. * Time Parsing:: Converting a time from numeric form to text
  22. and vice versa.
  23. * Processor Run Time:: Getting the run time used by Emacs.
  24. * Time Calculations:: Adding, subtracting, comparing times, etc.
  25. * Timers:: Setting a timer to call a function at a certain time.
  26. * Idle Timers:: Setting a timer to call a function when Emacs has
  27. been idle for a certain length of time.
  28. * Terminal Input:: Accessing and recording terminal input.
  29. * Terminal Output:: Controlling and recording terminal output.
  30. * Sound Output:: Playing sounds on the computer's speaker.
  31. * X11 Keysyms:: Operating on key symbols for X Windows.
  32. * Batch Mode:: Running Emacs without terminal interaction.
  33. * Session Management:: Saving and restoring state with X Session Management.
  34. * Desktop Notifications:: Desktop notifications.
  35. * File Notifications:: File notifications.
  36. * Dynamic Libraries:: On-demand loading of support libraries.
  37. * Security Considerations:: Running Emacs in an unfriendly environment.
  38. @end menu
  39. @node Starting Up
  40. @section Starting Up Emacs
  41. This section describes what Emacs does when it is started, and how you
  42. can customize these actions.
  43. @menu
  44. * Startup Summary:: Sequence of actions Emacs performs at startup.
  45. * Init File:: Details on reading the init file.
  46. * Terminal-Specific:: How the terminal-specific Lisp file is read.
  47. * Command-Line Arguments:: How command-line arguments are processed,
  48. and how you can customize them.
  49. @end menu
  50. @node Startup Summary
  51. @subsection Summary: Sequence of Actions at Startup
  52. @cindex initialization of Emacs
  53. @cindex startup of Emacs
  54. @cindex @file{startup.el}
  55. When Emacs is started up, it performs the following operations
  56. (see @code{normal-top-level} in @file{startup.el}):
  57. @enumerate
  58. @item
  59. It adds subdirectories to @code{load-path}, by running the file named
  60. @file{subdirs.el} in each directory in the list. Normally, this file
  61. adds the directory's subdirectories to the list, and those are scanned
  62. in their turn. The files @file{subdirs.el} are normally generated
  63. automatically when Emacs is installed.
  64. @item
  65. It loads any @file{leim-list.el} that it finds in the @code{load-path}
  66. directories. This file is intended for registering input methods.
  67. The search is only for any personal @file{leim-list.el} files that you
  68. may have created; it skips the directories containing the standard Emacs
  69. libraries (these should contain only a single @file{leim-list.el} file,
  70. which is compiled into the Emacs executable).
  71. @vindex before-init-time
  72. @item
  73. It sets the variable @code{before-init-time} to the value of
  74. @code{current-time} (@pxref{Time of Day}). It also sets
  75. @code{after-init-time} to @code{nil}, which signals to Lisp programs
  76. that Emacs is being initialized.
  77. @c set-locale-environment
  78. @item
  79. It sets the language environment and the terminal coding system,
  80. if requested by environment variables such as @env{LANG}.
  81. @item
  82. It does some basic parsing of the command-line arguments.
  83. @vindex initial-window-system@r{, and startup}
  84. @vindex window-system-initialization-alist
  85. @item
  86. If not running in batch mode, it initializes the window system that
  87. the variable @code{initial-window-system} specifies (@pxref{Window
  88. Systems, initial-window-system}). The initialization function for
  89. each supported window system is specified by
  90. @code{window-system-initialization-alist}. If the value
  91. of @code{initial-window-system} is @var{windowsystem}, then the
  92. appropriate initialization function is defined in the file
  93. @file{term/@var{windowsystem}-win.el}. This file should have been
  94. compiled into the Emacs executable when it was built.
  95. @item
  96. It runs the normal hook @code{before-init-hook}.
  97. @item
  98. If appropriate, it creates a graphical frame. This is not done if the
  99. options @samp{--batch} or @samp{--daemon} were specified.
  100. @item
  101. It initializes the initial frame's faces, and sets up the menu bar
  102. and tool bar if needed. If graphical frames are supported, it sets up
  103. the tool bar even if the current frame is not a graphical one, since a
  104. graphical frame may be created later on.
  105. @item
  106. It use @code{custom-reevaluate-setting} to re-initialize the members
  107. of the list @code{custom-delayed-init-variables}. These are any
  108. pre-loaded user options whose default value depends on the run-time,
  109. rather than build-time, context.
  110. @xref{Building Emacs, custom-initialize-delay}.
  111. @c @item
  112. @c It registers the colors available for tty frames.
  113. @item
  114. It loads the library @file{site-start}, if it exists. This is not
  115. done if the options @samp{-Q} or @samp{--no-site-file} were specified.
  116. @cindex @file{site-start.el}
  117. @item
  118. It loads your init file (@pxref{Init File}). This is not done if the
  119. options @samp{-q}, @samp{-Q}, or @samp{--batch} were specified. If
  120. the @samp{-u} option was specified, Emacs looks for the init file in
  121. that user's home directory instead.
  122. @item
  123. It loads the library @file{default}, if it exists. This is not done
  124. if @code{inhibit-default-init} is non-@code{nil}, nor if the options
  125. @samp{-q}, @samp{-Q}, or @samp{--batch} were specified.
  126. @cindex @file{default.el}
  127. @item
  128. It loads your abbrevs from the file specified by
  129. @code{abbrev-file-name}, if that file exists and can be read
  130. (@pxref{Abbrev Files, abbrev-file-name}). This is not done if the
  131. option @samp{--batch} was specified.
  132. @item
  133. If @code{package-enable-at-startup} is non-@code{nil}, it calls the
  134. function @code{package-initialize} to activate any optional Emacs Lisp
  135. package that has been installed. @xref{Packaging Basics}.
  136. @vindex after-init-time
  137. @item
  138. It sets the variable @code{after-init-time} to the value of
  139. @code{current-time}. This variable was set to @code{nil} earlier;
  140. setting it to the current time signals that the initialization phase
  141. is over, and, together with @code{before-init-time}, provides the
  142. measurement of how long it took.
  143. @item
  144. It runs the normal hook @code{after-init-hook}.
  145. @item
  146. If the buffer @file{*scratch*} exists and is still in Fundamental mode
  147. (as it should be by default), it sets its major mode according to
  148. @code{initial-major-mode}.
  149. @item
  150. If started on a text terminal, it loads the terminal-specific
  151. Lisp library (@pxref{Terminal-Specific}), and runs the hook
  152. @code{tty-setup-hook}. This is not done
  153. in @code{--batch} mode, nor if @code{term-file-prefix} is @code{nil}.
  154. @c Now command-line calls command-line-1.
  155. @item
  156. It displays the initial echo area message, unless you have suppressed
  157. that with @code{inhibit-startup-echo-area-message}.
  158. @item
  159. It processes any command-line options that were not handled earlier.
  160. @c This next one is back in command-line, but the remaining bits of
  161. @c command-line-1 are not done if noninteractive.
  162. @item
  163. It now exits if the option @code{--batch} was specified.
  164. @item
  165. If the @file{*scratch*} buffer exists and is empty, it inserts
  166. @code{(substitute-command-keys initial-scratch-message)} into that buffer.
  167. @item
  168. If @code{initial-buffer-choice} is a string, it visits the file (or
  169. directory) with that name. If it is a function, it calls the function
  170. with no arguments and selects the buffer that it returns. If one file
  171. is given as a command line argument, that file is visited and its
  172. buffer displayed alongside @code{initial-buffer-choice}. If more than
  173. one file is given, all of the files are visited and the @file{*Buffer
  174. List*} buffer is displayed alongside @code{initial-buffer-choice}.
  175. @ignore
  176. @c I do not think this should be mentioned. AFAICS it is just a dodge
  177. @c around inhibit-startup-screen not being settable on a site-wide basis.
  178. If it is @code{t}, it selects the @file{*scratch*} buffer.
  179. @end ignore
  180. @c To make things nice and confusing, the next three items can be
  181. @c called from two places. If displaying a startup screen, they are
  182. @c called in command-line-1 before the startup screen is shown.
  183. @c inhibit-startup-hooks is then set and window-setup-hook set to nil.
  184. @c If not displaying a startup screen, they are are called in
  185. @c normal-top-level.
  186. @c FIXME? So it seems they can be called before or after the
  187. @c daemon/session restore step?
  188. @item
  189. It runs @code{emacs-startup-hook}.
  190. @item
  191. It calls @code{frame-notice-user-settings}, which modifies the
  192. parameters of the selected frame according to whatever the init files
  193. specify.
  194. @item
  195. It runs @code{window-setup-hook}. The only difference between this
  196. hook and @code{emacs-startup-hook} is that this one runs after the
  197. previously mentioned modifications to the frame parameters.
  198. @item
  199. @cindex startup screen
  200. It displays the @dfn{startup screen}, which is a special buffer that
  201. contains information about copyleft and basic Emacs usage. This is
  202. not done if @code{inhibit-startup-screen} or @code{initial-buffer-choice}
  203. are non-@code{nil}, or if the @samp{--no-splash} or @samp{-Q} command-line
  204. options were specified.
  205. @c End of command-line-1.
  206. @c Back to command-line from command-line-1.
  207. @c This is the point at which we actually exit in batch mode, but the
  208. @c last few bits of command-line-1 are not done in batch mode.
  209. @item
  210. If the option @code{--daemon} was specified, it calls
  211. @code{server-start}, and on Posix systems also detaches from the
  212. controlling terminal. @xref{Emacs Server,,, emacs, The GNU Emacs
  213. Manual}.
  214. @item
  215. If started by the X session manager, it calls
  216. @code{emacs-session-restore} passing it as argument the ID of the
  217. previous session. @xref{Session Management}.
  218. @c End of command-line.
  219. @c Back to normal-top-level from command-line.
  220. @end enumerate
  221. @noindent
  222. The following options affect some aspects of the startup sequence.
  223. @defopt inhibit-startup-screen
  224. This variable, if non-@code{nil}, inhibits the startup screen. In
  225. that case, Emacs typically displays the @file{*scratch*} buffer; but
  226. see @code{initial-buffer-choice}, below.
  227. Do not set this variable in the init file of a new user, or in a way
  228. that affects more than one user, as that would prevent new users from
  229. receiving information about copyleft and basic Emacs usage.
  230. @vindex inhibit-startup-message
  231. @vindex inhibit-splash-screen
  232. @code{inhibit-startup-message} and @code{inhibit-splash-screen} are
  233. aliases for this variable.
  234. @end defopt
  235. @defopt initial-buffer-choice
  236. If non-@code{nil}, this variable is a string that specifies a file or
  237. directory for Emacs to display after starting up, instead of the
  238. startup screen.
  239. If its value is a function, Emacs calls that function which must
  240. return a buffer which is then displayed.
  241. If its value is @code{t}, Emacs displays the @file{*scratch*} buffer.
  242. @end defopt
  243. @defopt inhibit-startup-echo-area-message
  244. This variable controls the display of the startup echo area message.
  245. You can suppress the startup echo area message by adding text with this
  246. form to your init file:
  247. @example
  248. (setq inhibit-startup-echo-area-message
  249. "@var{your-login-name}")
  250. @end example
  251. Emacs explicitly checks for an expression as shown above in your init
  252. file; your login name must appear in the expression as a Lisp string
  253. constant. You can also use the Customize interface. Other methods of
  254. setting @code{inhibit-startup-echo-area-message} to the same value do
  255. not inhibit the startup message. This way, you can easily inhibit the
  256. message for yourself if you wish, but thoughtless copying of your init
  257. file will not inhibit the message for someone else.
  258. @end defopt
  259. @defopt initial-scratch-message
  260. This variable, if non-@code{nil}, should be a string, which is
  261. treated as documentation to be
  262. inserted into the @file{*scratch*} buffer when Emacs starts up. If it
  263. is @code{nil}, the @file{*scratch*} buffer is empty.
  264. @end defopt
  265. @noindent
  266. The following command-line options affect some aspects of the startup
  267. sequence. @xref{Initial Options,,, emacs, The GNU Emacs Manual}.
  268. @table @code
  269. @item --no-splash
  270. Do not display a splash screen.
  271. @item --batch
  272. Run without an interactive terminal. @xref{Batch Mode}.
  273. @item --daemon
  274. Do not initialize any display; just start a server in the background.
  275. @item --no-init-file
  276. @itemx -q
  277. Do not load either the init file, or the @file{default} library.
  278. @item --no-site-file
  279. Do not load the @file{site-start} library.
  280. @item --quick
  281. @itemx -Q
  282. Equivalent to @samp{-q --no-site-file --no-splash}.
  283. @c and --no-site-lisp, but let's not mention that here.
  284. @end table
  285. @node Init File
  286. @subsection The Init File
  287. @cindex init file
  288. @cindex @file{.emacs}
  289. @cindex @file{init.el}
  290. When you start Emacs, it normally attempts to load your @dfn{init
  291. file}. This is either a file named @file{.emacs} or @file{.emacs.el}
  292. in your home directory, or a file named @file{init.el} in a
  293. subdirectory named @file{.emacs.d} in your home directory.
  294. @ignore
  295. Whichever place you use, you can also compile the file (@pxref{Byte
  296. Compilation}); then the actual file loaded will be @file{.emacs.elc}
  297. or @file{init.elc}.
  298. @end ignore
  299. The command-line switches @samp{-q}, @samp{-Q}, and @samp{-u}
  300. control whether and where to find the init file; @samp{-q} (and the
  301. stronger @samp{-Q}) says not to load an init file, while @samp{-u
  302. @var{user}} says to load @var{user}'s init file instead of yours.
  303. @xref{Entering Emacs,,, emacs, The GNU Emacs Manual}. If neither
  304. option is specified, Emacs uses the @env{LOGNAME} environment
  305. variable, or the @env{USER} (most systems) or @env{USERNAME} (MS
  306. systems) variable, to find your home directory and thus your init
  307. file; this way, even if you have su'd, Emacs still loads your own init
  308. file. If those environment variables are absent, though, Emacs uses
  309. your user-id to find your home directory.
  310. @cindex default init file
  311. An Emacs installation may have a @dfn{default init file}, which is a
  312. Lisp library named @file{default.el}. Emacs finds this file through
  313. the standard search path for libraries (@pxref{How Programs Do
  314. Loading}). The Emacs distribution does not come with this file; it is
  315. intended for local customizations. If the default init file exists,
  316. it is loaded whenever you start Emacs. But your own personal init
  317. file, if any, is loaded first; if it sets @code{inhibit-default-init}
  318. to a non-@code{nil} value, then Emacs does not subsequently load the
  319. @file{default.el} file. In batch mode, or if you specify @samp{-q}
  320. (or @samp{-Q}), Emacs loads neither your personal init file nor
  321. the default init file.
  322. Another file for site-customization is @file{site-start.el}. Emacs
  323. loads this @emph{before} the user's init file. You can inhibit the
  324. loading of this file with the option @samp{--no-site-file}.
  325. @defopt site-run-file
  326. This variable specifies the site-customization file to load before the
  327. user's init file. Its normal value is @code{"site-start"}. The only
  328. way you can change it with real effect is to do so before dumping
  329. Emacs.
  330. @c So why even mention it here. I imagine it is almost never changed.
  331. @end defopt
  332. @xref{Init Examples,, Init File Examples, emacs, The GNU Emacs Manual}, for
  333. examples of how to make various commonly desired customizations in your
  334. @file{.emacs} file.
  335. @defopt inhibit-default-init
  336. If this variable is non-@code{nil}, it prevents Emacs from loading the
  337. default initialization library file. The default value is @code{nil}.
  338. @end defopt
  339. @defvar before-init-hook
  340. This normal hook is run, once, just before loading all the init files
  341. (@file{site-start.el}, your init file, and @file{default.el}).
  342. (The only way to change it with real effect is before dumping Emacs.)
  343. @end defvar
  344. @defvar after-init-hook
  345. This normal hook is run, once, just after loading all the init files
  346. (@file{site-start.el}, your init file, and @file{default.el}),
  347. before loading the terminal-specific library (if started on a text
  348. terminal) and processing the command-line action arguments.
  349. @end defvar
  350. @defvar emacs-startup-hook
  351. This normal hook is run, once, just after handling the command line
  352. arguments. In batch mode, Emacs does not run this hook.
  353. @end defvar
  354. @defvar window-setup-hook
  355. This normal hook is very similar to @code{emacs-startup-hook}.
  356. The only difference is that it runs slightly later, after setting
  357. of the frame parameters. @xref{Startup Summary, window-setup-hook}.
  358. @end defvar
  359. @defvar user-init-file
  360. This variable holds the absolute file name of the user's init file. If the
  361. actual init file loaded is a compiled file, such as @file{.emacs.elc},
  362. the value refers to the corresponding source file.
  363. @end defvar
  364. @defvar user-emacs-directory
  365. This variable holds the name of the @file{.emacs.d} directory. It is
  366. @file{~/.emacs.d} on all platforms but MS-DOS.
  367. @end defvar
  368. @node Terminal-Specific
  369. @subsection Terminal-Specific Initialization
  370. @cindex terminal-specific initialization
  371. Each terminal type can have its own Lisp library that Emacs loads when
  372. run on that type of terminal. The library's name is constructed by
  373. concatenating the value of the variable @code{term-file-prefix} and the
  374. terminal type (specified by the environment variable @env{TERM}).
  375. Normally, @code{term-file-prefix} has the value @code{"term/"};
  376. changing this is not recommended. If there is an entry matching
  377. @env{TERM} in the @code{term-file-aliases} association list,
  378. Emacs uses the associated value in place of @env{TERM}.
  379. Emacs finds the file in the normal manner, by searching the
  380. @code{load-path} directories, and trying the @samp{.elc} and
  381. @samp{.el} suffixes.
  382. @cindex Termcap
  383. The usual role of a terminal-specific library is to enable special
  384. keys to send sequences that Emacs can recognize. It may also need to
  385. set or add to @code{input-decode-map} if the Termcap or Terminfo entry
  386. does not specify all the terminal's function keys. @xref{Terminal Input}.
  387. When the name of the terminal type contains a hyphen or underscore,
  388. and no library is found whose name is identical to the terminal's
  389. name, Emacs strips from the terminal's name the last hyphen or
  390. underscore and everything that follows
  391. it, and tries again. This process is repeated until Emacs finds a
  392. matching library, or until there are no more hyphens or underscores in the name
  393. (i.e., there is no terminal-specific library). For example, if the
  394. terminal name is @samp{xterm-256color} and there is no
  395. @file{term/xterm-256color.el} library, Emacs tries to load
  396. @file{term/xterm.el}. If necessary, the terminal library can evaluate
  397. @code{(getenv "TERM")} to find the full name of the terminal type.
  398. Your init file can prevent the loading of the terminal-specific
  399. library by setting the variable @code{term-file-prefix} to @code{nil}.
  400. You can also arrange to override some of the actions of the
  401. terminal-specific library by using @code{tty-setup-hook}. This is
  402. a normal hook that Emacs runs after initializing a new text terminal.
  403. You could use this hook to define initializations for terminals that do not
  404. have their own libraries. @xref{Hooks}.
  405. @defopt term-file-prefix
  406. @cindex @env{TERM} environment variable
  407. If the value of this variable is non-@code{nil}, Emacs loads a
  408. terminal-specific initialization file as follows:
  409. @example
  410. (load (concat term-file-prefix (getenv "TERM")))
  411. @end example
  412. @noindent
  413. You may set the @code{term-file-prefix} variable to @code{nil} in your
  414. init file if you do not wish to load the
  415. terminal-initialization file.
  416. On MS-DOS, Emacs sets the @env{TERM} environment variable to @samp{internal}.
  417. @end defopt
  418. @defopt term-file-aliases
  419. This variable is an an association list mapping terminal types to
  420. their aliases. For example, an element of the form @code{("vt102"
  421. . "vt100")} means to treat a terminal of type @samp{vt102} like one of
  422. type @samp{vt100}.
  423. @end defopt
  424. @defvar tty-setup-hook
  425. This variable is a normal hook that Emacs runs after initializing a
  426. new text terminal. (This applies when Emacs starts up in non-windowed
  427. mode, and when making a tty @command{emacsclient} connection.) The
  428. hook runs after loading your init file (if applicable) and the
  429. terminal-specific Lisp file, so you can use it to adjust the
  430. definitions made by that file.
  431. For a related feature, @pxref{Init File, window-setup-hook}.
  432. @end defvar
  433. @node Command-Line Arguments
  434. @subsection Command-Line Arguments
  435. @cindex command-line arguments
  436. You can use command-line arguments to request various actions when
  437. you start Emacs. Note that the recommended way of using Emacs is to
  438. start it just once, after logging in, and then do all editing in the same
  439. Emacs session (@pxref{Entering Emacs,,, emacs, The GNU Emacs Manual}).
  440. For this reason, you might not use command-line arguments very often;
  441. nonetheless, they can be useful when invoking Emacs from session
  442. scripts or debugging Emacs. This section describes how Emacs
  443. processes command-line arguments.
  444. @defun command-line
  445. This function parses the command line that Emacs was called with,
  446. processes it, and (amongst other things) loads the user's init file and
  447. displays the startup messages.
  448. @end defun
  449. @defvar command-line-processed
  450. The value of this variable is @code{t} once the command line has been
  451. processed.
  452. If you redump Emacs by calling @code{dump-emacs} (@pxref{Building
  453. Emacs}), you may wish to set this variable to @code{nil} first in
  454. order to cause the new dumped Emacs to process its new command-line
  455. arguments.
  456. @end defvar
  457. @defvar command-switch-alist
  458. @cindex switches on command line
  459. @cindex options on command line
  460. @cindex command-line options
  461. This variable is an alist of user-defined command-line options and
  462. associated handler functions. By default it is empty, but you can
  463. add elements if you wish.
  464. A @dfn{command-line option} is an argument on the command line, which
  465. has the form:
  466. @example
  467. -@var{option}
  468. @end example
  469. The elements of the @code{command-switch-alist} look like this:
  470. @example
  471. (@var{option} . @var{handler-function})
  472. @end example
  473. The @sc{car}, @var{option}, is a string, the name of a command-line
  474. option (not including the initial hyphen). The @var{handler-function}
  475. is called to handle @var{option}, and receives the option name as its
  476. sole argument.
  477. In some cases, the option is followed in the command line by an
  478. argument. In these cases, the @var{handler-function} can find all the
  479. remaining command-line arguments in the variable
  480. @code{command-line-args-left} (see below). (The entire list of
  481. command-line arguments is in @code{command-line-args}.)
  482. The command-line arguments are parsed by the @code{command-line-1}
  483. function in the @file{startup.el} file. See also @ref{Emacs
  484. Invocation, , Command Line Arguments for Emacs Invocation, emacs, The
  485. GNU Emacs Manual}.
  486. @end defvar
  487. @defvar command-line-args
  488. The value of this variable is the list of command-line arguments passed
  489. to Emacs.
  490. @end defvar
  491. @defvar command-line-args-left
  492. @vindex argv
  493. The value of this variable is the list of command-line arguments that
  494. have not yet been processed.
  495. @c Don't mention this, since it is a "bad name for a dynamically bound variable"
  496. @c @code{argv} is an alias for this.
  497. @end defvar
  498. @defvar command-line-functions
  499. This variable's value is a list of functions for handling an
  500. unrecognized command-line argument. Each time the next argument to be
  501. processed has no special meaning, the functions in this list are called,
  502. in order of appearance, until one of them returns a non-@code{nil}
  503. value.
  504. These functions are called with no arguments. They can access the
  505. command-line argument under consideration through the variable
  506. @code{argi}, which is bound temporarily at this point. The remaining
  507. arguments (not including the current one) are in the variable
  508. @code{command-line-args-left}.
  509. When a function recognizes and processes the argument in @code{argi}, it
  510. should return a non-@code{nil} value to say it has dealt with that
  511. argument. If it has also dealt with some of the following arguments, it
  512. can indicate that by deleting them from @code{command-line-args-left}.
  513. If all of these functions return @code{nil}, then the argument is treated
  514. as a file name to visit.
  515. @end defvar
  516. @node Getting Out
  517. @section Getting Out of Emacs
  518. @cindex exiting Emacs
  519. There are two ways to get out of Emacs: you can kill the Emacs job,
  520. which exits permanently, or you can suspend it, which permits you to
  521. reenter the Emacs process later. (In a graphical environment, you can
  522. of course simply switch to another application without doing anything
  523. special to Emacs, then switch back to Emacs when you want.)
  524. @menu
  525. * Killing Emacs:: Exiting Emacs irreversibly.
  526. * Suspending Emacs:: Exiting Emacs reversibly.
  527. @end menu
  528. @node Killing Emacs
  529. @subsection Killing Emacs
  530. @cindex killing Emacs
  531. Killing Emacs means ending the execution of the Emacs process.
  532. If you started Emacs from a terminal, the parent process normally
  533. resumes control. The low-level primitive for killing Emacs is
  534. @code{kill-emacs}.
  535. @deffn Command kill-emacs &optional exit-data
  536. This command calls the hook @code{kill-emacs-hook}, then exits the
  537. Emacs process and kills it.
  538. If @var{exit-data} is an integer, that is used as the exit status of
  539. the Emacs process. (This is useful primarily in batch operation; see
  540. @ref{Batch Mode}.)
  541. If @var{exit-data} is a string, its contents are stuffed into the
  542. terminal input buffer so that the shell (or whatever program next reads
  543. input) can read them.
  544. @end deffn
  545. @cindex SIGTERM
  546. @cindex SIGHUP
  547. @cindex SIGINT
  548. @cindex operating system signal
  549. The @code{kill-emacs} function is normally called via the
  550. higher-level command @kbd{C-x C-c}
  551. (@code{save-buffers-kill-terminal}). @xref{Exiting,,, emacs, The GNU
  552. Emacs Manual}. It is also called automatically if Emacs receives a
  553. @code{SIGTERM} or @code{SIGHUP} operating system signal (e.g., when the
  554. controlling terminal is disconnected), or if it receives a
  555. @code{SIGINT} signal while running in batch mode (@pxref{Batch Mode}).
  556. @defvar kill-emacs-hook
  557. This normal hook is run by @code{kill-emacs}, before it kills Emacs.
  558. Because @code{kill-emacs} can be called in situations where user
  559. interaction is impossible (e.g., when the terminal is disconnected),
  560. functions on this hook should not attempt to interact with the user.
  561. If you want to interact with the user when Emacs is shutting down, use
  562. @code{kill-emacs-query-functions}, described below.
  563. @end defvar
  564. When Emacs is killed, all the information in the Emacs process,
  565. aside from files that have been saved, is lost. Because killing Emacs
  566. inadvertently can lose a lot of work, the
  567. @code{save-buffers-kill-terminal} command queries for confirmation if
  568. you have buffers that need saving or subprocesses that are running.
  569. It also runs the abnormal hook @code{kill-emacs-query-functions}:
  570. @defvar kill-emacs-query-functions
  571. When @code{save-buffers-kill-terminal} is killing Emacs, it calls the
  572. functions in this hook, after asking the standard questions and before
  573. calling @code{kill-emacs}. The functions are called in order of
  574. appearance, with no arguments. Each function can ask for additional
  575. confirmation from the user. If any of them returns @code{nil},
  576. @code{save-buffers-kill-emacs} does not kill Emacs, and does not run
  577. the remaining functions in this hook. Calling @code{kill-emacs}
  578. directly does not run this hook.
  579. @end defvar
  580. @node Suspending Emacs
  581. @subsection Suspending Emacs
  582. @cindex suspending Emacs
  583. On text terminals, it is possible to @dfn{suspend Emacs}, which
  584. means stopping Emacs temporarily and returning control to its superior
  585. process, which is usually the shell. This allows you to resume
  586. editing later in the same Emacs process, with the same buffers, the
  587. same kill ring, the same undo history, and so on. To resume Emacs,
  588. use the appropriate command in the parent shell---most likely
  589. @code{fg}.
  590. @cindex controlling terminal
  591. Suspending works only on a terminal device from which the Emacs
  592. session was started. We call that device the @dfn{controlling
  593. terminal} of the session. Suspending is not allowed if the
  594. controlling terminal is a graphical terminal. Suspending is usually
  595. not relevant in graphical environments, since you can simply switch to
  596. another application without doing anything special to Emacs.
  597. @c FIXME? Are there any systems Emacs still supports that do not
  598. @c have SIGTSTP?
  599. @cindex SIGTSTP
  600. Some operating systems (those without @code{SIGTSTP}, or MS-DOS) do
  601. not support suspension of jobs; on these systems, suspension
  602. actually creates a new shell temporarily as a subprocess of Emacs.
  603. Then you would exit the shell to return to Emacs.
  604. @deffn Command suspend-emacs &optional string
  605. This function stops Emacs and returns control to the superior process.
  606. If and when the superior process resumes Emacs, @code{suspend-emacs}
  607. returns @code{nil} to its caller in Lisp.
  608. This function works only on the controlling terminal of the Emacs
  609. session; to relinquish control of other tty devices, use
  610. @code{suspend-tty} (see below). If the Emacs session uses more than
  611. one terminal, you must delete the frames on all the other terminals
  612. before suspending Emacs, or this function signals an error.
  613. @xref{Multiple Terminals}.
  614. If @var{string} is non-@code{nil}, its characters are sent to Emacs's
  615. superior shell, to be read as terminal input.
  616. @c FIXME? It seems to me that shell does echo STRING.
  617. The characters in @var{string} are not echoed by the superior shell;
  618. only the results appear.
  619. Before suspending, @code{suspend-emacs} runs the normal hook
  620. @code{suspend-hook}. After the user resumes Emacs,
  621. @code{suspend-emacs} runs the normal hook @code{suspend-resume-hook}.
  622. @xref{Hooks}.
  623. The next redisplay after resumption will redraw the entire screen,
  624. unless the variable @code{no-redraw-on-reenter} is non-@code{nil}.
  625. @xref{Refresh Screen}.
  626. Here is an example of how you could use these hooks:
  627. @smallexample
  628. @group
  629. (add-hook 'suspend-hook
  630. (lambda () (or (y-or-n-p "Really suspend? ")
  631. (error "Suspend canceled"))))
  632. @end group
  633. (add-hook 'suspend-resume-hook (lambda () (message "Resumed!")
  634. (sit-for 2)))
  635. @end smallexample
  636. @c The sit-for prevents the @code{nil} that suspend-emacs returns
  637. @c hiding the message.
  638. Here is what you would see upon evaluating @code{(suspend-emacs "pwd")}:
  639. @smallexample
  640. @group
  641. ---------- Buffer: Minibuffer ----------
  642. Really suspend? @kbd{y}
  643. ---------- Buffer: Minibuffer ----------
  644. @end group
  645. @group
  646. ---------- Parent Shell ----------
  647. bash$ /home/username
  648. bash$ fg
  649. @end group
  650. @group
  651. ---------- Echo Area ----------
  652. Resumed!
  653. @end group
  654. @end smallexample
  655. @c FIXME? AFAICS, it is echoed.
  656. Note that @samp{pwd} is not echoed after Emacs is suspended. But it
  657. is read and executed by the shell.
  658. @end deffn
  659. @defvar suspend-hook
  660. This variable is a normal hook that Emacs runs before suspending.
  661. @end defvar
  662. @defvar suspend-resume-hook
  663. This variable is a normal hook that Emacs runs on resuming
  664. after a suspension.
  665. @end defvar
  666. @defun suspend-tty &optional tty
  667. If @var{tty} specifies a terminal device used by Emacs, this function
  668. relinquishes the device and restores it to its prior state. Frames
  669. that used the device continue to exist, but are not updated and Emacs
  670. doesn't read input from them. @var{tty} can be a terminal object, a
  671. frame (meaning the terminal for that frame), or @code{nil} (meaning
  672. the terminal for the selected frame). @xref{Multiple Terminals}.
  673. If @var{tty} is already suspended, this function does nothing.
  674. @vindex suspend-tty-functions
  675. This function runs the hook @code{suspend-tty-functions}, passing the
  676. terminal object as an argument to each function.
  677. @end defun
  678. @defun resume-tty &optional tty
  679. This function resumes the previously suspended terminal device
  680. @var{tty}; where @var{tty} has the same possible values as it does
  681. for @code{suspend-tty}.
  682. @vindex resume-tty-functions
  683. This function reopens the terminal device, re-initializes it, and
  684. redraws it with that terminal's selected frame. It then runs the
  685. hook @code{resume-tty-functions}, passing the terminal object as an
  686. argument to each function.
  687. If the same device is already used by another Emacs terminal, this
  688. function signals an error. If @var{tty} is not suspended, this
  689. function does nothing.
  690. @end defun
  691. @defun controlling-tty-p &optional tty
  692. This function returns non-@code{nil} if @var{tty} is the
  693. controlling terminal of the Emacs session; @var{tty} can be a
  694. terminal object, a frame (meaning the terminal for that frame), or
  695. @code{nil} (meaning the terminal for the selected frame).
  696. @end defun
  697. @deffn Command suspend-frame
  698. This command @dfn{suspends} a frame. For GUI frames, it calls
  699. @code{iconify-frame} (@pxref{Visibility of Frames}); for frames on
  700. text terminals, it calls either @code{suspend-emacs} or
  701. @code{suspend-tty}, depending on whether the frame is displayed on the
  702. controlling terminal device or not.
  703. @end deffn
  704. @node System Environment
  705. @section Operating System Environment
  706. @cindex operating system environment
  707. Emacs provides access to variables in the operating system environment
  708. through various functions. These variables include the name of the
  709. system, the user's @acronym{UID}, and so on.
  710. @defvar system-configuration
  711. This variable holds the standard GNU configuration name for the
  712. hardware/software configuration of your system, as a string. For
  713. example, a typical value for a 64-bit GNU/Linux system is
  714. @samp{"x86_64-unknown-linux-gnu"}.
  715. @end defvar
  716. @cindex system type and name
  717. @defvar system-type
  718. The value of this variable is a symbol indicating the type of operating
  719. system Emacs is running on. The possible values are:
  720. @table @code
  721. @item aix
  722. IBM's AIX.
  723. @item berkeley-unix
  724. Berkeley BSD and its variants.
  725. @item cygwin
  726. Cygwin, a Posix layer on top of MS-Windows.
  727. @item darwin
  728. Darwin (Mac OS X).
  729. @item gnu
  730. The GNU system (using the GNU kernel, which consists of the HURD and Mach).
  731. @item gnu/linux
  732. A GNU/Linux system---that is, a variant GNU system, using the Linux
  733. kernel. (These systems are the ones people often call ``Linux'', but
  734. actually Linux is just the kernel, not the whole system.)
  735. @item gnu/kfreebsd
  736. A GNU (glibc-based) system with a FreeBSD kernel.
  737. @item hpux
  738. Hewlett-Packard HPUX operating system.
  739. @item nacl
  740. Google Native Client (@acronym{NaCl}) sandboxing system.
  741. @item ms-dos
  742. Microsoft's DOS@. Emacs compiled with DJGPP for MS-DOS binds
  743. @code{system-type} to @code{ms-dos} even when you run it on MS-Windows.
  744. @item usg-unix-v
  745. AT&T Unix System V.
  746. @item windows-nt
  747. Microsoft Windows NT, 9X and later. The value of @code{system-type}
  748. is always @code{windows-nt}, e.g., even on Windows 10.
  749. @end table
  750. We do not wish to add new symbols to make finer distinctions unless it
  751. is absolutely necessary! In fact, we hope to eliminate some of these
  752. alternatives in the future. If you need to make a finer distinction
  753. than @code{system-type} allows for, you can test
  754. @code{system-configuration}, e.g., against a regexp.
  755. @end defvar
  756. @defun system-name
  757. This function returns the name of the machine you are running on, as a
  758. string.
  759. @end defun
  760. @c FIXME seems like this section is not the best place for this option?
  761. @defopt mail-host-address
  762. If this variable is non-@code{nil}, it is used instead of
  763. @code{system-name} for purposes of generating email addresses. For
  764. example, it is used when constructing the default value of
  765. @code{user-mail-address}. @xref{User Identification}. (Since this is
  766. done when Emacs starts up, the value actually used is the one saved when
  767. Emacs was dumped. @xref{Building Emacs}.)
  768. @c FIXME sounds like should probably give this a :set-after and some
  769. @c custom-initialize-delay voodoo.
  770. @end defopt
  771. @deffn Command getenv var &optional frame
  772. @cindex environment variable access
  773. This function returns the value of the environment variable @var{var},
  774. as a string. @var{var} should be a string. If @var{var} is undefined
  775. in the environment, @code{getenv} returns @code{nil}. It returns
  776. @samp{""} if @var{var} is set but null. Within Emacs, a list of environment
  777. variables and their values is kept in the variable @code{process-environment}.
  778. @example
  779. @group
  780. (getenv "USER")
  781. @result{} "lewis"
  782. @end group
  783. @end example
  784. The shell command @code{printenv} prints all or part of the environment:
  785. @example
  786. @group
  787. bash$ printenv
  788. PATH=/usr/local/bin:/usr/bin:/bin
  789. USER=lewis
  790. @end group
  791. @group
  792. TERM=xterm
  793. SHELL=/bin/bash
  794. HOME=/home/lewis
  795. @end group
  796. @dots{}
  797. @end example
  798. @end deffn
  799. @deffn Command setenv variable &optional value substitute
  800. This command sets the value of the environment variable named
  801. @var{variable} to @var{value}. @var{variable} should be a string.
  802. Internally, Emacs Lisp can handle any string. However, normally
  803. @var{variable} should be a valid shell identifier, that is, a sequence
  804. of letters, digits and underscores, starting with a letter or
  805. underscore. Otherwise, errors may occur if subprocesses of Emacs try
  806. to access the value of @var{variable}. If @var{value} is omitted or
  807. @code{nil} (or, interactively, with a prefix argument), @code{setenv}
  808. removes @var{variable} from the environment. Otherwise, @var{value}
  809. should be a string.
  810. @c FIXME: Document 'substitute-env-vars'? --xfq
  811. If the optional argument @var{substitute} is non-@code{nil}, Emacs
  812. calls the function @code{substitute-env-vars} to expand any
  813. environment variables in @var{value}.
  814. @code{setenv} works by modifying @code{process-environment}; binding
  815. that variable with @code{let} is also reasonable practice.
  816. @code{setenv} returns the new value of @var{variable}, or @code{nil}
  817. if it removed @var{variable} from the environment.
  818. @end deffn
  819. @defvar process-environment
  820. This variable is a list of strings, each describing one environment
  821. variable. The functions @code{getenv} and @code{setenv} work by means
  822. of this variable.
  823. @smallexample
  824. @group
  825. process-environment
  826. @result{} ("PATH=/usr/local/bin:/usr/bin:/bin"
  827. "USER=lewis"
  828. @end group
  829. @group
  830. "TERM=xterm"
  831. "SHELL=/bin/bash"
  832. "HOME=/home/lewis"
  833. @dots{})
  834. @end group
  835. @end smallexample
  836. If @code{process-environment} contains multiple elements that
  837. specify the same environment variable, the first of these elements
  838. specifies the variable, and the others are ignored.
  839. @end defvar
  840. @defvar initial-environment
  841. This variable holds the list of environment variables Emacs inherited
  842. from its parent process when Emacs started.
  843. @end defvar
  844. @defvar path-separator
  845. This variable holds a string that says which character separates
  846. directories in a search path (as found in an environment variable). Its
  847. value is @code{":"} for Unix and GNU systems, and @code{";"} for MS systems.
  848. @end defvar
  849. @defun parse-colon-path path
  850. This function takes a search path string such as the value of
  851. the @env{PATH} environment variable, and splits it at the separators,
  852. returning a list of directory names. @code{nil} in this list means
  853. the current directory. Although the function's name says
  854. ``colon'', it actually uses the value of @code{path-separator}.
  855. @example
  856. (parse-colon-path ":/foo:/bar")
  857. @result{} (nil "/foo/" "/bar/")
  858. @end example
  859. @end defun
  860. @defvar invocation-name
  861. This variable holds the program name under which Emacs was invoked. The
  862. value is a string, and does not include a directory name.
  863. @end defvar
  864. @defvar invocation-directory
  865. This variable holds the directory from which the Emacs executable was
  866. invoked, or @code{nil} if that directory cannot be determined.
  867. @end defvar
  868. @defvar installation-directory
  869. If non-@code{nil}, this is a directory within which to look for the
  870. @file{lib-src} and @file{etc} subdirectories. In an installed Emacs,
  871. it is normally @code{nil}. It is non-@code{nil}
  872. when Emacs can't find those directories in their standard installed
  873. locations, but can find them in a directory related somehow to the one
  874. containing the Emacs executable (i.e., @code{invocation-directory}).
  875. @end defvar
  876. @defun load-average &optional use-float
  877. This function returns the current 1-minute, 5-minute, and 15-minute
  878. system load averages, in a list. The load average indicates the
  879. number of processes trying to run on the system.
  880. By default, the values are integers that are 100 times the system load
  881. averages, but if @var{use-float} is non-@code{nil}, then they are
  882. returned as floating-point numbers without multiplying by 100.
  883. If it is impossible to obtain the load average, this function signals
  884. an error. On some platforms, access to load averages requires
  885. installing Emacs as setuid or setgid so that it can read kernel
  886. information, and that usually isn't advisable.
  887. @c FIXME which platforms are these? Are they still relevant?
  888. If the 1-minute load average is available, but the 5- or 15-minute
  889. averages are not, this function returns a shortened list containing
  890. the available averages.
  891. @example
  892. @group
  893. (load-average)
  894. @result{} (169 48 36)
  895. @end group
  896. @group
  897. (load-average t)
  898. @result{} (1.69 0.48 0.36)
  899. @end group
  900. @end example
  901. The shell command @code{uptime} returns similar information.
  902. @end defun
  903. @defun emacs-pid
  904. This function returns the process @acronym{ID} of the Emacs process,
  905. as an integer.
  906. @end defun
  907. @defvar tty-erase-char
  908. This variable holds the erase character that was selected
  909. in the system's terminal driver, before Emacs was started.
  910. @c FIXME? Seems untrue since 23.1. For me, it is 0.
  911. @c The value is @code{nil} if Emacs is running under a window system.
  912. @end defvar
  913. @node User Identification
  914. @section User Identification
  915. @cindex user identification
  916. @defvar init-file-user
  917. This variable says which user's init files should be used by
  918. Emacs---or @code{nil} if none. @code{""} stands for the user who
  919. originally logged in. The value reflects command-line options such as
  920. @samp{-q} or @samp{-u @var{user}}.
  921. Lisp packages that load files of customizations, or any other sort of
  922. user profile, should obey this variable in deciding where to find it.
  923. They should load the profile of the user name found in this variable.
  924. If @code{init-file-user} is @code{nil}, meaning that the @samp{-q},
  925. @samp{-Q}, or @samp{-batch} option was used, then Lisp packages should
  926. not load any customization files or user profile.
  927. @end defvar
  928. @defopt user-mail-address
  929. This holds the nominal email address of the user who is using Emacs.
  930. Emacs normally sets this variable to a default value after reading your
  931. init files, but not if you have already set it. So you can set the
  932. variable to some other value in your init file if you do not
  933. want to use the default value.
  934. @end defopt
  935. @defun user-login-name &optional uid
  936. This function returns the name under which the user is logged in.
  937. It uses the environment variables @env{LOGNAME} or @env{USER} if
  938. either is set. Otherwise, the value is based on the effective
  939. @acronym{UID}, not the real @acronym{UID}.
  940. If you specify @var{uid} (a number), the result is the user name that
  941. corresponds to @var{uid}, or @code{nil} if there is no such user.
  942. @end defun
  943. @defun user-real-login-name
  944. This function returns the user name corresponding to Emacs's real
  945. @acronym{UID}. This ignores the effective @acronym{UID}, and the
  946. environment variables @env{LOGNAME} and @env{USER}.
  947. @end defun
  948. @defun user-full-name &optional uid
  949. This function returns the full name of the logged-in user---or the value
  950. of the environment variable @env{NAME}, if that is set.
  951. If the Emacs process's user-id does not correspond to any known user (and
  952. provided @code{NAME} is not set), the result is @code{"unknown"}.
  953. If @var{uid} is non-@code{nil}, then it should be a number (a user-id)
  954. or a string (a login name). Then @code{user-full-name} returns the full
  955. name corresponding to that user-id or login name. If you specify a
  956. user-id or login name that isn't defined, it returns @code{nil}.
  957. @end defun
  958. @vindex user-full-name
  959. @vindex user-real-login-name
  960. @vindex user-login-name
  961. The symbols @code{user-login-name}, @code{user-real-login-name} and
  962. @code{user-full-name} are variables as well as functions. The functions
  963. return the same values that the variables hold. These variables allow
  964. you to fake out Emacs by telling the functions what to return. The
  965. variables are also useful for constructing frame titles (@pxref{Frame
  966. Titles}).
  967. @cindex UID
  968. @defun user-real-uid
  969. This function returns the real @acronym{UID} of the user.
  970. The value may be floating point, in the (unlikely) event that
  971. the UID is too large to fit in a Lisp integer.
  972. @end defun
  973. @defun user-uid
  974. This function returns the effective @acronym{UID} of the user.
  975. The value may be floating point.
  976. @end defun
  977. @cindex GID
  978. @defun group-gid
  979. This function returns the effective @acronym{GID} of the Emacs process.
  980. The value may be floating point.
  981. @end defun
  982. @defun group-real-gid
  983. This function returns the real @acronym{GID} of the Emacs process.
  984. The value may be floating point.
  985. @end defun
  986. @defun system-users
  987. This function returns a list of strings, listing the user names on the
  988. system. If Emacs cannot retrieve this information, the return value
  989. is a list containing just the value of @code{user-real-login-name}.
  990. @end defun
  991. @cindex user groups
  992. @defun system-groups
  993. This function returns a list of strings, listing the names of user
  994. groups on the system. If Emacs cannot retrieve this information, the
  995. return value is @code{nil}.
  996. @end defun
  997. @node Time of Day
  998. @section Time of Day
  999. @cindex time of day
  1000. This section explains how to determine the current time and time
  1001. zone.
  1002. @cindex epoch
  1003. Most of these functions represent time as a list of four integers
  1004. @code{(@var{sec-high} @var{sec-low} @var{microsec} @var{picosec})}.
  1005. This represents the number of seconds from the @dfn{epoch} (January
  1006. 1, 1970 at 00:00 UTC), using the formula:
  1007. @ifnottex
  1008. @var{high} * 2**16 + @var{low} + @var{micro} * 10**@minus{}6 +
  1009. @var{pico} * 10**@minus{}12.
  1010. @end ifnottex
  1011. @tex
  1012. $high*2^{16} + low + micro*10^{-6} + pico*10^{-12}$.
  1013. @end tex
  1014. The return value of @code{current-time} represents time using this
  1015. form, as do the timestamps in the return values of other functions
  1016. such as @code{file-attributes} (@pxref{Definition of
  1017. file-attributes}). In some cases, functions may return two- or
  1018. three-element lists, with omitted @var{microsec} and @var{picosec}
  1019. components defaulting to zero.
  1020. @cindex time value
  1021. Function arguments, e.g., the @var{time} argument to
  1022. @code{current-time-string}, accept a more-general @dfn{time value}
  1023. format, which can be a list of integers as above, or a single number
  1024. for seconds since the epoch, or @code{nil} for the current time. You
  1025. can convert a time value into a human-readable string using
  1026. @code{current-time-string} and @code{format-time-string}, into a list
  1027. of integers using @code{seconds-to-time}, and into other forms using
  1028. @code{decode-time} and @code{float-time}. These functions are
  1029. described in the following sections.
  1030. @defun current-time-string &optional time zone
  1031. This function returns the current time and date as a human-readable
  1032. string. The format does not vary for the initial part of the string,
  1033. which contains the day of week, month, day of month, and time of day
  1034. in that order: the number of characters used for these fields is
  1035. always the same, so you can reliably
  1036. use @code{substring} to extract them. You should count
  1037. characters from the beginning of the string rather than from the end,
  1038. as the year might not have exactly four digits, and additional
  1039. information may some day be added at the end.
  1040. The argument @var{time}, if given, specifies a time to format,
  1041. instead of the current time. The optional argument @var{zone}
  1042. defaults to the current time zone rule.
  1043. @example
  1044. @group
  1045. (current-time-string)
  1046. @result{} "Wed Oct 14 22:21:05 1987"
  1047. @end group
  1048. @end example
  1049. @end defun
  1050. @defun current-time
  1051. This function returns the current time, represented as a list of four
  1052. integers @code{(@var{sec-high} @var{sec-low} @var{microsec} @var{picosec})}.
  1053. These integers have trailing zeros on systems that return time with
  1054. lower resolutions. On all current machines @var{picosec} is a
  1055. multiple of 1000, but this may change as higher-resolution clocks
  1056. become available.
  1057. @end defun
  1058. @defun float-time &optional time
  1059. This function returns the current time as a floating-point number of
  1060. seconds since the epoch. The optional argument @var{time}, if
  1061. given, specifies a time to convert instead of the current time.
  1062. @emph{Warning}: Since the result is floating point, it may not be
  1063. exact. Do not use this function if precise time stamps are required.
  1064. @code{time-to-seconds} is an alias for this function.
  1065. @end defun
  1066. @defun seconds-to-time time
  1067. This function converts a time value to list-of-integer form.
  1068. For example, if @var{time} is a number, @code{(time-to-seconds
  1069. (seconds-to-time @var{time}))} equals the number unless overflow
  1070. or rounding errors occur.
  1071. @end defun
  1072. @defun current-time-zone &optional time zone
  1073. @cindex time zone, current
  1074. This function returns a list describing the time zone that the user is
  1075. in.
  1076. The value has the form @code{(@var{offset} @var{name})}. Here
  1077. @var{offset} is an integer giving the number of seconds ahead of Universal Time
  1078. (east of Greenwich). A negative value means west of Greenwich. The
  1079. second element, @var{name}, is a string giving the name of the time
  1080. zone. Both elements change when daylight saving time begins or ends;
  1081. if the user has specified a time zone that does not use a seasonal time
  1082. adjustment, then the value is constant through time.
  1083. If the operating system doesn't supply all the information necessary to
  1084. compute the value, the unknown elements of the list are @code{nil}.
  1085. The argument @var{time}, if given, specifies a time value to
  1086. analyze instead of the current time. The optional argument @var{zone}
  1087. defaults to the current time zone rule.
  1088. @end defun
  1089. @vindex TZ, environment variable
  1090. The default time zone is determined by the @env{TZ} environment
  1091. variable. @xref{System Environment}. For example, you can tell Emacs
  1092. to default to Universal Time with @code{(setenv "TZ" "UTC0")}. If
  1093. @env{TZ} is not in the environment, Emacs uses system wall clock time,
  1094. which is a platform-dependent default time zone.
  1095. @cindex time zone rule
  1096. Functions that convert to and from local time accept an optional
  1097. @dfn{time zone rule} argument, which specifies the conversion's time
  1098. zone and daylight saving time history. If the time zone rule is
  1099. omitted or @code{nil}, the conversion uses Emacs's default time zone.
  1100. If it is @code{t}, the conversion uses Universal Time. If it is
  1101. @code{wall}, the conversion uses the system wall clock time. If it is
  1102. a string, the conversion uses the time zone rule equivalent to setting
  1103. @env{TZ} to that string.
  1104. @node Time Conversion
  1105. @section Time Conversion
  1106. @cindex calendrical information
  1107. @cindex time conversion
  1108. These functions convert time values (@pxref{Time of Day}) into
  1109. calendrical information and vice versa.
  1110. Many 32-bit operating systems are limited to system times containing
  1111. 32 bits of information in their seconds component; these systems
  1112. typically handle only the times from 1901-12-13 20:45:52 through
  1113. 2038-01-19 03:14:07 Universal Time. However, 64-bit and some 32-bit operating
  1114. systems have larger seconds components, and can represent times far in
  1115. the past or future.
  1116. Time conversion functions always use the Gregorian calendar, even
  1117. for dates before the Gregorian calendar was introduced. Year numbers
  1118. count the number of years since the year 1 B.C., and do not skip zero
  1119. as traditional Gregorian years do; for example, the year number
  1120. @minus{}37 represents the Gregorian year 38 B.C@.
  1121. @defun decode-time &optional time zone
  1122. This function converts a time value into calendrical information. If
  1123. you don't specify @var{time}, it decodes the current time, and similarly
  1124. @var{zone} defaults to the current time zone rule. The return
  1125. value is a list of nine elements, as follows:
  1126. @example
  1127. (@var{seconds} @var{minutes} @var{hour} @var{day} @var{month} @var{year} @var{dow} @var{dst} @var{utcoff})
  1128. @end example
  1129. Here is what the elements mean:
  1130. @table @var
  1131. @item seconds
  1132. The number of seconds past the minute, as an integer between 0 and 59.
  1133. On some operating systems, this is 60 for leap seconds.
  1134. @item minutes
  1135. The number of minutes past the hour, as an integer between 0 and 59.
  1136. @item hour
  1137. The hour of the day, as an integer between 0 and 23.
  1138. @item day
  1139. The day of the month, as an integer between 1 and 31.
  1140. @item month
  1141. The month of the year, as an integer between 1 and 12.
  1142. @item year
  1143. The year, an integer typically greater than 1900.
  1144. @item dow
  1145. The day of week, as an integer between 0 and 6, where 0 stands for
  1146. Sunday.
  1147. @item dst
  1148. @code{t} if daylight saving time is effect, otherwise @code{nil}.
  1149. @item utcoff
  1150. An integer indicating the Universal Time offset in seconds, i.e., the number of
  1151. seconds east of Greenwich.
  1152. @end table
  1153. @strong{Common Lisp Note:} Common Lisp has different meanings for
  1154. @var{dow} and @var{utcoff}.
  1155. @end defun
  1156. @defun encode-time seconds minutes hour day month year &optional zone
  1157. This function is the inverse of @code{decode-time}. It converts seven
  1158. items of calendrical data into a list-of-integer time value. For the
  1159. meanings of the arguments, see the table above under
  1160. @code{decode-time}.
  1161. Year numbers less than 100 are not treated specially. If you want them
  1162. to stand for years above 1900, or years above 2000, you must alter them
  1163. yourself before you call @code{encode-time}.
  1164. The optional argument @var{zone} defaults to the current time zone rule.
  1165. In addition to the usual time zone rule values, it can also be a list
  1166. (as you would get from @code{current-time-zone}) or an integer (as
  1167. from @code{decode-time}), applied without any further alteration for
  1168. daylight saving time.
  1169. If you pass more than seven arguments to @code{encode-time}, the first
  1170. six are used as @var{seconds} through @var{year}, the last argument is
  1171. used as @var{zone}, and the arguments in between are ignored. This
  1172. feature makes it possible to use the elements of a list returned by
  1173. @code{decode-time} as the arguments to @code{encode-time}, like this:
  1174. @example
  1175. (apply 'encode-time (decode-time @dots{}))
  1176. @end example
  1177. You can perform simple date arithmetic by using out-of-range values for
  1178. the @var{seconds}, @var{minutes}, @var{hour}, @var{day}, and @var{month}
  1179. arguments; for example, day 0 means the day preceding the given month.
  1180. The operating system puts limits on the range of possible time values;
  1181. if you try to encode a time that is out of range, an error results.
  1182. For instance, years before 1970 do not work on some systems;
  1183. on others, years as early as 1901 do work.
  1184. @end defun
  1185. @node Time Parsing
  1186. @section Parsing and Formatting Times
  1187. @cindex time parsing
  1188. @cindex time formatting
  1189. @cindex formatting time values
  1190. These functions convert time values to text in a string, and vice versa.
  1191. Time values are lists of two to four integers (@pxref{Time of Day}).
  1192. @defun date-to-time string
  1193. This function parses the time-string @var{string} and returns the
  1194. corresponding time value.
  1195. @end defun
  1196. @defun format-time-string format-string &optional time zone
  1197. This function converts @var{time} (or the current time, if
  1198. @var{time} is omitted) to a string according to
  1199. @var{format-string}. The conversion uses the time zone rule @var{zone}
  1200. (or the current time zone rule, if omitted). The argument
  1201. @var{format-string} may contain @samp{%}-sequences which say to
  1202. substitute parts of the time. Here is a table of what the
  1203. @samp{%}-sequences mean:
  1204. @table @samp
  1205. @item %a
  1206. This stands for the abbreviated name of the day of week.
  1207. @item %A
  1208. This stands for the full name of the day of week.
  1209. @item %b
  1210. This stands for the abbreviated name of the month.
  1211. @item %B
  1212. This stands for the full name of the month.
  1213. @item %c
  1214. This is a synonym for @samp{%x %X}.
  1215. @item %C
  1216. This has a locale-specific meaning. In the default locale (named C), it
  1217. is equivalent to @samp{%A, %B %e, %Y}.
  1218. @item %d
  1219. This stands for the day of month, zero-padded.
  1220. @item %D
  1221. This is a synonym for @samp{%m/%d/%y}.
  1222. @item %e
  1223. This stands for the day of month, blank-padded.
  1224. @item %h
  1225. This is a synonym for @samp{%b}.
  1226. @item %H
  1227. This stands for the hour (00--23).
  1228. @item %I
  1229. This stands for the hour (01--12).
  1230. @item %j
  1231. This stands for the day of the year (001--366).
  1232. @item %k
  1233. This stands for the hour (0--23), blank padded.
  1234. @item %l
  1235. This stands for the hour (1--12), blank padded.
  1236. @item %m
  1237. This stands for the month (01--12).
  1238. @item %M
  1239. This stands for the minute (00--59).
  1240. @item %n
  1241. This stands for a newline.
  1242. @item %N
  1243. This stands for the nanoseconds (000000000--999999999). To ask for
  1244. fewer digits, use @samp{%3N} for milliseconds, @samp{%6N} for
  1245. microseconds, etc. Any excess digits are discarded, without rounding.
  1246. @item %p
  1247. This stands for @samp{AM} or @samp{PM}, as appropriate.
  1248. @item %r
  1249. This is a synonym for @samp{%I:%M:%S %p}.
  1250. @item %R
  1251. This is a synonym for @samp{%H:%M}.
  1252. @item %S
  1253. This stands for the seconds (00--59).
  1254. @item %t
  1255. This stands for a tab character.
  1256. @item %T
  1257. This is a synonym for @samp{%H:%M:%S}.
  1258. @item %U
  1259. This stands for the week of the year (01--52), assuming that weeks
  1260. start on Sunday.
  1261. @item %w
  1262. This stands for the numeric day of week (0--6). Sunday is day 0.
  1263. @item %W
  1264. This stands for the week of the year (01--52), assuming that weeks
  1265. start on Monday.
  1266. @item %x
  1267. This has a locale-specific meaning. In the default locale (named
  1268. @samp{C}), it is equivalent to @samp{%D}.
  1269. @item %X
  1270. This has a locale-specific meaning. In the default locale (named
  1271. @samp{C}), it is equivalent to @samp{%T}.
  1272. @item %y
  1273. This stands for the year without century (00--99).
  1274. @item %Y
  1275. This stands for the year with century.
  1276. @item %Z
  1277. This stands for the time zone abbreviation (e.g., @samp{EST}).
  1278. @item %z
  1279. This stands for the time zone numerical offset (e.g., @samp{-0500}).
  1280. @end table
  1281. You can also specify the field width and type of padding for any of
  1282. these @samp{%}-sequences. This works as in @code{printf}: you write
  1283. the field width as digits in the middle of a @samp{%}-sequences. If you
  1284. start the field width with @samp{0}, it means to pad with zeros. If you
  1285. start the field width with @samp{_}, it means to pad with spaces.
  1286. For example, @samp{%S} specifies the number of seconds since the minute;
  1287. @samp{%03S} means to pad this with zeros to 3 positions, @samp{%_3S} to
  1288. pad with spaces to 3 positions. Plain @samp{%3S} pads with zeros,
  1289. because that is how @samp{%S} normally pads to two positions.
  1290. The characters @samp{E} and @samp{O} act as modifiers when used between
  1291. @samp{%} and one of the letters in the table above. @samp{E} specifies
  1292. using the current locale's alternative version of the date and time.
  1293. In a Japanese locale, for example, @code{%Ex} might yield a date format
  1294. based on the Japanese Emperors' reigns. @samp{E} is allowed in
  1295. @samp{%Ec}, @samp{%EC}, @samp{%Ex}, @samp{%EX}, @samp{%Ey}, and
  1296. @samp{%EY}.
  1297. @samp{O} means to use the current locale's alternative
  1298. representation of numbers, instead of the ordinary decimal digits. This
  1299. is allowed with most letters, all the ones that output numbers.
  1300. This function uses the C library function @code{strftime}
  1301. (@pxref{Formatting Calendar Time,,, libc, The GNU C Library Reference
  1302. Manual}) to do most of the work. In order to communicate with that
  1303. function, it first encodes its argument using the coding system
  1304. specified by @code{locale-coding-system} (@pxref{Locales}); after
  1305. @code{strftime} returns the resulting string,
  1306. @code{format-time-string} decodes the string using that same coding
  1307. system.
  1308. @end defun
  1309. @defun format-seconds format-string seconds
  1310. This function converts its argument @var{seconds} into a string of
  1311. years, days, hours, etc., according to @var{format-string}. The
  1312. argument @var{format-string} may contain @samp{%}-sequences which
  1313. control the conversion. Here is a table of what the
  1314. @samp{%}-sequences mean:
  1315. @table @samp
  1316. @item %y
  1317. @itemx %Y
  1318. The integer number of 365-day years.
  1319. @item %d
  1320. @itemx %D
  1321. The integer number of days.
  1322. @item %h
  1323. @itemx %H
  1324. The integer number of hours.
  1325. @item %m
  1326. @itemx %M
  1327. The integer number of minutes.
  1328. @item %s
  1329. @itemx %S
  1330. The integer number of seconds.
  1331. @item %z
  1332. Non-printing control flag. When it is used, other specifiers must be
  1333. given in the order of decreasing size, i.e., years before days, hours
  1334. before minutes, etc. Nothing will be produced in the result string to
  1335. the left of @samp{%z} until the first non-zero conversion is
  1336. encountered. For example, the default format used by
  1337. @code{emacs-uptime} (@pxref{Processor Run Time, emacs-uptime})
  1338. @w{@code{"%Y, %D, %H, %M, %z%S"}} means that the number of seconds
  1339. will always be produced, but years, days, hours, and minutes will only
  1340. be shown if they are non-zero.
  1341. @item %%
  1342. Produces a literal @samp{%}.
  1343. @end table
  1344. Upper-case format sequences produce the units in addition to the
  1345. numbers, lower-case formats produce only the numbers.
  1346. You can also specify the field width by following the @samp{%} with a
  1347. number; shorter numbers will be padded with blanks. An optional
  1348. period before the width requests zero-padding instead. For example,
  1349. @code{"%.3Y"} might produce @code{"004 years"}.
  1350. @emph{Warning:} This function works only with values of @var{seconds}
  1351. that don't exceed @code{most-positive-fixnum} (@pxref{Integer Basics,
  1352. most-positive-fixnum}).
  1353. @end defun
  1354. @node Processor Run Time
  1355. @section Processor Run time
  1356. @cindex processor run time
  1357. @cindex Emacs process run time
  1358. Emacs provides several functions and primitives that return time,
  1359. both elapsed and processor time, used by the Emacs process.
  1360. @deffn Command emacs-uptime &optional format
  1361. @cindex uptime of Emacs
  1362. This function returns a string representing the Emacs
  1363. @dfn{uptime}---the elapsed wall-clock time this instance of Emacs is
  1364. running. The string is formatted by @code{format-seconds} according
  1365. to the optional argument @var{format}. For the available format
  1366. descriptors, see @ref{Time Parsing, format-seconds}. If @var{format}
  1367. is @code{nil} or omitted, it defaults to @code{"%Y, %D, %H, %M,
  1368. %z%S"}.
  1369. When called interactively, it prints the uptime in the echo area.
  1370. @end deffn
  1371. @defun get-internal-run-time
  1372. This function returns the processor run time used by Emacs as a list
  1373. of four integers: @code{(@var{sec-high} @var{sec-low} @var{microsec}
  1374. @var{picosec})}, using the same format as @code{current-time}
  1375. (@pxref{Time of Day}).
  1376. Note that the time returned by this function excludes the time Emacs
  1377. was not using the processor, and if the Emacs process has several
  1378. threads, the returned value is the sum of the processor times used up
  1379. by all Emacs threads.
  1380. If the system doesn't provide a way to determine the processor run
  1381. time, @code{get-internal-run-time} returns the same time as
  1382. @code{current-time}.
  1383. @end defun
  1384. @deffn Command emacs-init-time
  1385. This function returns the duration of the Emacs initialization
  1386. (@pxref{Startup Summary}) in seconds, as a string. When called
  1387. interactively, it prints the duration in the echo area.
  1388. @end deffn
  1389. @node Time Calculations
  1390. @section Time Calculations
  1391. @cindex time calculations
  1392. @cindex comparing time values
  1393. @cindex calendrical computations
  1394. These functions perform calendrical computations using time values
  1395. (@pxref{Time of Day}).
  1396. @defun time-less-p t1 t2
  1397. This returns @code{t} if time value @var{t1} is less than time value
  1398. @var{t2}.
  1399. @end defun
  1400. @defun time-subtract t1 t2
  1401. This returns the time difference @var{t1} @minus{} @var{t2} between
  1402. two time values, as a time value.
  1403. @end defun
  1404. @defun time-add t1 t2
  1405. This returns the sum of two time values, as a time value.
  1406. One argument should represent a time difference rather than a point in time.
  1407. Here is how to add a number of seconds to a time value:
  1408. @example
  1409. (time-add @var{time} @var{seconds})
  1410. @end example
  1411. @end defun
  1412. @defun time-to-days time-value
  1413. This function returns the number of days between the beginning of year
  1414. 1 and @var{time-value}.
  1415. @end defun
  1416. @defun time-to-day-in-year time-value
  1417. This returns the day number within the year corresponding to @var{time-value}.
  1418. @end defun
  1419. @defun date-leap-year-p year
  1420. This function returns @code{t} if @var{year} is a leap year.
  1421. @end defun
  1422. @node Timers
  1423. @section Timers for Delayed Execution
  1424. @cindex timer
  1425. You can set up a @dfn{timer} to call a function at a specified
  1426. future time or after a certain length of idleness.
  1427. Emacs cannot run timers at any arbitrary point in a Lisp program; it
  1428. can run them only when Emacs could accept output from a subprocess:
  1429. namely, while waiting or inside certain primitive functions such as
  1430. @code{sit-for} or @code{read-event} which @emph{can} wait. Therefore, a
  1431. timer's execution may be delayed if Emacs is busy. However, the time of
  1432. execution is very precise if Emacs is idle.
  1433. Emacs binds @code{inhibit-quit} to @code{t} before calling the timer
  1434. function, because quitting out of many timer functions can leave
  1435. things in an inconsistent state. This is normally unproblematical
  1436. because most timer functions don't do a lot of work. Indeed, for a
  1437. timer to call a function that takes substantial time to run is likely
  1438. to be annoying. If a timer function needs to allow quitting, it
  1439. should use @code{with-local-quit} (@pxref{Quitting}). For example, if
  1440. a timer function calls @code{accept-process-output} to receive output
  1441. from an external process, that call should be wrapped inside
  1442. @code{with-local-quit}, to ensure that @kbd{C-g} works if the external
  1443. process hangs.
  1444. It is usually a bad idea for timer functions to alter buffer
  1445. contents. When they do, they usually should call @code{undo-boundary}
  1446. both before and after changing the buffer, to separate the timer's
  1447. changes from user commands' changes and prevent a single undo entry
  1448. from growing to be quite large.
  1449. Timer functions should also avoid calling functions that cause Emacs
  1450. to wait, such as @code{sit-for} (@pxref{Waiting}). This can lead to
  1451. unpredictable effects, since other timers (or even the same timer) can
  1452. run while waiting. If a timer function needs to perform an action
  1453. after a certain time has elapsed, it can do this by scheduling a new
  1454. timer.
  1455. If a timer function calls functions that can change the match data,
  1456. it should save and restore the match data. @xref{Saving Match Data}.
  1457. @deffn Command run-at-time time repeat function &rest args
  1458. This sets up a timer that calls the function @var{function} with
  1459. arguments @var{args} at time @var{time}. If @var{repeat} is a number
  1460. (integer or floating point), the timer is scheduled to run again every
  1461. @var{repeat} seconds after @var{time}. If @var{repeat} is @code{nil},
  1462. the timer runs only once.
  1463. @var{time} may specify an absolute or a relative time.
  1464. Absolute times may be specified using a string with a limited variety
  1465. of formats, and are taken to be times @emph{today}, even if already in
  1466. the past. The recognized forms are @samp{@var{xxxx}},
  1467. @samp{@var{x}:@var{xx}}, or @samp{@var{xx}:@var{xx}} (military time),
  1468. and @samp{@var{xx}am}, @samp{@var{xx}AM}, @samp{@var{xx}pm},
  1469. @samp{@var{xx}PM}, @samp{@var{xx}:@var{xx}am},
  1470. @samp{@var{xx}:@var{xx}AM}, @samp{@var{xx}:@var{xx}pm}, or
  1471. @samp{@var{xx}:@var{xx}PM}. A period can be used instead of a colon
  1472. to separate the hour and minute parts.
  1473. To specify a relative time as a string, use numbers followed by units.
  1474. For example:
  1475. @table @samp
  1476. @item 1 min
  1477. denotes 1 minute from now.
  1478. @item 1 min 5 sec
  1479. denotes 65 seconds from now.
  1480. @item 1 min 2 sec 3 hour 4 day 5 week 6 fortnight 7 month 8 year
  1481. denotes exactly 103 months, 123 days, and 10862 seconds from now.
  1482. @end table
  1483. For relative time values, Emacs considers a month to be exactly thirty
  1484. days, and a year to be exactly 365.25 days.
  1485. Not all convenient formats are strings. If @var{time} is a number
  1486. (integer or floating point), that specifies a relative time measured in
  1487. seconds. The result of @code{encode-time} can also be used to specify
  1488. an absolute value for @var{time}.
  1489. In most cases, @var{repeat} has no effect on when @emph{first} call
  1490. takes place---@var{time} alone specifies that. There is one exception:
  1491. if @var{time} is @code{t}, then the timer runs whenever the time is a
  1492. multiple of @var{repeat} seconds after the epoch. This is useful for
  1493. functions like @code{display-time}.
  1494. The function @code{run-at-time} returns a timer value that identifies
  1495. the particular scheduled future action. You can use this value to call
  1496. @code{cancel-timer} (see below).
  1497. @end deffn
  1498. A repeating timer nominally ought to run every @var{repeat} seconds,
  1499. but remember that any invocation of a timer can be late. Lateness of
  1500. one repetition has no effect on the scheduled time of the next
  1501. repetition. For instance, if Emacs is busy computing for long enough
  1502. to cover three scheduled repetitions of the timer, and then starts to
  1503. wait, it will immediately call the timer function three times in
  1504. immediate succession (presuming no other timers trigger before or
  1505. between them). If you want a timer to run again no less than @var{n}
  1506. seconds after the last invocation, don't use the @var{repeat} argument.
  1507. Instead, the timer function should explicitly reschedule the timer.
  1508. @defopt timer-max-repeats
  1509. This variable's value specifies the maximum number of times to repeat
  1510. calling a timer function in a row, when many previously scheduled
  1511. calls were unavoidably delayed.
  1512. @end defopt
  1513. @defmac with-timeout (seconds timeout-forms@dots{}) body@dots{}
  1514. Execute @var{body}, but give up after @var{seconds} seconds. If
  1515. @var{body} finishes before the time is up, @code{with-timeout} returns
  1516. the value of the last form in @var{body}. If, however, the execution of
  1517. @var{body} is cut short by the timeout, then @code{with-timeout}
  1518. executes all the @var{timeout-forms} and returns the value of the last
  1519. of them.
  1520. This macro works by setting a timer to run after @var{seconds} seconds. If
  1521. @var{body} finishes before that time, it cancels the timer. If the
  1522. timer actually runs, it terminates execution of @var{body}, then
  1523. executes @var{timeout-forms}.
  1524. Since timers can run within a Lisp program only when the program calls a
  1525. primitive that can wait, @code{with-timeout} cannot stop executing
  1526. @var{body} while it is in the midst of a computation---only when it
  1527. calls one of those primitives. So use @code{with-timeout} only with a
  1528. @var{body} that waits for input, not one that does a long computation.
  1529. @end defmac
  1530. The function @code{y-or-n-p-with-timeout} provides a simple way to use
  1531. a timer to avoid waiting too long for an answer. @xref{Yes-or-No
  1532. Queries}.
  1533. @defun cancel-timer timer
  1534. This cancels the requested action for @var{timer}, which should be a
  1535. timer---usually, one previously returned by @code{run-at-time} or
  1536. @code{run-with-idle-timer}. This cancels the effect of that call to
  1537. one of these functions; the arrival of the specified time will not
  1538. cause anything special to happen.
  1539. @end defun
  1540. @findex timer-list
  1541. The @code{timer-list} command lists all the currently active timers.
  1542. There's only one command available in the buffer displayed: @kbd{c}
  1543. (@code{timer-list-cancel}) that will cancel the timer on the line
  1544. under point.
  1545. @node Idle Timers
  1546. @section Idle Timers
  1547. @cindex idle timers
  1548. Here is how to set up a timer that runs when Emacs is idle for a
  1549. certain length of time. Aside from how to set them up, idle timers
  1550. work just like ordinary timers.
  1551. @deffn Command run-with-idle-timer secs repeat function &rest args
  1552. Set up a timer which runs the next time Emacs is idle for @var{secs}
  1553. seconds. The value of @var{secs} may be a number or a value of the type
  1554. returned by @code{current-idle-time}.
  1555. If @var{repeat} is @code{nil}, the timer runs just once, the first time
  1556. Emacs remains idle for a long enough time. More often @var{repeat} is
  1557. non-@code{nil}, which means to run the timer @emph{each time} Emacs
  1558. remains idle for @var{secs} seconds.
  1559. The function @code{run-with-idle-timer} returns a timer value which you
  1560. can use in calling @code{cancel-timer} (@pxref{Timers}).
  1561. @end deffn
  1562. @cindex idleness
  1563. Emacs becomes @dfn{idle} when it starts waiting for user input, and
  1564. it remains idle until the user provides some input. If a timer is set
  1565. for five seconds of idleness, it runs approximately five seconds after
  1566. Emacs first becomes idle. Even if @var{repeat} is non-@code{nil},
  1567. this timer will not run again as long as Emacs remains idle, because
  1568. the duration of idleness will continue to increase and will not go
  1569. down to five seconds again.
  1570. Emacs can do various things while idle: garbage collect, autosave or
  1571. handle data from a subprocess. But these interludes during idleness do
  1572. not interfere with idle timers, because they do not reset the clock of
  1573. idleness to zero. An idle timer set for 600 seconds will run when ten
  1574. minutes have elapsed since the last user command was finished, even if
  1575. subprocess output has been accepted thousands of times within those ten
  1576. minutes, and even if there have been garbage collections and autosaves.
  1577. When the user supplies input, Emacs becomes non-idle while executing the
  1578. input. Then it becomes idle again, and all the idle timers that are
  1579. set up to repeat will subsequently run another time, one by one.
  1580. Do not write an idle timer function containing a loop which does a
  1581. certain amount of processing each time around, and exits when
  1582. @code{(input-pending-p)} is non-@code{nil}. This approach seems very
  1583. natural but has two problems:
  1584. @itemize
  1585. @item
  1586. It blocks out all process output (since Emacs accepts process output
  1587. only while waiting).
  1588. @item
  1589. It blocks out any idle timers that ought to run during that time.
  1590. @end itemize
  1591. @noindent
  1592. Similarly, do not write an idle timer function that sets up another
  1593. idle timer (including the same idle timer) with @var{secs} argument
  1594. less than or equal to the current idleness time. Such a timer will
  1595. run almost immediately, and continue running again and again, instead
  1596. of waiting for the next time Emacs becomes idle. The correct approach
  1597. is to reschedule with an appropriate increment of the current value of
  1598. the idleness time, as described below.
  1599. @defun current-idle-time
  1600. If Emacs is idle, this function returns the length of time Emacs has
  1601. been idle, as a list of four integers: @code{(@var{sec-high}
  1602. @var{sec-low} @var{microsec} @var{picosec})}, using the same format as
  1603. @code{current-time} (@pxref{Time of Day}).
  1604. When Emacs is not idle, @code{current-idle-time} returns @code{nil}.
  1605. This is a convenient way to test whether Emacs is idle.
  1606. @end defun
  1607. The main use of @code{current-idle-time} is when an idle timer
  1608. function wants to ``take a break'' for a while. It can set up another
  1609. idle timer to call the same function again, after a few seconds more
  1610. idleness. Here's an example:
  1611. @example
  1612. (defvar my-resume-timer nil
  1613. "Timer for `my-timer-function' to reschedule itself, or nil.")
  1614. (defun my-timer-function ()
  1615. ;; @r{If the user types a command while @code{my-resume-timer}}
  1616. ;; @r{is active, the next time this function is called from}
  1617. ;; @r{its main idle timer, deactivate @code{my-resume-timer}.}
  1618. (when my-resume-timer
  1619. (cancel-timer my-resume-timer))
  1620. ...@var{do the work for a while}...
  1621. (when @var{taking-a-break}
  1622. (setq my-resume-timer
  1623. (run-with-idle-timer
  1624. ;; Compute an idle time @var{break-length}
  1625. ;; more than the current value.
  1626. (time-add (current-idle-time) @var{break-length})
  1627. nil
  1628. 'my-timer-function))))
  1629. @end example
  1630. @node Terminal Input
  1631. @section Terminal Input
  1632. @cindex terminal input
  1633. This section describes functions and variables for recording or
  1634. manipulating terminal input. See @ref{Display}, for related
  1635. functions.
  1636. @menu
  1637. * Input Modes:: Options for how input is processed.
  1638. * Recording Input:: Saving histories of recent or all input events.
  1639. @end menu
  1640. @node Input Modes
  1641. @subsection Input Modes
  1642. @cindex input modes
  1643. @cindex terminal input modes
  1644. @defun set-input-mode interrupt flow meta &optional quit-char
  1645. This function sets the mode for reading keyboard input. If
  1646. @var{interrupt} is non-@code{nil}, then Emacs uses input interrupts.
  1647. If it is @code{nil}, then it uses @sc{cbreak} mode. The default
  1648. setting is system-dependent. Some systems always use @sc{cbreak} mode
  1649. regardless of what is specified.
  1650. When Emacs communicates directly with X, it ignores this argument and
  1651. uses interrupts if that is the way it knows how to communicate.
  1652. If @var{flow} is non-@code{nil}, then Emacs uses @sc{xon/xoff}
  1653. (@kbd{C-q}, @kbd{C-s}) flow control for output to the terminal. This
  1654. has no effect except in @sc{cbreak} mode.
  1655. The argument @var{meta} controls support for input character codes
  1656. above 127. If @var{meta} is @code{t}, Emacs converts characters with
  1657. the 8th bit set into Meta characters. If @var{meta} is @code{nil},
  1658. Emacs disregards the 8th bit; this is necessary when the terminal uses
  1659. it as a parity bit. If @var{meta} is neither @code{t} nor @code{nil},
  1660. Emacs uses all 8 bits of input unchanged. This is good for terminals
  1661. that use 8-bit character sets.
  1662. If @var{quit-char} is non-@code{nil}, it specifies the character to
  1663. use for quitting. Normally this character is @kbd{C-g}.
  1664. @xref{Quitting}.
  1665. @end defun
  1666. The @code{current-input-mode} function returns the input mode settings
  1667. Emacs is currently using.
  1668. @defun current-input-mode
  1669. This function returns the current mode for reading keyboard input. It
  1670. returns a list, corresponding to the arguments of @code{set-input-mode},
  1671. of the form @code{(@var{interrupt} @var{flow} @var{meta} @var{quit})} in
  1672. which:
  1673. @table @var
  1674. @item interrupt
  1675. is non-@code{nil} when Emacs is using interrupt-driven input. If
  1676. @code{nil}, Emacs is using @sc{cbreak} mode.
  1677. @item flow
  1678. is non-@code{nil} if Emacs uses @sc{xon/xoff} (@kbd{C-q}, @kbd{C-s})
  1679. flow control for output to the terminal. This value is meaningful only
  1680. when @var{interrupt} is @code{nil}.
  1681. @item meta
  1682. is @code{t} if Emacs treats the eighth bit of input characters as
  1683. the meta bit; @code{nil} means Emacs clears the eighth bit of every
  1684. input character; any other value means Emacs uses all eight bits as the
  1685. basic character code.
  1686. @item quit
  1687. is the character Emacs currently uses for quitting, usually @kbd{C-g}.
  1688. @end table
  1689. @end defun
  1690. @node Recording Input
  1691. @subsection Recording Input
  1692. @cindex recording input
  1693. @defun recent-keys
  1694. This function returns a vector containing the last 300 input events from
  1695. the keyboard or mouse. All input events are included, whether or not
  1696. they were used as parts of key sequences. Thus, you always get the last
  1697. 300 input events, not counting events generated by keyboard macros.
  1698. (These are excluded because they are less interesting for debugging; it
  1699. should be enough to see the events that invoked the macros.)
  1700. A call to @code{clear-this-command-keys} (@pxref{Command Loop Info})
  1701. causes this function to return an empty vector immediately afterward.
  1702. @end defun
  1703. @deffn Command open-dribble-file filename
  1704. @cindex dribble file
  1705. This function opens a @dfn{dribble file} named @var{filename}. When a
  1706. dribble file is open, each input event from the keyboard or mouse (but
  1707. not those from keyboard macros) is written in that file. A
  1708. non-character event is expressed using its printed representation
  1709. surrounded by @samp{<@dots{}>}. Be aware that sensitive information
  1710. (such as passwords) may end up recorded in the dribble file.
  1711. You close the dribble file by calling this function with an argument
  1712. of @code{nil}.
  1713. @end deffn
  1714. See also the @code{open-termscript} function (@pxref{Terminal Output}).
  1715. @node Terminal Output
  1716. @section Terminal Output
  1717. @cindex terminal output
  1718. The terminal output functions send output to a text terminal, or keep
  1719. track of output sent to the terminal. The variable @code{baud-rate}
  1720. tells you what Emacs thinks is the output speed of the terminal.
  1721. @defopt baud-rate
  1722. This variable's value is the output speed of the terminal, as far as
  1723. Emacs knows. Setting this variable does not change the speed of actual
  1724. data transmission, but the value is used for calculations such as
  1725. padding.
  1726. It also affects decisions about whether to scroll part of the
  1727. screen or repaint on text terminals. @xref{Forcing Redisplay},
  1728. for the corresponding functionality on graphical terminals.
  1729. The value is measured in baud.
  1730. @end defopt
  1731. If you are running across a network, and different parts of the
  1732. network work at different baud rates, the value returned by Emacs may be
  1733. different from the value used by your local terminal. Some network
  1734. protocols communicate the local terminal speed to the remote machine, so
  1735. that Emacs and other programs can get the proper value, but others do
  1736. not. If Emacs has the wrong value, it makes decisions that are less
  1737. than optimal. To fix the problem, set @code{baud-rate}.
  1738. @defun send-string-to-terminal string &optional terminal
  1739. This function sends @var{string} to @var{terminal} without alteration.
  1740. Control characters in @var{string} have terminal-dependent effects.
  1741. (If you need to display non-ASCII text on the terminal, encode it
  1742. using one of the functions described in @ref{Explicit Encoding}.)
  1743. This function operates only on text terminals. @var{terminal} may be
  1744. a terminal object, a frame, or @code{nil} for the selected frame's
  1745. terminal. In batch mode, @var{string} is sent to @code{stdout} when
  1746. @var{terminal} is @code{nil}.
  1747. One use of this function is to define function keys on terminals that
  1748. have downloadable function key definitions. For example, this is how (on
  1749. certain terminals) to define function key 4 to move forward four
  1750. characters (by transmitting the characters @kbd{C-u C-f} to the
  1751. computer):
  1752. @example
  1753. @group
  1754. (send-string-to-terminal "\eF4\^U\^F")
  1755. @result{} nil
  1756. @end group
  1757. @end example
  1758. @end defun
  1759. @deffn Command open-termscript filename
  1760. @cindex termscript file
  1761. This function is used to open a @dfn{termscript file} that will record
  1762. all the characters sent by Emacs to the terminal. It returns
  1763. @code{nil}. Termscript files are useful for investigating problems
  1764. where Emacs garbles the screen, problems that are due to incorrect
  1765. Termcap entries or to undesirable settings of terminal options more
  1766. often than to actual Emacs bugs. Once you are certain which characters
  1767. were actually output, you can determine reliably whether they correspond
  1768. to the Termcap specifications in use.
  1769. @example
  1770. @group
  1771. (open-termscript "../junk/termscript")
  1772. @result{} nil
  1773. @end group
  1774. @end example
  1775. You close the termscript file by calling this function with an
  1776. argument of @code{nil}.
  1777. See also @code{open-dribble-file} in @ref{Recording Input}.
  1778. @end deffn
  1779. @node Sound Output
  1780. @section Sound Output
  1781. @cindex sound
  1782. To play sound using Emacs, use the function @code{play-sound}. Only
  1783. certain systems are supported; if you call @code{play-sound} on a
  1784. system which cannot really do the job, it gives an error.
  1785. @c FIXME: Add indexes for Au and WAV? --xfq
  1786. The sound must be stored as a file in RIFF-WAVE format (@samp{.wav})
  1787. or Sun Audio format (@samp{.au}).
  1788. @defun play-sound sound
  1789. This function plays a specified sound. The argument, @var{sound}, has
  1790. the form @code{(sound @var{properties}...)}, where the @var{properties}
  1791. consist of alternating keywords (particular symbols recognized
  1792. specially) and values corresponding to them.
  1793. Here is a table of the keywords that are currently meaningful in
  1794. @var{sound}, and their meanings:
  1795. @table @code
  1796. @item :file @var{file}
  1797. This specifies the file containing the sound to play.
  1798. If the file name is not absolute, it is expanded against
  1799. the directory @code{data-directory}.
  1800. @item :data @var{data}
  1801. This specifies the sound to play without need to refer to a file. The
  1802. value, @var{data}, should be a string containing the same bytes as a
  1803. sound file. We recommend using a unibyte string.
  1804. @item :volume @var{volume}
  1805. This specifies how loud to play the sound. It should be a number in the
  1806. range of 0 to 1. The default is to use whatever volume has been
  1807. specified before.
  1808. @item :device @var{device}
  1809. This specifies the system device on which to play the sound, as a
  1810. string. The default device is system-dependent.
  1811. @end table
  1812. Before actually playing the sound, @code{play-sound}
  1813. calls the functions in the list @code{play-sound-functions}.
  1814. Each function is called with one argument, @var{sound}.
  1815. @end defun
  1816. @deffn Command play-sound-file file &optional volume device
  1817. This function is an alternative interface to playing a sound @var{file}
  1818. specifying an optional @var{volume} and @var{device}.
  1819. @end deffn
  1820. @defvar play-sound-functions
  1821. A list of functions to be called before playing a sound. Each function
  1822. is called with one argument, a property list that describes the sound.
  1823. @end defvar
  1824. @node X11 Keysyms
  1825. @section Operating on X11 Keysyms
  1826. @cindex X11 keysyms
  1827. To define system-specific X11 keysyms, set the variable
  1828. @code{system-key-alist}.
  1829. @defvar system-key-alist
  1830. This variable's value should be an alist with one element for each
  1831. system-specific keysym. Each element has the form @code{(@var{code}
  1832. . @var{symbol})}, where @var{code} is the numeric keysym code (not
  1833. including the vendor-specific bit,
  1834. @ifnottex
  1835. @minus{}2**28),
  1836. @end ifnottex
  1837. @tex
  1838. $-2^{28}$),
  1839. @end tex
  1840. and @var{symbol} is the name for the function key.
  1841. For example @code{(168 . mute-acute)} defines a system-specific key (used
  1842. by HP X servers) whose numeric code is
  1843. @ifnottex
  1844. @minus{}2**28
  1845. @end ifnottex
  1846. @tex
  1847. $-2^{28}$
  1848. @end tex
  1849. + 168.
  1850. It is not crucial to exclude from the alist the keysyms of other X
  1851. servers; those do no harm, as long as they don't conflict with the ones
  1852. used by the X server actually in use.
  1853. The variable is always local to the current terminal, and cannot be
  1854. buffer-local. @xref{Multiple Terminals}.
  1855. @end defvar
  1856. You can specify which keysyms Emacs should use for the Meta, Alt, Hyper, and Super modifiers by setting these variables:
  1857. @defvar x-alt-keysym
  1858. @defvarx x-meta-keysym
  1859. @defvarx x-hyper-keysym
  1860. @defvarx x-super-keysym
  1861. The name of the keysym that should stand for the Alt modifier
  1862. (respectively, for Meta, Hyper, and Super). For example, here is
  1863. how to swap the Meta and Alt modifiers within Emacs:
  1864. @lisp
  1865. (setq x-alt-keysym 'meta)
  1866. (setq x-meta-keysym 'alt)
  1867. @end lisp
  1868. @end defvar
  1869. @node Batch Mode
  1870. @section Batch Mode
  1871. @cindex batch mode
  1872. The command-line option @samp{-batch} causes Emacs to run
  1873. noninteractively. In this mode, Emacs does not read commands from the
  1874. terminal, it does not alter the terminal modes, and it does not expect
  1875. to be outputting to an erasable screen. The idea is that you specify
  1876. Lisp programs to run; when they are finished, Emacs should exit. The
  1877. way to specify the programs to run is with @samp{-l @var{file}}, which
  1878. loads the library named @var{file}, or @samp{-f @var{function}}, which
  1879. calls @var{function} with no arguments, or @samp{--eval @var{form}}.
  1880. Any Lisp program output that would normally go to the echo area,
  1881. either using @code{message}, or using @code{prin1}, etc., with
  1882. @code{t} as the stream, goes instead to Emacs's standard descriptors
  1883. when in batch mode: @code{message} writes to the standard error
  1884. descriptor, while @code{prin1} and other print functions write to the
  1885. standard output. Similarly, input that would normally come from the
  1886. minibuffer is read from the standard input descriptor. Thus, Emacs
  1887. behaves much like a noninteractive application program. (The echo
  1888. area output that Emacs itself normally generates, such as command
  1889. echoing, is suppressed entirely.)
  1890. Non-ASCII text written to the standard output or error descriptors is
  1891. by default encoded using @code{locale-coding-system} (@pxref{Locales})
  1892. if it is non-@code{nil}; this can be overridden by binding
  1893. @code{coding-system-for-write} to a coding system of you choice
  1894. (@pxref{Explicit Encoding}).
  1895. @defvar noninteractive
  1896. This variable is non-@code{nil} when Emacs is running in batch mode.
  1897. @end defvar
  1898. @node Session Management
  1899. @section Session Management
  1900. @cindex session manager
  1901. Emacs supports the X Session Management Protocol, which is used to
  1902. suspend and restart applications. In the X Window System, a program
  1903. called the @dfn{session manager} is responsible for keeping track of
  1904. the applications that are running. When the X server shuts down, the
  1905. session manager asks applications to save their state, and delays the
  1906. actual shutdown until they respond. An application can also cancel
  1907. the shutdown.
  1908. When the session manager restarts a suspended session, it directs
  1909. these applications to individually reload their saved state. It does
  1910. this by specifying a special command-line argument that says what
  1911. saved session to restore. For Emacs, this argument is @samp{--smid
  1912. @var{session}}.
  1913. @defvar emacs-save-session-functions
  1914. @cindex session file
  1915. Emacs supports saving state via a hook called
  1916. @code{emacs-save-session-functions}. Emacs runs this hook when the
  1917. session manager tells it that the window system is shutting down. The
  1918. functions are called with no arguments, and with the current buffer
  1919. set to a temporary buffer. Each function can use @code{insert} to add
  1920. Lisp code to this buffer. At the end, Emacs saves the buffer in a
  1921. file, called the @dfn{session file}.
  1922. @findex emacs-session-restore
  1923. Subsequently, when the session manager restarts Emacs, it loads the
  1924. session file automatically (@pxref{Loading}). This is performed by a
  1925. function named @code{emacs-session-restore}, which is called during
  1926. startup. @xref{Startup Summary}.
  1927. If a function in @code{emacs-save-session-functions} returns
  1928. non-@code{nil}, Emacs tells the session manager to cancel the
  1929. shutdown.
  1930. @end defvar
  1931. Here is an example that just inserts some text into @file{*scratch*} when
  1932. Emacs is restarted by the session manager.
  1933. @example
  1934. @group
  1935. (add-hook 'emacs-save-session-functions 'save-yourself-test)
  1936. @end group
  1937. @group
  1938. (defun save-yourself-test ()
  1939. (insert "(save-current-buffer
  1940. (switch-to-buffer \"*scratch*\")
  1941. (insert \"I am restored\"))")
  1942. nil)
  1943. @end group
  1944. @end example
  1945. @node Desktop Notifications
  1946. @section Desktop Notifications
  1947. @cindex desktop notifications
  1948. @cindex notifications, on desktop
  1949. Emacs is able to send @dfn{notifications} on systems that support the
  1950. freedesktop.org Desktop Notifications Specification and on MS-Windows.
  1951. In order to use this functionality on Posix hosts, Emacs must have
  1952. been compiled with D-Bus support, and the @code{notifications} library
  1953. must be loaded. @xref{Top, , D-Bus,dbus,D-Bus integration in Emacs}.
  1954. The following function is supported when D-Bus support is available:
  1955. @defun notifications-notify &rest params
  1956. This function sends a notification to the desktop via D-Bus,
  1957. consisting of the parameters specified by the @var{params} arguments.
  1958. These arguments should consist of alternating keyword and value pairs.
  1959. The supported keywords and values are as follows:
  1960. @table @code
  1961. @item :bus @var{bus}
  1962. The D-Bus bus. This argument is needed only if a bus other than
  1963. @code{:session} shall be used.
  1964. @item :title @var{title}
  1965. The notification title.
  1966. @item :body @var{text}
  1967. The notification body text. Depending on the implementation of the
  1968. notification server, the text could contain HTML markups, like
  1969. @samp{"<b>bold text</b>"}, hyperlinks, or images. Special HTML
  1970. characters must be encoded, as @samp{"Contact
  1971. &lt;postmaster@@localhost&gt;!"}.
  1972. @item :app-name @var{name}
  1973. The name of the application sending the notification. The default is
  1974. @code{notifications-application-name}.
  1975. @item :replaces-id @var{id}
  1976. The notification @var{id} that this notification replaces. @var{id}
  1977. must be the result of a previous @code{notifications-notify} call.
  1978. @item :app-icon @var{icon-file}
  1979. The file name of the notification icon. If set to @code{nil}, no icon
  1980. is displayed. The default is @code{notifications-application-icon}.
  1981. @item :actions (@var{key} @var{title} @var{key} @var{title} ...)
  1982. A list of actions to be applied. @var{key} and @var{title} are both
  1983. strings. The default action (usually invoked by clicking the
  1984. notification) should have a key named @samp{"default"}. The title can
  1985. be anything, though implementations are free not to display it.
  1986. @item :timeout @var{timeout}
  1987. The timeout time in milliseconds since the display of the notification
  1988. at which the notification should automatically close. If @minus{}1, the
  1989. notification's expiration time is dependent on the notification
  1990. server's settings, and may vary for the type of notification. If 0,
  1991. the notification never expires. Default value is @minus{}1.
  1992. @item :urgency @var{urgency}
  1993. The urgency level. It can be @code{low}, @code{normal}, or @code{critical}.
  1994. @item :action-items
  1995. When this keyword is given, the @var{title} string of the actions is
  1996. interpreted as icon name.
  1997. @item :category @var{category}
  1998. The type of notification this is, a string. See the
  1999. @uref{http://developer.gnome.org/notification-spec/#categories,
  2000. Desktop Notifications Specification} for a list of standard
  2001. categories.
  2002. @item :desktop-entry @var{filename}
  2003. This specifies the name of the desktop filename representing the
  2004. calling program, like @samp{"emacs"}.
  2005. @item :image-data (@var{width} @var{height} @var{rowstride} @var{has-alpha} @var{bits} @var{channels} @var{data})
  2006. This is a raw data image format that describes the width, height,
  2007. rowstride, whether there is an alpha channel, bits per sample,
  2008. channels and image data, respectively.
  2009. @item :image-path @var{path}
  2010. This is represented either as a URI (@samp{file://} is the only URI
  2011. schema supported right now) or a name in a freedesktop.org-compliant
  2012. icon theme from @samp{$XDG_DATA_DIRS/icons}.
  2013. @item :sound-file @var{filename}
  2014. The path to a sound file to play when the notification pops up.
  2015. @item :sound-name @var{name}
  2016. A themable named sound from the freedesktop.org sound naming
  2017. specification from @samp{$XDG_DATA_DIRS/sounds}, to play when the
  2018. notification pops up. Similar to the icon name, only for sounds. An
  2019. example would be @samp{"message-new-instant"}.
  2020. @item :suppress-sound
  2021. Causes the server to suppress playing any sounds, if it has that
  2022. ability.
  2023. @item :resident
  2024. When set the server will not automatically remove the notification
  2025. when an action has been invoked. The notification will remain resident
  2026. in the server until it is explicitly removed by the user or by the
  2027. sender. This hint is likely only useful when the server has the
  2028. @code{:persistence} capability.
  2029. @item :transient
  2030. When set the server will treat the notification as transient and
  2031. by-pass the server's persistence capability, if it should exist.
  2032. @item :x @var{position}
  2033. @itemx :y @var{position}
  2034. Specifies the X, Y location on the screen that the
  2035. notification should point to. Both arguments must be used together.
  2036. @item :on-action @var{function}
  2037. Function to call when an action is invoked. The notification @var{id}
  2038. and the @var{key} of the action are passed as arguments to the
  2039. function.
  2040. @item :on-close @var{function}
  2041. Function to call when the notification has been closed by timeout or
  2042. by the user. The function receive the notification @var{id} and the closing
  2043. @var{reason} as arguments:
  2044. @itemize
  2045. @item @code{expired} if the notification has expired
  2046. @item @code{dismissed} if the notification was dismissed by the user
  2047. @item @code{close-notification} if the notification was closed by a call to
  2048. @code{notifications-close-notification}
  2049. @item @code{undefined} if the notification server hasn't provided a reason
  2050. @end itemize
  2051. @end table
  2052. Which parameters are accepted by the notification server can be
  2053. checked via @code{notifications-get-capabilities}.
  2054. This function returns a notification id, an integer, which can be used
  2055. to manipulate the notification item with
  2056. @code{notifications-close-notification} or the @code{:replaces-id}
  2057. argument of another @code{notifications-notify} call. For example:
  2058. @example
  2059. @group
  2060. (defun my-on-action-function (id key)
  2061. (message "Message %d, key \"%s\" pressed" id key))
  2062. @result{} my-on-action-function
  2063. @end group
  2064. @group
  2065. (defun my-on-close-function (id reason)
  2066. (message "Message %d, closed due to \"%s\"" id reason))
  2067. @result{} my-on-close-function
  2068. @end group
  2069. @group
  2070. (notifications-notify
  2071. :title "Title"
  2072. :body "This is <b>important</b>."
  2073. :actions '("Confirm" "I agree" "Refuse" "I disagree")
  2074. :on-action 'my-on-action-function
  2075. :on-close 'my-on-close-function)
  2076. @result{} 22
  2077. @end group
  2078. @group
  2079. A message window opens on the desktop. Press ``I agree''.
  2080. @result{} Message 22, key "Confirm" pressed
  2081. Message 22, closed due to "dismissed"
  2082. @end group
  2083. @end example
  2084. @end defun
  2085. @defun notifications-close-notification id &optional bus
  2086. This function closes a notification with identifier @var{id}.
  2087. @var{bus} can be a string denoting a D-Bus connection, the default is
  2088. @code{:session}.
  2089. @end defun
  2090. @defun notifications-get-capabilities &optional bus
  2091. Returns the capabilities of the notification server, a list of
  2092. symbols. @var{bus} can be a string denoting a D-Bus connection, the
  2093. default is @code{:session}. The following capabilities can be
  2094. expected:
  2095. @table @code
  2096. @item :actions
  2097. The server will provide the specified actions to the user.
  2098. @item :body
  2099. Supports body text.
  2100. @item :body-hyperlinks
  2101. The server supports hyperlinks in the notifications.
  2102. @item :body-images
  2103. The server supports images in the notifications.
  2104. @item :body-markup
  2105. Supports markup in the body text.
  2106. @item :icon-multi
  2107. The server will render an animation of all the frames in a given image
  2108. array.
  2109. @item :icon-static
  2110. Supports display of exactly 1 frame of any given image array. This
  2111. value is mutually exclusive with @code{:icon-multi}.
  2112. @item :persistence
  2113. The server supports persistence of notifications.
  2114. @item :sound
  2115. The server supports sounds on notifications.
  2116. @end table
  2117. Further vendor-specific caps start with @code{:x-vendor}, like
  2118. @code{:x-gnome-foo-cap}.
  2119. @end defun
  2120. @defun notifications-get-server-information &optional bus
  2121. Return information on the notification server, a list of strings.
  2122. @var{bus} can be a string denoting a D-Bus connection, the default is
  2123. @code{:session}. The returned list is @code{(@var{name} @var{vendor}
  2124. @var{version} @var{spec-version})}.
  2125. @table @var
  2126. @item name
  2127. The product name of the server.
  2128. @item vendor
  2129. The vendor name. For example, @samp{"KDE"}, @samp{"GNOME"}.
  2130. @item version
  2131. The server's version number.
  2132. @item spec-version
  2133. The specification version the server is compliant with.
  2134. @end table
  2135. If @var{spec_version} is @code{nil}, the server supports a
  2136. specification prior to @samp{"1.0"}.
  2137. @end defun
  2138. @cindex tray notifications, MS-Windows
  2139. When Emacs runs on MS-Windows as a GUI session, it supports a small
  2140. subset of the D-Bus notifications functionality via a native
  2141. primitive:
  2142. @defun w32-notification-notify &rest params
  2143. This function displays an MS-Windows tray notification as specified by
  2144. @var{params}. MS-Windows tray notifications are displayed in a
  2145. balloon from an icon in the notification area of the taskbar.
  2146. Value is the integer unique ID of the notification that can be used to
  2147. remove the notification using @code{w32-notification-close}, described
  2148. below. If the function fails, the return value is @code{nil}.
  2149. The arguments @var{params} are specified as keyword/value pairs. All the
  2150. parameters are optional, but if no parameters are specified, the
  2151. function will do nothing and return @code{nil}.
  2152. The following parameters are supported:
  2153. @table @code
  2154. @item :icon @var{icon}
  2155. Display @var{icon} in the system tray. If @var{icon} is a string, it
  2156. should specify a file name from which to load the icon; the specified
  2157. file should be a @file{.ico} Windows icon file. If @var{icon} is not
  2158. a string, or if this parameter is not specified, the standard Emacs
  2159. icon will be used.
  2160. @item :tip @var{tip}
  2161. Use @var{tip} as the tooltip for the notification. If @var{tip} is a
  2162. string, this is the text of a tooltip that will be shown when the
  2163. mouse pointer hovers over the tray icon added by the notification. If
  2164. @var{tip} is not a string, or if this parameter is not specified, the
  2165. default tooltip text is @samp{Emacs notification}. The tooltip text can
  2166. be up to 127 characters long (63 on Windows versions before W2K).
  2167. Longer strings will be truncated.
  2168. @item :level @var{level}
  2169. Notification severity level, one of @code{info}, @code{warning}, or
  2170. @code{error}. If given, the value determines the icon displayed to the
  2171. left of the notification title, but only if the @code{:title} parameter
  2172. (see below) is also specified and is a string.
  2173. @item :title @var{title}
  2174. The title of the notification. If @var{title} is a string, it is
  2175. displayed in a larger font immediately above the body text. The title
  2176. text can be up to 63 characters long; longer text will be truncated.
  2177. @item :body @var{body}
  2178. The body of the notification. If @var{body} is a string, it specifies
  2179. the text of the notification message. Use embedded newlines to
  2180. control how the text is broken into lines. The body text can be up to
  2181. 255 characters long, and will be truncated if it's longer. Unlike
  2182. with D-Bus, the body text should be plain text, with no markup.
  2183. @end table
  2184. Note that versions of Windows before W2K support only @code{:icon} and
  2185. @code{:tip}. The other parameters can be passed, but they will be
  2186. ignored on those old systems.
  2187. There can be at most one active notification at any given time. An
  2188. active notification must be removed by calling
  2189. @code{w32-notification-close} before a new one can be shown.
  2190. @end defun
  2191. To remove the notification and its icon from the taskbar, use the
  2192. following function:
  2193. @defun w32-notification-close id
  2194. This function removes the tray notification given by its unique
  2195. @var{id}.
  2196. @end defun
  2197. @node File Notifications
  2198. @section Notifications on File Changes
  2199. @cindex file notifications
  2200. @cindex watch, for filesystem events
  2201. Several operating systems support watching of filesystems for changes
  2202. of files. If configured properly, Emacs links a respective library
  2203. like @file{inotify}, @file{kqueue}, @file{gfilenotify}, or
  2204. @file{w32notify} statically. These libraries enable watching of
  2205. filesystems on the local machine.
  2206. It is also possible to watch filesystems on remote machines,
  2207. @pxref{Remote Files,, Remote Files, emacs, The GNU Emacs Manual}
  2208. This does not depend on one of the libraries linked to Emacs.
  2209. Since all these libraries emit different events on notified file
  2210. changes, there is the Emacs library @code{filenotify} which provides a
  2211. unique interface.
  2212. @defun file-notify-add-watch file flags callback
  2213. Add a watch for filesystem events pertaining to @var{file}. This
  2214. arranges for filesystem events pertaining to @var{file} to be reported
  2215. to Emacs.
  2216. The returned value is a descriptor for the added watch. Its type
  2217. depends on the underlying library, it cannot be assumed to be an
  2218. integer as in the example below. It should be used for comparison by
  2219. @code{equal} only.
  2220. If the @var{file} cannot be watched for some reason, this function
  2221. signals a @code{file-notify-error} error.
  2222. Sometimes, mounted filesystems cannot be watched for file changes.
  2223. This is not detected by this function, a non-@code{nil} return value
  2224. does not guarantee that changes on @var{file} will be notified.
  2225. @var{flags} is a list of conditions to set what will be watched for.
  2226. It can include the following symbols:
  2227. @table @code
  2228. @item change
  2229. watch for file changes
  2230. @item attribute-change
  2231. watch for file attribute changes, like permissions or modification
  2232. time
  2233. @end table
  2234. If @var{file} is a directory, changes for all files in that directory
  2235. will be notified. This does not work recursively.
  2236. When any event happens, Emacs will call the @var{callback} function
  2237. passing it a single argument @var{event}, which is of the form
  2238. @lisp
  2239. (@var{descriptor} @var{action} @var{file} [@var{file1}])
  2240. @end lisp
  2241. @var{descriptor} is the same object as the one returned by this
  2242. function. @var{action} is the description of the event. It could be
  2243. any one of the following symbols:
  2244. @table @code
  2245. @item created
  2246. @var{file} was created
  2247. @item deleted
  2248. @var{file} was deleted
  2249. @item changed
  2250. @var{file}'s contents has changed; with @file{w32notify} library,
  2251. reports attribute changes as well
  2252. @item renamed
  2253. @var{file} has been renamed to @var{file1}
  2254. @item attribute-changed
  2255. a @var{file} attribute was changed
  2256. @item stopped
  2257. watching @var{file} has been stopped
  2258. @end table
  2259. Note that the @file{w32notify} library does not report
  2260. @code{attribute-changed} events. When some file's attribute, like
  2261. permissions or modification time, has changed, this library reports a
  2262. @code{changed} event. Likewise, the @file{kqueue} library does not
  2263. report reliably file attribute changes when watching a directory.
  2264. The @code{stopped} event reports, that watching the file has been
  2265. stopped. This could be because @code{file-notify-rm-watch} was called
  2266. (see below), or because the file being watched was deleted, or due to
  2267. another error reported from the underlying library.
  2268. @var{file} and @var{file1} are the name of the file(s) whose event is
  2269. being reported. For example:
  2270. @example
  2271. @group
  2272. (require 'filenotify)
  2273. @result{} filenotify
  2274. @end group
  2275. @group
  2276. (defun my-notify-callback (event)
  2277. (message "Event %S" event))
  2278. @result{} my-notify-callback
  2279. @end group
  2280. @group
  2281. (file-notify-add-watch
  2282. "/tmp" '(change attribute-change) 'my-notify-callback)
  2283. @result{} 35025468
  2284. @end group
  2285. @group
  2286. (write-region "foo" nil "/tmp/foo")
  2287. @result{} Event (35025468 created "/tmp/.#foo")
  2288. Event (35025468 created "/tmp/foo")
  2289. Event (35025468 changed "/tmp/foo")
  2290. Event (35025468 deleted "/tmp/.#foo")
  2291. @end group
  2292. @group
  2293. (write-region "bla" nil "/tmp/foo")
  2294. @result{} Event (35025468 created "/tmp/.#foo")
  2295. Event (35025468 changed "/tmp/foo")
  2296. Event (35025468 deleted "/tmp/.#foo")
  2297. @end group
  2298. @group
  2299. (set-file-modes "/tmp/foo" (default-file-modes))
  2300. @result{} Event (35025468 attribute-changed "/tmp/foo")
  2301. @end group
  2302. @end example
  2303. Whether the action @code{renamed} is returned, depends on the used
  2304. watch library. Otherwise, the actions @code{deleted} and
  2305. @code{created} could be returned in a random order.
  2306. @example
  2307. @group
  2308. (rename-file "/tmp/foo" "/tmp/bla")
  2309. @result{} Event (35025468 renamed "/tmp/foo" "/tmp/bla")
  2310. @end group
  2311. @group
  2312. (delete-file "/tmp/bla")
  2313. @result{} Event (35025468 deleted "/tmp/bla")
  2314. @end group
  2315. @end example
  2316. @end defun
  2317. @defun file-notify-rm-watch descriptor
  2318. Removes an existing file watch specified by its @var{descriptor}.
  2319. @var{descriptor} should be an object returned by
  2320. @code{file-notify-add-watch}.
  2321. @end defun
  2322. @defun file-notify-valid-p descriptor
  2323. Checks a watch specified by its @var{descriptor} for validity.
  2324. @var{descriptor} should be an object returned by
  2325. @code{file-notify-add-watch}.
  2326. A watch can become invalid if the file or directory it watches is
  2327. deleted, or if the watcher thread exits abnormally for any other
  2328. reason. Removing the watch by calling @code{file-notify-rm-watch}
  2329. also makes it invalid.
  2330. @example
  2331. @group
  2332. (make-directory "/tmp/foo")
  2333. @result{} Event (35025468 created "/tmp/foo")
  2334. @end group
  2335. @group
  2336. (setq desc
  2337. (file-notify-add-watch
  2338. "/tmp/foo" '(change) 'my-notify-callback))
  2339. @result{} 11359632
  2340. @end group
  2341. @group
  2342. (file-notify-valid-p desc)
  2343. @result{} t
  2344. @end group
  2345. @group
  2346. (write-region "bla" nil "/tmp/foo/bla")
  2347. @result{} Event (11359632 created "/tmp/foo/.#bla")
  2348. Event (11359632 created "/tmp/foo/bla")
  2349. Event (11359632 changed "/tmp/foo/bla")
  2350. Event (11359632 deleted "/tmp/foo/.#bla")
  2351. @end group
  2352. @group
  2353. ;; Deleting a file in the directory doesn't invalidate the watch.
  2354. (delete-file "/tmp/foo/bla")
  2355. @result{} Event (11359632 deleted "/tmp/foo/bla")
  2356. @end group
  2357. @group
  2358. (write-region "bla" nil "/tmp/foo/bla")
  2359. @result{} Event (11359632 created "/tmp/foo/.#bla")
  2360. Event (11359632 created "/tmp/foo/bla")
  2361. Event (11359632 changed "/tmp/foo/bla")
  2362. Event (11359632 deleted "/tmp/foo/.#bla")
  2363. @end group
  2364. @group
  2365. ;; Deleting the directory invalidates the watch.
  2366. ;; Events arrive for different watch descriptors.
  2367. (delete-directory "/tmp/foo" 'recursive)
  2368. @result{} Event (35025468 deleted "/tmp/foo")
  2369. Event (11359632 deleted "/tmp/foo/bla")
  2370. Event (11359632 deleted "/tmp/foo")
  2371. Event (11359632 stopped "/tmp/foo")
  2372. @end group
  2373. @group
  2374. (file-notify-valid-p desc)
  2375. @result{} nil
  2376. @end group
  2377. @end example
  2378. @end defun
  2379. @node Dynamic Libraries
  2380. @section Dynamically Loaded Libraries
  2381. @cindex dynamic libraries
  2382. A @dfn{dynamically loaded library} is a library that is loaded on
  2383. demand, when its facilities are first needed. Emacs supports such
  2384. on-demand loading of support libraries for some of its features.
  2385. @defvar dynamic-library-alist
  2386. This is an alist of dynamic libraries and external library files
  2387. implementing them.
  2388. Each element is a list of the form
  2389. @w{@code{(@var{library} @var{files}@dots{})}}, where the @code{car} is
  2390. a symbol representing a supported external library, and the rest are
  2391. strings giving alternate filenames for that library.
  2392. Emacs tries to load the library from the files in the order they
  2393. appear in the list; if none is found, the Emacs session won't have
  2394. access to that library, and the features it provides will be
  2395. unavailable.
  2396. Image support on some platforms uses this facility. Here's an example
  2397. of setting this variable for supporting images on MS-Windows:
  2398. @example
  2399. (setq dynamic-library-alist
  2400. '((xpm "libxpm.dll" "xpm4.dll" "libXpm-nox4.dll")
  2401. (png "libpng12d.dll" "libpng12.dll" "libpng.dll"
  2402. "libpng13d.dll" "libpng13.dll")
  2403. (jpeg "jpeg62.dll" "libjpeg.dll" "jpeg-62.dll"
  2404. "jpeg.dll")
  2405. (tiff "libtiff3.dll" "libtiff.dll")
  2406. (gif "giflib4.dll" "libungif4.dll" "libungif.dll")
  2407. (svg "librsvg-2-2.dll")
  2408. (gdk-pixbuf "libgdk_pixbuf-2.0-0.dll")
  2409. (glib "libglib-2.0-0.dll")
  2410. (gobject "libgobject-2.0-0.dll")))
  2411. @end example
  2412. Note that image types @code{pbm} and @code{xbm} do not need entries in
  2413. this variable because they do not depend on external libraries and are
  2414. always available in Emacs.
  2415. Also note that this variable is not meant to be a generic facility for
  2416. accessing external libraries; only those already known by Emacs can
  2417. be loaded through it.
  2418. This variable is ignored if the given @var{library} is statically
  2419. linked into Emacs.
  2420. @end defvar
  2421. @node Security Considerations
  2422. @section Security Considerations
  2423. @cindex security
  2424. @cindex hardening
  2425. Like any application, Emacs can be run in a secure environment, where
  2426. the operating system enforces rules about access and the like. With
  2427. some care, Emacs-based applications can also be part of a security
  2428. perimeter that checks such rules. Although the default settings for
  2429. Emacs work well for a typical software development environment, they
  2430. may require adjustment in environments containing untrusted users that
  2431. may include attackers. Here is a compendium of security issues that
  2432. may be helpful if you are developing such applications. It is by no
  2433. means complete; it is intended to give you an idea of the security
  2434. issues involved, rather than to be a security checklist.
  2435. @table @asis
  2436. @item File local variables
  2437. @cindex file local variables
  2438. A file that Emacs visits can contain variable settings that affects
  2439. the buffer visiting that file; @xref{File Local Variables}.
  2440. Similarly, a directory can specify local variable values common to all
  2441. files in that directory; @xref{Directory Local Variables}. Although
  2442. Emacs takes some effort to protect against misuse of these variables,
  2443. a security hole can be created merely by a package setting
  2444. @code{safe-local-variable} too optimistically, a problem that is all
  2445. too common. To disable this feature for both files and directories,
  2446. set @code{enable-local-variables} to @code{nil}.
  2447. @item Access control
  2448. Although Emacs normally respects access permissions of the underlying
  2449. operating system, in some cases it handles accesses specially. For
  2450. example, file names can have handlers that treat the files specially,
  2451. with their own access checking. @xref{Magic File Names}. Also, a
  2452. buffer can be read-only even if the corresponding file is writeable,
  2453. and vice versa, which can result in messages such as @samp{File passwd
  2454. is write-protected; try to save anyway? (yes or no)}. @xref{Read Only
  2455. Buffers}.
  2456. @item Authentication
  2457. Emacs has several functions that deal with passwords, e.g.,
  2458. @code{read-passwd}. @xref{Reading a Password}.
  2459. Although these functions do not attempt to
  2460. broadcast passwords to the world, their implementations are not proof
  2461. against determined attackers with access to Emacs internals. For
  2462. example, even if Elisp code uses @code{clear-string} to scrub a password from
  2463. its memory after using it, remnants of the password may still reside
  2464. in the garbage-collected free list. @xref{Modifying Strings}.
  2465. @item Code injection
  2466. Emacs can send commands to many other applications, and applications
  2467. should take care that strings sent as operands of these commands are
  2468. not misinterpreted as directives. For example, when using a shell
  2469. command to rename a file @var{a} to @var{b}, do not simply use the
  2470. string @code{mv @var{a} @var{b}}, because either file name might start
  2471. with @samp{-}, or might contain shell metacharacters like @samp{;}.
  2472. Although functions like @code{shell-quote-argument} can help avoid
  2473. this sort of problem, they are not panaceas; for example, on a POSIX
  2474. platform @code{shell-quote-argument} quotes shell metacharacters but
  2475. not leading @samp{-}. @xref{Shell Arguments}. Typically it is safer
  2476. to use @code{call-process} than a subshell. @xref{Synchronous
  2477. Processes}. And it is safer yet to use builtin Emacs functions; for
  2478. example, use @code{(rename-file "@var{a}" "@var{b}" t)} instead of
  2479. invoking @command{mv}. @xref{Changing Files}.
  2480. @item Coding systems
  2481. Emacs attempts to infer the coding systems of the files and network
  2482. connections it accesses. @xref{Coding Systems}.
  2483. If Emacs infers incorrectly, or if the other
  2484. parties to the network connection disagree with Emacs's inferences,
  2485. the resulting system could be unreliable. Also, even when it infers
  2486. correctly, Emacs often can use bytes that other programs cannot. For
  2487. example, although to Emacs the null byte is just a
  2488. character like any other, many other applications treat it as a string
  2489. terminator and mishandle strings or files containing null bytes.
  2490. @item Environment and configuration variables
  2491. POSIX specifies several environment variables that can affect how
  2492. Emacs behaves. Any environment variable whose name consists entirely
  2493. of uppercase ASCII letters, digits, and the underscore may affect the
  2494. internal behavior of Emacs. Emacs uses several such variables, e.g.,
  2495. @env{EMACSLOADPATH}. @xref{Library Search}. On some platforms some
  2496. environment variables (e.g., @env{PATH}, @env{POSIXLY_CORRECT},
  2497. @env{SHELL}, @env{TMPDIR}) need to have properly-configured values in
  2498. order to get standard behavior for any utility Emacs might invoke.
  2499. Even seemingly-benign variables like @env{TZ} may have security
  2500. implications. @xref{System Environment}.
  2501. Emacs has customization and other variables with similar
  2502. considerations. For example, if the variable @code{shell-file-name}
  2503. specifies a shell with nonstandard behavior, an Emacs-based
  2504. application may misbehave.
  2505. @item Installation
  2506. When Emacs is installed, if the installation directory hierarchy can
  2507. be modified by untrusted users, the application cannot be trusted.
  2508. This applies also to the directory hierarchies of the programs that
  2509. Emacs uses, and of the files that Emacs reads and writes.
  2510. @item Network access
  2511. Emacs often accesses the network, and you may want to configure it to
  2512. avoid network accesses that it would normally do. For example, unless
  2513. you set @code{tramp-mode} to @code{nil}, file names using a certain
  2514. syntax are interpreted as being network files, and are retrieved
  2515. across the network. @xref{Top, The Tramp Manual,, tramp, The Tramp
  2516. Manual}.
  2517. @item Race conditions
  2518. Emacs applications have the same sort of race-condition issues that
  2519. other applications do. For example, even when
  2520. @code{(file-readable-p "foo.txt")} returns @code{t}, it could be that
  2521. @file{foo.txt} is unreadable because some other program changed the
  2522. file's permissions between the call to @code{file-readable-p} and now.
  2523. @xref{Testing Accessibility}.
  2524. @item Resource limits
  2525. When Emacs exhausts memory or other operating system resources, its
  2526. behavior can be less reliable, in that computations that ordinarily
  2527. run to completion may abort back to the top level. This may cause
  2528. Emacs to neglect operations that it normally would have done.
  2529. @end table