diff options
| -rw-r--r-- | src/lread.c | 87 |
1 files changed, 69 insertions, 18 deletions
diff --git a/src/lread.c b/src/lread.c index 3b100d80e4d..892c102c58f 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -98,7 +98,7 @@ int load_in_progress; | |||
| 98 | Lisp_Object Vsource_directory; | 98 | Lisp_Object Vsource_directory; |
| 99 | 99 | ||
| 100 | /* Search path and suffixes for files to be loaded. */ | 100 | /* Search path and suffixes for files to be loaded. */ |
| 101 | Lisp_Object Vload_path, Vload_suffixes, default_suffixes; | 101 | Lisp_Object Vload_path, Vload_suffixes, Vload_file_rep_suffixes; |
| 102 | 102 | ||
| 103 | /* File name of user's init file. */ | 103 | /* File name of user's init file. */ |
| 104 | Lisp_Object Vuser_init_file; | 104 | Lisp_Object Vuser_init_file; |
| @@ -653,28 +653,64 @@ load_error_handler (data) | |||
| 653 | return Qnil; | 653 | return Qnil; |
| 654 | } | 654 | } |
| 655 | 655 | ||
| 656 | DEFUN ("get-load-suffixes", Fget_load_suffixes, Sget_load_suffixes, 0, 0, 0, | ||
| 657 | doc: /* Return the suffixes that `load' should try if a suffix is \ | ||
| 658 | required. | ||
| 659 | This uses the variables `load-suffixes' and `load-file-rep-suffixes'. */) | ||
| 660 | () | ||
| 661 | { | ||
| 662 | Lisp_Object lst = Qnil, suffixes = Vload_suffixes, suffix, ext; | ||
| 663 | while (CONSP (suffixes)) | ||
| 664 | { | ||
| 665 | Lisp_Object exts = Vload_file_rep_suffixes; | ||
| 666 | suffix = XCAR (suffixes); | ||
| 667 | suffixes = XCDR (suffixes); | ||
| 668 | while (CONSP (exts)) | ||
| 669 | { | ||
| 670 | ext = XCAR (exts); | ||
| 671 | exts = XCDR (exts); | ||
| 672 | lst = Fcons (concat2 (suffix, ext), lst); | ||
| 673 | } | ||
| 674 | } | ||
| 675 | return Fnreverse (lst); | ||
| 676 | } | ||
| 677 | |||
| 656 | DEFUN ("load", Fload, Sload, 1, 5, 0, | 678 | DEFUN ("load", Fload, Sload, 1, 5, 0, |
| 657 | doc: /* Execute a file of Lisp code named FILE. | 679 | doc: /* Execute a file of Lisp code named FILE. |
| 658 | First try FILE with `.elc' appended, then try with `.el', | 680 | First try FILE with `.elc' appended, then try with `.el', |
| 659 | then try FILE unmodified (the exact suffixes are determined by | 681 | then try FILE unmodified (the exact suffixes in the exact order are |
| 660 | `load-suffixes'). Environment variable references in FILE | 682 | determined by `load-suffixes'). Environment variable references in |
| 661 | are replaced with their values by calling `substitute-in-file-name'. | 683 | FILE are replaced with their values by calling `substitute-in-file-name'. |
| 662 | This function searches the directories in `load-path'. | 684 | This function searches the directories in `load-path'. |
| 685 | |||
| 663 | If optional second arg NOERROR is non-nil, | 686 | If optional second arg NOERROR is non-nil, |
| 664 | report no error if FILE doesn't exist. | 687 | report no error if FILE doesn't exist. |
| 665 | Print messages at start and end of loading unless | 688 | Print messages at start and end of loading unless |
| 666 | optional third arg NOMESSAGE is non-nil. | 689 | optional third arg NOMESSAGE is non-nil. |
| 667 | If optional fourth arg NOSUFFIX is non-nil, don't try adding | 690 | If optional fourth arg NOSUFFIX is non-nil, don't try adding |
| 668 | suffixes `.elc' or `.el' to the specified name FILE. | 691 | suffixes `.elc' or `.el' to the specified name FILE. |
| 669 | If optional fifth arg MUST-SUFFIX is non-nil, insist on | 692 | If optional fifth arg MUST-SUFFIX is non-nil, insist on |
| 670 | the suffix `.elc' or `.el'; don't accept just FILE unless | 693 | the suffix `.elc' or `.el'; don't accept just FILE unless |
| 671 | it ends in one of those suffixes or includes a directory name. | 694 | it ends in one of those suffixes or includes a directory name. |
| 695 | |||
| 696 | If this function fails to find a file, it may look for different | ||
| 697 | representations of that file before trying another file. | ||
| 698 | It does so by adding the non-empty suffixes in `load-file-rep-suffixes' | ||
| 699 | to the file name. Emacs uses this feature mainly to find compressed | ||
| 700 | versions of files when Auto Compression mode is enabled. | ||
| 701 | |||
| 702 | The exact suffixes that this function tries out, in the exact order, | ||
| 703 | are given by the value of the variable `load-file-rep-suffixes' if | ||
| 704 | NOSUFFIX is non-nil and by the return value of the function | ||
| 705 | `get-load-suffixes' if MUST-SUFFIX is non-nil. If both NOSUFFIX and | ||
| 706 | MUST-SUFFIX are nil, this function first tries out the latter suffixes | ||
| 707 | and then the former. | ||
| 672 | 708 | ||
| 673 | Loading a file records its definitions, and its `provide' and | 709 | Loading a file records its definitions, and its `provide' and |
| 674 | `require' calls, in an element of `load-history' whose | 710 | `require' calls, in an element of `load-history' whose |
| 675 | car is the file name loaded. See `load-history'. | 711 | car is the file name loaded. See `load-history'. |
| 676 | 712 | ||
| 677 | Return t if file exists. */) | 713 | Return t if the file exists and loads successfully. */) |
| 678 | (file, noerror, nomessage, nosuffix, must_suffix) | 714 | (file, noerror, nomessage, nosuffix, must_suffix) |
| 679 | Lisp_Object file, noerror, nomessage, nosuffix, must_suffix; | 715 | Lisp_Object file, noerror, nomessage, nosuffix, must_suffix; |
| 680 | { | 716 | { |
| @@ -749,9 +785,9 @@ Return t if file exists. */) | |||
| 749 | 785 | ||
| 750 | fd = openp (Vload_path, file, | 786 | fd = openp (Vload_path, file, |
| 751 | (!NILP (nosuffix) ? Qnil | 787 | (!NILP (nosuffix) ? Qnil |
| 752 | : !NILP (must_suffix) ? Vload_suffixes | 788 | : !NILP (must_suffix) ? Fget_load_suffixes () |
| 753 | : Fappend (2, (tmp[0] = Vload_suffixes, | 789 | : Fappend (2, (tmp[0] = Fget_load_suffixes (), |
| 754 | tmp[1] = default_suffixes, | 790 | tmp[1] = Vload_file_rep_suffixes, |
| 755 | tmp))), | 791 | tmp))), |
| 756 | &found, Qnil); | 792 | &found, Qnil); |
| 757 | UNGCPRO; | 793 | UNGCPRO; |
| @@ -1109,7 +1145,7 @@ openp (path, str, suffixes, storeptr, predicate) | |||
| 1109 | fn = (char *) alloca (fn_size = 100 + want_size); | 1145 | fn = (char *) alloca (fn_size = 100 + want_size); |
| 1110 | 1146 | ||
| 1111 | /* Loop over suffixes. */ | 1147 | /* Loop over suffixes. */ |
| 1112 | for (tail = NILP (suffixes) ? default_suffixes : suffixes; | 1148 | for (tail = NILP (suffixes) ? Fcons (build_string (""), Qnil) : suffixes; |
| 1113 | CONSP (tail); tail = XCDR (tail)) | 1149 | CONSP (tail); tail = XCDR (tail)) |
| 1114 | { | 1150 | { |
| 1115 | int lsuffix = SBYTES (XCAR (tail)); | 1151 | int lsuffix = SBYTES (XCAR (tail)); |
| @@ -3840,6 +3876,7 @@ syms_of_lread () | |||
| 3840 | defsubr (&Sintern); | 3876 | defsubr (&Sintern); |
| 3841 | defsubr (&Sintern_soft); | 3877 | defsubr (&Sintern_soft); |
| 3842 | defsubr (&Sunintern); | 3878 | defsubr (&Sunintern); |
| 3879 | defsubr (&Sget_load_suffixes); | ||
| 3843 | defsubr (&Sload); | 3880 | defsubr (&Sload); |
| 3844 | defsubr (&Seval_buffer); | 3881 | defsubr (&Seval_buffer); |
| 3845 | defsubr (&Seval_region); | 3882 | defsubr (&Seval_region); |
| @@ -3901,13 +3938,27 @@ Initialized based on EMACSLOADPATH environment variable, if any, | |||
| 3901 | otherwise to default specified by file `epaths.h' when Emacs was built. */); | 3938 | otherwise to default specified by file `epaths.h' when Emacs was built. */); |
| 3902 | 3939 | ||
| 3903 | DEFVAR_LISP ("load-suffixes", &Vload_suffixes, | 3940 | DEFVAR_LISP ("load-suffixes", &Vload_suffixes, |
| 3904 | doc: /* *List of suffixes to try for files to load. | 3941 | doc: /* List of suffixes for (compiled or source) Emacs Lisp files. |
| 3905 | This list should not include the empty string. */); | 3942 | This list should not include the empty string. |
| 3943 | `load' and related functions try to append these suffixes, in order, | ||
| 3944 | to the specified file name if a Lisp suffix is allowed or required. */); | ||
| 3906 | Vload_suffixes = Fcons (build_string (".elc"), | 3945 | Vload_suffixes = Fcons (build_string (".elc"), |
| 3907 | Fcons (build_string (".el"), Qnil)); | 3946 | Fcons (build_string (".el"), Qnil)); |
| 3947 | DEFVAR_LISP ("load-file-rep-suffixes", &Vload_file_rep_suffixes, | ||
| 3948 | doc: /* List of suffixes that indicate representations of \ | ||
| 3949 | the same file. | ||
| 3950 | This list should normally start with the empty string. | ||
| 3951 | |||
| 3952 | Enabling Auto Compression mode appends the suffixes in | ||
| 3953 | `jka-compr-load-suffixes' to this list and disabling Auto Compression | ||
| 3954 | mode removes them again. `load' and related functions use this list to | ||
| 3955 | determine whether they should look for compressed versions of a file | ||
| 3956 | and, if so, which suffixes they should try to append to the file name | ||
| 3957 | in order to do so. However, if you want to customize which suffixes | ||
| 3958 | the loading functions recognize as compression suffixes, you should | ||
| 3959 | customize `jka-compr-load-suffixes' rather than the present variable. */); | ||
| 3908 | /* We don't use empty_string because it's not initialized yet. */ | 3960 | /* We don't use empty_string because it's not initialized yet. */ |
| 3909 | default_suffixes = Fcons (build_string (""), Qnil); | 3961 | Vload_file_rep_suffixes = Fcons (build_string (""), Qnil); |
| 3910 | staticpro (&default_suffixes); | ||
| 3911 | 3962 | ||
| 3912 | DEFVAR_BOOL ("load-in-progress", &load_in_progress, | 3963 | DEFVAR_BOOL ("load-in-progress", &load_in_progress, |
| 3913 | doc: /* Non-nil iff inside of `load'. */); | 3964 | doc: /* Non-nil iff inside of `load'. */); |