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