annotate src/doc.c @ 935:7aa20c8e89b7

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