Mercurial > emacs
annotate src/doc.c @ 9024:d8000a9e6003
(PURESIZE): Definition deleted.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 23 Sep 1994 18:35:32 +0000 |
parents | fdb7ba55f05c |
children | e3c272c7f4d2 |
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 |
297 | 46 Lisp_Object |
47 get_doc_string (filepos) | |
48 long filepos; | |
49 { | |
50 char buf[512 * 32 + 1]; | |
51 register int fd; | |
52 register char *name; | |
53 register char *p, *p1; | |
54 register int count; | |
55 extern char *index (); | |
56 | |
6030
8b3f54fb451f
(get_doc_string, Snarf_documentation): Use new variable doc_directory.
Karl Heuer <kwzh@gnu.org>
parents:
5784
diff
changeset
|
57 if (XTYPE (Vdoc_directory) != Lisp_String |
297 | 58 || XTYPE (Vdoc_file_name) != Lisp_String) |
59 return Qnil; | |
60 | |
6030
8b3f54fb451f
(get_doc_string, Snarf_documentation): Use new variable doc_directory.
Karl Heuer <kwzh@gnu.org>
parents:
5784
diff
changeset
|
61 name = (char *) alloca (XSTRING (Vdoc_directory)->size |
297 | 62 + XSTRING (Vdoc_file_name)->size + 8); |
6030
8b3f54fb451f
(get_doc_string, Snarf_documentation): Use new variable doc_directory.
Karl Heuer <kwzh@gnu.org>
parents:
5784
diff
changeset
|
63 strcpy (name, XSTRING (Vdoc_directory)->data); |
297 | 64 strcat (name, XSTRING (Vdoc_file_name)->data); |
65 #ifdef VMS | |
66 #ifndef VMS4_4 | |
67 /* For VMS versions with limited file name syntax, | |
68 convert the name to something VMS will allow. */ | |
69 p = name; | |
70 while (*p) | |
71 { | |
72 if (*p == '-') | |
73 *p = '_'; | |
74 p++; | |
75 } | |
76 #endif /* not VMS4_4 */ | |
77 #ifdef VMS4_4 | |
78 strcpy (name, sys_translate_unix (name)); | |
79 #endif /* VMS4_4 */ | |
80 #endif /* VMS */ | |
81 | |
82 fd = open (name, O_RDONLY, 0); | |
83 if (fd < 0) | |
84 error ("Cannot open doc string file \"%s\"", name); | |
85 if (0 > lseek (fd, filepos, 0)) | |
86 { | |
87 close (fd); | |
88 error ("Position %ld out of range in doc string file \"%s\"", | |
89 filepos, name); | |
90 } | |
91 p = buf; | |
92 while (p != buf + sizeof buf - 1) | |
93 { | |
94 count = read (fd, p, 512); | |
95 p[count] = 0; | |
96 if (!count) | |
97 break; | |
98 p1 = index (p, '\037'); | |
99 if (p1) | |
100 { | |
101 *p1 = 0; | |
102 p = p1; | |
103 break; | |
104 } | |
105 p += count; | |
106 } | |
107 close (fd); | |
108 return make_string (buf, p - buf); | |
109 } | |
110 | |
570 | 111 DEFUN ("documentation", Fdocumentation, Sdocumentation, 1, 2, 0, |
604 | 112 "Return the documentation string of FUNCTION.\n\ |
113 Unless a non-nil second argument is given, the\n\ | |
570 | 114 string is passed through `substitute-command-keys'.") |
647 | 115 (function, raw) |
116 Lisp_Object function, raw; | |
297 | 117 { |
118 Lisp_Object fun; | |
119 Lisp_Object funcar; | |
570 | 120 Lisp_Object tem, doc; |
297 | 121 |
647 | 122 fun = Findirect_function (function); |
297 | 123 |
124 switch (XTYPE (fun)) | |
125 { | |
126 case Lisp_Subr: | |
127 if (XSUBR (fun)->doc == 0) return Qnil; | |
8823
fdb7ba55f05c
(Fdocumentation): Use EMACS_INT.
Richard M. Stallman <rms@gnu.org>
parents:
8552
diff
changeset
|
128 if ((EMACS_INT) XSUBR (fun)->doc >= 0) |
570 | 129 doc = build_string (XSUBR (fun)->doc); |
297 | 130 else |
8823
fdb7ba55f05c
(Fdocumentation): Use EMACS_INT.
Richard M. Stallman <rms@gnu.org>
parents:
8552
diff
changeset
|
131 doc = get_doc_string (- (EMACS_INT) XSUBR (fun)->doc); |
570 | 132 break; |
297 | 133 |
134 case Lisp_Compiled: | |
135 if (XVECTOR (fun)->size <= COMPILED_DOC_STRING) | |
136 return Qnil; | |
137 tem = XVECTOR (fun)->contents[COMPILED_DOC_STRING]; | |
138 if (XTYPE (tem) == Lisp_String) | |
570 | 139 doc = tem; |
140 else if (XTYPE (tem) == Lisp_Int && XINT (tem) >= 0) | |
141 doc = get_doc_string (XFASTINT (tem)); | |
142 else | |
143 return Qnil; | |
144 break; | |
297 | 145 |
146 case Lisp_String: | |
147 case Lisp_Vector: | |
148 return build_string ("Keyboard macro."); | |
149 | |
150 case Lisp_Cons: | |
151 funcar = Fcar (fun); | |
152 if (XTYPE (funcar) != Lisp_Symbol) | |
153 return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); | |
647 | 154 else if (EQ (funcar, Qkeymap)) |
297 | 155 return build_string ("Prefix command (definition is a keymap associating keystrokes with\n\ |
156 subcommands.)"); | |
647 | 157 else if (EQ (funcar, Qlambda) |
158 || EQ (funcar, Qautoload)) | |
297 | 159 { |
160 tem = Fcar (Fcdr (Fcdr (fun))); | |
161 if (XTYPE (tem) == Lisp_String) | |
570 | 162 doc = tem; |
163 else if (XTYPE (tem) == Lisp_Int && XINT (tem) >= 0) | |
164 doc = get_doc_string (XFASTINT (tem)); | |
165 else | |
166 return Qnil; | |
647 | 167 |
168 break; | |
297 | 169 } |
647 | 170 else if (EQ (funcar, Qmocklisp)) |
297 | 171 return Qnil; |
647 | 172 else if (EQ (funcar, Qmacro)) |
570 | 173 return Fdocumentation (Fcdr (fun), raw); |
297 | 174 |
175 /* Fall through to the default to report an error. */ | |
176 | |
177 default: | |
178 return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); | |
179 } | |
570 | 180 |
577 | 181 if (NILP (raw)) |
1511
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
182 { |
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
183 struct gcpro gcpro1; |
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
184 |
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
185 GCPRO1 (doc); |
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
186 doc = Fsubstitute_command_keys (doc); |
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
187 UNGCPRO; |
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
188 } |
570 | 189 return doc; |
297 | 190 } |
191 | |
5248
27d6275810a7
(Fsubstitute_command_keys): Ignore menu bar bindings.
Richard M. Stallman <rms@gnu.org>
parents:
4716
diff
changeset
|
192 DEFUN ("documentation-property", Fdocumentation_property, Sdocumentation_property, 2, 3, 0, |
297 | 193 "Return the documentation string that is SYMBOL's PROP property.\n\ |
570 | 194 This is like `get', but it can refer to strings stored in the\n\ |
604 | 195 `etc/DOC' file; and if the value is a string, it is passed through\n\ |
577 | 196 `substitute-command-keys'. A non-nil third argument avoids this\n\ |
197 translation.") | |
570 | 198 (sym, prop, raw) |
199 Lisp_Object sym, prop, raw; | |
297 | 200 { |
201 register Lisp_Object tem; | |
202 | |
203 tem = Fget (sym, prop); | |
204 if (XTYPE (tem) == Lisp_Int) | |
205 tem = get_doc_string (XINT (tem) > 0 ? XINT (tem) : - XINT (tem)); | |
577 | 206 if (NILP (raw) && XTYPE (tem) == Lisp_String) |
312
adba7439e87c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
297
diff
changeset
|
207 return Fsubstitute_command_keys (tem); |
adba7439e87c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
297
diff
changeset
|
208 return tem; |
297 | 209 } |
210 | |
1651
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
211 /* 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
|
212 |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
213 static void |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
214 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
|
215 Lisp_Object fun; |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
216 int offset; |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
217 { |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
218 fun = indirect_function (fun); |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
219 |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
220 /* 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
|
221 |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
222 /* 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
|
223 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
|
224 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
|
225 |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
226 /* 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
|
227 else if (CONSP (fun)) |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
228 { |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
229 Lisp_Object tem; |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
230 |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
231 tem = XCONS (fun)->car; |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
232 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
|
233 { |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
234 tem = Fcdr (Fcdr (fun)); |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
235 if (CONSP (tem) && |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
236 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
|
237 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
|
238 } |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
239 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
|
240 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
|
241 } |
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 /* 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
|
244 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
|
245 { |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
246 /* 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
|
247 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
|
248 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
|
249 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
|
250 } |
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 |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
253 |
297 | 254 DEFUN ("Snarf-documentation", Fsnarf_documentation, Ssnarf_documentation, |
255 1, 1, 0, | |
256 "Used during Emacs initialization, before dumping runnable Emacs,\n\ | |
604 | 257 to find pointers to doc strings stored in `etc/DOC...' and\n\ |
297 | 258 record them in function definitions.\n\ |
259 One arg, FILENAME, a string which does not include a directory.\n\ | |
604 | 260 The file is found in `../etc' now; found in the `data-directory'\n\ |
297 | 261 when doc strings are referred to later in the dumped Emacs.") |
262 (filename) | |
263 Lisp_Object filename; | |
264 { | |
265 int fd; | |
266 char buf[1024 + 1]; | |
267 register int filled; | |
268 register int pos; | |
269 register char *p, *end; | |
270 Lisp_Object sym, fun, tem; | |
271 char *name; | |
272 extern char *index (); | |
273 | |
1116
6d0d442e2ada
* doc.c (Fsnarf_documentation): Signal an error if this is
Jim Blandy <jimb@redhat.com>
parents:
961
diff
changeset
|
274 #ifndef CANNOT_DUMP |
6d0d442e2ada
* doc.c (Fsnarf_documentation): Signal an error if this is
Jim Blandy <jimb@redhat.com>
parents:
961
diff
changeset
|
275 if (NILP (Vpurify_flag)) |
6d0d442e2ada
* doc.c (Fsnarf_documentation): Signal an error if this is
Jim Blandy <jimb@redhat.com>
parents:
961
diff
changeset
|
276 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
|
277 #endif |
6d0d442e2ada
* doc.c (Fsnarf_documentation): Signal an error if this is
Jim Blandy <jimb@redhat.com>
parents:
961
diff
changeset
|
278 |
297 | 279 CHECK_STRING (filename, 0); |
280 | |
281 #ifndef CANNOT_DUMP | |
463 | 282 name = (char *) alloca (XSTRING (filename)->size + 14); |
604 | 283 strcpy (name, "../etc/"); |
297 | 284 #else /* CANNOT_DUMP */ |
6030
8b3f54fb451f
(get_doc_string, Snarf_documentation): Use new variable doc_directory.
Karl Heuer <kwzh@gnu.org>
parents:
5784
diff
changeset
|
285 CHECK_STRING (Vdoc_directory, 0); |
297 | 286 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
|
287 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
|
288 strcpy (name, XSTRING (Vdoc_directory)->data); |
297 | 289 #endif /* CANNOT_DUMP */ |
290 strcat (name, XSTRING (filename)->data); /*** Add this line ***/ | |
291 #ifdef VMS | |
292 #ifndef VMS4_4 | |
293 /* For VMS versions with limited file name syntax, | |
294 convert the name to something VMS will allow. */ | |
295 p = name; | |
296 while (*p) | |
297 { | |
298 if (*p == '-') | |
299 *p = '_'; | |
300 p++; | |
301 } | |
302 #endif /* not VMS4_4 */ | |
303 #ifdef VMS4_4 | |
304 strcpy (name, sys_translate_unix (name)); | |
305 #endif /* VMS4_4 */ | |
306 #endif /* VMS */ | |
307 | |
308 fd = open (name, O_RDONLY, 0); | |
309 if (fd < 0) | |
310 report_file_error ("Opening doc string file", | |
311 Fcons (build_string (name), Qnil)); | |
312 Vdoc_file_name = filename; | |
313 filled = 0; | |
314 pos = 0; | |
315 while (1) | |
316 { | |
317 if (filled < 512) | |
318 filled += read (fd, &buf[filled], sizeof buf - 1 - filled); | |
319 if (!filled) | |
320 break; | |
321 | |
322 buf[filled] = 0; | |
323 p = buf; | |
324 end = buf + (filled < 512 ? filled : filled - 128); | |
325 while (p != end && *p != '\037') p++; | |
326 /* p points to ^_Ffunctionname\n or ^_Vvarname\n. */ | |
327 if (p != end) | |
328 { | |
329 end = index (p, '\n'); | |
330 sym = oblookup (Vobarray, p + 2, end - p - 2); | |
331 if (XTYPE (sym) == Lisp_Symbol) | |
332 { | |
333 /* Attach a docstring to a variable? */ | |
334 if (p[1] == 'V') | |
335 { | |
336 /* Install file-position as variable-documentation property | |
337 and make it negative for a user-variable | |
338 (doc starts with a `*'). */ | |
339 Fput (sym, Qvariable_documentation, | |
340 make_number ((pos + end + 1 - buf) | |
341 * (end[1] == '*' ? -1 : 1))); | |
342 } | |
343 | |
1651
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
344 /* Attach a docstring to a function? */ |
297 | 345 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
|
346 store_function_docstring (sym, pos + end + 1 - buf); |
297 | 347 |
1651
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
348 else |
ef09501a0a9b
* doc.c (store_function_docstring): New function, made from part
Jim Blandy <jimb@redhat.com>
parents:
1511
diff
changeset
|
349 error ("DOC file invalid at position %d", pos); |
297 | 350 } |
351 } | |
352 pos += end - buf; | |
353 filled -= end - buf; | |
354 bcopy (end, buf, filled); | |
355 } | |
356 close (fd); | |
357 return Qnil; | |
358 } | |
359 | |
360 DEFUN ("substitute-command-keys", Fsubstitute_command_keys, | |
361 Ssubstitute_command_keys, 1, 1, 0, | |
362 "Substitute key descriptions for command names in STRING.\n\ | |
363 Return a new string which is STRING with substrings of the form \\=\\[COMMAND]\n\ | |
364 replaced by either: a keystroke sequence that will invoke COMMAND,\n\ | |
365 or \"M-x COMMAND\" if COMMAND is not on any keys.\n\ | |
366 Substrings of the form \\=\\{MAPVAR} are replaced by summaries\n\ | |
367 \(made by describe-bindings) of the value of MAPVAR, taken as a keymap.\n\ | |
368 Substrings of the form \\=\\<MAPVAR> specify to use the value of MAPVAR\n\ | |
369 as the keymap for future \\=\\[COMMAND] substrings.\n\ | |
370 \\=\\= quotes the following character and is discarded;\n\ | |
371 thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ into the output.") | |
372 (str) | |
373 Lisp_Object str; | |
374 { | |
375 unsigned char *buf; | |
376 int changed = 0; | |
377 register unsigned char *strp; | |
378 register unsigned char *bufp; | |
379 int idx; | |
380 int bsize; | |
381 unsigned char *new; | |
1511
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
382 Lisp_Object tem; |
297 | 383 Lisp_Object keymap; |
384 unsigned char *start; | |
385 int length; | |
1511
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
386 Lisp_Object name; |
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
387 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
297 | 388 |
485 | 389 if (NILP (str)) |
297 | 390 return Qnil; |
391 | |
392 CHECK_STRING (str, 0); | |
1511
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
393 tem = Qnil; |
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
394 keymap = Qnil; |
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
395 name = Qnil; |
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
396 GCPRO4 (str, tem, keymap, name); |
297 | 397 |
5784
9c3be8e0d2ef
(Fsubstitute_command_keys): Pass keymap as that arg
Richard M. Stallman <rms@gnu.org>
parents:
5550
diff
changeset
|
398 /* 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
|
399 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
|
400 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
|
401 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
|
402 keymap = Voverriding_local_map; |
297 | 403 |
404 bsize = XSTRING (str)->size; | |
405 bufp = buf = (unsigned char *) xmalloc (bsize); | |
406 | |
407 strp = (unsigned char *) XSTRING (str)->data; | |
408 while (strp < (unsigned char *) XSTRING (str)->data + XSTRING (str)->size) | |
409 { | |
410 if (strp[0] == '\\' && strp[1] == '=') | |
411 { | |
412 /* \= quotes the next character; | |
413 thus, to put in \[ without its special meaning, use \=\[. */ | |
414 changed = 1; | |
415 *bufp++ = strp[2]; | |
416 strp += 3; | |
417 } | |
418 else if (strp[0] == '\\' && strp[1] == '[') | |
419 { | |
5248
27d6275810a7
(Fsubstitute_command_keys): Ignore menu bar bindings.
Richard M. Stallman <rms@gnu.org>
parents:
4716
diff
changeset
|
420 Lisp_Object firstkey; |
27d6275810a7
(Fsubstitute_command_keys): Ignore menu bar bindings.
Richard M. Stallman <rms@gnu.org>
parents:
4716
diff
changeset
|
421 |
297 | 422 changed = 1; |
423 strp += 2; /* skip \[ */ | |
424 start = strp; | |
425 | |
426 while ((strp - (unsigned char *) XSTRING (str)->data | |
427 < XSTRING (str)->size) | |
428 && *strp != ']') | |
429 strp++; | |
430 length = strp - start; | |
431 strp++; /* skip ] */ | |
432 | |
433 /* Save STRP in IDX. */ | |
434 idx = strp - (unsigned char *) XSTRING (str)->data; | |
435 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
|
436 tem = Fwhere_is_internal (tem, keymap, Qt, Qnil); |
297 | 437 |
5248
27d6275810a7
(Fsubstitute_command_keys): Ignore menu bar bindings.
Richard M. Stallman <rms@gnu.org>
parents:
4716
diff
changeset
|
438 /* 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
|
439 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
|
440 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
|
441 if (!NILP (tem)) |
7a8463c07d8f
(Fsubstitute_command_keys): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
5248
diff
changeset
|
442 { |
7a8463c07d8f
(Fsubstitute_command_keys): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
5248
diff
changeset
|
443 firstkey = Faref (tem, make_number (0)); |
7a8463c07d8f
(Fsubstitute_command_keys): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
5248
diff
changeset
|
444 if (EQ (firstkey, Qmenu_bar)) |
7a8463c07d8f
(Fsubstitute_command_keys): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
5248
diff
changeset
|
445 tem = Qnil; |
7a8463c07d8f
(Fsubstitute_command_keys): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
5248
diff
changeset
|
446 } |
5248
27d6275810a7
(Fsubstitute_command_keys): Ignore menu bar bindings.
Richard M. Stallman <rms@gnu.org>
parents:
4716
diff
changeset
|
447 |
485 | 448 if (NILP (tem)) /* but not on any keys */ |
297 | 449 { |
450 new = (unsigned char *) xrealloc (buf, bsize += 4); | |
451 bufp += new - buf; | |
452 buf = new; | |
453 bcopy ("M-x ", bufp, 4); | |
454 bufp += 4; | |
455 goto subst; | |
456 } | |
457 else | |
458 { /* function is on a key */ | |
459 tem = Fkey_description (tem); | |
460 goto subst_string; | |
461 } | |
462 } | |
463 /* \{foo} is replaced with a summary of the keymap (symbol-value foo). | |
464 \<foo> just sets the keymap used for \[cmd]. */ | |
465 else if (strp[0] == '\\' && (strp[1] == '{' || strp[1] == '<')) | |
466 { | |
467 struct buffer *oldbuf; | |
468 | |
469 changed = 1; | |
470 strp += 2; /* skip \{ or \< */ | |
471 start = strp; | |
472 | |
473 while ((strp - (unsigned char *) XSTRING (str)->data | |
474 < XSTRING (str)->size) | |
475 && *strp != '}' && *strp != '>') | |
476 strp++; | |
477 length = strp - start; | |
478 strp++; /* skip } or > */ | |
479 | |
480 /* Save STRP in IDX. */ | |
481 idx = strp - (unsigned char *) XSTRING (str)->data; | |
482 | |
483 /* Get the value of the keymap in TEM, or nil if undefined. | |
484 Do this while still in the user's current buffer | |
485 in case it is a local variable. */ | |
486 name = Fintern (make_string (start, length), Qnil); | |
487 tem = Fboundp (name); | |
485 | 488 if (! NILP (tem)) |
297 | 489 { |
490 tem = Fsymbol_value (name); | |
485 | 491 if (! NILP (tem)) |
1511
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
492 tem = get_keymap_1 (tem, 0, 1); |
297 | 493 } |
494 | |
495 /* Now switch to a temp buffer. */ | |
496 oldbuf = current_buffer; | |
497 set_buffer_internal (XBUFFER (Vprin1_to_string_buffer)); | |
498 | |
485 | 499 if (NILP (tem)) |
297 | 500 { |
501 name = Fsymbol_name (name); | |
502 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
|
503 insert_from_string (name, 0, XSTRING (name)->size, 1); |
297 | 504 insert_string ("\", which is not currently defined.\n"); |
505 if (start[-1] == '<') keymap = Qnil; | |
506 } | |
507 else if (start[-1] == '<') | |
508 keymap = tem; | |
509 else | |
5550
9e8bbed9a9b6
(Fsubstitute_command_keys): Pass new arg to describe_map_tree.
Richard M. Stallman <rms@gnu.org>
parents:
5377
diff
changeset
|
510 describe_map_tree (tem, 1, Qnil, Qnil, 0, 1); |
297 | 511 tem = Fbuffer_string (); |
512 Ferase_buffer (); | |
513 set_buffer_internal (oldbuf); | |
514 | |
515 subst_string: | |
516 start = XSTRING (tem)->data; | |
517 length = XSTRING (tem)->size; | |
518 subst: | |
519 new = (unsigned char *) xrealloc (buf, bsize += length); | |
520 bufp += new - buf; | |
521 buf = new; | |
522 bcopy (start, bufp, length); | |
523 bufp += length; | |
524 /* Check STR again in case gc relocated it. */ | |
525 strp = (unsigned char *) XSTRING (str)->data + idx; | |
526 } | |
527 else /* just copy other chars */ | |
528 *bufp++ = *strp++; | |
529 } | |
530 | |
531 if (changed) /* don't bother if nothing substituted */ | |
532 tem = make_string (buf, bufp - buf); | |
533 else | |
534 tem = str; | |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
1651
diff
changeset
|
535 xfree (buf); |
1511
ff88f962a982
* doc.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1116
diff
changeset
|
536 RETURN_UNGCPRO (tem); |
297 | 537 } |
538 | |
539 syms_of_doc () | |
540 { | |
541 DEFVAR_LISP ("internal-doc-file-name", &Vdoc_file_name, | |
542 "Name of file containing documentation strings of built-in symbols."); | |
543 Vdoc_file_name = Qnil; | |
544 | |
545 defsubr (&Sdocumentation); | |
546 defsubr (&Sdocumentation_property); | |
547 defsubr (&Ssnarf_documentation); | |
548 defsubr (&Ssubstitute_command_keys); | |
549 } |