Mercurial > emacs
annotate src/doc.c @ 9123:c225137ddefb
(get_keyelt, store_in_keymap, Fcopy_keymap, Fdefine_key, Flookup_key,
current_minor_maps, Fkey_binding, Fminor_mode_key_binding, Fglobal_set_key,
Flocal_set_key, Faccessible_keymaps, ascii_sequence_p, Fwhere_is_internal,
describe_buffer_bindings, describe_map_tree, describe_command, describe_map,
describe_vector): Use type test macros.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Tue, 27 Sep 1994 02:26:34 +0000 |
parents | e3c272c7f4d2 |
children | 48820d57a24c |
rev | line source |
---|---|
297 | 1 /* Record indices of function doc strings stored in a file. |
7307 | 2 Copyright (C) 1985, 1986, 1993, 1994 Free Software Foundation, Inc. |
297 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 1, or (at your option) | |
9 any later version. | |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
20 | |
4696
1fc792473491
Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents:
3999
diff
changeset
|
21 #include <config.h> |
297 | 22 |
23 #include <sys/types.h> | |
24 #include <sys/file.h> /* Must be after sys/types.h for USG and BSD4_1*/ | |
25 | |
26 #ifdef USG5 | |
27 #include <fcntl.h> | |
28 #endif | |
29 | |
6862
653504b6b5dd
[HAVE_UNISTD_H]: Include unistd.h.
Richard M. Stallman <rms@gnu.org>
parents:
6030
diff
changeset
|
30 #ifdef HAVE_UNISTD_H |
653504b6b5dd
[HAVE_UNISTD_H]: Include unistd.h.
Richard M. Stallman <rms@gnu.org>
parents:
6030
diff
changeset
|
31 #include <unistd.h> |
653504b6b5dd
[HAVE_UNISTD_H]: Include unistd.h.
Richard M. Stallman <rms@gnu.org>
parents:
6030
diff
changeset
|
32 #endif |
653504b6b5dd
[HAVE_UNISTD_H]: Include unistd.h.
Richard M. Stallman <rms@gnu.org>
parents:
6030
diff
changeset
|
33 |
297 | 34 #ifndef O_RDONLY |
35 #define O_RDONLY 0 | |
36 #endif | |
37 | |
38 #include "lisp.h" | |
39 #include "buffer.h" | |
1511
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
40 #include "keyboard.h" |
297 | 41 |
961
8d2cbfd93066
* doc.c (Vdata_directory): Removed; this is declared in callproc.c.
Jim Blandy <jimb@redhat.com>
parents:
943
diff
changeset
|
42 Lisp_Object Vdoc_file_name; |
297 | 43 |
5784
9c3be8e0d2ef
(Fsubstitute_command_keys): Pass keymap as that arg
Richard M. Stallman <rms@gnu.org>
parents:
5550
diff
changeset
|
44 extern Lisp_Object Voverriding_local_map; |
9c3be8e0d2ef
(Fsubstitute_command_keys): Pass keymap as that arg
Richard M. Stallman <rms@gnu.org>
parents:
5550
diff
changeset
|
45 |
9087
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
46 /* For VMS versions with limited file name syntax, |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
47 convert the name to something VMS will allow. */ |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
48 static void |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
49 munge_doc_file_name (name) |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
50 char *name; |
297 | 51 { |
52 #ifdef VMS | |
53 #ifndef VMS4_4 | |
54 /* For VMS versions with limited file name syntax, | |
55 convert the name to something VMS will allow. */ | |
56 p = name; | |
57 while (*p) | |
58 { | |
59 if (*p == '-') | |
60 *p = '_'; | |
61 p++; | |
62 } | |
63 #endif /* not VMS4_4 */ | |
64 #ifdef VMS4_4 | |
65 strcpy (name, sys_translate_unix (name)); | |
66 #endif /* VMS4_4 */ | |
67 #endif /* VMS */ | |
9087
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
68 } |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
69 |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
70 Lisp_Object |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
71 get_doc_string (filepos) |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
72 long filepos; |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
73 { |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
74 char buf[512 * 32 + 1]; |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
75 register int fd; |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
76 register char *name; |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
77 register char *p, *p1; |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
78 register int count; |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
79 int minsize; |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
80 extern char *index (); |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
81 |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
82 if (XTYPE (Vdoc_directory) != Lisp_String |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
83 || XTYPE (Vdoc_file_name) != Lisp_String) |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
84 return Qnil; |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
85 |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
86 minsize = XSTRING (Vdoc_directory)->size; |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
87 /* sizeof ("../etc/") == 8 */ |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
88 if (minsize < 8) |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
89 minsize = 8; |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
90 name = (char *) alloca (minsize + XSTRING (Vdoc_file_name)->size + 8); |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
91 strcpy (name, XSTRING (Vdoc_directory)->data); |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
92 strcat (name, XSTRING (Vdoc_file_name)->data); |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
93 munge_doc_file_name (name); |
297 | 94 |
95 fd = open (name, O_RDONLY, 0); | |
96 if (fd < 0) | |
9087
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
97 { |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
98 #ifndef CANNOT_DUMP |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
99 if (!NILP (Vpurify_flag)) |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
100 { |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
101 /* Preparing to dump; DOC file is probably not installed. |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
102 So check in ../etc. */ |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
103 strcpy (name, "../etc/"); |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
104 strcat (name, XSTRING (Vdoc_file_name)->data); |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
105 munge_doc_file_name (name); |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
106 |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
107 fd = open (name, O_RDONLY, 0); |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
108 } |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
109 #endif |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
110 |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
111 if (fd < 0) |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
112 error ("Cannot open doc string file \"%s\"", name); |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
113 } |
e3c272c7f4d2
(get_doc_string): Look in ../etc while dumping.
Richard M. Stallman <rms@gnu.org>
parents:
8823
diff
changeset
|
114 |
297 | 115 if (0 > lseek (fd, filepos, 0)) |
116 { | |
117 close (fd); | |
118 error ("Position %ld out of range in doc string file \"%s\"", | |
119 filepos, name); | |
120 } | |
121 p = buf; | |
122 while (p != buf + sizeof buf - 1) | |
123 { | |
124 count = read (fd, p, 512); | |
125 p[count] = 0; | |
126 if (!count) | |
127 break; | |
128 p1 = index (p, '\037'); | |
129 if (p1) | |
130 { | |
131 *p1 = 0; | |
132 p = p1; | |
133 break; | |
134 } | |
135 p += count; | |
136 } | |
137 close (fd); | |
138 return make_string (buf, p - buf); | |
139 } | |
140 | |
570 | 141 DEFUN ("documentation", Fdocumentation, Sdocumentation, 1, 2, 0, |
604 | 142 "Return the documentation string of FUNCTION.\n\ |
143 Unless a non-nil second argument is given, the\n\ | |
570 | 144 string is passed through `substitute-command-keys'.") |
647 | 145 (function, raw) |
146 Lisp_Object function, raw; | |
297 | 147 { |
148 Lisp_Object fun; | |
149 Lisp_Object funcar; | |
570 | 150 Lisp_Object tem, doc; |
297 | 151 |
647 | 152 fun = Findirect_function (function); |
297 | 153 |
154 switch (XTYPE (fun)) | |
155 { | |
156 case Lisp_Subr: | |
157 if (XSUBR (fun)->doc == 0) return Qnil; | |
8823
fdb7ba55f05c
(Fdocumentation): Use EMACS_INT.
Richard M. Stallman <rms@gnu.org>
parents:
8552
diff
changeset
|
158 if ((EMACS_INT) XSUBR (fun)->doc >= 0) |
570 | 159 doc = build_string (XSUBR (fun)->doc); |
297 | 160 else |
8823
fdb7ba55f05c
(Fdocumentation): Use EMACS_INT.
Richard M. Stallman <rms@gnu.org>
parents:
8552
diff
changeset
|
161 doc = get_doc_string (- (EMACS_INT) XSUBR (fun)->doc); |
570 | 162 break; |
297 | 163 |
164 case Lisp_Compiled: | |
165 if (XVECTOR (fun)->size <= COMPILED_DOC_STRING) | |
166 return Qnil; | |
167 tem = XVECTOR (fun)->contents[COMPILED_DOC_STRING]; | |
168 if (XTYPE (tem) == Lisp_String) | |
570 | 169 doc = tem; |
170 else if (XTYPE (tem) == Lisp_Int && XINT (tem) >= 0) | |
171 doc = get_doc_string (XFASTINT (tem)); | |
172 else | |
173 return Qnil; | |
174 break; | |
297 | 175 |
176 case Lisp_String: | |
177 case Lisp_Vector: | |
178 return build_string ("Keyboard macro."); | |
179 | |
180 case Lisp_Cons: | |
181 funcar = Fcar (fun); | |
182 if (XTYPE (funcar) != Lisp_Symbol) | |
183 return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); | |
647 | 184 else if (EQ (funcar, Qkeymap)) |
297 | 185 return build_string ("Prefix command (definition is a keymap associating keystrokes with\n\ |
186 subcommands.)"); | |
647 | 187 else if (EQ (funcar, Qlambda) |
188 || EQ (funcar, Qautoload)) | |
297 | 189 { |
190 tem = Fcar (Fcdr (Fcdr (fun))); | |
191 if (XTYPE (tem) == Lisp_String) | |
570 | 192 doc = tem; |
193 else if (XTYPE (tem) == Lisp_Int && XINT (tem) >= 0) | |
194 doc = get_doc_string (XFASTINT (tem)); | |
195 else | |
196 return Qnil; | |
647 | 197 |
198 break; | |
297 | 199 } |
647 | 200 else if (EQ (funcar, Qmocklisp)) |
297 | 201 return Qnil; |
647 | 202 else if (EQ (funcar, Qmacro)) |
570 | 203 return Fdocumentation (Fcdr (fun), raw); |
297 | 204 |
205 /* Fall through to the default to report an error. */ | |
206 | |
207 default: | |
208 return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); | |
209 } | |
570 | 210 |
577 | 211 if (NILP (raw)) |
1511
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
212 { |
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
213 struct gcpro gcpro1; |
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
214 |
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
215 GCPRO1 (doc); |
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
216 doc = Fsubstitute_command_keys (doc); |
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
217 UNGCPRO; |
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
218 } |
570 | 219 return doc; |
297 | 220 } |
221 | |
5248
27d6275810a7
(Fsubstitute_command_keys): Ignore menu bar bindings.
Richard M. Stallman <rms@gnu.org>
parents:
4716
diff
changeset
|
222 DEFUN ("documentation-property", Fdocumentation_property, Sdocumentation_property, 2, 3, 0, |
297 | 223 "Return the documentation string that is SYMBOL's PROP property.\n\ |
570 | 224 This is like `get', but it can refer to strings stored in the\n\ |
604 | 225 `etc/DOC' file; and if the value is a string, it is passed through\n\ |
577 | 226 `substitute-command-keys'. A non-nil third argument avoids this\n\ |
227 translation.") | |
570 | 228 (sym, prop, raw) |
229 Lisp_Object sym, prop, raw; | |
297 | 230 { |
231 register Lisp_Object tem; | |
232 | |
233 tem = Fget (sym, prop); | |
234 if (XTYPE (tem) == Lisp_Int) | |
235 tem = get_doc_string (XINT (tem) > 0 ? XINT (tem) : - XINT (tem)); | |
577 | 236 if (NILP (raw) && XTYPE (tem) == Lisp_String) |
312
adba7439e87c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
297
diff
changeset
|
237 return Fsubstitute_command_keys (tem); |
adba7439e87c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
297
diff
changeset
|
238 return tem; |
297 | 239 } |
240 | |
1651
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
241 /* Scanning the DOC files and placing docstring offsets into functions. */ |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
242 |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
243 static void |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
244 store_function_docstring (fun, offset) |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
245 Lisp_Object fun; |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
246 int offset; |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
247 { |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
248 fun = indirect_function (fun); |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
249 |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
250 /* The type determines where the docstring is stored. */ |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
251 |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
252 /* Lisp_Subrs have a slot for it. */ |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
253 if (XTYPE (fun) == Lisp_Subr) |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
254 XSUBR (fun)->doc = (char *) - offset; |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
255 |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
256 /* If it's a lisp form, stick it in the form. */ |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
257 else if (CONSP (fun)) |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
258 { |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
259 Lisp_Object tem; |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
260 |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
261 tem = XCONS (fun)->car; |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
262 if (EQ (tem, Qlambda) || EQ (tem, Qautoload)) |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
263 { |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
264 tem = Fcdr (Fcdr (fun)); |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
265 if (CONSP (tem) && |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
266 XTYPE (XCONS (tem)->car) == Lisp_Int) |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
267 XFASTINT (XCONS (tem)->car) = offset; |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
268 } |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
269 else if (EQ (tem, Qmacro)) |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
270 store_function_docstring (XCONS (fun)->cdr, offset); |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
271 } |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
272 |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
273 /* Bytecode objects sometimes have slots for it. */ |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
274 else if (XTYPE (fun) == Lisp_Compiled) |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
275 { |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
276 /* This bytecode object must have a slot for the |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
277 docstring, since we've found a docstring for it. */ |
8552
1353c008cf8e
(store_function_docstring): Do nothing for bytecode object
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
278 if (XVECTOR (fun)->size > COMPILED_DOC_STRING) |
1353c008cf8e
(store_function_docstring): Do nothing for bytecode object
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
279 XFASTINT (XVECTOR (fun)->contents[COMPILED_DOC_STRING]) = offset; |
1651
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
280 } |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
281 } |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
282 |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
283 |
297 | 284 DEFUN ("Snarf-documentation", Fsnarf_documentation, Ssnarf_documentation, |
285 1, 1, 0, | |
286 "Used during Emacs initialization, before dumping runnable Emacs,\n\ | |
604 | 287 to find pointers to doc strings stored in `etc/DOC...' and\n\ |
297 | 288 record them in function definitions.\n\ |
289 One arg, FILENAME, a string which does not include a directory.\n\ | |
604 | 290 The file is found in `../etc' now; found in the `data-directory'\n\ |
297 | 291 when doc strings are referred to later in the dumped Emacs.") |
292 (filename) | |
293 Lisp_Object filename; | |
294 { | |
295 int fd; | |
296 char buf[1024 + 1]; | |
297 register int filled; | |
298 register int pos; | |
299 register char *p, *end; | |
300 Lisp_Object sym, fun, tem; | |
301 char *name; | |
302 extern char *index (); | |
303 | |
1116
6d0d442e2ada
* doc.c (Fsnarf_documentation): Signal an error if this is
Jim Blandy <jimb@redhat.com>
parents:
961
diff
changeset
|
304 #ifndef CANNOT_DUMP |
6d0d442e2ada
* doc.c (Fsnarf_documentation): Signal an error if this is
Jim Blandy <jimb@redhat.com>
parents:
961
diff
changeset
|
305 if (NILP (Vpurify_flag)) |
6d0d442e2ada
* doc.c (Fsnarf_documentation): Signal an error if this is
Jim Blandy <jimb@redhat.com>
parents:
961
diff
changeset
|
306 error ("Snarf-documentation can only be called in an undumped Emacs"); |
6d0d442e2ada
* doc.c (Fsnarf_documentation): Signal an error if this is
Jim Blandy <jimb@redhat.com>
parents:
961
diff
changeset
|
307 #endif |
6d0d442e2ada
* doc.c (Fsnarf_documentation): Signal an error if this is
Jim Blandy <jimb@redhat.com>
parents:
961
diff
changeset
|
308 |
297 | 309 CHECK_STRING (filename, 0); |
310 | |
311 #ifndef CANNOT_DUMP | |
463 | 312 name = (char *) alloca (XSTRING (filename)->size + 14); |
604 | 313 strcpy (name, "../etc/"); |
297 | 314 #else /* CANNOT_DUMP */ |
6030
8b3f54fb451f
(get_doc_string, Snarf_documentation): Use new variable doc_directory.
Karl Heuer <kwzh@gnu.org>
parents:
5784
diff
changeset
|
315 CHECK_STRING (Vdoc_directory, 0); |
297 | 316 name = (char *) alloca (XSTRING (filename)->size + |
6030
8b3f54fb451f
(get_doc_string, Snarf_documentation): Use new variable doc_directory.
Karl Heuer <kwzh@gnu.org>
parents:
5784
diff
changeset
|
317 XSTRING (Vdoc_directory)->size + 1); |
8b3f54fb451f
(get_doc_string, Snarf_documentation): Use new variable doc_directory.
Karl Heuer <kwzh@gnu.org>
parents:
5784
diff
changeset
|
318 strcpy (name, XSTRING (Vdoc_directory)->data); |
297 | 319 #endif /* CANNOT_DUMP */ |
320 strcat (name, XSTRING (filename)->data); /*** Add this line ***/ | |
321 #ifdef VMS | |
322 #ifndef VMS4_4 | |
323 /* For VMS versions with limited file name syntax, | |
324 convert the name to something VMS will allow. */ | |
325 p = name; | |
326 while (*p) | |
327 { | |
328 if (*p == '-') | |
329 *p = '_'; | |
330 p++; | |
331 } | |
332 #endif /* not VMS4_4 */ | |
333 #ifdef VMS4_4 | |
334 strcpy (name, sys_translate_unix (name)); | |
335 #endif /* VMS4_4 */ | |
336 #endif /* VMS */ | |
337 | |
338 fd = open (name, O_RDONLY, 0); | |
339 if (fd < 0) | |
340 report_file_error ("Opening doc string file", | |
341 Fcons (build_string (name), Qnil)); | |
342 Vdoc_file_name = filename; | |
343 filled = 0; | |
344 pos = 0; | |
345 while (1) | |
346 { | |
347 if (filled < 512) | |
348 filled += read (fd, &buf[filled], sizeof buf - 1 - filled); | |
349 if (!filled) | |
350 break; | |
351 | |
352 buf[filled] = 0; | |
353 p = buf; | |
354 end = buf + (filled < 512 ? filled : filled - 128); | |
355 while (p != end && *p != '\037') p++; | |
356 /* p points to ^_Ffunctionname\n or ^_Vvarname\n. */ | |
357 if (p != end) | |
358 { | |
359 end = index (p, '\n'); | |
360 sym = oblookup (Vobarray, p + 2, end - p - 2); | |
361 if (XTYPE (sym) == Lisp_Symbol) | |
362 { | |
363 /* Attach a docstring to a variable? */ | |
364 if (p[1] == 'V') | |
365 { | |
366 /* Install file-position as variable-documentation property | |
367 and make it negative for a user-variable | |
368 (doc starts with a `*'). */ | |
369 Fput (sym, Qvariable_documentation, | |
370 make_number ((pos + end + 1 - buf) | |
371 * (end[1] == '*' ? -1 : 1))); | |
372 } | |
373 | |
1651
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
374 /* Attach a docstring to a function? */ |
297 | 375 else if (p[1] == 'F') |
1651
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
376 store_function_docstring (sym, pos + end + 1 - buf); |
297 | 377 |
1651
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
378 else |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
379 error ("DOC file invalid at position %d", pos); |
297 | 380 } |
381 } | |
382 pos += end - buf; | |
383 filled -= end - buf; | |
384 bcopy (end, buf, filled); | |
385 } | |
386 close (fd); | |
387 return Qnil; | |
388 } | |
389 | |
390 DEFUN ("substitute-command-keys", Fsubstitute_command_keys, | |
391 Ssubstitute_command_keys, 1, 1, 0, | |
392 "Substitute key descriptions for command names in STRING.\n\ | |
393 Return a new string which is STRING with substrings of the form \\=\\[COMMAND]\n\ | |
394 replaced by either: a keystroke sequence that will invoke COMMAND,\n\ | |
395 or \"M-x COMMAND\" if COMMAND is not on any keys.\n\ | |
396 Substrings of the form \\=\\{MAPVAR} are replaced by summaries\n\ | |
397 \(made by describe-bindings) of the value of MAPVAR, taken as a keymap.\n\ | |
398 Substrings of the form \\=\\<MAPVAR> specify to use the value of MAPVAR\n\ | |
399 as the keymap for future \\=\\[COMMAND] substrings.\n\ | |
400 \\=\\= quotes the following character and is discarded;\n\ | |
401 thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ into the output.") | |
402 (str) | |
403 Lisp_Object str; | |
404 { | |
405 unsigned char *buf; | |
406 int changed = 0; | |
407 register unsigned char *strp; | |
408 register unsigned char *bufp; | |
409 int idx; | |
410 int bsize; | |
411 unsigned char *new; | |
1511
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
412 Lisp_Object tem; |
297 | 413 Lisp_Object keymap; |
414 unsigned char *start; | |
415 int length; | |
1511
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
416 Lisp_Object name; |
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
417 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
297 | 418 |
485 | 419 if (NILP (str)) |
297 | 420 return Qnil; |
421 | |
422 CHECK_STRING (str, 0); | |
1511
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
423 tem = Qnil; |
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
424 keymap = Qnil; |
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
425 name = Qnil; |
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
426 GCPRO4 (str, tem, keymap, name); |
297 | 427 |
5784
9c3be8e0d2ef
(Fsubstitute_command_keys): Pass keymap as that arg
Richard M. Stallman <rms@gnu.org>
parents:
5550
diff
changeset
|
428 /* KEYMAP is either nil (which means search all the active keymaps) |
9c3be8e0d2ef
(Fsubstitute_command_keys): Pass keymap as that arg
Richard M. Stallman <rms@gnu.org>
parents:
5550
diff
changeset
|
429 or a specified local map (which means search just that and the |
9c3be8e0d2ef
(Fsubstitute_command_keys): Pass keymap as that arg
Richard M. Stallman <rms@gnu.org>
parents:
5550
diff
changeset
|
430 global map). If non-nil, it might come from Voverriding_local_map, |
9c3be8e0d2ef
(Fsubstitute_command_keys): Pass keymap as that arg
Richard M. Stallman <rms@gnu.org>
parents:
5550
diff
changeset
|
431 or from a \\<mapname> construct in STR itself.. */ |
9c3be8e0d2ef
(Fsubstitute_command_keys): Pass keymap as that arg
Richard M. Stallman <rms@gnu.org>
parents:
5550
diff
changeset
|
432 keymap = Voverriding_local_map; |
297 | 433 |
434 bsize = XSTRING (str)->size; | |
435 bufp = buf = (unsigned char *) xmalloc (bsize); | |
436 | |
437 strp = (unsigned char *) XSTRING (str)->data; | |
438 while (strp < (unsigned char *) XSTRING (str)->data + XSTRING (str)->size) | |
439 { | |
440 if (strp[0] == '\\' && strp[1] == '=') | |
441 { | |
442 /* \= quotes the next character; | |
443 thus, to put in \[ without its special meaning, use \=\[. */ | |
444 changed = 1; | |
445 *bufp++ = strp[2]; | |
446 strp += 3; | |
447 } | |
448 else if (strp[0] == '\\' && strp[1] == '[') | |
449 { | |
5248
27d6275810a7
(Fsubstitute_command_keys): Ignore menu bar bindings.
Richard M. Stallman <rms@gnu.org>
parents:
4716
diff
changeset
|
450 Lisp_Object firstkey; |
27d6275810a7
(Fsubstitute_command_keys): Ignore menu bar bindings.
Richard M. Stallman <rms@gnu.org>
parents:
4716
diff
changeset
|
451 |
297 | 452 changed = 1; |
453 strp += 2; /* skip \[ */ | |
454 start = strp; | |
455 | |
456 while ((strp - (unsigned char *) XSTRING (str)->data | |
457 < XSTRING (str)->size) | |
458 && *strp != ']') | |
459 strp++; | |
460 length = strp - start; | |
461 strp++; /* skip ] */ | |
462 | |
463 /* Save STRP in IDX. */ | |
464 idx = strp - (unsigned char *) XSTRING (str)->data; | |
465 tem = Fintern (make_string (start, length), Qnil); | |
5784
9c3be8e0d2ef
(Fsubstitute_command_keys): Pass keymap as that arg
Richard M. Stallman <rms@gnu.org>
parents:
5550
diff
changeset
|
466 tem = Fwhere_is_internal (tem, keymap, Qt, Qnil); |
297 | 467 |
5248
27d6275810a7
(Fsubstitute_command_keys): Ignore menu bar bindings.
Richard M. Stallman <rms@gnu.org>
parents:
4716
diff
changeset
|
468 /* Disregard menu bar bindings; it is positively annoying to |
27d6275810a7
(Fsubstitute_command_keys): Ignore menu bar bindings.
Richard M. Stallman <rms@gnu.org>
parents:
4716
diff
changeset
|
469 mention them when there's no menu bar, and it isn't terribly |
27d6275810a7
(Fsubstitute_command_keys): Ignore menu bar bindings.
Richard M. Stallman <rms@gnu.org>
parents:
4716
diff
changeset
|
470 useful even when there is a menu bar. */ |
5377
7a8463c07d8f
(Fsubstitute_command_keys): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
5248
diff
changeset
|
471 if (!NILP (tem)) |
7a8463c07d8f
(Fsubstitute_command_keys): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
5248
diff
changeset
|
472 { |
7a8463c07d8f
(Fsubstitute_command_keys): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
5248
diff
changeset
|
473 firstkey = Faref (tem, make_number (0)); |
7a8463c07d8f
(Fsubstitute_command_keys): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
5248
diff
changeset
|
474 if (EQ (firstkey, Qmenu_bar)) |
7a8463c07d8f
(Fsubstitute_command_keys): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
5248
diff
changeset
|
475 tem = Qnil; |
7a8463c07d8f
(Fsubstitute_command_keys): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
5248
diff
changeset
|
476 } |
5248
27d6275810a7
(Fsubstitute_command_keys): Ignore menu bar bindings.
Richard M. Stallman <rms@gnu.org>
parents:
4716
diff
changeset
|
477 |
485 | 478 if (NILP (tem)) /* but not on any keys */ |
297 | 479 { |
480 new = (unsigned char *) xrealloc (buf, bsize += 4); | |
481 bufp += new - buf; | |
482 buf = new; | |
483 bcopy ("M-x ", bufp, 4); | |
484 bufp += 4; | |
485 goto subst; | |
486 } | |
487 else | |
488 { /* function is on a key */ | |
489 tem = Fkey_description (tem); | |
490 goto subst_string; | |
491 } | |
492 } | |
493 /* \{foo} is replaced with a summary of the keymap (symbol-value foo). | |
494 \<foo> just sets the keymap used for \[cmd]. */ | |
495 else if (strp[0] == '\\' && (strp[1] == '{' || strp[1] == '<')) | |
496 { | |
497 struct buffer *oldbuf; | |
498 | |
499 changed = 1; | |
500 strp += 2; /* skip \{ or \< */ | |
501 start = strp; | |
502 | |
503 while ((strp - (unsigned char *) XSTRING (str)->data | |
504 < XSTRING (str)->size) | |
505 && *strp != '}' && *strp != '>') | |
506 strp++; | |
507 length = strp - start; | |
508 strp++; /* skip } or > */ | |
509 | |
510 /* Save STRP in IDX. */ | |
511 idx = strp - (unsigned char *) XSTRING (str)->data; | |
512 | |
513 /* Get the value of the keymap in TEM, or nil if undefined. | |
514 Do this while still in the user's current buffer | |
515 in case it is a local variable. */ | |
516 name = Fintern (make_string (start, length), Qnil); | |
517 tem = Fboundp (name); | |
485 | 518 if (! NILP (tem)) |
297 | 519 { |
520 tem = Fsymbol_value (name); | |
485 | 521 if (! NILP (tem)) |
1511
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
522 tem = get_keymap_1 (tem, 0, 1); |
297 | 523 } |
524 | |
525 /* Now switch to a temp buffer. */ | |
526 oldbuf = current_buffer; | |
527 set_buffer_internal (XBUFFER (Vprin1_to_string_buffer)); | |
528 | |
485 | 529 if (NILP (tem)) |
297 | 530 { |
531 name = Fsymbol_name (name); | |
532 insert_string ("\nUses keymap \""); | |
4716
4382ad05411e
(Fsubstitute_command_keys): Pass new arg to insert_from_string.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
533 insert_from_string (name, 0, XSTRING (name)->size, 1); |
297 | 534 insert_string ("\", which is not currently defined.\n"); |
535 if (start[-1] == '<') keymap = Qnil; | |
536 } | |
537 else if (start[-1] == '<') | |
538 keymap = tem; | |
539 else | |
5550
9e8bbed9a9b6
(Fsubstitute_command_keys): Pass new arg to describe_map_tree.
Richard M. Stallman <rms@gnu.org>
parents:
5377
diff
changeset
|
540 describe_map_tree (tem, 1, Qnil, Qnil, 0, 1); |
297 | 541 tem = Fbuffer_string (); |
542 Ferase_buffer (); | |
543 set_buffer_internal (oldbuf); | |
544 | |
545 subst_string: | |
546 start = XSTRING (tem)->data; | |
547 length = XSTRING (tem)->size; | |
548 subst: | |
549 new = (unsigned char *) xrealloc (buf, bsize += length); | |
550 bufp += new - buf; | |
551 buf = new; | |
552 bcopy (start, bufp, length); | |
553 bufp += length; | |
554 /* Check STR again in case gc relocated it. */ | |
555 strp = (unsigned char *) XSTRING (str)->data + idx; | |
556 } | |
557 else /* just copy other chars */ | |
558 *bufp++ = *strp++; | |
559 } | |
560 | |
561 if (changed) /* don't bother if nothing substituted */ | |
562 tem = make_string (buf, bufp - buf); | |
563 else | |
564 tem = str; | |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
1651
diff
changeset
|
565 xfree (buf); |
1511
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
566 RETURN_UNGCPRO (tem); |
297 | 567 } |
568 | |
569 syms_of_doc () | |
570 { | |
571 DEFVAR_LISP ("internal-doc-file-name", &Vdoc_file_name, | |
572 "Name of file containing documentation strings of built-in symbols."); | |
573 Vdoc_file_name = Qnil; | |
574 | |
575 defsubr (&Sdocumentation); | |
576 defsubr (&Sdocumentation_property); | |
577 defsubr (&Ssnarf_documentation); | |
578 defsubr (&Ssubstitute_command_keys); | |
579 } |