startup.el 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405
  1. ;;; startup.el --- process Emacs shell arguments -*- lexical-binding: t -*-
  2. ;; Copyright (C) 1985-1986, 1992, 1994-2012 Free Software Foundation, Inc.
  3. ;; Maintainer: FSF
  4. ;; Keywords: internal
  5. ;; Package: emacs
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; This file parses the command line and gets Emacs running. Options
  19. ;; on the command line are handled in precedence order. For priorities
  20. ;; see the structure standard_args in the emacs.c file.
  21. ;;; Code:
  22. (setq top-level '(normal-top-level))
  23. (defvar command-line-processed nil
  24. "Non-nil once command line has been processed.")
  25. (defgroup initialization nil
  26. "Emacs start-up procedure."
  27. :group 'environment)
  28. (defcustom initial-buffer-choice nil
  29. "Buffer to show after starting Emacs.
  30. If the value is nil and `inhibit-startup-screen' is nil, show the
  31. startup screen. If the value is a string, visit the specified file
  32. or directory using `find-file'. If t, open the `*scratch*'
  33. buffer."
  34. :type '(choice
  35. (const :tag "Startup screen" nil)
  36. (directory :tag "Directory" :value "~/")
  37. (file :tag "File" :value "~/.emacs")
  38. (const :tag "Lisp scratch buffer" t))
  39. :version "23.1"
  40. :group 'initialization)
  41. (defcustom inhibit-startup-screen nil
  42. "Non-nil inhibits the startup screen.
  43. This is for use in your personal init file (but NOT site-start.el),
  44. once you are familiar with the contents of the startup screen."
  45. :type 'boolean
  46. :group 'initialization)
  47. (defvaralias 'inhibit-splash-screen 'inhibit-startup-screen)
  48. (defvaralias 'inhibit-startup-message 'inhibit-startup-screen)
  49. (defvar startup-screen-inhibit-startup-screen nil)
  50. ;; FIXME? Why does this get such weirdly extreme treatment, when the
  51. ;; more important inhibit-startup-screen does not.
  52. (defcustom inhibit-startup-echo-area-message nil
  53. "Non-nil inhibits the initial startup echo area message.
  54. Setting this variable takes effect
  55. only if you do it with the customization buffer
  56. or if your `.emacs' file contains a line of this form:
  57. (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
  58. If your `.emacs' file is byte-compiled, use the following form instead:
  59. (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
  60. Thus, someone else using a copy of your `.emacs' file will see
  61. the startup message unless he personally acts to inhibit it."
  62. :type '(choice (const :tag "Don't inhibit")
  63. (string :tag "Enter your user name, to inhibit"))
  64. :group 'initialization)
  65. (defcustom inhibit-default-init nil
  66. "Non-nil inhibits loading the `default' library."
  67. :type 'boolean
  68. :group 'initialization)
  69. (defcustom inhibit-startup-buffer-menu nil
  70. "Non-nil inhibits display of buffer list when more than 2 files are loaded."
  71. :type 'boolean
  72. :group 'initialization)
  73. (defvar command-switch-alist nil
  74. "Alist of command-line switches.
  75. Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
  76. HANDLER-FUNCTION receives the switch string as its sole argument;
  77. the remaining command-line args are in the variable `command-line-args-left'.")
  78. (defvar command-line-args-left nil
  79. "List of command-line args not yet processed.")
  80. (defvaralias 'argv 'command-line-args-left
  81. ;; FIXME: Bad name for a dynamically bound variable.
  82. "List of command-line args not yet processed.
  83. This is a convenience alias, so that one can write \(pop argv\)
  84. inside of --eval command line arguments in order to access
  85. following arguments.")
  86. (with-no-warnings
  87. ;; FIXME: Bad name for a dynamically bound variable
  88. (defvar argi nil
  89. "Current command-line argument."))
  90. (defvar command-line-functions nil ;; lrs 7/31/89
  91. "List of functions to process unrecognized command-line arguments.
  92. Each function should access the dynamically bound variables
  93. `argi' (the current argument) and `command-line-args-left' (the remaining
  94. arguments). The function should return non-nil only if it recognizes and
  95. processes `argi'. If it does so, it may consume successive arguments by
  96. altering `command-line-args-left' to remove them.")
  97. (defvar command-line-default-directory nil
  98. "Default directory to use for command line arguments.
  99. This is normally copied from `default-directory' when Emacs starts.")
  100. ;;; This is here, rather than in x-win.el, so that we can ignore these
  101. ;;; options when we are not using X.
  102. (defconst command-line-x-option-alist
  103. '(("-bw" 1 x-handle-numeric-switch border-width)
  104. ("-d" 1 x-handle-display)
  105. ("-display" 1 x-handle-display)
  106. ("-name" 1 x-handle-name-switch)
  107. ("-title" 1 x-handle-switch title)
  108. ("-T" 1 x-handle-switch title)
  109. ("-r" 0 x-handle-switch reverse t)
  110. ("-rv" 0 x-handle-switch reverse t)
  111. ("-reverse" 0 x-handle-switch reverse t)
  112. ("-reverse-video" 0 x-handle-switch reverse t)
  113. ("-fn" 1 x-handle-switch font)
  114. ("-font" 1 x-handle-switch font)
  115. ("-fs" 0 x-handle-initial-switch fullscreen fullboth)
  116. ("-fw" 0 x-handle-initial-switch fullscreen fullwidth)
  117. ("-fh" 0 x-handle-initial-switch fullscreen fullheight)
  118. ("-mm" 0 x-handle-initial-switch fullscreen maximized)
  119. ("-ib" 1 x-handle-numeric-switch internal-border-width)
  120. ("-g" 1 x-handle-geometry)
  121. ("-lsp" 1 x-handle-numeric-switch line-spacing)
  122. ("-geometry" 1 x-handle-geometry)
  123. ("-fg" 1 x-handle-switch foreground-color)
  124. ("-foreground" 1 x-handle-switch foreground-color)
  125. ("-bg" 1 x-handle-switch background-color)
  126. ("-background" 1 x-handle-switch background-color)
  127. ("-ms" 1 x-handle-switch mouse-color)
  128. ("-nbi" 0 x-handle-switch icon-type nil)
  129. ("-iconic" 0 x-handle-iconic)
  130. ("-xrm" 1 x-handle-xrm-switch)
  131. ("-cr" 1 x-handle-switch cursor-color)
  132. ("-vb" 0 x-handle-switch vertical-scroll-bars t)
  133. ("-hb" 0 x-handle-switch horizontal-scroll-bars t)
  134. ("-bd" 1 x-handle-switch)
  135. ("--border-width" 1 x-handle-numeric-switch border-width)
  136. ("--display" 1 x-handle-display)
  137. ("--name" 1 x-handle-name-switch)
  138. ("--title" 1 x-handle-switch title)
  139. ("--reverse-video" 0 x-handle-switch reverse t)
  140. ("--font" 1 x-handle-switch font)
  141. ("--fullscreen" 0 x-handle-initial-switch fullscreen fullboth)
  142. ("--fullwidth" 0 x-handle-initial-switch fullscreen fullwidth)
  143. ("--fullheight" 0 x-handle-initial-switch fullscreen fullheight)
  144. ("--maximized" 0 x-handle-initial-switch fullscreen maximized)
  145. ("--internal-border" 1 x-handle-numeric-switch internal-border-width)
  146. ("--geometry" 1 x-handle-geometry)
  147. ("--foreground-color" 1 x-handle-switch foreground-color)
  148. ("--background-color" 1 x-handle-switch background-color)
  149. ("--mouse-color" 1 x-handle-switch mouse-color)
  150. ("--no-bitmap-icon" 0 x-handle-no-bitmap-icon)
  151. ("--iconic" 0 x-handle-iconic)
  152. ("--xrm" 1 x-handle-xrm-switch)
  153. ("--cursor-color" 1 x-handle-switch cursor-color)
  154. ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t)
  155. ("--line-spacing" 1 x-handle-numeric-switch line-spacing)
  156. ("--border-color" 1 x-handle-switch border-color)
  157. ("--smid" 1 x-handle-smid)
  158. ("--parent-id" 1 x-handle-parent-id))
  159. "Alist of X Windows options.
  160. Each element has the form
  161. (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
  162. where NAME is the option name string, NUMARGS is the number of arguments
  163. that the option accepts, HANDLER is a function to call to handle the option.
  164. FRAME-PARAM (optional) is the frame parameter this option specifies,
  165. and VALUE is the value which is given to that frame parameter
  166. \(most options use the argument for this, so VALUE is not present).")
  167. (defconst command-line-ns-option-alist
  168. '(("-NSAutoLaunch" 1 ns-ignore-1-arg)
  169. ("-NXAutoLaunch" 1 ns-ignore-1-arg)
  170. ("-macosx" 0 ignore)
  171. ("-NSHost" 1 ns-ignore-1-arg)
  172. ("-_NSMachLaunch" 1 ns-ignore-1-arg)
  173. ("-MachLaunch" 1 ns-ignore-1-arg)
  174. ("-NXOpen" 1 ns-ignore-1-arg)
  175. ("-NSOpen" 1 ns-handle-nxopen)
  176. ("-NXOpenTemp" 1 ns-ignore-1-arg)
  177. ("-NSOpenTemp" 1 ns-handle-nxopentemp)
  178. ("-GSFilePath" 1 ns-handle-nxopen)
  179. ;;("-bw" . x-handle-numeric-switch)
  180. ;;("-d" . x-handle-display)
  181. ;;("-display" . x-handle-display)
  182. ("-name" 1 x-handle-name-switch)
  183. ("-title" 1 x-handle-switch title)
  184. ("-T" 1 x-handle-switch title)
  185. ("-r" 0 x-handle-switch reverse t)
  186. ("-rv" 0 x-handle-switch reverse t)
  187. ("-reverse" 0 x-handle-switch reverse t)
  188. ("-fn" 1 x-handle-switch font)
  189. ("-font" 1 x-handle-switch font)
  190. ("-ib" 1 x-handle-numeric-switch internal-border-width)
  191. ;;("-g" . x-handle-geometry)
  192. ;;("-geometry" . x-handle-geometry)
  193. ("-fg" 1 x-handle-switch foreground-color)
  194. ("-foreground" 1 x-handle-switch foreground-color)
  195. ("-bg" 1 x-handle-switch background-color)
  196. ("-background" 1 x-handle-switch background-color)
  197. ; ("-ms" 1 x-handle-switch mouse-color)
  198. ("-itype" 0 x-handle-switch icon-type t)
  199. ("-i" 0 x-handle-switch icon-type t)
  200. ("-iconic" 0 x-handle-iconic icon-type t)
  201. ;;("-xrm" . x-handle-xrm-switch)
  202. ("-cr" 1 x-handle-switch cursor-color)
  203. ("-vb" 0 x-handle-switch vertical-scroll-bars t)
  204. ("-hb" 0 x-handle-switch horizontal-scroll-bars t)
  205. ("-bd" 1 x-handle-switch)
  206. ;; ("--border-width" 1 x-handle-numeric-switch border-width)
  207. ;; ("--display" 1 ns-handle-display)
  208. ("--name" 1 x-handle-name-switch)
  209. ("--title" 1 x-handle-switch title)
  210. ("--reverse-video" 0 x-handle-switch reverse t)
  211. ("--font" 1 x-handle-switch font)
  212. ("--internal-border" 1 x-handle-numeric-switch internal-border-width)
  213. ;; ("--geometry" 1 ns-handle-geometry)
  214. ("--foreground-color" 1 x-handle-switch foreground-color)
  215. ("--background-color" 1 x-handle-switch background-color)
  216. ("--mouse-color" 1 x-handle-switch mouse-color)
  217. ("--icon-type" 0 x-handle-switch icon-type t)
  218. ("--iconic" 0 x-handle-iconic)
  219. ;; ("--xrm" 1 ns-handle-xrm-switch)
  220. ("--cursor-color" 1 x-handle-switch cursor-color)
  221. ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t)
  222. ("--border-color" 1 x-handle-switch border-width))
  223. "Alist of NS options.
  224. Each element has the form
  225. (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
  226. where NAME is the option name string, NUMARGS is the number of arguments
  227. that the option accepts, HANDLER is a function to call to handle the option.
  228. FRAME-PARAM (optional) is the frame parameter this option specifies,
  229. and VALUE is the value which is given to that frame parameter
  230. \(most options use the argument for this, so VALUE is not present).")
  231. (defvar before-init-hook nil
  232. "Normal hook run after handling urgent options but before loading init files.")
  233. (defvar after-init-hook nil
  234. "Normal hook run after loading the init files, `~/.emacs' and `default.el'.
  235. There is no `condition-case' around the running of these functions;
  236. therefore, if you set `debug-on-error' non-nil in `.emacs',
  237. an error in one of these functions will invoke the debugger.")
  238. (defvar emacs-startup-hook nil
  239. "Normal hook run after loading init files and handling the command line.")
  240. (defvar term-setup-hook nil
  241. "Normal hook run after loading terminal-specific Lisp code.
  242. It also follows `emacs-startup-hook'. This hook exists for users to set,
  243. so as to override the definitions made by the terminal-specific file.
  244. Emacs never sets this variable itself.")
  245. (defvar inhibit-startup-hooks nil
  246. "Non-nil means don't run `term-setup-hook' and `emacs-startup-hook'.
  247. This is because we already did so.")
  248. (defvar keyboard-type nil
  249. "The brand of keyboard you are using.
  250. This variable is used to define the proper function and keypad
  251. keys for use under X. It is used in a fashion analogous to the
  252. environment variable TERM.")
  253. (defvar window-setup-hook nil
  254. "Normal hook run to initialize window system display.
  255. Emacs runs this hook after processing the command line arguments and loading
  256. the user's init file.")
  257. (defcustom initial-major-mode 'lisp-interaction-mode
  258. "Major mode command symbol to use for the initial `*scratch*' buffer."
  259. :type 'function
  260. :group 'initialization)
  261. (defvar init-file-user nil
  262. "Identity of user whose `.emacs' file is or was read.
  263. The value is nil if `-q' or `--no-init-file' was specified,
  264. meaning do not load any init file.
  265. Otherwise, the value may be an empty string, meaning
  266. use the init file for the user who originally logged in,
  267. or it may be a string containing a user's name meaning
  268. use that person's init file.
  269. In either of the latter cases, `(concat \"~\" init-file-user \"/\")'
  270. evaluates to the name of the directory where the `.emacs' file was
  271. looked for.
  272. Setting `init-file-user' does not prevent Emacs from loading
  273. `site-start.el'. The only way to do that is to use `--no-site-file'.")
  274. (defcustom site-run-file (purecopy "site-start")
  275. "File containing site-wide run-time initializations.
  276. This file is loaded at run-time before `~/.emacs'. It contains inits
  277. that need to be in place for the entire site, but which, due to their
  278. higher incidence of change, don't make sense to load into Emacs's
  279. dumped image. Thus, the run-time load order is: 1. file described in
  280. this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'.
  281. Don't use the `site-start.el' file for things some users may not like.
  282. Put them in `default.el' instead, so that users can more easily
  283. override them. Users can prevent loading `default.el' with the `-q'
  284. option or by setting `inhibit-default-init' in their own init files,
  285. but inhibiting `site-start.el' requires `--no-site-file', which
  286. is less convenient.
  287. This variable is defined for customization so as to make
  288. it visible in the relevant context. However, actually customizing it
  289. is not allowed, since it would not work anyway. The only way to set
  290. this variable usefully is to set it while building and dumping Emacs."
  291. :type '(choice (const :tag "none" nil) string)
  292. :group 'initialization
  293. :initialize 'custom-initialize-default
  294. :set (lambda (_variable _value)
  295. (error "Customizing `site-run-file' does not work")))
  296. (defcustom mail-host-address nil
  297. "Name of this machine, for purposes of naming users.
  298. If non-nil, Emacs uses this instead of `system-name' when constructing
  299. email addresses."
  300. :type '(choice (const nil) string)
  301. :group 'mail)
  302. (defcustom user-mail-address (if command-line-processed
  303. (or (getenv "EMAIL")
  304. (concat (user-login-name) "@"
  305. (or mail-host-address
  306. (system-name))))
  307. ;; Empty string means "not set yet".
  308. "")
  309. "Full mailing address of this user.
  310. This is initialized with environment variable `EMAIL' or, as a
  311. fallback, using `mail-host-address'. This is done after your
  312. init file is read, in case it sets `mail-host-address'."
  313. :type 'string
  314. :group 'mail)
  315. (defcustom auto-save-list-file-prefix
  316. (cond ((eq system-type 'ms-dos)
  317. ;; MS-DOS cannot have initial dot, and allows only 8.3 names
  318. (concat user-emacs-directory "auto-save.list/_s"))
  319. (t
  320. (concat user-emacs-directory "auto-save-list/.saves-")))
  321. "Prefix for generating `auto-save-list-file-name'.
  322. This is used after reading your `.emacs' file to initialize
  323. `auto-save-list-file-name', by appending Emacs's pid and the system name,
  324. if you have not already set `auto-save-list-file-name' yourself.
  325. Directories in the prefix will be created if necessary.
  326. Set this to nil if you want to prevent `auto-save-list-file-name'
  327. from being initialized."
  328. :type '(choice (const :tag "Don't record a session's auto save list" nil)
  329. string)
  330. :group 'auto-save)
  331. (defvar emacs-basic-display nil)
  332. (defvar init-file-debug nil)
  333. (defvar init-file-had-error nil
  334. "Non-nil if there was an error loading the user's init file.")
  335. (defvar normal-top-level-add-subdirs-inode-list nil)
  336. (defvar no-blinking-cursor nil)
  337. (defvar default-frame-background-mode)
  338. (defvar pure-space-overflow nil
  339. "Non-nil if building Emacs overflowed pure space.")
  340. (defvar pure-space-overflow-message (purecopy "\
  341. Warning Warning!!! Pure space overflow !!!Warning Warning
  342. \(See the node Pure Storage in the Lisp manual for details.)\n"))
  343. (defcustom tutorial-directory
  344. (file-name-as-directory (expand-file-name "tutorials" data-directory))
  345. "Directory containing the Emacs TUTORIAL files."
  346. :group 'installation
  347. :type 'directory
  348. :initialize 'custom-initialize-delay)
  349. (defconst package-subdirectory-regexp
  350. "\\([^.].*?\\)-\\([0-9]+\\(?:[.][0-9]+\\|\\(?:pre\\|beta\\|alpha\\)[0-9]+\\)*\\)"
  351. "Regular expression matching the name of a package subdirectory.
  352. The first subexpression is the package name.
  353. The second subexpression is the version string.
  354. The regexp should not contain a starting \"\\`\" or a trailing
  355. \"\\'\"; those are added automatically by callers.")
  356. (defun normal-top-level-add-subdirs-to-load-path ()
  357. "Add all subdirectories of `default-directory' to `load-path'.
  358. More precisely, this uses only the subdirectories whose names
  359. start with letters or digits; it excludes any subdirectory named `RCS'
  360. or `CVS', and any subdirectory that contains a file named `.nosearch'."
  361. (let (dirs
  362. attrs
  363. (pending (list default-directory)))
  364. ;; This loop does a breadth-first tree walk on DIR's subtree,
  365. ;; putting each subdir into DIRS as its contents are examined.
  366. (while pending
  367. (push (pop pending) dirs)
  368. (let* ((this-dir (car dirs))
  369. (contents (directory-files this-dir))
  370. (default-directory this-dir)
  371. (canonicalized (if (fboundp 'untranslated-canonical-name)
  372. (untranslated-canonical-name this-dir))))
  373. ;; The Windows version doesn't report meaningful inode numbers, so
  374. ;; use the canonicalized absolute file name of the directory instead.
  375. (setq attrs (or canonicalized
  376. (nthcdr 10 (file-attributes this-dir))))
  377. (unless (member attrs normal-top-level-add-subdirs-inode-list)
  378. (push attrs normal-top-level-add-subdirs-inode-list)
  379. (dolist (file contents)
  380. (and (string-match "\\`[[:alnum:]]" file)
  381. ;; The lower-case variants of RCS and CVS are for DOS/Windows.
  382. (not (member file '("RCS" "CVS" "rcs" "cvs")))
  383. ;; Avoid doing a `stat' when it isn't necessary because
  384. ;; that can cause trouble when an NFS server is down.
  385. (not (string-match "\\.elc?\\'" file))
  386. (file-directory-p file)
  387. (let ((expanded (expand-file-name file)))
  388. (or (file-exists-p (expand-file-name ".nosearch" expanded))
  389. (setq pending (nconc pending (list expanded))))))))))
  390. (normal-top-level-add-to-load-path (cdr (nreverse dirs)))))
  391. (defun normal-top-level-add-to-load-path (dirs)
  392. "This function is called from a subdirs.el file.
  393. It assumes that `default-directory' is the directory in which the
  394. subdirs.el file exists, and it adds to `load-path' the subdirs of
  395. that directory as specified in DIRS. Normally the elements of
  396. DIRS are relative."
  397. (let ((tail load-path)
  398. (thisdir (directory-file-name default-directory)))
  399. (while (and tail
  400. ;;Don't go all the way to the nil terminator.
  401. (cdr tail)
  402. (not (equal thisdir (car tail)))
  403. (not (and (memq system-type '(ms-dos windows-nt))
  404. (equal (downcase thisdir) (downcase (car tail))))))
  405. (setq tail (cdr tail)))
  406. ;;Splice the new section in.
  407. (when tail
  408. (setcdr tail (append (mapcar 'expand-file-name dirs) (cdr tail))))))
  409. (defun normal-top-level ()
  410. "Emacs calls this function when it first starts up.
  411. It sets `command-line-processed', processes the command-line,
  412. reads the initialization files, etc.
  413. It is the default value of the variable `top-level'."
  414. (if command-line-processed
  415. (message "Back to top level.")
  416. (setq command-line-processed t)
  417. (let ((dir default-directory))
  418. (with-current-buffer "*Messages*"
  419. ;; Make it easy to do like "tail -f".
  420. (set (make-local-variable 'window-point-insertion-type) t)
  421. ;; Give *Messages* the same default-directory as *scratch*,
  422. ;; just to keep things predictable.
  423. (setq default-directory dir)))
  424. ;; `user-full-name' is now known; reset its standard-value here.
  425. (put 'user-full-name 'standard-value
  426. (list (default-value 'user-full-name)))
  427. ;; Look in each dir in load-path for a subdirs.el file.
  428. ;; If we find one, load it, which will add the appropriate subdirs
  429. ;; of that dir into load-path,
  430. ;; Look for a leim-list.el file too. Loading it will register
  431. ;; available input methods.
  432. (let ((tail load-path) dir)
  433. (while tail
  434. (setq dir (car tail))
  435. (let ((default-directory dir))
  436. (load (expand-file-name "subdirs.el") t t t))
  437. (let ((default-directory dir))
  438. (load (expand-file-name "leim-list.el") t t t))
  439. ;; We don't use a dolist loop and we put this "setq-cdr" command at
  440. ;; the end, because the subdirs.el files may add elements to the end
  441. ;; of load-path and we want to take it into account.
  442. (setq tail (cdr tail))))
  443. ;; If the PWD environment variable isn't accurate, delete it.
  444. (let ((pwd (getenv "PWD")))
  445. (and (stringp pwd)
  446. ;; Use FOO/., so that if FOO is a symlink, file-attributes
  447. ;; describes the directory linked to, not FOO itself.
  448. (or (equal (file-attributes
  449. (concat (file-name-as-directory pwd) "."))
  450. (file-attributes
  451. (concat (file-name-as-directory default-directory)
  452. ".")))
  453. (setq process-environment
  454. (delete (concat "PWD=" pwd)
  455. process-environment)))))
  456. (setq default-directory (abbreviate-file-name default-directory))
  457. (let ((old-face-font-rescale-alist face-font-rescale-alist))
  458. (unwind-protect
  459. (command-line)
  460. ;; Do this again, in case .emacs defined more abbreviations.
  461. (setq default-directory (abbreviate-file-name default-directory))
  462. ;; Specify the file for recording all the auto save files of this session.
  463. ;; This is used by recover-session.
  464. (or auto-save-list-file-name
  465. (and auto-save-list-file-prefix
  466. (setq auto-save-list-file-name
  467. ;; Under MS-DOS our PID is almost always reused between
  468. ;; Emacs invocations. We need something more unique.
  469. (cond ((eq system-type 'ms-dos)
  470. ;; We are going to access the auto-save
  471. ;; directory, so make sure it exists.
  472. (make-directory
  473. (file-name-directory auto-save-list-file-prefix)
  474. t)
  475. (concat
  476. (make-temp-name
  477. (expand-file-name
  478. auto-save-list-file-prefix))
  479. "~"))
  480. (t
  481. (expand-file-name
  482. (format "%s%d-%s~"
  483. auto-save-list-file-prefix
  484. (emacs-pid)
  485. (system-name))))))))
  486. (unless inhibit-startup-hooks
  487. (run-hooks 'emacs-startup-hook)
  488. (and term-setup-hook
  489. (run-hooks 'term-setup-hook)))
  490. ;; Don't do this if we failed to create the initial frame,
  491. ;; for instance due to a dense colormap.
  492. (when (or frame-initial-frame
  493. ;; If frame-initial-frame has no meaning, do this anyway.
  494. (not (and initial-window-system
  495. (not noninteractive)
  496. (not (eq initial-window-system 'pc)))))
  497. ;; FIXME: The user's init file may change
  498. ;; face-font-rescale-alist. However, the default face
  499. ;; already has an assigned font object, which does not take
  500. ;; face-font-rescale-alist into account. For such
  501. ;; situations, we ought to have a way to find all font
  502. ;; objects and regenerate them; currently we do not. As a
  503. ;; workaround, we specifically reset te default face's :font
  504. ;; attribute here. See bug#1785.
  505. (unless (eq face-font-rescale-alist
  506. old-face-font-rescale-alist)
  507. (set-face-attribute 'default nil :font (font-spec)))
  508. ;; Modify the initial frame based on what .emacs puts into
  509. ;; ...-frame-alist.
  510. (if (fboundp 'frame-notice-user-settings)
  511. (frame-notice-user-settings))
  512. ;; Set the faces for the initial background mode even if
  513. ;; frame-notice-user-settings didn't (such as on a tty).
  514. ;; frame-set-background-mode is idempotent, so it won't
  515. ;; cause any harm if it's already been done.
  516. (if (fboundp 'frame-set-background-mode)
  517. (frame-set-background-mode (selected-frame))))
  518. ;; Now we know the user's default font, so add it to the menu.
  519. (if (fboundp 'font-menu-add-default)
  520. (font-menu-add-default))
  521. (and window-setup-hook
  522. (run-hooks 'window-setup-hook))))
  523. ;; Subprocesses of Emacs do not have direct access to the terminal, so
  524. ;; unless told otherwise they should only assume a dumb terminal.
  525. ;; We are careful to do it late (after term-setup-hook), although the
  526. ;; new multi-tty code does not use $TERM any more there anyway.
  527. (setenv "TERM" "dumb")
  528. ;; Remove DISPLAY from the process-environment as well. This allows
  529. ;; `callproc.c' to give it a useful adaptive default which is either
  530. ;; the value of the `display' frame-parameter or the DISPLAY value
  531. ;; from initial-environment.
  532. (let ((display (frame-parameter nil 'display)))
  533. ;; Be careful which DISPLAY to remove from process-environment: follow
  534. ;; the logic of `callproc.c'.
  535. (if (stringp display) (setq display (concat "DISPLAY=" display))
  536. (dolist (varval initial-environment)
  537. (if (string-match "\\`DISPLAY=" varval)
  538. (setq display varval))))
  539. (when display
  540. (delete display process-environment)))))
  541. ;; Precompute the keyboard equivalents in the menu bar items.
  542. ;; Command-line options supported by tty's:
  543. (defconst tty-long-option-alist
  544. '(("--name" . "-name")
  545. ("--title" . "-T")
  546. ("--reverse-video" . "-reverse")
  547. ("--foreground-color" . "-fg")
  548. ("--background-color" . "-bg")
  549. ("--color" . "-color")))
  550. (defconst tool-bar-images-pixel-height 24
  551. "Height in pixels of images in the tool-bar.")
  552. (defvar tool-bar-originally-present nil
  553. "Non-nil if tool-bars are present before user and site init files are read.")
  554. (defvar handle-args-function-alist '((nil . tty-handle-args))
  555. "Functions for processing window-system dependent command-line arguments.
  556. Window system startup files should add their own function to this
  557. alist, which should parse the command line arguments. Those
  558. pertaining to the window system should be processed and removed
  559. from the returned command line.")
  560. (defvar window-system-initialization-alist '((nil . ignore))
  561. "Alist of window-system initialization functions.
  562. Window-system startup files should add their own initialization
  563. function to this list. The function should take no arguments,
  564. and initialize the window system environment to prepare for
  565. opening the first frame (e.g. open a connection to an X server).")
  566. (defun tty-handle-args (args)
  567. "Handle the X-like command-line arguments \"-fg\", \"-bg\", \"-name\", etc."
  568. (let (rest)
  569. (message "%S" args)
  570. (while (and args
  571. (not (equal (car args) "--")))
  572. (let* ((argi (pop args))
  573. (orig-argi argi)
  574. argval completion)
  575. ;; Check for long options with attached arguments
  576. ;; and separate out the attached option argument into argval.
  577. (when (string-match "^\\(--[^=]*\\)=" argi)
  578. (setq argval (substring argi (match-end 0))
  579. argi (match-string 1 argi)))
  580. (when (string-match "^--" argi)
  581. (setq completion (try-completion argi tty-long-option-alist))
  582. (if (eq completion t)
  583. ;; Exact match for long option.
  584. (setq argi (cdr (assoc argi tty-long-option-alist)))
  585. (if (stringp completion)
  586. (let ((elt (assoc completion tty-long-option-alist)))
  587. ;; Check for abbreviated long option.
  588. (or elt
  589. (error "Option `%s' is ambiguous" argi))
  590. (setq argi (cdr elt)))
  591. ;; Check for a short option.
  592. (setq argval nil
  593. argi orig-argi))))
  594. (cond ((member argi '("-fg" "-foreground"))
  595. (push (cons 'foreground-color (or argval (pop args)))
  596. default-frame-alist))
  597. ((member argi '("-bg" "-background"))
  598. (push (cons 'background-color (or argval (pop args)))
  599. default-frame-alist))
  600. ((member argi '("-T" "-name"))
  601. (unless argval (setq argval (pop args)))
  602. (push (cons 'title
  603. (if (stringp argval)
  604. argval
  605. (let ((case-fold-search t)
  606. i)
  607. (setq argval (invocation-name))
  608. ;; Change any . or * characters in name to
  609. ;; hyphens, so as to emulate behavior on X.
  610. (while
  611. (setq i (string-match "[.*]" argval))
  612. (aset argval i ?-))
  613. argval)))
  614. default-frame-alist))
  615. ((member argi '("-r" "-rv" "-reverse"))
  616. (push '(reverse . t)
  617. default-frame-alist))
  618. ((equal argi "-color")
  619. (unless argval (setq argval 8)) ; default --color means 8 ANSI colors
  620. (push (cons 'tty-color-mode
  621. (cond
  622. ((numberp argval) argval)
  623. ((string-match "-?[0-9]+" argval)
  624. (string-to-number argval))
  625. (t (intern argval))))
  626. default-frame-alist))
  627. (t
  628. (push argi rest)))))
  629. (nreverse rest)))
  630. (declare-function x-get-resource "frame.c"
  631. (attribute class &optional component subclass))
  632. (declare-function tool-bar-mode "tool-bar" (&optional arg))
  633. (declare-function tool-bar-setup "tool-bar")
  634. (defvar server-name)
  635. (defvar server-process)
  636. (defun command-line ()
  637. "A subroutine of `normal-top-level'.
  638. Amongst another things, it parses the command-line arguments."
  639. (setq before-init-time (current-time)
  640. after-init-time nil
  641. command-line-default-directory default-directory)
  642. ;; Force recomputation, in case it was computed during the dump.
  643. (setq abbreviated-home-dir nil)
  644. ;; See if we should import version-control from the environment variable.
  645. (let ((vc (getenv "VERSION_CONTROL")))
  646. (cond ((eq vc nil)) ;don't do anything if not set
  647. ((member vc '("t" "numbered"))
  648. (setq version-control t))
  649. ((member vc '("nil" "existing"))
  650. (setq version-control nil))
  651. ((member vc '("never" "simple"))
  652. (setq version-control 'never))))
  653. ;;! This has been commented out; I currently find the behavior when
  654. ;;! split-window-keep-point is nil disturbing, but if I can get used
  655. ;;! to it, then it would be better to eliminate the option.
  656. ;;! ;; Choose a good default value for split-window-keep-point.
  657. ;;! (setq split-window-keep-point (> baud-rate 2400))
  658. ;; Set the default strings to display in mode line for
  659. ;; end-of-line formats that aren't native to this platform.
  660. (cond
  661. ((memq system-type '(ms-dos windows-nt))
  662. (setq eol-mnemonic-unix "(Unix)"
  663. eol-mnemonic-mac "(Mac)"))
  664. (t ; this is for Unix/GNU/Linux systems
  665. (setq eol-mnemonic-dos "(DOS)"
  666. eol-mnemonic-mac "(Mac)")))
  667. (set-locale-environment nil)
  668. ;; Convert preloaded file names in load-history to absolute.
  669. (let ((simple-file-name
  670. ;; Look for simple.el or simple.elc and use their directory
  671. ;; as the place where all Lisp files live.
  672. (locate-file "simple" load-path (get-load-suffixes)))
  673. lisp-dir)
  674. ;; Don't abort if simple.el cannot be found, but print a warning.
  675. (if (null simple-file-name)
  676. (progn
  677. (princ "Warning: Could not find simple.el nor simple.elc"
  678. 'external-debugging-output)
  679. (terpri 'external-debugging-output))
  680. (setq lisp-dir (file-truename (file-name-directory simple-file-name)))
  681. (setq load-history
  682. (mapcar (lambda (elt)
  683. (if (and (stringp (car elt))
  684. (not (file-name-absolute-p (car elt))))
  685. (cons (concat lisp-dir
  686. (car elt))
  687. (cdr elt))
  688. elt))
  689. load-history))))
  690. ;; Convert the arguments to Emacs internal representation.
  691. (let ((args (cdr command-line-args)))
  692. (while args
  693. (setcar args
  694. (decode-coding-string (car args) locale-coding-system t))
  695. (pop args)))
  696. (let ((done nil)
  697. (args (cdr command-line-args))
  698. display-arg)
  699. ;; Figure out which user's init file to load,
  700. ;; either from the environment or from the options.
  701. (setq init-file-user (if noninteractive nil (user-login-name)))
  702. ;; If user has not done su, use current $HOME to find .emacs.
  703. (and init-file-user
  704. (equal init-file-user (user-real-login-name))
  705. (setq init-file-user ""))
  706. ;; Process the command-line args, and delete the arguments
  707. ;; processed. This is consistent with the way main in emacs.c
  708. ;; does things.
  709. (while (and (not done) args)
  710. (let* ((longopts '(("--no-init-file") ("--no-site-file") ("--debug-init")
  711. ("--user") ("--iconic") ("--icon-type") ("--quick")
  712. ("--no-blinking-cursor") ("--basic-display")))
  713. (argi (pop args))
  714. (orig-argi argi)
  715. argval)
  716. ;; Handle --OPTION=VALUE format.
  717. (when (string-match "\\`\\(--[^=]*\\)=" argi)
  718. (setq argval (substring argi (match-end 0))
  719. argi (match-string 1 argi)))
  720. (when (string-match "\\`--." orig-argi)
  721. (let ((completion (try-completion argi longopts)))
  722. (cond ((eq completion t)
  723. (setq argi (substring argi 1)))
  724. ((stringp completion)
  725. (let ((elt (assoc completion longopts)))
  726. (unless elt
  727. (error "Option `%s' is ambiguous" argi))
  728. (setq argi (substring (car elt) 1))))
  729. (t
  730. (setq argval nil
  731. argi orig-argi)))))
  732. (cond
  733. ;; The --display arg is handled partly in C, partly in Lisp.
  734. ;; When it shows up here, we just put it back to be handled
  735. ;; by `command-line-1'.
  736. ((member argi '("-d" "-display"))
  737. (setq display-arg (list argi (pop args))))
  738. ((member argi '("-Q" "-quick"))
  739. (setq init-file-user nil
  740. site-run-file nil
  741. inhibit-x-resources t))
  742. ((member argi '("-D" "-basic-display"))
  743. (setq no-blinking-cursor t
  744. emacs-basic-display t)
  745. (push '(vertical-scroll-bars . nil) initial-frame-alist))
  746. ((member argi '("-q" "-no-init-file"))
  747. (setq init-file-user nil))
  748. ((member argi '("-u" "-user"))
  749. (setq init-file-user (or argval (pop args))
  750. argval nil))
  751. ((equal argi "-no-site-file")
  752. (setq site-run-file nil))
  753. ((equal argi "-debug-init")
  754. (setq init-file-debug t))
  755. ((equal argi "-iconic")
  756. (push '(visibility . icon) initial-frame-alist))
  757. ((member argi '("-nbc" "-no-blinking-cursor"))
  758. (setq no-blinking-cursor t))
  759. ;; Push the popped arg back on the list of arguments.
  760. (t
  761. (push argi args)
  762. (setq done t)))
  763. ;; Was argval set but not used?
  764. (and argval
  765. (error "Option `%s' doesn't allow an argument" argi))))
  766. ;; Re-attach the --display arg.
  767. (and display-arg (setq args (append display-arg args)))
  768. ;; Re-attach the program name to the front of the arg list.
  769. (and command-line-args
  770. (setcdr command-line-args args)))
  771. ;; Make sure window system's init file was loaded in loadup.el if
  772. ;; using a window system.
  773. ;; Initialize the window-system only after processing the command-line
  774. ;; args so that -Q can influence this initialization.
  775. (condition-case error
  776. (unless noninteractive
  777. (if (and initial-window-system
  778. (not (featurep
  779. (intern
  780. (concat (symbol-name initial-window-system) "-win")))))
  781. (error "Unsupported window system `%s'" initial-window-system))
  782. ;; Process window-system specific command line parameters.
  783. (setq command-line-args
  784. (funcall
  785. (or (cdr (assq initial-window-system handle-args-function-alist))
  786. (error "Unsupported window system `%s'" initial-window-system))
  787. command-line-args))
  788. ;; Initialize the window system. (Open connection, etc.)
  789. (funcall
  790. (or (cdr (assq initial-window-system window-system-initialization-alist))
  791. (error "Unsupported window system `%s'" initial-window-system))))
  792. ;; If there was an error, print the error message and exit.
  793. (error
  794. (princ
  795. (if (eq (car error) 'error)
  796. (apply 'concat (cdr error))
  797. (if (memq 'file-error (get (car error) 'error-conditions))
  798. (format "%s: %s"
  799. (nth 1 error)
  800. (mapconcat (lambda (obj) (prin1-to-string obj t))
  801. (cdr (cdr error)) ", "))
  802. (format "%s: %s"
  803. (get (car error) 'error-message)
  804. (mapconcat (lambda (obj) (prin1-to-string obj t))
  805. (cdr error) ", "))))
  806. 'external-debugging-output)
  807. (terpri 'external-debugging-output)
  808. (setq initial-window-system nil)
  809. (kill-emacs)))
  810. (run-hooks 'before-init-hook)
  811. ;; Under X, this creates the X frame and deletes the terminal frame.
  812. (unless (daemonp)
  813. ;; If X resources are available, use them to initialize the values
  814. ;; of `tool-bar-mode' and `menu-bar-mode', as well as the value of
  815. ;; `no-blinking-cursor' and the `cursor' face.
  816. (cond
  817. ((or noninteractive emacs-basic-display)
  818. (setq menu-bar-mode nil
  819. tool-bar-mode nil
  820. no-blinking-cursor t))
  821. ((memq initial-window-system '(x w32 ns))
  822. (let ((no-vals '("no" "off" "false" "0")))
  823. (if (member (x-get-resource "menuBar" "MenuBar") no-vals)
  824. (setq menu-bar-mode nil))
  825. (if (member (x-get-resource "toolBar" "ToolBar") no-vals)
  826. (setq tool-bar-mode nil))
  827. (if (member (x-get-resource "cursorBlink" "CursorBlink")
  828. no-vals)
  829. (setq no-blinking-cursor t)))
  830. ;; If the cursorColor X resource exists, alter the `cursor' face
  831. ;; spec, but mark it as changed outside of Customize.
  832. (let ((color (x-get-resource "cursorColor" "Foreground")))
  833. (when color
  834. (put 'cursor 'theme-face
  835. `((changed ((t :background ,color)))))
  836. (put 'cursor 'face-modified t)))))
  837. (frame-initialize))
  838. (when (fboundp 'x-create-frame)
  839. ;; Set up the tool-bar (even in tty frames, since Emacs might open a
  840. ;; graphical frame later).
  841. (unless noninteractive
  842. (tool-bar-setup)))
  843. ;; Turn off blinking cursor if so specified in X resources. This is here
  844. ;; only because all other settings of no-blinking-cursor are here.
  845. (unless (or noninteractive
  846. emacs-basic-display
  847. (and (memq window-system '(x w32 ns))
  848. (not (member (x-get-resource "cursorBlink" "CursorBlink")
  849. '("no" "off" "false" "0")))))
  850. (setq no-blinking-cursor t))
  851. ;; Re-evaluate predefined variables whose initial value depends on
  852. ;; the runtime context.
  853. (mapc 'custom-reevaluate-setting
  854. ;; Initialize them in the same order they were loaded, in case there
  855. ;; are dependencies between them.
  856. (prog1 (nreverse custom-delayed-init-variables)
  857. (setq custom-delayed-init-variables nil)))
  858. (normal-erase-is-backspace-setup-frame)
  859. ;; Register default TTY colors for the case the terminal hasn't a
  860. ;; terminal init file. We do this regardless of whether the terminal
  861. ;; supports colors or not and regardless the current display type,
  862. ;; since users can connect to color-capable terminals and also
  863. ;; switch color support on or off in mid-session by setting the
  864. ;; tty-color-mode frame parameter.
  865. ;; Exception: the `pc' ``window system'' has only 16 fixed colors,
  866. ;; and they are already set at this point by a suitable function in
  867. ;; window-system-initialization-alist.
  868. (or (eq initial-window-system 'pc)
  869. (tty-register-default-colors))
  870. ;; Record whether the tool-bar is present before the user and site
  871. ;; init files are processed. frame-notice-user-settings uses this
  872. ;; to determine if the tool-bar has been disabled by the init files,
  873. ;; and the frame needs to be resized.
  874. (when (fboundp 'frame-notice-user-settings)
  875. (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
  876. (assq 'tool-bar-lines default-frame-alist))))
  877. (setq tool-bar-originally-present
  878. (and tool-bar-lines
  879. (cdr tool-bar-lines)
  880. (not (eq 0 (cdr tool-bar-lines)))))))
  881. (let ((old-scalable-fonts-allowed scalable-fonts-allowed)
  882. (old-font-list-limit font-list-limit)
  883. (old-face-ignored-fonts face-ignored-fonts))
  884. ;; Run the site-start library if it exists. The point of this file is
  885. ;; that it is run before .emacs. There is no point in doing this after
  886. ;; .emacs; that is useless.
  887. ;; Note that user-init-file is nil at this point. Code that might
  888. ;; be loaded from site-run-file and wants to test if -q was given
  889. ;; should check init-file-user instead, since that is already set.
  890. ;; See cus-edit.el for an example.
  891. (if site-run-file
  892. (load site-run-file t t))
  893. ;; Sites should not disable this. Only individuals should disable
  894. ;; the startup screen.
  895. (setq inhibit-startup-screen nil)
  896. ;; Warn for invalid user name.
  897. (when init-file-user
  898. (if (string-match "[~/:\n]" init-file-user)
  899. (display-warning 'initialization
  900. (format "Invalid user name %s"
  901. init-file-user)
  902. :error)
  903. (if (file-directory-p (expand-file-name
  904. ;; We don't support ~USER on MS-Windows
  905. ;; and MS-DOS except for the current
  906. ;; user, and always load .emacs from
  907. ;; the current user's home directory
  908. ;; (see below). So always check "~",
  909. ;; even if invoked with "-u USER", or
  910. ;; if $USER or $LOGNAME are set to
  911. ;; something different.
  912. (if (memq system-type '(windows-nt ms-dos))
  913. "~"
  914. (concat "~" init-file-user))))
  915. nil
  916. (display-warning 'initialization
  917. (format "User %s has no home directory"
  918. init-file-user)
  919. :error))))
  920. ;; Load that user's init file, or the default one, or none.
  921. (let (debug-on-error-from-init-file
  922. debug-on-error-should-be-set
  923. (debug-on-error-initial
  924. (if (eq init-file-debug t) 'startup init-file-debug))
  925. (orig-enable-multibyte (default-value 'enable-multibyte-characters)))
  926. (let ((debug-on-error debug-on-error-initial)
  927. ;; This function actually reads the init files.
  928. (inner
  929. (function
  930. (lambda ()
  931. (if init-file-user
  932. (let ((user-init-file-1
  933. (cond
  934. ((eq system-type 'ms-dos)
  935. (concat "~" init-file-user "/_emacs"))
  936. ((not (eq system-type 'windows-nt))
  937. (concat "~" init-file-user "/.emacs"))
  938. ;; Else deal with the Windows situation
  939. ((directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$")
  940. ;; Prefer .emacs on Windows.
  941. "~/.emacs")
  942. ((directory-files "~" nil "^_emacs\\(\\.elc?\\)?$")
  943. ;; Also support _emacs for compatibility, but warn about it.
  944. (push '(initialization
  945. "`_emacs' init file is deprecated, please use `.emacs'")
  946. delayed-warnings-list)
  947. "~/_emacs")
  948. (t ;; But default to .emacs if _emacs does not exist.
  949. "~/.emacs"))))
  950. ;; This tells `load' to store the file name found
  951. ;; into user-init-file.
  952. (setq user-init-file t)
  953. (load user-init-file-1 t t)
  954. (when (eq user-init-file t)
  955. ;; If we did not find ~/.emacs, try
  956. ;; ~/.emacs.d/init.el.
  957. (let ((otherfile
  958. (expand-file-name
  959. "init"
  960. (file-name-as-directory
  961. (concat "~" init-file-user "/.emacs.d")))))
  962. (load otherfile t t)
  963. ;; If we did not find the user's init file,
  964. ;; set user-init-file conclusively.
  965. ;; Don't let it be set from default.el.
  966. (when (eq user-init-file t)
  967. (setq user-init-file user-init-file-1))))
  968. ;; If we loaded a compiled file, set
  969. ;; `user-init-file' to the source version if that
  970. ;; exists.
  971. (when (and user-init-file
  972. (equal (file-name-extension user-init-file)
  973. "elc"))
  974. (let* ((source (file-name-sans-extension user-init-file))
  975. (alt (concat source ".el")))
  976. (setq source (cond ((file-exists-p alt) alt)
  977. ((file-exists-p source) source)
  978. (t nil)))
  979. (when source
  980. (when (file-newer-than-file-p source user-init-file)
  981. (message "Warning: %s is newer than %s"
  982. source user-init-file)
  983. (sit-for 1))
  984. (setq user-init-file source))))
  985. (unless inhibit-default-init
  986. (let ((inhibit-startup-screen nil))
  987. ;; Users are supposed to be told their rights.
  988. ;; (Plus how to get help and how to undo.)
  989. ;; Don't you dare turn this off for anyone
  990. ;; except yourself.
  991. (load "default" t t)))))))))
  992. (if init-file-debug
  993. ;; Do this without a condition-case if the user wants to debug.
  994. (funcall inner)
  995. (condition-case error
  996. (progn
  997. (funcall inner)
  998. (setq init-file-had-error nil))
  999. (error
  1000. (display-warning
  1001. 'initialization
  1002. (format "An error occurred while loading `%s':\n\n%s%s%s\n\n\
  1003. To ensure normal operation, you should investigate and remove the
  1004. cause of the error in your initialization file. Start Emacs with
  1005. the `--debug-init' option to view a complete error backtrace."
  1006. user-init-file
  1007. (get (car error) 'error-message)
  1008. (if (cdr error) ": " "")
  1009. (mapconcat (lambda (s) (prin1-to-string s t))
  1010. (cdr error) ", "))
  1011. :warning)
  1012. (setq init-file-had-error t))))
  1013. (if (and deactivate-mark transient-mark-mode)
  1014. (with-current-buffer (window-buffer)
  1015. (deactivate-mark)))
  1016. ;; If the user has a file of abbrevs, read it (unless -batch).
  1017. (when (and (not noninteractive)
  1018. (file-exists-p abbrev-file-name)
  1019. (file-readable-p abbrev-file-name))
  1020. (quietly-read-abbrev-file abbrev-file-name))
  1021. ;; If the abbrevs came entirely from the init file or the
  1022. ;; abbrevs file, they do not need saving.
  1023. (setq abbrevs-changed nil)
  1024. ;; If we can tell that the init file altered debug-on-error,
  1025. ;; arrange to preserve the value that it set up.
  1026. (or (eq debug-on-error debug-on-error-initial)
  1027. (setq debug-on-error-should-be-set t
  1028. debug-on-error-from-init-file debug-on-error)))
  1029. (if debug-on-error-should-be-set
  1030. (setq debug-on-error debug-on-error-from-init-file))
  1031. (unless (or (default-value 'enable-multibyte-characters)
  1032. (eq orig-enable-multibyte (default-value
  1033. 'enable-multibyte-characters)))
  1034. ;; Init file changed to unibyte. Reset existing multibyte
  1035. ;; buffers (probably *scratch*, *Messages*, *Minibuf-0*).
  1036. ;; Arguably this should only be done if they're free of
  1037. ;; multibyte characters.
  1038. (mapc (lambda (buffer)
  1039. (with-current-buffer buffer
  1040. (if enable-multibyte-characters
  1041. (set-buffer-multibyte nil))))
  1042. (buffer-list))
  1043. ;; Also re-set the language environment in case it was
  1044. ;; originally done before unibyte was set and is sensitive to
  1045. ;; unibyte (display table, terminal coding system &c).
  1046. (set-language-environment current-language-environment)))
  1047. ;; Do this here in case the init file sets mail-host-address.
  1048. (if (equal user-mail-address "")
  1049. (setq user-mail-address (or (getenv "EMAIL")
  1050. (concat (user-login-name) "@"
  1051. (or mail-host-address
  1052. (system-name))))))
  1053. ;; Originally face attributes were specified via
  1054. ;; `font-lock-face-attributes'. Users then changed the default
  1055. ;; face attributes by setting that variable. However, we try and
  1056. ;; be back-compatible and respect its value if set except for
  1057. ;; faces where M-x customize has been used to save changes for the
  1058. ;; face.
  1059. (when (boundp 'font-lock-face-attributes)
  1060. (let ((face-attributes font-lock-face-attributes))
  1061. (while face-attributes
  1062. (let* ((face-attribute (pop face-attributes))
  1063. (face (car face-attribute)))
  1064. ;; Rustle up a `defface' SPEC from a
  1065. ;; `font-lock-face-attributes' entry.
  1066. (unless (get face 'saved-face)
  1067. (let ((foreground (nth 1 face-attribute))
  1068. (background (nth 2 face-attribute))
  1069. (bold-p (nth 3 face-attribute))
  1070. (italic-p (nth 4 face-attribute))
  1071. (underline-p (nth 5 face-attribute))
  1072. face-spec)
  1073. (when foreground
  1074. (setq face-spec (cons ':foreground (cons foreground face-spec))))
  1075. (when background
  1076. (setq face-spec (cons ':background (cons background face-spec))))
  1077. (when bold-p
  1078. (setq face-spec (append '(:weight bold) face-spec)))
  1079. (when italic-p
  1080. (setq face-spec (append '(:slant italic) face-spec)))
  1081. (when underline-p
  1082. (setq face-spec (append '(:underline t) face-spec)))
  1083. (face-spec-set face (list (list t face-spec)) nil)))))))
  1084. ;; If parameter have been changed in the init file which influence
  1085. ;; face realization, clear the face cache so that new faces will
  1086. ;; be realized.
  1087. (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed)
  1088. (eq font-list-limit old-font-list-limit)
  1089. (eq face-ignored-fonts old-face-ignored-fonts))
  1090. (clear-face-cache)))
  1091. ;; If any package directory exists, initialize the package system.
  1092. (and user-init-file
  1093. package-enable-at-startup
  1094. (catch 'package-dir-found
  1095. (let (dirs)
  1096. (if (boundp 'package-directory-list)
  1097. (setq dirs package-directory-list)
  1098. (dolist (f load-path)
  1099. (and (stringp f)
  1100. (equal (file-name-nondirectory f) "site-lisp")
  1101. (push (expand-file-name "elpa" f) dirs))))
  1102. (push (if (boundp 'package-user-dir)
  1103. package-user-dir
  1104. (locate-user-emacs-file "elpa"))
  1105. dirs)
  1106. (dolist (dir dirs)
  1107. (when (file-directory-p dir)
  1108. (dolist (subdir (directory-files dir))
  1109. (when (and (file-directory-p (expand-file-name subdir dir))
  1110. (string-match
  1111. (concat "\\`" package-subdirectory-regexp "\\'")
  1112. subdir))
  1113. (throw 'package-dir-found t)))))))
  1114. (package-initialize))
  1115. (setq after-init-time (current-time))
  1116. (run-hooks 'after-init-hook)
  1117. ;; Decode all default-directory.
  1118. (if (and (default-value 'enable-multibyte-characters) locale-coding-system)
  1119. (save-excursion
  1120. (dolist (elt (buffer-list))
  1121. (set-buffer elt)
  1122. (if default-directory
  1123. (setq default-directory
  1124. (decode-coding-string default-directory
  1125. locale-coding-system t))))
  1126. (setq command-line-default-directory
  1127. (decode-coding-string command-line-default-directory
  1128. locale-coding-system t))))
  1129. ;; If *scratch* exists and init file didn't change its mode, initialize it.
  1130. (if (get-buffer "*scratch*")
  1131. (with-current-buffer "*scratch*"
  1132. (if (eq major-mode 'fundamental-mode)
  1133. (funcall initial-major-mode))))
  1134. ;; Load library for our terminal type.
  1135. ;; User init file can set term-file-prefix to nil to prevent this.
  1136. (unless (or noninteractive
  1137. initial-window-system)
  1138. (tty-run-terminal-initialization (selected-frame)))
  1139. ;; Update the out-of-memory error message based on user's key bindings
  1140. ;; for save-some-buffers.
  1141. (setq memory-signal-data
  1142. (list 'error
  1143. (substitute-command-keys "Memory exhausted--use \\[save-some-buffers] then exit and restart Emacs")))
  1144. ;; Process the remaining args.
  1145. (command-line-1 (cdr command-line-args))
  1146. ;; If -batch, terminate after processing the command options.
  1147. (if noninteractive (kill-emacs t))
  1148. ;; In daemon mode, start the server to allow clients to connect.
  1149. ;; This is done after loading the user's init file and after
  1150. ;; processing all command line arguments to allow e.g. `server-name'
  1151. ;; to be changed before the server starts.
  1152. (let ((dn (daemonp)))
  1153. (when dn
  1154. (when (stringp dn) (setq server-name dn))
  1155. (server-start)
  1156. (if server-process
  1157. (daemon-initialized)
  1158. (if (stringp dn)
  1159. (message
  1160. "Unable to start daemon: Emacs server named %S already running"
  1161. server-name)
  1162. (message "Unable to start the daemon.\nAnother instance of Emacs is running the server, either as daemon or interactively.\nYou can use emacsclient to connect to that Emacs process."))
  1163. (kill-emacs 1))))
  1164. ;; Run emacs-session-restore (session management) if started by
  1165. ;; the session manager and we have a session manager connection.
  1166. (if (and (boundp 'x-session-previous-id)
  1167. (stringp x-session-previous-id))
  1168. (with-no-warnings
  1169. (emacs-session-restore x-session-previous-id))))
  1170. (defcustom initial-scratch-message (purecopy "\
  1171. ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
  1172. ;; If you want to create a file, visit that file with C-x C-f,
  1173. ;; then enter the text in that file's own buffer.
  1174. ")
  1175. "Initial message displayed in *scratch* buffer at startup.
  1176. If this is nil, no message will be displayed."
  1177. :type '(choice (text :tag "Message")
  1178. (const :tag "none" nil))
  1179. :group 'initialization)
  1180. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1181. ;;; Fancy splash screen
  1182. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1183. (defconst fancy-startup-text
  1184. `((:face (variable-pitch font-lock-comment-face)
  1185. "Welcome to "
  1186. :link ("GNU Emacs"
  1187. ,(lambda (_button) (browse-url "http://www.gnu.org/software/emacs/"))
  1188. "Browse http://www.gnu.org/software/emacs/")
  1189. ", one component of the "
  1190. :link
  1191. ,(lambda ()
  1192. (if (eq system-type 'gnu/linux)
  1193. `("GNU/Linux"
  1194. ,(lambda (_button) (browse-url "http://www.gnu.org/gnu/linux-and-gnu.html"))
  1195. "Browse http://www.gnu.org/gnu/linux-and-gnu.html")
  1196. `("GNU" ,(lambda (_button) (describe-gnu-project))
  1197. "Display info on the GNU project")))
  1198. " operating system.\n\n"
  1199. :face variable-pitch
  1200. :link ("Emacs Tutorial" ,(lambda (_button) (help-with-tutorial)))
  1201. "\tLearn basic keystroke commands"
  1202. ,(lambda ()
  1203. (let* ((en "TUTORIAL")
  1204. (tut (or (get-language-info current-language-environment
  1205. 'tutorial)
  1206. en))
  1207. (title (with-temp-buffer
  1208. (insert-file-contents
  1209. (expand-file-name tut tutorial-directory)
  1210. nil 0 256)
  1211. (search-forward ".")
  1212. (buffer-substring (point-min) (1- (point))))))
  1213. ;; If there is a specific tutorial for the current language
  1214. ;; environment and it is not English, append its title.
  1215. (if (string= en tut)
  1216. ""
  1217. (concat " (" title ")"))))
  1218. "\n"
  1219. :link ("Emacs Guided Tour"
  1220. ,(lambda (_button)
  1221. (browse-url "http://www.gnu.org/software/emacs/tour/"))
  1222. "Browse http://www.gnu.org/software/emacs/tour/")
  1223. "\tOverview of Emacs features at gnu.org\n"
  1224. :link ("View Emacs Manual" ,(lambda (_button) (info-emacs-manual)))
  1225. "\tView the Emacs manual using Info\n"
  1226. :link ("Absence of Warranty" ,(lambda (_button) (describe-no-warranty)))
  1227. "\tGNU Emacs comes with "
  1228. :face (variable-pitch (:slant oblique))
  1229. "ABSOLUTELY NO WARRANTY\n"
  1230. :face variable-pitch
  1231. :link ("Copying Conditions" ,(lambda (_button) (describe-copying)))
  1232. "\tConditions for redistributing and changing Emacs\n"
  1233. :link ("Ordering Manuals" ,(lambda (_button) (view-order-manuals)))
  1234. "\tPurchasing printed copies of manuals\n"
  1235. "\n"))
  1236. "A list of texts to show in the middle part of splash screens.
  1237. Each element in the list should be a list of strings or pairs
  1238. `:face FACE', like `fancy-splash-insert' accepts them.")
  1239. (defconst fancy-about-text
  1240. `((:face (variable-pitch font-lock-comment-face)
  1241. "This is "
  1242. :link ("GNU Emacs"
  1243. ,(lambda (_button) (browse-url "http://www.gnu.org/software/emacs/"))
  1244. "Browse http://www.gnu.org/software/emacs/")
  1245. ", one component of the "
  1246. :link
  1247. ,(lambda ()
  1248. (if (eq system-type 'gnu/linux)
  1249. `("GNU/Linux"
  1250. ,(lambda (_button)
  1251. (browse-url "http://www.gnu.org/gnu/linux-and-gnu.html"))
  1252. "Browse http://www.gnu.org/gnu/linux-and-gnu.html")
  1253. `("GNU" ,(lambda (_button) (describe-gnu-project))
  1254. "Display info on the GNU project.")))
  1255. " operating system.\n"
  1256. :face (variable-pitch font-lock-builtin-face)
  1257. "\n"
  1258. ,(lambda () (emacs-version))
  1259. "\n"
  1260. :face (variable-pitch (:height 0.8))
  1261. ,(lambda () emacs-copyright)
  1262. "\n\n"
  1263. :face variable-pitch
  1264. :link ("Authors"
  1265. ,(lambda (_button)
  1266. (view-file (expand-file-name "AUTHORS" data-directory))
  1267. (goto-char (point-min))))
  1268. "\tMany people have contributed code included in GNU Emacs\n"
  1269. :link ("Contributing"
  1270. ,(lambda (_button)
  1271. (view-file (expand-file-name "CONTRIBUTE" data-directory))
  1272. (goto-char (point-min))))
  1273. "\tHow to contribute improvements to Emacs\n"
  1274. "\n"
  1275. :link ("GNU and Freedom" ,(lambda (_button) (describe-gnu-project)))
  1276. "\tWhy we developed GNU Emacs, and the GNU operating system\n"
  1277. :link ("Absence of Warranty" ,(lambda (_button) (describe-no-warranty)))
  1278. "\tGNU Emacs comes with "
  1279. :face (variable-pitch (:slant oblique))
  1280. "ABSOLUTELY NO WARRANTY\n"
  1281. :face variable-pitch
  1282. :link ("Copying Conditions" ,(lambda (_button) (describe-copying)))
  1283. "\tConditions for redistributing and changing Emacs\n"
  1284. :link ("Getting New Versions" ,(lambda (_button) (describe-distribution)))
  1285. "\tHow to obtain the latest version of Emacs\n"
  1286. :link ("Ordering Manuals" ,(lambda (_button) (view-order-manuals)))
  1287. "\tBuying printed manuals from the FSF\n"
  1288. "\n"
  1289. :link ("Emacs Tutorial" ,(lambda (_button) (help-with-tutorial)))
  1290. "\tLearn basic Emacs keystroke commands"
  1291. ,(lambda ()
  1292. (let* ((en "TUTORIAL")
  1293. (tut (or (get-language-info current-language-environment
  1294. 'tutorial)
  1295. en))
  1296. (title (with-temp-buffer
  1297. (insert-file-contents
  1298. (expand-file-name tut tutorial-directory)
  1299. nil 0 256)
  1300. (search-forward ".")
  1301. (buffer-substring (point-min) (1- (point))))))
  1302. ;; If there is a specific tutorial for the current language
  1303. ;; environment and it is not English, append its title.
  1304. (if (string= en tut)
  1305. ""
  1306. (concat " (" title ")"))))
  1307. "\n"
  1308. :link ("Emacs Guided Tour"
  1309. ,(lambda (_button)
  1310. (browse-url "http://www.gnu.org/software/emacs/tour/"))
  1311. "Browse http://www.gnu.org/software/emacs/tour/")
  1312. "\tSee an overview of Emacs features at gnu.org"))
  1313. "A list of texts to show in the middle part of the About screen.
  1314. Each element in the list should be a list of strings or pairs
  1315. `:face FACE', like `fancy-splash-insert' accepts them.")
  1316. (defgroup fancy-splash-screen ()
  1317. "Fancy splash screen when Emacs starts."
  1318. :version "21.1"
  1319. :group 'initialization)
  1320. (defcustom fancy-splash-image nil
  1321. "The image to show in the splash screens, or nil for defaults."
  1322. :group 'fancy-splash-screen
  1323. :type '(choice (const :tag "Default" nil)
  1324. (file :tag "File")))
  1325. (defvar splash-screen-keymap
  1326. (let ((map (make-sparse-keymap)))
  1327. (suppress-keymap map)
  1328. (set-keymap-parent map button-buffer-map)
  1329. (define-key map "\C-?" 'scroll-down-command)
  1330. (define-key map " " 'scroll-up-command)
  1331. (define-key map "q" 'exit-splash-screen)
  1332. map)
  1333. "Keymap for splash screen buffer.")
  1334. ;; These are temporary storage areas for the splash screen display.
  1335. (defun fancy-splash-insert (&rest args)
  1336. "Insert text into the current buffer, with faces.
  1337. Arguments from ARGS should be either strings; functions called
  1338. with no args that return a string; pairs `:face FACE', where FACE
  1339. is a face specification usable with `put-text-property'; or pairs
  1340. `:link LINK' where LINK is a list of arguments to pass to
  1341. `insert-button', of the form (LABEL ACTION [HELP-ECHO]), which
  1342. specifies the button's label, `action' property and help-echo string.
  1343. FACE and LINK can also be functions, which are evaluated to obtain
  1344. a face or button specification."
  1345. (let ((current-face nil))
  1346. (while args
  1347. (cond ((eq (car args) :face)
  1348. (setq args (cdr args) current-face (car args))
  1349. (if (functionp current-face)
  1350. (setq current-face (funcall current-face))))
  1351. ((eq (car args) :link)
  1352. (setq args (cdr args))
  1353. (let ((spec (car args)))
  1354. (if (functionp spec)
  1355. (setq spec (funcall spec)))
  1356. (insert-button (car spec)
  1357. 'face (list 'link current-face)
  1358. 'action (cadr spec)
  1359. 'help-echo (concat "mouse-2, RET: "
  1360. (or (nth 2 spec)
  1361. "Follow this link"))
  1362. 'follow-link t)))
  1363. (t (insert (propertize (let ((it (car args)))
  1364. (if (functionp it)
  1365. (funcall it)
  1366. it))
  1367. 'face current-face
  1368. 'help-echo (startup-echo-area-message)))))
  1369. (setq args (cdr args)))))
  1370. (declare-function image-size "image.c" (spec &optional pixels frame))
  1371. (defun fancy-splash-head ()
  1372. "Insert the head part of the splash screen into the current buffer."
  1373. (let* ((image-file (cond ((stringp fancy-splash-image)
  1374. fancy-splash-image)
  1375. ((display-color-p)
  1376. (cond ((<= (display-planes) 8)
  1377. (if (image-type-available-p 'xpm)
  1378. "splash.xpm"
  1379. "splash.pbm"))
  1380. ((image-type-available-p 'svg)
  1381. "splash.svg")
  1382. ((image-type-available-p 'png)
  1383. "splash.png")
  1384. ((image-type-available-p 'xpm)
  1385. "splash.xpm")
  1386. (t "splash.pbm")))
  1387. (t "splash.pbm")))
  1388. (img (create-image image-file))
  1389. (image-width (and img (car (image-size img))))
  1390. (window-width (window-width (selected-window))))
  1391. (when img
  1392. (when (> window-width image-width)
  1393. ;; Center the image in the window.
  1394. (insert (propertize " " 'display
  1395. `(space :align-to (+ center (-0.5 . ,img)))))
  1396. ;; Change the color of the XPM version of the splash image
  1397. ;; so that it is visible with a dark frame background.
  1398. (when (and (memq 'xpm img)
  1399. (eq (frame-parameter nil 'background-mode) 'dark))
  1400. (setq img (append img '(:color-symbols (("#000000" . "gray30"))))))
  1401. ;; Insert the image with a help-echo and a link.
  1402. (make-button (prog1 (point) (insert-image img)) (point)
  1403. 'face 'default
  1404. 'help-echo "mouse-2, RET: Browse http://www.gnu.org/"
  1405. 'action (lambda (_button) (browse-url "http://www.gnu.org/"))
  1406. 'follow-link t)
  1407. (insert "\n\n")))))
  1408. (defun fancy-startup-tail (&optional concise)
  1409. "Insert the tail part of the splash screen into the current buffer."
  1410. (unless concise
  1411. (fancy-splash-insert
  1412. :face 'variable-pitch
  1413. "\nTo start... "
  1414. :link `("Open a File"
  1415. ,(lambda (_button) (call-interactively 'find-file))
  1416. "Specify a new file's name, to edit the file")
  1417. " "
  1418. :link `("Open Home Directory"
  1419. ,(lambda (_button) (dired "~"))
  1420. "Open your home directory, to operate on its files")
  1421. " "
  1422. :link `("Customize Startup"
  1423. ,(lambda (_button) (customize-group 'initialization))
  1424. "Change initialization settings including this screen")
  1425. "\n"))
  1426. (fancy-splash-insert
  1427. :face 'variable-pitch "To quit a partially entered command, type "
  1428. :face 'default "Control-g"
  1429. :face 'variable-pitch ".\n")
  1430. (fancy-splash-insert :face `(variable-pitch font-lock-builtin-face)
  1431. "\nThis is "
  1432. (emacs-version)
  1433. "\n"
  1434. :face '(variable-pitch (:height 0.8))
  1435. emacs-copyright
  1436. "\n")
  1437. (and auto-save-list-file-prefix
  1438. ;; Don't signal an error if the
  1439. ;; directory for auto-save-list files
  1440. ;; does not yet exist.
  1441. (file-directory-p (file-name-directory
  1442. auto-save-list-file-prefix))
  1443. (directory-files
  1444. (file-name-directory auto-save-list-file-prefix)
  1445. nil
  1446. (concat "\\`"
  1447. (regexp-quote (file-name-nondirectory
  1448. auto-save-list-file-prefix)))
  1449. t)
  1450. (fancy-splash-insert :face '(variable-pitch font-lock-comment-face)
  1451. "\nIf an Emacs session crashed recently, "
  1452. "type "
  1453. :face '(fixed-pitch font-lock-comment-face)
  1454. "Meta-x recover-session RET"
  1455. :face '(variable-pitch font-lock-comment-face)
  1456. "\nto recover"
  1457. " the files you were editing."))
  1458. (when concise
  1459. (fancy-splash-insert
  1460. :face 'variable-pitch "\n"
  1461. :link `("Dismiss this startup screen"
  1462. ,(lambda (_button)
  1463. (when startup-screen-inhibit-startup-screen
  1464. (customize-set-variable 'inhibit-startup-screen t)
  1465. (customize-mark-to-save 'inhibit-startup-screen)
  1466. (custom-save-all))
  1467. (let ((w (get-buffer-window "*GNU Emacs*")))
  1468. (and w (not (one-window-p)) (delete-window w)))
  1469. (kill-buffer "*GNU Emacs*")))
  1470. " ")
  1471. (when (or user-init-file custom-file)
  1472. (let ((checked (create-image "checked.xpm"
  1473. nil nil :ascent 'center))
  1474. (unchecked (create-image "unchecked.xpm"
  1475. nil nil :ascent 'center)))
  1476. (insert-button
  1477. " "
  1478. :on-glyph checked
  1479. :off-glyph unchecked
  1480. 'checked nil 'display unchecked 'follow-link t
  1481. 'action (lambda (button)
  1482. (if (overlay-get button 'checked)
  1483. (progn (overlay-put button 'checked nil)
  1484. (overlay-put button 'display
  1485. (overlay-get button :off-glyph))
  1486. (setq startup-screen-inhibit-startup-screen
  1487. nil))
  1488. (overlay-put button 'checked t)
  1489. (overlay-put button 'display
  1490. (overlay-get button :on-glyph))
  1491. (setq startup-screen-inhibit-startup-screen t)))))
  1492. (fancy-splash-insert :face '(variable-pitch (:height 0.9))
  1493. " Never show it again."))))
  1494. (defun exit-splash-screen ()
  1495. "Stop displaying the splash screen buffer."
  1496. (interactive)
  1497. (quit-window t))
  1498. (defun fancy-startup-screen (&optional concise)
  1499. "Display fancy startup screen.
  1500. If CONCISE is non-nil, display a concise version of the
  1501. splash screen in another window."
  1502. (let ((splash-buffer (get-buffer-create "*GNU Emacs*")))
  1503. (with-current-buffer splash-buffer
  1504. (let ((inhibit-read-only t))
  1505. (erase-buffer)
  1506. (setq default-directory command-line-default-directory)
  1507. (make-local-variable 'startup-screen-inhibit-startup-screen)
  1508. (if pure-space-overflow
  1509. (insert pure-space-overflow-message))
  1510. (unless concise
  1511. (fancy-splash-head))
  1512. (dolist (text fancy-startup-text)
  1513. (apply #'fancy-splash-insert text)
  1514. (insert "\n"))
  1515. (skip-chars-backward "\n")
  1516. (delete-region (point) (point-max))
  1517. (insert "\n")
  1518. (fancy-startup-tail concise))
  1519. (use-local-map splash-screen-keymap)
  1520. (setq tab-width 22
  1521. buffer-read-only t)
  1522. (set-buffer-modified-p nil)
  1523. (if (and view-read-only (not view-mode))
  1524. (view-mode-enter nil 'kill-buffer))
  1525. (goto-char (point-min))
  1526. (forward-line (if concise 2 4)))
  1527. (if concise
  1528. (progn
  1529. (display-buffer splash-buffer)
  1530. ;; If the splash screen is in a split window, fit it.
  1531. (let ((window (get-buffer-window splash-buffer t)))
  1532. (or (null window)
  1533. (eq window (selected-window))
  1534. (eq window (next-window window))
  1535. (fit-window-to-buffer window))))
  1536. (switch-to-buffer splash-buffer))))
  1537. (defun fancy-about-screen ()
  1538. "Display fancy About screen."
  1539. (let ((frame (fancy-splash-frame)))
  1540. (save-selected-window
  1541. (select-frame frame)
  1542. (switch-to-buffer "*About GNU Emacs*")
  1543. (setq buffer-undo-list t)
  1544. (let ((inhibit-read-only t))
  1545. (erase-buffer)
  1546. (if pure-space-overflow
  1547. (insert pure-space-overflow-message))
  1548. (fancy-splash-head)
  1549. (dolist (text fancy-about-text)
  1550. (apply #'fancy-splash-insert text)
  1551. (insert "\n"))
  1552. (set-buffer-modified-p nil)
  1553. (goto-char (point-min))
  1554. (force-mode-line-update))
  1555. (use-local-map splash-screen-keymap)
  1556. (setq tab-width 22)
  1557. (message "%s" (startup-echo-area-message))
  1558. (setq buffer-read-only t)
  1559. (goto-char (point-min))
  1560. (forward-line 3))))
  1561. (defun fancy-splash-frame ()
  1562. "Return the frame to use for the fancy splash screen.
  1563. Returning non-nil does not mean we should necessarily
  1564. use the fancy splash screen, but if we do use it,
  1565. we put it on this frame."
  1566. (let (chosen-frame)
  1567. (dolist (frame (append (frame-list) (list (selected-frame))))
  1568. (if (and (frame-visible-p frame)
  1569. (not (window-minibuffer-p (frame-selected-window frame))))
  1570. (setq chosen-frame frame)))
  1571. chosen-frame))
  1572. (defun use-fancy-splash-screens-p ()
  1573. "Return t if fancy splash screens should be used."
  1574. (when (and (display-graphic-p)
  1575. (or (and (display-color-p)
  1576. (image-type-available-p 'xpm))
  1577. (image-type-available-p 'pbm)))
  1578. (let ((frame (fancy-splash-frame)))
  1579. (when frame
  1580. (let* ((img (create-image (or fancy-splash-image
  1581. (if (and (display-color-p)
  1582. (image-type-available-p 'xpm))
  1583. "splash.xpm" "splash.pbm"))))
  1584. (image-height (and img (cdr (image-size img nil frame))))
  1585. ;; We test frame-height so that, if the frame is split
  1586. ;; by displaying a warning, that doesn't cause the normal
  1587. ;; splash screen to be used.
  1588. (frame-height (1- (frame-height frame))))
  1589. (> frame-height (+ image-height 19)))))))
  1590. (defun normal-splash-screen (&optional startup concise)
  1591. "Display non-graphic splash screen.
  1592. If optional argument STARTUP is non-nil, display the startup screen
  1593. after Emacs starts. If STARTUP is nil, display the About screen.
  1594. If CONCISE is non-nil, display a concise version of the
  1595. splash screen in another window."
  1596. (let ((splash-buffer (get-buffer-create "*About GNU Emacs*")))
  1597. (with-current-buffer splash-buffer
  1598. (setq buffer-read-only nil)
  1599. (erase-buffer)
  1600. (setq default-directory command-line-default-directory)
  1601. (set (make-local-variable 'tab-width) 8)
  1602. (if pure-space-overflow
  1603. (insert pure-space-overflow-message))
  1604. ;; The convention for this piece of code is that
  1605. ;; each piece of output starts with one or two newlines
  1606. ;; and does not end with any newlines.
  1607. (insert (if startup "Welcome to GNU Emacs" "This is GNU Emacs"))
  1608. (insert
  1609. (if (eq system-type 'gnu/linux)
  1610. ", one component of the GNU/Linux operating system.\n"
  1611. ", a part of the GNU operating system.\n"))
  1612. (if startup
  1613. (if (display-mouse-p)
  1614. ;; The user can use the mouse to activate menus
  1615. ;; so give help in terms of menu items.
  1616. (normal-mouse-startup-screen)
  1617. ;; No mouse menus, so give help using kbd commands.
  1618. (normal-no-mouse-startup-screen))
  1619. (normal-about-screen))
  1620. ;; The rest of the startup screen is the same on all
  1621. ;; kinds of terminals.
  1622. ;; Give information on recovering, if there was a crash.
  1623. (and startup
  1624. auto-save-list-file-prefix
  1625. ;; Don't signal an error if the
  1626. ;; directory for auto-save-list files
  1627. ;; does not yet exist.
  1628. (file-directory-p (file-name-directory
  1629. auto-save-list-file-prefix))
  1630. (directory-files
  1631. (file-name-directory auto-save-list-file-prefix)
  1632. nil
  1633. (concat "\\`"
  1634. (regexp-quote (file-name-nondirectory
  1635. auto-save-list-file-prefix)))
  1636. t)
  1637. (insert "\n\nIf an Emacs session crashed recently, "
  1638. "type Meta-x recover-session RET\nto recover"
  1639. " the files you were editing.\n"))
  1640. (use-local-map splash-screen-keymap)
  1641. ;; Display the input that we set up in the buffer.
  1642. (set-buffer-modified-p nil)
  1643. (setq buffer-read-only t)
  1644. (if (and view-read-only (not view-mode))
  1645. (view-mode-enter nil 'kill-buffer))
  1646. (if startup (rename-buffer "*GNU Emacs*" t))
  1647. (goto-char (point-min)))
  1648. (if concise
  1649. (display-buffer splash-buffer)
  1650. (switch-to-buffer splash-buffer))))
  1651. (defun normal-mouse-startup-screen ()
  1652. ;; The user can use the mouse to activate menus
  1653. ;; so give help in terms of menu items.
  1654. (insert "\
  1655. To follow a link, click Mouse-1 on it, or move to it and type RET.
  1656. To quit a partially entered command, type Control-g.\n")
  1657. (insert "\nImportant Help menu items:\n")
  1658. (insert-button "Emacs Tutorial"
  1659. 'action (lambda (_button) (help-with-tutorial))
  1660. 'follow-link t)
  1661. (insert "\t\tLearn basic Emacs keystroke commands\n")
  1662. (insert-button "Read the Emacs Manual"
  1663. 'action (lambda (_button) (info-emacs-manual))
  1664. 'follow-link t)
  1665. (insert "\tView the Emacs manual using Info\n")
  1666. (insert-button "\(Non)Warranty"
  1667. 'action (lambda (_button) (describe-no-warranty))
  1668. 'follow-link t)
  1669. (insert "\t\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
  1670. (insert-button "Copying Conditions"
  1671. 'action (lambda (_button) (describe-copying))
  1672. 'follow-link t)
  1673. (insert "\tConditions for redistributing and changing Emacs\n")
  1674. (insert-button "More Manuals / Ordering Manuals"
  1675. 'action (lambda (_button) (view-order-manuals))
  1676. 'follow-link t)
  1677. (insert " How to order printed manuals from the FSF\n")
  1678. (insert "\nUseful tasks:\n")
  1679. (insert-button "Visit New File"
  1680. 'action (lambda (_button) (call-interactively 'find-file))
  1681. 'follow-link t)
  1682. (insert "\t\tSpecify a new file's name, to edit the file\n")
  1683. (insert-button "Open Home Directory"
  1684. 'action (lambda (_button) (dired "~"))
  1685. 'follow-link t)
  1686. (insert "\tOpen your home directory, to operate on its files\n")
  1687. (insert-button "Customize Startup"
  1688. 'action (lambda (_button) (customize-group 'initialization))
  1689. 'follow-link t)
  1690. (insert "\tChange initialization settings including this screen\n")
  1691. (insert "\n" (emacs-version)
  1692. "\n" emacs-copyright))
  1693. ;; No mouse menus, so give help using kbd commands.
  1694. (defun normal-no-mouse-startup-screen ()
  1695. ;; If keys have their default meanings,
  1696. ;; use precomputed string to save lots of time.
  1697. (let* ((c-h-accessible
  1698. ;; If normal-erase-is-backspace is used on a tty, there's
  1699. ;; no way to invoke C-h and you have to use F1 instead.
  1700. (or (not (char-table-p keyboard-translate-table))
  1701. (eq (aref keyboard-translate-table ?\C-h) ?\C-h)))
  1702. (minor-mode-overriding-map-alist
  1703. (cons (cons (not c-h-accessible)
  1704. ;; If C-h can't be invoked, temporarily disable its
  1705. ;; binding, so where-is uses alternative bindings.
  1706. (let ((map (make-sparse-keymap)))
  1707. (define-key map [?\C-h] 'undefined)
  1708. map))
  1709. minor-mode-overriding-map-alist)))
  1710. (insert (format "\nGet help\t %s\n"
  1711. (let ((where (where-is-internal 'help-command nil t)))
  1712. (cond
  1713. ((equal where [?\C-h])
  1714. "C-h (Hold down CTRL and press h)")
  1715. (where (key-description where))
  1716. (t "M-x help")))))
  1717. (insert-button "Emacs manual"
  1718. 'action (lambda (_button) (info-emacs-manual))
  1719. 'follow-link t)
  1720. (insert (substitute-command-keys"\t \\[info-emacs-manual]\t"))
  1721. (insert-button "Browse manuals"
  1722. 'action (lambda (_button) (Info-directory))
  1723. 'follow-link t)
  1724. (insert (substitute-command-keys "\t \\[info]\n"))
  1725. (insert-button "Emacs tutorial"
  1726. 'action (lambda (_button) (help-with-tutorial))
  1727. 'follow-link t)
  1728. (insert (substitute-command-keys
  1729. "\t \\[help-with-tutorial]\tUndo changes\t \\[undo]\n"))
  1730. (insert-button "Buy manuals"
  1731. 'action (lambda (_button) (view-order-manuals))
  1732. 'follow-link t)
  1733. (insert (substitute-command-keys
  1734. "\t \\[view-order-manuals]\tExit Emacs\t \\[save-buffers-kill-terminal]")))
  1735. ;; Say how to use the menu bar with the keyboard.
  1736. (insert "\n")
  1737. (insert-button "Activate menubar"
  1738. 'action (lambda (_button) (tmm-menubar))
  1739. 'follow-link t)
  1740. (if (and (eq (key-binding "\M-`") 'tmm-menubar)
  1741. (eq (key-binding [f10]) 'tmm-menubar))
  1742. (insert " F10 or ESC ` or M-`")
  1743. (insert (substitute-command-keys " \\[tmm-menubar]")))
  1744. ;; Many users seem to have problems with these.
  1745. (insert "
  1746. \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
  1747. If you have no Meta key, you may instead type ESC followed by the character.)")
  1748. ;; Insert links to useful tasks
  1749. (insert "\nUseful tasks:\n")
  1750. (insert-button "Visit New File"
  1751. 'action (lambda (_button) (call-interactively 'find-file))
  1752. 'follow-link t)
  1753. (insert "\t\t\t")
  1754. (insert-button "Open Home Directory"
  1755. 'action (lambda (_button) (dired "~"))
  1756. 'follow-link t)
  1757. (insert "\n")
  1758. (insert-button "Customize Startup"
  1759. 'action (lambda (_button) (customize-group 'initialization))
  1760. 'follow-link t)
  1761. (insert "\t\t")
  1762. (insert-button "Open *scratch* buffer"
  1763. 'action (lambda (_button) (switch-to-buffer
  1764. (get-buffer-create "*scratch*")))
  1765. 'follow-link t)
  1766. (insert "\n")
  1767. (insert "\n" (emacs-version) "\n" emacs-copyright "\n")
  1768. (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
  1769. (eq (key-binding "\C-h\C-d") 'describe-distribution)
  1770. (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
  1771. (progn
  1772. (insert
  1773. "
  1774. GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for ")
  1775. (insert-button "full details"
  1776. 'action (lambda (_button) (describe-no-warranty))
  1777. 'follow-link t)
  1778. (insert ".
  1779. Emacs is Free Software--Free as in Freedom--so you can redistribute copies
  1780. of Emacs and modify it; type C-h C-c to see ")
  1781. (insert-button "the conditions"
  1782. 'action (lambda (_button) (describe-copying))
  1783. 'follow-link t)
  1784. (insert ".
  1785. Type C-h C-d for information on ")
  1786. (insert-button "getting the latest version"
  1787. 'action (lambda (_button) (describe-distribution))
  1788. 'follow-link t)
  1789. (insert "."))
  1790. (insert (substitute-command-keys
  1791. "
  1792. GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for "))
  1793. (insert-button "full details"
  1794. 'action (lambda (_button) (describe-no-warranty))
  1795. 'follow-link t)
  1796. (insert (substitute-command-keys ".
  1797. Emacs is Free Software--Free as in Freedom--so you can redistribute copies
  1798. of Emacs and modify it; type \\[describe-copying] to see "))
  1799. (insert-button "the conditions"
  1800. 'action (lambda (_button) (describe-copying))
  1801. 'follow-link t)
  1802. (insert (substitute-command-keys".
  1803. Type \\[describe-distribution] for information on "))
  1804. (insert-button "getting the latest version"
  1805. 'action (lambda (_button) (describe-distribution))
  1806. 'follow-link t)
  1807. (insert ".")))
  1808. (defun normal-about-screen ()
  1809. (insert "\n" (emacs-version) "\n" emacs-copyright "\n\n")
  1810. (insert "To follow a link, click Mouse-1 on it, or move to it and type RET.\n\n")
  1811. (insert-button "Authors"
  1812. 'action
  1813. (lambda (_button)
  1814. (view-file (expand-file-name "AUTHORS" data-directory))
  1815. (goto-char (point-min)))
  1816. 'follow-link t)
  1817. (insert "\t\tMany people have contributed code included in GNU Emacs\n")
  1818. (insert-button "Contributing"
  1819. 'action
  1820. (lambda (_button)
  1821. (view-file (expand-file-name "CONTRIBUTE" data-directory))
  1822. (goto-char (point-min)))
  1823. 'follow-link t)
  1824. (insert "\tHow to contribute improvements to Emacs\n\n")
  1825. (insert-button "GNU and Freedom"
  1826. 'action (lambda (_button) (describe-gnu-project))
  1827. 'follow-link t)
  1828. (insert "\t\tWhy we developed GNU Emacs and the GNU system\n")
  1829. (insert-button "Absence of Warranty"
  1830. 'action (lambda (_button) (describe-no-warranty))
  1831. 'follow-link t)
  1832. (insert "\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
  1833. (insert-button "Copying Conditions"
  1834. 'action (lambda (_button) (describe-copying))
  1835. 'follow-link t)
  1836. (insert "\tConditions for redistributing and changing Emacs\n")
  1837. (insert-button "Getting New Versions"
  1838. 'action (lambda (_button) (describe-distribution))
  1839. 'follow-link t)
  1840. (insert "\tHow to get the latest version of GNU Emacs\n")
  1841. (insert-button "More Manuals / Ordering Manuals"
  1842. 'action (lambda (_button) (view-order-manuals))
  1843. 'follow-link t)
  1844. (insert "\tBuying printed manuals from the FSF\n"))
  1845. (defun startup-echo-area-message ()
  1846. (cond ((daemonp)
  1847. "Starting Emacs daemon.")
  1848. ((eq (key-binding "\C-h\C-a") 'about-emacs)
  1849. "For information about GNU Emacs and the GNU system, type C-h C-a.")
  1850. (t
  1851. (substitute-command-keys
  1852. "For information about GNU Emacs and the GNU system, type \
  1853. \\[about-emacs]."))))
  1854. (defun display-startup-echo-area-message ()
  1855. (let ((resize-mini-windows t))
  1856. (or noninteractive ;(input-pending-p) init-file-had-error
  1857. ;; t if the init file says to inhibit the echo area startup message.
  1858. (and inhibit-startup-echo-area-message
  1859. user-init-file
  1860. (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
  1861. (equal inhibit-startup-echo-area-message
  1862. (if (equal init-file-user "")
  1863. (user-login-name)
  1864. init-file-user)))
  1865. ;; Wasn't set with custom; see if .emacs has a setq.
  1866. (condition-case nil
  1867. (with-temp-buffer
  1868. (insert-file-contents user-init-file)
  1869. (re-search-forward
  1870. (concat
  1871. "([ \t\n]*setq[ \t\n]+"
  1872. "inhibit-startup-echo-area-message[ \t\n]+"
  1873. (regexp-quote
  1874. (prin1-to-string
  1875. (if (equal init-file-user "")
  1876. (user-login-name)
  1877. init-file-user)))
  1878. "[ \t\n]*)")
  1879. nil t))
  1880. (error nil))))
  1881. (message "%s" (startup-echo-area-message)))))
  1882. (defun display-startup-screen (&optional concise)
  1883. "Display startup screen according to display.
  1884. A fancy display is used on graphic displays, normal otherwise.
  1885. If CONCISE is non-nil, display a concise version of the startup
  1886. screen."
  1887. ;; Prevent recursive calls from server-process-filter.
  1888. (if (not (get-buffer "*GNU Emacs*"))
  1889. (if (use-fancy-splash-screens-p)
  1890. (fancy-startup-screen concise)
  1891. (normal-splash-screen t concise))))
  1892. (defun display-about-screen ()
  1893. "Display the *About GNU Emacs* buffer.
  1894. A fancy display is used on graphic displays, normal otherwise."
  1895. (interactive)
  1896. (if (use-fancy-splash-screens-p)
  1897. (fancy-about-screen)
  1898. (normal-splash-screen nil)))
  1899. (defalias 'about-emacs 'display-about-screen)
  1900. (defalias 'display-splash-screen 'display-startup-screen)
  1901. (defun command-line-1 (args-left)
  1902. "A subroutine of `command-line'."
  1903. (display-startup-echo-area-message)
  1904. (when (and pure-space-overflow
  1905. (not noninteractive))
  1906. (display-warning
  1907. 'initialization
  1908. "Building Emacs overflowed pure space.\
  1909. (See the node Pure Storage in the Lisp manual for details.)"
  1910. :warning))
  1911. (let ((file-count 0)
  1912. (command-line-args-left args-left)
  1913. first-file-buffer)
  1914. (when command-line-args-left
  1915. ;; We have command args; process them.
  1916. (let ((dir command-line-default-directory)
  1917. tem
  1918. ;; This approach loses for "-batch -L DIR --eval "(require foo)",
  1919. ;; if foo is intended to be found in DIR.
  1920. ;;
  1921. ;; ;; The directories listed in --directory/-L options will *appear*
  1922. ;; ;; at the front of `load-path' in the order they appear on the
  1923. ;; ;; command-line. We cannot do this by *placing* them at the front
  1924. ;; ;; in the order they appear, so we need this variable to hold them,
  1925. ;; ;; temporarily.
  1926. ;; extra-load-path
  1927. ;;
  1928. ;; To DTRT we keep track of the splice point and modify `load-path'
  1929. ;; straight away upon any --directory/-L option.
  1930. splice
  1931. just-files ;; t if this follows the magic -- option.
  1932. ;; This includes our standard options' long versions
  1933. ;; and long versions of what's on command-switch-alist.
  1934. (longopts
  1935. (append '("--funcall" "--load" "--insert" "--kill"
  1936. "--directory" "--eval" "--execute" "--no-splash"
  1937. "--find-file" "--visit" "--file" "--no-desktop")
  1938. (mapcar (lambda (elt) (concat "-" (car elt)))
  1939. command-switch-alist)))
  1940. (line 0)
  1941. (column 0))
  1942. ;; Add the long X options to longopts.
  1943. (dolist (tem command-line-x-option-alist)
  1944. (if (string-match "^--" (car tem))
  1945. (push (car tem) longopts)))
  1946. ;; Add the long NS options to longopts.
  1947. (dolist (tem command-line-ns-option-alist)
  1948. (if (string-match "^--" (car tem))
  1949. (push (list (car tem)) longopts)))
  1950. ;; Loop, processing options.
  1951. (while command-line-args-left
  1952. (let* ((argi (car command-line-args-left))
  1953. (orig-argi argi)
  1954. argval completion)
  1955. (setq command-line-args-left (cdr command-line-args-left))
  1956. ;; Do preliminary decoding of the option.
  1957. (if just-files
  1958. ;; After --, don't look for options; treat all args as files.
  1959. (setq argi "")
  1960. ;; Convert long options to ordinary options
  1961. ;; and separate out an attached option argument into argval.
  1962. (when (string-match "\\`\\(--[^=]*\\)=" argi)
  1963. (setq argval (substring argi (match-end 0))
  1964. argi (match-string 1 argi)))
  1965. (when (string-match "\\`--?[^-]" orig-argi)
  1966. (setq completion (try-completion argi longopts))
  1967. (if (eq completion t)
  1968. (setq argi (substring argi 1))
  1969. (if (stringp completion)
  1970. (let ((elt (member completion longopts)))
  1971. (or elt
  1972. (error "Option `%s' is ambiguous" argi))
  1973. (setq argi (substring (car elt) 1)))
  1974. (setq argval nil
  1975. argi orig-argi)))))
  1976. ;; Execute the option.
  1977. (cond ((setq tem (assoc argi command-switch-alist))
  1978. (if argval
  1979. (let ((command-line-args-left
  1980. (cons argval command-line-args-left)))
  1981. (funcall (cdr tem) argi))
  1982. (funcall (cdr tem) argi)))
  1983. ((equal argi "-no-splash")
  1984. (setq inhibit-startup-screen t))
  1985. ((member argi '("-f" ; what the manual claims
  1986. "-funcall"
  1987. "-e")) ; what the source used to say
  1988. (setq inhibit-startup-screen t)
  1989. (setq tem (intern (or argval (pop command-line-args-left))))
  1990. (if (commandp tem)
  1991. (command-execute tem)
  1992. (funcall tem)))
  1993. ((member argi '("-eval" "-execute"))
  1994. (setq inhibit-startup-screen t)
  1995. (eval (read (or argval (pop command-line-args-left)))))
  1996. ((member argi '("-L" "-directory"))
  1997. (setq tem (expand-file-name
  1998. (command-line-normalize-file-name
  1999. (or argval (pop command-line-args-left)))))
  2000. (cond (splice (setcdr splice (cons tem (cdr splice)))
  2001. (setq splice (cdr splice)))
  2002. (t (setq load-path (cons tem load-path)
  2003. splice load-path))))
  2004. ((member argi '("-l" "-load"))
  2005. (let* ((file (command-line-normalize-file-name
  2006. (or argval (pop command-line-args-left))))
  2007. ;; Take file from default dir if it exists there;
  2008. ;; otherwise let `load' search for it.
  2009. (file-ex (expand-file-name file)))
  2010. (when (file-exists-p file-ex)
  2011. (setq file file-ex))
  2012. (load file nil t)))
  2013. ;; This is used to handle -script. It's not clear
  2014. ;; we need to document it (it is totally internal).
  2015. ((member argi '("-scriptload"))
  2016. (let* ((file (command-line-normalize-file-name
  2017. (or argval (pop command-line-args-left))))
  2018. ;; Take file from default dir.
  2019. (file-ex (expand-file-name file)))
  2020. (load file-ex nil t t)))
  2021. ((equal argi "-insert")
  2022. (setq inhibit-startup-screen t)
  2023. (setq tem (or argval (pop command-line-args-left)))
  2024. (or (stringp tem)
  2025. (error "File name omitted from `-insert' option"))
  2026. (insert-file-contents (command-line-normalize-file-name tem)))
  2027. ((equal argi "-kill")
  2028. (kill-emacs t))
  2029. ;; This is for when they use --no-desktop with -q, or
  2030. ;; don't load Desktop in their .emacs. If desktop.el
  2031. ;; _is_ loaded, it will handle this switch, and we
  2032. ;; won't see it by the time we get here.
  2033. ((equal argi "-no-desktop")
  2034. (message "\"--no-desktop\" ignored because the Desktop package is not loaded"))
  2035. ((string-match "^\\+[0-9]+\\'" argi)
  2036. (setq line (string-to-number argi)))
  2037. ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
  2038. (setq line (string-to-number (match-string 1 argi))
  2039. column (string-to-number (match-string 2 argi))))
  2040. ((setq tem (assoc orig-argi command-line-x-option-alist))
  2041. ;; Ignore X-windows options and their args if not using X.
  2042. (setq command-line-args-left
  2043. (nthcdr (nth 1 tem) command-line-args-left)))
  2044. ((setq tem (assoc orig-argi command-line-ns-option-alist))
  2045. ;; Ignore NS-windows options and their args if not using NS.
  2046. (setq command-line-args-left
  2047. (nthcdr (nth 1 tem) command-line-args-left)))
  2048. ((member argi '("-find-file" "-file" "-visit"))
  2049. (setq inhibit-startup-screen t)
  2050. ;; An explicit option to specify visiting a file.
  2051. (setq tem (or argval (pop command-line-args-left)))
  2052. (unless (stringp tem)
  2053. (error "File name omitted from `%s' option" argi))
  2054. (setq file-count (1+ file-count))
  2055. (let ((file (expand-file-name
  2056. (command-line-normalize-file-name tem)
  2057. dir)))
  2058. (if (= file-count 1)
  2059. (setq first-file-buffer (find-file file))
  2060. (find-file-other-window file)))
  2061. (unless (zerop line)
  2062. (goto-char (point-min))
  2063. (forward-line (1- line)))
  2064. (setq line 0)
  2065. (unless (< column 1)
  2066. (move-to-column (1- column)))
  2067. (setq column 0))
  2068. ;; These command lines now have no effect.
  2069. ((string-match "\\`--?\\(no-\\)?\\(uni\\|multi\\)byte$" argi)
  2070. (display-warning 'initialization
  2071. (format "Ignoring obsolete arg %s" argi)))
  2072. ((equal argi "--")
  2073. (setq just-files t))
  2074. (t
  2075. ;; We have almost exhausted our options. See if the
  2076. ;; user has made any other command-line options available
  2077. (let ((hooks command-line-functions)
  2078. (did-hook nil))
  2079. (while (and hooks
  2080. (not (setq did-hook (funcall (car hooks)))))
  2081. (setq hooks (cdr hooks)))
  2082. (if (not did-hook)
  2083. ;; Presume that the argument is a file name.
  2084. (progn
  2085. (if (string-match "\\`-" argi)
  2086. (error "Unknown option `%s'" argi))
  2087. (unless initial-window-system
  2088. (setq inhibit-startup-screen t))
  2089. (setq file-count (1+ file-count))
  2090. (let ((file
  2091. (expand-file-name
  2092. (command-line-normalize-file-name orig-argi)
  2093. dir)))
  2094. (cond ((= file-count 1)
  2095. (setq first-file-buffer (find-file file)))
  2096. (inhibit-startup-screen
  2097. (find-file-other-window file))
  2098. (t (find-file file))))
  2099. (unless (zerop line)
  2100. (goto-char (point-min))
  2101. (forward-line (1- line)))
  2102. (setq line 0)
  2103. (unless (< column 1)
  2104. (move-to-column (1- column)))
  2105. (setq column 0))))))
  2106. ;; In unusual circumstances, the execution of Lisp code due
  2107. ;; to command-line options can cause the last visible frame
  2108. ;; to be deleted. In this case, kill emacs to avoid an
  2109. ;; abort later.
  2110. (unless (frame-live-p (selected-frame)) (kill-emacs nil))))))
  2111. (when (eq initial-buffer-choice t)
  2112. ;; When initial-buffer-choice equals t make sure that *scratch*
  2113. ;; exists.
  2114. (get-buffer-create "*scratch*"))
  2115. ;; If *scratch* exists and is empty, insert initial-scratch-message.
  2116. ;; Do this before switching to *scratch* below to handle bug#9605.
  2117. (and initial-scratch-message
  2118. (get-buffer "*scratch*")
  2119. (with-current-buffer "*scratch*"
  2120. (when (zerop (buffer-size))
  2121. (insert initial-scratch-message)
  2122. (set-buffer-modified-p nil))))
  2123. (when initial-buffer-choice
  2124. (cond ((eq initial-buffer-choice t)
  2125. (switch-to-buffer (get-buffer-create "*scratch*")))
  2126. ((stringp initial-buffer-choice)
  2127. (find-file initial-buffer-choice))))
  2128. (if (or inhibit-startup-screen
  2129. initial-buffer-choice
  2130. noninteractive
  2131. (daemonp)
  2132. inhibit-x-resources)
  2133. ;; Not displaying a startup screen. If 3 or more files
  2134. ;; visited, and not all visible, show user what they all are.
  2135. (and (> file-count 2)
  2136. (not noninteractive)
  2137. (not inhibit-startup-buffer-menu)
  2138. (or (get-buffer-window first-file-buffer)
  2139. (list-buffers)))
  2140. ;; Display a startup screen, after some preparations.
  2141. ;; If there are no switches to process, we might as well
  2142. ;; run this hook now, and there may be some need to do it
  2143. ;; before doing any output.
  2144. (run-hooks 'emacs-startup-hook)
  2145. (and term-setup-hook
  2146. (run-hooks 'term-setup-hook))
  2147. (setq inhibit-startup-hooks t)
  2148. ;; It's important to notice the user settings before we
  2149. ;; display the startup message; otherwise, the settings
  2150. ;; won't take effect until the user gives the first
  2151. ;; keystroke, and that's distracting.
  2152. (when (fboundp 'frame-notice-user-settings)
  2153. (frame-notice-user-settings))
  2154. ;; If there are no switches to process, we might as well
  2155. ;; run this hook now, and there may be some need to do it
  2156. ;; before doing any output.
  2157. (when window-setup-hook
  2158. (run-hooks 'window-setup-hook)
  2159. ;; Don't let the hook be run twice.
  2160. (setq window-setup-hook nil))
  2161. ;; ;; Do this now to avoid an annoying delay if the user
  2162. ;; ;; clicks the menu bar during the sit-for.
  2163. ;; (when (display-popup-menus-p)
  2164. ;; (precompute-menubar-bindings))
  2165. ;; (with-no-warnings
  2166. ;; (setq menubar-bindings-done t))
  2167. (display-startup-screen (> file-count 0)))))
  2168. (defun command-line-normalize-file-name (file)
  2169. "Collapse multiple slashes to one, to handle non-Emacs file names."
  2170. (save-match-data
  2171. ;; Use arg 1 so that we don't collapse // at the start of the file name.
  2172. ;; That is significant on some systems.
  2173. ;; However, /// at the beginning is supposed to mean just /, not //.
  2174. (if (string-match "^///+" file)
  2175. (setq file (replace-match "/" t t file)))
  2176. (and (memq system-type '(ms-dos windows-nt))
  2177. (string-match "^[A-Za-z]:\\(\\\\[\\\\/]\\)" file) ; C:\/ or C:\\
  2178. (setq file (replace-match "/" t t file 1)))
  2179. (while (string-match "//+" file 1)
  2180. (setq file (replace-match "/" t t file)))
  2181. file))
  2182. ;;; startup.el ends here