annotate src/doc.c @ 464:4ddaee1a9029

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Fri, 20 Dec 1991 07:15:37 +0000
parents ffdbf3445088
children 8c615e453683
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
297
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /* Record indices of function doc strings stored in a file.
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2 Copyright (C) 1985, 1986 Free Software Foundation, Inc.
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 This file is part of GNU Emacs.
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 the Free Software Foundation; either version 1, or (at your option)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 any later version.
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 GNU General Public License for more details.
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 #include "config.h"
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 #include <sys/types.h>
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 #include <sys/file.h> /* Must be after sys/types.h for USG and BSD4_1*/
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 #ifdef USG5
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27 #include <fcntl.h>
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 #endif
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 #ifndef O_RDONLY
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 #define O_RDONLY 0
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 #endif
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 #undef NULL
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 #include "lisp.h"
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 #include "buffer.h"
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 Lisp_Object Vdoc_file_name;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 Lisp_Object
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 get_doc_string (filepos)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 long filepos;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 char buf[512 * 32 + 1];
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 register int fd;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 register char *name;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 register char *p, *p1;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 register int count;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 extern char *index ();
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50
463
ffdbf3445088 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 312
diff changeset
51 if (XTYPE (Vdata_directory) != Lisp_String
297
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 || XTYPE (Vdoc_file_name) != Lisp_String)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 return Qnil;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54
463
ffdbf3445088 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 312
diff changeset
55 name = (char *) alloca (XSTRING (Vdata_directory)->size
297
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 + XSTRING (Vdoc_file_name)->size + 8);
463
ffdbf3445088 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 312
diff changeset
57 strcpy (name, XSTRING (Vdata_directory)->data);
297
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 strcat (name, XSTRING (Vdoc_file_name)->data);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 #ifdef VMS
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 #ifndef VMS4_4
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 /* For VMS versions with limited file name syntax,
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 convert the name to something VMS will allow. */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 p = name;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 while (*p)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 if (*p == '-')
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 *p = '_';
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 p++;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 #endif /* not VMS4_4 */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 #ifdef VMS4_4
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 strcpy (name, sys_translate_unix (name));
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 #endif /* VMS4_4 */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 #endif /* VMS */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 fd = open (name, O_RDONLY, 0);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 if (fd < 0)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 error ("Cannot open doc string file \"%s\"", name);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 if (0 > lseek (fd, filepos, 0))
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 close (fd);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 error ("Position %ld out of range in doc string file \"%s\"",
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 filepos, name);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 p = buf;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 while (p != buf + sizeof buf - 1)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 count = read (fd, p, 512);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 p[count] = 0;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 if (!count)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 break;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 p1 = index (p, '\037');
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 if (p1)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 *p1 = 0;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 p = p1;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 break;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 p += count;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 close (fd);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 return make_string (buf, p - buf);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 DEFUN ("documentation", Fdocumentation, Sdocumentation, 1, 1, 0,
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 "Return the documentation string of FUNCTION.")
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 (fun1)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 Lisp_Object fun1;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 Lisp_Object fun;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 Lisp_Object funcar;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 Lisp_Object tem;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 fun = fun1;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 while (XTYPE (fun) == Lisp_Symbol)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 QUIT;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 fun = Fsymbol_function (fun);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 switch (XTYPE (fun))
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 case Lisp_Subr:
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 if (XSUBR (fun)->doc == 0) return Qnil;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 if ((int) XSUBR (fun)->doc >= 0)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 return Fsubstitute_command_keys (build_string (XSUBR (fun)->doc));
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 else
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 return
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 Fsubstitute_command_keys (get_doc_string (- (int) XSUBR (fun)->doc));
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 case Lisp_Compiled:
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 if (XVECTOR (fun)->size <= COMPILED_DOC_STRING)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 return Qnil;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 tem = XVECTOR (fun)->contents[COMPILED_DOC_STRING];
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 if (XTYPE (tem) == Lisp_String)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 return Fsubstitute_command_keys (tem);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 if (XTYPE (tem) == Lisp_Int && XINT (tem) >= 0)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 return Fsubstitute_command_keys (get_doc_string (XFASTINT (tem)));
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 return Qnil;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 case Lisp_String:
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 case Lisp_Vector:
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 return build_string ("Keyboard macro.");
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 case Lisp_Cons:
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 funcar = Fcar (fun);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 if (XTYPE (funcar) != Lisp_Symbol)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 if (XSYMBOL (funcar) == XSYMBOL (Qkeymap))
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 return build_string ("Prefix command (definition is a keymap associating keystrokes with\n\
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 subcommands.)");
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 if (XSYMBOL (funcar) == XSYMBOL (Qlambda)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 || XSYMBOL (funcar) == XSYMBOL (Qautoload))
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 tem = Fcar (Fcdr (Fcdr (fun)));
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 if (XTYPE (tem) == Lisp_String)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 return Fsubstitute_command_keys (tem);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 if (XTYPE (tem) == Lisp_Int && XINT (tem) >= 0)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 return Fsubstitute_command_keys (get_doc_string (XFASTINT (tem)));
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 return Qnil;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 if (XSYMBOL (funcar) == XSYMBOL (Qmocklisp))
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 return Qnil;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 if (XSYMBOL (funcar) == XSYMBOL (Qmacro))
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 return Fdocumentation (Fcdr (fun));
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 /* Fall through to the default to report an error. */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 default:
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 DEFUN ("documentation-property", Fdocumentation_property,
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 Sdocumentation_property, 2, 2, 0,
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 "Return the documentation string that is SYMBOL's PROP property.\n\
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 This differs from using `get' only in that it can refer to strings\n\
463
ffdbf3445088 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 312
diff changeset
178 stored in the `share-lib/DOC' file.")
297
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 (sym, prop)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 Lisp_Object sym, prop;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 register Lisp_Object tem;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 tem = Fget (sym, prop);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 if (XTYPE (tem) == Lisp_Int)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 tem = get_doc_string (XINT (tem) > 0 ? XINT (tem) : - XINT (tem));
312
adba7439e87c *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 297
diff changeset
187 if (XTYPE (tem) == Lisp_String)
adba7439e87c *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 297
diff changeset
188 return Fsubstitute_command_keys (tem);
adba7439e87c *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 297
diff changeset
189 return tem;
297
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 DEFUN ("Snarf-documentation", Fsnarf_documentation, Ssnarf_documentation,
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 1, 1, 0,
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 "Used during Emacs initialization, before dumping runnable Emacs,\n\
463
ffdbf3445088 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 312
diff changeset
195 to find pointers to doc strings stored in `share-lib/DOC...' and\n\
297
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 record them in function definitions.\n\
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 One arg, FILENAME, a string which does not include a directory.\n\
463
ffdbf3445088 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 312
diff changeset
198 The file is found in `../share-lib' now; found in the `data-directory'\n\
297
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 when doc strings are referred to later in the dumped Emacs.")
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 (filename)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 Lisp_Object filename;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 int fd;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 char buf[1024 + 1];
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 register int filled;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 register int pos;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 register char *p, *end;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 Lisp_Object sym, fun, tem;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 char *name;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 extern char *index ();
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 CHECK_STRING (filename, 0);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 #ifndef CANNOT_DUMP
463
ffdbf3445088 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 312
diff changeset
215 name = (char *) alloca (XSTRING (filename)->size + 14);
ffdbf3445088 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 312
diff changeset
216 strcpy (name, "../share-lib/");
297
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 #else /* CANNOT_DUMP */
463
ffdbf3445088 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 312
diff changeset
218 CHECK_STRING (Vdata_directory, 0);
297
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 name = (char *) alloca (XSTRING (filename)->size +
463
ffdbf3445088 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 312
diff changeset
220 XSTRING (Vdata_directory)->size + 1);
ffdbf3445088 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 312
diff changeset
221 strcpy (name, XSTRING (Vdata_directory)->data);
297
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 #endif /* CANNOT_DUMP */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 strcat (name, XSTRING (filename)->data); /*** Add this line ***/
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 #ifdef VMS
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 #ifndef VMS4_4
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 /* For VMS versions with limited file name syntax,
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 convert the name to something VMS will allow. */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 p = name;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 while (*p)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 if (*p == '-')
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 *p = '_';
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 p++;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 #endif /* not VMS4_4 */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 #ifdef VMS4_4
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 strcpy (name, sys_translate_unix (name));
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 #endif /* VMS4_4 */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 #endif /* VMS */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 fd = open (name, O_RDONLY, 0);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 if (fd < 0)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 report_file_error ("Opening doc string file",
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 Fcons (build_string (name), Qnil));
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 Vdoc_file_name = filename;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 filled = 0;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 pos = 0;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 while (1)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 if (filled < 512)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 filled += read (fd, &buf[filled], sizeof buf - 1 - filled);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 if (!filled)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 break;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 buf[filled] = 0;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 p = buf;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 end = buf + (filled < 512 ? filled : filled - 128);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 while (p != end && *p != '\037') p++;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 /* p points to ^_Ffunctionname\n or ^_Vvarname\n. */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 if (p != end)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 end = index (p, '\n');
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 sym = oblookup (Vobarray, p + 2, end - p - 2);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 if (XTYPE (sym) == Lisp_Symbol)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 /* Attach a docstring to a variable? */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 if (p[1] == 'V')
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 /* Install file-position as variable-documentation property
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 and make it negative for a user-variable
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 (doc starts with a `*'). */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 Fput (sym, Qvariable_documentation,
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 make_number ((pos + end + 1 - buf)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 * (end[1] == '*' ? -1 : 1)));
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 /* Attach a docstring to a function? The type determines where
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 the docstring is stored. */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 else if (p[1] == 'F')
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 fun = XSYMBOL (sym)->function;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 /* Lisp_Subrs have a slot for it. */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 if (XTYPE (fun) == Lisp_Subr)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 XSUBR (fun)->doc = (char *) - (pos + end + 1 - buf);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 /* If it's a lisp form, stick it in the form. */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 else if (CONSP (fun))
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 tem = XCONS (fun)->car;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 if (EQ (tem, Qlambda) || EQ (tem, Qautoload))
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 tem = Fcdr (Fcdr (fun));
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 if (CONSP (tem) &&
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 XTYPE (XCONS (tem)->car) == Lisp_Int)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 XFASTINT (XCONS (tem)->car) = (pos + end + 1 - buf);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 /* Bytecode objects sometimes have slots for it. */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 else if (XTYPE (fun) == Lisp_Compiled)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 /* This bytecode object must have a slot for the
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 docstring, since we've found a docstring for it. */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 if (XVECTOR (fun)->size <= COMPILED_DOC_STRING)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 abort ();
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 XFASTINT (XVECTOR (fun)->contents[COMPILED_DOC_STRING])
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 = pos + end + 1 - buf;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 else error ("DOC file invalid at position %d", pos);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 pos += end - buf;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 filled -= end - buf;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 bcopy (end, buf, filled);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 close (fd);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 return Qnil;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323 DEFUN ("substitute-command-keys", Fsubstitute_command_keys,
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 Ssubstitute_command_keys, 1, 1, 0,
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 "Substitute key descriptions for command names in STRING.\n\
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 Return a new string which is STRING with substrings of the form \\=\\[COMMAND]\n\
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 replaced by either: a keystroke sequence that will invoke COMMAND,\n\
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 or \"M-x COMMAND\" if COMMAND is not on any keys.\n\
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 Substrings of the form \\=\\{MAPVAR} are replaced by summaries\n\
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 \(made by describe-bindings) of the value of MAPVAR, taken as a keymap.\n\
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 Substrings of the form \\=\\<MAPVAR> specify to use the value of MAPVAR\n\
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 as the keymap for future \\=\\[COMMAND] substrings.\n\
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 \\=\\= quotes the following character and is discarded;\n\
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ into the output.")
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 (str)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336 Lisp_Object str;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 unsigned char *buf;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 int changed = 0;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 register unsigned char *strp;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 register unsigned char *bufp;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 int idx;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 int bsize;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 unsigned char *new;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 register Lisp_Object tem;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 Lisp_Object keymap;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 unsigned char *start;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348 int length;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349 struct gcpro gcpro1;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351 if (NULL (str))
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 return Qnil;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
353
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 CHECK_STRING (str, 0);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355 GCPRO1 (str);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 keymap = current_buffer->keymap;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359 bsize = XSTRING (str)->size;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360 bufp = buf = (unsigned char *) xmalloc (bsize);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 strp = (unsigned char *) XSTRING (str)->data;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 while (strp < (unsigned char *) XSTRING (str)->data + XSTRING (str)->size)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365 if (strp[0] == '\\' && strp[1] == '=')
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 /* \= quotes the next character;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 thus, to put in \[ without its special meaning, use \=\[. */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 changed = 1;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 *bufp++ = strp[2];
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 strp += 3;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 else if (strp[0] == '\\' && strp[1] == '[')
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 changed = 1;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 strp += 2; /* skip \[ */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 start = strp;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 while ((strp - (unsigned char *) XSTRING (str)->data
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 < XSTRING (str)->size)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381 && *strp != ']')
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382 strp++;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383 length = strp - start;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384 strp++; /* skip ] */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386 /* Save STRP in IDX. */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 idx = strp - (unsigned char *) XSTRING (str)->data;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 tem = Fintern (make_string (start, length), Qnil);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389 tem = Fwhere_is_internal (tem, keymap, Qnil, Qt, Qnil);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 if (NULL (tem)) /* but not on any keys */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393 new = (unsigned char *) xrealloc (buf, bsize += 4);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394 bufp += new - buf;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 buf = new;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396 bcopy ("M-x ", bufp, 4);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 bufp += 4;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398 goto subst;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400 else
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401 { /* function is on a key */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
402 tem = Fkey_description (tem);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
403 goto subst_string;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
404 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
405 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
406 /* \{foo} is replaced with a summary of the keymap (symbol-value foo).
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407 \<foo> just sets the keymap used for \[cmd]. */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408 else if (strp[0] == '\\' && (strp[1] == '{' || strp[1] == '<'))
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410 struct buffer *oldbuf;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411 Lisp_Object name;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413 changed = 1;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
414 strp += 2; /* skip \{ or \< */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 start = strp;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417 while ((strp - (unsigned char *) XSTRING (str)->data
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418 < XSTRING (str)->size)
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419 && *strp != '}' && *strp != '>')
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420 strp++;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421 length = strp - start;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422 strp++; /* skip } or > */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424 /* Save STRP in IDX. */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425 idx = strp - (unsigned char *) XSTRING (str)->data;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 /* Get the value of the keymap in TEM, or nil if undefined.
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428 Do this while still in the user's current buffer
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 in case it is a local variable. */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430 name = Fintern (make_string (start, length), Qnil);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 tem = Fboundp (name);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432 if (! NULL (tem))
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
434 tem = Fsymbol_value (name);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
435 if (! NULL (tem))
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436 tem = get_keymap_1 (tem, 0);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
438
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439 /* Now switch to a temp buffer. */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440 oldbuf = current_buffer;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
441 set_buffer_internal (XBUFFER (Vprin1_to_string_buffer));
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443 if (NULL (tem))
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
444 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
445 name = Fsymbol_name (name);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
446 insert_string ("\nUses keymap \"");
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
447 insert_from_string (name, 0, XSTRING (name)->size);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448 insert_string ("\", which is not currently defined.\n");
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449 if (start[-1] == '<') keymap = Qnil;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
451 else if (start[-1] == '<')
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452 keymap = tem;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453 else
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
454 describe_map_tree (tem, 1, Qnil);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455 tem = Fbuffer_string ();
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456 Ferase_buffer ();
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457 set_buffer_internal (oldbuf);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 subst_string:
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
460 start = XSTRING (tem)->data;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
461 length = XSTRING (tem)->size;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462 subst:
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
463 new = (unsigned char *) xrealloc (buf, bsize += length);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
464 bufp += new - buf;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
465 buf = new;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
466 bcopy (start, bufp, length);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
467 bufp += length;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
468 /* Check STR again in case gc relocated it. */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
469 strp = (unsigned char *) XSTRING (str)->data + idx;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471 else /* just copy other chars */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
472 *bufp++ = *strp++;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
473 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
474
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
475 if (changed) /* don't bother if nothing substituted */
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
476 tem = make_string (buf, bufp - buf);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
477 else
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
478 tem = str;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
479 UNGCPRO;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
480 free (buf);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
481 return tem;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
482 }
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
483
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
484 syms_of_doc ()
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
485 {
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
486 DEFVAR_LISP ("internal-doc-file-name", &Vdoc_file_name,
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
487 "Name of file containing documentation strings of built-in symbols.");
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
488 Vdoc_file_name = Qnil;
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
489
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
490 defsubr (&Sdocumentation);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
491 defsubr (&Sdocumentation_property);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
492 defsubr (&Ssnarf_documentation);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
493 defsubr (&Ssubstitute_command_keys);
785f88514b16 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
494 }