comparison src/emacs.c @ 4484:c589c71324dd

(Vinvocation_directory): New var. (init_cmdargs): Set up its value. (Finvocation_directory): New function. (main): Call init_buffer, init_callproc and init_cmdargs before init_lread. (syms_of_emacs): Install the function, and protect the variable.
author Richard M. Stallman <rms@gnu.org>
date Sun, 08 Aug 1993 06:23:21 +0000
parents fd9865b5a41e
children e61769cebbd4
comparison
equal deleted inserted replaced
4483:6894dd27c9ec 4484:c589c71324dd
56 Lisp_Object Vcommand_line_args; 56 Lisp_Object Vcommand_line_args;
57 57
58 /* The name under which Emacs was invoked, with any leading directory 58 /* The name under which Emacs was invoked, with any leading directory
59 names discarded. */ 59 names discarded. */
60 Lisp_Object Vinvocation_name; 60 Lisp_Object Vinvocation_name;
61
62 /* The directory name from which Emacs was invoked. */
63 Lisp_Object Vinvocation_directory;
61 64
62 /* Hook run by `kill-emacs' before it does really anything. */ 65 /* Hook run by `kill-emacs' before it does really anything. */
63 Lisp_Object Vkill_emacs_hook; 66 Lisp_Object Vkill_emacs_hook;
64 67
65 /* Set nonzero after Emacs has started up the first time. 68 /* Set nonzero after Emacs has started up the first time.
157 int skip_args; 160 int skip_args;
158 { 161 {
159 register int i; 162 register int i;
160 163
161 Vinvocation_name = Ffile_name_nondirectory (build_string (argv[0])); 164 Vinvocation_name = Ffile_name_nondirectory (build_string (argv[0]));
165 Vinvocation_directory = Ffile_name_directory (build_string (argv[0]));
166 /* If we got no directory in argv[0], search PATH to find where
167 Emacs actually came from. */
168 if (NILP (Vinvocation_directory))
169 {
170 Lisp_Object found;
171 int yes = openp (Vexec_path, Vinvocation_name,
172 "", &found, 1);
173 if (yes)
174 Vinvocation_directory = Ffile_name_directory (found);
175 }
162 176
163 Vcommand_line_args = Qnil; 177 Vcommand_line_args = Qnil;
164 178
165 for (i = argc - 1; i >= 0; i--) 179 for (i = argc - 1; i >= 0; i--)
166 { 180 {
174 "Return the program name that was used to run Emacs.\n\ 188 "Return the program name that was used to run Emacs.\n\
175 Any directory names are omitted.") 189 Any directory names are omitted.")
176 () 190 ()
177 { 191 {
178 return Fcopy_sequence (Vinvocation_name); 192 return Fcopy_sequence (Vinvocation_name);
193 }
194
195 DEFUN ("invocation-directory", Finvocation_directory, Sinvocation_directory,
196 0, 0, 0,
197 "Return the directory name in which the Emacs executable was located")
198 ()
199 {
200 return Fcopy_sequence (Vinvocation_directory);
179 } 201 }
180 202
181 203
182 #ifdef VMS 204 #ifdef VMS
183 #ifdef LINK_CRTL_SHARE 205 #ifdef LINK_CRTL_SHARE
467 /* egetenv is a pretty low-level facility, which may get called in 489 /* egetenv is a pretty low-level facility, which may get called in
468 many circumstances; it seems flimsy to put off initializing it 490 many circumstances; it seems flimsy to put off initializing it
469 until calling init_callproc. */ 491 until calling init_callproc. */
470 set_process_environment (); 492 set_process_environment ();
471 493
494 init_buffer (); /* Init default directory of main buffer */
495
496 init_callproc (); /* Must precede init_cmdargs and init_sys_modes. */
497 init_cmdargs (argc, argv, skip_args); /* Must precede init_lread. */
472 init_lread (); 498 init_lread ();
473 499
474 init_cmdargs (argc, argv, skip_args); /* Create list Vcommand_line_args */
475 init_buffer (); /* Init default directory of main buffer */
476 if (!noninteractive) 500 if (!noninteractive)
477 { 501 {
478 #ifdef VMS 502 #ifdef VMS
479 init_vms_input ();/* init_display calls get_frame_size, that needs this */ 503 init_vms_input ();/* init_display calls get_frame_size, that needs this */
480 #endif /* VMS */ 504 #endif /* VMS */
481 init_display (); /* Determine terminal type. init_sys_modes uses results */ 505 init_display (); /* Determine terminal type. init_sys_modes uses results */
482 } 506 }
483 init_keyboard (); /* This too must precede init_sys_modes */ 507 init_keyboard (); /* This too must precede init_sys_modes */
484 init_callproc (); /* And this too. */
485 #ifdef VMS 508 #ifdef VMS
486 init_vmsproc (); /* And this too. */ 509 init_vmsproc (); /* And this too. */
487 #endif /* VMS */ 510 #endif /* VMS */
488 init_sys_modes (); /* Init system terminal modes (RAW or CBREAK, etc.) */ 511 init_sys_modes (); /* Init system terminal modes (RAW or CBREAK, etc.) */
489 init_xdisp (); 512 init_xdisp ();
861 #endif 884 #endif
862 885
863 defsubr (&Skill_emacs); 886 defsubr (&Skill_emacs);
864 887
865 defsubr (&Sinvocation_name); 888 defsubr (&Sinvocation_name);
889 defsubr (&Sinvocation_directory);
866 890
867 DEFVAR_LISP ("command-line-args", &Vcommand_line_args, 891 DEFVAR_LISP ("command-line-args", &Vcommand_line_args,
868 "Args passed by shell to Emacs, as a list of strings."); 892 "Args passed by shell to Emacs, as a list of strings.");
869 893
870 DEFVAR_LISP ("system-type", &Vsystem_type, 894 DEFVAR_LISP ("system-type", &Vsystem_type,
888 it to change priority. (Emacs sets its uid back to the real uid.)"); 912 it to change priority. (Emacs sets its uid back to the real uid.)");
889 emacs_priority = 0; 913 emacs_priority = 0;
890 914
891 staticpro (&Vinvocation_name); 915 staticpro (&Vinvocation_name);
892 Vinvocation_name = Qnil; 916 Vinvocation_name = Qnil;
893 } 917 staticpro (&Vinvocation_directory);
918 Vinvocation_directory = Qnil;
919 }