Mercurial > emacs
comparison src/lread.c @ 70880:b34d05d3a567
lread.c (Vload_history): Enhance doc-string to say that the file is the
absolute truename of the loaded file.
lread.c (Vafter_load_alist): doc-string: state that an element now has a
regexp to match file names, not a file name as such.
lread.c (readevalloop): Call file-truename on the name for load-history,
except at preloading time.
lread.c (Fload): At preloading time, preserve the extension of the
filename which goes into load-history. New variable hist_file_name.
lread.c (Fload): Do eval-after-load stuff by calling the lisp function
do-after-load-evaluation.
author | Alan Mackenzie <acm@muc.de> |
---|---|
date | Wed, 24 May 2006 13:24:21 +0000 |
parents | 136d07d2859f |
children | 767eeffaf27a a8190f7e546e |
comparison
equal
deleted
inserted
replaced
70879:238e43ed886e | 70880:b34d05d3a567 |
---|---|
85 Lisp_Object Qvariable_documentation, Vvalues, Vstandard_input, Vafter_load_alist; | 85 Lisp_Object Qvariable_documentation, Vvalues, Vstandard_input, Vafter_load_alist; |
86 Lisp_Object Qascii_character, Qload, Qload_file_name; | 86 Lisp_Object Qascii_character, Qload, Qload_file_name; |
87 Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction; | 87 Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction; |
88 Lisp_Object Qinhibit_file_name_operation; | 88 Lisp_Object Qinhibit_file_name_operation; |
89 Lisp_Object Qeval_buffer_list, Veval_buffer_list; | 89 Lisp_Object Qeval_buffer_list, Veval_buffer_list; |
90 Lisp_Object Qfile_truename, Qdo_after_load_evaluation; /* ACM 2006/5/16 */ | |
90 | 91 |
91 extern Lisp_Object Qevent_symbol_element_mask; | 92 extern Lisp_Object Qevent_symbol_element_mask; |
92 extern Lisp_Object Qfile_exists_p; | 93 extern Lisp_Object Qfile_exists_p; |
93 | 94 |
94 /* non-zero iff inside `load' */ | 95 /* non-zero iff inside `load' */ |
716 { | 717 { |
717 register FILE *stream; | 718 register FILE *stream; |
718 register int fd = -1; | 719 register int fd = -1; |
719 int count = SPECPDL_INDEX (); | 720 int count = SPECPDL_INDEX (); |
720 Lisp_Object temp; | 721 Lisp_Object temp; |
721 struct gcpro gcpro1, gcpro2; | 722 struct gcpro gcpro1, gcpro2, gcpro3; |
722 Lisp_Object found, efound; | 723 Lisp_Object found, efound, hist_file_name; |
723 /* 1 means we printed the ".el is newer" message. */ | 724 /* 1 means we printed the ".el is newer" message. */ |
724 int newer = 0; | 725 int newer = 0; |
725 /* 1 means we are loading a compiled file. */ | 726 /* 1 means we are loading a compiled file. */ |
726 int compiled = 0; | 727 int compiled = 0; |
727 Lisp_Object handler; | 728 Lisp_Object handler; |
728 int safe_p = 1; | 729 int safe_p = 1; |
729 char *fmode = "r"; | 730 char *fmode = "r"; |
731 Lisp_Object tmp[2]; | |
730 #ifdef DOS_NT | 732 #ifdef DOS_NT |
731 fmode = "rt"; | 733 fmode = "rt"; |
732 #endif /* DOS_NT */ | 734 #endif /* DOS_NT */ |
733 | 735 |
734 CHECK_STRING (file); | 736 CHECK_STRING (file); |
741 | 743 |
742 /* Do this after the handler to avoid | 744 /* Do this after the handler to avoid |
743 the need to gcpro noerror, nomessage and nosuffix. | 745 the need to gcpro noerror, nomessage and nosuffix. |
744 (Below here, we care only whether they are nil or not.) | 746 (Below here, we care only whether they are nil or not.) |
745 The presence of this call is the result of a historical accident: | 747 The presence of this call is the result of a historical accident: |
746 it used to be in every file-operations and when it got removed | 748 it used to be in every file-operation and when it got removed |
747 everywhere, it accidentally stayed here. Since then, enough people | 749 everywhere, it accidentally stayed here. Since then, enough people |
748 supposedly have things like (load "$PROJECT/foo.el") in their .emacs | 750 supposedly have things like (load "$PROJECT/foo.el") in their .emacs |
749 that it seemed risky to remove. */ | 751 that it seemed risky to remove. */ |
750 if (! NILP (noerror)) | 752 if (! NILP (noerror)) |
751 { | 753 { |
761 /* Avoid weird lossage with null string as arg, | 763 /* Avoid weird lossage with null string as arg, |
762 since it would try to load a directory as a Lisp file */ | 764 since it would try to load a directory as a Lisp file */ |
763 if (SCHARS (file) > 0) | 765 if (SCHARS (file) > 0) |
764 { | 766 { |
765 int size = SBYTES (file); | 767 int size = SBYTES (file); |
766 Lisp_Object tmp[2]; | |
767 | 768 |
768 found = Qnil; | 769 found = Qnil; |
769 GCPRO2 (file, found); | 770 GCPRO2 (file, found); |
770 | 771 |
771 if (! NILP (must_suffix)) | 772 if (! NILP (must_suffix)) |
845 } | 846 } |
846 record_unwind_protect (record_load_unwind, Vloads_in_progress); | 847 record_unwind_protect (record_load_unwind, Vloads_in_progress); |
847 Vloads_in_progress = Fcons (found, Vloads_in_progress); | 848 Vloads_in_progress = Fcons (found, Vloads_in_progress); |
848 } | 849 } |
849 | 850 |
851 /* Get the name for load-history. */ | |
852 hist_file_name = (! NILP (Vpurify_flag) | |
853 ? Fconcat (2, (tmp[0] = Ffile_name_directory (file), | |
854 tmp[1] = Ffile_name_nondirectory (found), | |
855 tmp)) | |
856 : found) ; | |
857 | |
850 if (!bcmp (SDATA (found) + SBYTES (found) - 4, | 858 if (!bcmp (SDATA (found) + SBYTES (found) - 4, |
851 ".elc", 4)) | 859 ".elc", 4)) |
852 /* Load .elc files directly, but not when they are | 860 /* Load .elc files directly, but not when they are |
853 remote and have no handler! */ | 861 remote and have no handler! */ |
854 { | 862 { |
855 if (fd != -2) | 863 if (fd != -2) |
856 { | 864 { |
857 struct stat s1, s2; | 865 struct stat s1, s2; |
858 int result; | 866 int result; |
859 | 867 |
860 GCPRO2 (file, found); | 868 GCPRO3 (file, found, hist_file_name); |
861 | 869 |
862 if (!safe_to_load_p (fd)) | 870 if (!safe_to_load_p (fd)) |
863 { | 871 { |
864 safe_p = 0; | 872 safe_p = 0; |
865 if (!load_dangerous_libraries) | 873 if (!load_dangerous_libraries) |
909 { | 917 { |
910 Lisp_Object val; | 918 Lisp_Object val; |
911 | 919 |
912 if (fd >= 0) | 920 if (fd >= 0) |
913 emacs_close (fd); | 921 emacs_close (fd); |
914 val = call4 (Vload_source_file_function, found, file, | 922 val = call4 (Vload_source_file_function, found, hist_file_name, |
915 NILP (noerror) ? Qnil : Qt, | 923 NILP (noerror) ? Qnil : Qt, |
916 NILP (nomessage) ? Qnil : Qt); | 924 NILP (nomessage) ? Qnil : Qt); |
917 return unbind_to (count, val); | 925 return unbind_to (count, val); |
918 } | 926 } |
919 } | 927 } |
920 | 928 |
921 GCPRO2 (file, found); | 929 GCPRO3 (file, found, hist_file_name); |
922 | 930 |
923 #ifdef WINDOWSNT | 931 #ifdef WINDOWSNT |
924 emacs_close (fd); | 932 emacs_close (fd); |
925 efound = ENCODE_FILE (found); | 933 efound = ENCODE_FILE (found); |
926 stream = fopen ((char *) SDATA (efound), fmode); | 934 stream = fopen ((char *) SDATA (efound), fmode); |
955 specbind (Qload_file_name, found); | 963 specbind (Qload_file_name, found); |
956 specbind (Qinhibit_file_name_operation, Qnil); | 964 specbind (Qinhibit_file_name_operation, Qnil); |
957 load_descriptor_list | 965 load_descriptor_list |
958 = Fcons (make_number (fileno (stream)), load_descriptor_list); | 966 = Fcons (make_number (fileno (stream)), load_descriptor_list); |
959 load_in_progress++; | 967 load_in_progress++; |
960 readevalloop (Qget_file_char, stream, (! NILP (Vpurify_flag) ? file : found), | 968 readevalloop (Qget_file_char, stream, hist_file_name, |
961 Feval, 0, Qnil, Qnil, Qnil, Qnil); | 969 Feval, 0, Qnil, Qnil, Qnil, Qnil); |
962 unbind_to (count, Qnil); | 970 unbind_to (count, Qnil); |
963 | 971 |
964 /* Run any load-hooks for this file. */ | 972 /* Run any eval-after-load forms for this file */ |
965 temp = Fassoc (file, Vafter_load_alist); | 973 if (NILP (Vpurify_flag) |
966 if (!NILP (temp)) | 974 && (!NILP (Ffboundp (Qdo_after_load_evaluation)))) |
967 Fprogn (Fcdr (temp)); | 975 call1 (Qdo_after_load_evaluation, hist_file_name) ; |
976 | |
968 UNGCPRO; | 977 UNGCPRO; |
969 | 978 |
970 if (saved_doc_string) | 979 if (saved_doc_string) |
971 free (saved_doc_string); | 980 free (saved_doc_string); |
972 saved_doc_string = 0; | 981 saved_doc_string = 0; |
1388 load_convert_to_unibyte = !NILP (unibyte); | 1397 load_convert_to_unibyte = !NILP (unibyte); |
1389 | 1398 |
1390 readchar_backlog = -1; | 1399 readchar_backlog = -1; |
1391 | 1400 |
1392 GCPRO4 (sourcename, readfun, start, end); | 1401 GCPRO4 (sourcename, readfun, start, end); |
1402 | |
1403 /* Try to ensure sourcename is a truename, except whilst preloading. */ | |
1404 if (NILP (Vpurify_flag) | |
1405 && !NILP (sourcename) && Ffile_name_absolute_p (sourcename) | |
1406 && (!NILP (Ffboundp (Qfile_truename)))) | |
1407 sourcename = call1 (Qfile_truename, sourcename) ; | |
1393 | 1408 |
1394 LOADHIST_ATTACH (sourcename); | 1409 LOADHIST_ATTACH (sourcename); |
1395 | 1410 |
1396 continue_reading_p = 1; | 1411 continue_reading_p = 1; |
1397 while (continue_reading_p) | 1412 while (continue_reading_p) |
3969 DEFVAR_BOOL ("load-in-progress", &load_in_progress, | 3984 DEFVAR_BOOL ("load-in-progress", &load_in_progress, |
3970 doc: /* Non-nil iff inside of `load'. */); | 3985 doc: /* Non-nil iff inside of `load'. */); |
3971 | 3986 |
3972 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist, | 3987 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist, |
3973 doc: /* An alist of expressions to be evalled when particular files are loaded. | 3988 doc: /* An alist of expressions to be evalled when particular files are loaded. |
3974 Each element looks like (FILENAME FORMS...). | 3989 Each element looks like (REGEXP-OR-FEATURE FORMS...). |
3975 When `load' is run and the file-name argument is FILENAME, | 3990 |
3976 the FORMS in the corresponding element are executed at the end of loading. | 3991 REGEXP-OR-FEATURE is either a regular expression to match file names, or |
3977 | 3992 a symbol \(a feature name). |
3978 FILENAME must match exactly! Normally FILENAME is the name of a library, | 3993 |
3979 with no directory specified, since that is how `load' is normally called. | 3994 When `load' is run and the file-name argument matches an element's |
3980 An error in FORMS does not undo the load, | 3995 REGEXP-OR-FEATURE, or when `provide' is run and provides the symbol |
3981 but does prevent execution of the rest of the FORMS. | 3996 REGEXP-OR-FEATURE, the FORMS in the element are executed. |
3982 FILENAME can also be a symbol (a feature) and FORMS are then executed | 3997 |
3983 when the corresponding call to `provide' is made. */); | 3998 An error in FORMS does not undo the load, but does prevent execution of |
3999 the rest of the FORMS. */); | |
3984 Vafter_load_alist = Qnil; | 4000 Vafter_load_alist = Qnil; |
3985 | 4001 |
3986 DEFVAR_LISP ("load-history", &Vload_history, | 4002 DEFVAR_LISP ("load-history", &Vload_history, |
3987 doc: /* Alist mapping file names to symbols and features. | 4003 doc: /* Alist mapping file names to symbols and features. |
3988 Each alist element is a list that starts with a file name, | 4004 Each alist element is a list that starts with a file name, |
3989 except for one element (optional) that starts with nil and describes | 4005 except for one element (optional) that starts with nil and describes |
3990 definitions evaluated from buffers not visiting files. | 4006 definitions evaluated from buffers not visiting files. |
4007 | |
4008 The file name is absolute and is the true file name (i.e. it doesn't | |
4009 contain symbolic links) of the loaded file. | |
4010 | |
3991 The remaining elements of each list are symbols defined as variables | 4011 The remaining elements of each list are symbols defined as variables |
3992 and cons cells of the form `(provide . FEATURE)', `(require . FEATURE)', | 4012 and cons cells of the form `(provide . FEATURE)', `(require . FEATURE)', |
3993 `(defun . FUNCTION)', `(autoload . SYMBOL)', and `(t . SYMBOL)'. | 4013 `(defun . FUNCTION)', `(autoload . SYMBOL)', and `(t . SYMBOL)'. |
3994 An element `(t . SYMBOL)' precedes an entry `(defun . FUNCTION)', | 4014 An element `(t . SYMBOL)' precedes an entry `(defun . FUNCTION)', |
3995 and means that SYMBOL was an autoload before this file redefined it | 4015 and means that SYMBOL was an autoload before this file redefined it |
4116 staticpro (&Qload_file_name); | 4136 staticpro (&Qload_file_name); |
4117 | 4137 |
4118 Qeval_buffer_list = intern ("eval-buffer-list"); | 4138 Qeval_buffer_list = intern ("eval-buffer-list"); |
4119 staticpro (&Qeval_buffer_list); | 4139 staticpro (&Qeval_buffer_list); |
4120 | 4140 |
4141 Qfile_truename = intern ("file-truename"); | |
4142 staticpro (&Qfile_truename) ; | |
4143 | |
4144 Qdo_after_load_evaluation = intern ("do-after-load-evaluation"); | |
4145 staticpro (&Qdo_after_load_evaluation) ; | |
4146 | |
4121 staticpro (&dump_path); | 4147 staticpro (&dump_path); |
4122 | 4148 |
4123 staticpro (&read_objects); | 4149 staticpro (&read_objects); |
4124 read_objects = Qnil; | 4150 read_objects = Qnil; |
4125 staticpro (&seen_list); | 4151 staticpro (&seen_list); |