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