startup.el 103 KB

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