Mercurial > emacs
annotate src/editfns.c @ 1276:6b63876aea1c
(kill-word): Don't change point before calling kill-region.
(delete-indentation): Don't go beyond eob, comparing with fill-prefix.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 30 Sep 1992 10:31:31 +0000 |
parents | c7e7e3438711 |
children | d50533e23dff |
rev | line source |
---|---|
305 | 1 /* Lisp functions pertaining to editing. |
577 | 2 Copyright (C) 1985, 1986, 1987, 1989, 1992 Free Software Foundation, Inc. |
305 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 1, or (at your option) | |
9 any later version. | |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
20 | |
21 #include "config.h" | |
372 | 22 |
23 #ifdef VMS | |
577 | 24 #include "vms-pwd.h" |
372 | 25 #else |
305 | 26 #include <pwd.h> |
372 | 27 #endif |
28 | |
305 | 29 #include "lisp.h" |
30 #include "buffer.h" | |
31 #include "window.h" | |
32 | |
577 | 33 #include "systime.h" |
305 | 34 |
35 #define min(a, b) ((a) < (b) ? (a) : (b)) | |
36 #define max(a, b) ((a) > (b) ? (a) : (b)) | |
37 | |
38 /* Some static data, and a function to initialize it for each run */ | |
39 | |
40 Lisp_Object Vsystem_name; | |
41 Lisp_Object Vuser_real_name; /* login name of current user ID */ | |
42 Lisp_Object Vuser_full_name; /* full name of current user */ | |
43 Lisp_Object Vuser_name; /* user name from USER or LOGNAME. */ | |
44 | |
45 void | |
46 init_editfns () | |
47 { | |
330 | 48 char *user_name; |
305 | 49 register unsigned char *p, *q, *r; |
50 struct passwd *pw; /* password entry for the current user */ | |
51 extern char *index (); | |
52 Lisp_Object tem; | |
53 | |
54 /* Set up system_name even when dumping. */ | |
55 | |
56 Vsystem_name = build_string (get_system_name ()); | |
57 p = XSTRING (Vsystem_name)->data; | |
58 while (*p) | |
59 { | |
60 if (*p == ' ' || *p == '\t') | |
61 *p = '-'; | |
62 p++; | |
63 } | |
64 | |
65 #ifndef CANNOT_DUMP | |
66 /* Don't bother with this on initial start when just dumping out */ | |
67 if (!initialized) | |
68 return; | |
69 #endif /* not CANNOT_DUMP */ | |
70 | |
71 pw = (struct passwd *) getpwuid (getuid ()); | |
72 Vuser_real_name = build_string (pw ? pw->pw_name : "unknown"); | |
73 | |
330 | 74 /* Get the effective user name, by consulting environment variables, |
75 or the effective uid if those are unset. */ | |
76 user_name = (char *) getenv ("USER"); | |
77 if (!user_name) | |
78 user_name = (char *) getenv ("LOGNAME"); | |
305 | 79 if (!user_name) |
330 | 80 { |
81 pw = (struct passwd *) getpwuid (geteuid ()); | |
82 user_name = (char *) (pw ? pw->pw_name : "unknown"); | |
83 } | |
84 Vuser_name = build_string (user_name); | |
305 | 85 |
330 | 86 /* If the user name claimed in the environment vars differs from |
87 the real uid, use the claimed name to find the full name. */ | |
305 | 88 tem = Fstring_equal (Vuser_name, Vuser_real_name); |
488 | 89 if (NILP (tem)) |
330 | 90 pw = (struct passwd *) getpwnam (XSTRING (Vuser_name)->data); |
305 | 91 |
92 p = (unsigned char *) (pw ? USER_FULL_NAME : "unknown"); | |
93 q = (unsigned char *) index (p, ','); | |
94 Vuser_full_name = make_string (p, q ? q - p : strlen (p)); | |
95 | |
96 #ifdef AMPERSAND_FULL_NAME | |
97 p = XSTRING (Vuser_full_name)->data; | |
98 q = (char *) index (p, '&'); | |
99 /* Substitute the login name for the &, upcasing the first character. */ | |
100 if (q) | |
101 { | |
102 r = (char *) alloca (strlen (p) + XSTRING (Vuser_name)->size + 1); | |
103 bcopy (p, r, q - p); | |
104 r[q - p] = 0; | |
330 | 105 strcat (r, XSTRING (Vuser_name)->data); |
305 | 106 r[q - p] = UPCASE (r[q - p]); |
107 strcat (r, q + 1); | |
108 Vuser_full_name = build_string (r); | |
109 } | |
110 #endif /* AMPERSAND_FULL_NAME */ | |
111 } | |
112 | |
113 DEFUN ("char-to-string", Fchar_to_string, Schar_to_string, 1, 1, 0, | |
114 "Convert arg CHAR to a one-character string containing that character.") | |
115 (n) | |
116 Lisp_Object n; | |
117 { | |
118 char c; | |
119 CHECK_NUMBER (n, 0); | |
120 | |
121 c = XINT (n); | |
122 return make_string (&c, 1); | |
123 } | |
124 | |
125 DEFUN ("string-to-char", Fstring_to_char, Sstring_to_char, 1, 1, 0, | |
126 "Convert arg STRING to a character, the first character of that string.") | |
127 (str) | |
128 register Lisp_Object str; | |
129 { | |
130 register Lisp_Object val; | |
131 register struct Lisp_String *p; | |
132 CHECK_STRING (str, 0); | |
133 | |
134 p = XSTRING (str); | |
135 if (p->size) | |
136 XFASTINT (val) = ((unsigned char *) p->data)[0]; | |
137 else | |
138 XFASTINT (val) = 0; | |
139 return val; | |
140 } | |
141 | |
142 static Lisp_Object | |
143 buildmark (val) | |
144 int val; | |
145 { | |
146 register Lisp_Object mark; | |
147 mark = Fmake_marker (); | |
148 Fset_marker (mark, make_number (val), Qnil); | |
149 return mark; | |
150 } | |
151 | |
152 DEFUN ("point", Fpoint, Spoint, 0, 0, 0, | |
153 "Return value of point, as an integer.\n\ | |
154 Beginning of buffer is position (point-min)") | |
155 () | |
156 { | |
157 Lisp_Object temp; | |
158 XFASTINT (temp) = point; | |
159 return temp; | |
160 } | |
161 | |
162 DEFUN ("point-marker", Fpoint_marker, Spoint_marker, 0, 0, 0, | |
163 "Return value of point, as a marker object.") | |
164 () | |
165 { | |
166 return buildmark (point); | |
167 } | |
168 | |
169 int | |
170 clip_to_bounds (lower, num, upper) | |
171 int lower, num, upper; | |
172 { | |
173 if (num < lower) | |
174 return lower; | |
175 else if (num > upper) | |
176 return upper; | |
177 else | |
178 return num; | |
179 } | |
180 | |
181 DEFUN ("goto-char", Fgoto_char, Sgoto_char, 1, 1, "NGoto char: ", | |
182 "Set point to POSITION, a number or marker.\n\ | |
183 Beginning of buffer is position (point-min), end is (point-max).") | |
184 (n) | |
185 register Lisp_Object n; | |
186 { | |
187 CHECK_NUMBER_COERCE_MARKER (n, 0); | |
188 | |
189 SET_PT (clip_to_bounds (BEGV, XINT (n), ZV)); | |
190 return n; | |
191 } | |
192 | |
193 static Lisp_Object | |
194 region_limit (beginningp) | |
195 int beginningp; | |
196 { | |
197 register Lisp_Object m; | |
198 m = Fmarker_position (current_buffer->mark); | |
488 | 199 if (NILP (m)) error ("There is no region now"); |
305 | 200 if ((point < XFASTINT (m)) == beginningp) |
201 return (make_number (point)); | |
202 else | |
203 return (m); | |
204 } | |
205 | |
206 DEFUN ("region-beginning", Fregion_beginning, Sregion_beginning, 0, 0, 0, | |
207 "Return position of beginning of region, as an integer.") | |
208 () | |
209 { | |
210 return (region_limit (1)); | |
211 } | |
212 | |
213 DEFUN ("region-end", Fregion_end, Sregion_end, 0, 0, 0, | |
214 "Return position of end of region, as an integer.") | |
215 () | |
216 { | |
217 return (region_limit (0)); | |
218 } | |
219 | |
220 #if 0 /* now in lisp code */ | |
221 DEFUN ("mark", Fmark, Smark, 0, 0, 0, | |
222 "Return this buffer's mark value as integer, or nil if no mark.\n\ | |
223 If you are using this in an editing command, you are most likely making\n\ | |
224 a mistake; see the documentation of `set-mark'.") | |
225 () | |
226 { | |
227 return Fmarker_position (current_buffer->mark); | |
228 } | |
229 #endif /* commented out code */ | |
230 | |
231 DEFUN ("mark-marker", Fmark_marker, Smark_marker, 0, 0, 0, | |
232 "Return this buffer's mark, as a marker object.\n\ | |
233 Watch out! Moving this marker changes the mark position.\n\ | |
234 If you set the marker not to point anywhere, the buffer will have no mark.") | |
235 () | |
236 { | |
237 return current_buffer->mark; | |
238 } | |
239 | |
240 #if 0 /* this is now in lisp code */ | |
241 DEFUN ("set-mark", Fset_mark, Sset_mark, 1, 1, 0, | |
242 "Set this buffer's mark to POS. Don't use this function!\n\ | |
243 That is to say, don't use this function unless you want\n\ | |
244 the user to see that the mark has moved, and you want the previous\n\ | |
245 mark position to be lost.\n\ | |
246 \n\ | |
247 Normally, when a new mark is set, the old one should go on the stack.\n\ | |
248 This is why most applications should use push-mark, not set-mark.\n\ | |
249 \n\ | |
250 Novice programmers often try to use the mark for the wrong purposes.\n\ | |
251 The mark saves a location for the user's convenience.\n\ | |
252 Most editing commands should not alter the mark.\n\ | |
253 To remember a location for internal use in the Lisp program,\n\ | |
254 store it in a Lisp variable. Example:\n\ | |
255 \n\ | |
256 (let ((beg (point))) (forward-line 1) (delete-region beg (point))).") | |
257 (pos) | |
258 Lisp_Object pos; | |
259 { | |
488 | 260 if (NILP (pos)) |
305 | 261 { |
262 current_buffer->mark = Qnil; | |
263 return Qnil; | |
264 } | |
265 CHECK_NUMBER_COERCE_MARKER (pos, 0); | |
266 | |
488 | 267 if (NILP (current_buffer->mark)) |
305 | 268 current_buffer->mark = Fmake_marker (); |
269 | |
270 Fset_marker (current_buffer->mark, pos, Qnil); | |
271 return pos; | |
272 } | |
273 #endif /* commented-out code */ | |
274 | |
275 Lisp_Object | |
276 save_excursion_save () | |
277 { | |
1254
c7e7e3438711
* editfns.c (save_excursion_save, save_excursion_restore):
Jim Blandy <jimb@redhat.com>
parents:
1117
diff
changeset
|
278 register int visible = (XBUFFER (XWINDOW (selected_window)->buffer) |
c7e7e3438711
* editfns.c (save_excursion_save, save_excursion_restore):
Jim Blandy <jimb@redhat.com>
parents:
1117
diff
changeset
|
279 == current_buffer); |
305 | 280 |
281 return Fcons (Fpoint_marker (), | |
1254
c7e7e3438711
* editfns.c (save_excursion_save, save_excursion_restore):
Jim Blandy <jimb@redhat.com>
parents:
1117
diff
changeset
|
282 Fcons (Fcopy_marker (current_buffer->mark), |
c7e7e3438711
* editfns.c (save_excursion_save, save_excursion_restore):
Jim Blandy <jimb@redhat.com>
parents:
1117
diff
changeset
|
283 visible ? Qt : Qnil)); |
305 | 284 } |
285 | |
286 Lisp_Object | |
287 save_excursion_restore (info) | |
288 register Lisp_Object info; | |
289 { | |
290 register Lisp_Object tem; | |
291 | |
292 tem = Fmarker_buffer (Fcar (info)); | |
293 /* If buffer being returned to is now deleted, avoid error */ | |
294 /* Otherwise could get error here while unwinding to top level | |
295 and crash */ | |
296 /* In that case, Fmarker_buffer returns nil now. */ | |
488 | 297 if (NILP (tem)) |
305 | 298 return Qnil; |
299 Fset_buffer (tem); | |
300 tem = Fcar (info); | |
301 Fgoto_char (tem); | |
302 unchain_marker (tem); | |
303 tem = Fcar (Fcdr (info)); | |
304 Fset_marker (current_buffer->mark, tem, Fcurrent_buffer ()); | |
305 unchain_marker (tem); | |
306 tem = Fcdr (Fcdr (info)); | |
1254
c7e7e3438711
* editfns.c (save_excursion_save, save_excursion_restore):
Jim Blandy <jimb@redhat.com>
parents:
1117
diff
changeset
|
307 if (!NILP (tem) |
c7e7e3438711
* editfns.c (save_excursion_save, save_excursion_restore):
Jim Blandy <jimb@redhat.com>
parents:
1117
diff
changeset
|
308 && current_buffer != XBUFFER (XWINDOW (selected_window)->buffer)) |
305 | 309 Fswitch_to_buffer (Fcurrent_buffer (), Qnil); |
310 return Qnil; | |
311 } | |
312 | |
313 DEFUN ("save-excursion", Fsave_excursion, Ssave_excursion, 0, UNEVALLED, 0, | |
314 "Save point, mark, and current buffer; execute BODY; restore those things.\n\ | |
315 Executes BODY just like `progn'.\n\ | |
316 The values of point, mark and the current buffer are restored\n\ | |
317 even in case of abnormal exit (throw or error).") | |
318 (args) | |
319 Lisp_Object args; | |
320 { | |
321 register Lisp_Object val; | |
322 int count = specpdl_ptr - specpdl; | |
323 | |
324 record_unwind_protect (save_excursion_restore, save_excursion_save ()); | |
325 | |
326 val = Fprogn (args); | |
327 return unbind_to (count, val); | |
328 } | |
329 | |
330 DEFUN ("buffer-size", Fbufsize, Sbufsize, 0, 0, 0, | |
331 "Return the number of characters in the current buffer.") | |
332 () | |
333 { | |
334 Lisp_Object temp; | |
335 XFASTINT (temp) = Z - BEG; | |
336 return temp; | |
337 } | |
338 | |
339 DEFUN ("point-min", Fpoint_min, Spoint_min, 0, 0, 0, | |
340 "Return the minimum permissible value of point in the current buffer.\n\ | |
341 This is 1, unless a clipping restriction is in effect.") | |
342 () | |
343 { | |
344 Lisp_Object temp; | |
345 XFASTINT (temp) = BEGV; | |
346 return temp; | |
347 } | |
348 | |
349 DEFUN ("point-min-marker", Fpoint_min_marker, Spoint_min_marker, 0, 0, 0, | |
350 "Return a marker to the minimum permissible value of point in this buffer.\n\ | |
351 This is the beginning, unless a clipping restriction is in effect.") | |
352 () | |
353 { | |
354 return buildmark (BEGV); | |
355 } | |
356 | |
357 DEFUN ("point-max", Fpoint_max, Spoint_max, 0, 0, 0, | |
358 "Return the maximum permissible value of point in the current buffer.\n\ | |
359 This is (1+ (buffer-size)), unless a clipping restriction is in effect,\n\ | |
360 in which case it is less.") | |
361 () | |
362 { | |
363 Lisp_Object temp; | |
364 XFASTINT (temp) = ZV; | |
365 return temp; | |
366 } | |
367 | |
368 DEFUN ("point-max-marker", Fpoint_max_marker, Spoint_max_marker, 0, 0, 0, | |
369 "Return a marker to the maximum permissible value of point in this buffer.\n\ | |
370 This is (1+ (buffer-size)), unless a clipping restriction is in effect,\n\ | |
371 in which case it is less.") | |
372 () | |
373 { | |
374 return buildmark (ZV); | |
375 } | |
376 | |
512 | 377 DEFUN ("following-char", Ffollowing_char, Sfollowing_char, 0, 0, 0, |
378 "Return the character following point, as a number.\n\ | |
379 At the end of the buffer or accessible region, return 0.") | |
305 | 380 () |
381 { | |
382 Lisp_Object temp; | |
512 | 383 if (point >= ZV) |
384 XFASTINT (temp) = 0; | |
385 else | |
386 XFASTINT (temp) = FETCH_CHAR (point); | |
305 | 387 return temp; |
388 } | |
389 | |
512 | 390 DEFUN ("preceding-char", Fprevious_char, Sprevious_char, 0, 0, 0, |
391 "Return the character preceding point, as a number.\n\ | |
392 At the beginning of the buffer or accessible region, return 0.") | |
305 | 393 () |
394 { | |
395 Lisp_Object temp; | |
396 if (point <= BEGV) | |
397 XFASTINT (temp) = 0; | |
398 else | |
399 XFASTINT (temp) = FETCH_CHAR (point - 1); | |
400 return temp; | |
401 } | |
402 | |
403 DEFUN ("bobp", Fbobp, Sbobp, 0, 0, 0, | |
404 "Return T if point is at the beginning of the buffer.\n\ | |
405 If the buffer is narrowed, this means the beginning of the narrowed part.") | |
406 () | |
407 { | |
408 if (point == BEGV) | |
409 return Qt; | |
410 return Qnil; | |
411 } | |
412 | |
413 DEFUN ("eobp", Feobp, Seobp, 0, 0, 0, | |
414 "Return T if point is at the end of the buffer.\n\ | |
415 If the buffer is narrowed, this means the end of the narrowed part.") | |
416 () | |
417 { | |
418 if (point == ZV) | |
419 return Qt; | |
420 return Qnil; | |
421 } | |
422 | |
423 DEFUN ("bolp", Fbolp, Sbolp, 0, 0, 0, | |
424 "Return T if point is at the beginning of a line.") | |
425 () | |
426 { | |
427 if (point == BEGV || FETCH_CHAR (point - 1) == '\n') | |
428 return Qt; | |
429 return Qnil; | |
430 } | |
431 | |
432 DEFUN ("eolp", Feolp, Seolp, 0, 0, 0, | |
433 "Return T if point is at the end of a line.\n\ | |
434 `End of a line' includes point being at the end of the buffer.") | |
435 () | |
436 { | |
437 if (point == ZV || FETCH_CHAR (point) == '\n') | |
438 return Qt; | |
439 return Qnil; | |
440 } | |
441 | |
442 DEFUN ("char-after", Fchar_after, Schar_after, 1, 1, 0, | |
443 "Return character in current buffer at position POS.\n\ | |
444 POS is an integer or a buffer pointer.\n\ | |
445 If POS is out of range, the value is nil.") | |
446 (pos) | |
447 Lisp_Object pos; | |
448 { | |
449 register Lisp_Object val; | |
450 register int n; | |
451 | |
452 CHECK_NUMBER_COERCE_MARKER (pos, 0); | |
453 | |
454 n = XINT (pos); | |
455 if (n < BEGV || n >= ZV) return Qnil; | |
456 | |
457 XFASTINT (val) = FETCH_CHAR (n); | |
458 return val; | |
459 } | |
460 | |
461 DEFUN ("user-login-name", Fuser_login_name, Suser_login_name, 0, 0, 0, | |
462 "Return the name under which the user logged in, as a string.\n\ | |
463 This is based on the effective uid, not the real uid.\n\ | |
464 Also, if the environment variable USER or LOGNAME is set,\n\ | |
465 that determines the value of this function.") | |
466 () | |
467 { | |
468 return Vuser_name; | |
469 } | |
470 | |
471 DEFUN ("user-real-login-name", Fuser_real_login_name, Suser_real_login_name, | |
472 0, 0, 0, | |
473 "Return the name of the user's real uid, as a string.\n\ | |
474 Differs from `user-login-name' when running under `su'.") | |
475 () | |
476 { | |
477 return Vuser_real_name; | |
478 } | |
479 | |
480 DEFUN ("user-uid", Fuser_uid, Suser_uid, 0, 0, 0, | |
481 "Return the effective uid of Emacs, as an integer.") | |
482 () | |
483 { | |
484 return make_number (geteuid ()); | |
485 } | |
486 | |
487 DEFUN ("user-real-uid", Fuser_real_uid, Suser_real_uid, 0, 0, 0, | |
488 "Return the real uid of Emacs, as an integer.") | |
489 () | |
490 { | |
491 return make_number (getuid ()); | |
492 } | |
493 | |
494 DEFUN ("user-full-name", Fuser_full_name, Suser_full_name, 0, 0, 0, | |
495 "Return the full name of the user logged in, as a string.") | |
496 () | |
497 { | |
498 return Vuser_full_name; | |
499 } | |
500 | |
501 DEFUN ("system-name", Fsystem_name, Ssystem_name, 0, 0, 0, | |
502 "Return the name of the machine you are running on, as a string.") | |
503 () | |
504 { | |
505 return Vsystem_name; | |
506 } | |
507 | |
448 | 508 DEFUN ("current-time", Fcurrent_time, Scurrent_time, 0, 0, 0, |
577 | 509 "Return the current time, as the number of seconds since 12:00 AM January 1970.\n\ |
510 The time is returned as a list of three integers. The first has the\n\ | |
511 most significant 16 bits of the seconds, while the second has the\n\ | |
512 least significant 16 bits. The third integer gives the microsecond\n\ | |
513 count.\n\ | |
514 \n\ | |
515 The microsecond count is zero on systems that do not provide\n\ | |
516 resolution finer than a second.") | |
448 | 517 () |
518 { | |
577 | 519 EMACS_TIME t; |
520 Lisp_Object result[3]; | |
521 | |
522 EMACS_GET_TIME (t); | |
523 XSET (result[0], Lisp_Int, (EMACS_SECS (t) >> 16) & 0xffff); | |
524 XSET (result[1], Lisp_Int, (EMACS_SECS (t) >> 0) & 0xffff); | |
525 XSET (result[2], Lisp_Int, EMACS_USECS (t)); | |
526 | |
527 return Flist (3, result); | |
448 | 528 } |
529 | |
530 | |
305 | 531 DEFUN ("current-time-string", Fcurrent_time_string, Scurrent_time_string, 0, 0, 0, |
532 "Return the current time, as a human-readable string.\n\ | |
533 Programs can use it too, since the number of columns in each field is fixed.\n\ | |
534 The format is `Sun Sep 16 01:03:52 1973'.\n\ | |
1117
878afcdce84e
* editfns.c (Fcurrent_time_string): Change docstring to
Jim Blandy <jimb@redhat.com>
parents:
962
diff
changeset
|
535 In a future Emacs version, the time zone may be added at the end.") |
305 | 536 () |
537 { | |
538 long current_time = time ((long *) 0); | |
539 char buf[30]; | |
540 register char *tem = (char *) ctime (¤t_time); | |
541 | |
542 strncpy (buf, tem, 24); | |
543 buf[24] = 0; | |
544 | |
545 return build_string (buf); | |
546 } | |
962
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
547 |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
548 DEFUN ("current-time-zone", Fcurrent_time_zone, Scurrent_time_zone, 0, 0, 0, |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
549 "Return the offset, savings state, and names for the current time zone.\n\ |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
550 This returns a list of the form (OFFSET SAVINGS-FLAG STANDARD SAVINGS).\n\ |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
551 OFFSET is an integer specifying how many minutes east of Greenwich the\n\ |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
552 current time zone is located. A negative value means west of\n\ |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
553 Greenwich. Note that this describes the standard time; If daylight\n\ |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
554 savings time is in effect, it does not affect this value.\n\ |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
555 SAVINGS-FLAG is non-nil iff daylight savings time or some other sort\n\ |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
556 of seasonal time adjustment is in effect.\n\ |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
557 STANDARD is a string giving the name of the time zone when no seasonal\n\ |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
558 time adjustment is in effect.\n\ |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
559 SAVINGS is a string giving the name of the time zone when there is a\n\ |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
560 seasonal time adjustment in effect.\n\ |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
561 If the local area does not use a seasonal time adjustment,\n\ |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
562 SAVINGS-FLAG will always be nil, and STANDARD and SAVINGS will be the\n\ |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
563 same.") |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
564 () |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
565 { |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
566 #ifdef EMACS_CURRENT_TIME_ZONE |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
567 int offset, savings_flag; |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
568 char standard[11]; |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
569 char savings[11]; |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
570 |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
571 EMACS_CURRENT_TIME_ZONE (&offset, &savings_flag, standard, savings); |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
572 |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
573 return Fcons (make_number (offset), |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
574 Fcons ((savings_flag ? Qt : Qnil), |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
575 Fcons (build_string (standard), |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
576 Fcons (build_string (savings), |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
577 Qnil)))); |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
578 #else |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
579 error |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
580 ("current-time-zone has not been implemented on this operating system."); |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
581 #endif |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
582 } |
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
583 |
305 | 584 |
585 void | |
586 insert1 (arg) | |
587 Lisp_Object arg; | |
588 { | |
589 Finsert (1, &arg); | |
590 } | |
591 | |
330 | 592 |
593 /* Callers passing one argument to Finsert need not gcpro the | |
594 argument "array", since the only element of the array will | |
595 not be used after calling insert or insert_from_string, so | |
596 we don't care if it gets trashed. */ | |
597 | |
305 | 598 DEFUN ("insert", Finsert, Sinsert, 0, MANY, 0, |
599 "Insert the arguments, either strings or characters, at point.\n\ | |
600 Point moves forward so that it ends up after the inserted text.\n\ | |
601 Any other markers at the point of insertion remain before the text.") | |
602 (nargs, args) | |
603 int nargs; | |
604 register Lisp_Object *args; | |
605 { | |
606 register int argnum; | |
607 register Lisp_Object tem; | |
608 char str[1]; | |
609 | |
610 for (argnum = 0; argnum < nargs; argnum++) | |
611 { | |
612 tem = args[argnum]; | |
613 retry: | |
614 if (XTYPE (tem) == Lisp_Int) | |
615 { | |
616 str[0] = XINT (tem); | |
617 insert (str, 1); | |
618 } | |
619 else if (XTYPE (tem) == Lisp_String) | |
620 { | |
621 insert_from_string (tem, 0, XSTRING (tem)->size); | |
622 } | |
623 else | |
624 { | |
625 tem = wrong_type_argument (Qchar_or_string_p, tem); | |
626 goto retry; | |
627 } | |
628 } | |
629 | |
630 return Qnil; | |
631 } | |
632 | |
633 DEFUN ("insert-before-markers", Finsert_before_markers, Sinsert_before_markers, 0, MANY, 0, | |
634 "Insert strings or characters at point, relocating markers after the text.\n\ | |
635 Point moves forward so that it ends up after the inserted text.\n\ | |
636 Any other markers at the point of insertion also end up after the text.") | |
637 (nargs, args) | |
638 int nargs; | |
639 register Lisp_Object *args; | |
640 { | |
641 register int argnum; | |
642 register Lisp_Object tem; | |
643 char str[1]; | |
644 | |
645 for (argnum = 0; argnum < nargs; argnum++) | |
646 { | |
647 tem = args[argnum]; | |
648 retry: | |
649 if (XTYPE (tem) == Lisp_Int) | |
650 { | |
651 str[0] = XINT (tem); | |
652 insert_before_markers (str, 1); | |
653 } | |
654 else if (XTYPE (tem) == Lisp_String) | |
655 { | |
656 insert_from_string_before_markers (tem, 0, XSTRING (tem)->size); | |
657 } | |
658 else | |
659 { | |
660 tem = wrong_type_argument (Qchar_or_string_p, tem); | |
661 goto retry; | |
662 } | |
663 } | |
664 | |
665 return Qnil; | |
666 } | |
667 | |
668 DEFUN ("insert-char", Finsert_char, Sinsert_char, 2, 2, 0, | |
669 "Insert COUNT (second arg) copies of CHAR (first arg).\n\ | |
670 Point and all markers are affected as in the function `insert'.\n\ | |
671 Both arguments are required.") | |
672 (chr, count) | |
673 Lisp_Object chr, count; | |
674 { | |
675 register unsigned char *string; | |
676 register int strlen; | |
677 register int i, n; | |
678 | |
679 CHECK_NUMBER (chr, 0); | |
680 CHECK_NUMBER (count, 1); | |
681 | |
682 n = XINT (count); | |
683 if (n <= 0) | |
684 return Qnil; | |
685 strlen = min (n, 256); | |
686 string = (unsigned char *) alloca (strlen); | |
687 for (i = 0; i < strlen; i++) | |
688 string[i] = XFASTINT (chr); | |
689 while (n >= strlen) | |
690 { | |
691 insert (string, strlen); | |
692 n -= strlen; | |
693 } | |
694 if (n > 0) | |
695 insert (string, n); | |
696 return Qnil; | |
697 } | |
698 | |
699 | |
648 | 700 /* Making strings from buffer contents. */ |
701 | |
702 /* Return a Lisp_String containing the text of the current buffer from | |
703 START to END. | |
704 | |
705 We don't want to use plain old make_string here, because it calls | |
706 make_uninit_string, which can cause the buffer arena to be | |
707 compacted. make_string has no way of knowing that the data has | |
708 been moved, and thus copies the wrong data into the string. This | |
709 doesn't effect most of the other users of make_string, so it should | |
710 be left as is. But we should use this function when conjuring | |
711 buffer substrings. */ | |
712 Lisp_Object | |
713 make_buffer_string (start, end) | |
714 int start, end; | |
715 { | |
716 Lisp_Object result; | |
717 | |
718 if (start < GPT && GPT < end) | |
719 move_gap (start); | |
720 | |
721 result = make_uninit_string (end - start); | |
722 bcopy (&FETCH_CHAR (start), XSTRING (result)->data, end - start); | |
723 | |
724 return result; | |
725 } | |
305 | 726 |
727 DEFUN ("buffer-substring", Fbuffer_substring, Sbuffer_substring, 2, 2, 0, | |
728 "Return the contents of part of the current buffer as a string.\n\ | |
729 The two arguments START and END are character positions;\n\ | |
730 they can be in either order.") | |
731 (b, e) | |
732 Lisp_Object b, e; | |
733 { | |
734 register int beg, end; | |
735 | |
736 validate_region (&b, &e); | |
737 beg = XINT (b); | |
738 end = XINT (e); | |
739 | |
648 | 740 return make_buffer_string (beg, end); |
305 | 741 } |
742 | |
743 DEFUN ("buffer-string", Fbuffer_string, Sbuffer_string, 0, 0, 0, | |
744 "Return the contents of the current buffer as a string.") | |
745 () | |
746 { | |
648 | 747 return make_buffer_string (BEGV, ZV); |
305 | 748 } |
749 | |
750 DEFUN ("insert-buffer-substring", Finsert_buffer_substring, Sinsert_buffer_substring, | |
751 1, 3, 0, | |
752 "Insert before point a substring of the contents buffer BUFFER.\n\ | |
753 BUFFER may be a buffer or a buffer name.\n\ | |
754 Arguments START and END are character numbers specifying the substring.\n\ | |
755 They default to the beginning and the end of BUFFER.") | |
756 (buf, b, e) | |
757 Lisp_Object buf, b, e; | |
758 { | |
759 register int beg, end, exch; | |
760 register struct buffer *bp; | |
761 | |
762 buf = Fget_buffer (buf); | |
763 bp = XBUFFER (buf); | |
764 | |
488 | 765 if (NILP (b)) |
305 | 766 beg = BUF_BEGV (bp); |
767 else | |
768 { | |
769 CHECK_NUMBER_COERCE_MARKER (b, 0); | |
770 beg = XINT (b); | |
771 } | |
488 | 772 if (NILP (e)) |
305 | 773 end = BUF_ZV (bp); |
774 else | |
775 { | |
776 CHECK_NUMBER_COERCE_MARKER (e, 1); | |
777 end = XINT (e); | |
778 } | |
779 | |
780 if (beg > end) | |
781 exch = beg, beg = end, end = exch; | |
782 | |
783 /* Move the gap or create enough gap in the current buffer. */ | |
784 | |
785 if (point != GPT) | |
786 move_gap (point); | |
787 if (GAP_SIZE < end - beg) | |
788 make_gap (end - beg - GAP_SIZE); | |
789 | |
790 if (!(BUF_BEGV (bp) <= beg | |
791 && beg <= end | |
792 && end <= BUF_ZV (bp))) | |
793 args_out_of_range (b, e); | |
794 | |
795 /* Now the actual insertion will not do any gap motion, | |
796 so it matters not if BUF is the current buffer. */ | |
797 if (beg < BUF_GPT (bp)) | |
798 { | |
799 insert (BUF_CHAR_ADDRESS (bp, beg), min (end, BUF_GPT (bp)) - beg); | |
800 beg = min (end, BUF_GPT (bp)); | |
801 } | |
802 if (beg < end) | |
803 insert (BUF_CHAR_ADDRESS (bp, beg), end - beg); | |
804 | |
805 return Qnil; | |
806 } | |
807 | |
808 DEFUN ("subst-char-in-region", Fsubst_char_in_region, | |
809 Ssubst_char_in_region, 4, 5, 0, | |
810 "From START to END, replace FROMCHAR with TOCHAR each time it occurs.\n\ | |
811 If optional arg NOUNDO is non-nil, don't record this change for undo\n\ | |
812 and don't mark the buffer as really changed.") | |
813 (start, end, fromchar, tochar, noundo) | |
814 Lisp_Object start, end, fromchar, tochar, noundo; | |
815 { | |
816 register int pos, stop, look; | |
817 | |
818 validate_region (&start, &end); | |
819 CHECK_NUMBER (fromchar, 2); | |
820 CHECK_NUMBER (tochar, 3); | |
821 | |
822 pos = XINT (start); | |
823 stop = XINT (end); | |
824 look = XINT (fromchar); | |
825 | |
826 modify_region (pos, stop); | |
488 | 827 if (! NILP (noundo)) |
305 | 828 { |
829 if (MODIFF - 1 == current_buffer->save_modified) | |
830 current_buffer->save_modified++; | |
831 if (MODIFF - 1 == current_buffer->auto_save_modified) | |
832 current_buffer->auto_save_modified++; | |
833 } | |
834 | |
835 while (pos < stop) | |
836 { | |
837 if (FETCH_CHAR (pos) == look) | |
838 { | |
488 | 839 if (NILP (noundo)) |
305 | 840 record_change (pos, 1); |
841 FETCH_CHAR (pos) = XINT (tochar); | |
488 | 842 if (NILP (noundo)) |
305 | 843 signal_after_change (pos, 1, 1); |
844 } | |
845 pos++; | |
846 } | |
847 | |
848 return Qnil; | |
849 } | |
850 | |
851 DEFUN ("translate-region", Ftranslate_region, Stranslate_region, 3, 3, 0, | |
852 "From START to END, translate characters according to TABLE.\n\ | |
853 TABLE is a string; the Nth character in it is the mapping\n\ | |
854 for the character with code N. Returns the number of characters changed.") | |
855 (start, end, table) | |
856 Lisp_Object start; | |
857 Lisp_Object end; | |
858 register Lisp_Object table; | |
859 { | |
860 register int pos, stop; /* Limits of the region. */ | |
861 register unsigned char *tt; /* Trans table. */ | |
862 register int oc; /* Old character. */ | |
863 register int nc; /* New character. */ | |
864 int cnt; /* Number of changes made. */ | |
865 Lisp_Object z; /* Return. */ | |
866 int size; /* Size of translate table. */ | |
867 | |
868 validate_region (&start, &end); | |
869 CHECK_STRING (table, 2); | |
870 | |
871 size = XSTRING (table)->size; | |
872 tt = XSTRING (table)->data; | |
873 | |
874 pos = XINT (start); | |
875 stop = XINT (end); | |
876 modify_region (pos, stop); | |
877 | |
878 cnt = 0; | |
879 for (; pos < stop; ++pos) | |
880 { | |
881 oc = FETCH_CHAR (pos); | |
882 if (oc < size) | |
883 { | |
884 nc = tt[oc]; | |
885 if (nc != oc) | |
886 { | |
887 record_change (pos, 1); | |
888 FETCH_CHAR (pos) = nc; | |
889 signal_after_change (pos, 1, 1); | |
890 ++cnt; | |
891 } | |
892 } | |
893 } | |
894 | |
895 XFASTINT (z) = cnt; | |
896 return (z); | |
897 } | |
898 | |
899 DEFUN ("delete-region", Fdelete_region, Sdelete_region, 2, 2, "r", | |
900 "Delete the text between point and mark.\n\ | |
901 When called from a program, expects two arguments,\n\ | |
902 positions (integers or markers) specifying the stretch to be deleted.") | |
903 (b, e) | |
904 Lisp_Object b, e; | |
905 { | |
906 validate_region (&b, &e); | |
907 del_range (XINT (b), XINT (e)); | |
908 return Qnil; | |
909 } | |
910 | |
911 DEFUN ("widen", Fwiden, Swiden, 0, 0, "", | |
912 "Remove restrictions (narrowing) from current buffer.\n\ | |
913 This allows the buffer's full text to be seen and edited.") | |
914 () | |
915 { | |
916 BEGV = BEG; | |
917 SET_BUF_ZV (current_buffer, Z); | |
918 clip_changed = 1; | |
330 | 919 /* Changing the buffer bounds invalidates any recorded current column. */ |
920 invalidate_current_column (); | |
305 | 921 return Qnil; |
922 } | |
923 | |
924 DEFUN ("narrow-to-region", Fnarrow_to_region, Snarrow_to_region, 2, 2, "r", | |
925 "Restrict editing in this buffer to the current region.\n\ | |
926 The rest of the text becomes temporarily invisible and untouchable\n\ | |
927 but is not deleted; if you save the buffer in a file, the invisible\n\ | |
928 text is included in the file. \\[widen] makes all visible again.\n\ | |
929 See also `save-restriction'.\n\ | |
930 \n\ | |
931 When calling from a program, pass two arguments; positions (integers\n\ | |
932 or markers) bounding the text that should remain visible.") | |
933 (b, e) | |
934 register Lisp_Object b, e; | |
935 { | |
936 register int i; | |
937 | |
938 CHECK_NUMBER_COERCE_MARKER (b, 0); | |
939 CHECK_NUMBER_COERCE_MARKER (e, 1); | |
940 | |
941 if (XINT (b) > XINT (e)) | |
942 { | |
943 i = XFASTINT (b); | |
944 b = e; | |
945 XFASTINT (e) = i; | |
946 } | |
947 | |
948 if (!(BEG <= XINT (b) && XINT (b) <= XINT (e) && XINT (e) <= Z)) | |
949 args_out_of_range (b, e); | |
950 | |
951 BEGV = XFASTINT (b); | |
952 SET_BUF_ZV (current_buffer, XFASTINT (e)); | |
953 if (point < XFASTINT (b)) | |
954 SET_PT (XFASTINT (b)); | |
955 if (point > XFASTINT (e)) | |
956 SET_PT (XFASTINT (e)); | |
957 clip_changed = 1; | |
330 | 958 /* Changing the buffer bounds invalidates any recorded current column. */ |
959 invalidate_current_column (); | |
305 | 960 return Qnil; |
961 } | |
962 | |
963 Lisp_Object | |
964 save_restriction_save () | |
965 { | |
966 register Lisp_Object bottom, top; | |
967 /* Note: I tried using markers here, but it does not win | |
968 because insertion at the end of the saved region | |
969 does not advance mh and is considered "outside" the saved region. */ | |
970 XFASTINT (bottom) = BEGV - BEG; | |
971 XFASTINT (top) = Z - ZV; | |
972 | |
973 return Fcons (Fcurrent_buffer (), Fcons (bottom, top)); | |
974 } | |
975 | |
976 Lisp_Object | |
977 save_restriction_restore (data) | |
978 Lisp_Object data; | |
979 { | |
980 register struct buffer *buf; | |
981 register int newhead, newtail; | |
982 register Lisp_Object tem; | |
983 | |
984 buf = XBUFFER (XCONS (data)->car); | |
985 | |
986 data = XCONS (data)->cdr; | |
987 | |
988 tem = XCONS (data)->car; | |
989 newhead = XINT (tem); | |
990 tem = XCONS (data)->cdr; | |
991 newtail = XINT (tem); | |
992 if (newhead + newtail > BUF_Z (buf) - BUF_BEG (buf)) | |
993 { | |
994 newhead = 0; | |
995 newtail = 0; | |
996 } | |
997 BUF_BEGV (buf) = BUF_BEG (buf) + newhead; | |
998 SET_BUF_ZV (buf, BUF_Z (buf) - newtail); | |
999 clip_changed = 1; | |
1000 | |
1001 /* If point is outside the new visible range, move it inside. */ | |
1002 SET_BUF_PT (buf, | |
1003 clip_to_bounds (BUF_BEGV (buf), BUF_PT (buf), BUF_ZV (buf))); | |
1004 | |
1005 return Qnil; | |
1006 } | |
1007 | |
1008 DEFUN ("save-restriction", Fsave_restriction, Ssave_restriction, 0, UNEVALLED, 0, | |
1009 "Execute BODY, saving and restoring current buffer's restrictions.\n\ | |
1010 The buffer's restrictions make parts of the beginning and end invisible.\n\ | |
1011 \(They are set up with `narrow-to-region' and eliminated with `widen'.)\n\ | |
1012 This special form, `save-restriction', saves the current buffer's restrictions\n\ | |
1013 when it is entered, and restores them when it is exited.\n\ | |
1014 So any `narrow-to-region' within BODY lasts only until the end of the form.\n\ | |
1015 The old restrictions settings are restored\n\ | |
1016 even in case of abnormal exit (throw or error).\n\ | |
1017 \n\ | |
1018 The value returned is the value of the last form in BODY.\n\ | |
1019 \n\ | |
1020 `save-restriction' can get confused if, within the BODY, you widen\n\ | |
1021 and then make changes outside the area within the saved restrictions.\n\ | |
1022 \n\ | |
1023 Note: if you are using both `save-excursion' and `save-restriction',\n\ | |
1024 use `save-excursion' outermost:\n\ | |
1025 (save-excursion (save-restriction ...))") | |
1026 (body) | |
1027 Lisp_Object body; | |
1028 { | |
1029 register Lisp_Object val; | |
1030 int count = specpdl_ptr - specpdl; | |
1031 | |
1032 record_unwind_protect (save_restriction_restore, save_restriction_save ()); | |
1033 val = Fprogn (body); | |
1034 return unbind_to (count, val); | |
1035 } | |
1036 | |
1037 DEFUN ("message", Fmessage, Smessage, 1, MANY, 0, | |
1038 "Print a one-line message at the bottom of the screen.\n\ | |
1039 The first argument is a control string.\n\ | |
1040 It may contain %s or %d or %c to print successive following arguments.\n\ | |
1041 %s means print an argument as a string, %d means print as number in decimal,\n\ | |
1042 %c means print a number as a single character.\n\ | |
1043 The argument used by %s must be a string or a symbol;\n\ | |
1044 the argument used by %d or %c must be a number.") | |
1045 (nargs, args) | |
1046 int nargs; | |
1047 Lisp_Object *args; | |
1048 { | |
1049 register Lisp_Object val; | |
1050 | |
1051 val = Fformat (nargs, args); | |
1052 message ("%s", XSTRING (val)->data); | |
1053 return val; | |
1054 } | |
1055 | |
1056 DEFUN ("format", Fformat, Sformat, 1, MANY, 0, | |
1057 "Format a string out of a control-string and arguments.\n\ | |
1058 The first argument is a control string.\n\ | |
1059 The other arguments are substituted into it to make the result, a string.\n\ | |
1060 It may contain %-sequences meaning to substitute the next argument.\n\ | |
1061 %s means print a string argument. Actually, prints any object, with `princ'.\n\ | |
1062 %d means print as number in decimal (%o octal, %x hex).\n\ | |
1063 %c means print a number as a single character.\n\ | |
1064 %S means print any object as an s-expression (using prin1).\n\ | |
330 | 1065 The argument used for %d, %o, %x or %c must be a number.\n\ |
1066 Use %% to put a single % into the output.") | |
305 | 1067 (nargs, args) |
1068 int nargs; | |
1069 register Lisp_Object *args; | |
1070 { | |
1071 register int n; /* The number of the next arg to substitute */ | |
1072 register int total = 5; /* An estimate of the final length */ | |
1073 char *buf; | |
1074 register unsigned char *format, *end; | |
1075 int length; | |
1076 extern char *index (); | |
1077 /* It should not be necessary to GCPRO ARGS, because | |
1078 the caller in the interpreter should take care of that. */ | |
1079 | |
1080 CHECK_STRING (args[0], 0); | |
1081 format = XSTRING (args[0])->data; | |
1082 end = format + XSTRING (args[0])->size; | |
1083 | |
1084 n = 0; | |
1085 while (format != end) | |
1086 if (*format++ == '%') | |
1087 { | |
1088 int minlen; | |
1089 | |
1090 /* Process a numeric arg and skip it. */ | |
1091 minlen = atoi (format); | |
1092 if (minlen > 0) | |
1093 total += minlen; | |
1094 else | |
1095 total -= minlen; | |
1096 while ((*format >= '0' && *format <= '9') | |
1097 || *format == '-' || *format == ' ' || *format == '.') | |
1098 format++; | |
1099 | |
1100 if (*format == '%') | |
1101 format++; | |
1102 else if (++n >= nargs) | |
1103 ; | |
1104 else if (*format == 'S') | |
1105 { | |
1106 /* For `S', prin1 the argument and then treat like a string. */ | |
1107 register Lisp_Object tem; | |
1108 tem = Fprin1_to_string (args[n], Qnil); | |
1109 args[n] = tem; | |
1110 goto string; | |
1111 } | |
1112 else if (XTYPE (args[n]) == Lisp_Symbol) | |
1113 { | |
1114 XSET (args[n], Lisp_String, XSYMBOL (args[n])->name); | |
1115 goto string; | |
1116 } | |
1117 else if (XTYPE (args[n]) == Lisp_String) | |
1118 { | |
1119 string: | |
1120 total += XSTRING (args[n])->size; | |
1121 } | |
1122 /* Would get MPV otherwise, since Lisp_Int's `point' to low memory. */ | |
1123 else if (XTYPE (args[n]) == Lisp_Int && *format != 's') | |
1124 { | |
621 | 1125 #ifdef LISP_FLOAT_TYPE |
305 | 1126 /* The following loop issumes the Lisp type indicates |
1127 the proper way to pass the argument. | |
1128 So make sure we have a flonum if the argument should | |
1129 be a double. */ | |
1130 if (*format == 'e' || *format == 'f' || *format == 'g') | |
1131 args[n] = Ffloat (args[n]); | |
621 | 1132 #endif |
305 | 1133 total += 10; |
1134 } | |
621 | 1135 #ifdef LISP_FLOAT_TYPE |
305 | 1136 else if (XTYPE (args[n]) == Lisp_Float && *format != 's') |
1137 { | |
1138 if (! (*format == 'e' || *format == 'f' || *format == 'g')) | |
1139 args[n] = Ftruncate (args[n]); | |
1140 total += 20; | |
1141 } | |
621 | 1142 #endif |
305 | 1143 else |
1144 { | |
1145 /* Anything but a string, convert to a string using princ. */ | |
1146 register Lisp_Object tem; | |
1147 tem = Fprin1_to_string (args[n], Qt); | |
1148 args[n] = tem; | |
1149 goto string; | |
1150 } | |
1151 } | |
1152 | |
1153 { | |
1154 register int nstrings = n + 1; | |
1155 register unsigned char **strings | |
1156 = (unsigned char **) alloca (nstrings * sizeof (unsigned char *)); | |
1157 | |
1158 for (n = 0; n < nstrings; n++) | |
1159 { | |
1160 if (n >= nargs) | |
1161 strings[n] = (unsigned char *) ""; | |
1162 else if (XTYPE (args[n]) == Lisp_Int) | |
1163 /* We checked above that the corresponding format effector | |
1164 isn't %s, which would cause MPV. */ | |
1165 strings[n] = (unsigned char *) XINT (args[n]); | |
621 | 1166 #ifdef LISP_FLOAT_TYPE |
305 | 1167 else if (XTYPE (args[n]) == Lisp_Float) |
1168 { | |
1169 union { double d; int half[2]; } u; | |
1170 | |
1171 u.d = XFLOAT (args[n])->data; | |
1172 strings[n++] = (unsigned char *) u.half[0]; | |
1173 strings[n] = (unsigned char *) u.half[1]; | |
1174 } | |
621 | 1175 #endif |
305 | 1176 else |
1177 strings[n] = XSTRING (args[n])->data; | |
1178 } | |
1179 | |
1180 /* Format it in bigger and bigger buf's until it all fits. */ | |
1181 while (1) | |
1182 { | |
1183 buf = (char *) alloca (total + 1); | |
1184 buf[total - 1] = 0; | |
1185 | |
1186 length = doprnt (buf, total + 1, strings[0], end, nargs, strings + 1); | |
1187 if (buf[total - 1] == 0) | |
1188 break; | |
1189 | |
1190 total *= 2; | |
1191 } | |
1192 } | |
1193 | |
1194 /* UNGCPRO; */ | |
1195 return make_string (buf, length); | |
1196 } | |
1197 | |
1198 /* VARARGS 1 */ | |
1199 Lisp_Object | |
1200 #ifdef NO_ARG_ARRAY | |
1201 format1 (string1, arg0, arg1, arg2, arg3, arg4) | |
1202 int arg0, arg1, arg2, arg3, arg4; | |
1203 #else | |
1204 format1 (string1) | |
1205 #endif | |
1206 char *string1; | |
1207 { | |
1208 char buf[100]; | |
1209 #ifdef NO_ARG_ARRAY | |
1210 int args[5]; | |
1211 args[0] = arg0; | |
1212 args[1] = arg1; | |
1213 args[2] = arg2; | |
1214 args[3] = arg3; | |
1215 args[4] = arg4; | |
1216 doprnt (buf, sizeof buf, string1, 0, 5, args); | |
1217 #else | |
1218 doprnt (buf, sizeof buf, string1, 0, 5, &string1 + 1); | |
1219 #endif | |
1220 return build_string (buf); | |
1221 } | |
1222 | |
1223 DEFUN ("char-equal", Fchar_equal, Schar_equal, 2, 2, 0, | |
1224 "Return t if two characters match, optionally ignoring case.\n\ | |
1225 Both arguments must be characters (i.e. integers).\n\ | |
1226 Case is ignored if `case-fold-search' is non-nil in the current buffer.") | |
1227 (c1, c2) | |
1228 register Lisp_Object c1, c2; | |
1229 { | |
1230 unsigned char *downcase = DOWNCASE_TABLE; | |
1231 CHECK_NUMBER (c1, 0); | |
1232 CHECK_NUMBER (c2, 1); | |
1233 | |
488 | 1234 if (!NILP (current_buffer->case_fold_search) |
305 | 1235 ? downcase[0xff & XFASTINT (c1)] == downcase[0xff & XFASTINT (c2)] |
1236 : XINT (c1) == XINT (c2)) | |
1237 return Qt; | |
1238 return Qnil; | |
1239 } | |
1240 | |
1241 | |
1242 void | |
1243 syms_of_editfns () | |
1244 { | |
1245 DEFVAR_LISP ("system-name", &Vsystem_name, | |
1246 "The name of the machine Emacs is running on."); | |
1247 | |
1248 DEFVAR_LISP ("user-full-name", &Vuser_full_name, | |
1249 "The full name of the user logged in."); | |
1250 | |
1251 DEFVAR_LISP ("user-name", &Vuser_name, | |
1252 "The user's name, based on the effective uid."); | |
1253 | |
1254 DEFVAR_LISP ("user-real-name", &Vuser_real_name, | |
1255 "The user's name, base upon the real uid."); | |
1256 | |
1257 defsubr (&Schar_equal); | |
1258 defsubr (&Sgoto_char); | |
1259 defsubr (&Sstring_to_char); | |
1260 defsubr (&Schar_to_string); | |
1261 defsubr (&Sbuffer_substring); | |
1262 defsubr (&Sbuffer_string); | |
1263 | |
1264 defsubr (&Spoint_marker); | |
1265 defsubr (&Smark_marker); | |
1266 defsubr (&Spoint); | |
1267 defsubr (&Sregion_beginning); | |
1268 defsubr (&Sregion_end); | |
1269 /* defsubr (&Smark); */ | |
1270 /* defsubr (&Sset_mark); */ | |
1271 defsubr (&Ssave_excursion); | |
1272 | |
1273 defsubr (&Sbufsize); | |
1274 defsubr (&Spoint_max); | |
1275 defsubr (&Spoint_min); | |
1276 defsubr (&Spoint_min_marker); | |
1277 defsubr (&Spoint_max_marker); | |
1278 | |
1279 defsubr (&Sbobp); | |
1280 defsubr (&Seobp); | |
1281 defsubr (&Sbolp); | |
1282 defsubr (&Seolp); | |
512 | 1283 defsubr (&Sfollowing_char); |
1284 defsubr (&Sprevious_char); | |
305 | 1285 defsubr (&Schar_after); |
1286 defsubr (&Sinsert); | |
1287 defsubr (&Sinsert_before_markers); | |
1288 defsubr (&Sinsert_char); | |
1289 | |
1290 defsubr (&Suser_login_name); | |
1291 defsubr (&Suser_real_login_name); | |
1292 defsubr (&Suser_uid); | |
1293 defsubr (&Suser_real_uid); | |
1294 defsubr (&Suser_full_name); | |
448 | 1295 defsubr (&Scurrent_time); |
305 | 1296 defsubr (&Scurrent_time_string); |
962
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
1297 defsubr (&Scurrent_time_zone); |
305 | 1298 defsubr (&Ssystem_name); |
1299 defsubr (&Smessage); | |
1300 defsubr (&Sformat); | |
1301 | |
1302 defsubr (&Sinsert_buffer_substring); | |
1303 defsubr (&Ssubst_char_in_region); | |
1304 defsubr (&Stranslate_region); | |
1305 defsubr (&Sdelete_region); | |
1306 defsubr (&Swiden); | |
1307 defsubr (&Snarrow_to_region); | |
1308 defsubr (&Ssave_restriction); | |
1309 } |