0
|
1 /* Lisp functions pertaining to editing.
|
|
2 Copyright (C) 1985-1987, 1989, 1992-1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
|
|
4 Copyright (C) 1996 Ben Wing.
|
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: Mule 2.0, FSF 19.30. */
|
|
24
|
|
25 /* This file has been Mule-ized. */
|
|
26
|
|
27 /* Hacked on for Mule by Ben Wing, December 1994. */
|
|
28
|
|
29 #include <config.h>
|
|
30 #include "lisp.h"
|
|
31
|
|
32 #include "buffer.h"
|
|
33 #include "commands.h"
|
|
34 #include "events.h" /* for EVENTP */
|
|
35 #include "extents.h"
|
|
36 #include "frame.h"
|
|
37 #include "insdel.h"
|
|
38 #include "window.h"
|
|
39
|
|
40 #include "systime.h"
|
|
41 #include "sysdep.h"
|
|
42 #include "syspwd.h"
|
|
43
|
|
44 /* Some static data, and a function to initialize it for each run */
|
|
45
|
|
46 Lisp_Object Vsystem_name; /* #### - I don't see why this should be */
|
|
47 /* static, either... --Stig */
|
|
48 #if 0 /* XEmacs - this is now dynamic */
|
|
49 /* if at some point it's deemed desirable to
|
|
50 use lisp variables here, then they can be
|
|
51 initialized to nil and then set to their
|
|
52 real values upon the first call to the
|
|
53 functions that generate them. --stig */
|
|
54 Lisp_Object Vuser_real_login_name; /* login name of current user ID */
|
|
55 Lisp_Object Vuser_full_name; /* full name of current user */
|
|
56 Lisp_Object Vuser_login_name; /* user name from LOGNAME or USER. */
|
|
57 #endif
|
|
58
|
|
59 extern char *get_system_name (void);
|
|
60
|
|
61 Lisp_Object Qformat;
|
|
62
|
|
63 Lisp_Object Qpoint, Qmark, Qregion_beginning, Qregion_end;
|
|
64
|
|
65 /* This holds the value of `environ' produced by the previous
|
|
66 call to Fset_time_zone_rule, or 0 if Fset_time_zone_rule
|
|
67 has never been called. */
|
|
68 static char **environbuf;
|
|
69
|
|
70 void
|
|
71 init_editfns (void)
|
|
72 {
|
|
73 /* Only used in removed code below. */
|
|
74 #if 0
|
|
75 char *user_name;
|
|
76 Bufbyte *p, *q;
|
|
77 struct passwd *pw; /* password entry for the current user */
|
|
78 Lisp_Object tem;
|
|
79 #endif
|
|
80
|
|
81 environbuf = 0;
|
|
82
|
|
83 /* Set up system_name even when dumping. */
|
|
84 init_system_name ();
|
|
85
|
|
86 #if 0 /* this is now dynamic */
|
|
87 /* don't lose utterly if someone uses these during loadup. */
|
|
88 Vuser_real_login_name = Qnil;
|
|
89 Vuser_login_name = Qnil;
|
|
90 Vuser_full_name = Qnil;
|
|
91
|
|
92 #ifndef CANNOT_DUMP
|
|
93 /* Don't bother with this on initial start when just dumping out */
|
|
94 if (!initialized)
|
|
95 return;
|
|
96 #endif /* not CANNOT_DUMP */
|
|
97
|
|
98 pw = (struct passwd *) getpwuid (getuid ());
|
|
99 #ifdef MSDOS
|
|
100 /* We let the real user name default to "root" because that's quite
|
|
101 accurate on MSDOG and because it lets Emacs find the init file.
|
|
102 (The DVX libraries override the Djgpp libraries here.) */
|
|
103 Vuser_real_login_name = build_string (pw ? pw->pw_name : "root");
|
|
104 #else
|
|
105 Vuser_real_login_name = build_string (pw ? pw->pw_name : "unknown");
|
|
106 #endif
|
|
107
|
|
108 /* Get the effective user name, by consulting environment variables,
|
|
109 or the effective uid if those are unset. */
|
|
110 user_name = getenv ("LOGNAME");
|
|
111 if (!user_name)
|
|
112 #ifdef WINDOWSNT
|
|
113 user_name = (char *) getenv ("USERNAME"); /* it's USERNAME on NT */
|
|
114 #else /* WINDOWSNT */
|
|
115 user_name = (char *) getenv ("USER");
|
|
116 #endif /* WINDOWSNT */
|
|
117 if (!user_name)
|
|
118 {
|
|
119 /* #### - do we really want the EFFECTIVE uid here? Are these flipped? */
|
|
120 /* I ask because LOGNAME and USER vars WILL NOT MATCH the euid. --Stig */
|
|
121 pw = (struct passwd *) getpwuid (geteuid ());
|
|
122 user_name = (char *) (pw ? pw->pw_name : "unknown");
|
|
123 }
|
|
124 Vuser_login_name = build_string (user_name);
|
|
125
|
|
126 /* If the user name claimed in the environment vars differs from
|
|
127 the real uid, use the claimed name to find the full name. */
|
|
128 tem = Fstring_equal (Vuser_login_name, Vuser_real_login_name);
|
|
129 if (NILP (tem))
|
|
130 {
|
|
131 /* Jamie reports that IRIX gets wedged by SIGIO/SIGALARM occurring
|
|
132 in select(), called from getpwnam(). */
|
|
133 slow_down_interrupts ();
|
|
134 pw = (struct passwd *)
|
14
|
135 getpwnam ((char *) XSTRING_DATA (Vuser_login_name));
|
0
|
136 speed_up_interrupts ();
|
|
137 }
|
|
138
|
|
139 p = (Bufbyte *) ((pw) ? USER_FULL_NAME : "unknown"); /* don't gettext here */
|
|
140 q = (Bufbyte *) strchr ((char *) p, ',');
|
|
141 Vuser_full_name = make_ext_string (p, (q ? q - p : strlen ((char *) p)),
|
|
142 FORMAT_OS);
|
|
143
|
|
144 #ifdef AMPERSAND_FULL_NAME
|
14
|
145 p = XSTRING_DATA (Vuser_full_name);
|
0
|
146 q = (Bufbyte *) strchr ((char *) p, '&');
|
|
147 /* Substitute the login name for the &, upcasing the first character. */
|
|
148 if (q)
|
|
149 {
|
|
150 char *r = (char *)
|
14
|
151 alloca (strlen ((char *) p) + XSTRING_LENGTH (Vuser_login_name) + 1);
|
0
|
152 Charcount fullname_off = bytecount_to_charcount (p, q - p);
|
|
153 memcpy (r, p, q - p);
|
|
154 r[q - p] = 0;
|
14
|
155 strcat (r, (char *) XSTRING_DATA (Vuser_login_name));
|
0
|
156 strcat (r, q + 1);
|
|
157 Vuser_full_name = build_string (r);
|
|
158 set_string_char (XSTRING (Vuser_full_name), fullname_off,
|
|
159 UPCASE (current_buffer,
|
|
160 string_char (XSTRING (Vuser_full_name),
|
|
161 fullname_off)));
|
|
162 }
|
|
163 #endif /* AMPERSAND_FULL_NAME */
|
|
164
|
|
165 p = (Bufbyte *) getenv ("NAME");
|
|
166 if (p)
|
|
167 Vuser_full_name = build_string ((char *) p);
|
|
168 #endif /* 0 */
|
|
169 }
|
|
170
|
|
171 DEFUN ("char-to-string", Fchar_to_string, Schar_to_string, 1, 1, 0 /*
|
|
172 Convert arg CH to a one-character string containing that character.
|
|
173 */ )
|
|
174 (ch)
|
|
175 Lisp_Object ch;
|
|
176 {
|
|
177 Bytecount len;
|
|
178 Bufbyte str[MAX_EMCHAR_LEN];
|
|
179
|
|
180 if (EVENTP (ch))
|
|
181 {
|
|
182 Lisp_Object ch2 = Fevent_to_character (ch, Qt, Qnil, Qnil);
|
|
183 if (NILP (ch2))
|
|
184 return
|
|
185 signal_simple_continuable_error
|
|
186 ("character has no ASCII equivalent:", Fcopy_event (ch, Qnil));
|
|
187 ch = ch2;
|
|
188 }
|
|
189
|
|
190 CHECK_CHAR_COERCE_INT (ch);
|
|
191
|
|
192 len = set_charptr_emchar (str, XCHAR (ch));
|
|
193 return make_string (str, len);
|
|
194 }
|
|
195
|
|
196 DEFUN ("string-to-char", Fstring_to_char, Sstring_to_char, 1, 1, 0 /*
|
|
197 Convert arg STRING to a character, the first character of that string.
|
|
198 */ )
|
|
199 (str)
|
|
200 Lisp_Object str;
|
|
201 {
|
|
202 struct Lisp_String *p;
|
|
203 CHECK_STRING (str);
|
|
204
|
|
205 p = XSTRING (str);
|
|
206 if (string_length (p) != 0)
|
|
207 {
|
|
208 return (make_char (string_char (p, 0)));
|
|
209 }
|
|
210 else /* #### Gag me! */
|
|
211 return (Qzero);
|
|
212 }
|
|
213
|
|
214
|
|
215 static Lisp_Object
|
|
216 buildmark (Bufpos val, Lisp_Object buffer)
|
|
217 {
|
|
218 Lisp_Object mark;
|
|
219 mark = Fmake_marker ();
|
|
220 Fset_marker (mark, make_int (val), buffer);
|
|
221 return mark;
|
|
222 }
|
|
223
|
|
224 DEFUN ("point", Fpoint, Spoint, 0, 1, 0 /*
|
|
225 Return value of point, as an integer.
|
|
226 Beginning of buffer is position (point-min).
|
|
227 If BUFFER is nil, the current buffer is assumed.
|
|
228 */ )
|
|
229 (buffer)
|
|
230 Lisp_Object buffer;
|
|
231 {
|
|
232 struct buffer *b = decode_buffer (buffer, 1);
|
|
233 return (make_int (BUF_PT (b)));
|
|
234 }
|
|
235
|
|
236 DEFUN ("point-marker", Fpoint_marker, Spoint_marker, 0, 2, 0 /*
|
|
237 Return value of point, as a marker object.
|
|
238 This marker is a copy; you may modify it with reckless abandon.
|
|
239 If optional argument DONT-COPY-P is non-nil, then it returns the real
|
|
240 point-marker; modifying the position of this marker will move point.
|
|
241 It is illegal to change the buffer of it, or make it point nowhere.
|
|
242 If BUFFER is nil, the current buffer is assumed.
|
|
243 */ )
|
|
244 (dont_copy_p, buffer)
|
|
245 Lisp_Object dont_copy_p, buffer;
|
|
246 {
|
|
247 struct buffer *b = decode_buffer (buffer, 1);
|
|
248 if (NILP (dont_copy_p))
|
|
249 return Fcopy_marker (b->point_marker, Qnil);
|
|
250 return b->point_marker;
|
|
251 }
|
|
252
|
|
253 /* The following two functions end up being identical but it's
|
|
254 cleaner to declare them separately. */
|
|
255
|
|
256 Bufpos
|
|
257 bufpos_clip_to_bounds (Bufpos lower, Bufpos num, Bufpos upper)
|
|
258 {
|
|
259 if (num < lower)
|
|
260 return lower;
|
|
261 else if (num > upper)
|
|
262 return upper;
|
|
263 else
|
|
264 return num;
|
|
265 }
|
|
266
|
|
267 Bytind
|
|
268 bytind_clip_to_bounds (Bytind lower, Bytind num, Bytind upper)
|
|
269 {
|
|
270 if (num < lower)
|
|
271 return lower;
|
|
272 else if (num > upper)
|
|
273 return upper;
|
|
274 else
|
|
275 return num;
|
|
276 }
|
|
277
|
|
278 /*
|
|
279 * Chuck says:
|
|
280 * There is no absolute way to determine if goto-char is the function
|
|
281 * being run. this-command doesn't work because it is often eval'd
|
|
282 * and this-command ends up set to eval-expression. So this flag gets
|
|
283 * added for now.
|
|
284 *
|
|
285 * Jamie thinks he's wrong, but we'll leave this in for now.
|
|
286 */
|
|
287 int atomic_extent_goto_char_p;
|
|
288
|
|
289 DEFUN ("goto-char", Fgoto_char, Sgoto_char, 1, 2, "NGoto char: " /*
|
|
290 Set point to POSITION, a number or marker.
|
|
291 Beginning of buffer is position (point-min), end is (point-max).
|
|
292 If BUFFER is nil, the current buffer is assumed.
|
|
293 Return value of POSITION, as an integer.
|
|
294 */ )
|
|
295 (position, buffer)
|
|
296 Lisp_Object position, buffer;
|
|
297 {
|
|
298 struct buffer *b = decode_buffer (buffer, 1);
|
|
299 Bufpos n = get_buffer_pos_char (b, position, GB_COERCE_RANGE);
|
|
300 BUF_SET_PT (b, n);
|
|
301 atomic_extent_goto_char_p = 1;
|
|
302 return (make_int (n));
|
|
303 }
|
|
304
|
|
305 static Lisp_Object
|
|
306 region_limit (int beginningp, struct buffer *b)
|
|
307 {
|
|
308 Lisp_Object m;
|
|
309
|
|
310 #if 0 /* FSFmacs */
|
|
311 if (!NILP (Vtransient_mark_mode) && NILP (Vmark_even_if_inactive)
|
|
312 && NILP (b->mark_active))
|
|
313 Fsignal (Qmark_inactive, Qnil);
|
|
314 #endif
|
|
315 m = Fmarker_position (b->mark);
|
|
316 if (NILP (m)) error ("There is no region now");
|
|
317 if (!!(BUF_PT (b) < XINT (m)) == !!beginningp)
|
|
318 return (make_int (BUF_PT (b)));
|
|
319 else
|
|
320 return (m);
|
|
321 }
|
|
322
|
|
323 DEFUN ("region-beginning", Fregion_beginning, Sregion_beginning, 0, 1, 0 /*
|
|
324 Return position of beginning of region, as an integer.
|
|
325 If BUFFER is nil, the current buffer is assumed.
|
|
326 */ )
|
|
327 (buffer)
|
|
328 Lisp_Object buffer;
|
|
329 {
|
|
330 return (region_limit (1, decode_buffer (buffer, 1)));
|
|
331 }
|
|
332
|
|
333 DEFUN ("region-end", Fregion_end, Sregion_end, 0, 1, 0 /*
|
|
334 Return position of end of region, as an integer.
|
|
335 If BUFFER is nil, the current buffer is assumed.
|
|
336 */ )
|
|
337 (buffer)
|
|
338 Lisp_Object buffer;
|
|
339 {
|
|
340 return (region_limit (0, decode_buffer (buffer, 1)));
|
|
341 }
|
|
342
|
|
343 /* Whether to use lispm-style active-regions */
|
|
344 int zmacs_regions;
|
|
345
|
|
346 /* Whether the zmacs region is active. This is not per-buffer because
|
|
347 there can be only one active region at a time. #### Now that the
|
|
348 zmacs region are not directly tied to the X selections this may not
|
|
349 necessarily have to be true. */
|
|
350 int zmacs_region_active_p;
|
|
351
|
|
352 int zmacs_region_stays;
|
|
353
|
|
354 Lisp_Object Qzmacs_update_region, Qzmacs_deactivate_region;
|
|
355 Lisp_Object Qzmacs_region_buffer;
|
|
356
|
|
357 void
|
|
358 zmacs_update_region (void)
|
|
359 {
|
|
360 /* This function can GC */
|
|
361 if (zmacs_region_active_p)
|
|
362 call0 (Qzmacs_update_region);
|
|
363 }
|
|
364
|
|
365 void
|
|
366 zmacs_deactivate_region (void)
|
|
367 {
|
|
368 /* This function can GC */
|
|
369 if (zmacs_region_active_p)
|
|
370 call0 (Qzmacs_deactivate_region);
|
|
371 }
|
|
372
|
|
373 Lisp_Object
|
|
374 zmacs_region_buffer (void)
|
|
375 {
|
|
376 if (zmacs_region_active_p)
|
|
377 return call0 (Qzmacs_region_buffer);
|
|
378 else
|
|
379 return Qnil;
|
|
380 }
|
|
381
|
|
382 DEFUN ("mark-marker", Fmark_marker, Smark_marker, 0, 2, 0 /*
|
|
383 Return this buffer's mark, as a marker object.
|
|
384 If `zmacs-regions' is true, then this returns nil unless the region is
|
|
385 currently in the active (highlighted) state. If optional argument FORCE
|
|
386 is t, this returns the mark (if there is one) regardless of the zmacs-region
|
|
387 state. You should *generally* not use the mark unless the region is active,
|
|
388 if the user has expressed a preference for the zmacs-region model.
|
|
389 Watch out! Moving this marker changes the mark position.
|
|
390 If you set the marker not to point anywhere, the buffer will have no mark.
|
|
391 If BUFFER is nil, the current buffer is assumed.
|
|
392 */ )
|
|
393 (force, buffer)
|
|
394 Lisp_Object force, buffer;
|
|
395 {
|
|
396 struct buffer *b = decode_buffer (buffer, 1);
|
|
397 if (! zmacs_regions || zmacs_region_active_p || !NILP (force))
|
|
398 return b->mark;
|
|
399 return Qnil;
|
|
400 }
|
|
401
|
|
402
|
|
403 /* The saved object looks like this:
|
|
404
|
|
405 (COPY-OF-POINT-MARKER . (COPY-OF-MARK . VISIBLE-P))
|
|
406
|
|
407 where
|
|
408
|
|
409 VISIBLE-P is t if `(eq (current-buffer) (window-buffer (selected-window)))'
|
|
410 but is not actually used any more.
|
|
411 */
|
|
412 Lisp_Object
|
|
413 save_excursion_save (void)
|
|
414 {
|
|
415 struct buffer *b;
|
|
416 int visible;
|
|
417 Lisp_Object tem;
|
|
418
|
|
419 if (preparing_for_armageddon)
|
|
420 return Qnil;
|
|
421 else
|
|
422 {
|
|
423 b = current_buffer;
|
|
424 visible = (XBUFFER (XWINDOW (Fselected_window (Qnil))->buffer) == b);
|
|
425 tem = ((visible) ? Qt : Qnil);
|
|
426 }
|
|
427
|
|
428 #ifdef ERROR_CHECK_BUFPOS
|
|
429 assert (XINT (Fpoint (Qnil)) ==
|
|
430 XINT (Fmarker_position (Fpoint_marker (Qt, Qnil))));
|
|
431 #endif
|
|
432
|
|
433 #if 0 /* FSFmacs */
|
|
434 tem = Fcons (tem, b->mark_active);
|
|
435 #endif
|
|
436
|
|
437 return noseeum_cons (noseeum_copy_marker (Fpoint_marker (Qt, Qnil), Qnil),
|
|
438 noseeum_cons (noseeum_copy_marker (b->mark, Qnil),
|
|
439 tem));
|
|
440 }
|
|
441
|
|
442 Lisp_Object
|
|
443 save_excursion_restore (Lisp_Object info)
|
|
444 {
|
|
445 Lisp_Object tem;
|
|
446 int visible;
|
|
447 struct gcpro gcpro1, gcpro2;
|
|
448
|
|
449 tem = Fmarker_buffer (Fcar (info));
|
|
450 /* If buffer being returned to is now deleted, avoid error */
|
|
451 /* Otherwise could get error here while unwinding to top level
|
|
452 and crash */
|
|
453 /* In that case, Fmarker_buffer returns nil now. */
|
|
454 if (NILP (tem))
|
|
455 return Qnil;
|
|
456 /* Need gcpro in case Lisp hooks get run */
|
|
457 GCPRO2 (info, tem);
|
|
458 Fset_buffer (tem);
|
|
459 tem = Fcar (info);
|
|
460 Fgoto_char (tem, Fcurrent_buffer ());
|
|
461 tem = Fcar (Fcdr (info));
|
|
462 Fset_marker (current_buffer->mark, tem, Fcurrent_buffer ());
|
|
463 tem = Fcdr (Fcdr (info));
|
|
464 visible = !NILP (tem);
|
|
465
|
|
466 #if 0 /* We used to make the current buffer visible in the selected window
|
|
467 if that was true previously. That avoids some anomalies.
|
|
468 But it creates others, and it wasn't documented, and it is simpler
|
|
469 and cleaner never to alter the window/buffer connections. */
|
|
470 /* #### I'm certain some code somewhere depends on this behavior. --jwz */
|
|
471
|
|
472 if (visible
|
|
473 && (current_buffer != XBUFFER (XWINDOW (selected_window)->buffer)))
|
|
474 switch_to_buffer (Fcurrent_buffer (), Qnil);
|
|
475 #endif
|
|
476
|
|
477 UNGCPRO;
|
|
478 /* Free all the junk we allocated, so that a `save-excursion' comes
|
|
479 for free in terms of GC junk. */
|
|
480 free_marker (XMARKER (XCAR (info)));
|
|
481 free_marker (XMARKER (XCAR (XCDR (info))));
|
|
482 free_cons (XCONS (XCDR (info)));
|
|
483 free_cons (XCONS (info));
|
|
484 return Qnil;
|
|
485 }
|
|
486
|
|
487 DEFUN ("save-excursion", Fsave_excursion, Ssave_excursion, 0, UNEVALLED, 0 /*
|
|
488 Save point, mark, and current buffer; execute BODY; restore those things.
|
|
489 Executes BODY just like `progn'.
|
|
490 The values of point, mark and the current buffer are restored
|
|
491 even in case of abnormal exit (throw or error).
|
|
492 */ )
|
|
493 (args)
|
|
494 Lisp_Object args;
|
|
495 {
|
|
496 /* This function can GC */
|
|
497 int speccount = specpdl_depth ();
|
|
498
|
|
499 record_unwind_protect (save_excursion_restore, save_excursion_save ());
|
|
500
|
|
501 return unbind_to (speccount, Fprogn (args));
|
|
502 }
|
|
503
|
|
504 DEFUN ("buffer-size", Fbufsize, Sbufsize, 0, 1, 0 /*
|
|
505 Return the number of characters in BUFFER.
|
|
506 If BUFFER is nil, the current buffer is assumed.
|
|
507 */ )
|
|
508 (buffer)
|
|
509 Lisp_Object buffer;
|
|
510 {
|
|
511 struct buffer *b = decode_buffer (buffer, 1);
|
|
512 return (make_int (BUF_SIZE (b)));
|
|
513 }
|
|
514
|
|
515 DEFUN ("point-min", Fpoint_min, Spoint_min, 0, 1, 0 /*
|
|
516 Return the minimum permissible value of point in BUFFER.
|
|
517 This is 1, unless narrowing (a buffer restriction) is in effect.
|
|
518 If BUFFER is nil, the current buffer is assumed.
|
|
519 */ )
|
|
520 (buffer)
|
|
521 Lisp_Object buffer;
|
|
522 {
|
|
523 struct buffer *b = decode_buffer (buffer, 1);
|
|
524 return (make_int (BUF_BEGV (b)));
|
|
525 }
|
|
526
|
|
527 DEFUN ("point-min-marker", Fpoint_min_marker, Spoint_min_marker, 0, 1, 0 /*
|
|
528 Return a marker to the minimum permissible value of point in BUFFER.
|
|
529 This is the beginning, unless narrowing (a buffer restriction) is in effect.
|
|
530 If BUFFER is nil, the current buffer is assumed.
|
|
531 */ )
|
|
532 (buffer)
|
|
533 Lisp_Object buffer;
|
|
534 {
|
|
535 struct buffer *b = decode_buffer (buffer, 1);
|
|
536 return buildmark (BUF_BEGV (b), make_buffer (b));
|
|
537 }
|
|
538
|
|
539 DEFUN ("point-max", Fpoint_max, Spoint_max, 0, 1, 0 /*
|
|
540 Return the maximum permissible value of point in BUFFER.
|
|
541 This is (1+ (buffer-size)), unless narrowing (a buffer restriction)
|
|
542 is in effect, in which case it is less.
|
|
543 If BUFFER is nil, the current buffer is assumed.
|
|
544 */ )
|
|
545 (buffer)
|
|
546 Lisp_Object buffer;
|
|
547 {
|
|
548 struct buffer *b = decode_buffer (buffer, 1);
|
|
549 return (make_int (BUF_ZV (b)));
|
|
550 }
|
|
551
|
|
552 DEFUN ("point-max-marker", Fpoint_max_marker, Spoint_max_marker, 0, 1, 0 /*
|
|
553 Return a marker to the maximum permissible value of point BUFFER.
|
|
554 This is (1+ (buffer-size)), unless narrowing (a buffer restriction)
|
|
555 is in effect, in which case it is less.
|
|
556 If BUFFER is nil, the current buffer is assumed.
|
|
557 */ )
|
|
558 (buffer)
|
|
559 Lisp_Object buffer;
|
|
560 {
|
|
561 struct buffer *b = decode_buffer (buffer, 1);
|
|
562 return buildmark (BUF_ZV (b), make_buffer (b));
|
|
563 }
|
|
564
|
|
565 DEFUN ("following-char", Ffollowing_char, Sfollowing_char, 0, 1, 0 /*
|
|
566 Return the character following point, as a number.
|
|
567 At the end of the buffer or accessible region, return 0.
|
|
568 If BUFFER is nil, the current buffer is assumed.
|
|
569 */ )
|
|
570 (buffer)
|
|
571 Lisp_Object buffer;
|
|
572 {
|
|
573 struct buffer *b = decode_buffer (buffer, 1);
|
|
574 if (BUF_PT (b) >= BUF_ZV (b))
|
|
575 return (Qzero); /* #### Gag me! */
|
|
576 else
|
|
577 return (make_char (BUF_FETCH_CHAR (b, BUF_PT (b))));
|
|
578 }
|
|
579
|
|
580 DEFUN ("preceding-char", Fpreceding_char, Spreceding_char, 0, 1, 0 /*
|
|
581 Return the character preceding point, as a number.
|
|
582 At the beginning of the buffer or accessible region, return 0.
|
|
583 If BUFFER is nil, the current buffer is assumed.
|
|
584 */ )
|
|
585 (buffer)
|
|
586 Lisp_Object buffer;
|
|
587 {
|
|
588 struct buffer *b = decode_buffer (buffer, 1);
|
|
589 if (BUF_PT (b) <= BUF_BEGV (b))
|
|
590 return (Qzero); /* #### Gag me! */
|
|
591 else
|
|
592 return (make_char (BUF_FETCH_CHAR (b, BUF_PT (b) - 1)));
|
|
593 }
|
|
594
|
|
595 DEFUN ("bobp", Fbobp, Sbobp, 0, 1, 0 /*
|
|
596 Return T if point is at the beginning of the buffer.
|
|
597 If the buffer is narrowed, this means the beginning of the narrowed part.
|
|
598 If BUFFER is nil, the current buffer is assumed.
|
|
599 */ )
|
|
600 (buffer)
|
|
601 Lisp_Object buffer;
|
|
602 {
|
|
603 struct buffer *b = decode_buffer (buffer, 1);
|
14
|
604 return BUF_PT (b) == BUF_BEGV (b) ? Qt : Qnil;
|
0
|
605 }
|
|
606
|
|
607 DEFUN ("eobp", Feobp, Seobp, 0, 1, 0 /*
|
|
608 Return T if point is at the end of the buffer.
|
|
609 If the buffer is narrowed, this means the end of the narrowed part.
|
|
610 If BUFFER is nil, the current buffer is assumed.
|
|
611 */ )
|
|
612 (buffer)
|
|
613 Lisp_Object buffer;
|
|
614 {
|
|
615 struct buffer *b = decode_buffer (buffer, 1);
|
14
|
616 return BUF_PT (b) == BUF_ZV (b) ? Qt : Qnil;
|
0
|
617 }
|
|
618
|
|
619 int
|
|
620 beginning_of_line_p (struct buffer *b, Bufpos pt)
|
|
621 {
|
|
622 if (pt <= BUF_BEGV (b))
|
|
623 return 1;
|
|
624 return BUF_FETCH_CHAR (b, pt - 1) == '\n';
|
|
625 }
|
|
626
|
|
627
|
|
628 DEFUN ("bolp", Fbolp, Sbolp, 0, 1, 0 /*
|
|
629 Return T if point is at the beginning of a line.
|
|
630 If BUFFER is nil, the current buffer is assumed.
|
|
631 */ )
|
|
632 (buffer)
|
|
633 Lisp_Object buffer;
|
|
634 {
|
|
635 struct buffer *b = decode_buffer (buffer, 1);
|
|
636
|
|
637 return beginning_of_line_p (b, BUF_PT (b)) ? Qt : Qnil;
|
|
638 }
|
|
639
|
|
640 DEFUN ("eolp", Feolp, Seolp, 0, 1, 0 /*
|
|
641 Return T if point is at the end of a line.
|
|
642 `End of a line' includes point being at the end of the buffer.
|
|
643 If BUFFER is nil, the current buffer is assumed.
|
|
644 */ )
|
|
645 (buffer)
|
|
646 Lisp_Object buffer;
|
|
647 {
|
|
648 struct buffer *b = decode_buffer (buffer, 1);
|
|
649 if (BUF_PT (b) == BUF_ZV (b) || BUF_FETCH_CHAR (b, BUF_PT (b)) == '\n')
|
|
650 return Qt;
|
|
651 return Qnil;
|
|
652 }
|
|
653
|
|
654 DEFUN ("char-after", Fchar_after, Schar_after, 1, 2, 0 /*
|
|
655 Return character in BUFFER at position POS.
|
|
656 POS is an integer or a buffer pointer.
|
|
657 If POS is out of range, the value is nil.
|
|
658 If BUFFER is nil, the current buffer is assumed.
|
|
659 */ )
|
|
660 (pos, buffer)
|
|
661 Lisp_Object pos, buffer;
|
|
662 {
|
|
663 struct buffer *b = decode_buffer (buffer, 1);
|
|
664 Bufpos n = get_buffer_pos_char (b, pos, GB_NO_ERROR_IF_BAD);
|
|
665
|
|
666 if (n < 0 || n == BUF_ZV (b))
|
|
667 return Qnil;
|
|
668 return (make_char (BUF_FETCH_CHAR (b, n)));
|
|
669 }
|
|
670
|
|
671
|
|
672 DEFUN ("user-login-name", Fuser_login_name, Suser_login_name, 0, 1, 0 /*
|
|
673 Return the name under which the user logged in, as a string.
|
|
674 This is based on the effective uid, not the real uid.
|
|
675 Also, if the environment variable LOGNAME or USER is set,
|
|
676 that determines the value of this function.
|
|
677 If the optional argument UID is present, then environment variables are
|
|
678 ignored and this function returns the login name for that UID, or nil.
|
|
679 */ )
|
|
680 (uid)
|
|
681 Lisp_Object uid;
|
|
682 {
|
|
683 struct passwd *pw = NULL;
|
|
684
|
|
685 if (!NILP (uid))
|
|
686 {
|
|
687 CHECK_INT (uid);
|
|
688 pw = (struct passwd *) getpwuid (XINT (uid));
|
|
689 }
|
|
690 else
|
|
691 {
|
|
692 char *user_name;
|
|
693 /* #### - when euid != uid, then LOGNAME and USER are leftovers from the
|
|
694 old environment (I site observed behavior on sunos and linux), so the
|
|
695 environment variables should be disregarded in that case. --Stig */
|
|
696 user_name = getenv ("LOGNAME");
|
|
697 if (!user_name)
|
|
698 #ifdef WINDOWSNT
|
|
699 user_name = (char *) getenv ("USERNAME"); /* it's USERNAME on NT */
|
|
700 #else /* WINDOWSNT */
|
|
701 user_name = (char *) getenv ("USER");
|
|
702 #endif /* WINDOWSNT */
|
|
703 if (user_name)
|
|
704 return (build_string (user_name));
|
|
705 else
|
|
706 pw = (struct passwd *) getpwuid (geteuid ());
|
|
707 }
|
|
708 /* #### - I believe this should return nil instead of "unknown" when pw==0 */
|
|
709 return (pw ? build_string (pw->pw_name) : Qnil);
|
|
710 }
|
|
711
|
|
712 DEFUN ("user-real-login-name", Fuser_real_login_name, Suser_real_login_name,
|
|
713 0, 0, 0 /*
|
|
714 Return the name of the user's real uid, as a string.
|
|
715 This ignores the environment variables LOGNAME and USER, so it differs from
|
|
716 `user-login-name' when running under `su'.
|
|
717 */ )
|
|
718 ()
|
|
719 {
|
|
720 struct passwd *pw = (struct passwd *) getpwuid (getuid ());
|
|
721 /* #### - I believe this should return nil instead of "unknown" when pw==0 */
|
|
722
|
|
723 #ifdef MSDOS
|
|
724 /* We let the real user name default to "root" because that's quite
|
|
725 accurate on MSDOG and because it lets Emacs find the init file.
|
|
726 (The DVX libraries override the Djgpp libraries here.) */
|
|
727 Lisp_Object tem = build_string (pw ? pw->pw_name : "root");/* no gettext */
|
|
728 #else
|
|
729 Lisp_Object tem = build_string (pw ? pw->pw_name : "unknown");/* no gettext */
|
|
730 #endif
|
|
731 return (tem);
|
|
732 }
|
|
733
|
|
734 DEFUN ("user-uid", Fuser_uid, Suser_uid, 0, 0, 0 /*
|
|
735 Return the effective uid of Emacs, as an integer.
|
|
736 */ )
|
|
737 ()
|
|
738 {
|
|
739 return make_int (geteuid ());
|
|
740 }
|
|
741
|
|
742 DEFUN ("user-real-uid", Fuser_real_uid, Suser_real_uid, 0, 0, 0 /*
|
|
743 Return the real uid of Emacs, as an integer.
|
|
744 */ )
|
|
745 ()
|
|
746 {
|
|
747 return make_int (getuid ());
|
|
748 }
|
|
749
|
|
750 DEFUN ("user-full-name", Fuser_full_name, Suser_full_name, 0, 1, 0 /*
|
|
751 Return the full name of the user logged in, as a string.
|
|
752 If the optional argument USER is given, then the full name for that
|
|
753 user is returned, or nil. USER may be either a login name or a uid.
|
|
754 */ )
|
|
755 (user)
|
|
756 Lisp_Object user;
|
|
757 {
|
|
758 Lisp_Object uname = (STRINGP (user) ? user : Fuser_login_name (user));
|
|
759 struct passwd *pw = NULL;
|
|
760 Lisp_Object tem;
|
|
761 char *p, *q;
|
|
762
|
|
763 if (!NILP (uname)) /* nil when nonexistent UID passed as arg */
|
|
764 {
|
|
765 CONST char *uname_ext;
|
|
766
|
|
767 /* Fuck me. getpwnam() can call select() and (under IRIX at least)
|
|
768 things get wedged if a SIGIO arrives during this time. */
|
|
769 GET_C_STRING_OS_DATA_ALLOCA (uname, uname_ext);
|
|
770 slow_down_interrupts ();
|
|
771 pw = (struct passwd *) getpwnam (uname_ext);
|
|
772 speed_up_interrupts ();
|
|
773 }
|
|
774
|
|
775 /* #### - Stig sez: this should return nil instead of "unknown" when pw==0 */
|
|
776 /* Ben sez: bad idea because it's likely to break something */
|
|
777 #ifndef AMPERSAND_FULL_NAME
|
|
778 p = (char *) ((pw) ? USER_FULL_NAME : "unknown"); /* don't gettext */
|
|
779 q = (char *) strchr ((char *) p, ',');
|
|
780 #else
|
|
781 p = (char *) ((pw) ? USER_FULL_NAME : "unknown"); /* don't gettext */
|
|
782 q = (char *) strchr ((char *) p, ',');
|
|
783 #endif
|
|
784 tem = ((!NILP (user) && !pw)
|
|
785 ? Qnil
|
|
786 : make_ext_string ((unsigned char *) p, (q ? q - p : strlen (p)),
|
|
787 FORMAT_OS));
|
|
788
|
|
789 #ifdef AMPERSAND_FULL_NAME
|
|
790 if (!NILP (tem))
|
|
791 {
|
14
|
792 p = (char *) XSTRING_DATA (tem);
|
0
|
793 q = strchr (p, '&');
|
|
794 /* Substitute the login name for the &, upcasing the first character. */
|
|
795 if (q)
|
|
796 {
|
14
|
797 char *r = (char *) alloca (strlen (p) + XSTRING_LENGTH (uname) + 1);
|
0
|
798 memcpy (r, p, q - p);
|
|
799 r[q - p] = 0;
|
14
|
800 strcat (r, (char *) XSTRING_DATA (uname));
|
0
|
801 /* #### current_buffer dependency! */
|
|
802 r[q - p] = UPCASE (current_buffer, r[q - p]);
|
|
803 strcat (r, q + 1);
|
|
804 tem = build_string (r);
|
|
805 }
|
|
806 }
|
|
807 #endif /* AMPERSAND_FULL_NAME */
|
|
808
|
|
809 p = getenv ("NAME");
|
|
810 if (p)
|
|
811 tem = build_string (p);
|
|
812 return (tem);
|
|
813 }
|
|
814
|
|
815 DEFUN ("system-name", Fsystem_name, Ssystem_name, 0, 0, 0 /*
|
|
816 Return the name of the machine you are running on, as a string.
|
|
817 */ )
|
|
818 ()
|
|
819 {
|
|
820 return (Fcopy_sequence (Vsystem_name));
|
|
821 }
|
|
822
|
|
823 /* For the benefit of callers who don't want to include lisp.h.
|
|
824 Caller must free! */
|
|
825 char *
|
|
826 get_system_name (void)
|
|
827 {
|
14
|
828 return xstrdup ((char *) XSTRING_DATA (Vsystem_name));
|
0
|
829 }
|
|
830
|
|
831 DEFUN ("emacs-pid", Femacs_pid, Semacs_pid, 0, 0, 0 /*
|
|
832 Return the process ID of Emacs, as an integer.
|
|
833 */ )
|
|
834 ()
|
|
835 {
|
|
836 return make_int (getpid ());
|
|
837 }
|
|
838
|
|
839 DEFUN ("current-time", Fcurrent_time, Scurrent_time, 0, 0, 0 /*
|
|
840 Return the current time, as the number of seconds since 1970-01-01 00:00:00.
|
|
841 The time is returned as a list of three integers. The first has the
|
|
842 most significant 16 bits of the seconds, while the second has the
|
|
843 least significant 16 bits. The third integer gives the microsecond
|
|
844 count.
|
|
845
|
|
846 The microsecond count is zero on systems that do not provide
|
|
847 resolution finer than a second.
|
|
848 */ )
|
|
849 ()
|
|
850 {
|
|
851 EMACS_TIME t;
|
|
852 Lisp_Object result[3];
|
|
853
|
|
854 EMACS_GET_TIME (t);
|
|
855 XSETINT (result[0], (EMACS_SECS (t) >> 16) & 0xffff);
|
|
856 XSETINT (result[1], (EMACS_SECS (t) >> 0) & 0xffff);
|
|
857 XSETINT (result[2], EMACS_USECS (t));
|
|
858
|
|
859 return Flist (3, result);
|
|
860 }
|
|
861
|
|
862 DEFUN ("current-process-time", Fcurrent_process_time, Scurrent_process_time,
|
|
863 0, 0, 0 /*
|
|
864 Return the amount of time used by this XEmacs process so far.
|
|
865 The return value is a list of three floating-point numbers, expressing
|
|
866 the user, system, and real times used by the process. The user time
|
|
867 measures the time actually spent by the CPU executing the code in this
|
|
868 process. The system time measures time spent by the CPU executing kernel
|
|
869 code on behalf of this process (e.g. I/O requests made by the process).
|
|
870
|
|
871 Note that the user and system times measure processor time, as opposed
|
|
872 to real time, and only accrue when the processor is actually doing
|
|
873 something: Time spent in an idle wait (waiting for user events to come
|
|
874 in or for I/O on a disk drive or other device to complete) does not
|
|
875 count. Thus, the user and system times will often be considerably
|
|
876 less than the real time.
|
|
877
|
|
878 Some systems do not allow the user and system times to be distinguished.
|
|
879 In this case, the user time will be the total processor time used by
|
|
880 the process, and the system time will be 0.
|
|
881
|
|
882 Some systems do not allow the real and processor times to be distinguished.
|
|
883 In this case, the user and real times will be the same and the system
|
|
884 time will be 0.
|
|
885 */ )
|
|
886 ()
|
|
887 {
|
|
888 double user, sys, real;
|
|
889
|
|
890 get_process_times (&user, &sys, &real);
|
|
891 return list3 (make_float (user), make_float (sys), make_float (real));
|
|
892 }
|
|
893
|
|
894
|
|
895 int
|
|
896 lisp_to_time (Lisp_Object specified_time, time_t *result)
|
|
897 {
|
|
898 if (NILP (specified_time))
|
|
899 return time (result) != -1;
|
|
900 else
|
|
901 {
|
|
902 Lisp_Object high, low;
|
|
903 high = Fcar (specified_time);
|
|
904 CHECK_INT (high);
|
|
905 low = Fcdr (specified_time);
|
|
906 if (CONSP (low))
|
|
907 low = Fcar (low);
|
|
908 CHECK_INT (low);
|
|
909 *result = (XINT (high) << 16) + (XINT (low) & 0xffff);
|
|
910 return *result >> 16 == XINT (high);
|
|
911 }
|
|
912 }
|
|
913
|
|
914 Lisp_Object
|
|
915 time_to_lisp (time_t the_time)
|
|
916 {
|
|
917 unsigned int item = (unsigned int) the_time;
|
|
918 return Fcons (make_int (item >> 16), make_int (item & 0xffff));
|
|
919 }
|
|
920
|
|
921 size_t emacs_strftime (char *string, size_t max, CONST char *format,
|
|
922 CONST struct tm *tm);
|
|
923 static long difftm (CONST struct tm *a, CONST struct tm *b);
|
|
924
|
|
925
|
|
926 DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string,
|
|
927 2, 2, 0 /*
|
|
928 Use FORMAT-STRING to format the time TIME.
|
|
929 TIME is specified as (HIGH LOW . IGNORED) or (HIGH . LOW), as from
|
|
930 `current-time' and `file-attributes'.
|
|
931 FORMAT-STRING may contain %-sequences to substitute parts of the time.
|
|
932 %a is replaced by the abbreviated name of the day of week.
|
|
933 %A is replaced by the full name of the day of week.
|
|
934 %b is replaced by the abbreviated name of the month.
|
|
935 %B is replaced by the full name of the month.
|
|
936 %c is a synonym for \"%x %X\".
|
|
937 %C is a locale-specific synonym, which defaults to \"%A, %B %e, %Y\" in the C locale.
|
|
938 %d is replaced by the day of month, zero-padded.
|
|
939 %D is a synonym for \"%m/%d/%y\".
|
|
940 %e is replaced by the day of month, blank-padded.
|
|
941 %h is a synonym for \"%b\".
|
|
942 %H is replaced by the hour (00-23).
|
|
943 %I is replaced by the hour (00-12).
|
|
944 %j is replaced by the day of the year (001-366).
|
|
945 %k is replaced by the hour (0-23), blank padded.
|
|
946 %l is replaced by the hour (1-12), blank padded.
|
|
947 %m is replaced by the month (01-12).
|
|
948 %M is replaced by the minute (00-59).
|
|
949 %n is a synonym for \"\\n\".
|
|
950 %p is replaced by AM or PM, as appropriate.
|
|
951 %r is a synonym for \"%I:%M:%S %p\".
|
|
952 %R is a synonym for \"%H:%M\".
|
|
953 %S is replaced by the second (00-60).
|
|
954 %t is a synonym for \"\\t\".
|
|
955 %T is a synonym for \"%H:%M:%S\".
|
|
956 %U is replaced by the week of the year (00-53), first day of week is Sunday.
|
|
957 %w is replaced by the day of week (0-6), Sunday is day 0.
|
|
958 %W is replaced by the week of the year (00-53), first day of week is Monday.
|
|
959 %x is a locale-specific synonym, which defaults to \"%D\" in the C locale.
|
|
960 %X is a locale-specific synonym, which defaults to \"%T\" in the C locale.
|
|
961 %y is replaced by the year without century (00-99).
|
|
962 %Y is replaced by the year with century.
|
|
963 %Z is replaced by the time zone abbreviation.
|
|
964
|
|
965 The number of options reflects the `strftime' function.
|
|
966
|
|
967 BUG: If the charset used by the current locale is not ISO 8859-1, the
|
|
968 characters appearing in the day and month names may be incorrect.
|
|
969 */ )
|
|
970 (format_string, _time)
|
|
971 Lisp_Object format_string, _time;
|
|
972 {
|
|
973 time_t value;
|
|
974 int size;
|
|
975
|
|
976 CHECK_STRING (format_string);
|
|
977
|
|
978 if (! lisp_to_time (_time, &value))
|
|
979 error ("Invalid time specification");
|
|
980
|
|
981 /* This is probably enough. */
|
14
|
982 size = XSTRING_LENGTH (format_string) * 6 + 50;
|
0
|
983
|
|
984 while (1)
|
|
985 {
|
|
986 char *buf = (char *) alloca (size);
|
|
987 *buf = 1;
|
|
988 if (emacs_strftime (buf, size,
|
14
|
989 (CONST char *) XSTRING_DATA (format_string),
|
0
|
990 localtime (&value))
|
|
991 || !*buf)
|
|
992 return build_ext_string (buf, FORMAT_BINARY);
|
|
993 /* If buffer was too small, make it bigger. */
|
|
994 size *= 2;
|
|
995 }
|
|
996 }
|
|
997
|
|
998 DEFUN ("decode-time", Fdecode_time, Sdecode_time, 0, 1, 0 /*
|
|
999 Decode a time value as (SEC MINUTE HOUR DAY MONTH YEAR DOW DST ZONE).
|
|
1000 The optional SPECIFIED-TIME should be a list of (HIGH LOW . IGNORED)
|
|
1001 or (HIGH . LOW), as from `current-time' and `file-attributes', or `nil'
|
|
1002 to use the current time. The list has the following nine members:
|
|
1003 SEC is an integer between 0 and 60; SEC is 60 for a leap second, which
|
|
1004 only some operating systems support. MINUTE is an integer between 0 and 59.
|
|
1005 HOUR is an integer between 0 and 23. DAY is an integer between 1 and 31.
|
|
1006 MONTH is an integer between 1 and 12. YEAR is an integer indicating the
|
|
1007 four-digit year. DOW is the day of week, an integer between 0 and 6, where
|
|
1008 0 is Sunday. DST is t if daylight savings time is effect, otherwise nil.
|
|
1009 ZONE is an integer indicating the number of seconds east of Greenwich.
|
|
1010 \(Note that Common Lisp has different meanings for DOW and ZONE.)
|
|
1011 */ )
|
|
1012 (specified_time)
|
|
1013 Lisp_Object specified_time;
|
|
1014 {
|
|
1015 time_t time_spec;
|
|
1016 struct tm save_tm;
|
|
1017 struct tm *decoded_time;
|
|
1018 Lisp_Object list_args[9];
|
|
1019
|
|
1020 if (! lisp_to_time (specified_time, &time_spec))
|
|
1021 error ("Invalid time specification");
|
|
1022
|
|
1023 decoded_time = localtime (&time_spec);
|
|
1024 XSETINT (list_args[0], decoded_time->tm_sec);
|
|
1025 XSETINT (list_args[1], decoded_time->tm_min);
|
|
1026 XSETINT (list_args[2], decoded_time->tm_hour);
|
|
1027 XSETINT (list_args[3], decoded_time->tm_mday);
|
|
1028 XSETINT (list_args[4], decoded_time->tm_mon + 1);
|
|
1029 XSETINT (list_args[5], decoded_time->tm_year + 1900);
|
|
1030 XSETINT (list_args[6], decoded_time->tm_wday);
|
|
1031 list_args[7] = (decoded_time->tm_isdst)? Qt : Qnil;
|
|
1032
|
|
1033 /* Make a copy, in case gmtime modifies the struct. */
|
|
1034 save_tm = *decoded_time;
|
|
1035 decoded_time = gmtime (&time_spec);
|
|
1036 if (decoded_time == 0)
|
|
1037 list_args[8] = Qnil;
|
|
1038 else
|
|
1039 XSETINT (list_args[8], difftm (&save_tm, decoded_time));
|
|
1040 return Flist (9, list_args);
|
|
1041 }
|
|
1042
|
|
1043 static void set_time_zone_rule (char *tzstring);
|
|
1044
|
|
1045 DEFUN ("encode-time", Fencode_time, Sencode_time, 6, MANY, 0 /*
|
|
1046 Convert SECOND, MINUTE, HOUR, DAY, MONTH, YEAR and ZONE to internal time.
|
|
1047 This is the reverse operation of `decode-time', which see.
|
|
1048 ZONE defaults to the current time zone rule. This can
|
|
1049 be a string (as from `set-time-zone-rule'), or it can be a list
|
|
1050 (as from `current-time-zone') or an integer (as from `decode-time')
|
|
1051 applied without consideration for daylight savings time.
|
|
1052
|
|
1053 You can pass more than 7 arguments; then the first six arguments
|
|
1054 are used as SECOND through YEAR, and the *last* argument is used as ZONE.
|
|
1055 The intervening arguments are ignored.
|
|
1056 This feature lets (apply 'encode-time (decode-time ...)) work.
|
|
1057
|
|
1058 Out-of-range values for SEC, MINUTE, HOUR, DAY, or MONTH are allowed;
|
|
1059 for example, a DAY of 0 means the day preceding the given month.
|
|
1060 Year numbers less than 100 are treated just like other year numbers.
|
|
1061 If you want them to stand for years in this century, you must do that yourself
|
|
1062 */ )
|
|
1063 (nargs, args)
|
|
1064 int nargs;
|
|
1065 Lisp_Object *args;
|
|
1066 {
|
|
1067 time_t _time;
|
|
1068 struct tm tm;
|
|
1069 Lisp_Object zone = (nargs > 6) ? args[nargs - 1] : Qnil;
|
|
1070
|
|
1071 CHECK_INT (args[0]); /* second */
|
|
1072 CHECK_INT (args[1]); /* minute */
|
|
1073 CHECK_INT (args[2]); /* hour */
|
|
1074 CHECK_INT (args[3]); /* day */
|
|
1075 CHECK_INT (args[4]); /* month */
|
|
1076 CHECK_INT (args[5]); /* year */
|
|
1077
|
|
1078 tm.tm_sec = XINT (args[0]);
|
|
1079 tm.tm_min = XINT (args[1]);
|
|
1080 tm.tm_hour = XINT (args[2]);
|
|
1081 tm.tm_mday = XINT (args[3]);
|
|
1082 tm.tm_mon = XINT (args[4]) - 1;
|
|
1083 tm.tm_year = XINT (args[5]) - 1900;
|
|
1084 tm.tm_isdst = -1;
|
|
1085
|
|
1086 if (CONSP (zone))
|
|
1087 zone = Fcar (zone);
|
|
1088 if (NILP (zone))
|
|
1089 _time = mktime (&tm);
|
|
1090 else
|
|
1091 {
|
|
1092 char tzbuf[100];
|
|
1093 char *tzstring;
|
|
1094 char **oldenv = environ, **newenv;
|
|
1095
|
|
1096 if (STRINGP (zone))
|
14
|
1097 tzstring = (char *) XSTRING_DATA (zone);
|
0
|
1098 else if (INTP (zone))
|
|
1099 {
|
|
1100 int abszone = abs (XINT (zone));
|
|
1101 sprintf (tzbuf, "XXX%s%d:%02d:%02d", "-" + (XINT (zone) < 0),
|
|
1102 abszone / (60*60), (abszone/60) % 60, abszone % 60);
|
|
1103 tzstring = tzbuf;
|
|
1104 }
|
|
1105 else
|
|
1106 error ("Invalid time zone specification");
|
|
1107
|
|
1108 /* Set TZ before calling mktime; merely adjusting mktime's returned
|
|
1109 value doesn't suffice, since that would mishandle leap seconds. */
|
|
1110 set_time_zone_rule (tzstring);
|
|
1111
|
|
1112 _time = mktime (&tm);
|
|
1113
|
|
1114 /* Restore TZ to previous value. */
|
|
1115 newenv = environ;
|
|
1116 environ = oldenv;
|
|
1117 free (newenv);
|
|
1118 #ifdef LOCALTIME_CACHE
|
|
1119 tzset ();
|
|
1120 #endif
|
|
1121 }
|
|
1122
|
|
1123 if (_time == (time_t) -1)
|
|
1124 error ("Specified time is not representable");
|
|
1125
|
|
1126 return wasteful_word_to_lisp (_time);
|
|
1127 }
|
|
1128
|
|
1129 DEFUN ("current-time-string", Fcurrent_time_string, Scurrent_time_string,
|
|
1130 0, 1, 0 /*
|
|
1131 Return the current time, as a human-readable string.
|
|
1132 Programs can use this function to decode a time,
|
|
1133 since the number of columns in each field is fixed.
|
|
1134 The format is `Sun Sep 16 01:03:52 1973'.
|
|
1135 If an argument is given, it specifies a time to format
|
|
1136 instead of the current time. The argument should have the form:
|
|
1137 (HIGH . LOW)
|
|
1138 or the form:
|
|
1139 (HIGH LOW . IGNORED).
|
|
1140 Thus, you can use times obtained from `current-time'
|
|
1141 and from `file-attributes'.
|
|
1142 */ )
|
|
1143 (specified_time)
|
|
1144 Lisp_Object specified_time;
|
|
1145 {
|
|
1146 time_t value;
|
|
1147 char buf[30];
|
|
1148 char *tem;
|
|
1149
|
|
1150 if (! lisp_to_time (specified_time, &value))
|
|
1151 value = -1;
|
|
1152 tem = (char *) ctime (&value);
|
|
1153
|
|
1154 strncpy (buf, tem, 24);
|
|
1155 buf[24] = 0;
|
|
1156
|
|
1157 return build_ext_string (buf, FORMAT_BINARY);
|
|
1158 }
|
|
1159
|
|
1160 #define TM_YEAR_ORIGIN 1900
|
|
1161
|
|
1162 /* Yield A - B, measured in seconds. */
|
|
1163 static long
|
|
1164 difftm (CONST struct tm *a, CONST struct tm *b)
|
|
1165 {
|
|
1166 int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
|
|
1167 int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
|
|
1168 /* Some compilers can't handle this as a single return statement. */
|
|
1169 long days = (
|
|
1170 /* difference in day of year */
|
|
1171 a->tm_yday - b->tm_yday
|
|
1172 /* + intervening leap days */
|
|
1173 + ((ay >> 2) - (by >> 2))
|
|
1174 - (ay/100 - by/100)
|
|
1175 + ((ay/100 >> 2) - (by/100 >> 2))
|
|
1176 /* + difference in years * 365 */
|
|
1177 + (long)(ay-by) * 365
|
|
1178 );
|
|
1179 return (60*(60*(24*days + (a->tm_hour - b->tm_hour))
|
|
1180 + (a->tm_min - b->tm_min))
|
|
1181 + (a->tm_sec - b->tm_sec));
|
|
1182 }
|
|
1183
|
|
1184 DEFUN ("current-time-zone", Fcurrent_time_zone, Scurrent_time_zone, 0, 1, 0 /*
|
|
1185 Return the offset and name for the local time zone.
|
|
1186 This returns a list of the form (OFFSET NAME).
|
|
1187 OFFSET is an integer number of seconds ahead of UTC (east of Greenwich).
|
|
1188 A negative value means west of Greenwich.
|
|
1189 NAME is a string giving the name of the time zone.
|
|
1190 If an argument is given, it specifies when the time zone offset is determined
|
|
1191 instead of using the current time. The argument should have the form:
|
|
1192 (HIGH . LOW)
|
|
1193 or the form:
|
|
1194 (HIGH LOW . IGNORED).
|
|
1195 Thus, you can use times obtained from `current-time'
|
|
1196 and from `file-attributes'.
|
|
1197
|
|
1198 Some operating systems cannot provide all this information to Emacs;
|
|
1199 in this case, `current-time-zone' returns a list containing nil for
|
|
1200 the data it can't find.
|
|
1201 */ )
|
|
1202 (specified_time)
|
|
1203 Lisp_Object specified_time;
|
|
1204 {
|
|
1205 time_t value;
|
|
1206 struct tm *t;
|
|
1207
|
|
1208 if (lisp_to_time (specified_time, &value)
|
|
1209 && (t = gmtime (&value)) != 0)
|
|
1210 {
|
|
1211 struct tm gmt;
|
|
1212 long offset;
|
|
1213 char *s, buf[6];
|
|
1214
|
|
1215 gmt = *t; /* Make a copy, in case localtime modifies *t. */
|
|
1216 t = localtime (&value);
|
|
1217 offset = difftm (t, &gmt);
|
|
1218 s = 0;
|
|
1219 #ifdef HAVE_TM_ZONE
|
|
1220 if (t->tm_zone)
|
|
1221 s = (char *)t->tm_zone;
|
|
1222 #else /* not HAVE_TM_ZONE */
|
|
1223 #ifdef HAVE_TZNAME
|
|
1224 if (t->tm_isdst == 0 || t->tm_isdst == 1)
|
|
1225 s = tzname[t->tm_isdst];
|
|
1226 #endif
|
|
1227 #endif /* not HAVE_TM_ZONE */
|
|
1228 if (!s)
|
|
1229 {
|
|
1230 /* No local time zone name is available; use "+-NNNN" instead. */
|
|
1231 int am = (offset < 0 ? -offset : offset) / 60;
|
|
1232 sprintf (buf, "%c%02d%02d", (offset < 0 ? '-' : '+'), am/60, am%60);
|
|
1233 s = buf;
|
|
1234 }
|
|
1235 return list2 (make_int (offset), build_string (s));
|
|
1236 }
|
|
1237 else
|
|
1238 return list2 (Qnil, Qnil);
|
|
1239 }
|
|
1240
|
|
1241 /* Set the local time zone rule to TZSTRING.
|
|
1242 This allocates memory into `environ', which it is the caller's
|
|
1243 responsibility to free. */
|
|
1244 static void
|
|
1245 set_time_zone_rule (char *tzstring)
|
|
1246 {
|
|
1247 int envptrs;
|
|
1248 char **from, **to, **newenv;
|
|
1249
|
|
1250 for (from = environ; *from; from++)
|
|
1251 continue;
|
|
1252 envptrs = from - environ + 2;
|
|
1253 newenv = to = (char **) xmalloc (envptrs * sizeof (char *)
|
|
1254 + (tzstring ? strlen (tzstring) + 4 : 0));
|
|
1255 if (tzstring)
|
|
1256 {
|
|
1257 char *t = (char *) (to + envptrs);
|
|
1258 strcpy (t, "TZ=");
|
|
1259 strcat (t, tzstring);
|
|
1260 *to++ = t;
|
|
1261 }
|
|
1262
|
|
1263 for (from = environ; *from; from++)
|
|
1264 if (strncmp (*from, "TZ=", 3) != 0)
|
|
1265 *to++ = *from;
|
|
1266 *to = 0;
|
|
1267
|
|
1268 environ = newenv;
|
|
1269
|
|
1270 #ifdef LOCALTIME_CACHE
|
|
1271 tzset ();
|
|
1272 #endif
|
|
1273 }
|
|
1274
|
|
1275 DEFUN ("set-time-zone-rule", Fset_time_zone_rule, Sset_time_zone_rule,
|
|
1276 1, 1, 0 /*
|
|
1277 Set the local time zone using TZ, a string specifying a time zone rule.
|
|
1278 If TZ is nil, use implementation-defined default time zone information.
|
|
1279 */ )
|
|
1280 (tz)
|
|
1281 Lisp_Object tz;
|
|
1282 {
|
|
1283 char *tzstring;
|
|
1284
|
|
1285 if (NILP (tz))
|
|
1286 tzstring = 0;
|
|
1287 else
|
|
1288 {
|
|
1289 CHECK_STRING (tz);
|
14
|
1290 tzstring = (char *) XSTRING_DATA (tz);
|
0
|
1291 }
|
|
1292
|
|
1293 set_time_zone_rule (tzstring);
|
|
1294 if (environbuf)
|
|
1295 xfree (environbuf);
|
|
1296 environbuf = environ;
|
|
1297
|
|
1298 return Qnil;
|
|
1299 }
|
|
1300
|
|
1301
|
|
1302 void
|
|
1303 buffer_insert1 (struct buffer *buf, Lisp_Object arg)
|
|
1304 {
|
|
1305 /* This function can GC */
|
|
1306 struct gcpro gcpro1;
|
|
1307 GCPRO1 (arg);
|
|
1308 retry:
|
|
1309 if (CHAR_OR_CHAR_INTP (arg))
|
|
1310 {
|
|
1311 buffer_insert_emacs_char (buf, XCHAR_OR_CHAR_INT (arg));
|
|
1312 }
|
|
1313 else if (STRINGP (arg))
|
|
1314 {
|
|
1315 buffer_insert_lisp_string (buf, arg);
|
|
1316 }
|
|
1317 else
|
|
1318 {
|
|
1319 arg = wrong_type_argument (Qchar_or_string_p, arg);
|
|
1320 goto retry;
|
|
1321 }
|
|
1322 zmacs_region_stays = 0;
|
|
1323 UNGCPRO;
|
|
1324 }
|
|
1325
|
|
1326
|
|
1327 /* Callers passing one argument to Finsert need not gcpro the
|
|
1328 argument "array", since the only element of the array will
|
|
1329 not be used after calling insert_emacs_char or insert_lisp_string,
|
|
1330 so we don't care if it gets trashed. */
|
|
1331
|
|
1332 DEFUN ("insert", Finsert, Sinsert, 0, MANY, 0 /*
|
|
1333 Insert the arguments, either strings or characters, at point.
|
|
1334 Point moves forward so that it ends up after the inserted text.
|
|
1335 Any other markers at the point of insertion remain before the text.
|
|
1336 If a string has non-null string-extent-data, new extents will be created.
|
|
1337 */ )
|
|
1338 (nargs, args)
|
|
1339 int nargs;
|
|
1340 Lisp_Object *args;
|
|
1341 {
|
|
1342 /* This function can GC */
|
|
1343 REGISTER int argnum;
|
|
1344
|
|
1345 for (argnum = 0; argnum < nargs; argnum++)
|
|
1346 {
|
|
1347 buffer_insert1 (current_buffer, args[argnum]);
|
|
1348 }
|
|
1349
|
|
1350 return Qnil;
|
|
1351 }
|
|
1352
|
|
1353 DEFUN ("insert-before-markers", Finsert_before_markers, Sinsert_before_markers, 0, MANY, 0 /*
|
|
1354 Insert strings or characters at point, relocating markers after the text.
|
|
1355 Point moves forward so that it ends up after the inserted text.
|
|
1356 Any other markers at the point of insertion also end up after the text.
|
|
1357 */ )
|
|
1358 (nargs, args)
|
|
1359 int nargs;
|
|
1360 Lisp_Object *args;
|
|
1361 {
|
|
1362 /* This function can GC */
|
|
1363 REGISTER int argnum;
|
|
1364 REGISTER Lisp_Object tem;
|
|
1365
|
|
1366 for (argnum = 0; argnum < nargs; argnum++)
|
|
1367 {
|
|
1368 tem = args[argnum];
|
|
1369 retry:
|
|
1370 if (CHAR_OR_CHAR_INTP (tem))
|
|
1371 {
|
|
1372 buffer_insert_emacs_char_1 (current_buffer, -1,
|
|
1373 XCHAR_OR_CHAR_INT (tem),
|
|
1374 INSDEL_BEFORE_MARKERS);
|
|
1375 }
|
|
1376 else if (STRINGP (tem))
|
|
1377 {
|
|
1378 buffer_insert_lisp_string_1 (current_buffer, -1, tem,
|
|
1379 INSDEL_BEFORE_MARKERS);
|
|
1380 }
|
|
1381 else
|
|
1382 {
|
|
1383 tem = wrong_type_argument (Qchar_or_string_p, tem);
|
|
1384 goto retry;
|
|
1385 }
|
|
1386 }
|
|
1387 zmacs_region_stays = 0;
|
|
1388 return Qnil;
|
|
1389 }
|
|
1390
|
|
1391 DEFUN ("insert-string", Finsert_string, Sinsert_string, 1, 2, 0 /*
|
|
1392 Insert STRING into BUFFER at BUFFER's point.
|
|
1393 Point moves forward so that it ends up after the inserted text.
|
|
1394 Any other markers at the point of insertion remain before the text.
|
|
1395 If a string has non-null string-extent-data, new extents will be created.
|
|
1396 BUFFER defaults to the current buffer.
|
|
1397 */ )
|
|
1398 (string, buffer)
|
|
1399 Lisp_Object string, buffer;
|
|
1400 {
|
|
1401 struct buffer *buf = decode_buffer (buffer, 1);
|
|
1402 CHECK_STRING (string);
|
|
1403 buffer_insert_lisp_string (buf, string);
|
|
1404 zmacs_region_stays = 0;
|
|
1405 return Qnil;
|
|
1406 }
|
|
1407
|
|
1408 /* Third argument in FSF is INHERIT:
|
|
1409
|
|
1410 "The optional third arg INHERIT, if non-nil, says to inherit text properties\n\
|
|
1411 from adjoining text, if those properties are sticky."
|
|
1412
|
|
1413 Jamie thinks this is bogus. */
|
|
1414
|
|
1415
|
|
1416 DEFUN ("insert-char", Finsert_char, Sinsert_char, 1, 4, 0 /*
|
|
1417 Insert COUNT (second arg) copies of CHR (first arg).
|
|
1418 Point and all markers are affected as in the function `insert'.
|
|
1419 COUNT defaults to 1 if omitted.
|
|
1420 The optional third arg IGNORED is INHERIT under FSF Emacs.
|
|
1421 This is highly bogus, however, and XEmacs always behaves as if
|
|
1422 `t' were passed to INHERIT.
|
|
1423 The optional fourth arg BUFFER specifies the buffer to insert the
|
|
1424 text into. If BUFFER is nil, the current buffer is assumed.
|
|
1425 */ )
|
|
1426 (chr, count, ignored, buffer)
|
|
1427 Lisp_Object chr, count, ignored, buffer;
|
|
1428 {
|
|
1429 /* This function can GC */
|
|
1430 REGISTER Bufbyte *string;
|
|
1431 REGISTER int slen;
|
|
1432 REGISTER int i, j;
|
|
1433 REGISTER Bytecount n;
|
|
1434 REGISTER Bytecount charlen;
|
|
1435 Bufbyte str[MAX_EMCHAR_LEN];
|
|
1436 struct buffer *buf = decode_buffer (buffer, 1);
|
|
1437 int cou;
|
|
1438
|
|
1439 CHECK_CHAR_COERCE_INT (chr);
|
|
1440 if (NILP (count))
|
|
1441 cou = 1;
|
|
1442 else
|
|
1443 {
|
|
1444 CHECK_INT (count);
|
|
1445 cou = XINT (count);
|
|
1446 }
|
|
1447
|
|
1448 charlen = set_charptr_emchar (str, XCHAR (chr));
|
|
1449 n = cou * charlen;
|
|
1450 if (n <= 0)
|
|
1451 return Qnil;
|
|
1452 slen = min (n, 768);
|
|
1453 string = (Bufbyte *) alloca (slen * sizeof (Bufbyte));
|
|
1454 /* Write as many copies of the character into the temp string as will fit. */
|
|
1455 for (i = 0; i + charlen <= slen; i += charlen)
|
|
1456 for (j = 0; j < charlen; j++)
|
|
1457 string[i + j] = str[j];
|
|
1458 slen = i;
|
|
1459 while (n >= slen)
|
|
1460 {
|
|
1461 buffer_insert_raw_string (buf, string, slen);
|
|
1462 n -= slen;
|
|
1463 }
|
|
1464 if (n > 0)
|
|
1465 #if 0 /* FSFmacs bogosity */
|
|
1466 {
|
|
1467 if (!NILP (inherit))
|
|
1468 insert_and_inherit (string, n);
|
|
1469 else
|
|
1470 insert (string, n);
|
|
1471 }
|
|
1472 #else
|
|
1473 buffer_insert_raw_string (buf, string, n);
|
|
1474 #endif
|
|
1475
|
|
1476 zmacs_region_stays = 0;
|
|
1477 return Qnil;
|
|
1478 }
|
|
1479
|
|
1480
|
|
1481 /* Making strings from buffer contents. */
|
|
1482
|
|
1483 DEFUN ("buffer-substring", Fbuffer_substring, Sbuffer_substring, 0, 3, 0 /*
|
|
1484 Return the contents of part of BUFFER as a string.
|
|
1485 The two arguments START and END are character positions;
|
|
1486 they can be in either order. If omitted, they default to the beginning
|
|
1487 and end of BUFFER, respectively.
|
|
1488 If there are duplicable extents in the region, the string remembers
|
|
1489 them in its extent data.
|
|
1490 If BUFFER is nil, the current buffer is assumed.
|
|
1491 */ )
|
|
1492 (start, end, buffer)
|
|
1493 Lisp_Object start, end, buffer;
|
|
1494 {
|
|
1495 /* This function can GC */
|
|
1496 Bufpos begv, zv;
|
|
1497 struct buffer *b = decode_buffer (buffer, 1);
|
|
1498
|
|
1499 get_buffer_range_char (b, start, end, &begv, &zv, GB_ALLOW_NIL);
|
|
1500 return make_string_from_buffer (b, begv, zv - begv);
|
|
1501 }
|
|
1502
|
|
1503 DEFUN ("insert-buffer-substring", Finsert_buffer_substring, Sinsert_buffer_substring,
|
|
1504 1, 3, 0 /*
|
|
1505 Insert before point a substring of the contents of buffer BUFFER.
|
|
1506 BUFFER may be a buffer or a buffer name.
|
|
1507 Arguments START and END are character numbers specifying the substring.
|
|
1508 They default to the beginning and the end of BUFFER.
|
|
1509 */ )
|
|
1510 (buffer, start, end)
|
|
1511 Lisp_Object buffer, start, end;
|
|
1512 {
|
|
1513 /* This function can GC */
|
|
1514 Bufpos b, e;
|
|
1515 struct buffer *bp;
|
|
1516
|
|
1517 bp = XBUFFER (get_buffer (buffer, 1));
|
|
1518 get_buffer_range_char (bp, start, end, &b, &e, GB_ALLOW_NIL);
|
|
1519
|
|
1520 if (b < e)
|
|
1521 buffer_insert_from_buffer (current_buffer, bp, b, e - b);
|
|
1522
|
|
1523 return Qnil;
|
|
1524 }
|
|
1525
|
|
1526 DEFUN ("compare-buffer-substrings", Fcompare_buffer_substrings, Scompare_buffer_substrings,
|
|
1527 6, 6, 0 /*
|
|
1528 Compare two substrings of two buffers; return result as number.
|
|
1529 the value is -N if first string is less after N-1 chars,
|
|
1530 +N if first string is greater after N-1 chars, or 0 if strings match.
|
|
1531 Each substring is represented as three arguments: BUFFER, START and END.
|
|
1532 That makes six args in all, three for each substring.
|
|
1533
|
|
1534 The value of `case-fold-search' in the current buffer
|
|
1535 determines whether case is significant or ignored.
|
|
1536 */ )
|
|
1537 (buffer1, start1, end1, buffer2, start2, end2)
|
|
1538 Lisp_Object buffer1, start1, end1, buffer2, start2, end2;
|
|
1539 {
|
|
1540 Bufpos begp1, endp1, begp2, endp2;
|
|
1541 REGISTER Charcount len1, len2, length, i;
|
|
1542 struct buffer *bp1, *bp2;
|
|
1543 Lisp_Object trt = ((!NILP (current_buffer->case_fold_search)) ?
|
|
1544 current_buffer->case_canon_table : Qnil);
|
|
1545
|
|
1546 /* Find the first buffer and its substring. */
|
|
1547
|
|
1548 bp1 = decode_buffer (buffer1, 1);
|
|
1549 get_buffer_range_char (bp1, start1, end1, &begp1, &endp1, GB_ALLOW_NIL);
|
|
1550
|
|
1551 /* Likewise for second substring. */
|
|
1552
|
|
1553 bp2 = decode_buffer (buffer2, 1);
|
|
1554 get_buffer_range_char (bp2, start2, end2, &begp2, &endp2, GB_ALLOW_NIL);
|
|
1555
|
|
1556 len1 = endp1 - begp1;
|
|
1557 len2 = endp2 - begp2;
|
|
1558 length = len1;
|
|
1559 if (len2 < length)
|
|
1560 length = len2;
|
|
1561
|
|
1562 for (i = 0; i < length; i++)
|
|
1563 {
|
|
1564 Emchar c1 = BUF_FETCH_CHAR (bp1, begp1 + i);
|
|
1565 Emchar c2 = BUF_FETCH_CHAR (bp2, begp2 + i);
|
|
1566 if (!NILP (trt))
|
|
1567 {
|
|
1568 c1 = TRT_TABLE_OF (trt, c1);
|
|
1569 c2 = TRT_TABLE_OF (trt, c2);
|
|
1570 }
|
|
1571 if (c1 < c2)
|
|
1572 return make_int (- 1 - i);
|
|
1573 if (c1 > c2)
|
|
1574 return make_int (i + 1);
|
|
1575 }
|
|
1576
|
|
1577 /* The strings match as far as they go.
|
|
1578 If one is shorter, that one is less. */
|
|
1579 if (length < len1)
|
|
1580 return make_int (length + 1);
|
|
1581 else if (length < len2)
|
|
1582 return make_int (- length - 1);
|
|
1583
|
|
1584 /* Same length too => they are equal. */
|
|
1585 return Qzero;
|
|
1586 }
|
|
1587
|
|
1588
|
|
1589 static Lisp_Object
|
|
1590 subst_char_in_region_unwind (Lisp_Object arg)
|
|
1591 {
|
|
1592 XBUFFER (XCAR (arg))->undo_list = XCDR (arg);
|
|
1593 return Qnil;
|
|
1594 }
|
|
1595
|
|
1596 static Lisp_Object
|
|
1597 subst_char_in_region_unwind_1 (Lisp_Object arg)
|
|
1598 {
|
|
1599 XBUFFER (XCAR (arg))->filename = XCDR (arg);
|
|
1600 return Qnil;
|
|
1601 }
|
|
1602
|
|
1603 DEFUN ("subst-char-in-region", Fsubst_char_in_region,
|
|
1604 Ssubst_char_in_region, 4, 5, 0 /*
|
|
1605 From START to END, replace FROMCHAR with TOCHAR each time it occurs.
|
|
1606 If optional arg NOUNDO is non-nil, don't record this change for undo
|
|
1607 and don't mark the buffer as really changed.
|
|
1608 */ )
|
|
1609 (start, end, fromchar, tochar, noundo)
|
|
1610 Lisp_Object start, end, fromchar, tochar, noundo;
|
|
1611 {
|
|
1612 /* This function can GC */
|
|
1613 Bufpos pos, stop;
|
|
1614 Emchar fromc, toc;
|
|
1615 int mc_count;
|
|
1616 struct buffer *buf = current_buffer;
|
|
1617 int count = specpdl_depth ();
|
|
1618
|
|
1619 get_buffer_range_char (buf, start, end, &pos, &stop, 0);
|
|
1620 CHECK_CHAR_COERCE_INT (fromchar);
|
|
1621 CHECK_CHAR_COERCE_INT (tochar);
|
|
1622
|
|
1623 fromc = XCHAR (fromchar);
|
|
1624 toc = XCHAR (tochar);
|
|
1625
|
|
1626 /* If we don't want undo, turn off putting stuff on the list.
|
|
1627 That's faster than getting rid of things,
|
|
1628 and it prevents even the entry for a first change.
|
|
1629 Also inhibit locking the file. */
|
|
1630 if (!NILP (noundo))
|
|
1631 {
|
|
1632 record_unwind_protect (subst_char_in_region_unwind,
|
|
1633 Fcons (Fcurrent_buffer (), buf->undo_list));
|
|
1634 buf->undo_list = Qt;
|
|
1635 /* Don't do file-locking. */
|
|
1636 record_unwind_protect (subst_char_in_region_unwind_1,
|
|
1637 Fcons (Fcurrent_buffer (), buf->filename));
|
|
1638 buf->filename = Qnil;
|
|
1639 }
|
|
1640
|
|
1641 mc_count = begin_multiple_change (buf, pos, stop);
|
|
1642 while (pos < stop)
|
|
1643 {
|
|
1644 if (BUF_FETCH_CHAR (buf, pos) == fromc)
|
|
1645 {
|
|
1646 /* There used to be some code here that set the buffer to
|
|
1647 unmodified if NOUNDO was specified and there was only
|
|
1648 one change to the buffer since it was last saved.
|
|
1649 This is a crock of shit, so I'm not duplicating this
|
|
1650 behavior. I think this was left over from when
|
|
1651 prepare_to_modify_buffer() actually bumped MODIFF,
|
|
1652 so that code was supposed to undo this change. --ben */
|
|
1653 buffer_replace_char (buf, pos, toc, !NILP (noundo), 0);
|
|
1654
|
|
1655 /* If noundo is not nil then we don't mark the buffer as
|
|
1656 modified. In reality that needs to happen externally
|
|
1657 only. Internally redisplay needs to know that the actual
|
|
1658 contents it should be displaying have changed. */
|
|
1659 if (!NILP (noundo))
|
|
1660 Fset_buffer_modified_p (Fbuffer_modified_p (Qnil), Qnil);
|
|
1661 }
|
|
1662 pos++;
|
|
1663 }
|
|
1664 end_multiple_change (buf, mc_count);
|
|
1665
|
|
1666 unbind_to (count, Qnil);
|
|
1667 return Qnil;
|
|
1668 }
|
|
1669
|
|
1670 DEFUN ("translate-region", Ftranslate_region, Stranslate_region, 3, 3, 0 /*
|
|
1671 From START to END, translate characters according to TABLE.
|
|
1672 TABLE is a string; the Nth character in it is the mapping
|
|
1673 for the character with code N. Returns the number of characters changed.
|
|
1674 */ )
|
|
1675 (start, end, table)
|
|
1676 Lisp_Object start;
|
|
1677 Lisp_Object end;
|
|
1678 Lisp_Object table;
|
|
1679 {
|
|
1680 /* This function can GC */
|
|
1681 Bufpos pos, stop; /* Limits of the region. */
|
|
1682 REGISTER Emchar oc; /* Old character. */
|
|
1683 REGISTER Emchar nc; /* New character. */
|
|
1684 int cnt; /* Number of changes made. */
|
|
1685 Charcount size; /* Size of translate table. */
|
|
1686 int mc_count;
|
|
1687 struct buffer *buf = current_buffer;
|
|
1688
|
|
1689 get_buffer_range_char (buf, start, end, &pos, &stop, 0);
|
|
1690 CHECK_STRING (table);
|
|
1691
|
|
1692 size = string_char_length (XSTRING (table));
|
|
1693
|
|
1694 cnt = 0;
|
|
1695 mc_count = begin_multiple_change (buf, pos, stop);
|
|
1696 for (; pos < stop; pos++)
|
|
1697 {
|
|
1698 oc = BUF_FETCH_CHAR (buf, pos);
|
|
1699 if (oc >= 0 && oc < size)
|
|
1700 {
|
|
1701 nc = string_char (XSTRING (table), oc);
|
|
1702 if (nc != oc)
|
|
1703 {
|
|
1704 buffer_replace_char (buf, pos, nc, 0, 0);
|
|
1705 ++cnt;
|
|
1706 }
|
|
1707 }
|
|
1708 }
|
|
1709 end_multiple_change (buf, mc_count);
|
|
1710
|
|
1711 return make_int (cnt);
|
|
1712 }
|
|
1713
|
|
1714 DEFUN ("delete-region", Fdelete_region, Sdelete_region, 2, 3, "r" /*
|
|
1715 Delete the text between point and mark.
|
|
1716 When called from a program, expects two arguments,
|
|
1717 positions (integers or markers) specifying the stretch to be deleted.
|
|
1718 If BUFFER is nil, the current buffer is assumed.
|
|
1719 */ )
|
|
1720 (b, e, buffer)
|
|
1721 Lisp_Object b, e, buffer;
|
|
1722 {
|
|
1723 /* This function can GC */
|
|
1724 Bufpos start, end;
|
|
1725 struct buffer *buf = decode_buffer (buffer, 1);
|
|
1726
|
|
1727 get_buffer_range_char (buf, b, e, &start, &end, 0);
|
|
1728 buffer_delete_range (buf, start, end, 0);
|
|
1729 zmacs_region_stays = 0;
|
|
1730 return Qnil;
|
|
1731 }
|
|
1732
|
|
1733 void
|
|
1734 widen_buffer (struct buffer *b, int no_clip)
|
|
1735 {
|
|
1736 if (BUF_BEGV (b) != BUF_BEG (b))
|
|
1737 {
|
|
1738 clip_changed = 1;
|
|
1739 SET_BOTH_BUF_BEGV (b, BUF_BEG (b), BI_BUF_BEG (b));
|
|
1740 }
|
|
1741 if (BUF_ZV (b) != BUF_Z (b))
|
|
1742 {
|
|
1743 clip_changed = 1;
|
|
1744 SET_BOTH_BUF_ZV (b, BUF_Z (b), BI_BUF_Z (b));
|
|
1745 }
|
|
1746 if (clip_changed)
|
|
1747 {
|
|
1748 if (!no_clip)
|
|
1749 MARK_CLIP_CHANGED;
|
|
1750 /* Changing the buffer bounds invalidates any recorded current
|
|
1751 column. */
|
|
1752 invalidate_current_column ();
|
|
1753 }
|
|
1754 }
|
|
1755
|
|
1756 DEFUN ("widen", Fwiden, Swiden, 0, 1, "" /*
|
|
1757 Remove restrictions (narrowing) from BUFFER.
|
|
1758 This allows the buffer's full text to be seen and edited.
|
|
1759 If BUFFER is nil, the current buffer is assumed.
|
|
1760 */ )
|
|
1761 (buffer)
|
|
1762 Lisp_Object buffer;
|
|
1763 {
|
|
1764 struct buffer *b = decode_buffer (buffer, 1);
|
|
1765 widen_buffer (b, 0);
|
|
1766 zmacs_region_stays = 0;
|
|
1767 return Qnil;
|
|
1768 }
|
|
1769
|
|
1770 DEFUN ("narrow-to-region", Fnarrow_to_region, Snarrow_to_region, 2, 3, "r" /*
|
|
1771 Restrict editing in BUFFER to the current region.
|
|
1772 The rest of the text becomes temporarily invisible and untouchable
|
|
1773 but is not deleted; if you save the buffer in a file, the invisible
|
|
1774 text is included in the file. \\[widen] makes all visible again.
|
|
1775 If BUFFER is nil, the current buffer is assumed.
|
|
1776 See also `save-restriction'.
|
|
1777
|
|
1778 When calling from a program, pass two arguments; positions (integers
|
|
1779 or markers) bounding the text that should remain visible.
|
|
1780 */ )
|
|
1781 (b, e, buffer)
|
|
1782 Lisp_Object b, e, buffer;
|
|
1783 {
|
|
1784 Bufpos start, end;
|
|
1785 struct buffer *buf = decode_buffer (buffer, 1);
|
|
1786 Bytind bi_start, bi_end;
|
|
1787
|
|
1788 get_buffer_range_char (buf, b, e, &start, &end, GB_ALLOW_PAST_ACCESSIBLE);
|
|
1789 bi_start = bufpos_to_bytind (buf, start);
|
|
1790 bi_end = bufpos_to_bytind (buf, end);
|
|
1791
|
|
1792 SET_BOTH_BUF_BEGV (buf, start, bi_start);
|
|
1793 SET_BOTH_BUF_ZV (buf, end, bi_end);
|
|
1794 if (BUF_PT (buf) < start)
|
|
1795 BUF_SET_PT (buf, start);
|
|
1796 if (BUF_PT (buf) > end)
|
|
1797 BUF_SET_PT (buf, end);
|
|
1798 MARK_CLIP_CHANGED;
|
|
1799 /* Changing the buffer bounds invalidates any recorded current column. */
|
|
1800 invalidate_current_column ();
|
|
1801 zmacs_region_stays = 0;
|
|
1802 return Qnil;
|
|
1803 }
|
|
1804
|
|
1805 Lisp_Object
|
|
1806 save_restriction_save (void)
|
|
1807 {
|
|
1808 Lisp_Object bottom, top;
|
|
1809 /* Note: I tried using markers here, but it does not win
|
|
1810 because insertion at the end of the saved region
|
|
1811 does not advance mh and is considered "outside" the saved region. */
|
|
1812 bottom = make_int (BUF_BEGV (current_buffer) - BUF_BEG (current_buffer));
|
|
1813 top = make_int (BUF_Z (current_buffer) - BUF_ZV (current_buffer));
|
|
1814
|
|
1815 return noseeum_cons (Fcurrent_buffer (), noseeum_cons (bottom, top));
|
|
1816 }
|
|
1817
|
|
1818 Lisp_Object
|
|
1819 save_restriction_restore (Lisp_Object data)
|
|
1820 {
|
|
1821 struct buffer *buf;
|
|
1822 Charcount newhead, newtail;
|
|
1823 Lisp_Object tem;
|
|
1824 int local_clip_changed = 0;
|
|
1825
|
|
1826 buf = XBUFFER (Fcar (data));
|
|
1827 if (!BUFFER_LIVE_P (buf))
|
|
1828 /* someone could have killed the buffer in the meantime ... */
|
|
1829 return Qnil;
|
|
1830 tem = Fcdr (data);
|
|
1831 newhead = XINT (Fcar (tem));
|
|
1832 newtail = XINT (Fcdr (tem));
|
|
1833 while (CONSP (data))
|
|
1834 {
|
|
1835 struct Lisp_Cons *victim = XCONS (data);
|
|
1836 data = victim->cdr;
|
|
1837 free_cons (victim);
|
|
1838 }
|
|
1839
|
|
1840 if (newhead + newtail > BUF_Z (buf) - BUF_BEG (buf))
|
|
1841 {
|
|
1842 newhead = 0;
|
|
1843 newtail = 0;
|
|
1844 }
|
|
1845 {
|
|
1846 Bufpos start, end;
|
|
1847 Bytind bi_start, bi_end;
|
|
1848
|
|
1849 start = BUF_BEG (buf) + newhead;
|
|
1850 end = BUF_Z (buf) - newtail;
|
|
1851
|
|
1852 bi_start = bufpos_to_bytind (buf, start);
|
|
1853 bi_end = bufpos_to_bytind (buf, end);
|
|
1854
|
|
1855 if (BUF_BEGV (buf) != start)
|
|
1856 {
|
|
1857 local_clip_changed = 1;
|
|
1858 SET_BOTH_BUF_BEGV (buf, start, bi_start);
|
|
1859 }
|
|
1860 if (BUF_ZV (buf) != end)
|
|
1861 {
|
|
1862 local_clip_changed = 1;
|
|
1863 SET_BOTH_BUF_ZV (buf, end, bi_end);
|
|
1864 }
|
|
1865 }
|
|
1866 if (local_clip_changed)
|
|
1867 MARK_CLIP_CHANGED;
|
|
1868
|
|
1869 /* If point is outside the new visible range, move it inside. */
|
|
1870 BUF_SET_PT (buf,
|
|
1871 bufpos_clip_to_bounds (BUF_BEGV (buf),
|
|
1872 BUF_PT (buf),
|
|
1873 BUF_ZV (buf)));
|
|
1874
|
|
1875 return Qnil;
|
|
1876 }
|
|
1877
|
|
1878 DEFUN ("save-restriction", Fsave_restriction, Ssave_restriction, 0, UNEVALLED, 0 /*
|
|
1879 Execute BODY, saving and restoring current buffer's restrictions.
|
|
1880 The buffer's restrictions make parts of the beginning and end invisible.
|
|
1881 \(They are set up with `narrow-to-region' and eliminated with `widen'.)
|
|
1882 This special form, `save-restriction', saves the current buffer's restrictions
|
|
1883 when it is entered, and restores them when it is exited.
|
|
1884 So any `narrow-to-region' within BODY lasts only until the end of the form.
|
|
1885 The old restrictions settings are restored
|
|
1886 even in case of abnormal exit (throw or error).
|
|
1887
|
|
1888 The value returned is the value of the last form in BODY.
|
|
1889
|
|
1890 `save-restriction' can get confused if, within the BODY, you widen
|
|
1891 and then make changes outside the area within the saved restrictions.
|
|
1892
|
|
1893 Note: if you are using both `save-excursion' and `save-restriction',
|
|
1894 use `save-excursion' outermost:
|
|
1895 (save-excursion (save-restriction ...))
|
|
1896 */ )
|
|
1897 (body)
|
|
1898 Lisp_Object body;
|
|
1899 {
|
|
1900 /* This function can GC */
|
|
1901 int speccount = specpdl_depth ();
|
|
1902
|
|
1903 record_unwind_protect (save_restriction_restore, save_restriction_save ());
|
|
1904
|
|
1905 return unbind_to (speccount, Fprogn (body));
|
|
1906 }
|
|
1907
|
|
1908
|
|
1909 DEFUN ("format", Fformat, Sformat, 1, MANY, 0 /*
|
|
1910 Format a string out of a control-string and arguments.
|
|
1911 The first argument is a control string.
|
|
1912 The other arguments are substituted into it to make the result, a string.
|
|
1913 It may contain %-sequences meaning to substitute the next argument.
|
|
1914 %s means print all objects as-is, using `princ'.
|
|
1915 %S means print all objects as s-expressions, using `prin1'.
|
|
1916 %d or %i means print as an integer in decimal (%o octal, %x lowercase hex,
|
|
1917 %X uppercase hex).
|
|
1918 %c means print as a single character.
|
|
1919 %f means print as a floating-point number in fixed notation (e.g. 785.200).
|
|
1920 %e or %E means print as a floating-point number in scientific notation
|
|
1921 (e.g. 7.85200e+03).
|
|
1922 %g or %G means print as a floating-point number in \"pretty format\";
|
|
1923 depending on the number, either %f or %e/%E format will be used, and
|
|
1924 trailing zeroes are removed from the fractional part.
|
|
1925 The argument used for all but %s and %S must be a number. It will be
|
|
1926 converted to an integer or a floating-point number as necessary.
|
|
1927
|
|
1928 %$ means reposition to read a specific numbered argument; for example,
|
|
1929 %3$s would apply the `%s' to the third argument after the control string,
|
|
1930 and the next format directive would use the fourth argument, the
|
|
1931 following one the fifth argument, etc. (There must be a positive integer
|
|
1932 between the % and the $).
|
|
1933 Zero or more of the flag characters `-', `+', ` ', `0', and `#' may be
|
|
1934 specified between the optional repositioning spec and the conversion
|
|
1935 character; see below.
|
|
1936 An optional minimum field width may be specified after any flag characters
|
|
1937 and before the conversion character; it specifies the minimum number of
|
|
1938 characters that the converted argument will take up. Padding will be
|
|
1939 added on the left (or on the right, if the `-' flag is specified), as
|
|
1940 necessary. Padding is done with spaces, or with zeroes if the `0' flag
|
|
1941 is specified.
|
|
1942 An optional period character and precision may be specified after any
|
|
1943 minimum field width. It specifies the minimum number of digits to
|
|
1944 appear in %d, %i, %o, %x, and %X conversions (the number is padded
|
|
1945 on the left with zeroes as necessary); the number of digits printed
|
|
1946 after the decimal point for %f, %e, and %E conversions; the number
|
|
1947 of significant digits printed in %g and %G conversions; and the
|
|
1948 maximum number of non-padding characters printed in %s and %S
|
|
1949 conversions. The default precision for floating-point conversions
|
|
1950 is six.
|
|
1951
|
|
1952 The ` ' and `+' flags mean prefix non-negative numbers with a space or
|
|
1953 plus sign, respectively.
|
|
1954 The `#' flag means print numbers in an alternate, more verbose format:
|
|
1955 octal numbers begin with zero; hex numbers begin with a 0x or 0X;
|
|
1956 a decimal point is printed in %f, %e, and %E conversions even if no
|
|
1957 numbers are printed after it; and trailing zeroes are not omitted in
|
|
1958 %g and %G conversions.
|
|
1959
|
|
1960 Use %% to put a single % into the output.
|
|
1961 */ )
|
|
1962 (nargs, args)
|
|
1963 int nargs;
|
|
1964 Lisp_Object *args;
|
|
1965 {
|
|
1966 /* It should not be necessary to GCPRO ARGS, because
|
|
1967 the caller in the interpreter should take care of that. */
|
|
1968
|
|
1969 CHECK_STRING (args[0]);
|
|
1970 return emacs_doprnt_string_lisp (0, args[0], 0, nargs - 1, args + 1);
|
|
1971 }
|
|
1972
|
|
1973
|
|
1974 DEFUN ("char-equal", Fchar_equal, Schar_equal, 2, 3, 0 /*
|
|
1975 Return t if two characters match, optionally ignoring case.
|
|
1976 Both arguments must be characters (i.e. integers).
|
|
1977 Case is ignored if `case-fold-search' is non-nil in BUFFER.
|
|
1978 If BUFFER is nil, the current buffer is assumed.
|
|
1979 */ )
|
|
1980 (c1, c2, buffer)
|
|
1981 Lisp_Object c1, c2, buffer;
|
|
1982 {
|
|
1983 Emchar x1, x2;
|
|
1984 struct buffer *buf = decode_buffer (buffer, 1);
|
|
1985
|
|
1986 CHECK_CHAR_COERCE_INT (c1);
|
|
1987 CHECK_CHAR_COERCE_INT (c2);
|
|
1988 x1 = XCHAR (c1);
|
|
1989 x2 = XCHAR (c2);
|
|
1990
|
|
1991 if (!NILP (buf->case_fold_search)
|
|
1992 ? DOWNCASE (buf, x1) == DOWNCASE (buf, x2)
|
|
1993 : x1 == x2)
|
|
1994 return Qt;
|
|
1995 return Qnil;
|
|
1996 }
|
|
1997
|
|
1998 #if 0 /* Undebugged FSFmacs code */
|
|
1999 /* Transpose the markers in two regions of the current buffer, and
|
|
2000 adjust the ones between them if necessary (i.e.: if the regions
|
|
2001 differ in size).
|
|
2002
|
|
2003 Traverses the entire marker list of the buffer to do so, adding an
|
|
2004 appropriate amount to some, subtracting from some, and leaving the
|
|
2005 rest untouched. Most of this is copied from adjust_markers in insdel.c.
|
|
2006
|
|
2007 It's the caller's job to see that (start1 <= end1 <= start2 <= end2). */
|
|
2008
|
|
2009 void
|
|
2010 transpose_markers (Bufpos start1, Bufpos end1, Bufpos start2, Bufpos end2)
|
|
2011 {
|
|
2012 Charcount amt1, amt2, diff;
|
|
2013 Bufpos mpos;
|
|
2014 Lisp_Object marker;
|
|
2015 struct buffer *buf = current_buffer;
|
|
2016
|
|
2017 /* Update point as if it were a marker. */
|
|
2018 if (BUF_PT (buf) < start1)
|
|
2019 ;
|
|
2020 else if (BUF_PT (buf) < end1)
|
|
2021 BUF_SET_PT (buf, BUF_PT (buf) + (end2 - end1));
|
|
2022 else if (BUF_PT (buf) < start2)
|
|
2023 BUF_SET_PT (buf, BUF_PT (buf) + (end2 - start2) - (end1 - start1));
|
|
2024 else if (BUF_PT (buf) < end2)
|
|
2025 BUF_SET_PT (buf, BUF_PT (buf) - (start2 - start1));
|
|
2026
|
|
2027 /* We used to adjust the endpoints here to account for the gap, but that
|
|
2028 isn't good enough. Even if we assume the caller has tried to move the
|
|
2029 gap out of our way, it might still be at start1 exactly, for example;
|
|
2030 and that places it `inside' the interval, for our purposes. The amount
|
|
2031 of adjustment is nontrivial if there's a `denormalized' marker whose
|
|
2032 position is between GPT and GPT + GAP_SIZE, so it's simpler to leave
|
|
2033 the dirty work to Fmarker_position, below. */
|
|
2034
|
|
2035 /* The difference between the region's lengths */
|
|
2036 diff = (end2 - start2) - (end1 - start1);
|
|
2037
|
|
2038 /* For shifting each marker in a region by the length of the other
|
|
2039 * region plus the distance between the regions.
|
|
2040 */
|
|
2041 amt1 = (end2 - start2) + (start2 - end1);
|
|
2042 amt2 = (end1 - start1) + (start2 - end1);
|
|
2043
|
|
2044 for (marker = BUF_MARKERS (buf); !NILP (marker);
|
|
2045 marker = XMARKER (marker)->chain)
|
|
2046 {
|
|
2047 mpos = marker_position (marker);
|
|
2048 if (mpos >= start1 && mpos < end2)
|
|
2049 {
|
|
2050 if (mpos < end1)
|
|
2051 mpos += amt1;
|
|
2052 else if (mpos < start2)
|
|
2053 mpos += diff;
|
|
2054 else
|
|
2055 mpos -= amt2;
|
|
2056 set_marker_position (marker, mpos);
|
|
2057 }
|
|
2058 }
|
|
2059 }
|
|
2060
|
|
2061 #endif
|
|
2062
|
|
2063 DEFUN ("transpose-regions", Ftranspose_regions, Stranspose_regions, 4, 5, 0 /*
|
|
2064 Transpose region START1 to END1 with START2 to END2.
|
|
2065 The regions may not be overlapping, because the size of the buffer is
|
|
2066 never changed in a transposition.
|
|
2067
|
|
2068 Optional fifth arg LEAVE_MARKERS, if non-nil, means don't transpose
|
|
2069 any markers that happen to be located in the regions. (#### BUG: currently
|
|
2070 this function always acts as if LEAVE_MARKERS is non-nil.)
|
|
2071
|
|
2072 Transposing beyond buffer boundaries is an error.
|
|
2073 */ )
|
|
2074 (startr1, endr1, startr2, endr2, leave_markers)
|
|
2075 Lisp_Object startr1, endr1, startr2, endr2, leave_markers;
|
|
2076 {
|
|
2077 Bufpos start1, end1, start2, end2;
|
|
2078 Charcount len1, len2;
|
|
2079 Lisp_Object string1, string2;
|
|
2080 struct buffer *buf = current_buffer;
|
|
2081
|
|
2082 get_buffer_range_char (buf, startr1, endr1, &start1, &end1, 0);
|
|
2083 get_buffer_range_char (buf, startr2, endr2, &start2, &end2, 0);
|
|
2084
|
|
2085 len1 = end1 - start1;
|
|
2086 len2 = end2 - start2;
|
|
2087
|
|
2088 if (start2 < end1)
|
|
2089 error ("transposed regions not properly ordered");
|
|
2090 else if (start1 == end1 || start2 == end2)
|
|
2091 error ("transposed region may not be of length 0");
|
|
2092
|
|
2093 string1 = make_string_from_buffer (buf, start1, len1);
|
|
2094 string2 = make_string_from_buffer (buf, start2, len2);
|
|
2095 buffer_delete_range (buf, start2, end2, 0);
|
|
2096 buffer_insert_lisp_string_1 (buf, start2, string1, 0);
|
|
2097 buffer_delete_range (buf, start1, end1, 0);
|
|
2098 buffer_insert_lisp_string_1 (buf, start1, string2, 0);
|
|
2099
|
|
2100 /* In FSFmacs there is a whole bunch of really ugly code here
|
|
2101 to attempt to transpose the regions without using up any
|
|
2102 extra memory. Although the intent may be good, the result
|
|
2103 was highly bogus. */
|
|
2104
|
|
2105 return Qnil;
|
|
2106 }
|
|
2107
|
|
2108
|
|
2109 /************************************************************************/
|
|
2110 /* initialization */
|
|
2111 /************************************************************************/
|
|
2112
|
|
2113 void
|
|
2114 syms_of_editfns (void)
|
|
2115 {
|
|
2116 defsymbol (&Qpoint, "point");
|
|
2117 defsymbol (&Qmark, "mark");
|
|
2118 defsymbol (&Qregion_beginning, "region-beginning");
|
|
2119 defsymbol (&Qregion_end, "region-end");
|
|
2120 defsymbol (&Qformat, "format");
|
|
2121
|
|
2122 defsubr (&Schar_equal);
|
|
2123 defsubr (&Sgoto_char);
|
|
2124 defsubr (&Sstring_to_char);
|
|
2125 defsubr (&Schar_to_string);
|
|
2126 defsubr (&Sbuffer_substring);
|
|
2127
|
|
2128 defsubr (&Spoint_marker);
|
|
2129 defsubr (&Smark_marker);
|
|
2130 defsubr (&Spoint);
|
|
2131 defsubr (&Sregion_beginning);
|
|
2132 defsubr (&Sregion_end);
|
|
2133 defsubr (&Ssave_excursion);
|
|
2134
|
|
2135 defsubr (&Sbufsize);
|
|
2136 defsubr (&Spoint_max);
|
|
2137 defsubr (&Spoint_min);
|
|
2138 defsubr (&Spoint_min_marker);
|
|
2139 defsubr (&Spoint_max_marker);
|
|
2140
|
|
2141 defsubr (&Sbobp);
|
|
2142 defsubr (&Seobp);
|
|
2143 defsubr (&Sbolp);
|
|
2144 defsubr (&Seolp);
|
|
2145 defsubr (&Sfollowing_char);
|
|
2146 defsubr (&Spreceding_char);
|
|
2147 defsubr (&Schar_after);
|
|
2148 defsubr (&Sinsert);
|
|
2149 defsubr (&Sinsert_string);
|
|
2150 defsubr (&Sinsert_before_markers);
|
|
2151 defsubr (&Sinsert_char);
|
|
2152
|
|
2153 defsubr (&Suser_login_name);
|
|
2154 defsubr (&Suser_real_login_name);
|
|
2155 defsubr (&Suser_uid);
|
|
2156 defsubr (&Suser_real_uid);
|
|
2157 defsubr (&Suser_full_name);
|
|
2158 defsubr (&Semacs_pid);
|
|
2159 defsubr (&Scurrent_time);
|
|
2160 defsubr (&Scurrent_process_time);
|
|
2161 defsubr (&Sformat_time_string);
|
|
2162 defsubr (&Sdecode_time);
|
|
2163 defsubr (&Sencode_time);
|
|
2164 defsubr (&Scurrent_time_string);
|
|
2165 defsubr (&Scurrent_time_zone);
|
|
2166 defsubr (&Sset_time_zone_rule);
|
|
2167 defsubr (&Ssystem_name);
|
|
2168 defsubr (&Sformat);
|
|
2169
|
|
2170 defsubr (&Sinsert_buffer_substring);
|
|
2171 defsubr (&Scompare_buffer_substrings);
|
|
2172 defsubr (&Ssubst_char_in_region);
|
|
2173 defsubr (&Stranslate_region);
|
|
2174 defsubr (&Sdelete_region);
|
|
2175 defsubr (&Swiden);
|
|
2176 defsubr (&Snarrow_to_region);
|
|
2177 defsubr (&Ssave_restriction);
|
|
2178 defsubr (&Stranspose_regions);
|
|
2179
|
|
2180 defsymbol (&Qzmacs_update_region, "zmacs-update-region");
|
|
2181 defsymbol (&Qzmacs_deactivate_region, "zmacs-deactivate-region");
|
|
2182 defsymbol (&Qzmacs_region_buffer, "zmacs-region-buffer");
|
|
2183 }
|
|
2184
|
|
2185 void
|
|
2186 vars_of_editfns (void)
|
|
2187 {
|
|
2188 staticpro (&Vsystem_name);
|
|
2189 #if 0
|
|
2190 staticpro (&Vuser_full_name);
|
|
2191 staticpro (&Vuser_name);
|
|
2192 staticpro (&Vuser_real_name);
|
|
2193 #endif
|
|
2194 DEFVAR_BOOL ("zmacs-regions", &zmacs_regions /*
|
|
2195 *Whether LISPM-style active regions should be used.
|
|
2196 This means that commands which operate on the region (the area between the
|
|
2197 point and the mark) will only work while the region is in the ``active''
|
|
2198 state, which is indicated by highlighting. Executing most commands causes
|
|
2199 the region to not be in the active state, so (for example) \\[kill-region] will only
|
|
2200 work immediately after activating the region.
|
|
2201
|
|
2202 More specifically:
|
|
2203
|
|
2204 - Commands which operate on the region only work if the region is active.
|
|
2205 - Only a very small set of commands cause the region to become active:
|
|
2206 Those commands whose semantics are to mark an area, like mark-defun.
|
|
2207 - The region is deactivated after each command that is executed, except that:
|
|
2208 - \"Motion\" commands do not change whether the region is active or not.
|
|
2209
|
|
2210 set-mark-command (C-SPC) pushes a mark and activates the region. Moving the
|
|
2211 cursor with normal motion commands (C-n, C-p, etc) will cause the region
|
|
2212 between point and the recently-pushed mark to be highlighted. It will
|
|
2213 remain highlighted until some non-motion comand is executed.
|
|
2214
|
|
2215 exchange-point-and-mark (\\[exchange-point-and-mark]) activates the region. So if you mark a
|
|
2216 region and execute a command that operates on it, you can reactivate the
|
|
2217 same region with \\[exchange-point-and-mark] (or perhaps \\[exchange-point-and-mark] \\[exchange-point-and-mark]) to operate on it
|
|
2218 again.
|
|
2219
|
|
2220 Generally, commands which push marks as a means of navigation (like
|
|
2221 beginning-of-buffer and end-of-buffer (M-< and M->)) do not activate the
|
|
2222 region. But commands which push marks as a means of marking an area of
|
|
2223 text (like mark-defun (\\[mark-defun]), mark-word (\\[mark-word]) or mark-whole-buffer (\\[mark-whole-buffer]))
|
|
2224 do activate the region.
|
|
2225
|
|
2226 The way the command loop actually works with regard to deactivating the
|
|
2227 region is as follows:
|
|
2228
|
|
2229 - If the variable `zmacs-region-stays' has been set to t during the command
|
|
2230 just executed, the region is left alone (this is how the motion commands
|
|
2231 make the region stay around; see the `_' flag in the `interactive'
|
|
2232 specification). `zmacs-region-stays' is reset to nil before each command
|
|
2233 is executed.
|
|
2234 - If the function `zmacs-activate-region' has been called during the command
|
|
2235 just executed, the region is left alone. Very few functions should
|
|
2236 actually call this function.
|
|
2237 - Otherwise, if the region is active, the region is deactivated and
|
|
2238 the `zmacs-deactivate-region-hook' is called.
|
|
2239 */ );
|
|
2240 /* Zmacs style active regions are now ON by default */
|
|
2241 zmacs_regions = 1;
|
|
2242
|
|
2243 DEFVAR_BOOL ("zmacs-region-active-p", &zmacs_region_active_p /*
|
|
2244 Do not alter this. It is for internal use only.
|
|
2245 */ );
|
|
2246 zmacs_region_active_p = 0;
|
|
2247
|
|
2248 DEFVAR_BOOL ("zmacs-region-stays", &zmacs_region_stays /*
|
|
2249 Commands which do not wish to affect whether the region is currently
|
|
2250 highlighted should set this to t. Normally, the region is turned off after
|
|
2251 executing each command that did not explicitly turn it on with the function
|
|
2252 zmacs-activate-region. Setting this to true lets a command be non-intrusive.
|
|
2253 See the variable `zmacs-regions'.
|
|
2254 */ );
|
|
2255 zmacs_region_stays = 0;
|
|
2256
|
|
2257 DEFVAR_BOOL ("atomic-extent-goto-char-p", &atomic_extent_goto_char_p /*
|
|
2258 Do not use this -- it will be going away soon.
|
|
2259 Indicates if `goto-char' has just been run. This information is allegedly
|
|
2260 needed to get the desired behavior for atomic extents and unfortunately
|
|
2261 is not available by any other means.
|
|
2262 */ );
|
|
2263 atomic_extent_goto_char_p = 0;
|
|
2264 }
|