annotate src/editfns.c @ 20878:34e0c8eb49eb

(Fposition_bytes): Allow marker as arg POSITION. Use XINT for type consistency.
author Kenichi Handa <handa@m17n.org>
date Tue, 10 Feb 1998 03:55:04 +0000
parents 9f9937a74050
children 64d2baa47498
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /* Lisp functions pertaining to editing.
20706
d43ba5d91281 Update copyright year.
Richard M. Stallman <rms@gnu.org>
parents: 20696
diff changeset
2 Copyright (C) 1985,86,87,89,93,94,95,96,97,98 Free Software Foundation, Inc.
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 This file is part of GNU Emacs.
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
12244
ac7375e60931 Update GPL to version 2.
Karl Heuer <kwzh@gnu.org>
parents: 12063
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 any later version.
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 GNU General Public License for more details.
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
14862
e368c0d12356 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 14440
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
e368c0d12356 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 14440
diff changeset
19 Boston, MA 02111-1307, USA. */
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21
2962
79314d830f7d * editfns.c: #include <sys/types.h>, to get time_t for Eggert's
Jim Blandy <jimb@redhat.com>
parents: 2921
diff changeset
22 #include <sys/types.h>
79314d830f7d * editfns.c: #include <sys/types.h>, to get time_t for Eggert's
Jim Blandy <jimb@redhat.com>
parents: 2921
diff changeset
23
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 4420
diff changeset
24 #include <config.h>
372
481e29c1e27e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 330
diff changeset
25
481e29c1e27e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 330
diff changeset
26 #ifdef VMS
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
27 #include "vms-pwd.h"
372
481e29c1e27e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 330
diff changeset
28 #else
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 #include <pwd.h>
372
481e29c1e27e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 330
diff changeset
30 #endif
481e29c1e27e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 330
diff changeset
31
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 #include "lisp.h"
1285
d50533e23dff * editfns.c (make_buffer_string): Call copy_intervals_to_string().
Joseph Arceneaux <jla@gnu.org>
parents: 1254
diff changeset
33 #include "intervals.h"
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 #include "buffer.h"
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
35 #include "charset.h"
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 #include "window.h"
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
38 #include "systime.h"
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 #define min(a, b) ((a) < (b) ? (a) : (b))
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 #define max(a, b) ((a) > (b) ? (a) : (b))
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42
19441
2e2b54ae9b9d (NULL): Define, if not defined.
Richard M. Stallman <rms@gnu.org>
parents: 19416
diff changeset
43 #ifndef NULL
2e2b54ae9b9d (NULL): Define, if not defined.
Richard M. Stallman <rms@gnu.org>
parents: 19416
diff changeset
44 #define NULL 0
2e2b54ae9b9d (NULL): Define, if not defined.
Richard M. Stallman <rms@gnu.org>
parents: 19416
diff changeset
45 #endif
2e2b54ae9b9d (NULL): Define, if not defined.
Richard M. Stallman <rms@gnu.org>
parents: 19416
diff changeset
46
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
47 extern char **environ;
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
48 extern Lisp_Object make_time ();
9657
0fc126c193e7 (Finsert_buffer_substring): Use insert_from_buffer instead of insert.
Karl Heuer <kwzh@gnu.org>
parents: 9572
diff changeset
49 extern void insert_from_buffer ();
16269
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
50 static int tm_diff ();
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
51 static void update_buffer_properties ();
20338
d55ca55974a0 (emacs_strftime): New decl.
Paul Eggert <eggert@twinsun.com>
parents: 20311
diff changeset
52 size_t emacs_strftime ();
14201
ff372902386d (set_time_zone_rule): No longer static.
Richard M. Stallman <rms@gnu.org>
parents: 14126
diff changeset
53 void set_time_zone_rule ();
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
54
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
55 Lisp_Object Vbuffer_access_fontify_functions;
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
56 Lisp_Object Qbuffer_access_fontify_functions;
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
57 Lisp_Object Vbuffer_access_fontified_property;
9657
0fc126c193e7 (Finsert_buffer_substring): Use insert_from_buffer instead of insert.
Karl Heuer <kwzh@gnu.org>
parents: 9572
diff changeset
58
17829
2d98572c57ab Declare Fuser_full_name as Lisp_Object in advance to
Kenichi Handa <handa@m17n.org>
parents: 17115
diff changeset
59 Lisp_Object Fuser_full_name ();
2d98572c57ab Declare Fuser_full_name as Lisp_Object in advance to
Kenichi Handa <handa@m17n.org>
parents: 17115
diff changeset
60
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 /* Some static data, and a function to initialize it for each run */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 Lisp_Object Vsystem_name;
12026
505a894d943e (syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents: 11912
diff changeset
64 Lisp_Object Vuser_real_login_name; /* login name of current user ID */
505a894d943e (syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents: 11912
diff changeset
65 Lisp_Object Vuser_full_name; /* full name of current user */
505a894d943e (syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents: 11912
diff changeset
66 Lisp_Object Vuser_login_name; /* user name from LOGNAME or USER */
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 void
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 init_editfns ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 {
330
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
71 char *user_name;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 register unsigned char *p, *q, *r;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 struct passwd *pw; /* password entry for the current user */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 Lisp_Object tem;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 /* Set up system_name even when dumping. */
7907
148ad20d6774 (init_editfns): Call init_system_name instead of get_system_name.
Karl Heuer <kwzh@gnu.org>
parents: 7862
diff changeset
77 init_system_name ();
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 #ifndef CANNOT_DUMP
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 /* Don't bother with this on initial start when just dumping out */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 if (!initialized)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 return;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 #endif /* not CANNOT_DUMP */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 pw = (struct passwd *) getpwuid (getuid ());
9572
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
86 #ifdef MSDOS
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
87 /* We let the real user name default to "root" because that's quite
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
88 accurate on MSDOG and because it lets Emacs find the init file.
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
89 (The DVX libraries override the Djgpp libraries here.) */
12026
505a894d943e (syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents: 11912
diff changeset
90 Vuser_real_login_name = build_string (pw ? pw->pw_name : "root");
9572
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
91 #else
12026
505a894d943e (syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents: 11912
diff changeset
92 Vuser_real_login_name = build_string (pw ? pw->pw_name : "unknown");
9572
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
93 #endif
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94
330
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
95 /* Get the effective user name, by consulting environment variables,
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
96 or the effective uid if those are unset. */
5907
5fdb226fe9a4 (init_editfns): Look at LOGNAME before USER.
Karl Heuer <kwzh@gnu.org>
parents: 5884
diff changeset
97 user_name = (char *) getenv ("LOGNAME");
330
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
98 if (!user_name)
9801
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
99 #ifdef WINDOWSNT
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
100 user_name = (char *) getenv ("USERNAME"); /* it's USERNAME on NT */
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
101 #else /* WINDOWSNT */
5907
5fdb226fe9a4 (init_editfns): Look at LOGNAME before USER.
Karl Heuer <kwzh@gnu.org>
parents: 5884
diff changeset
102 user_name = (char *) getenv ("USER");
9801
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
103 #endif /* WINDOWSNT */
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 if (!user_name)
330
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
105 {
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
106 pw = (struct passwd *) getpwuid (geteuid ());
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
107 user_name = (char *) (pw ? pw->pw_name : "unknown");
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
108 }
12026
505a894d943e (syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents: 11912
diff changeset
109 Vuser_login_name = build_string (user_name);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110
330
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
111 /* If the user name claimed in the environment vars differs from
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
112 the real uid, use the claimed name to find the full name. */
12026
505a894d943e (syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents: 11912
diff changeset
113 tem = Fstring_equal (Vuser_login_name, Vuser_real_login_name);
16641
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
114 Vuser_full_name = Fuser_full_name (NILP (tem)? make_number (geteuid())
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
115 : Vuser_login_name);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116
11447
d51e912495be (init_editfns): Add casts.
Richard M. Stallman <rms@gnu.org>
parents: 11433
diff changeset
117 p = (unsigned char *) getenv ("NAME");
11135
9ab21ef32537 (init_editfns): Use NAME envvar to init user-full-name.
Richard M. Stallman <rms@gnu.org>
parents: 10480
diff changeset
118 if (p)
9ab21ef32537 (init_editfns): Use NAME envvar to init user-full-name.
Richard M. Stallman <rms@gnu.org>
parents: 10480
diff changeset
119 Vuser_full_name = build_string (p);
16683
6802dbd07a80 (Fuser_full_name): Return nil if the specified user doesn't exist.
Richard M. Stallman <rms@gnu.org>
parents: 16648
diff changeset
120 else if (NILP (Vuser_full_name))
6802dbd07a80 (Fuser_full_name): Return nil if the specified user doesn't exist.
Richard M. Stallman <rms@gnu.org>
parents: 16648
diff changeset
121 Vuser_full_name = build_string ("unknown");
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 DEFUN ("char-to-string", Fchar_to_string, Schar_to_string, 1, 1, 0,
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
125 "Convert arg CHAR to a string containing multi-byte form of that character.")
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
126 (character)
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
127 Lisp_Object character;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 {
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
129 int len;
20311
2841215c1cb4 (Fchar_to_string): Declare `workbuf' as unsigned char.
Andreas Schwab <schwab@suse.de>
parents: 20229
diff changeset
130 unsigned char workbuf[4], *str;
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
131
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
132 CHECK_NUMBER (character, 0);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
134 len = CHAR_STRING (XFASTINT (character), workbuf, str);
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
135 return make_multibyte_string (str, 1, len);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 DEFUN ("string-to-char", Fstring_to_char, Sstring_to_char, 1, 1, 0,
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
139 "Convert arg STRING to a character, the first character of that string.\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
140 A multibyte character is handled correctly.")
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
141 (string)
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
142 register Lisp_Object string;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 register Lisp_Object val;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 register struct Lisp_String *p;
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
146 CHECK_STRING (string, 0);
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
147 p = XSTRING (string);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 if (p->size)
20834
95a80c1e06c3 (Fsubst_char_in_region): Handle character-base
Kenichi Handa <handa@m17n.org>
parents: 20826
diff changeset
149 XSETFASTINT (val, STRING_CHAR (p->data, p->size_byte));
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 else
9305
ac077e2a75f1 (Fstring_to_char, Fpoint, Fbufsize, Fpoint_min, Fpoint_max, Ffollowing_char,
Karl Heuer <kwzh@gnu.org>
parents: 9265
diff changeset
151 XSETFASTINT (val, 0);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 return val;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 static Lisp_Object
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
156 buildmark (charpos, bytepos)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
157 int charpos, bytepos;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 register Lisp_Object mark;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 mark = Fmake_marker ();
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
161 set_marker_both (mark, Qnil, charpos, bytepos);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 return mark;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 DEFUN ("point", Fpoint, Spoint, 0, 0, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 "Return value of point, as an integer.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 Beginning of buffer is position (point-min)")
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 Lisp_Object temp;
16039
855c8d8ba0f0 Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents: 15910
diff changeset
171 XSETFASTINT (temp, PT);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 return temp;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 DEFUN ("point-marker", Fpoint_marker, Spoint_marker, 0, 0, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 "Return value of point, as a marker object.")
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
179 return buildmark (PT, PT_BYTE);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 int
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 clip_to_bounds (lower, num, upper)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 int lower, num, upper;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 if (num < lower)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 return lower;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 else if (num > upper)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 return upper;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 else
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 return num;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 DEFUN ("goto-char", Fgoto_char, Sgoto_char, 1, 1, "NGoto char: ",
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 "Set point to POSITION, a number or marker.\n\
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
196 Beginning of buffer is position (point-min), end is (point-max).\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
197 If the position is in the middle of a multibyte form,\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
198 the actual point is set at the head of the multibyte form\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
199 except in the case that `enable-multibyte-characters' is nil.")
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
200 (position)
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
201 register Lisp_Object position;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 {
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
203 int pos;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
204 unsigned char *p;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
205
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
206 if (MARKERP (position))
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
207 {
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
208 pos = marker_position (position);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
209 if (pos < BEGV)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
210 SET_PT_BOTH (BEGV, BEGV_BYTE);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
211 else if (pos > ZV)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
212 SET_PT_BOTH (ZV, ZV_BYTE);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
213 else
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
214 SET_PT_BOTH (pos, marker_byte_position (position));
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
215
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
216 return position;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
217 }
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
218
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
219 CHECK_NUMBER_COERCE_MARKER (position, 0);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
221 pos = clip_to_bounds (BEGV, XINT (position), ZV);
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
222 SET_PT (pos);
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
223 return position;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 static Lisp_Object
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 region_limit (beginningp)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 int beginningp;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 {
4047
e950abdc9ed2 (region_limit): Declare Vmark_even_if_inactive.
Roland McGrath <roland@gnu.org>
parents: 4038
diff changeset
230 extern Lisp_Object Vmark_even_if_inactive; /* Defined in callint.c. */
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 register Lisp_Object m;
4038
03a4c3912c13 (region_limit): Don't error if Vmark_even_if_inactive is set. When the
Roland McGrath <roland@gnu.org>
parents: 4019
diff changeset
232 if (!NILP (Vtransient_mark_mode) && NILP (Vmark_even_if_inactive)
03a4c3912c13 (region_limit): Don't error if Vmark_even_if_inactive is set. When the
Roland McGrath <roland@gnu.org>
parents: 4019
diff changeset
233 && NILP (current_buffer->mark_active))
03a4c3912c13 (region_limit): Don't error if Vmark_even_if_inactive is set. When the
Roland McGrath <roland@gnu.org>
parents: 4019
diff changeset
234 Fsignal (Qmark_inactive, Qnil);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 m = Fmarker_position (current_buffer->mark);
488
4fddd0f0fc33 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 448
diff changeset
236 if (NILP (m)) error ("There is no region now");
16039
855c8d8ba0f0 Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents: 15910
diff changeset
237 if ((PT < XFASTINT (m)) == beginningp)
855c8d8ba0f0 Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents: 15910
diff changeset
238 return (make_number (PT));
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 else
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 return (m);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 DEFUN ("region-beginning", Fregion_beginning, Sregion_beginning, 0, 0, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 "Return position of beginning of region, as an integer.")
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 return (region_limit (1));
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 DEFUN ("region-end", Fregion_end, Sregion_end, 0, 0, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 "Return position of end of region, as an integer.")
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 return (region_limit (0));
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 DEFUN ("mark-marker", Fmark_marker, Smark_marker, 0, 0, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 "Return this buffer's mark, as a marker object.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 Watch out! Moving this marker changes the mark position.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 If you set the marker not to point anywhere, the buffer will have no mark.")
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 return current_buffer->mark;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 }
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
265
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
266 DEFUN ("line-beginning-position", Fline_beginning_position, Sline_beginning_position,
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
267 0, 1, 0,
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
268 "Return the character position of the first character on the current line.\n\
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
269 With argument N not nil or 1, move forward N - 1 lines first.\n\
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
270 If scan reaches end of buffer, return that position.\n\
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
271 This function does not move point.")
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
272 (n)
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
273 Lisp_Object n;
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
274 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
275 register int orig, orig_byte, end;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
277 if (NILP (n))
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
278 XSETFASTINT (n, 1);
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
279 else
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
280 CHECK_NUMBER (n, 0);
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
281
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
282 orig = PT;
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
283 orig_byte = PT_BYTE;
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
284 Fforward_line (make_number (XINT (n) - 1));
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
285 end = PT;
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
286 SET_PT_BOTH (orig, orig_byte);
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
287
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
288 return make_number (end);
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
289 }
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
290
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
291 DEFUN ("line-end-position", Fline_end_position, Sline_end_position,
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
292 0, 1, 0,
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
293 "Return the character position of the last character on the current line.\n\
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
294 With argument N not nil or 1, move forward N - 1 lines first.\n\
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
295 If scan reaches end of buffer, return that position.\n\
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
296 This function does not move point.")
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
297 (n)
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
298 Lisp_Object n;
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
299 {
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
300 if (NILP (n))
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
301 XSETFASTINT (n, 1);
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
302 else
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
303 CHECK_NUMBER (n, 0);
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
304
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
305 return make_number (find_before_next_newline
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
306 (PT, 0, XINT (n) - (XINT (n) <= 0)));
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
307 }
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
308
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 Lisp_Object
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 save_excursion_save ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 {
1254
c7e7e3438711 * editfns.c (save_excursion_save, save_excursion_restore):
Jim Blandy <jimb@redhat.com>
parents: 1117
diff changeset
312 register int visible = (XBUFFER (XWINDOW (selected_window)->buffer)
c7e7e3438711 * editfns.c (save_excursion_save, save_excursion_restore):
Jim Blandy <jimb@redhat.com>
parents: 1117
diff changeset
313 == current_buffer);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 return Fcons (Fpoint_marker (),
12982
385a67ad96c3 (save_excursion_save): Pass the new arg to Fcopy_marker.
Richard M. Stallman <rms@gnu.org>
parents: 12973
diff changeset
316 Fcons (Fcopy_marker (current_buffer->mark, Qnil),
2049
a358c97a23e4 (save_excursion_save): Save mark_active of buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1916
diff changeset
317 Fcons (visible ? Qt : Qnil,
a358c97a23e4 (save_excursion_save): Save mark_active of buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1916
diff changeset
318 current_buffer->mark_active)));
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 Lisp_Object
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 save_excursion_restore (info)
15075
e8613675066c (save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents: 15015
diff changeset
323 Lisp_Object info;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 {
15075
e8613675066c (save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents: 15015
diff changeset
325 Lisp_Object tem, tem1, omark, nmark;
e8613675066c (save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents: 15015
diff changeset
326 struct gcpro gcpro1, gcpro2, gcpro3;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 tem = Fmarker_buffer (Fcar (info));
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 /* If buffer being returned to is now deleted, avoid error */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 /* Otherwise could get error here while unwinding to top level
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 and crash */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 /* In that case, Fmarker_buffer returns nil now. */
488
4fddd0f0fc33 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 448
diff changeset
333 if (NILP (tem))
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 return Qnil;
15075
e8613675066c (save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents: 15015
diff changeset
335
e8613675066c (save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents: 15015
diff changeset
336 omark = nmark = Qnil;
e8613675066c (save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents: 15015
diff changeset
337 GCPRO3 (info, omark, nmark);
e8613675066c (save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents: 15015
diff changeset
338
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 Fset_buffer (tem);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 tem = Fcar (info);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 Fgoto_char (tem);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 unchain_marker (tem);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 tem = Fcar (Fcdr (info));
7485
a1b7f72e0ea2 (save_excursion_restore): Don't run activate-mark-hook
Richard M. Stallman <rms@gnu.org>
parents: 7307
diff changeset
344 omark = Fmarker_position (current_buffer->mark);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 Fset_marker (current_buffer->mark, tem, Fcurrent_buffer ());
7485
a1b7f72e0ea2 (save_excursion_restore): Don't run activate-mark-hook
Richard M. Stallman <rms@gnu.org>
parents: 7307
diff changeset
346 nmark = Fmarker_position (tem);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 unchain_marker (tem);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348 tem = Fcdr (Fcdr (info));
4420
8113d9ba472e (save_excursion_restore): Never make the buffer visible.
Richard M. Stallman <rms@gnu.org>
parents: 4358
diff changeset
349 #if 0 /* We used to make the current buffer visible in the selected window
8113d9ba472e (save_excursion_restore): Never make the buffer visible.
Richard M. Stallman <rms@gnu.org>
parents: 4358
diff changeset
350 if that was true previously. That avoids some anomalies.
8113d9ba472e (save_excursion_restore): Never make the buffer visible.
Richard M. Stallman <rms@gnu.org>
parents: 4358
diff changeset
351 But it creates others, and it wasn't documented, and it is simpler
8113d9ba472e (save_excursion_restore): Never make the buffer visible.
Richard M. Stallman <rms@gnu.org>
parents: 4358
diff changeset
352 and cleaner never to alter the window/buffer connections. */
2049
a358c97a23e4 (save_excursion_save): Save mark_active of buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1916
diff changeset
353 tem1 = Fcar (tem);
a358c97a23e4 (save_excursion_save): Save mark_active of buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1916
diff changeset
354 if (!NILP (tem1)
1254
c7e7e3438711 * editfns.c (save_excursion_save, save_excursion_restore):
Jim Blandy <jimb@redhat.com>
parents: 1117
diff changeset
355 && current_buffer != XBUFFER (XWINDOW (selected_window)->buffer))
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356 Fswitch_to_buffer (Fcurrent_buffer (), Qnil);
4420
8113d9ba472e (save_excursion_restore): Never make the buffer visible.
Richard M. Stallman <rms@gnu.org>
parents: 4358
diff changeset
357 #endif /* 0 */
2049
a358c97a23e4 (save_excursion_save): Save mark_active of buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1916
diff changeset
358
a358c97a23e4 (save_excursion_save): Save mark_active of buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1916
diff changeset
359 tem1 = current_buffer->mark_active;
a358c97a23e4 (save_excursion_save): Save mark_active of buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1916
diff changeset
360 current_buffer->mark_active = Fcdr (tem);
6206
67c608b0e2f7 (save_excursion_restore): Don't call Vrun_hooks if nil.
Richard M. Stallman <rms@gnu.org>
parents: 5915
diff changeset
361 if (!NILP (Vrun_hooks))
67c608b0e2f7 (save_excursion_restore): Don't call Vrun_hooks if nil.
Richard M. Stallman <rms@gnu.org>
parents: 5915
diff changeset
362 {
7485
a1b7f72e0ea2 (save_excursion_restore): Don't run activate-mark-hook
Richard M. Stallman <rms@gnu.org>
parents: 7307
diff changeset
363 /* If mark is active now, and either was not active
a1b7f72e0ea2 (save_excursion_restore): Don't run activate-mark-hook
Richard M. Stallman <rms@gnu.org>
parents: 7307
diff changeset
364 or was at a different place, run the activate hook. */
6206
67c608b0e2f7 (save_excursion_restore): Don't call Vrun_hooks if nil.
Richard M. Stallman <rms@gnu.org>
parents: 5915
diff changeset
365 if (! NILP (current_buffer->mark_active))
7485
a1b7f72e0ea2 (save_excursion_restore): Don't run activate-mark-hook
Richard M. Stallman <rms@gnu.org>
parents: 7307
diff changeset
366 {
a1b7f72e0ea2 (save_excursion_restore): Don't run activate-mark-hook
Richard M. Stallman <rms@gnu.org>
parents: 7307
diff changeset
367 if (! EQ (omark, nmark))
a1b7f72e0ea2 (save_excursion_restore): Don't run activate-mark-hook
Richard M. Stallman <rms@gnu.org>
parents: 7307
diff changeset
368 call1 (Vrun_hooks, intern ("activate-mark-hook"));
a1b7f72e0ea2 (save_excursion_restore): Don't run activate-mark-hook
Richard M. Stallman <rms@gnu.org>
parents: 7307
diff changeset
369 }
a1b7f72e0ea2 (save_excursion_restore): Don't run activate-mark-hook
Richard M. Stallman <rms@gnu.org>
parents: 7307
diff changeset
370 /* If mark has ceased to be active, run deactivate hook. */
6206
67c608b0e2f7 (save_excursion_restore): Don't call Vrun_hooks if nil.
Richard M. Stallman <rms@gnu.org>
parents: 5915
diff changeset
371 else if (! NILP (tem1))
67c608b0e2f7 (save_excursion_restore): Don't call Vrun_hooks if nil.
Richard M. Stallman <rms@gnu.org>
parents: 5915
diff changeset
372 call1 (Vrun_hooks, intern ("deactivate-mark-hook"));
67c608b0e2f7 (save_excursion_restore): Don't call Vrun_hooks if nil.
Richard M. Stallman <rms@gnu.org>
parents: 5915
diff changeset
373 }
15075
e8613675066c (save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents: 15015
diff changeset
374 UNGCPRO;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378 DEFUN ("save-excursion", Fsave_excursion, Ssave_excursion, 0, UNEVALLED, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 "Save point, mark, and current buffer; execute BODY; restore those things.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 Executes BODY just like `progn'.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381 The values of point, mark and the current buffer are restored\n\
2049
a358c97a23e4 (save_excursion_save): Save mark_active of buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1916
diff changeset
382 even in case of abnormal exit (throw or error).\n\
a358c97a23e4 (save_excursion_save): Save mark_active of buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1916
diff changeset
383 The state of activation of the mark is also restored.")
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384 (args)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 Lisp_Object args;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 register Lisp_Object val;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 int count = specpdl_ptr - specpdl;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 record_unwind_protect (save_excursion_restore, save_excursion_save ());
16298
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
391
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
392 val = Fprogn (args);
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
393 return unbind_to (count, val);
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
394 }
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
395
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
396 DEFUN ("save-current-buffer", Fsave_current_buffer, Ssave_current_buffer, 0, UNEVALLED, 0,
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
397 "Save the current buffer; execute BODY; restore the current buffer.\n\
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
398 Executes BODY just like `progn'.")
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
399 (args)
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
400 Lisp_Object args;
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
401 {
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
402 register Lisp_Object val;
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
403 int count = specpdl_ptr - specpdl;
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
404
20696
cdbe4824e7f1 (Fsave_current_buffer): Use set_buffer_if_live.
Richard M. Stallman <rms@gnu.org>
parents: 20688
diff changeset
405 record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ());
16298
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
406
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407 val = Fprogn (args);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408 return unbind_to (count, val);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411 DEFUN ("buffer-size", Fbufsize, Sbufsize, 0, 0, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412 "Return the number of characters in the current buffer.")
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
414 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 Lisp_Object temp;
9305
ac077e2a75f1 (Fstring_to_char, Fpoint, Fbufsize, Fpoint_min, Fpoint_max, Ffollowing_char,
Karl Heuer <kwzh@gnu.org>
parents: 9265
diff changeset
416 XSETFASTINT (temp, Z - BEG);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417 return temp;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420 DEFUN ("point-min", Fpoint_min, Spoint_min, 0, 0, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421 "Return the minimum permissible value of point in the current buffer.\n\
4943
7a6aea972b7e Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4714
diff changeset
422 This is 1, unless narrowing (a buffer restriction) is in effect.")
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425 Lisp_Object temp;
9305
ac077e2a75f1 (Fstring_to_char, Fpoint, Fbufsize, Fpoint_min, Fpoint_max, Ffollowing_char,
Karl Heuer <kwzh@gnu.org>
parents: 9265
diff changeset
426 XSETFASTINT (temp, BEGV);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 return temp;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430 DEFUN ("point-min-marker", Fpoint_min_marker, Spoint_min_marker, 0, 0, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 "Return a marker to the minimum permissible value of point in this buffer.\n\
4943
7a6aea972b7e Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4714
diff changeset
432 This is the beginning, unless narrowing (a buffer restriction) is in effect.")
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
434 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
435 return buildmark (BEGV, BEGV_BYTE);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
438 DEFUN ("point-max", Fpoint_max, Spoint_max, 0, 0, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439 "Return the maximum permissible value of point in the current buffer.\n\
4943
7a6aea972b7e Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4714
diff changeset
440 This is (1+ (buffer-size)), unless narrowing (a buffer restriction)\n\
7a6aea972b7e Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4714
diff changeset
441 is in effect, in which case it is less.")
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
444 Lisp_Object temp;
9305
ac077e2a75f1 (Fstring_to_char, Fpoint, Fbufsize, Fpoint_min, Fpoint_max, Ffollowing_char,
Karl Heuer <kwzh@gnu.org>
parents: 9265
diff changeset
445 XSETFASTINT (temp, ZV);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
446 return temp;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
447 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449 DEFUN ("point-max-marker", Fpoint_max_marker, Spoint_max_marker, 0, 0, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450 "Return a marker to the maximum permissible value of point in this buffer.\n\
4943
7a6aea972b7e Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4714
diff changeset
451 This is (1+ (buffer-size)), unless narrowing (a buffer restriction)\n\
7a6aea972b7e Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4714
diff changeset
452 is in effect, in which case it is less.")
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
454 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
455 return buildmark (ZV, ZV_BYTE);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457
20861
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
458 DEFUN ("position-bytes", Fposition_bytes, Sposition_bytes, 1, 1, 0,
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
459 "Return the byte position for character position POSITION.")
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
460 (position)
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
461 {
20878
34e0c8eb49eb (Fposition_bytes): Allow marker as arg POSITION. Use
Kenichi Handa <handa@m17n.org>
parents: 20861
diff changeset
462 CHECK_NUMBER_COERCE_MARKER (position, 1);
34e0c8eb49eb (Fposition_bytes): Allow marker as arg POSITION. Use
Kenichi Handa <handa@m17n.org>
parents: 20861
diff changeset
463 return make_number (CHAR_TO_BYTE (XINT (position)));
20861
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
464 }
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
465
512
b7a1e4e4e7e6 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 488
diff changeset
466 DEFUN ("following-char", Ffollowing_char, Sfollowing_char, 0, 0, 0,
b7a1e4e4e7e6 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 488
diff changeset
467 "Return the character following point, as a number.\n\
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
468 At the end of the buffer or accessible region, return 0.\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
469 If `enable-multibyte-characters' is nil or point is not\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
470 at character boundary, multibyte form is ignored,\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
471 and only one byte following point is returned as a character.")
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
472 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
473 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
474 Lisp_Object temp;
16039
855c8d8ba0f0 Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents: 15910
diff changeset
475 if (PT >= ZV)
9305
ac077e2a75f1 (Fstring_to_char, Fpoint, Fbufsize, Fpoint_min, Fpoint_max, Ffollowing_char,
Karl Heuer <kwzh@gnu.org>
parents: 9265
diff changeset
476 XSETFASTINT (temp, 0);
512
b7a1e4e4e7e6 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 488
diff changeset
477 else
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
478 XSETFASTINT (temp, FETCH_CHAR (PT_BYTE));
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
479 return temp;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
480 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
481
512
b7a1e4e4e7e6 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 488
diff changeset
482 DEFUN ("preceding-char", Fprevious_char, Sprevious_char, 0, 0, 0,
b7a1e4e4e7e6 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 488
diff changeset
483 "Return the character preceding point, as a number.\n\
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
484 At the beginning of the buffer or accessible region, return 0.\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
485 If `enable-multibyte-characters' is nil or point is not\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
486 at character boundary, multi-byte form is ignored,\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
487 and only one byte preceding point is returned as a character.")
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
488 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
489 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
490 Lisp_Object temp;
16039
855c8d8ba0f0 Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents: 15910
diff changeset
491 if (PT <= BEGV)
9305
ac077e2a75f1 (Fstring_to_char, Fpoint, Fbufsize, Fpoint_min, Fpoint_max, Ffollowing_char,
Karl Heuer <kwzh@gnu.org>
parents: 9265
diff changeset
492 XSETFASTINT (temp, 0);
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
493 else if (!NILP (current_buffer->enable_multibyte_characters))
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
494 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
495 int pos = PT_BYTE;
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
496 DEC_POS (pos);
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
497 XSETFASTINT (temp, FETCH_CHAR (pos));
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
498 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
499 else
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
500 XSETFASTINT (temp, FETCH_BYTE (PT_BYTE - 1));
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
501 return temp;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
502 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
503
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
504 DEFUN ("bobp", Fbobp, Sbobp, 0, 0, 0,
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
505 "Return t if point is at the beginning of the buffer.\n\
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
506 If the buffer is narrowed, this means the beginning of the narrowed part.")
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
507 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
508 {
16039
855c8d8ba0f0 Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents: 15910
diff changeset
509 if (PT == BEGV)
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
510 return Qt;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
511 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
512 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
513
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
514 DEFUN ("eobp", Feobp, Seobp, 0, 0, 0,
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
515 "Return t if point is at the end of the buffer.\n\
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
516 If the buffer is narrowed, this means the end of the narrowed part.")
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
517 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
518 {
16039
855c8d8ba0f0 Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents: 15910
diff changeset
519 if (PT == ZV)
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
520 return Qt;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
521 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
522 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
523
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
524 DEFUN ("bolp", Fbolp, Sbolp, 0, 0, 0,
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
525 "Return t if point is at the beginning of a line.")
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
526 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
527 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
528 if (PT == BEGV || FETCH_BYTE (PT_BYTE - 1) == '\n')
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
529 return Qt;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
530 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
531 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
532
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
533 DEFUN ("eolp", Feolp, Seolp, 0, 0, 0,
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
534 "Return t if point is at the end of a line.\n\
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
535 `End of a line' includes point being at the end of the buffer.")
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
536 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
537 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
538 if (PT == ZV || FETCH_BYTE (PT_BYTE) == '\n')
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
539 return Qt;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
540 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
541 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
542
18252
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
543 DEFUN ("char-after", Fchar_after, Schar_after, 0, 1, 0,
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
544 "Return character in current buffer at position POS.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
545 POS is an integer or a buffer pointer.\n\
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
546 If POS is out of range, the value is nil.\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
547 If `enable-multibyte-characters' is nil or POS is not at character boundary,\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
548 multi-byte form is ignored, and only one byte at POS\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
549 is returned as a character.")
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
550 (pos)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
551 Lisp_Object pos;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
552 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
553 register int pos_byte;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
554 register Lisp_Object val;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
555
18252
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
556 if (NILP (pos))
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
557 return make_number (FETCH_CHAR (PT_BYTE));
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
559 if (MARKERP (pos))
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
560 pos_byte = marker_byte_position (pos);
18252
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
561 else
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
562 {
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
563 CHECK_NUMBER_COERCE_MARKER (pos, 0);
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
564
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
565 pos_byte = CHAR_TO_BYTE (XINT (pos));
18252
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
566 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
567
20561
24acae12e085 (Fchar_after): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 20558
diff changeset
568 if (pos_byte < BEGV_BYTE || pos_byte >= ZV_BYTE)
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
569 return Qnil;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
570
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
571 return make_number (FETCH_CHAR (pos_byte));
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
572 }
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
573
18252
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
574 DEFUN ("char-before", Fchar_before, Schar_before, 0, 1, 0,
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
575 "Return character in current buffer preceding position POS.\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
576 POS is an integer or a buffer pointer.\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
577 If POS is out of range, the value is nil.\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
578 If `enable-multibyte-characters' is nil or POS is not at character boundary,\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
579 multi-byte form is ignored, and only one byte preceding POS\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
580 is returned as a character.")
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
581 (pos)
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
582 Lisp_Object pos;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
583 {
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
584 register Lisp_Object val;
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
585 register int pos_byte;
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
586
18252
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
587 if (NILP (pos))
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
588 pos_byte = PT_BYTE;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
589 else if (MARKERP (pos))
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
590 pos_byte = marker_byte_position (pos);
18252
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
591 else
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
592 {
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
593 CHECK_NUMBER_COERCE_MARKER (pos, 0);
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
594
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
595 pos_byte = CHAR_TO_BYTE (XINT (pos));
18252
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
596 }
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
597
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
598 if (pos_byte <= BEGV_BYTE || pos_byte > ZV_BYTE)
19416
719fd5370c3e (Fchar_before): Do range check before decrement.
Richard M. Stallman <rms@gnu.org>
parents: 19207
diff changeset
599 return Qnil;
719fd5370c3e (Fchar_before): Do range check before decrement.
Richard M. Stallman <rms@gnu.org>
parents: 19207
diff changeset
600
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
601 if (!NILP (current_buffer->enable_multibyte_characters))
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
602 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
603 DEC_POS (pos_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
604 XSETFASTINT (val, FETCH_CHAR (pos_byte));
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
605 }
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
606 else
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
607 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
608 pos_byte--;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
609 XSETFASTINT (val, FETCH_BYTE (pos_byte));
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
610 }
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
611 return val;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
612 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
613
9572
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
614 DEFUN ("user-login-name", Fuser_login_name, Suser_login_name, 0, 1, 0,
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
615 "Return the name under which the user logged in, as a string.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
616 This is based on the effective uid, not the real uid.\n\
5907
5fdb226fe9a4 (init_editfns): Look at LOGNAME before USER.
Karl Heuer <kwzh@gnu.org>
parents: 5884
diff changeset
617 Also, if the environment variable LOGNAME or USER is set,\n\
9572
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
618 that determines the value of this function.\n\n\
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
619 If optional argument UID is an integer, return the login name of the user\n\
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
620 with that uid, or nil if there is no such user.")
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
621 (uid)
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
622 Lisp_Object uid;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
623 {
9572
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
624 struct passwd *pw;
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
625
9520
5187a4159d16 (Fuser_login_name, Fuser_real_login_name):
Richard M. Stallman <rms@gnu.org>
parents: 9305
diff changeset
626 /* Set up the user name info if we didn't do it before.
5187a4159d16 (Fuser_login_name, Fuser_real_login_name):
Richard M. Stallman <rms@gnu.org>
parents: 9305
diff changeset
627 (That can happen if Emacs is dumpable
5187a4159d16 (Fuser_login_name, Fuser_real_login_name):
Richard M. Stallman <rms@gnu.org>
parents: 9305
diff changeset
628 but you decide to run `temacs -l loadup' and not dump. */
12026
505a894d943e (syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents: 11912
diff changeset
629 if (INTEGERP (Vuser_login_name))
9520
5187a4159d16 (Fuser_login_name, Fuser_real_login_name):
Richard M. Stallman <rms@gnu.org>
parents: 9305
diff changeset
630 init_editfns ();
9572
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
631
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
632 if (NILP (uid))
12026
505a894d943e (syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents: 11912
diff changeset
633 return Vuser_login_name;
9572
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
634
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
635 CHECK_NUMBER (uid, 0);
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
636 pw = (struct passwd *) getpwuid (XINT (uid));
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
637 return (pw ? build_string (pw->pw_name) : Qnil);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
638 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
639
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
640 DEFUN ("user-real-login-name", Fuser_real_login_name, Suser_real_login_name,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
641 0, 0, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
642 "Return the name of the user's real uid, as a string.\n\
6878
175e4da3d3f4 (Fuser_real_login_name): Doc syntax fix.
Richard M. Stallman <rms@gnu.org>
parents: 6772
diff changeset
643 This ignores the environment variables LOGNAME and USER, so it differs from\n\
5915
11c1e1696fe3 (Fuser_real_login_name): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 5907
diff changeset
644 `user-login-name' when running under `su'.")
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
645 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
646 {
9520
5187a4159d16 (Fuser_login_name, Fuser_real_login_name):
Richard M. Stallman <rms@gnu.org>
parents: 9305
diff changeset
647 /* Set up the user name info if we didn't do it before.
5187a4159d16 (Fuser_login_name, Fuser_real_login_name):
Richard M. Stallman <rms@gnu.org>
parents: 9305
diff changeset
648 (That can happen if Emacs is dumpable
5187a4159d16 (Fuser_login_name, Fuser_real_login_name):
Richard M. Stallman <rms@gnu.org>
parents: 9305
diff changeset
649 but you decide to run `temacs -l loadup' and not dump. */
12026
505a894d943e (syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents: 11912
diff changeset
650 if (INTEGERP (Vuser_login_name))
9520
5187a4159d16 (Fuser_login_name, Fuser_real_login_name):
Richard M. Stallman <rms@gnu.org>
parents: 9305
diff changeset
651 init_editfns ();
12026
505a894d943e (syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents: 11912
diff changeset
652 return Vuser_real_login_name;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
653 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
654
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
655 DEFUN ("user-uid", Fuser_uid, Suser_uid, 0, 0, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
656 "Return the effective uid of Emacs, as an integer.")
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
657 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
658 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
659 return make_number (geteuid ());
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
660 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
661
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
662 DEFUN ("user-real-uid", Fuser_real_uid, Suser_real_uid, 0, 0, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
663 "Return the real uid of Emacs, as an integer.")
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
664 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
665 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
666 return make_number (getuid ());
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
667 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
668
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
669 DEFUN ("user-full-name", Fuser_full_name, Suser_full_name, 0, 1, 0,
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
670 "Return the full name of the user logged in, as a string.\n\
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
671 If optional argument UID is an integer, return the full name of the user\n\
17115
dd39f3c57b3e Escape newlines in docstring.
Kenichi Handa <handa@m17n.org>
parents: 17031
diff changeset
672 with that uid, or \"unknown\" if there is no such user.\n\
16641
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
673 If UID is a string, return the full name of the user with that login\n\
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
674 name, or \"unknown\" if no such user could be found.")
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
675 (uid)
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
676 Lisp_Object uid;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
677 {
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
678 struct passwd *pw;
18661
537522d5e6d8 (Fuser_full_name): Declare p, q and r as unsigned char *.
Richard M. Stallman <rms@gnu.org>
parents: 18613
diff changeset
679 register unsigned char *p, *q;
16641
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
680 extern char *index ();
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
681 Lisp_Object full;
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
682
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
683 if (NILP (uid))
16641
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
684 return Vuser_full_name;
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
685 else if (NUMBERP (uid))
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
686 pw = (struct passwd *) getpwuid (XINT (uid));
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
687 else if (STRINGP (uid))
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
688 pw = (struct passwd *) getpwnam (XSTRING (uid)->data);
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
689 else
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
690 error ("Invalid UID specification");
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
691
16641
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
692 if (!pw)
16683
6802dbd07a80 (Fuser_full_name): Return nil if the specified user doesn't exist.
Richard M. Stallman <rms@gnu.org>
parents: 16648
diff changeset
693 return Qnil;
16641
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
694
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
695 p = (unsigned char *) USER_FULL_NAME;
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
696 /* Chop off everything after the first comma. */
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
697 q = (unsigned char *) index (p, ',');
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
698 full = make_string (p, q ? q - p : strlen (p));
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
699
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
700 #ifdef AMPERSAND_FULL_NAME
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
701 p = XSTRING (full)->data;
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
702 q = (unsigned char *) index (p, '&');
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
703 /* Substitute the login name for the &, upcasing the first character. */
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
704 if (q)
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
705 {
18661
537522d5e6d8 (Fuser_full_name): Declare p, q and r as unsigned char *.
Richard M. Stallman <rms@gnu.org>
parents: 18613
diff changeset
706 register unsigned char *r;
16641
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
707 Lisp_Object login;
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
708
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
709 login = Fuser_login_name (make_number (pw->pw_uid));
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
710 r = (unsigned char *) alloca (strlen (p) + XSTRING (login)->size + 1);
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
711 bcopy (p, r, q - p);
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
712 r[q - p] = 0;
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
713 strcat (r, XSTRING (login)->data);
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
714 r[q - p] = UPCASE (r[q - p]);
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
715 strcat (r, q + 1);
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
716 full = build_string (r);
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
717 }
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
718 #endif /* AMPERSAND_FULL_NAME */
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
719
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
720 return full;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
721 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
722
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
723 DEFUN ("system-name", Fsystem_name, Ssystem_name, 0, 0, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
724 "Return the name of the machine you are running on, as a string.")
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
725 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
726 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
727 return Vsystem_name;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
728 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
729
7907
148ad20d6774 (init_editfns): Call init_system_name instead of get_system_name.
Karl Heuer <kwzh@gnu.org>
parents: 7862
diff changeset
730 /* For the benefit of callers who don't want to include lisp.h */
148ad20d6774 (init_editfns): Call init_system_name instead of get_system_name.
Karl Heuer <kwzh@gnu.org>
parents: 7862
diff changeset
731 char *
148ad20d6774 (init_editfns): Call init_system_name instead of get_system_name.
Karl Heuer <kwzh@gnu.org>
parents: 7862
diff changeset
732 get_system_name ()
148ad20d6774 (init_editfns): Call init_system_name instead of get_system_name.
Karl Heuer <kwzh@gnu.org>
parents: 7862
diff changeset
733 {
18756
751f531e5a20 (get_system_name): Don't crash if Vsystem_name does not contain a string.
Richard M. Stallman <rms@gnu.org>
parents: 18745
diff changeset
734 if (STRINGP (Vsystem_name))
751f531e5a20 (get_system_name): Don't crash if Vsystem_name does not contain a string.
Richard M. Stallman <rms@gnu.org>
parents: 18745
diff changeset
735 return (char *) XSTRING (Vsystem_name)->data;
751f531e5a20 (get_system_name): Don't crash if Vsystem_name does not contain a string.
Richard M. Stallman <rms@gnu.org>
parents: 18745
diff changeset
736 else
751f531e5a20 (get_system_name): Don't crash if Vsystem_name does not contain a string.
Richard M. Stallman <rms@gnu.org>
parents: 18745
diff changeset
737 return "";
7907
148ad20d6774 (init_editfns): Call init_system_name instead of get_system_name.
Karl Heuer <kwzh@gnu.org>
parents: 7862
diff changeset
738 }
148ad20d6774 (init_editfns): Call init_system_name instead of get_system_name.
Karl Heuer <kwzh@gnu.org>
parents: 7862
diff changeset
739
5373
a70b89d2d6bb (Femacs_pid): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5242
diff changeset
740 DEFUN ("emacs-pid", Femacs_pid, Semacs_pid, 0, 0, 0,
a70b89d2d6bb (Femacs_pid): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5242
diff changeset
741 "Return the process ID of Emacs, as an integer.")
a70b89d2d6bb (Femacs_pid): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5242
diff changeset
742 ()
a70b89d2d6bb (Femacs_pid): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5242
diff changeset
743 {
a70b89d2d6bb (Femacs_pid): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5242
diff changeset
744 return make_number (getpid ());
a70b89d2d6bb (Femacs_pid): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5242
diff changeset
745 }
a70b89d2d6bb (Femacs_pid): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5242
diff changeset
746
448
129e6320092c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 372
diff changeset
747 DEFUN ("current-time", Fcurrent_time, Scurrent_time, 0, 0, 0,
13618
5fe951036f57 (Fcurrent_time): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 13450
diff changeset
748 "Return the current time, as the number of seconds since 1970-01-01 00:00:00.\n\
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
749 The time is returned as a list of three integers. The first has the\n\
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
750 most significant 16 bits of the seconds, while the second has the\n\
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
751 least significant 16 bits. The third integer gives the microsecond\n\
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
752 count.\n\
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
753 \n\
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
754 The microsecond count is zero on systems that do not provide\n\
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
755 resolution finer than a second.")
448
129e6320092c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 372
diff changeset
756 ()
129e6320092c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 372
diff changeset
757 {
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
758 EMACS_TIME t;
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
759 Lisp_Object result[3];
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
760
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
761 EMACS_GET_TIME (t);
9265
e44908d7323b (Fcurrent_time, Fformat): Use new accessor macros instead of calling XSET
Karl Heuer <kwzh@gnu.org>
parents: 9163
diff changeset
762 XSETINT (result[0], (EMACS_SECS (t) >> 16) & 0xffff);
e44908d7323b (Fcurrent_time, Fformat): Use new accessor macros instead of calling XSET
Karl Heuer <kwzh@gnu.org>
parents: 9163
diff changeset
763 XSETINT (result[1], (EMACS_SECS (t) >> 0) & 0xffff);
e44908d7323b (Fcurrent_time, Fformat): Use new accessor macros instead of calling XSET
Karl Heuer <kwzh@gnu.org>
parents: 9163
diff changeset
764 XSETINT (result[2], EMACS_USECS (t));
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
765
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
766 return Flist (3, result);
448
129e6320092c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 372
diff changeset
767 }
129e6320092c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 372
diff changeset
768
129e6320092c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 372
diff changeset
769
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
770 static int
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
771 lisp_time_argument (specified_time, result)
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
772 Lisp_Object specified_time;
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
773 time_t *result;
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
774 {
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
775 if (NILP (specified_time))
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
776 return time (result) != -1;
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
777 else
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
778 {
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
779 Lisp_Object high, low;
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
780 high = Fcar (specified_time);
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
781 CHECK_NUMBER (high, 0);
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
782 low = Fcdr (specified_time);
9163
41fe5f636879 (lisp_time_argument, Finsert, Finsert_and_inherit, Finsert_before_markers,
Karl Heuer <kwzh@gnu.org>
parents: 9154
diff changeset
783 if (CONSP (low))
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
784 low = Fcar (low);
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
785 CHECK_NUMBER (low, 0);
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
786 *result = (XINT (high) << 16) + (XINT (low) & 0xffff);
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
787 return *result >> 16 == XINT (high);
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
788 }
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
789 }
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
790
18511
92e9fb8b88f4 (Fformat_time_string): Move doc string outside DEFUN.
Richard M. Stallman <rms@gnu.org>
parents: 18315
diff changeset
791 /*
17907
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
792 DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string, 1, 3, 0,
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
793 "Use FORMAT-STRING to format the time TIME, or now if omitted.\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
794 TIME is specified as (HIGH LOW . IGNORED) or (HIGH . LOW), as returned by\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
795 `current-time' or `file-attributes'.\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
796 The third, optional, argument UNIVERSAL, if non-nil, means describe TIME\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
797 as Universal Time; nil means describe TIME in the local time zone.\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
798 The value is a copy of FORMAT-STRING, but with certain constructs replaced\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
799 by text that describes the specified date and time in TIME:\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
800 \n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
801 %Y is the year, %y within the century, %C the century.\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
802 %G is the year corresponding to the ISO week, %g within the century.\n\
20338
d55ca55974a0 (emacs_strftime): New decl.
Paul Eggert <eggert@twinsun.com>
parents: 20311
diff changeset
803 %m is the numeric month.\n\
d55ca55974a0 (emacs_strftime): New decl.
Paul Eggert <eggert@twinsun.com>
parents: 20311
diff changeset
804 %b and %h are the locale's abbreviated month name, %B the full name.\n\
17907
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
805 %d is the day of the month, zero-padded, %e is blank-padded.\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
806 %u is the numeric day of week from 1 (Monday) to 7, %w from 0 (Sunday) to 6.\n\
20338
d55ca55974a0 (emacs_strftime): New decl.
Paul Eggert <eggert@twinsun.com>
parents: 20311
diff changeset
807 %a is the locale's abbreviated name of the day of week, %A the full name.\n\
17907
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
808 %U is the week number starting on Sunday, %W starting on Monday,\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
809 %V according to ISO 8601.\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
810 %j is the day of the year.\n\
9154
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
811 \n\
17907
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
812 %H is the hour on a 24-hour clock, %I is on a 12-hour clock, %k is like %H\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
813 only blank-padded, %l is like %I blank-padded.\n\
20338
d55ca55974a0 (emacs_strftime): New decl.
Paul Eggert <eggert@twinsun.com>
parents: 20311
diff changeset
814 %p is the locale's equivalent of either AM or PM.\n\
17907
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
815 %M is the minute.\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
816 %S is the second.\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
817 %Z is the time zone name, %z is the numeric form.\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
818 %s is the number of seconds since 1970-01-01 00:00:00 +0000.\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
819 \n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
820 %c is the locale's date and time format.\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
821 %x is the locale's \"preferred\" date format.\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
822 %D is like \"%m/%d/%y\".\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
823 \n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
824 %R is like \"%H:%M\", %T is like \"%H:%M:%S\", %r is like \"%I:%M:%S %p\".\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
825 %X is the locale's \"preferred\" time format.\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
826 \n\
20338
d55ca55974a0 (emacs_strftime): New decl.
Paul Eggert <eggert@twinsun.com>
parents: 20311
diff changeset
827 Finally, %n is a newline, %t is a tab, %% is a literal %.\n\
17907
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
828 \n\
18511
92e9fb8b88f4 (Fformat_time_string): Move doc string outside DEFUN.
Richard M. Stallman <rms@gnu.org>
parents: 18315
diff changeset
829 Certain flags and modifiers are available with some format controls.\n\
17907
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
830 The flags are `_' and `-'. For certain characters X, %_X is like %X,\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
831 but padded with blanks; %-X is like %X, but without padding.\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
832 %NX (where N stands for an integer) is like %X,\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
833 but takes up at least N (a number) positions.\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
834 The modifiers are `E' and `O'. For certain characters X,\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
835 %EX is a locale's alternative version of %X;\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
836 %OX is like %X, but uses the locale's number symbols.\n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
837 \n\
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
838 For example, to produce full ISO 8601 format, use \"%Y-%m-%dT%T%z\".")
20023
b89c59bccc68 Repeat the argument list of format-time-string in the
Karl Heuer <kwzh@gnu.org>
parents: 19441
diff changeset
839 (format_string, time, universal)
18511
92e9fb8b88f4 (Fformat_time_string): Move doc string outside DEFUN.
Richard M. Stallman <rms@gnu.org>
parents: 18315
diff changeset
840 */
92e9fb8b88f4 (Fformat_time_string): Move doc string outside DEFUN.
Richard M. Stallman <rms@gnu.org>
parents: 18315
diff changeset
841
92e9fb8b88f4 (Fformat_time_string): Move doc string outside DEFUN.
Richard M. Stallman <rms@gnu.org>
parents: 18315
diff changeset
842 DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string, 1, 3, 0,
92e9fb8b88f4 (Fformat_time_string): Move doc string outside DEFUN.
Richard M. Stallman <rms@gnu.org>
parents: 18315
diff changeset
843 0 /* See immediately above */)
17907
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
844 (format_string, time, universal)
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
845 Lisp_Object format_string, time, universal;
9154
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
846 {
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
847 time_t value;
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
848 int size;
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
849
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
850 CHECK_STRING (format_string, 1);
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
851
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
852 if (! lisp_time_argument (time, &value))
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
853 error ("Invalid time specification");
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
854
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
855 /* This is probably enough. */
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
856 size = XSTRING (format_string)->size_byte * 6 + 50;
9154
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
857
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
858 while (1)
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
859 {
17907
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
860 char *buf = (char *) alloca (size + 1);
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
861 int result;
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
862
19032
84ae0a03a643 (Fformat_time_string): Don't hang if strftime produces
Richard M. Stallman <rms@gnu.org>
parents: 18937
diff changeset
863 buf[0] = '\1';
17907
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
864 result = emacs_strftime (buf, size, XSTRING (format_string)->data,
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
865 (NILP (universal) ? localtime (&value)
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
866 : gmtime (&value)));
19032
84ae0a03a643 (Fformat_time_string): Don't hang if strftime produces
Richard M. Stallman <rms@gnu.org>
parents: 18937
diff changeset
867 if ((result > 0 && result < size) || (result == 0 && buf[0] == '\0'))
9154
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
868 return build_string (buf);
17907
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
869
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
870 /* If buffer was too small, make it bigger and try again. */
19032
84ae0a03a643 (Fformat_time_string): Don't hang if strftime produces
Richard M. Stallman <rms@gnu.org>
parents: 18937
diff changeset
871 result = emacs_strftime (NULL, 0x7fffffff, XSTRING (format_string)->data,
17907
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
872 (NILP (universal) ? localtime (&value)
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
873 : gmtime (&value)));
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
874 size = result + 1;
9154
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
875 }
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
876 }
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
877
9801
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
878 DEFUN ("decode-time", Fdecode_time, Sdecode_time, 0, 1, 0,
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
879 "Decode a time value as (SEC MINUTE HOUR DAY MONTH YEAR DOW DST ZONE).\n\
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
880 The optional SPECIFIED-TIME should be a list of (HIGH LOW . IGNORED)\n\
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
881 or (HIGH . LOW), as from `current-time' and `file-attributes', or `nil'\n\
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
882 to use the current time. The list has the following nine members:\n\
13013
2511f0ccd986 (Fdecode_time): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 12982
diff changeset
883 SEC is an integer between 0 and 60; SEC is 60 for a leap second, which\n\
2511f0ccd986 (Fdecode_time): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 12982
diff changeset
884 only some operating systems support. MINUTE is an integer between 0 and 59.\n\
9801
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
885 HOUR is an integer between 0 and 23. DAY is an integer between 1 and 31.\n\
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
886 MONTH is an integer between 1 and 12. YEAR is an integer indicating the\n\
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
887 four-digit year. DOW is the day of week, an integer between 0 and 6, where\n\
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
888 0 is Sunday. DST is t if daylight savings time is effect, otherwise nil.\n\
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
889 ZONE is an integer indicating the number of seconds east of Greenwich.\n\
12973
2c0225a5aa91 (Fdecode_time): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 12958
diff changeset
890 \(Note that Common Lisp has different meanings for DOW and ZONE.)")
9801
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
891 (specified_time)
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
892 Lisp_Object specified_time;
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
893 {
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
894 time_t time_spec;
9812
bc352c8f079c (Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents: 9809
diff changeset
895 struct tm save_tm;
9801
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
896 struct tm *decoded_time;
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
897 Lisp_Object list_args[9];
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
898
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
899 if (! lisp_time_argument (specified_time, &time_spec))
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
900 error ("Invalid time specification");
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
901
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
902 decoded_time = localtime (&time_spec);
9812
bc352c8f079c (Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents: 9809
diff changeset
903 XSETFASTINT (list_args[0], decoded_time->tm_sec);
bc352c8f079c (Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents: 9809
diff changeset
904 XSETFASTINT (list_args[1], decoded_time->tm_min);
bc352c8f079c (Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents: 9809
diff changeset
905 XSETFASTINT (list_args[2], decoded_time->tm_hour);
bc352c8f079c (Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents: 9809
diff changeset
906 XSETFASTINT (list_args[3], decoded_time->tm_mday);
bc352c8f079c (Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents: 9809
diff changeset
907 XSETFASTINT (list_args[4], decoded_time->tm_mon + 1);
15757
5ddb082ffebb (Fdecode_time, difftm): Work even if tm_year represents
Richard M. Stallman <rms@gnu.org>
parents: 15334
diff changeset
908 XSETINT (list_args[5], decoded_time->tm_year + 1900);
9812
bc352c8f079c (Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents: 9809
diff changeset
909 XSETFASTINT (list_args[6], decoded_time->tm_wday);
9801
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
910 list_args[7] = (decoded_time->tm_isdst)? Qt : Qnil;
9812
bc352c8f079c (Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents: 9809
diff changeset
911
bc352c8f079c (Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents: 9809
diff changeset
912 /* Make a copy, in case gmtime modifies the struct. */
bc352c8f079c (Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents: 9809
diff changeset
913 save_tm = *decoded_time;
bc352c8f079c (Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents: 9809
diff changeset
914 decoded_time = gmtime (&time_spec);
bc352c8f079c (Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents: 9809
diff changeset
915 if (decoded_time == 0)
bc352c8f079c (Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents: 9809
diff changeset
916 list_args[8] = Qnil;
bc352c8f079c (Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents: 9809
diff changeset
917 else
16269
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
918 XSETINT (list_args[8], tm_diff (&save_tm, decoded_time));
9801
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
919 return Flist (9, list_args);
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
920 }
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
921
15180
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
922 DEFUN ("encode-time", Fencode_time, Sencode_time, 6, MANY, 0,
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
923 "Convert SECOND, MINUTE, HOUR, DAY, MONTH, YEAR and ZONE to internal time.\n\
15180
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
924 This is the reverse operation of `decode-time', which see.\n\
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
925 ZONE defaults to the current time zone rule. This can\n\
15910
8cd4f2fd5525 (Fencode_time, Fset_time_zone_rule): Use UTC if the zone is t.
Erik Naggum <erik@naggum.no>
parents: 15841
diff changeset
926 be a string or t (as from `set-time-zone-rule'), or it can be a list\n\
16526
f34bfb5aa684 (Fencode_time): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16521
diff changeset
927 \(as from `current-time-zone') or an integer (as from `decode-time')\n\
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
928 applied without consideration for daylight savings time.\n\
15180
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
929 \n\
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
930 You can pass more than 7 arguments; then the first six arguments\n\
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
931 are used as SECOND through YEAR, and the *last* argument is used as ZONE.\n\
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
932 The intervening arguments are ignored.\n\
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
933 This feature lets (apply 'encode-time (decode-time ...)) work.\n\
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
934 \n\
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
935 Out-of-range values for SEC, MINUTE, HOUR, DAY, or MONTH are allowed;\n\
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
936 for example, a DAY of 0 means the day preceding the given month.\n\
11476
7917226c3ea9 (Fencode_time): Don't treat years < 100 as special.
Richard M. Stallman <rms@gnu.org>
parents: 11468
diff changeset
937 Year numbers less than 100 are treated just like other year numbers.\n\
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
938 If you want them to stand for years in this century, you must do that yourself.")
15180
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
939 (nargs, args)
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
940 int nargs;
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
941 register Lisp_Object *args;
11402
66d935214d8e (Fencode_time): Use XINT to examine `zone'.
Richard M. Stallman <rms@gnu.org>
parents: 11263
diff changeset
942 {
11468
772f49d1969d (Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents: 11451
diff changeset
943 time_t time;
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
944 struct tm tm;
16874
0b914fcd97a1 Clean up parentheses.
Richard M. Stallman <rms@gnu.org>
parents: 16683
diff changeset
945 Lisp_Object zone = (nargs > 6 ? args[nargs - 1] : Qnil);
11402
66d935214d8e (Fencode_time): Use XINT to examine `zone'.
Richard M. Stallman <rms@gnu.org>
parents: 11263
diff changeset
946
15180
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
947 CHECK_NUMBER (args[0], 0); /* second */
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
948 CHECK_NUMBER (args[1], 1); /* minute */
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
949 CHECK_NUMBER (args[2], 2); /* hour */
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
950 CHECK_NUMBER (args[3], 3); /* day */
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
951 CHECK_NUMBER (args[4], 4); /* month */
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
952 CHECK_NUMBER (args[5], 5); /* year */
11468
772f49d1969d (Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents: 11451
diff changeset
953
15180
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
954 tm.tm_sec = XINT (args[0]);
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
955 tm.tm_min = XINT (args[1]);
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
956 tm.tm_hour = XINT (args[2]);
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
957 tm.tm_mday = XINT (args[3]);
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
958 tm.tm_mon = XINT (args[4]) - 1;
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
959 tm.tm_year = XINT (args[5]) - 1900;
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
960 tm.tm_isdst = -1;
11468
772f49d1969d (Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents: 11451
diff changeset
961
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
962 if (CONSP (zone))
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
963 zone = Fcar (zone);
11468
772f49d1969d (Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents: 11451
diff changeset
964 if (NILP (zone))
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
965 time = mktime (&tm);
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
966 else
11468
772f49d1969d (Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents: 11451
diff changeset
967 {
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
968 char tzbuf[100];
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
969 char *tzstring;
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
970 char **oldenv = environ, **newenv;
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
971
18613
614b916ff5bf Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents: 18605
diff changeset
972 if (EQ (zone, Qt))
15910
8cd4f2fd5525 (Fencode_time, Fset_time_zone_rule): Use UTC if the zone is t.
Erik Naggum <erik@naggum.no>
parents: 15841
diff changeset
973 tzstring = "UTC0";
8cd4f2fd5525 (Fencode_time, Fset_time_zone_rule): Use UTC if the zone is t.
Erik Naggum <erik@naggum.no>
parents: 15841
diff changeset
974 else if (STRINGP (zone))
13347
186d80572f4f (Fencode_time): Add cast.
Richard M. Stallman <rms@gnu.org>
parents: 13238
diff changeset
975 tzstring = (char *) XSTRING (zone)->data;
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
976 else if (INTEGERP (zone))
11468
772f49d1969d (Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents: 11451
diff changeset
977 {
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
978 int abszone = abs (XINT (zone));
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
979 sprintf (tzbuf, "XXX%s%d:%02d:%02d", "-" + (XINT (zone) < 0),
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
980 abszone / (60*60), (abszone/60) % 60, abszone % 60);
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
981 tzstring = tzbuf;
11468
772f49d1969d (Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents: 11451
diff changeset
982 }
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
983 else
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
984 error ("Invalid time zone specification");
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
985
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
986 /* Set TZ before calling mktime; merely adjusting mktime's returned
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
987 value doesn't suffice, since that would mishandle leap seconds. */
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
988 set_time_zone_rule (tzstring);
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
989
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
990 time = mktime (&tm);
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
991
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
992 /* Restore TZ to previous value. */
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
993 newenv = environ;
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
994 environ = oldenv;
16521
fe9cc0d392dd (Fencode_time): Use xfree, not free.
Richard M. Stallman <rms@gnu.org>
parents: 16485
diff changeset
995 xfree (newenv);
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
996 #ifdef LOCALTIME_CACHE
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
997 tzset ();
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
998 #endif
11468
772f49d1969d (Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents: 11451
diff changeset
999 }
11402
66d935214d8e (Fencode_time): Use XINT to examine `zone'.
Richard M. Stallman <rms@gnu.org>
parents: 11263
diff changeset
1000
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1001 if (time == (time_t) -1)
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1002 error ("Specified time is not representable");
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1003
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1004 return make_time (time);
11402
66d935214d8e (Fencode_time): Use XINT to examine `zone'.
Richard M. Stallman <rms@gnu.org>
parents: 11263
diff changeset
1005 }
66d935214d8e (Fencode_time): Use XINT to examine `zone'.
Richard M. Stallman <rms@gnu.org>
parents: 11263
diff changeset
1006
2154
69c58e548ca5 (Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents: 2049
diff changeset
1007 DEFUN ("current-time-string", Fcurrent_time_string, Scurrent_time_string, 0, 1, 0,
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1008 "Return the current time, as a human-readable string.\n\
2154
69c58e548ca5 (Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents: 2049
diff changeset
1009 Programs can use this function to decode a time,\n\
69c58e548ca5 (Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents: 2049
diff changeset
1010 since the number of columns in each field is fixed.\n\
69c58e548ca5 (Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents: 2049
diff changeset
1011 The format is `Sun Sep 16 01:03:52 1973'.\n\
18031
9567ae426b73 (Fcurrent_time_string): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 18007
diff changeset
1012 However, see also the functions `decode-time' and `format-time-string'\n\
9567ae426b73 (Fcurrent_time_string): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 18007
diff changeset
1013 which provide a much more powerful and general facility.\n\
9567ae426b73 (Fcurrent_time_string): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 18007
diff changeset
1014 \n\
2154
69c58e548ca5 (Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents: 2049
diff changeset
1015 If an argument is given, it specifies a time to format\n\
69c58e548ca5 (Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents: 2049
diff changeset
1016 instead of the current time. The argument should have the form:\n\
69c58e548ca5 (Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents: 2049
diff changeset
1017 (HIGH . LOW)\n\
69c58e548ca5 (Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents: 2049
diff changeset
1018 or the form:\n\
69c58e548ca5 (Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents: 2049
diff changeset
1019 (HIGH LOW . IGNORED).\n\
69c58e548ca5 (Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents: 2049
diff changeset
1020 Thus, you can use times obtained from `current-time'\n\
69c58e548ca5 (Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents: 2049
diff changeset
1021 and from `file-attributes'.")
69c58e548ca5 (Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents: 2049
diff changeset
1022 (specified_time)
69c58e548ca5 (Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents: 2049
diff changeset
1023 Lisp_Object specified_time;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1024 {
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1025 time_t value;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1026 char buf[30];
2154
69c58e548ca5 (Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents: 2049
diff changeset
1027 register char *tem;
69c58e548ca5 (Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents: 2049
diff changeset
1028
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1029 if (! lisp_time_argument (specified_time, &value))
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1030 value = -1;
2154
69c58e548ca5 (Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents: 2049
diff changeset
1031 tem = (char *) ctime (&value);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1032
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1033 strncpy (buf, tem, 24);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1034 buf[24] = 0;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1035
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1036 return build_string (buf);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1037 }
962
3533821d6edc * editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents: 690
diff changeset
1038
16269
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1039 #define TM_YEAR_BASE 1900
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1040
16269
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1041 /* Yield A - B, measured in seconds.
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1042 This function is copied from the GNU C Library. */
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1043 static int
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1044 tm_diff (a, b)
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1045 struct tm *a, *b;
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1046 {
16269
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1047 /* Compute intervening leap days correctly even if year is negative.
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1048 Take care to avoid int overflow in leap day calculations,
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1049 but it's OK to assume that A and B are close to each other. */
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1050 int a4 = (a->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (a->tm_year & 3);
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1051 int b4 = (b->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (b->tm_year & 3);
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1052 int a100 = a4 / 25 - (a4 % 25 < 0);
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1053 int b100 = b4 / 25 - (b4 % 25 < 0);
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1054 int a400 = a100 >> 2;
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1055 int b400 = b100 >> 2;
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1056 int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1057 int years = a->tm_year - b->tm_year;
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1058 int days = (365 * years + intervening_leap_days
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1059 + (a->tm_yday - b->tm_yday));
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1060 return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1061 + (a->tm_min - b->tm_min))
5882
319a7fcb7609 (difftm): Simplify expression.
Karl Heuer <kwzh@gnu.org>
parents: 5373
diff changeset
1062 + (a->tm_sec - b->tm_sec));
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1063 }
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1064
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1065 DEFUN ("current-time-zone", Fcurrent_time_zone, Scurrent_time_zone, 0, 1, 0,
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1066 "Return the offset and name for the local time zone.\n\
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1067 This returns a list of the form (OFFSET NAME).\n\
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1068 OFFSET is an integer number of seconds ahead of UTC (east of Greenwich).\n\
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1069 A negative value means west of Greenwich.\n\
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1070 NAME is a string giving the name of the time zone.\n\
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1071 If an argument is given, it specifies when the time zone offset is determined\n\
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1072 instead of using the current time. The argument should have the form:\n\
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1073 (HIGH . LOW)\n\
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1074 or the form:\n\
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1075 (HIGH LOW . IGNORED).\n\
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1076 Thus, you can use times obtained from `current-time'\n\
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1077 and from `file-attributes'.\n\
2462
4a7e1c2a2a9e * editfns.c (Fcurrent_time_zone): Return a list whose elements are
Jim Blandy <jimb@redhat.com>
parents: 2384
diff changeset
1078 \n\
4a7e1c2a2a9e * editfns.c (Fcurrent_time_zone): Return a list whose elements are
Jim Blandy <jimb@redhat.com>
parents: 2384
diff changeset
1079 Some operating systems cannot provide all this information to Emacs;\n\
2976
6fe71a039fce (Fcurrent_time_zone): Assign gmt, instead of init.
Richard M. Stallman <rms@gnu.org>
parents: 2962
diff changeset
1080 in this case, `current-time-zone' returns a list containing nil for\n\
2462
4a7e1c2a2a9e * editfns.c (Fcurrent_time_zone): Return a list whose elements are
Jim Blandy <jimb@redhat.com>
parents: 2384
diff changeset
1081 the data it can't find.")
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1082 (specified_time)
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1083 Lisp_Object specified_time;
962
3533821d6edc * editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents: 690
diff changeset
1084 {
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1085 time_t value;
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1086 struct tm *t;
962
3533821d6edc * editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents: 690
diff changeset
1087
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1088 if (lisp_time_argument (specified_time, &value)
2976
6fe71a039fce (Fcurrent_time_zone): Assign gmt, instead of init.
Richard M. Stallman <rms@gnu.org>
parents: 2962
diff changeset
1089 && (t = gmtime (&value)) != 0)
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1090 {
2976
6fe71a039fce (Fcurrent_time_zone): Assign gmt, instead of init.
Richard M. Stallman <rms@gnu.org>
parents: 2962
diff changeset
1091 struct tm gmt;
16269
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1092 int offset;
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1093 char *s, buf[6];
2976
6fe71a039fce (Fcurrent_time_zone): Assign gmt, instead of init.
Richard M. Stallman <rms@gnu.org>
parents: 2962
diff changeset
1094
6fe71a039fce (Fcurrent_time_zone): Assign gmt, instead of init.
Richard M. Stallman <rms@gnu.org>
parents: 2962
diff changeset
1095 gmt = *t; /* Make a copy, in case localtime modifies *t. */
6fe71a039fce (Fcurrent_time_zone): Assign gmt, instead of init.
Richard M. Stallman <rms@gnu.org>
parents: 2962
diff changeset
1096 t = localtime (&value);
16269
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1097 offset = tm_diff (t, &gmt);
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1098 s = 0;
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1099 #ifdef HAVE_TM_ZONE
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1100 if (t->tm_zone)
7506
9fa47d36798a (Fcurrent_time_zone): Add cast.
Richard M. Stallman <rms@gnu.org>
parents: 7485
diff changeset
1101 s = (char *)t->tm_zone;
3522
dc9f7a107e28 (Fcurrent_time_zone): Add alternative for !HAVE_TM_ZONE.
Richard M. Stallman <rms@gnu.org>
parents: 2994
diff changeset
1102 #else /* not HAVE_TM_ZONE */
dc9f7a107e28 (Fcurrent_time_zone): Add alternative for !HAVE_TM_ZONE.
Richard M. Stallman <rms@gnu.org>
parents: 2994
diff changeset
1103 #ifdef HAVE_TZNAME
dc9f7a107e28 (Fcurrent_time_zone): Add alternative for !HAVE_TM_ZONE.
Richard M. Stallman <rms@gnu.org>
parents: 2994
diff changeset
1104 if (t->tm_isdst == 0 || t->tm_isdst == 1)
dc9f7a107e28 (Fcurrent_time_zone): Add alternative for !HAVE_TM_ZONE.
Richard M. Stallman <rms@gnu.org>
parents: 2994
diff changeset
1105 s = tzname[t->tm_isdst];
962
3533821d6edc * editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents: 690
diff changeset
1106 #endif
3522
dc9f7a107e28 (Fcurrent_time_zone): Add alternative for !HAVE_TM_ZONE.
Richard M. Stallman <rms@gnu.org>
parents: 2994
diff changeset
1107 #endif /* not HAVE_TM_ZONE */
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1108 if (!s)
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1109 {
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1110 /* No local time zone name is available; use "+-NNNN" instead. */
2994
b087b4fd6066 (Fcurrent_time_zone): Make `am' an int, not long.
Richard M. Stallman <rms@gnu.org>
parents: 2976
diff changeset
1111 int am = (offset < 0 ? -offset : offset) / 60;
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1112 sprintf (buf, "%c%02d%02d", (offset < 0 ? '-' : '+'), am/60, am%60);
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1113 s = buf;
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1114 }
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1115 return Fcons (make_number (offset), Fcons (build_string (s), Qnil));
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1116 }
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1117 else
18745
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
1118 return Fmake_list (make_number (2), Qnil);
962
3533821d6edc * editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents: 690
diff changeset
1119 }
3533821d6edc * editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents: 690
diff changeset
1120
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1121 /* This holds the value of `environ' produced by the previous
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1122 call to Fset_time_zone_rule, or 0 if Fset_time_zone_rule
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1123 has never been called. */
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1124 static char **environbuf;
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1125
13019
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1126 DEFUN ("set-time-zone-rule", Fset_time_zone_rule, Sset_time_zone_rule, 1, 1, 0,
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1127 "Set the local time zone using TZ, a string specifying a time zone rule.\n\
15910
8cd4f2fd5525 (Fencode_time, Fset_time_zone_rule): Use UTC if the zone is t.
Erik Naggum <erik@naggum.no>
parents: 15841
diff changeset
1128 If TZ is nil, use implementation-defined default time zone information.\n\
8cd4f2fd5525 (Fencode_time, Fset_time_zone_rule): Use UTC if the zone is t.
Erik Naggum <erik@naggum.no>
parents: 15841
diff changeset
1129 If TZ is t, use Universal Time.")
13019
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1130 (tz)
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1131 Lisp_Object tz;
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1132 {
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1133 char *tzstring;
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1134
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1135 if (NILP (tz))
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1136 tzstring = 0;
18613
614b916ff5bf Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents: 18605
diff changeset
1137 else if (EQ (tz, Qt))
15910
8cd4f2fd5525 (Fencode_time, Fset_time_zone_rule): Use UTC if the zone is t.
Erik Naggum <erik@naggum.no>
parents: 15841
diff changeset
1138 tzstring = "UTC0";
13019
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1139 else
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1140 {
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1141 CHECK_STRING (tz, 0);
13347
186d80572f4f (Fencode_time): Add cast.
Richard M. Stallman <rms@gnu.org>
parents: 13238
diff changeset
1142 tzstring = (char *) XSTRING (tz)->data;
13019
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1143 }
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1144
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1145 set_time_zone_rule (tzstring);
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1146 if (environbuf)
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1147 free (environbuf);
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1148 environbuf = environ;
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1149
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1150 return Qnil;
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1151 }
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1152
16918
ab49512bcdff (set_time_zone_rule_tz1, set_time_zone_rule_tz2):
Paul Eggert <eggert@twinsun.com>
parents: 16874
diff changeset
1153 #ifdef LOCALTIME_CACHE
ab49512bcdff (set_time_zone_rule_tz1, set_time_zone_rule_tz2):
Paul Eggert <eggert@twinsun.com>
parents: 16874
diff changeset
1154
ab49512bcdff (set_time_zone_rule_tz1, set_time_zone_rule_tz2):
Paul Eggert <eggert@twinsun.com>
parents: 16874
diff changeset
1155 /* These two values are known to load tz files in buggy implementations,
ab49512bcdff (set_time_zone_rule_tz1, set_time_zone_rule_tz2):
Paul Eggert <eggert@twinsun.com>
parents: 16874
diff changeset
1156 i.e. Solaris 1 executables running under either Solaris 1 or Solaris 2.
15841
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1157 Their values shouldn't matter in non-buggy implementations.
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1158 We don't use string literals for these strings,
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1159 since if a string in the environment is in readonly
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1160 storage, it runs afoul of bugs in SVR4 and Solaris 2.3.
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1161 See Sun bugs 1113095 and 1114114, ``Timezone routines
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1162 improperly modify environment''. */
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1163
16918
ab49512bcdff (set_time_zone_rule_tz1, set_time_zone_rule_tz2):
Paul Eggert <eggert@twinsun.com>
parents: 16874
diff changeset
1164 static char set_time_zone_rule_tz1[] = "TZ=GMT+0";
ab49512bcdff (set_time_zone_rule_tz1, set_time_zone_rule_tz2):
Paul Eggert <eggert@twinsun.com>
parents: 16874
diff changeset
1165 static char set_time_zone_rule_tz2[] = "TZ=GMT+1";
ab49512bcdff (set_time_zone_rule_tz1, set_time_zone_rule_tz2):
Paul Eggert <eggert@twinsun.com>
parents: 16874
diff changeset
1166
ab49512bcdff (set_time_zone_rule_tz1, set_time_zone_rule_tz2):
Paul Eggert <eggert@twinsun.com>
parents: 16874
diff changeset
1167 #endif
15841
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1168
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1169 /* Set the local time zone rule to TZSTRING.
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1170 This allocates memory into `environ', which it is the caller's
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1171 responsibility to free. */
14201
ff372902386d (set_time_zone_rule): No longer static.
Richard M. Stallman <rms@gnu.org>
parents: 14126
diff changeset
1172 void
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1173 set_time_zone_rule (tzstring)
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1174 char *tzstring;
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1175 {
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1176 int envptrs;
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1177 char **from, **to, **newenv;
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1178
15334
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1179 /* Make the ENVIRON vector longer with room for TZSTRING. */
13019
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1180 for (from = environ; *from; from++)
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1181 continue;
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1182 envptrs = from - environ + 2;
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1183 newenv = to = (char **) xmalloc (envptrs * sizeof (char *)
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1184 + (tzstring ? strlen (tzstring) + 4 : 0));
15334
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1185
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1186 /* Add TZSTRING to the end of environ, as a value for TZ. */
13019
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1187 if (tzstring)
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1188 {
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1189 char *t = (char *) (to + envptrs);
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1190 strcpy (t, "TZ=");
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1191 strcat (t, tzstring);
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1192 *to++ = t;
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1193 }
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1194
15334
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1195 /* Copy the old environ vector elements into NEWENV,
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1196 but don't copy the TZ variable.
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1197 So we have only one definition of TZ, which came from TZSTRING. */
13019
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1198 for (from = environ; *from; from++)
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1199 if (strncmp (*from, "TZ=", 3) != 0)
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1200 *to++ = *from;
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1201 *to = 0;
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1202
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1203 environ = newenv;
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1204
15334
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1205 /* If we do have a TZSTRING, NEWENV points to the vector slot where
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1206 the TZ variable is stored. If we do not have a TZSTRING,
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1207 TO points to the vector slot which has the terminating null. */
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1208
13019
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1209 #ifdef LOCALTIME_CACHE
15334
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1210 {
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1211 /* In SunOS 4.1.3_U1 and 4.1.4, if TZ has a value like
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1212 "US/Pacific" that loads a tz file, then changes to a value like
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1213 "XXX0" that does not load a tz file, and then changes back to
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1214 its original value, the last change is (incorrectly) ignored.
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1215 Also, if TZ changes twice in succession to values that do
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1216 not load a tz file, tzset can dump core (see Sun bug#1225179).
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1217 The following code works around these bugs. */
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1218
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1219 if (tzstring)
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1220 {
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1221 /* Temporarily set TZ to a value that loads a tz file
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1222 and that differs from tzstring. */
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1223 char *tz = *newenv;
15841
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1224 *newenv = (strcmp (tzstring, set_time_zone_rule_tz1 + 3) == 0
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1225 ? set_time_zone_rule_tz2 : set_time_zone_rule_tz1);
15334
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1226 tzset ();
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1227 *newenv = tz;
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1228 }
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1229 else
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1230 {
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1231 /* The implied tzstring is unknown, so temporarily set TZ to
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1232 two different values that each load a tz file. */
15841
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1233 *to = set_time_zone_rule_tz1;
15334
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1234 to[1] = 0;
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1235 tzset ();
15841
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1236 *to = set_time_zone_rule_tz2;
15334
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1237 tzset ();
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1238 *to = 0;
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1239 }
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1240
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1241 /* Now TZ has the desired value, and tzset can be invoked safely. */
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1242 }
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1243
13019
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1244 tzset ();
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1245 #endif
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1246 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1247
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1248 /* Insert NARGS Lisp objects in the array ARGS by calling INSERT_FUNC
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1249 (if a type of object is Lisp_Int) or INSERT_FROM_STRING_FUNC (if a
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1250 type of object is Lisp_String). INHERIT is passed to
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1251 INSERT_FROM_STRING_FUNC as the last argument. */
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1252
20311
2841215c1cb4 (Fchar_to_string): Declare `workbuf' as unsigned char.
Andreas Schwab <schwab@suse.de>
parents: 20229
diff changeset
1253 void
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1254 general_insert_function (insert_func, insert_from_string_func,
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1255 inherit, nargs, args)
20311
2841215c1cb4 (Fchar_to_string): Declare `workbuf' as unsigned char.
Andreas Schwab <schwab@suse.de>
parents: 20229
diff changeset
1256 void (*insert_func) P_ ((unsigned char *, int));
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1257 void (*insert_from_string_func) P_ ((Lisp_Object, int, int, int, int, int));
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1258 int inherit, nargs;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1259 register Lisp_Object *args;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1260 {
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1261 register int argnum;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1262 register Lisp_Object val;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1263
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1264 for (argnum = 0; argnum < nargs; argnum++)
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1265 {
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1266 val = args[argnum];
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1267 retry:
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1268 if (INTEGERP (val))
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1269 {
20311
2841215c1cb4 (Fchar_to_string): Declare `workbuf' as unsigned char.
Andreas Schwab <schwab@suse.de>
parents: 20229
diff changeset
1270 unsigned char workbuf[4], *str;
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1271 int len;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1272
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1273 if (!NILP (current_buffer->enable_multibyte_characters))
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1274 len = CHAR_STRING (XFASTINT (val), workbuf, str);
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1275 else
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1276 workbuf[0] = XINT (val), str = workbuf, len = 1;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1277 (*insert_func) (str, len);
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1278 }
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1279 else if (STRINGP (val))
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1280 {
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1281 (*insert_from_string_func) (val, 0, 0,
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1282 XSTRING (val)->size,
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1283 XSTRING (val)->size_byte,
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1284 inherit);
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1285 }
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1286 else
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1287 {
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1288 val = wrong_type_argument (Qchar_or_string_p, val);
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1289 goto retry;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1290 }
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1291 }
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1292 }
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1293
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1294 void
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1295 insert1 (arg)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1296 Lisp_Object arg;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1297 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1298 Finsert (1, &arg);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1299 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1300
330
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
1301
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
1302 /* Callers passing one argument to Finsert need not gcpro the
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
1303 argument "array", since the only element of the array will
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
1304 not be used after calling insert or insert_from_string, so
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
1305 we don't care if it gets trashed. */
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
1306
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1307 DEFUN ("insert", Finsert, Sinsert, 0, MANY, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1308 "Insert the arguments, either strings or characters, at point.\n\
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1309 Point and before-insertion-markers move forward so that it ends up\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1310 after the inserted text.\n\
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1311 Any other markers at the point of insertion remain before the text.")
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1312 (nargs, args)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1313 int nargs;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1314 register Lisp_Object *args;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1315 {
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1316 general_insert_function (insert, insert_from_string, 0, nargs, args);
4714
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
1317 return Qnil;
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
1318 }
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
1319
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
1320 DEFUN ("insert-and-inherit", Finsert_and_inherit, Sinsert_and_inherit,
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
1321 0, MANY, 0,
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
1322 "Insert the arguments at point, inheriting properties from adjoining text.\n\
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1323 Point and before-insertion-markers move forward so that it ends up\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1324 after the inserted text.\n\
4714
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
1325 Any other markers at the point of insertion remain before the text.")
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
1326 (nargs, args)
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
1327 int nargs;
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
1328 register Lisp_Object *args;
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
1329 {
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1330 general_insert_function (insert_and_inherit, insert_from_string, 1,
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1331 nargs, args);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1332 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1333 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1334
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1335 DEFUN ("insert-before-markers", Finsert_before_markers, Sinsert_before_markers, 0, MANY, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1336 "Insert strings or characters at point, relocating markers after the text.\n\
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1337 Point and before-insertion-markers move forward so that it ends up\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1338 after the inserted text.\n\
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1339 Any other markers at the point of insertion also end up after the text.")
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1340 (nargs, args)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1341 int nargs;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1342 register Lisp_Object *args;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1343 {
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1344 general_insert_function (insert_before_markers,
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1345 insert_from_string_before_markers, 0,
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1346 nargs, args);
4714
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
1347 return Qnil;
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
1348 }
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
1349
16485
9b919c5464a4 Reorganize function definitions so etags finds them.
Erik Naggum <erik@naggum.no>
parents: 16298
diff changeset
1350 DEFUN ("insert-before-markers-and-inherit", Finsert_and_inherit_before_markers,
9b919c5464a4 Reorganize function definitions so etags finds them.
Erik Naggum <erik@naggum.no>
parents: 16298
diff changeset
1351 Sinsert_and_inherit_before_markers, 0, MANY, 0,
4714
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
1352 "Insert text at point, relocating markers and inheriting properties.\n\
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
1353 Point moves forward so that it ends up after the inserted text.\n\
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
1354 Any other markers at the point of insertion also end up after the text.")
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
1355 (nargs, args)
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
1356 int nargs;
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
1357 register Lisp_Object *args;
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
1358 {
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1359 general_insert_function (insert_before_markers_and_inherit,
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1360 insert_from_string_before_markers, 1,
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1361 nargs, args);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1362 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1363 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1364
8646
0f05e3e89f87 (Finsert_char): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents: 8333
diff changeset
1365 DEFUN ("insert-char", Finsert_char, Sinsert_char, 2, 3, 0,
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1366 "Insert COUNT (second arg) copies of CHARACTER (first arg).\n\
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1367 Point and before-insertion-markers are affected as in the function `insert'.\n\
8646
0f05e3e89f87 (Finsert_char): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents: 8333
diff changeset
1368 Both arguments are required.\n\
0f05e3e89f87 (Finsert_char): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents: 8333
diff changeset
1369 The optional third arg INHERIT, if non-nil, says to inherit text properties\n\
0f05e3e89f87 (Finsert_char): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents: 8333
diff changeset
1370 from adjoining text, if those properties are sticky.")
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1371 (character, count, inherit)
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1372 Lisp_Object character, count, inherit;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1373 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1374 register unsigned char *string;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1375 register int strlen;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1376 register int i, n;
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1377 int len;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1378 unsigned char workbuf[4], *str;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1379
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1380 CHECK_NUMBER (character, 0);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1381 CHECK_NUMBER (count, 1);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1382
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1383 if (!NILP (current_buffer->enable_multibyte_characters))
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1384 len = CHAR_STRING (XFASTINT (character), workbuf, str);
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1385 else
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1386 workbuf[0] = XFASTINT (character), str = workbuf, len = 1;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1387 n = XINT (count) * len;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1388 if (n <= 0)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1389 return Qnil;
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1390 strlen = min (n, 256 * len);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1391 string = (unsigned char *) alloca (strlen);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1392 for (i = 0; i < strlen; i++)
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1393 string[i] = str[i % len];
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1394 while (n >= strlen)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1395 {
18194
c291aa915b85 (Finsert_char): Check QUIT.
Richard M. Stallman <rms@gnu.org>
parents: 18106
diff changeset
1396 QUIT;
8646
0f05e3e89f87 (Finsert_char): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents: 8333
diff changeset
1397 if (!NILP (inherit))
0f05e3e89f87 (Finsert_char): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents: 8333
diff changeset
1398 insert_and_inherit (string, strlen);
0f05e3e89f87 (Finsert_char): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents: 8333
diff changeset
1399 else
0f05e3e89f87 (Finsert_char): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents: 8333
diff changeset
1400 insert (string, strlen);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1401 n -= strlen;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1402 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1403 if (n > 0)
10382
9738aad59697 (Finsert_char): Check inherit flag for long strings too.
Karl Heuer <kwzh@gnu.org>
parents: 10308
diff changeset
1404 {
9738aad59697 (Finsert_char): Check inherit flag for long strings too.
Karl Heuer <kwzh@gnu.org>
parents: 10308
diff changeset
1405 if (!NILP (inherit))
9738aad59697 (Finsert_char): Check inherit flag for long strings too.
Karl Heuer <kwzh@gnu.org>
parents: 10308
diff changeset
1406 insert_and_inherit (string, n);
9738aad59697 (Finsert_char): Check inherit flag for long strings too.
Karl Heuer <kwzh@gnu.org>
parents: 10308
diff changeset
1407 else
9738aad59697 (Finsert_char): Check inherit flag for long strings too.
Karl Heuer <kwzh@gnu.org>
parents: 10308
diff changeset
1408 insert (string, n);
9738aad59697 (Finsert_char): Check inherit flag for long strings too.
Karl Heuer <kwzh@gnu.org>
parents: 10308
diff changeset
1409 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1410 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1411 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1412
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1413
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
1414 /* Making strings from buffer contents. */
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
1415
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
1416 /* Return a Lisp_String containing the text of the current buffer from
1285
d50533e23dff * editfns.c (make_buffer_string): Call copy_intervals_to_string().
Joseph Arceneaux <jla@gnu.org>
parents: 1254
diff changeset
1417 START to END. If text properties are in use and the current buffer
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3522
diff changeset
1418 has properties in the range specified, the resulting string will also
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1419 have them, if PROPS is nonzero.
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
1420
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
1421 We don't want to use plain old make_string here, because it calls
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
1422 make_uninit_string, which can cause the buffer arena to be
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
1423 compacted. make_string has no way of knowing that the data has
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
1424 been moved, and thus copies the wrong data into the string. This
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
1425 doesn't effect most of the other users of make_string, so it should
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
1426 be left as is. But we should use this function when conjuring
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
1427 buffer substrings. */
1285
d50533e23dff * editfns.c (make_buffer_string): Call copy_intervals_to_string().
Joseph Arceneaux <jla@gnu.org>
parents: 1254
diff changeset
1428
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
1429 Lisp_Object
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1430 make_buffer_string (start, end, props)
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
1431 int start, end;
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1432 int props;
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
1433 {
6772
6e53158ad17d (make_buffer_string): Copy properties whenever we have some
Richard M. Stallman <rms@gnu.org>
parents: 6714
diff changeset
1434 Lisp_Object result, tem, tem1;
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1435 int start_byte = CHAR_TO_BYTE (start);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1436 int end_byte = CHAR_TO_BYTE (end);
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
1437
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
1438 if (start < GPT && GPT < end)
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
1439 move_gap (start);
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
1440
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1441 result = make_uninit_multibyte_string (end - start, end_byte - start_byte);
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1442 bcopy (BYTE_POS_ADDR (start_byte), XSTRING (result)->data,
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1443 end_byte - start_byte);
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
1444
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1445 /* If desired, update and copy the text properties. */
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1446 #ifdef USE_TEXT_PROPERTIES
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1447 if (props)
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1448 {
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1449 update_buffer_properties (start, end);
5130
ddee29e260d2 (make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents: 4943
diff changeset
1450
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1451 tem = Fnext_property_change (make_number (start), Qnil, make_number (end));
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1452 tem1 = Ftext_properties_at (make_number (start), Qnil);
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1453
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1454 if (XINT (tem) != end || !NILP (tem1))
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1455 copy_intervals_to_string (result, current_buffer, start,
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1456 end - start);
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1457 }
5130
ddee29e260d2 (make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents: 4943
diff changeset
1458 #endif
1285
d50533e23dff * editfns.c (make_buffer_string): Call copy_intervals_to_string().
Joseph Arceneaux <jla@gnu.org>
parents: 1254
diff changeset
1459
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
1460 return result;
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
1461 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1462
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1463 /* Call Vbuffer_access_fontify_functions for the range START ... END
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1464 in the current buffer, if necessary. */
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1465
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1466 static void
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1467 update_buffer_properties (start, end)
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1468 int start, end;
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1469 {
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1470 #ifdef USE_TEXT_PROPERTIES
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1471 /* If this buffer has some access functions,
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1472 call them, specifying the range of the buffer being accessed. */
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1473 if (!NILP (Vbuffer_access_fontify_functions))
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1474 {
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1475 Lisp_Object args[3];
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1476 Lisp_Object tem;
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1477
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1478 args[0] = Qbuffer_access_fontify_functions;
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1479 XSETINT (args[1], start);
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1480 XSETINT (args[2], end);
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1481
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1482 /* But don't call them if we can tell that the work
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1483 has already been done. */
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1484 if (!NILP (Vbuffer_access_fontified_property))
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1485 {
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1486 tem = Ftext_property_any (args[1], args[2],
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1487 Vbuffer_access_fontified_property,
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1488 Qnil, Qnil);
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1489 if (! NILP (tem))
14126
edc94b82c3b3 (update_buffer_properties): Delete superfluous &'s.
Karl Heuer <kwzh@gnu.org>
parents: 14071
diff changeset
1490 Frun_hook_with_args (3, args);
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1491 }
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1492 else
14126
edc94b82c3b3 (update_buffer_properties): Delete superfluous &'s.
Karl Heuer <kwzh@gnu.org>
parents: 14071
diff changeset
1493 Frun_hook_with_args (3, args);
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1494 }
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1495 #endif
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1496 }
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1497
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1498 DEFUN ("buffer-substring", Fbuffer_substring, Sbuffer_substring, 2, 2, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1499 "Return the contents of part of the current buffer as a string.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1500 The two arguments START and END are character positions;\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1501 they can be in either order.")
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1502 (start, end)
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1503 Lisp_Object start, end;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1504 {
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1505 register int b, e;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1506
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1507 validate_region (&start, &end);
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1508 b = XINT (start);
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1509 e = XINT (end);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1510
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1511 return make_buffer_string (b, e, 1);
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1512 }
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1513
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1514 DEFUN ("buffer-substring-no-properties", Fbuffer_substring_no_properties,
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1515 Sbuffer_substring_no_properties, 2, 2, 0,
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1516 "Return the characters of part of the buffer, without the text properties.\n\
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1517 The two arguments START and END are character positions;\n\
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1518 they can be in either order.")
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1519 (start, end)
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1520 Lisp_Object start, end;
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1521 {
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1522 register int b, e;
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1523
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1524 validate_region (&start, &end);
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1525 b = XINT (start);
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1526 e = XINT (end);
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1527
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1528 return make_buffer_string (b, e, 0);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1529 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1530
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1531 DEFUN ("buffer-string", Fbuffer_string, Sbuffer_string, 0, 0, 0,
11433
6f7bdb6c3739 (Fbuffer_string): Doc clarification.
Karl Heuer <kwzh@gnu.org>
parents: 11402
diff changeset
1532 "Return the contents of the current buffer as a string.\n\
6f7bdb6c3739 (Fbuffer_string): Doc clarification.
Karl Heuer <kwzh@gnu.org>
parents: 11402
diff changeset
1533 If narrowing is in effect, this function returns only the visible part\n\
6f7bdb6c3739 (Fbuffer_string): Doc clarification.
Karl Heuer <kwzh@gnu.org>
parents: 11402
diff changeset
1534 of the buffer.")
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1535 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1536 {
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1537 return make_buffer_string (BEGV, ZV, 1);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1538 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1539
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1540 DEFUN ("insert-buffer-substring", Finsert_buffer_substring, Sinsert_buffer_substring,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1541 1, 3, 0,
3776
301e2dca5fd7 (Finsert_buffer_substring): Doc fix.
Roland McGrath <roland@gnu.org>
parents: 3591
diff changeset
1542 "Insert before point a substring of the contents of buffer BUFFER.\n\
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1543 BUFFER may be a buffer or a buffer name.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1544 Arguments START and END are character numbers specifying the substring.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1545 They default to the beginning and the end of BUFFER.")
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1546 (buf, start, end)
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1547 Lisp_Object buf, start, end;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1548 {
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1549 register int b, e, temp;
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1550 register struct buffer *bp, *obuf;
1854
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
1551 Lisp_Object buffer;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1552
1854
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
1553 buffer = Fget_buffer (buf);
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
1554 if (NILP (buffer))
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
1555 nsberror (buf);
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
1556 bp = XBUFFER (buffer);
16134
7558d82368f9 (Finsert_buffer_substring): Check for deleted buffer.
Karl Heuer <kwzh@gnu.org>
parents: 16097
diff changeset
1557 if (NILP (bp->name))
7558d82368f9 (Finsert_buffer_substring): Check for deleted buffer.
Karl Heuer <kwzh@gnu.org>
parents: 16097
diff changeset
1558 error ("Selecting deleted buffer");
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1559
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1560 if (NILP (start))
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1561 b = BUF_BEGV (bp);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1562 else
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1563 {
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1564 CHECK_NUMBER_COERCE_MARKER (start, 0);
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1565 b = XINT (start);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1566 }
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1567 if (NILP (end))
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1568 e = BUF_ZV (bp);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1569 else
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1570 {
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1571 CHECK_NUMBER_COERCE_MARKER (end, 1);
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1572 e = XINT (end);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1573 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1574
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1575 if (b > e)
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1576 temp = b, b = e, e = temp;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1577
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1578 if (!(BUF_BEGV (bp) <= b && e <= BUF_ZV (bp)))
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1579 args_out_of_range (start, end);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1580
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1581 obuf = current_buffer;
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1582 set_buffer_internal_1 (bp);
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1583 update_buffer_properties (b, e);
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1584 set_buffer_internal_1 (obuf);
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1585
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1586 insert_from_buffer (bp, b, e - b, 0);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1587 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1588 }
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1589
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1590 DEFUN ("compare-buffer-substrings", Fcompare_buffer_substrings, Scompare_buffer_substrings,
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1591 6, 6, 0,
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1592 "Compare two substrings of two buffers; return result as number.\n\
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1593 the value is -N if first string is less after N-1 chars,\n\
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1594 +N if first string is greater after N-1 chars, or 0 if strings match.\n\
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1595 Each substring is represented as three arguments: BUFFER, START and END.\n\
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1596 That makes six args in all, three for each substring.\n\n\
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1597 The value of `case-fold-search' in the current buffer\n\
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1598 determines whether case is significant or ignored.")
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1599 (buffer1, start1, end1, buffer2, start2, end2)
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1600 Lisp_Object buffer1, start1, end1, buffer2, start2, end2;
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1601 {
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1602 register int begp1, endp1, begp2, endp2, temp, len1, len2, length, i;
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1603 register struct buffer *bp1, *bp2;
14391
dfdf939f3e8c (Fcompare_buffer_substrings): Access case_canon_table as a char_table.
Richard M. Stallman <rms@gnu.org>
parents: 14237
diff changeset
1604 register Lisp_Object *trt
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1605 = (!NILP (current_buffer->case_fold_search)
14391
dfdf939f3e8c (Fcompare_buffer_substrings): Access case_canon_table as a char_table.
Richard M. Stallman <rms@gnu.org>
parents: 14237
diff changeset
1606 ? XCHAR_TABLE (current_buffer->case_canon_table)->contents : 0);
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1607 int chars = 0;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1608 int beg1_byte, beg2_byte;
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1609
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1610 /* Find the first buffer and its substring. */
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1611
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1612 if (NILP (buffer1))
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1613 bp1 = current_buffer;
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1614 else
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1615 {
1854
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
1616 Lisp_Object buf1;
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
1617 buf1 = Fget_buffer (buffer1);
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
1618 if (NILP (buf1))
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
1619 nsberror (buffer1);
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
1620 bp1 = XBUFFER (buf1);
16134
7558d82368f9 (Finsert_buffer_substring): Check for deleted buffer.
Karl Heuer <kwzh@gnu.org>
parents: 16097
diff changeset
1621 if (NILP (bp1->name))
7558d82368f9 (Finsert_buffer_substring): Check for deleted buffer.
Karl Heuer <kwzh@gnu.org>
parents: 16097
diff changeset
1622 error ("Selecting deleted buffer");
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1623 }
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1624
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1625 if (NILP (start1))
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1626 begp1 = BUF_BEGV (bp1);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1627 else
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1628 {
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1629 CHECK_NUMBER_COERCE_MARKER (start1, 1);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1630 begp1 = XINT (start1);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1631 }
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1632 if (NILP (end1))
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1633 endp1 = BUF_ZV (bp1);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1634 else
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1635 {
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1636 CHECK_NUMBER_COERCE_MARKER (end1, 2);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1637 endp1 = XINT (end1);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1638 }
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1639
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1640 if (begp1 > endp1)
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1641 temp = begp1, begp1 = endp1, endp1 = temp;
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1642
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1643 if (!(BUF_BEGV (bp1) <= begp1
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1644 && begp1 <= endp1
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1645 && endp1 <= BUF_ZV (bp1)))
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1646 args_out_of_range (start1, end1);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1647
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1648 /* Likewise for second substring. */
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1649
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1650 if (NILP (buffer2))
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1651 bp2 = current_buffer;
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1652 else
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1653 {
1854
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
1654 Lisp_Object buf2;
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
1655 buf2 = Fget_buffer (buffer2);
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
1656 if (NILP (buf2))
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
1657 nsberror (buffer2);
15015
8f8d48ab0a53 (Fcompare_buffer_substrings): Fix dumb bug handling buffer name as second arg.
Richard M. Stallman <rms@gnu.org>
parents: 15004
diff changeset
1658 bp2 = XBUFFER (buf2);
16134
7558d82368f9 (Finsert_buffer_substring): Check for deleted buffer.
Karl Heuer <kwzh@gnu.org>
parents: 16097
diff changeset
1659 if (NILP (bp2->name))
7558d82368f9 (Finsert_buffer_substring): Check for deleted buffer.
Karl Heuer <kwzh@gnu.org>
parents: 16097
diff changeset
1660 error ("Selecting deleted buffer");
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1661 }
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1662
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1663 if (NILP (start2))
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1664 begp2 = BUF_BEGV (bp2);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1665 else
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1666 {
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1667 CHECK_NUMBER_COERCE_MARKER (start2, 4);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1668 begp2 = XINT (start2);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1669 }
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1670 if (NILP (end2))
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1671 endp2 = BUF_ZV (bp2);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1672 else
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1673 {
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1674 CHECK_NUMBER_COERCE_MARKER (end2, 5);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1675 endp2 = XINT (end2);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1676 }
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1677
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1678 if (begp2 > endp2)
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1679 temp = begp2, begp2 = endp2, endp2 = temp;
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1680
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1681 if (!(BUF_BEGV (bp2) <= begp2
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1682 && begp2 <= endp2
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1683 && endp2 <= BUF_ZV (bp2)))
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1684 args_out_of_range (start2, end2);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1685
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1686 beg1_byte = buf_charpos_to_bytepos (bp1, begp1);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1687 beg2_byte = buf_charpos_to_bytepos (bp2, begp2);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1688 len1 = buf_charpos_to_bytepos (bp1, endp1) - begp1;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1689 len2 = buf_charpos_to_bytepos (bp2, endp2) - begp2;
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1690 length = len1;
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1691 if (len2 < length)
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1692 length = len2;
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1693
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1694 for (i = 0; i < length; i++)
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1695 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1696 unsigned char *p1 = BUF_BYTE_ADDRESS (bp1, beg1_byte + i);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1697 int c1 = *p1;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1698 int c2 = *BUF_BYTE_ADDRESS (bp2, beg2_byte + i);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1699
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1700 /* If a character begins here,
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1701 count the previous character now. */
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1702 if (i > 0
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1703 && (NILP (current_buffer->enable_multibyte_characters)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1704 || CHAR_HEAD_P (*p1)))
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1705 chars++;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1706
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1707 if (trt)
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1708 {
18106
b129c5fd7925 (Fcompare_buffer_substrings): trt contains Lisp_Objects.
Richard M. Stallman <rms@gnu.org>
parents: 18031
diff changeset
1709 c1 = XINT (trt[c1]);
b129c5fd7925 (Fcompare_buffer_substrings): trt contains Lisp_Objects.
Richard M. Stallman <rms@gnu.org>
parents: 18031
diff changeset
1710 c2 = XINT (trt[c2]);
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1711 }
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1712 if (c1 < c2)
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1713 return make_number (- 1 - chars);
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1714 if (c1 > c2)
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1715 return make_number (chars + 1);
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1716 }
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1717
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1718 /* The strings match as far as they go.
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1719 If one is shorter, that one is less. */
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1720 if (length < len1)
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1721 return make_number (chars + 1);
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1722 else if (length < len2)
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1723 return make_number (- chars - 1);
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1724
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1725 /* Same length too => they are equal. */
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1726 return make_number (0);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
1727 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1728
10480
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
1729 static Lisp_Object
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
1730 subst_char_in_region_unwind (arg)
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
1731 Lisp_Object arg;
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
1732 {
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
1733 return current_buffer->undo_list = arg;
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
1734 }
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
1735
12622
205232bb7efe (Fsubst_char_in_region): Bind buffer-file-name to nil if NOUNDO is true.
Richard M. Stallman <rms@gnu.org>
parents: 12603
diff changeset
1736 static Lisp_Object
205232bb7efe (Fsubst_char_in_region): Bind buffer-file-name to nil if NOUNDO is true.
Richard M. Stallman <rms@gnu.org>
parents: 12603
diff changeset
1737 subst_char_in_region_unwind_1 (arg)
205232bb7efe (Fsubst_char_in_region): Bind buffer-file-name to nil if NOUNDO is true.
Richard M. Stallman <rms@gnu.org>
parents: 12603
diff changeset
1738 Lisp_Object arg;
205232bb7efe (Fsubst_char_in_region): Bind buffer-file-name to nil if NOUNDO is true.
Richard M. Stallman <rms@gnu.org>
parents: 12603
diff changeset
1739 {
205232bb7efe (Fsubst_char_in_region): Bind buffer-file-name to nil if NOUNDO is true.
Richard M. Stallman <rms@gnu.org>
parents: 12603
diff changeset
1740 return current_buffer->filename = arg;
205232bb7efe (Fsubst_char_in_region): Bind buffer-file-name to nil if NOUNDO is true.
Richard M. Stallman <rms@gnu.org>
parents: 12603
diff changeset
1741 }
205232bb7efe (Fsubst_char_in_region): Bind buffer-file-name to nil if NOUNDO is true.
Richard M. Stallman <rms@gnu.org>
parents: 12603
diff changeset
1742
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1743 DEFUN ("subst-char-in-region", Fsubst_char_in_region,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1744 Ssubst_char_in_region, 4, 5, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1745 "From START to END, replace FROMCHAR with TOCHAR each time it occurs.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1746 If optional arg NOUNDO is non-nil, don't record this change for undo\n\
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1747 and don't mark the buffer as really changed.\n\
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1748 Both characters must have the same length of multi-byte form.")
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1749 (start, end, fromchar, tochar, noundo)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1750 Lisp_Object start, end, fromchar, tochar, noundo;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1751 {
20834
95a80c1e06c3 (Fsubst_char_in_region): Handle character-base
Kenichi Handa <handa@m17n.org>
parents: 20826
diff changeset
1752 register int pos, pos_byte, stop, i, len, end_byte;
5130
ddee29e260d2 (make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents: 4943
diff changeset
1753 int changed = 0;
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1754 unsigned char fromwork[4], *fromstr, towork[4], *tostr, *p;
10480
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
1755 int count = specpdl_ptr - specpdl;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1756
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1757 validate_region (&start, &end);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1758 CHECK_NUMBER (fromchar, 2);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1759 CHECK_NUMBER (tochar, 3);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1760
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1761 if (! NILP (current_buffer->enable_multibyte_characters))
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1762 {
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1763 len = CHAR_STRING (XFASTINT (fromchar), fromwork, fromstr);
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1764 if (CHAR_STRING (XFASTINT (tochar), towork, tostr) != len)
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1765 error ("Characters in subst-char-in-region have different byte-lengths");
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1766 }
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1767 else
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1768 {
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1769 len = 1;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1770 fromwork[0] = XFASTINT (fromchar), fromstr = fromwork;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1771 towork[0] = XFASTINT (tochar), tostr = towork;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1772 }
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1773
20834
95a80c1e06c3 (Fsubst_char_in_region): Handle character-base
Kenichi Handa <handa@m17n.org>
parents: 20826
diff changeset
1774 pos = XINT (start);
95a80c1e06c3 (Fsubst_char_in_region): Handle character-base
Kenichi Handa <handa@m17n.org>
parents: 20826
diff changeset
1775 pos_byte = CHAR_TO_BYTE (pos);
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1776 stop = CHAR_TO_BYTE (XINT (end));
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1777 end_byte = stop;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1778
10480
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
1779 /* If we don't want undo, turn off putting stuff on the list.
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
1780 That's faster than getting rid of things,
12622
205232bb7efe (Fsubst_char_in_region): Bind buffer-file-name to nil if NOUNDO is true.
Richard M. Stallman <rms@gnu.org>
parents: 12603
diff changeset
1781 and it prevents even the entry for a first change.
205232bb7efe (Fsubst_char_in_region): Bind buffer-file-name to nil if NOUNDO is true.
Richard M. Stallman <rms@gnu.org>
parents: 12603
diff changeset
1782 Also inhibit locking the file. */
10480
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
1783 if (!NILP (noundo))
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
1784 {
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
1785 record_unwind_protect (subst_char_in_region_unwind,
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
1786 current_buffer->undo_list);
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
1787 current_buffer->undo_list = Qt;
12622
205232bb7efe (Fsubst_char_in_region): Bind buffer-file-name to nil if NOUNDO is true.
Richard M. Stallman <rms@gnu.org>
parents: 12603
diff changeset
1788 /* Don't do file-locking. */
205232bb7efe (Fsubst_char_in_region): Bind buffer-file-name to nil if NOUNDO is true.
Richard M. Stallman <rms@gnu.org>
parents: 12603
diff changeset
1789 record_unwind_protect (subst_char_in_region_unwind_1,
205232bb7efe (Fsubst_char_in_region): Bind buffer-file-name to nil if NOUNDO is true.
Richard M. Stallman <rms@gnu.org>
parents: 12603
diff changeset
1790 current_buffer->filename);
205232bb7efe (Fsubst_char_in_region): Bind buffer-file-name to nil if NOUNDO is true.
Richard M. Stallman <rms@gnu.org>
parents: 12603
diff changeset
1791 current_buffer->filename = Qnil;
10480
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
1792 }
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
1793
20834
95a80c1e06c3 (Fsubst_char_in_region): Handle character-base
Kenichi Handa <handa@m17n.org>
parents: 20826
diff changeset
1794 if (pos_byte < GPT_BYTE)
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1795 stop = min (stop, GPT_BYTE);
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1796 while (1)
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1797 {
20834
95a80c1e06c3 (Fsubst_char_in_region): Handle character-base
Kenichi Handa <handa@m17n.org>
parents: 20826
diff changeset
1798 if (pos_byte >= stop)
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1799 {
20834
95a80c1e06c3 (Fsubst_char_in_region): Handle character-base
Kenichi Handa <handa@m17n.org>
parents: 20826
diff changeset
1800 if (pos_byte >= end_byte) break;
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1801 stop = end_byte;
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1802 }
20834
95a80c1e06c3 (Fsubst_char_in_region): Handle character-base
Kenichi Handa <handa@m17n.org>
parents: 20826
diff changeset
1803 p = BYTE_POS_ADDR (pos_byte);
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1804 if (p[0] == fromstr[0]
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1805 && (len == 1
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1806 || (p[1] == fromstr[1]
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1807 && (len == 2 || (p[2] == fromstr[2]
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1808 && (len == 3 || p[3] == fromstr[3]))))))
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1809 {
5130
ddee29e260d2 (make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents: 4943
diff changeset
1810 if (! changed)
ddee29e260d2 (make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents: 4943
diff changeset
1811 {
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1812 modify_region (current_buffer, XINT (start), XINT (end));
5242
0e99ea9941e2 (Fmessage): Use message2.
Richard M. Stallman <rms@gnu.org>
parents: 5130
diff changeset
1813
0e99ea9941e2 (Fmessage): Use message2.
Richard M. Stallman <rms@gnu.org>
parents: 5130
diff changeset
1814 if (! NILP (noundo))
0e99ea9941e2 (Fmessage): Use message2.
Richard M. Stallman <rms@gnu.org>
parents: 5130
diff changeset
1815 {
10308
90784ed0416f Use SAVE_MODIFF and BUF_SAVE_MODIFF
Richard M. Stallman <rms@gnu.org>
parents: 9812
diff changeset
1816 if (MODIFF - 1 == SAVE_MODIFF)
90784ed0416f Use SAVE_MODIFF and BUF_SAVE_MODIFF
Richard M. Stallman <rms@gnu.org>
parents: 9812
diff changeset
1817 SAVE_MODIFF++;
5242
0e99ea9941e2 (Fmessage): Use message2.
Richard M. Stallman <rms@gnu.org>
parents: 5130
diff changeset
1818 if (MODIFF - 1 == current_buffer->auto_save_modified)
0e99ea9941e2 (Fmessage): Use message2.
Richard M. Stallman <rms@gnu.org>
parents: 5130
diff changeset
1819 current_buffer->auto_save_modified++;
0e99ea9941e2 (Fmessage): Use message2.
Richard M. Stallman <rms@gnu.org>
parents: 5130
diff changeset
1820 }
0e99ea9941e2 (Fmessage): Use message2.
Richard M. Stallman <rms@gnu.org>
parents: 5130
diff changeset
1821
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1822 changed = 1;
5130
ddee29e260d2 (make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents: 4943
diff changeset
1823 }
ddee29e260d2 (make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents: 4943
diff changeset
1824
488
4fddd0f0fc33 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 448
diff changeset
1825 if (NILP (noundo))
20834
95a80c1e06c3 (Fsubst_char_in_region): Handle character-base
Kenichi Handa <handa@m17n.org>
parents: 20826
diff changeset
1826 record_change (pos, 1);
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1827 for (i = 0; i < len; i++) *p++ = tostr[i];
20834
95a80c1e06c3 (Fsubst_char_in_region): Handle character-base
Kenichi Handa <handa@m17n.org>
parents: 20826
diff changeset
1828 pos++;
95a80c1e06c3 (Fsubst_char_in_region): Handle character-base
Kenichi Handa <handa@m17n.org>
parents: 20826
diff changeset
1829 pos_byte += len;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1830 }
20834
95a80c1e06c3 (Fsubst_char_in_region): Handle character-base
Kenichi Handa <handa@m17n.org>
parents: 20826
diff changeset
1831 INC_BOTH (pos, pos_byte);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1832 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1833
5130
ddee29e260d2 (make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents: 4943
diff changeset
1834 if (changed)
ddee29e260d2 (make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents: 4943
diff changeset
1835 signal_after_change (XINT (start),
20834
95a80c1e06c3 (Fsubst_char_in_region): Handle character-base
Kenichi Handa <handa@m17n.org>
parents: 20826
diff changeset
1836 XINT (end) - XINT (start), XINT (end) - XINT (start));
5130
ddee29e260d2 (make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents: 4943
diff changeset
1837
10480
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
1838 unbind_to (count, Qnil);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1839 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1840 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1841
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1842 DEFUN ("translate-region", Ftranslate_region, Stranslate_region, 3, 3, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1843 "From START to END, translate characters according to TABLE.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1844 TABLE is a string; the Nth character in it is the mapping\n\
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1845 for the character with code N.\n\
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1846 This function does not alter multibyte characters.\n\
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1847 It returns the number of characters changed.")
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1848 (start, end, table)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1849 Lisp_Object start;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1850 Lisp_Object end;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1851 register Lisp_Object table;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1852 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1853 register int pos_byte, stop; /* Limits of the region. */
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1854 register unsigned char *tt; /* Trans table. */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1855 register int nc; /* New character. */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1856 int cnt; /* Number of changes made. */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1857 int size; /* Size of translate table. */
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1858 int pos;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1859
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1860 validate_region (&start, &end);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1861 CHECK_STRING (table, 2);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1862
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1863 size = XSTRING (table)->size_byte;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1864 tt = XSTRING (table)->data;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1865
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1866 pos_byte = CHAR_TO_BYTE (XINT (start));
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1867 stop = CHAR_TO_BYTE (XINT (end));
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1868 modify_region (current_buffer, XINT (start), XINT (end));
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1869 pos = XINT (start);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1870
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1871 cnt = 0;
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1872 for (; pos_byte < stop; )
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1873 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1874 register unsigned char *p = BYTE_POS_ADDR (pos_byte);
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1875 int len;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1876 int oc;
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1877
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1878 oc = STRING_CHAR_AND_LENGTH (p, stop - pos_byte, len);
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1879 if (oc < size && len == 1)
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1880 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1881 nc = tt[oc];
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1882 if (nc != oc)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1883 {
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1884 record_change (pos, 1);
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1885 *p = nc;
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1886 signal_after_change (pos, 1, 1);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1887 ++cnt;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1888 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1889 }
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1890 pos_byte += len;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1891 pos++;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1892 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1893
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1894 return make_number (cnt);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1895 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1896
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1897 DEFUN ("delete-region", Fdelete_region, Sdelete_region, 2, 2, "r",
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1898 "Delete the text between point and mark.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1899 When called from a program, expects two arguments,\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1900 positions (integers or markers) specifying the stretch to be deleted.")
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1901 (start, end)
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1902 Lisp_Object start, end;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1903 {
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1904 validate_region (&start, &end);
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1905 del_range (XINT (start), XINT (end));
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1906 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1907 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1908
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1909 DEFUN ("widen", Fwiden, Swiden, 0, 0, "",
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1910 "Remove restrictions (narrowing) from current buffer.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1911 This allows the buffer's full text to be seen and edited.")
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1912 ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1913 {
19207
be370e94fb42 (Fwiden, Fnarrow_to_region, save_restriction_restore):
Richard M. Stallman <rms@gnu.org>
parents: 19032
diff changeset
1914 if (BEG != BEGV || Z != ZV)
be370e94fb42 (Fwiden, Fnarrow_to_region, save_restriction_restore):
Richard M. Stallman <rms@gnu.org>
parents: 19032
diff changeset
1915 current_buffer->clip_changed = 1;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1916 BEGV = BEG;
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1917 BEGV_BYTE = BEG_BYTE;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1918 SET_BUF_ZV_BOTH (current_buffer, Z, Z_BYTE);
330
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
1919 /* Changing the buffer bounds invalidates any recorded current column. */
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
1920 invalidate_current_column ();
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1921 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1922 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1923
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1924 DEFUN ("narrow-to-region", Fnarrow_to_region, Snarrow_to_region, 2, 2, "r",
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1925 "Restrict editing in this buffer to the current region.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1926 The rest of the text becomes temporarily invisible and untouchable\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1927 but is not deleted; if you save the buffer in a file, the invisible\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1928 text is included in the file. \\[widen] makes all visible again.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1929 See also `save-restriction'.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1930 \n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1931 When calling from a program, pass two arguments; positions (integers\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1932 or markers) bounding the text that should remain visible.")
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1933 (start, end)
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1934 register Lisp_Object start, end;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1935 {
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1936 CHECK_NUMBER_COERCE_MARKER (start, 0);
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1937 CHECK_NUMBER_COERCE_MARKER (end, 1);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1938
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1939 if (XINT (start) > XINT (end))
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1940 {
10383
a7fe0fb11314 (Fnarrow_to_region): Swap using temp Lisp_Object, not int.
Karl Heuer <kwzh@gnu.org>
parents: 10382
diff changeset
1941 Lisp_Object tem;
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1942 tem = start; start = end; end = tem;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1943 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1944
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1945 if (!(BEG <= XINT (start) && XINT (start) <= XINT (end) && XINT (end) <= Z))
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1946 args_out_of_range (start, end);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1947
19207
be370e94fb42 (Fwiden, Fnarrow_to_region, save_restriction_restore):
Richard M. Stallman <rms@gnu.org>
parents: 19032
diff changeset
1948 if (BEGV != XFASTINT (start) || ZV != XFASTINT (end))
be370e94fb42 (Fwiden, Fnarrow_to_region, save_restriction_restore):
Richard M. Stallman <rms@gnu.org>
parents: 19032
diff changeset
1949 current_buffer->clip_changed = 1;
be370e94fb42 (Fwiden, Fnarrow_to_region, save_restriction_restore):
Richard M. Stallman <rms@gnu.org>
parents: 19032
diff changeset
1950
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1951 SET_BUF_BEGV (current_buffer, XFASTINT (start));
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1952 SET_BUF_ZV (current_buffer, XFASTINT (end));
16039
855c8d8ba0f0 Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents: 15910
diff changeset
1953 if (PT < XFASTINT (start))
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1954 SET_PT (XFASTINT (start));
16039
855c8d8ba0f0 Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents: 15910
diff changeset
1955 if (PT > XFASTINT (end))
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
1956 SET_PT (XFASTINT (end));
330
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
1957 /* Changing the buffer bounds invalidates any recorded current column. */
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
1958 invalidate_current_column ();
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1959 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1960 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1961
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1962 Lisp_Object
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1963 save_restriction_save ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1964 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1965 register Lisp_Object bottom, top;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1966 /* Note: I tried using markers here, but it does not win
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1967 because insertion at the end of the saved region
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1968 does not advance mh and is considered "outside" the saved region. */
9305
ac077e2a75f1 (Fstring_to_char, Fpoint, Fbufsize, Fpoint_min, Fpoint_max, Ffollowing_char,
Karl Heuer <kwzh@gnu.org>
parents: 9265
diff changeset
1969 XSETFASTINT (bottom, BEGV - BEG);
ac077e2a75f1 (Fstring_to_char, Fpoint, Fbufsize, Fpoint_min, Fpoint_max, Ffollowing_char,
Karl Heuer <kwzh@gnu.org>
parents: 9265
diff changeset
1970 XSETFASTINT (top, Z - ZV);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1971
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1972 return Fcons (Fcurrent_buffer (), Fcons (bottom, top));
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1973 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1974
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1975 Lisp_Object
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1976 save_restriction_restore (data)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1977 Lisp_Object data;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1978 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1979 register struct buffer *buf;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1980 register int newhead, newtail;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1981 register Lisp_Object tem;
19207
be370e94fb42 (Fwiden, Fnarrow_to_region, save_restriction_restore):
Richard M. Stallman <rms@gnu.org>
parents: 19032
diff changeset
1982 int obegv, ozv;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1983
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1984 buf = XBUFFER (XCONS (data)->car);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1985
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1986 data = XCONS (data)->cdr;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1987
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1988 tem = XCONS (data)->car;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1989 newhead = XINT (tem);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1990 tem = XCONS (data)->cdr;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1991 newtail = XINT (tem);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1992 if (newhead + newtail > BUF_Z (buf) - BUF_BEG (buf))
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1993 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1994 newhead = 0;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1995 newtail = 0;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1996 }
19207
be370e94fb42 (Fwiden, Fnarrow_to_region, save_restriction_restore):
Richard M. Stallman <rms@gnu.org>
parents: 19032
diff changeset
1997
be370e94fb42 (Fwiden, Fnarrow_to_region, save_restriction_restore):
Richard M. Stallman <rms@gnu.org>
parents: 19032
diff changeset
1998 obegv = BUF_BEGV (buf);
be370e94fb42 (Fwiden, Fnarrow_to_region, save_restriction_restore):
Richard M. Stallman <rms@gnu.org>
parents: 19032
diff changeset
1999 ozv = BUF_ZV (buf);
be370e94fb42 (Fwiden, Fnarrow_to_region, save_restriction_restore):
Richard M. Stallman <rms@gnu.org>
parents: 19032
diff changeset
2000
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2001 SET_BUF_BEGV (buf, BUF_BEG (buf) + newhead);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2002 SET_BUF_ZV (buf, BUF_Z (buf) - newtail);
19207
be370e94fb42 (Fwiden, Fnarrow_to_region, save_restriction_restore):
Richard M. Stallman <rms@gnu.org>
parents: 19032
diff changeset
2003
be370e94fb42 (Fwiden, Fnarrow_to_region, save_restriction_restore):
Richard M. Stallman <rms@gnu.org>
parents: 19032
diff changeset
2004 if (obegv != BUF_BEGV (buf) || ozv != BUF_ZV (buf))
be370e94fb42 (Fwiden, Fnarrow_to_region, save_restriction_restore):
Richard M. Stallman <rms@gnu.org>
parents: 19032
diff changeset
2005 current_buffer->clip_changed = 1;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2006
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2007 /* If point is outside the new visible range, move it inside. */
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2008 SET_BUF_PT_BOTH (buf,
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2009 clip_to_bounds (BUF_BEGV (buf), BUF_PT (buf), BUF_ZV (buf)),
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2010 clip_to_bounds (BUF_BEGV_BYTE (buf), BUF_PT_BYTE (buf),
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2011 BUF_ZV_BYTE (buf)));
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2012
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2013 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2014 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2015
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2016 DEFUN ("save-restriction", Fsave_restriction, Ssave_restriction, 0, UNEVALLED, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2017 "Execute BODY, saving and restoring current buffer's restrictions.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2018 The buffer's restrictions make parts of the beginning and end invisible.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2019 \(They are set up with `narrow-to-region' and eliminated with `widen'.)\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2020 This special form, `save-restriction', saves the current buffer's restrictions\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2021 when it is entered, and restores them when it is exited.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2022 So any `narrow-to-region' within BODY lasts only until the end of the form.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2023 The old restrictions settings are restored\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2024 even in case of abnormal exit (throw or error).\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2025 \n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2026 The value returned is the value of the last form in BODY.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2027 \n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2028 `save-restriction' can get confused if, within the BODY, you widen\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2029 and then make changes outside the area within the saved restrictions.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2030 \n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2031 Note: if you are using both `save-excursion' and `save-restriction',\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2032 use `save-excursion' outermost:\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2033 (save-excursion (save-restriction ...))")
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2034 (body)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2035 Lisp_Object body;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2036 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2037 register Lisp_Object val;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2038 int count = specpdl_ptr - specpdl;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2039
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2040 record_unwind_protect (save_restriction_restore, save_restriction_save ());
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2041 val = Fprogn (body);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2042 return unbind_to (count, val);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2043 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2044
5884
d02095ea13a5 (Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents: 5882
diff changeset
2045 /* Buffer for the most recent text displayed by Fmessage. */
d02095ea13a5 (Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents: 5882
diff changeset
2046 static char *message_text;
d02095ea13a5 (Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents: 5882
diff changeset
2047
d02095ea13a5 (Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents: 5882
diff changeset
2048 /* Allocated length of that buffer. */
d02095ea13a5 (Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents: 5882
diff changeset
2049 static int message_length;
d02095ea13a5 (Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents: 5882
diff changeset
2050
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2051 DEFUN ("message", Fmessage, Smessage, 1, MANY, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2052 "Print a one-line message at the bottom of the screen.\n\
12602
3c9d53f851f4 (Fmessage): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 12489
diff changeset
2053 The first argument is a format control string, and the rest are data\n\
3c9d53f851f4 (Fmessage): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 12489
diff changeset
2054 to be formatted under control of the string. See `format' for details.\n\
3c9d53f851f4 (Fmessage): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 12489
diff changeset
2055 \n\
1426
67fd35416ba3 * * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents: 1285
diff changeset
2056 If the first argument is nil, clear any existing message; let the\n\
67fd35416ba3 * * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents: 1285
diff changeset
2057 minibuffer contents show.")
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2058 (nargs, args)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2059 int nargs;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2060 Lisp_Object *args;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2061 {
1426
67fd35416ba3 * * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents: 1285
diff changeset
2062 if (NILP (args[0]))
1916
e21c1f3e37cb * editfns.c (Fmessage): Don't forget to return a value when
Jim Blandy <jimb@redhat.com>
parents: 1854
diff changeset
2063 {
e21c1f3e37cb * editfns.c (Fmessage): Don't forget to return a value when
Jim Blandy <jimb@redhat.com>
parents: 1854
diff changeset
2064 message (0);
e21c1f3e37cb * editfns.c (Fmessage): Don't forget to return a value when
Jim Blandy <jimb@redhat.com>
parents: 1854
diff changeset
2065 return Qnil;
e21c1f3e37cb * editfns.c (Fmessage): Don't forget to return a value when
Jim Blandy <jimb@redhat.com>
parents: 1854
diff changeset
2066 }
1426
67fd35416ba3 * * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents: 1285
diff changeset
2067 else
67fd35416ba3 * * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents: 1285
diff changeset
2068 {
67fd35416ba3 * * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents: 1285
diff changeset
2069 register Lisp_Object val;
67fd35416ba3 * * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents: 1285
diff changeset
2070 val = Fformat (nargs, args);
5884
d02095ea13a5 (Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents: 5882
diff changeset
2071 /* Copy the data so that it won't move when we GC. */
d02095ea13a5 (Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents: 5882
diff changeset
2072 if (! message_text)
d02095ea13a5 (Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents: 5882
diff changeset
2073 {
d02095ea13a5 (Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents: 5882
diff changeset
2074 message_text = (char *)xmalloc (80);
d02095ea13a5 (Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents: 5882
diff changeset
2075 message_length = 80;
d02095ea13a5 (Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents: 5882
diff changeset
2076 }
d02095ea13a5 (Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents: 5882
diff changeset
2077 if (XSTRING (val)->size > message_length)
d02095ea13a5 (Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents: 5882
diff changeset
2078 {
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2079 message_length = XSTRING (val)->size_byte;
5884
d02095ea13a5 (Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents: 5882
diff changeset
2080 message_text = (char *)xrealloc (message_text, message_length);
d02095ea13a5 (Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents: 5882
diff changeset
2081 }
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2082 bcopy (XSTRING (val)->data, message_text, XSTRING (val)->size_byte);
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2083 message2 (message_text, XSTRING (val)->size_byte,
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2084 STRING_MULTIBYTE (val));
1426
67fd35416ba3 * * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents: 1285
diff changeset
2085 return val;
67fd35416ba3 * * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents: 1285
diff changeset
2086 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2087 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2088
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2089 DEFUN ("message-box", Fmessage_box, Smessage_box, 1, MANY, 0,
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2090 "Display a message, in a dialog box if possible.\n\
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2091 If a dialog box is not available, use the echo area.\n\
13878
2a71500dfb93 (Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents: 13767
diff changeset
2092 The first argument is a format control string, and the rest are data\n\
2a71500dfb93 (Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents: 13767
diff changeset
2093 to be formatted under control of the string. See `format' for details.\n\
2a71500dfb93 (Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents: 13767
diff changeset
2094 \n\
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2095 If the first argument is nil, clear any existing message; let the\n\
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2096 minibuffer contents show.")
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2097 (nargs, args)
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2098 int nargs;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2099 Lisp_Object *args;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2100 {
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2101 if (NILP (args[0]))
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2102 {
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2103 message (0);
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2104 return Qnil;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2105 }
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2106 else
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2107 {
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2108 register Lisp_Object val;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2109 val = Fformat (nargs, args);
13878
2a71500dfb93 (Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents: 13767
diff changeset
2110 #ifdef HAVE_MENUS
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2111 {
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2112 Lisp_Object pane, menu, obj;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2113 struct gcpro gcpro1;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2114 pane = Fcons (Fcons (build_string ("OK"), Qt), Qnil);
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2115 GCPRO1 (pane);
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2116 menu = Fcons (val, pane);
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2117 obj = Fx_popup_dialog (Qt, menu);
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2118 UNGCPRO;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2119 return val;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2120 }
13878
2a71500dfb93 (Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents: 13767
diff changeset
2121 #else /* not HAVE_MENUS */
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2122 /* Copy the data so that it won't move when we GC. */
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2123 if (! message_text)
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2124 {
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2125 message_text = (char *)xmalloc (80);
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2126 message_length = 80;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2127 }
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2128 if (XSTRING (val)->size_byte > message_length)
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2129 {
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2130 message_length = XSTRING (val)->size_byte;
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2131 message_text = (char *)xrealloc (message_text, message_length);
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2132 }
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2133 bcopy (XSTRING (val)->data, message_text, XSTRING (val)->size_byte);
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2134 message2 (message_text, XSTRING (val)->size_byte);
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2135 return val;
13878
2a71500dfb93 (Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents: 13767
diff changeset
2136 #endif /* not HAVE_MENUS */
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2137 }
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2138 }
13878
2a71500dfb93 (Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents: 13767
diff changeset
2139 #ifdef HAVE_MENUS
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2140 extern Lisp_Object last_nonmenu_event;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2141 #endif
13878
2a71500dfb93 (Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents: 13767
diff changeset
2142
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2143 DEFUN ("message-or-box", Fmessage_or_box, Smessage_or_box, 1, MANY, 0,
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2144 "Display a message in a dialog box or in the echo area.\n\
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2145 If this command was invoked with the mouse, use a dialog box.\n\
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2146 Otherwise, use the echo area.\n\
13878
2a71500dfb93 (Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents: 13767
diff changeset
2147 The first argument is a format control string, and the rest are data\n\
2a71500dfb93 (Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents: 13767
diff changeset
2148 to be formatted under control of the string. See `format' for details.\n\
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2149 \n\
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2150 If the first argument is nil, clear any existing message; let the\n\
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2151 minibuffer contents show.")
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2152 (nargs, args)
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2153 int nargs;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2154 Lisp_Object *args;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2155 {
13878
2a71500dfb93 (Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents: 13767
diff changeset
2156 #ifdef HAVE_MENUS
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2157 if (NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
8981
6e1a5ff3d795 (Fmessage_or_box): Use Fmessage_box with new name.
Richard M. Stallman <rms@gnu.org>
parents: 8975
diff changeset
2158 return Fmessage_box (nargs, args);
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2159 #endif
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2160 return Fmessage (nargs, args);
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2161 }
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2162
18937
ddb91108a9d2 (Fcurrent_message): New function.
Richard M. Stallman <rms@gnu.org>
parents: 18756
diff changeset
2163 DEFUN ("current-message", Fcurrent_message, Scurrent_message, 0, 0, 0,
ddb91108a9d2 (Fcurrent_message): New function.
Richard M. Stallman <rms@gnu.org>
parents: 18756
diff changeset
2164 "Return the string currently displayed in the echo area, or nil if none.")
ddb91108a9d2 (Fcurrent_message): New function.
Richard M. Stallman <rms@gnu.org>
parents: 18756
diff changeset
2165 ()
ddb91108a9d2 (Fcurrent_message): New function.
Richard M. Stallman <rms@gnu.org>
parents: 18756
diff changeset
2166 {
ddb91108a9d2 (Fcurrent_message): New function.
Richard M. Stallman <rms@gnu.org>
parents: 18756
diff changeset
2167 return (echo_area_glyphs
ddb91108a9d2 (Fcurrent_message): New function.
Richard M. Stallman <rms@gnu.org>
parents: 18756
diff changeset
2168 ? make_string (echo_area_glyphs, echo_area_glyphs_length)
ddb91108a9d2 (Fcurrent_message): New function.
Richard M. Stallman <rms@gnu.org>
parents: 18756
diff changeset
2169 : Qnil);
ddb91108a9d2 (Fcurrent_message): New function.
Richard M. Stallman <rms@gnu.org>
parents: 18756
diff changeset
2170 }
ddb91108a9d2 (Fcurrent_message): New function.
Richard M. Stallman <rms@gnu.org>
parents: 18756
diff changeset
2171
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2172 /* Number of bytes that STRING will occupy when put into the result.
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2173 MULTIBYTE is nonzero if the result should be multibyte. */
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2174
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2175 #define CONVERTED_BYTE_SIZE(MULTIBYTE, STRING) \
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2176 (((MULTIBYTE) && ! STRING_MULTIBYTE (STRING)) \
20804
14fa73136e64 (CONVERTED_BYTE_SIZE): Fix the logic.
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
2177 ? count_size_as_multibyte (XSTRING (STRING)->data, \
14fa73136e64 (CONVERTED_BYTE_SIZE): Fix the logic.
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
2178 XSTRING (STRING)->size_byte) \
14fa73136e64 (CONVERTED_BYTE_SIZE): Fix the logic.
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
2179 : XSTRING (STRING)->size_byte)
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2180
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2181 DEFUN ("format", Fformat, Sformat, 1, MANY, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2182 "Format a string out of a control-string and arguments.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2183 The first argument is a control string.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2184 The other arguments are substituted into it to make the result, a string.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2185 It may contain %-sequences meaning to substitute the next argument.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2186 %s means print a string argument. Actually, prints any object, with `princ'.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2187 %d means print as number in decimal (%o octal, %x hex).\n\
12623
903fb74f5b36 (Fformat): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 12622
diff changeset
2188 %e means print a number in exponential notation.\n\
903fb74f5b36 (Fformat): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 12622
diff changeset
2189 %f means print a number in decimal-point notation.\n\
903fb74f5b36 (Fformat): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 12622
diff changeset
2190 %g means print a number in exponential notation\n\
903fb74f5b36 (Fformat): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 12622
diff changeset
2191 or decimal-point notation, whichever uses fewer characters.\n\
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2192 %c means print a number as a single character.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2193 %S means print any object as an s-expression (using prin1).\n\
12623
903fb74f5b36 (Fformat): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 12622
diff changeset
2194 The argument used for %d, %o, %x, %e, %f, %g or %c must be a number.\n\
330
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
2195 Use %% to put a single % into the output.")
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2196 (nargs, args)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2197 int nargs;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2198 register Lisp_Object *args;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2199 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2200 register int n; /* The number of the next arg to substitute */
20826
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2201 register int total; /* An estimate of the final length */
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2202 char *buf, *p;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2203 register unsigned char *format, *end;
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2204 int length, nchars;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2205 /* Nonzero if the output should be a multibyte string,
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2206 which is true if any of the inputs is one. */
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2207 int multibyte = 0;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2208 unsigned char *this_format;
20826
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2209 int longest_format;
20804
14fa73136e64 (CONVERTED_BYTE_SIZE): Fix the logic.
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
2210 Lisp_Object val;
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2211
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2212 extern char *index ();
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2213
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2214 /* It should not be necessary to GCPRO ARGS, because
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2215 the caller in the interpreter should take care of that. */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2216
20826
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2217 /* Try to determine whether the result should be multibyte.
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2218 This is not always right; sometimes the result needs to be multibyte
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2219 because of an object that we will pass through prin1,
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2220 and in that case, we won't know it here. */
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2221 for (n = 0; n < nargs; n++)
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2222 if (STRINGP (args[n]) && STRING_MULTIBYTE (args[n]))
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2223 multibyte = 1;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2224
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2225 CHECK_STRING (args[0], 0);
20826
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2226
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2227 /* If we start out planning a unibyte result,
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2228 and later find it has to be multibyte, we jump back to retry. */
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2229 retry:
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2230
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2231 format = XSTRING (args[0])->data;
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2232 end = format + XSTRING (args[0])->size_byte;
20826
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2233 longest_format = 0;
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2234
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2235 /* Make room in result for all the non-%-codes in the control string. */
20826
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2236 total = 5 + CONVERTED_BYTE_SIZE (multibyte, args[0]);
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2237
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2238 /* Add to TOTAL enough space to hold the converted arguments. */
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2239
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2240 n = 0;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2241 while (format != end)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2242 if (*format++ == '%')
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2243 {
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2244 int minlen, thissize = 0;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2245 unsigned char *this_format_start = format - 1;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2246
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2247 /* Process a numeric arg and skip it. */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2248 minlen = atoi (format);
12831
3917c5d131d3 (Fformat): Limit minlen to avoid stack overflow.
Richard M. Stallman <rms@gnu.org>
parents: 12623
diff changeset
2249 if (minlen < 0)
3917c5d131d3 (Fformat): Limit minlen to avoid stack overflow.
Richard M. Stallman <rms@gnu.org>
parents: 12623
diff changeset
2250 minlen = - minlen;
3917c5d131d3 (Fformat): Limit minlen to avoid stack overflow.
Richard M. Stallman <rms@gnu.org>
parents: 12623
diff changeset
2251
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2252 while ((*format >= '0' && *format <= '9')
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2253 || *format == '-' || *format == ' ' || *format == '.')
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2254 format++;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2255
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2256 if (format - this_format_start + 1 > longest_format)
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2257 longest_format = format - this_format_start + 1;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2258
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2259 if (*format == '%')
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2260 format++;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2261 else if (++n >= nargs)
12831
3917c5d131d3 (Fformat): Limit minlen to avoid stack overflow.
Richard M. Stallman <rms@gnu.org>
parents: 12623
diff changeset
2262 error ("Not enough arguments for format string");
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2263 else if (*format == 'S')
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2264 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2265 /* For `S', prin1 the argument and then treat like a string. */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2266 register Lisp_Object tem;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2267 tem = Fprin1_to_string (args[n], Qnil);
20826
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2268 if (STRING_MULTIBYTE (tem) && ! multibyte)
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2269 {
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2270 multibyte = 1;
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2271 goto retry;
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2272 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2273 args[n] = tem;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2274 goto string;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2275 }
9163
41fe5f636879 (lisp_time_argument, Finsert, Finsert_and_inherit, Finsert_before_markers,
Karl Heuer <kwzh@gnu.org>
parents: 9154
diff changeset
2276 else if (SYMBOLP (args[n]))
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2277 {
9265
e44908d7323b (Fcurrent_time, Fformat): Use new accessor macros instead of calling XSET
Karl Heuer <kwzh@gnu.org>
parents: 9163
diff changeset
2278 XSETSTRING (args[n], XSYMBOL (args[n])->name);
20861
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
2279 if (STRING_MULTIBYTE (args[n]) && ! multibyte)
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
2280 {
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
2281 multibyte = 1;
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
2282 goto retry;
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
2283 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2284 goto string;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2285 }
9163
41fe5f636879 (lisp_time_argument, Finsert, Finsert_and_inherit, Finsert_before_markers,
Karl Heuer <kwzh@gnu.org>
parents: 9154
diff changeset
2286 else if (STRINGP (args[n]))
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2287 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2288 string:
6528
d0f6a386b7cb (Fformat): Validate number and type of arguments.
Karl Heuer <kwzh@gnu.org>
parents: 6206
diff changeset
2289 if (*format != 's' && *format != 'S')
d0f6a386b7cb (Fformat): Validate number and type of arguments.
Karl Heuer <kwzh@gnu.org>
parents: 6206
diff changeset
2290 error ("format specifier doesn't match argument type");
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2291 thissize = CONVERTED_BYTE_SIZE (multibyte, args[n]);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2292 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2293 /* Would get MPV otherwise, since Lisp_Int's `point' to low memory. */
9163
41fe5f636879 (lisp_time_argument, Finsert, Finsert_and_inherit, Finsert_before_markers,
Karl Heuer <kwzh@gnu.org>
parents: 9154
diff changeset
2294 else if (INTEGERP (args[n]) && *format != 's')
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2295 {
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 577
diff changeset
2296 #ifdef LISP_FLOAT_TYPE
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3522
diff changeset
2297 /* The following loop assumes the Lisp type indicates
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2298 the proper way to pass the argument.
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2299 So make sure we have a flonum if the argument should
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2300 be a double. */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2301 if (*format == 'e' || *format == 'f' || *format == 'g')
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2302 args[n] = Ffloat (args[n]);
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 577
diff changeset
2303 #endif
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2304 thissize = 30;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2305 }
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 577
diff changeset
2306 #ifdef LISP_FLOAT_TYPE
9163
41fe5f636879 (lisp_time_argument, Finsert, Finsert_and_inherit, Finsert_before_markers,
Karl Heuer <kwzh@gnu.org>
parents: 9154
diff changeset
2307 else if (FLOATP (args[n]) && *format != 's')
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2308 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2309 if (! (*format == 'e' || *format == 'f' || *format == 'g'))
18605
0567c4086813 (Fformat): Add second argument in call to Ftruncate.
Richard M. Stallman <rms@gnu.org>
parents: 18511
diff changeset
2310 args[n] = Ftruncate (args[n], Qnil);
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2311 thissize = 60;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2312 }
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 577
diff changeset
2313 #endif
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2314 else
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2315 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2316 /* Anything but a string, convert to a string using princ. */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2317 register Lisp_Object tem;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2318 tem = Fprin1_to_string (args[n], Qt);
20804
14fa73136e64 (CONVERTED_BYTE_SIZE): Fix the logic.
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
2319 if (STRING_MULTIBYTE (tem))
20826
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2320 {
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2321 multibyte = 1;
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2322 goto retry;
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2323 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2324 args[n] = tem;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2325 goto string;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2326 }
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2327
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2328 if (thissize < minlen)
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2329 thissize = minlen;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2330
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2331 total += thissize + 4;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2332 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2333
20826
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2334 /* Now we can no longer jump to retry.
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2335 TOTAL and LONGEST_FORMAT are known for certain. */
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
2336
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2337 this_format = (unsigned char *) alloca (longest_format + 1);
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2338
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2339 /* Allocate the space for the result.
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2340 Note that TOTAL is an overestimate. */
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2341 if (total < 1000)
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2342 buf = (unsigned char *) alloca (total + 1);
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2343 else
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2344 buf = (unsigned char *) xmalloc (total + 1);
4019
0463aae99f4e * editfns.c (Fformat): Since floats occupy two elements in the
Jim Blandy <jimb@redhat.com>
parents: 3776
diff changeset
2345
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2346 p = buf;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2347 nchars = 0;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2348 n = 0;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2349
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2350 /* Scan the format and store result in BUF. */
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2351 format = XSTRING (args[0])->data;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2352 while (format != end)
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2353 {
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2354 if (*format == '%')
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2355 {
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2356 int minlen;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2357 unsigned char *this_format_start = format;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2358
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2359 format++;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2360
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2361 /* Process a numeric arg and skip it. */
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2362 minlen = atoi (format);
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2363 if (minlen < 0)
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2364 minlen = - minlen;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2365
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2366 while ((*format >= '0' && *format <= '9')
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2367 || *format == '-' || *format == ' ' || *format == '.')
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2368 format++;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2369
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2370 if (*format++ == '%')
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2371 {
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2372 *p++ = '%';
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2373 nchars++;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2374 continue;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2375 }
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2376
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2377 ++n;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2378
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2379 if (STRINGP (args[n]))
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2380 {
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2381 int padding, nbytes;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2382
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2383 nbytes = copy_text (XSTRING (args[n])->data, p,
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2384 XSTRING (args[n])->size_byte,
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2385 STRING_MULTIBYTE (args[n]), multibyte);
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2386 p += nbytes;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2387 nchars += XSTRING (args[n])->size;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2388
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2389 /* If spec requires it, pad on right with spaces. */
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2390 padding = minlen - XSTRING (args[n])->size;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2391 while (padding-- > 0)
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2392 {
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2393 *p++ = ' ';
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2394 nchars++;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2395 }
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2396 }
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2397 else if (INTEGERP (args[n]) || FLOATP (args[n]))
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2398 {
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2399 int this_nchars;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2400
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2401 bcopy (this_format_start, this_format,
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2402 format - this_format_start);
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2403 this_format[format - this_format_start] = 0;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2404
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2405 sprintf (p, this_format, XINT (args[n]));
12603
6d033c8501d4 (Fformat): Increment total for size of control string.
Richard M. Stallman <rms@gnu.org>
parents: 12602
diff changeset
2406
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2407 this_nchars = strlen (p);
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2408 p += this_nchars;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2409 nchars += this_nchars;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2410 }
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2411 }
20861
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
2412 else if (STRING_MULTIBYTE (args[0]))
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
2413 {
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
2414 /* Copy a whole multibyte character. */
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
2415 *p++ = *format++;
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
2416 while (! CHAR_HEAD_P (*format)) *p++ = *format++;
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
2417 nchars++;
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
2418 }
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
2419 else if (multibyte)
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2420 {
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2421 /* Convert a single-byte character to multibyte. */
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2422 int len = copy_text (format, p, 1, 0, 1);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2423
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2424 p += len;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2425 format++;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2426 nchars++;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2427 }
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2428 else
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2429 *p++ = *format++, nchars++;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2430 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2431
20804
14fa73136e64 (CONVERTED_BYTE_SIZE): Fix the logic.
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
2432 val = make_multibyte_string (buf, nchars, p - buf);
14fa73136e64 (CONVERTED_BYTE_SIZE): Fix the logic.
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
2433
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2434 /* If we allocated BUF with malloc, free it too. */
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2435 if (total >= 1000)
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2436 xfree (buf);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2437
20804
14fa73136e64 (CONVERTED_BYTE_SIZE): Fix the logic.
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
2438 return val;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2439 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2440
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2441 /* VARARGS 1 */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2442 Lisp_Object
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2443 #ifdef NO_ARG_ARRAY
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2444 format1 (string1, arg0, arg1, arg2, arg3, arg4)
8824
589f82d1bb32 (Fnarrow_to_region, format1): Use EMACS_INT.
Richard M. Stallman <rms@gnu.org>
parents: 8771
diff changeset
2445 EMACS_INT arg0, arg1, arg2, arg3, arg4;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2446 #else
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2447 format1 (string1)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2448 #endif
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2449 char *string1;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2450 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2451 char buf[100];
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2452 #ifdef NO_ARG_ARRAY
8824
589f82d1bb32 (Fnarrow_to_region, format1): Use EMACS_INT.
Richard M. Stallman <rms@gnu.org>
parents: 8771
diff changeset
2453 EMACS_INT args[5];
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2454 args[0] = arg0;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2455 args[1] = arg1;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2456 args[2] = arg2;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2457 args[3] = arg3;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2458 args[4] = arg4;
11912
bb03a720fd58 (format1): Cast arg of doprnt.
Karl Heuer <kwzh@gnu.org>
parents: 11877
diff changeset
2459 doprnt (buf, sizeof buf, string1, (char *)0, 5, args);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2460 #else
11912
bb03a720fd58 (format1): Cast arg of doprnt.
Karl Heuer <kwzh@gnu.org>
parents: 11877
diff changeset
2461 doprnt (buf, sizeof buf, string1, (char *)0, 5, &string1 + 1);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2462 #endif
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2463 return build_string (buf);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2464 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2465
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2466 DEFUN ("char-equal", Fchar_equal, Schar_equal, 2, 2, 0,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2467 "Return t if two characters match, optionally ignoring case.\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2468 Both arguments must be characters (i.e. integers).\n\
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2469 Case is ignored if `case-fold-search' is non-nil in the current buffer.")
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2470 (c1, c2)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2471 register Lisp_Object c1, c2;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2472 {
20688
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
2473 int i1, i2;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2474 CHECK_NUMBER (c1, 0);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2475 CHECK_NUMBER (c2, 1);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2476
20688
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
2477 if (XINT (c1) == XINT (c2))
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2478 return Qt;
20688
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
2479 if (NILP (current_buffer->case_fold_search))
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
2480 return Qnil;
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
2481
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
2482 /* Do these in separate statements,
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
2483 then compare the variables.
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
2484 because of the way DOWNCASE uses temp variables. */
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
2485 i1 = DOWNCASE (XFASTINT (c1));
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
2486 i2 = DOWNCASE (XFASTINT (c2));
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
2487 return (i1 == i2 ? Qt : Qnil);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2488 }
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2489
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2490 /* Transpose the markers in two regions of the current buffer, and
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2491 adjust the ones between them if necessary (i.e.: if the regions
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2492 differ in size).
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2493
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2494 START1, END1 are the character positions of the first region.
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2495 START1_BYTE, END1_BYTE are the byte positions.
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2496 START2, END2 are the character positions of the second region.
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2497 START2_BYTE, END2_BYTE are the byte positions.
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2498
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2499 Traverses the entire marker list of the buffer to do so, adding an
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2500 appropriate amount to some, subtracting from some, and leaving the
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2501 rest untouched. Most of this is copied from adjust_markers in insdel.c.
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2502
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2503 It's the caller's job to ensure that START1 <= END1 <= START2 <= END2. */
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2504
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2505 void
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2506 transpose_markers (start1, end1, start2, end2,
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2507 start1_byte, end1_byte, start2_byte, end2_byte)
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2508 register int start1, end1, start2, end2;
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2509 register int start1_byte, end1_byte, start2_byte, end2_byte;
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2510 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2511 register int amt1, amt1_byte, amt2, amt2_byte, diff, diff_byte, mpos;
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2512 register Lisp_Object marker;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2513
7862
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2514 /* Update point as if it were a marker. */
7519
987ab382275c (Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents: 7506
diff changeset
2515 if (PT < start1)
987ab382275c (Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents: 7506
diff changeset
2516 ;
987ab382275c (Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents: 7506
diff changeset
2517 else if (PT < end1)
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2518 TEMP_SET_PT_BOTH (PT + (end2 - end1),
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2519 PT_BYTE + (end2_byte - end1_byte));
7519
987ab382275c (Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents: 7506
diff changeset
2520 else if (PT < start2)
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2521 TEMP_SET_PT_BOTH (PT + (end2 - start2) - (end1 - start1),
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2522 (PT_BYTE + (end2_byte - start2_byte)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2523 - (end1_byte - start1_byte)));
7519
987ab382275c (Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents: 7506
diff changeset
2524 else if (PT < end2)
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2525 TEMP_SET_PT_BOTH (PT - (start2 - start1),
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2526 PT_BYTE - (start2_byte - start1_byte));
7519
987ab382275c (Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents: 7506
diff changeset
2527
7862
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2528 /* We used to adjust the endpoints here to account for the gap, but that
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2529 isn't good enough. Even if we assume the caller has tried to move the
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2530 gap out of our way, it might still be at start1 exactly, for example;
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2531 and that places it `inside' the interval, for our purposes. The amount
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2532 of adjustment is nontrivial if there's a `denormalized' marker whose
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2533 position is between GPT and GPT + GAP_SIZE, so it's simpler to leave
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2534 the dirty work to Fmarker_position, below. */
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2535
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2536 /* The difference between the region's lengths */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2537 diff = (end2 - start2) - (end1 - start1);
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2538 diff_byte = (end2_byte - start2_byte) - (end1_byte - start1_byte);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2539
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2540 /* For shifting each marker in a region by the length of the other
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2541 region plus the distance between the regions. */
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2542 amt1 = (end2 - start2) + (start2 - end1);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2543 amt2 = (end1 - start1) + (start2 - end1);
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2544 amt1_byte = (end2_byte - start2_byte) + (start2_byte - end1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2545 amt2_byte = (end1_byte - start1_byte) + (start2_byte - end1_byte);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2546
10308
90784ed0416f Use SAVE_MODIFF and BUF_SAVE_MODIFF
Richard M. Stallman <rms@gnu.org>
parents: 9812
diff changeset
2547 for (marker = BUF_MARKERS (current_buffer); !NILP (marker);
7862
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2548 marker = XMARKER (marker)->chain)
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2549 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2550 mpos = marker_byte_position (marker);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2551 if (mpos >= start1_byte && mpos < end2_byte)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2552 {
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2553 if (mpos < end1_byte)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2554 mpos += amt1_byte;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2555 else if (mpos < start2_byte)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2556 mpos += diff_byte;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2557 else
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2558 mpos -= amt2_byte;
20564
4d06099b7e09 (transpose_markers): Update marker's bytepos.
Richard M. Stallman <rms@gnu.org>
parents: 20561
diff changeset
2559 XMARKER (marker)->bytepos = mpos;
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2560 }
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2561 mpos = XMARKER (marker)->charpos;
7862
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2562 if (mpos >= start1 && mpos < end2)
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2563 {
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2564 if (mpos < end1)
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2565 mpos += amt1;
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2566 else if (mpos < start2)
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2567 mpos += diff;
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2568 else
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2569 mpos -= amt2;
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2570 }
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2571 XMARKER (marker)->charpos = mpos;
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2572 }
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2573 }
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2574
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2575 DEFUN ("transpose-regions", Ftranspose_regions, Stranspose_regions, 4, 5, 0,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2576 "Transpose region START1 to END1 with START2 to END2.\n\
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2577 The regions may not be overlapping, because the size of the buffer is\n\
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2578 never changed in a transposition.\n\
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2579 \n\
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2580 Optional fifth arg LEAVE_MARKERS, if non-nil, means don't update\n\
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2581 any markers that happen to be located in the regions.\n\
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2582 \n\
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2583 Transposing beyond buffer boundaries is an error.")
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2584 (startr1, endr1, startr2, endr2, leave_markers)
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2585 Lisp_Object startr1, endr1, startr2, endr2, leave_markers;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2586 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2587 register int start1, end1, start2, end2;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2588 int start1_byte, start2_byte, len1_byte, len2_byte;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2589 int gap, len1, len_mid, len2;
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2590 unsigned char *start1_addr, *start2_addr, *temp;
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2591
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2592 #ifdef USE_TEXT_PROPERTIES
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2593 INTERVAL cur_intv, tmp_interval1, tmp_interval_mid, tmp_interval2;
10308
90784ed0416f Use SAVE_MODIFF and BUF_SAVE_MODIFF
Richard M. Stallman <rms@gnu.org>
parents: 9812
diff changeset
2594 cur_intv = BUF_INTERVALS (current_buffer);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2595 #endif /* USE_TEXT_PROPERTIES */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2596
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2597 validate_region (&startr1, &endr1);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2598 validate_region (&startr2, &endr2);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2599
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2600 start1 = XFASTINT (startr1);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2601 end1 = XFASTINT (endr1);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2602 start2 = XFASTINT (startr2);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2603 end2 = XFASTINT (endr2);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2604 gap = GPT;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2605
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2606 /* Swap the regions if they're reversed. */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2607 if (start2 < end1)
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2608 {
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2609 register int glumph = start1;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2610 start1 = start2;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2611 start2 = glumph;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2612 glumph = end1;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2613 end1 = end2;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2614 end2 = glumph;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2615 }
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2616
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2617 len1 = end1 - start1;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2618 len2 = end2 - start2;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2619
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2620 if (start2 < end1)
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2621 error ("Transposed regions not properly ordered");
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2622 else if (start1 == end1 || start2 == end2)
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2623 error ("Transposed region may not be of length 0");
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2624
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2625 /* The possibilities are:
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2626 1. Adjacent (contiguous) regions, or separate but equal regions
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2627 (no, really equal, in this case!), or
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2628 2. Separate regions of unequal size.
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2629
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2630 The worst case is usually No. 2. It means that (aside from
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2631 potential need for getting the gap out of the way), there also
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2632 needs to be a shifting of the text between the two regions. So
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2633 if they are spread far apart, we are that much slower... sigh. */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2634
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2635 /* It must be pointed out that the really studly thing to do would
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2636 be not to move the gap at all, but to leave it in place and work
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2637 around it if necessary. This would be extremely efficient,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2638 especially considering that people are likely to do
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2639 transpositions near where they are working interactively, which
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2640 is exactly where the gap would be found. However, such code
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2641 would be much harder to write and to read. So, if you are
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2642 reading this comment and are feeling squirrely, by all means have
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2643 a go! I just didn't feel like doing it, so I will simply move
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2644 the gap the minimum distance to get it out of the way, and then
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2645 deal with an unbroken array. */
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2646
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2647 /* Make sure the gap won't interfere, by moving it out of the text
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2648 we will operate on. */
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2649 if (start1 < gap && gap < end2)
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2650 {
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2651 if (gap - start1 < end2 - gap)
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2652 move_gap (start1);
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2653 else
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2654 move_gap (end2);
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2655 }
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2656
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2657 start1_byte = CHAR_TO_BYTE (start1);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2658 start2_byte = CHAR_TO_BYTE (start2);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2659 len1_byte = CHAR_TO_BYTE (end1) - start1_byte;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2660 len2_byte = CHAR_TO_BYTE (end2) - start2_byte;
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2661
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2662 /* Hmmm... how about checking to see if the gap is large
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2663 enough to use as the temporary storage? That would avoid an
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2664 allocation... interesting. Later, don't fool with it now. */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2665
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2666 /* Working without memmove, for portability (sigh), so must be
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2667 careful of overlapping subsections of the array... */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2668
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2669 if (end1 == start2) /* adjacent regions */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2670 {
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2671 modify_region (current_buffer, start1, end2);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2672 record_change (start1, len1 + len2);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2673
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2674 #ifdef USE_TEXT_PROPERTIES
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2675 tmp_interval1 = copy_intervals (cur_intv, start1, len1);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2676 tmp_interval2 = copy_intervals (cur_intv, start2, len2);
18745
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
2677 Fset_text_properties (make_number (start1), make_number (end2),
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
2678 Qnil, Qnil);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2679 #endif /* USE_TEXT_PROPERTIES */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2680
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2681 /* First region smaller than second. */
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2682 if (len1_byte < len2_byte)
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2683 {
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2684 /* We use alloca only if it is small,
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2685 because we want to avoid stack overflow. */
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2686 if (len2_byte > 20000)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2687 temp = (unsigned char *) xmalloc (len2_byte);
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2688 else
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2689 temp = (unsigned char *) alloca (len2_byte);
7862
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2690
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2691 /* Don't precompute these addresses. We have to compute them
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2692 at the last minute, because the relocating allocator might
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2693 have moved the buffer around during the xmalloc. */
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2694 start1_addr = BUF_CHAR_ADDRESS (current_buffer, start1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2695 start2_addr = BUF_CHAR_ADDRESS (current_buffer, start2_byte);
7862
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
2696
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2697 bcopy (start2_addr, temp, len2_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2698 bcopy (start1_addr, start1_addr + len2_byte, len1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2699 bcopy (temp, start1_addr, len2_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2700 if (len2_byte > 20000)
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2701 free (temp);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2702 }
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2703 else
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2704 /* First region not smaller than second. */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2705 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2706 if (len1_byte > 20000)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2707 temp = (unsigned char *) xmalloc (len1_byte);
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2708 else
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2709 temp = (unsigned char *) alloca (len1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2710 start1_addr = BUF_CHAR_ADDRESS (current_buffer, start1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2711 start2_addr = BUF_CHAR_ADDRESS (current_buffer, start2_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2712 bcopy (start1_addr, temp, len1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2713 bcopy (start2_addr, start1_addr, len2_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2714 bcopy (temp, start1_addr + len2_byte, len1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2715 if (len1_byte > 20000)
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2716 free (temp);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2717 }
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2718 #ifdef USE_TEXT_PROPERTIES
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2719 graft_intervals_into_buffer (tmp_interval1, start1 + len2,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2720 len1, current_buffer, 0);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2721 graft_intervals_into_buffer (tmp_interval2, start1,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2722 len2, current_buffer, 0);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2723 #endif /* USE_TEXT_PROPERTIES */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2724 }
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2725 /* Non-adjacent regions, because end1 != start2, bleagh... */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2726 else
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2727 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2728 len_mid = start2_byte - (start1_byte + len1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2729
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2730 if (len1_byte == len2_byte)
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2731 /* Regions are same size, though, how nice. */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2732 {
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2733 modify_region (current_buffer, start1, end1);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2734 modify_region (current_buffer, start2, end2);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2735 record_change (start1, len1);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2736 record_change (start2, len2);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2737 #ifdef USE_TEXT_PROPERTIES
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2738 tmp_interval1 = copy_intervals (cur_intv, start1, len1);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2739 tmp_interval2 = copy_intervals (cur_intv, start2, len2);
18745
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
2740 Fset_text_properties (make_number (start1), make_number (end1),
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
2741 Qnil, Qnil);
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
2742 Fset_text_properties (make_number (start2), make_number (end2),
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
2743 Qnil, Qnil);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2744 #endif /* USE_TEXT_PROPERTIES */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2745
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2746 if (len1_byte > 20000)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2747 temp = (unsigned char *) xmalloc (len1_byte);
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2748 else
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2749 temp = (unsigned char *) alloca (len1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2750 start1_addr = BUF_CHAR_ADDRESS (current_buffer, start1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2751 start2_addr = BUF_CHAR_ADDRESS (current_buffer, start2_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2752 bcopy (start1_addr, temp, len1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2753 bcopy (start2_addr, start1_addr, len2_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2754 bcopy (temp, start2_addr, len1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2755 if (len1_byte > 20000)
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2756 free (temp);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2757 #ifdef USE_TEXT_PROPERTIES
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2758 graft_intervals_into_buffer (tmp_interval1, start2,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2759 len1, current_buffer, 0);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2760 graft_intervals_into_buffer (tmp_interval2, start1,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2761 len2, current_buffer, 0);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2762 #endif /* USE_TEXT_PROPERTIES */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2763 }
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2764
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2765 else if (len1_byte < len2_byte) /* Second region larger than first */
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2766 /* Non-adjacent & unequal size, area between must also be shifted. */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2767 {
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2768 modify_region (current_buffer, start1, end2);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2769 record_change (start1, (end2 - start1));
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2770 #ifdef USE_TEXT_PROPERTIES
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2771 tmp_interval1 = copy_intervals (cur_intv, start1, len1);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2772 tmp_interval_mid = copy_intervals (cur_intv, end1, len_mid);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2773 tmp_interval2 = copy_intervals (cur_intv, start2, len2);
18745
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
2774 Fset_text_properties (make_number (start1), make_number (end2),
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
2775 Qnil, Qnil);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2776 #endif /* USE_TEXT_PROPERTIES */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2777
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2778 /* holds region 2 */
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2779 if (len2_byte > 20000)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2780 temp = (unsigned char *) xmalloc (len2_byte);
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2781 else
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2782 temp = (unsigned char *) alloca (len2_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2783 start1_addr = BUF_CHAR_ADDRESS (current_buffer, start1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2784 start2_addr = BUF_CHAR_ADDRESS (current_buffer, start2_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2785 bcopy (start2_addr, temp, len2_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2786 bcopy (start1_addr, start1_addr + len_mid + len2_byte, len1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2787 safe_bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2788 bcopy (temp, start1_addr, len2_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2789 if (len2_byte > 20000)
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2790 free (temp);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2791 #ifdef USE_TEXT_PROPERTIES
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2792 graft_intervals_into_buffer (tmp_interval1, end2 - len1,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2793 len1, current_buffer, 0);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2794 graft_intervals_into_buffer (tmp_interval_mid, start1 + len2,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2795 len_mid, current_buffer, 0);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2796 graft_intervals_into_buffer (tmp_interval2, start1,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2797 len2, current_buffer, 0);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2798 #endif /* USE_TEXT_PROPERTIES */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2799 }
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2800 else
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2801 /* Second region smaller than first. */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2802 {
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2803 record_change (start1, (end2 - start1));
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2804 modify_region (current_buffer, start1, end2);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2805
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2806 #ifdef USE_TEXT_PROPERTIES
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2807 tmp_interval1 = copy_intervals (cur_intv, start1, len1);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2808 tmp_interval_mid = copy_intervals (cur_intv, end1, len_mid);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2809 tmp_interval2 = copy_intervals (cur_intv, start2, len2);
18745
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
2810 Fset_text_properties (make_number (start1), make_number (end2),
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
2811 Qnil, Qnil);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2812 #endif /* USE_TEXT_PROPERTIES */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2813
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2814 /* holds region 1 */
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2815 if (len1_byte > 20000)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2816 temp = (unsigned char *) xmalloc (len1_byte);
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2817 else
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2818 temp = (unsigned char *) alloca (len1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2819 start1_addr = BUF_CHAR_ADDRESS (current_buffer, start1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2820 start2_addr = BUF_CHAR_ADDRESS (current_buffer, start2_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2821 bcopy (start1_addr, temp, len1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2822 bcopy (start2_addr, start1_addr, len2_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2823 bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2824 bcopy (temp, start1_addr + len2_byte + len_mid, len1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2825 if (len1_byte > 20000)
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
2826 free (temp);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2827 #ifdef USE_TEXT_PROPERTIES
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2828 graft_intervals_into_buffer (tmp_interval1, end2 - len1,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2829 len1, current_buffer, 0);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2830 graft_intervals_into_buffer (tmp_interval_mid, start1 + len2,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2831 len_mid, current_buffer, 0);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2832 graft_intervals_into_buffer (tmp_interval2, start1,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2833 len2, current_buffer, 0);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2834 #endif /* USE_TEXT_PROPERTIES */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2835 }
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2836 }
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2837
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2838 /* When doing multiple transpositions, it might be nice
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2839 to optimize this. Perhaps the markers in any one buffer
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2840 should be organized in some sorted data tree. */
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2841 if (NILP (leave_markers))
7519
987ab382275c (Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents: 7506
diff changeset
2842 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2843 transpose_markers (start1, end1, start2, end2,
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2844 start1_byte, start1_byte + len1_byte,
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2845 start2_byte, start2_byte + len2_byte);
7519
987ab382275c (Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents: 7506
diff changeset
2846 fix_overlays_in_range (start1, end2);
987ab382275c (Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents: 7506
diff changeset
2847 }
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2848
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2849 return Qnil;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2850 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2851
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2852
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2853 void
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2854 syms_of_editfns ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2855 {
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2856 environbuf = 0;
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2857
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2858 Qbuffer_access_fontify_functions
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2859 = intern ("buffer-access-fontify-functions");
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2860 staticpro (&Qbuffer_access_fontify_functions);
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2861
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2862 DEFVAR_LISP ("buffer-access-fontify-functions",
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2863 &Vbuffer_access_fontify_functions,
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2864 "List of functions called by `buffer-substring' to fontify if necessary.\n\
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2865 Each function is called with two arguments which specify the range\n\
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2866 of the buffer being accessed.");
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2867 Vbuffer_access_fontify_functions = Qnil;
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2868
14440
e99b3302c154 (syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents: 14391
diff changeset
2869 {
e99b3302c154 (syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents: 14391
diff changeset
2870 Lisp_Object obuf;
e99b3302c154 (syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents: 14391
diff changeset
2871 extern Lisp_Object Vprin1_to_string_buffer;
e99b3302c154 (syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents: 14391
diff changeset
2872 obuf = Fcurrent_buffer ();
e99b3302c154 (syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents: 14391
diff changeset
2873 /* Do this here, because init_buffer_once is too early--it won't work. */
e99b3302c154 (syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents: 14391
diff changeset
2874 Fset_buffer (Vprin1_to_string_buffer);
e99b3302c154 (syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents: 14391
diff changeset
2875 /* Make sure buffer-access-fontify-functions is nil in this buffer. */
e99b3302c154 (syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents: 14391
diff changeset
2876 Fset (Fmake_local_variable (intern ("buffer-access-fontify-functions")),
e99b3302c154 (syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents: 14391
diff changeset
2877 Qnil);
e99b3302c154 (syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents: 14391
diff changeset
2878 Fset_buffer (obuf);
e99b3302c154 (syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents: 14391
diff changeset
2879 }
e99b3302c154 (syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents: 14391
diff changeset
2880
14220
74d7745bcaa4 sp correction
Simon Marshall <simon@gnu.org>
parents: 14201
diff changeset
2881 DEFVAR_LISP ("buffer-access-fontified-property",
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2882 &Vbuffer_access_fontified_property,
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2883 "Property which (if non-nil) indicates text has been fontified.\n\
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2884 `buffer-substring' need not call the `buffer-access-fontify-functions'\n\
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2885 functions if all the text being accessed has this property.");
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2886 Vbuffer_access_fontified_property = Qnil;
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2887
8771
31b8e48045f3 (syms_of_editfns): Make Vsystem_name and Vuser...name lisp variables again.
Karl Heuer <kwzh@gnu.org>
parents: 8667
diff changeset
2888 DEFVAR_LISP ("system-name", &Vsystem_name,
31b8e48045f3 (syms_of_editfns): Make Vsystem_name and Vuser...name lisp variables again.
Karl Heuer <kwzh@gnu.org>
parents: 8667
diff changeset
2889 "The name of the machine Emacs is running on.");
31b8e48045f3 (syms_of_editfns): Make Vsystem_name and Vuser...name lisp variables again.
Karl Heuer <kwzh@gnu.org>
parents: 8667
diff changeset
2890
31b8e48045f3 (syms_of_editfns): Make Vsystem_name and Vuser...name lisp variables again.
Karl Heuer <kwzh@gnu.org>
parents: 8667
diff changeset
2891 DEFVAR_LISP ("user-full-name", &Vuser_full_name,
31b8e48045f3 (syms_of_editfns): Make Vsystem_name and Vuser...name lisp variables again.
Karl Heuer <kwzh@gnu.org>
parents: 8667
diff changeset
2892 "The full name of the user logged in.");
31b8e48045f3 (syms_of_editfns): Make Vsystem_name and Vuser...name lisp variables again.
Karl Heuer <kwzh@gnu.org>
parents: 8667
diff changeset
2893
12026
505a894d943e (syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents: 11912
diff changeset
2894 DEFVAR_LISP ("user-login-name", &Vuser_login_name,
8771
31b8e48045f3 (syms_of_editfns): Make Vsystem_name and Vuser...name lisp variables again.
Karl Heuer <kwzh@gnu.org>
parents: 8667
diff changeset
2895 "The user's name, taken from environment variables if possible.");
31b8e48045f3 (syms_of_editfns): Make Vsystem_name and Vuser...name lisp variables again.
Karl Heuer <kwzh@gnu.org>
parents: 8667
diff changeset
2896
12026
505a894d943e (syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents: 11912
diff changeset
2897 DEFVAR_LISP ("user-real-login-name", &Vuser_real_login_name,
8771
31b8e48045f3 (syms_of_editfns): Make Vsystem_name and Vuser...name lisp variables again.
Karl Heuer <kwzh@gnu.org>
parents: 8667
diff changeset
2898 "The user's name, based upon the real uid only.");
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2899
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2900 defsubr (&Schar_equal);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2901 defsubr (&Sgoto_char);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2902 defsubr (&Sstring_to_char);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2903 defsubr (&Schar_to_string);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2904 defsubr (&Sbuffer_substring);
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2905 defsubr (&Sbuffer_substring_no_properties);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2906 defsubr (&Sbuffer_string);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2907
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2908 defsubr (&Spoint_marker);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2909 defsubr (&Smark_marker);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2910 defsubr (&Spoint);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2911 defsubr (&Sregion_beginning);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2912 defsubr (&Sregion_end);
20861
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
2913
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
2914 defsubr (&Sline_beginning_position);
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
2915 defsubr (&Sline_end_position);
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
2916
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2917 /* defsubr (&Smark); */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2918 /* defsubr (&Sset_mark); */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2919 defsubr (&Ssave_excursion);
16298
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
2920 defsubr (&Ssave_current_buffer);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2921
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2922 defsubr (&Sbufsize);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2923 defsubr (&Spoint_max);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2924 defsubr (&Spoint_min);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2925 defsubr (&Spoint_min_marker);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2926 defsubr (&Spoint_max_marker);
20861
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
2927 defsubr (&Sposition_bytes);
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
2928
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2929 defsubr (&Sbobp);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2930 defsubr (&Seobp);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2931 defsubr (&Sbolp);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2932 defsubr (&Seolp);
512
b7a1e4e4e7e6 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 488
diff changeset
2933 defsubr (&Sfollowing_char);
b7a1e4e4e7e6 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 488
diff changeset
2934 defsubr (&Sprevious_char);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2935 defsubr (&Schar_after);
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2936 defsubr (&Schar_before);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2937 defsubr (&Sinsert);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2938 defsubr (&Sinsert_before_markers);
4714
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
2939 defsubr (&Sinsert_and_inherit);
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
2940 defsubr (&Sinsert_and_inherit_before_markers);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2941 defsubr (&Sinsert_char);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2942
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2943 defsubr (&Suser_login_name);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2944 defsubr (&Suser_real_login_name);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2945 defsubr (&Suser_uid);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2946 defsubr (&Suser_real_uid);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2947 defsubr (&Suser_full_name);
5373
a70b89d2d6bb (Femacs_pid): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5242
diff changeset
2948 defsubr (&Semacs_pid);
448
129e6320092c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 372
diff changeset
2949 defsubr (&Scurrent_time);
9154
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
2950 defsubr (&Sformat_time_string);
9801
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
2951 defsubr (&Sdecode_time);
11402
66d935214d8e (Fencode_time): Use XINT to examine `zone'.
Richard M. Stallman <rms@gnu.org>
parents: 11263
diff changeset
2952 defsubr (&Sencode_time);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2953 defsubr (&Scurrent_time_string);
962
3533821d6edc * editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents: 690
diff changeset
2954 defsubr (&Scurrent_time_zone);
13019
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
2955 defsubr (&Sset_time_zone_rule);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2956 defsubr (&Ssystem_name);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2957 defsubr (&Smessage);
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2958 defsubr (&Smessage_box);
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2959 defsubr (&Smessage_or_box);
18937
ddb91108a9d2 (Fcurrent_message): New function.
Richard M. Stallman <rms@gnu.org>
parents: 18756
diff changeset
2960 defsubr (&Scurrent_message);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2961 defsubr (&Sformat);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2962
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2963 defsubr (&Sinsert_buffer_substring);
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2964 defsubr (&Scompare_buffer_substrings);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2965 defsubr (&Ssubst_char_in_region);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2966 defsubr (&Stranslate_region);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2967 defsubr (&Sdelete_region);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2968 defsubr (&Swiden);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2969 defsubr (&Snarrow_to_region);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2970 defsubr (&Ssave_restriction);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
2971 defsubr (&Stranspose_regions);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2972 }