428
|
1 /* Record indices of function doc strings stored in a file.
|
|
2 Copyright (C) 1985, 1986, 1992, 1993, 1994, 1995
|
|
3 Free Software Foundation, Inc.
|
2367
|
4 Copyright (C) 2001, 2002, 2004 Ben Wing.
|
428
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: FSF 19.30. */
|
|
24
|
814
|
25 /* This file has been Mule-ized. */
|
428
|
26
|
|
27 #include <config.h>
|
|
28 #include "lisp.h"
|
|
29
|
|
30 #include "buffer.h"
|
|
31 #include "bytecode.h"
|
814
|
32 #include "file-coding.h"
|
428
|
33 #include "insdel.h"
|
|
34 #include "keymap.h"
|
814
|
35 #include "lstream.h"
|
428
|
36 #include "sysfile.h"
|
|
37
|
|
38 Lisp_Object Vinternal_doc_file_name;
|
|
39
|
|
40 Lisp_Object QSsubstitute;
|
|
41
|
3368
|
42 /* Work out what source file a function or variable came from, taking the
|
|
43 information from the documentation file. */
|
|
44
|
|
45 static Lisp_Object
|
|
46 extract_object_file_name (int fd, EMACS_INT doc_pos,
|
|
47 Ibyte *name_nonreloc, Lisp_Object name_reloc,
|
|
48 int standard_doc_file)
|
|
49 {
|
|
50 Ibyte buf[DOC_MAX_FILENAME_LENGTH];
|
|
51 Ibyte *buffer = buf;
|
|
52 int buffer_size = sizeof (buf), space_left;
|
|
53 Ibyte *from, *to;
|
|
54 REGISTER Ibyte *p = buffer;
|
|
55 Lisp_Object return_me;
|
|
56 Lisp_Object fdstream = Qnil, instream = Qnil;
|
|
57 struct gcpro gcpro1, gcpro2;
|
|
58 EMACS_INT position, seenS = 0;
|
|
59
|
|
60 GCPRO2 (fdstream, instream);
|
|
61
|
|
62 position = doc_pos > DOC_MAX_FILENAME_LENGTH ?
|
|
63 doc_pos - DOC_MAX_FILENAME_LENGTH : 0;
|
|
64
|
|
65 if (0 > lseek (fd, position, 0))
|
|
66 {
|
|
67 if (name_nonreloc)
|
|
68 name_reloc = build_intstring (name_nonreloc);
|
|
69 return_me = list3 (build_msg_string
|
|
70 ("Position out of range in doc string file"),
|
|
71 name_reloc, make_int (position));
|
|
72 goto done;
|
|
73 }
|
|
74
|
|
75 fdstream = make_filedesc_input_stream (fd, 0, -1, 0);
|
|
76 Lstream_set_buffering (XLSTREAM (fdstream), LSTREAM_UNBUFFERED, 0);
|
|
77 instream =
|
|
78 make_coding_input_stream
|
|
79 (XLSTREAM (fdstream), standard_doc_file ? Qescape_quoted : Qbinary,
|
|
80 CODING_DECODE, 0);
|
|
81 Lstream_set_buffering (XLSTREAM (instream), LSTREAM_UNBUFFERED, 0);
|
|
82
|
|
83 space_left = buffer_size - (p - buffer);
|
|
84 while (space_left > 0)
|
|
85 {
|
|
86 int nread;
|
|
87
|
|
88 nread = Lstream_read (XLSTREAM (instream), p, space_left);
|
|
89 if (nread < 0)
|
|
90 {
|
|
91 return_me = list1 (build_msg_string
|
|
92 ("Read error on documentation file"));
|
|
93 goto done;
|
|
94 }
|
|
95
|
|
96 p[nread] = 0;
|
|
97
|
|
98 if (!nread)
|
|
99 break;
|
|
100
|
|
101 p += nread;
|
|
102 space_left = buffer_size - (p - buffer);
|
|
103 }
|
|
104
|
|
105 /* First, search backward for the "\037S" that marks the beginning of the
|
|
106 file name, then search forward from that to the newline or to the end
|
|
107 of the buffer. */
|
|
108 from = p;
|
|
109
|
|
110 while (from > buf)
|
|
111 {
|
|
112 --from;
|
|
113 if (seenS)
|
|
114 {
|
|
115 if ('\037' == *from)
|
|
116 {
|
|
117 /* Got a file name; adjust `from' to point to it, break out of
|
|
118 the loop. */
|
|
119 from += 2;
|
|
120 break;
|
|
121 }
|
|
122 }
|
|
123 /* Is *from 'S' ? */
|
|
124 seenS = ('S' == *from);
|
|
125 }
|
|
126
|
|
127 if (buf == from)
|
|
128 {
|
|
129 /* We've scanned back to the beginning of the buffer without hitting
|
|
130 the file name. Either the file name plus the symbol name is longer
|
|
131 than DOC_MAX_FILENAME_LENGTH--which shouldn't happen, because it'll
|
|
132 trigger an assertion failure in make-docfile, the DOC file is
|
|
133 corrupt, or it was produced by a version of make-docfile that
|
|
134 doesn't store the file name with the symbol name and docstring. */
|
|
135 return_me = list1 (build_msg_string
|
|
136 ("Object file name not stored in doc file"));
|
|
137 goto done;
|
|
138 }
|
|
139
|
|
140 to = from;
|
|
141 /* Search for the end of the file name. */
|
|
142 while (++to < p)
|
|
143 {
|
|
144 if ('\n' == *to || '\037' == *to)
|
|
145 {
|
|
146 break;
|
|
147 }
|
|
148 }
|
|
149
|
|
150 /* Don't require the file name to end in a newline. */
|
|
151 return_me = make_string (from, to - from);
|
|
152
|
|
153 done:
|
|
154 if (!NILP (instream))
|
|
155 {
|
|
156 Lstream_delete (XLSTREAM (instream));
|
|
157 Lstream_delete (XLSTREAM (fdstream));
|
|
158 }
|
|
159
|
|
160 UNGCPRO;
|
|
161 return return_me;
|
|
162 }
|
428
|
163
|
|
164 Lisp_Object
|
|
165 unparesseuxify_doc_string (int fd, EMACS_INT position,
|
867
|
166 Ibyte *name_nonreloc, Lisp_Object name_reloc,
|
814
|
167 int standard_doc_file)
|
428
|
168 {
|
867
|
169 Ibyte buf[512 * 32 + 1];
|
|
170 Ibyte *buffer = buf;
|
428
|
171 int buffer_size = sizeof (buf);
|
867
|
172 Ibyte *from, *to;
|
|
173 REGISTER Ibyte *p = buffer;
|
428
|
174 Lisp_Object return_me;
|
814
|
175 Lisp_Object fdstream = Qnil, instream = Qnil;
|
|
176 struct gcpro gcpro1, gcpro2;
|
|
177
|
|
178 GCPRO2 (fdstream, instream);
|
428
|
179
|
|
180 if (0 > lseek (fd, position, 0))
|
|
181 {
|
|
182 if (name_nonreloc)
|
771
|
183 name_reloc = build_intstring (name_nonreloc);
|
|
184 return_me = list3 (build_msg_string
|
428
|
185 ("Position out of range in doc string file"),
|
|
186 name_reloc, make_int (position));
|
|
187 goto done;
|
|
188 }
|
|
189
|
814
|
190 fdstream = make_filedesc_input_stream (fd, 0, -1, 0);
|
|
191 Lstream_set_buffering (XLSTREAM (fdstream), LSTREAM_UNBUFFERED, 0);
|
|
192 instream =
|
|
193 make_coding_input_stream
|
|
194 /* Major trouble if we are too clever when reading byte-code
|
|
195 instructions!
|
|
196
|
|
197 #### We should have a way of handling escape-quoted elc files
|
|
198 (i.e. files with non-ASCII/Latin-1 chars in them). Currently this
|
|
199 is "solved" in bytecomp.el by never inserting lazy references in
|
|
200 such files. */
|
826
|
201 (XLSTREAM (fdstream), standard_doc_file ? Qescape_quoted : Qbinary,
|
814
|
202 CODING_DECODE, 0);
|
|
203 Lstream_set_buffering (XLSTREAM (instream), LSTREAM_UNBUFFERED, 0);
|
|
204
|
428
|
205 /* Read the doc string into a buffer.
|
|
206 Use the fixed buffer BUF if it is big enough; otherwise allocate one.
|
|
207 We store the buffer in use in BUFFER and its size in BUFFER_SIZE. */
|
|
208
|
|
209 while (1)
|
|
210 {
|
|
211 int space_left = buffer_size - (p - buffer);
|
|
212 int nread;
|
|
213
|
|
214 /* Switch to a bigger buffer if we need one. */
|
|
215 if (space_left == 0)
|
|
216 {
|
867
|
217 Ibyte *old_buffer = buffer;
|
771
|
218 if (buffer == buf)
|
|
219 {
|
2367
|
220 buffer = xnew_ibytes (buffer_size *= 2);
|
771
|
221 memcpy (buffer, old_buffer, p - old_buffer);
|
|
222 }
|
|
223 else
|
2367
|
224 XREALLOC_ARRAY (buffer, Ibyte, buffer_size *= 2);
|
428
|
225 p += buffer - old_buffer;
|
|
226 space_left = buffer_size - (p - buffer);
|
|
227 }
|
|
228
|
|
229 /* Don't read too much at one go. */
|
|
230 if (space_left > 1024 * 8)
|
|
231 space_left = 1024 * 8;
|
814
|
232 nread = Lstream_read (XLSTREAM (instream), p, space_left);
|
428
|
233 if (nread < 0)
|
|
234 {
|
771
|
235 return_me = list1 (build_msg_string
|
428
|
236 ("Read error on documentation file"));
|
|
237 goto done;
|
|
238 }
|
|
239 p[nread] = 0;
|
|
240 if (!nread)
|
|
241 break;
|
|
242 {
|
867
|
243 Ibyte *p1 = qxestrchr (p, '\037'); /* End of doc string marker */
|
814
|
244 if (p1)
|
|
245 {
|
|
246 *p1 = 0;
|
|
247 p = p1;
|
|
248 break;
|
|
249 }
|
428
|
250 }
|
|
251 p += nread;
|
|
252 }
|
|
253
|
|
254 /* Scan the text and remove quoting with ^A (char code 1).
|
|
255 ^A^A becomes ^A, ^A0 becomes a null char, and ^A_ becomes a ^_. */
|
|
256 from = to = buffer;
|
|
257 while (from < p)
|
|
258 {
|
|
259 if (*from != 1 /*^A*/)
|
|
260 *to++ = *from++;
|
|
261 else
|
|
262 {
|
|
263 int c = *(++from);
|
|
264
|
|
265 from++;
|
|
266 switch (c)
|
|
267 {
|
|
268 case 1: *to++ = c; break;
|
|
269 case '0': *to++ = '\0'; break;
|
|
270 case '_': *to++ = '\037'; break;
|
|
271 default:
|
771
|
272 return_me = list2 (build_msg_string
|
428
|
273 ("Invalid data in documentation file -- ^A followed by weird code"),
|
|
274 make_int (c));
|
|
275 goto done;
|
|
276 }
|
|
277 }
|
|
278 }
|
|
279
|
814
|
280 return_me = make_string (buffer, to - buffer);
|
428
|
281
|
|
282 done:
|
814
|
283 if (!NILP (instream))
|
|
284 {
|
|
285 Lstream_delete (XLSTREAM (instream));
|
|
286 Lstream_delete (XLSTREAM (fdstream));
|
|
287 }
|
|
288 UNGCPRO;
|
428
|
289 if (buffer != buf) /* We must have allocated buffer above */
|
1726
|
290 xfree (buffer, Ibyte *);
|
428
|
291 return return_me;
|
|
292 }
|
|
293
|
771
|
294 #define string_join(dest, s1, s2) \
|
|
295 memcpy (dest, XSTRING_DATA (s1), XSTRING_LENGTH (s1)); \
|
|
296 memcpy (dest + XSTRING_LENGTH (s1), XSTRING_DATA (s2), \
|
|
297 XSTRING_LENGTH (s2)); \
|
428
|
298 dest[XSTRING_LENGTH (s1) + XSTRING_LENGTH (s2)] = '\0'
|
|
299
|
|
300 /* Extract a doc string from a file. FILEPOS says where to get it.
|
|
301 (This could actually be byte code instructions/constants instead
|
|
302 of a doc string.)
|
|
303 If it is an integer, use that position in the standard DOC file.
|
|
304 If it is (FILE . INTEGER), use FILE as the file name
|
|
305 and INTEGER as the position in that file.
|
|
306 But if INTEGER is negative, make it positive.
|
|
307 (A negative integer is used for user variables, so we can distinguish
|
|
308 them without actually fetching the doc string.) */
|
|
309
|
|
310 static Lisp_Object
|
|
311 get_doc_string (Lisp_Object filepos)
|
|
312 {
|
|
313 REGISTER int fd;
|
867
|
314 REGISTER Ibyte *name_nonreloc = 0;
|
428
|
315 EMACS_INT position;
|
|
316 Lisp_Object file, tem;
|
|
317 Lisp_Object name_reloc = Qnil;
|
814
|
318 int standard_doc_file = 0;
|
428
|
319
|
|
320 if (INTP (filepos))
|
|
321 {
|
|
322 file = Vinternal_doc_file_name;
|
814
|
323 standard_doc_file = 1;
|
428
|
324 position = XINT (filepos);
|
|
325 }
|
|
326 else if (CONSP (filepos) && INTP (XCDR (filepos)))
|
|
327 {
|
|
328 file = XCAR (filepos);
|
|
329 position = XINT (XCDR (filepos));
|
|
330 if (position < 0)
|
|
331 position = - position;
|
|
332 }
|
|
333 else
|
|
334 return Qnil;
|
|
335
|
|
336 if (!STRINGP (file))
|
|
337 return Qnil;
|
|
338
|
|
339 /* Put the file name in NAME as a C string.
|
|
340 If it is relative, combine it with Vdoc_directory. */
|
|
341
|
|
342 tem = Ffile_name_absolute_p (file);
|
|
343 if (NILP (tem))
|
|
344 {
|
647
|
345 Bytecount minsize;
|
428
|
346 /* XEmacs: Move this check here. OK if called during loadup to
|
|
347 load byte code instructions. */
|
|
348 if (!STRINGP (Vdoc_directory))
|
|
349 return Qnil;
|
|
350
|
|
351 minsize = XSTRING_LENGTH (Vdoc_directory);
|
|
352 /* sizeof ("../lib-src/") == 12 */
|
|
353 if (minsize < 12)
|
|
354 minsize = 12;
|
867
|
355 name_nonreloc = alloca_ibytes (minsize + XSTRING_LENGTH (file) + 8);
|
428
|
356 string_join (name_nonreloc, Vdoc_directory, file);
|
|
357 }
|
|
358 else
|
|
359 name_reloc = file;
|
|
360
|
771
|
361 fd = qxe_open (name_nonreloc ? name_nonreloc :
|
|
362 XSTRING_DATA (name_reloc), O_RDONLY | OPEN_BINARY, 0);
|
428
|
363 if (fd < 0)
|
|
364 {
|
|
365 if (purify_flag)
|
|
366 {
|
|
367 /* sizeof ("../lib-src/") == 12 */
|
2367
|
368 name_nonreloc = alloca_ibytes (12 + XSTRING_LENGTH (file) + 8);
|
428
|
369 /* Preparing to dump; DOC file is probably not installed.
|
|
370 So check in ../lib-src. */
|
2367
|
371 qxestrcpy_ascii (name_nonreloc, "../lib-src/");
|
771
|
372 qxestrcat (name_nonreloc, XSTRING_DATA (file));
|
428
|
373
|
771
|
374 fd = qxe_open (name_nonreloc, O_RDONLY | OPEN_BINARY, 0);
|
428
|
375 }
|
|
376
|
|
377 if (fd < 0)
|
814
|
378 report_file_error ("Cannot open doc string file",
|
|
379 name_nonreloc ? build_intstring (name_nonreloc) :
|
|
380 name_reloc);
|
428
|
381 }
|
|
382
|
814
|
383 tem = unparesseuxify_doc_string (fd, position, name_nonreloc, name_reloc,
|
|
384 standard_doc_file);
|
771
|
385 retry_close (fd);
|
428
|
386
|
|
387 if (!STRINGP (tem))
|
563
|
388 signal_error_1 (Qinvalid_byte_code, tem);
|
428
|
389
|
|
390 return tem;
|
|
391 }
|
|
392
|
|
393 /* Get a string from position FILEPOS and pass it through the Lisp reader.
|
|
394 We use this for fetching the bytecode string and constants vector
|
|
395 of a compiled function from the .elc file. */
|
|
396
|
|
397 Lisp_Object
|
|
398 read_doc_string (Lisp_Object filepos)
|
|
399 {
|
|
400 Lisp_Object string = get_doc_string (filepos);
|
|
401
|
|
402 if (!STRINGP (string))
|
563
|
403 invalid_state ("loading bytecode failed to return string", string);
|
428
|
404 return Fread (string);
|
|
405 }
|
|
406
|
3368
|
407 static Lisp_Object
|
|
408 get_object_file_name (Lisp_Object filepos)
|
|
409 {
|
|
410 REGISTER int fd;
|
|
411 REGISTER Ibyte *name_nonreloc = 0;
|
|
412 EMACS_INT position;
|
|
413 Lisp_Object file, tem;
|
|
414 Lisp_Object name_reloc = Qnil;
|
|
415 int standard_doc_file = 0;
|
|
416
|
|
417 if (INTP (filepos))
|
|
418 {
|
|
419 file = Vinternal_doc_file_name;
|
|
420 standard_doc_file = 1;
|
|
421 position = XINT (filepos);
|
|
422 }
|
|
423 else if (CONSP (filepos) && INTP (XCDR (filepos)))
|
|
424 {
|
|
425 file = XCAR (filepos);
|
|
426 position = XINT (XCDR (filepos));
|
|
427 if (position < 0)
|
|
428 position = - position;
|
|
429 }
|
|
430 else
|
|
431 return Qnil;
|
|
432
|
|
433 if (!STRINGP (file))
|
|
434 return Qnil;
|
|
435
|
|
436 /* Put the file name in NAME as a C string.
|
|
437 If it is relative, combine it with Vdoc_directory. */
|
|
438
|
|
439 tem = Ffile_name_absolute_p (file);
|
|
440 if (NILP (tem))
|
|
441 {
|
|
442 Bytecount minsize;
|
|
443 /* XEmacs: Move this check here. OK if called during loadup to
|
|
444 load byte code instructions. */
|
|
445 if (!STRINGP (Vdoc_directory))
|
|
446 return Qnil;
|
|
447
|
|
448 minsize = XSTRING_LENGTH (Vdoc_directory);
|
|
449 /* sizeof ("../lib-src/") == 12 */
|
|
450 if (minsize < 12)
|
|
451 minsize = 12;
|
|
452 name_nonreloc = alloca_ibytes (minsize + XSTRING_LENGTH (file) + 8);
|
|
453 string_join (name_nonreloc, Vdoc_directory, file);
|
|
454 }
|
|
455 else
|
|
456 name_reloc = file;
|
|
457
|
|
458 fd = qxe_open (name_nonreloc ? name_nonreloc :
|
|
459 XSTRING_DATA (name_reloc), O_RDONLY | OPEN_BINARY, 0);
|
|
460 if (fd < 0)
|
|
461 {
|
|
462 if (purify_flag)
|
|
463 {
|
|
464 /* sizeof ("../lib-src/") == 12 */
|
|
465 name_nonreloc = alloca_ibytes (12 + XSTRING_LENGTH (file) + 8);
|
|
466 /* Preparing to dump; DOC file is probably not installed.
|
|
467 So check in ../lib-src. */
|
|
468 qxestrcpy_ascii (name_nonreloc, "../lib-src/");
|
|
469 qxestrcat (name_nonreloc, XSTRING_DATA (file));
|
|
470
|
|
471 fd = qxe_open (name_nonreloc, O_RDONLY | OPEN_BINARY, 0);
|
|
472 }
|
|
473
|
|
474 if (fd < 0)
|
|
475 report_file_error ("Cannot open doc string file",
|
|
476 name_nonreloc ? build_intstring (name_nonreloc) :
|
|
477 name_reloc);
|
|
478 }
|
|
479
|
|
480 tem = extract_object_file_name (fd, position, name_nonreloc, name_reloc,
|
|
481 standard_doc_file);
|
|
482 retry_close (fd);
|
|
483
|
|
484 if (!STRINGP (tem))
|
|
485 signal_error_1 (Qinvalid_byte_code, tem);
|
|
486
|
|
487 return tem;
|
|
488 }
|
|
489
|
|
490
|
|
491 static void
|
|
492 weird_doc (Lisp_Object sym, const CIbyte *weirdness, const CIbyte *type,
|
|
493 int pos)
|
|
494 {
|
|
495 if (!strcmp (weirdness, GETTEXT ("duplicate"))) return;
|
|
496 message ("Note: Strange doc (%s) for %s %s @ %d",
|
|
497 weirdness, type, XSTRING_DATA (XSYMBOL (sym)->name), pos);
|
|
498 }
|
|
499
|
|
500 DEFUN ("built-in-symbol-file", Fbuilt_in_symbol_file, 1, 1, 0, /*
|
|
501 Return the C source file built-in symbol SYM comes from.
|
|
502 Don't use this. Use the more general `symbol-file' (q.v.) instead.
|
|
503 */
|
|
504 (symbol))
|
|
505 {
|
|
506 /* This function can GC */
|
|
507 Lisp_Object fun;
|
|
508 Lisp_Object filename = Qnil;
|
|
509
|
|
510 if (EQ(Ffboundp(symbol), Qt))
|
|
511 {
|
|
512 fun = Findirect_function (symbol);
|
|
513
|
|
514 if (SUBRP (fun))
|
|
515 {
|
|
516 if (XSUBR (fun)->doc == 0)
|
|
517 return Qnil;
|
|
518
|
|
519 if ((EMACS_INT) XSUBR (fun)->doc >= 0)
|
|
520 {
|
|
521 weird_doc (symbol, "No file info available for function",
|
|
522 GETTEXT("function"), 0);
|
|
523 return Qnil;
|
|
524 }
|
|
525 else
|
|
526 filename = get_object_file_name
|
|
527 (make_int (- (EMACS_INT) XSUBR (fun)->doc));
|
|
528 }
|
|
529 }
|
|
530 else if (EQ(Fboundp(symbol), Qt))
|
|
531 {
|
|
532 Lisp_Object doc_offset = Fget (symbol, Qvariable_documentation, Qnil);
|
|
533
|
|
534 if (!NILP(doc_offset))
|
|
535 {
|
|
536 if (INTP(doc_offset))
|
|
537 {
|
|
538 filename = get_object_file_name
|
|
539 (XINT (doc_offset) > 0 ? doc_offset
|
|
540 : make_int (- XINT (doc_offset)));
|
|
541 }
|
|
542 else if (CONSP(doc_offset))
|
|
543 {
|
|
544 filename = get_object_file_name(doc_offset);
|
|
545 }
|
|
546 }
|
|
547 }
|
|
548 return filename;
|
|
549 }
|
|
550
|
428
|
551 DEFUN ("documentation", Fdocumentation, 1, 2, 0, /*
|
|
552 Return the documentation string of FUNCTION.
|
444
|
553 Unless a non-nil second argument RAW is given, the
|
428
|
554 string is passed through `substitute-command-keys'.
|
|
555 */
|
|
556 (function, raw))
|
|
557 {
|
|
558 /* This function can GC */
|
|
559 Lisp_Object fun;
|
|
560 Lisp_Object doc;
|
|
561
|
|
562 fun = Findirect_function (function);
|
|
563
|
|
564 if (SUBRP (fun))
|
|
565 {
|
|
566 if (XSUBR (fun)->doc == 0)
|
|
567 return Qnil;
|
|
568 if ((EMACS_INT) XSUBR (fun)->doc >= 0)
|
|
569 doc = build_string (XSUBR (fun)->doc);
|
|
570 else
|
|
571 doc = get_doc_string (make_int (- (EMACS_INT) XSUBR (fun)->doc));
|
|
572 }
|
|
573 else if (COMPILED_FUNCTIONP (fun))
|
|
574 {
|
|
575 Lisp_Object tem;
|
440
|
576 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (fun);
|
428
|
577 if (! (f->flags.documentationp))
|
|
578 return Qnil;
|
|
579 tem = compiled_function_documentation (f);
|
|
580 if (STRINGP (tem))
|
|
581 doc = tem;
|
|
582 else if (NATNUMP (tem) || CONSP (tem))
|
|
583 doc = get_doc_string (tem);
|
|
584 else
|
|
585 return Qnil;
|
|
586 }
|
|
587 else if (KEYMAPP (fun))
|
771
|
588 return build_msg_string ("Prefix command (definition is a keymap of subcommands).");
|
428
|
589 else if (STRINGP (fun) || VECTORP (fun))
|
771
|
590 return build_msg_string ("Keyboard macro.");
|
428
|
591 else if (CONSP (fun))
|
|
592 {
|
|
593 Lisp_Object funcar = Fcar (fun);
|
|
594
|
|
595 if (!SYMBOLP (funcar))
|
|
596 return Fsignal (Qinvalid_function, list1 (fun));
|
|
597 else if (EQ (funcar, Qlambda)
|
|
598 || EQ (funcar, Qautoload))
|
|
599 {
|
|
600 Lisp_Object tem, tem1;
|
|
601 tem1 = Fcdr (Fcdr (fun));
|
|
602 tem = Fcar (tem1);
|
|
603 if (STRINGP (tem))
|
|
604 doc = tem;
|
|
605 /* Handle a doc reference--but these never come last
|
|
606 in the function body, so reject them if they are last. */
|
|
607 else if ((NATNUMP (tem) || CONSP (tem))
|
|
608 && ! NILP (XCDR (tem1)))
|
|
609 doc = get_doc_string (tem);
|
|
610 else
|
|
611 return Qnil;
|
|
612 }
|
|
613 else if (EQ (funcar, Qmacro))
|
|
614 return Fdocumentation (Fcdr (fun), raw);
|
|
615 else
|
|
616 goto oops;
|
|
617 }
|
|
618 else
|
|
619 {
|
|
620 oops:
|
|
621 return Fsignal (Qinvalid_function, list1 (fun));
|
|
622 }
|
|
623
|
|
624 if (NILP (raw))
|
|
625 {
|
|
626 struct gcpro gcpro1;
|
|
627 #ifdef I18N3
|
|
628 Lisp_Object domain = Qnil;
|
|
629 if (COMPILED_FUNCTIONP (fun))
|
|
630 domain = compiled_function_domain (XCOMPILED_FUNCTION (fun));
|
|
631 if (NILP (domain))
|
|
632 doc = Fgettext (doc);
|
|
633 else
|
|
634 doc = Fdgettext (domain, doc);
|
|
635 #endif
|
|
636
|
|
637 GCPRO1 (doc);
|
|
638 doc = Fsubstitute_command_keys (doc);
|
|
639 UNGCPRO;
|
|
640 }
|
|
641 return doc;
|
|
642 }
|
|
643
|
|
644 DEFUN ("documentation-property", Fdocumentation_property, 2, 3, 0, /*
|
|
645 Return the documentation string that is SYMBOL's PROP property.
|
|
646 This is like `get', but it can refer to strings stored in the
|
|
647 `doc-directory/DOC' file; and if the value is a string, it is passed
|
|
648 through `substitute-command-keys'. A non-nil third argument avoids this
|
|
649 translation.
|
|
650 */
|
444
|
651 (symbol, prop, raw))
|
428
|
652 {
|
|
653 /* This function can GC */
|
1849
|
654 Lisp_Object doc = Qnil;
|
428
|
655 #ifdef I18N3
|
|
656 REGISTER Lisp_Object domain;
|
|
657 #endif
|
|
658 struct gcpro gcpro1;
|
|
659
|
|
660 GCPRO1 (doc);
|
|
661
|
444
|
662 doc = Fget (symbol, prop, Qnil);
|
428
|
663 if (INTP (doc))
|
|
664 doc = get_doc_string (XINT (doc) > 0 ? doc : make_int (- XINT (doc)));
|
|
665 else if (CONSP (doc))
|
|
666 doc = get_doc_string (doc);
|
|
667 #ifdef I18N3
|
|
668 if (!NILP (doc))
|
|
669 {
|
444
|
670 domain = Fget (symbol, Qvariable_domain, Qnil);
|
428
|
671 if (NILP (domain))
|
|
672 doc = Fgettext (doc);
|
|
673 else
|
|
674 doc = Fdgettext (domain, doc);
|
|
675 }
|
|
676 #endif
|
|
677 if (NILP (raw) && STRINGP (doc))
|
|
678 doc = Fsubstitute_command_keys (doc);
|
|
679 UNGCPRO;
|
|
680 return doc;
|
|
681 }
|
|
682
|
|
683
|
|
684 DEFUN ("Snarf-documentation", Fsnarf_documentation, 1, 1, 0, /*
|
|
685 Used during Emacs initialization, before dumping runnable Emacs,
|
|
686 to find pointers to doc strings stored in `.../lib-src/DOC' and
|
|
687 record them in function definitions.
|
|
688 One arg, FILENAME, a string which does not include a directory.
|
|
689 The file is written to `../lib-src', and later found in `exec-directory'
|
|
690 when doc strings are referred to in the dumped Emacs.
|
|
691 */
|
|
692 (filename))
|
|
693 {
|
|
694 int fd;
|
867
|
695 Ibyte buf[1024 + 1];
|
428
|
696 REGISTER int filled;
|
|
697 REGISTER int pos;
|
867
|
698 REGISTER Ibyte *p, *end;
|
428
|
699 Lisp_Object sym, fun, tem;
|
867
|
700 Ibyte *name;
|
428
|
701
|
814
|
702 /* This function should not pass the data it's reading through a coding
|
|
703 stream. The reason is that the only purpose of this function is to
|
|
704 find the file offsets for the documentation of the various functions,
|
|
705 not do anything with the documentation itself. If we pass through a
|
|
706 coding stream, the pointers will get messed up when we start reading
|
|
707 ISO 2022 data because our pointers will reflect internal format, not
|
|
708 external format. */
|
|
709
|
428
|
710 if (!purify_flag)
|
563
|
711 invalid_operation ("Snarf-documentation can only be called in an undumped Emacs", Qunbound);
|
428
|
712
|
|
713 CHECK_STRING (filename);
|
|
714
|
1330
|
715 {
|
|
716 name = alloca_ibytes (XSTRING_LENGTH (filename) + 14);
|
2367
|
717 qxestrcpy_ascii (name, "../lib-src/");
|
1330
|
718 }
|
428
|
719
|
771
|
720 qxestrcat (name, XSTRING_DATA (filename));
|
428
|
721
|
771
|
722 fd = qxe_open (name, O_RDONLY | OPEN_BINARY, 0);
|
428
|
723 if (fd < 0)
|
771
|
724 report_file_error ("Opening doc string file", build_intstring (name));
|
428
|
725 Vinternal_doc_file_name = filename;
|
|
726 filled = 0;
|
|
727 pos = 0;
|
|
728 while (1)
|
|
729 {
|
|
730 if (filled < 512)
|
771
|
731 filled += retry_read (fd, &buf[filled], sizeof (buf) - 1 - filled);
|
428
|
732 if (!filled)
|
|
733 break;
|
|
734
|
|
735 buf[filled] = 0;
|
|
736 p = buf;
|
|
737 end = buf + (filled < 512 ? filled : filled - 128);
|
|
738 while (p != end && *p != '\037') p++;
|
|
739 /* p points to ^_Ffunctionname\n or ^_Vvarname\n. */
|
|
740 if (p != end)
|
|
741 {
|
771
|
742 end = qxestrchr (p, '\n');
|
|
743 sym = oblookup (Vobarray, p + 2, end - p - 2);
|
428
|
744 if (SYMBOLP (sym))
|
|
745 {
|
|
746 Lisp_Object offset = make_int (pos + end + 1 - buf);
|
|
747 /* Attach a docstring to a variable */
|
|
748 if (p[1] == 'V')
|
|
749 {
|
|
750 /* Install file-position as variable-documentation property
|
|
751 and make it negative for a user-variable
|
|
752 (doc starts with a `*'). */
|
|
753 Lisp_Object old = Fget (sym, Qvariable_documentation, Qzero);
|
|
754 if (!ZEROP (old))
|
|
755 {
|
|
756 weird_doc (sym, GETTEXT ("duplicate"),
|
|
757 GETTEXT ("variable"), pos);
|
|
758 /* In the case of duplicate doc file entries, always
|
|
759 take the later one. But if the doc is not an int
|
|
760 (a string, say) leave it alone. */
|
|
761 if (!INTP (old))
|
|
762 goto weird;
|
|
763 }
|
|
764 Fput (sym, Qvariable_documentation,
|
|
765 ((end[1] == '*')
|
|
766 ? make_int (- XINT (offset))
|
|
767 : offset));
|
|
768 }
|
|
769 /* Attach a docstring to a function.
|
|
770 The type determines where the docstring is stored. */
|
|
771 else if (p[1] == 'F')
|
|
772 {
|
|
773 fun = indirect_function (sym,0);
|
|
774
|
|
775 if (CONSP (fun) && EQ (XCAR (fun), Qmacro))
|
|
776 fun = XCDR (fun);
|
|
777
|
|
778 if (UNBOUNDP (fun))
|
|
779 {
|
771
|
780 #if 0 /* There are lots of legitimate cases where this message will appear
|
|
781 (e.g. any function that's only defined when MULE is defined,
|
|
782 provided that the function is used somewhere in a dumped Lisp
|
|
783 file, so that the symbol is interned in the dumped XEmacs), and
|
|
784 there's not a lot that can be done to eliminate the warning other
|
|
785 than kludges like moving the function to a Mule-only source file,
|
|
786 which often results in ugly code. Furthermore, the only point of
|
|
787 this warning is to warn you when you have a DEFUN that you forget
|
|
788 to DEFSUBR, but the compiler will also warn you, because the DEFUN
|
|
789 declares a static object, and the object will be unused -- you'll
|
|
790 get something like
|
|
791
|
|
792 /src/xemacs/mule/src/abbrev.c:269: warning: `SFexpand_abbrev' defined but not used
|
|
793
|
|
794 So I'm disabling this. --ben */
|
|
795
|
428
|
796 /* May have been #if'ed out or something */
|
|
797 weird_doc (sym, GETTEXT ("not fboundp"),
|
|
798 GETTEXT ("function"), pos);
|
771
|
799 #endif
|
428
|
800 goto weird;
|
|
801 }
|
|
802 else if (SUBRP (fun))
|
|
803 {
|
|
804 /* Lisp_Subrs have a slot for it. */
|
|
805 if (XSUBR (fun)->doc)
|
|
806 {
|
|
807 weird_doc (sym, GETTEXT ("duplicate"),
|
|
808 GETTEXT ("subr"), pos);
|
|
809 goto weird;
|
|
810 }
|
|
811 XSUBR (fun)->doc = (char *) (- XINT (offset));
|
|
812 }
|
|
813 else if (CONSP (fun))
|
|
814 {
|
|
815 /* If it's a lisp form, stick it in the form. */
|
|
816 tem = XCAR (fun);
|
|
817 if (EQ (tem, Qlambda) || EQ (tem, Qautoload))
|
|
818 {
|
|
819 tem = Fcdr (Fcdr (fun));
|
|
820 if (CONSP (tem) &&
|
|
821 INTP (XCAR (tem)))
|
|
822 {
|
|
823 Lisp_Object old = XCAR (tem);
|
|
824 if (!ZEROP (old))
|
|
825 {
|
|
826 weird_doc (sym, GETTEXT ("duplicate"),
|
|
827 (EQ (tem, Qlambda)
|
|
828 ? GETTEXT ("lambda")
|
|
829 : GETTEXT ("autoload")),
|
|
830 pos);
|
|
831 /* In the case of duplicate doc file entries,
|
|
832 always take the later one. But if the doc
|
|
833 is not an int (a string, say) leave it
|
|
834 alone. */
|
|
835 if (!INTP (old))
|
|
836 goto weird;
|
|
837 }
|
|
838 XCAR (tem) = offset;
|
|
839 }
|
|
840 else if (!CONSP (tem))
|
|
841 {
|
|
842 weird_doc (sym, GETTEXT ("!CONSP(tem)"),
|
|
843 GETTEXT ("function"), pos);
|
|
844 goto cont;
|
|
845 }
|
|
846 else
|
|
847 {
|
|
848 /* DOC string is a string not integer 0 */
|
|
849 #if 0
|
|
850 weird_doc (sym, GETTEXT ("!INTP(XCAR(tem))"),
|
|
851 GETTEXT ("function"), pos);
|
|
852 #endif
|
|
853 goto cont;
|
|
854 }
|
|
855 }
|
|
856 else
|
|
857 {
|
|
858 weird_doc (sym, GETTEXT ("not lambda or autoload"),
|
|
859 GETTEXT ("function"), pos);
|
|
860 goto cont;
|
|
861 }
|
|
862 }
|
|
863 else if (COMPILED_FUNCTIONP (fun))
|
|
864 {
|
|
865 /* Compiled-Function objects sometimes have
|
|
866 slots for it. */
|
440
|
867 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (fun);
|
428
|
868
|
|
869 /* This compiled-function object must have a
|
|
870 slot for the docstring, since we've found a
|
|
871 docstring for it. Unless there were multiple
|
|
872 definitions of it, and the latter one didn't
|
|
873 have any doc, which is a legal if slightly
|
|
874 bogus situation, so don't blow up. */
|
|
875
|
|
876 if (! (f->flags.documentationp))
|
|
877 {
|
|
878 weird_doc (sym, GETTEXT ("no doc slot"),
|
|
879 GETTEXT ("bytecode"), pos);
|
|
880 goto weird;
|
|
881 }
|
|
882 else
|
|
883 {
|
|
884 Lisp_Object old =
|
|
885 compiled_function_documentation (f);
|
|
886 if (!ZEROP (old))
|
|
887 {
|
|
888 weird_doc (sym, GETTEXT ("duplicate"),
|
|
889 GETTEXT ("bytecode"), pos);
|
|
890 /* In the case of duplicate doc file entries,
|
|
891 always take the later one. But if the doc is
|
|
892 not an int (a string, say) leave it alone. */
|
|
893 if (!INTP (old))
|
|
894 goto weird;
|
|
895 }
|
|
896 set_compiled_function_documentation (f, offset);
|
|
897 }
|
|
898 }
|
|
899 else
|
|
900 {
|
|
901 /* Otherwise the function is undefined or
|
|
902 otherwise weird. Ignore it. */
|
|
903 weird_doc (sym, GETTEXT ("weird function"),
|
|
904 GETTEXT ("function"), pos);
|
|
905 goto weird;
|
|
906 }
|
|
907 }
|
|
908 else
|
|
909 {
|
|
910 /* lose: */
|
771
|
911 signal_error (Qfile_error, "DOC file invalid at position",
|
|
912 make_int (pos));
|
428
|
913 weird:
|
|
914 /* goto lose */;
|
|
915 }
|
|
916 }
|
|
917 }
|
|
918 cont:
|
|
919 pos += end - buf;
|
|
920 filled -= end - buf;
|
|
921 memmove (buf, end, filled);
|
|
922 }
|
771
|
923 retry_close (fd);
|
428
|
924 return Qnil;
|
|
925 }
|
|
926
|
|
927 #if 1 /* Don't warn about functions whose doc was lost because they were
|
|
928 wrapped by advice-freeze.el... */
|
|
929 static int
|
|
930 kludgily_ignore_lost_doc_p (Lisp_Object sym)
|
|
931 {
|
|
932 # define kludge_prefix "ad-Orig-"
|
793
|
933 Lisp_Object name = XSYMBOL (sym)->name;
|
|
934 return (XSTRING_LENGTH (name) > (Bytecount) (sizeof (kludge_prefix)) &&
|
2367
|
935 !qxestrncmp_ascii (XSTRING_DATA (name), kludge_prefix,
|
793
|
936 sizeof (kludge_prefix) - 1));
|
428
|
937 # undef kludge_prefix
|
|
938 }
|
|
939 #else
|
|
940 # define kludgily_ignore_lost_doc_p(sym) 0
|
|
941 #endif
|
|
942
|
|
943
|
|
944 static int
|
|
945 verify_doc_mapper (Lisp_Object sym, void *arg)
|
|
946 {
|
793
|
947 Lisp_Object closure = * (Lisp_Object *) arg;
|
428
|
948
|
|
949 if (!NILP (Ffboundp (sym)))
|
|
950 {
|
|
951 int doc = 0;
|
|
952 Lisp_Object fun = XSYMBOL (sym)->function;
|
|
953 if (CONSP (fun) &&
|
|
954 EQ (XCAR (fun), Qmacro))
|
|
955 fun = XCDR (fun);
|
|
956
|
|
957 if (SUBRP (fun))
|
|
958 doc = (EMACS_INT) XSUBR (fun)->doc;
|
|
959 else if (SYMBOLP (fun))
|
|
960 doc = -1;
|
|
961 else if (KEYMAPP (fun))
|
|
962 doc = -1;
|
|
963 else if (CONSP (fun))
|
|
964 {
|
|
965 Lisp_Object tem = XCAR (fun);
|
|
966 if (EQ (tem, Qlambda) || EQ (tem, Qautoload))
|
|
967 {
|
|
968 doc = -1;
|
|
969 tem = Fcdr (Fcdr (fun));
|
|
970 if (CONSP (tem) &&
|
|
971 INTP (XCAR (tem)))
|
|
972 doc = XINT (XCAR (tem));
|
|
973 }
|
|
974 }
|
|
975 else if (COMPILED_FUNCTIONP (fun))
|
|
976 {
|
440
|
977 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (fun);
|
428
|
978 if (! (f->flags.documentationp))
|
|
979 doc = -1;
|
|
980 else
|
|
981 {
|
|
982 Lisp_Object tem = compiled_function_documentation (f);
|
|
983 if (INTP (tem))
|
|
984 doc = XINT (tem);
|
|
985 }
|
|
986 }
|
|
987
|
|
988 if (doc == 0 && !kludgily_ignore_lost_doc_p (sym))
|
|
989 {
|
|
990 message ("Warning: doc lost for function %s.",
|
793
|
991 XSTRING_DATA (XSYMBOL (sym)->name));
|
428
|
992 XCDR (closure) = Qt;
|
|
993 }
|
|
994 }
|
|
995 if (!NILP (Fboundp (sym)))
|
|
996 {
|
|
997 Lisp_Object doc = Fget (sym, Qvariable_documentation, Qnil);
|
|
998 if (ZEROP (doc))
|
|
999 {
|
|
1000 message ("Warning: doc lost for variable %s.",
|
793
|
1001 XSTRING_DATA (XSYMBOL (sym)->name));
|
428
|
1002 XCDR (closure) = Qt;
|
|
1003 }
|
|
1004 }
|
|
1005 return 0; /* Never stop */
|
|
1006 }
|
|
1007
|
|
1008 DEFUN ("Verify-documentation", Fverify_documentation, 0, 0, 0, /*
|
|
1009 Used to make sure everything went well with Snarf-documentation.
|
|
1010 Writes to stderr if not.
|
|
1011 */
|
|
1012 ())
|
|
1013 {
|
|
1014 Lisp_Object closure = Fcons (Qnil, Qnil);
|
|
1015 struct gcpro gcpro1;
|
|
1016 GCPRO1 (closure);
|
|
1017 map_obarray (Vobarray, verify_doc_mapper, &closure);
|
|
1018 if (!NILP (Fcdr (closure)))
|
|
1019 message ("\n"
|
|
1020 "This is usually because some files were preloaded by loaddefs.el or\n"
|
|
1021 "site-load.el, but were not passed to make-docfile by Makefile.\n");
|
|
1022 UNGCPRO;
|
|
1023 return NILP (Fcdr (closure)) ? Qt : Qnil;
|
|
1024 }
|
|
1025
|
|
1026
|
|
1027 DEFUN ("substitute-command-keys", Fsubstitute_command_keys, 1, 1, 0, /*
|
|
1028 Substitute key descriptions for command names in STRING.
|
|
1029 Return a new string which is STRING with substrings of the form \\=\\[COMMAND]
|
|
1030 replaced by either: a keystroke sequence that will invoke COMMAND,
|
|
1031 or "M-x COMMAND" if COMMAND is not on any keys.
|
|
1032 Substrings of the form \\=\\{MAPVAR} are replaced by summaries
|
444
|
1033 \(made by `describe-bindings') of the value of MAPVAR, taken as a keymap.
|
428
|
1034 Substrings of the form \\=\\<MAPVAR> specify to use the value of MAPVAR
|
|
1035 as the keymap for future \\=\\[COMMAND] substrings.
|
|
1036 \\=\\= quotes the following character and is discarded;
|
|
1037 thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ into the output.
|
|
1038 */
|
444
|
1039 (string))
|
428
|
1040 {
|
|
1041 /* This function can GC */
|
867
|
1042 Ibyte *buf;
|
428
|
1043 int changed = 0;
|
867
|
1044 REGISTER Ibyte *strdata;
|
|
1045 REGISTER Ibyte *bufp;
|
428
|
1046 Bytecount strlength;
|
|
1047 Bytecount idx;
|
|
1048 Bytecount bsize;
|
3025
|
1049 Ibyte *new_;
|
444
|
1050 Lisp_Object tem = Qnil;
|
|
1051 Lisp_Object keymap = Qnil;
|
|
1052 Lisp_Object name = Qnil;
|
867
|
1053 Ibyte *start;
|
428
|
1054 Bytecount length;
|
|
1055 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
1056
|
444
|
1057 if (NILP (string))
|
428
|
1058 return Qnil;
|
|
1059
|
444
|
1060 CHECK_STRING (string);
|
|
1061 GCPRO4 (string, tem, keymap, name);
|
428
|
1062
|
|
1063 /* There is the possibility that the string is not destined for a
|
|
1064 translating stream, and it could be argued that we should do the
|
|
1065 same thing here as in Fformat(), but there are very few times
|
|
1066 when this will be the case and many calls to this function
|
|
1067 would have to have `gettext' calls added. (I18N3) */
|
444
|
1068 string = LISP_GETTEXT (string);
|
428
|
1069
|
|
1070 /* KEYMAP is either nil (which means search all the active keymaps)
|
|
1071 or a specified local map (which means search just that and the
|
|
1072 global map). If non-nil, it might come from Voverriding_local_map,
|
444
|
1073 or from a \\<mapname> construct in STRING itself.. */
|
428
|
1074 #if 0 /* FSFmacs */
|
|
1075 /* This is really weird and garbagey. If keymap is nil and there's
|
|
1076 an overriding-local-map, `where-is-internal' will correctly note
|
|
1077 this, so there's no reason to do it here. Maybe FSFmacs
|
|
1078 `where-is-internal' is broken. */
|
|
1079 /*
|
|
1080 keymap = current_kboard->Voverriding_terminal_local_map;
|
|
1081 if (NILP (keymap))
|
|
1082 keymap = Voverriding_local_map;
|
|
1083 */
|
|
1084 #endif
|
|
1085
|
444
|
1086 strlength = XSTRING_LENGTH (string);
|
2367
|
1087 bsize = ITEXT_ZTERM_SIZE + strlength;
|
|
1088 buf = xnew_ibytes (bsize);
|
428
|
1089 bufp = buf;
|
|
1090
|
|
1091 /* Have to reset strdata every time GC might be called */
|
444
|
1092 strdata = XSTRING_DATA (string);
|
428
|
1093 for (idx = 0; idx < strlength; )
|
|
1094 {
|
867
|
1095 Ibyte *strp = strdata + idx;
|
428
|
1096
|
|
1097 if (strp[0] != '\\')
|
|
1098 {
|
|
1099 /* just copy other chars */
|
|
1100 /* As it happens, this will work with Mule even if the
|
|
1101 character quoted is multi-byte; the remaining multi-byte
|
|
1102 characters will just be copied by this loop. */
|
|
1103 *bufp++ = *strp;
|
|
1104 idx++;
|
|
1105 }
|
|
1106 else switch (strp[1])
|
|
1107 {
|
|
1108 default:
|
|
1109 {
|
|
1110 /* just copy unknown escape sequences */
|
|
1111 *bufp++ = *strp;
|
|
1112 idx++;
|
|
1113 break;
|
|
1114 }
|
|
1115 case '=':
|
|
1116 {
|
|
1117 /* \= quotes the next character;
|
|
1118 thus, to put in \[ without its special meaning, use \=\[. */
|
|
1119 /* As it happens, this will work with Mule even if the
|
|
1120 character quoted is multi-byte; the remaining multi-byte
|
|
1121 characters will just be copied by this loop. */
|
|
1122 changed = 1;
|
|
1123 *bufp++ = strp[2];
|
|
1124 idx += 3;
|
|
1125 break;
|
|
1126 }
|
|
1127 case '[':
|
|
1128 {
|
|
1129 changed = 1;
|
|
1130 idx += 2; /* skip \[ */
|
|
1131 strp += 2;
|
|
1132 start = strp;
|
|
1133
|
|
1134 while ((idx < strlength)
|
|
1135 && *strp != ']')
|
|
1136 {
|
|
1137 strp++;
|
|
1138 idx++;
|
|
1139 }
|
|
1140 length = strp - start;
|
|
1141 idx++; /* skip ] */
|
|
1142
|
|
1143 tem = Fintern (make_string (start, length), Qnil);
|
|
1144 tem = Fwhere_is_internal (tem, keymap, Qt, Qnil, Qnil);
|
|
1145
|
|
1146 #if 0 /* FSFmacs */
|
444
|
1147 /* Disregard menu bar bindings; it is positively annoying to
|
|
1148 mention them when there's no menu bar, and it isn't terribly
|
|
1149 useful even when there is a menu bar. */
|
|
1150 if (!NILP (tem))
|
|
1151 {
|
|
1152 firstkey = Faref (tem, Qzero);
|
|
1153 if (EQ (firstkey, Qmenu_bar))
|
|
1154 tem = Qnil;
|
|
1155 }
|
428
|
1156 #endif
|
|
1157
|
|
1158 if (NILP (tem)) /* but not on any keys */
|
|
1159 {
|
3025
|
1160 new_ = (Ibyte *) xrealloc (buf, bsize += 4);
|
|
1161 bufp += new_ - buf;
|
|
1162 buf = new_;
|
428
|
1163 memcpy (bufp, "M-x ", 4);
|
|
1164 bufp += 4;
|
|
1165 goto subst;
|
|
1166 }
|
|
1167 else
|
|
1168 { /* function is on a key */
|
|
1169 tem = Fkey_description (tem);
|
|
1170 goto subst_string;
|
|
1171 }
|
|
1172 }
|
|
1173 case '{':
|
|
1174 case '<':
|
|
1175 {
|
444
|
1176 Lisp_Object buffer = Fget_buffer_create (QSsubstitute);
|
|
1177 struct buffer *buf_ = XBUFFER (buffer);
|
428
|
1178
|
|
1179 Fbuffer_disable_undo (buffer);
|
|
1180 Ferase_buffer (buffer);
|
|
1181
|
|
1182 /* \{foo} is replaced with a summary of keymap (symbol-value foo).
|
|
1183 \<foo> just sets the keymap used for \[cmd]. */
|
|
1184 changed = 1;
|
|
1185 idx += 2; /* skip \{ or \< */
|
|
1186 strp += 2;
|
|
1187 start = strp;
|
|
1188
|
|
1189 while ((idx < strlength)
|
|
1190 && *strp != '}' && *strp != '>')
|
|
1191 {
|
|
1192 strp++;
|
|
1193 idx++;
|
|
1194 }
|
|
1195 length = strp - start;
|
|
1196 idx++; /* skip } or > */
|
|
1197
|
|
1198 /* Get the value of the keymap in TEM, or nil if undefined.
|
|
1199 Do this while still in the user's current buffer
|
|
1200 in case it is a local variable. */
|
|
1201 name = Fintern (make_string (start, length), Qnil);
|
|
1202 tem = Fboundp (name);
|
|
1203 if (! NILP (tem))
|
|
1204 {
|
|
1205 tem = Fsymbol_value (name);
|
|
1206 if (! NILP (tem))
|
|
1207 tem = get_keymap (tem, 0, 1);
|
|
1208 }
|
|
1209
|
|
1210 if (NILP (tem))
|
|
1211 {
|
444
|
1212 buffer_insert_c_string (buf_, "(uses keymap \"");
|
|
1213 buffer_insert_lisp_string (buf_, Fsymbol_name (name));
|
|
1214 buffer_insert_c_string (buf_, "\", which is not currently defined) ");
|
428
|
1215
|
|
1216 if (start[-1] == '<') keymap = Qnil;
|
|
1217 }
|
|
1218 else if (start[-1] == '<')
|
|
1219 keymap = tem;
|
|
1220 else
|
|
1221 describe_map_tree (tem, 1, Qnil, Qnil, 0, buffer);
|
|
1222
|
|
1223 tem = make_string_from_buffer (buf_, BUF_BEG (buf_),
|
|
1224 BUF_Z (buf_) - BUF_BEG (buf_));
|
|
1225 Ferase_buffer (buffer);
|
444
|
1226 }
|
|
1227 goto subst_string;
|
428
|
1228
|
444
|
1229 subst_string:
|
|
1230 start = XSTRING_DATA (tem);
|
|
1231 length = XSTRING_LENGTH (tem);
|
|
1232 subst:
|
|
1233 bsize += length;
|
3025
|
1234 new_ = (Ibyte *) xrealloc (buf, bsize);
|
|
1235 bufp += new_ - buf;
|
|
1236 buf = new_;
|
444
|
1237 memcpy (bufp, start, length);
|
|
1238 bufp += length;
|
428
|
1239
|
444
|
1240 /* Reset STRDATA in case gc relocated it. */
|
|
1241 strdata = XSTRING_DATA (string);
|
428
|
1242
|
444
|
1243 break;
|
428
|
1244 }
|
|
1245 }
|
|
1246
|
|
1247 if (changed) /* don't bother if nothing substituted */
|
|
1248 tem = make_string (buf, bufp - buf);
|
|
1249 else
|
444
|
1250 tem = string;
|
1726
|
1251 xfree (buf, Ibyte *);
|
428
|
1252 UNGCPRO;
|
|
1253 return tem;
|
|
1254 }
|
|
1255
|
|
1256
|
|
1257 /************************************************************************/
|
|
1258 /* initialization */
|
|
1259 /************************************************************************/
|
|
1260
|
|
1261 void
|
|
1262 syms_of_doc (void)
|
|
1263 {
|
3368
|
1264 DEFSUBR (Fbuilt_in_symbol_file);
|
428
|
1265 DEFSUBR (Fdocumentation);
|
|
1266 DEFSUBR (Fdocumentation_property);
|
|
1267 DEFSUBR (Fsnarf_documentation);
|
|
1268 DEFSUBR (Fverify_documentation);
|
|
1269 DEFSUBR (Fsubstitute_command_keys);
|
|
1270 }
|
|
1271
|
|
1272 void
|
|
1273 vars_of_doc (void)
|
|
1274 {
|
|
1275 DEFVAR_LISP ("internal-doc-file-name", &Vinternal_doc_file_name /*
|
|
1276 Name of file containing documentation strings of built-in symbols.
|
|
1277 */ );
|
|
1278 Vinternal_doc_file_name = Qnil;
|
|
1279
|
|
1280 QSsubstitute = build_string (" *substitute*");
|
|
1281 staticpro (&QSsubstitute);
|
|
1282 }
|