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