Mercurial > emacs
annotate src/editfns.c @ 15757:5ddb082ffebb
(Fdecode_time, difftm): Work even if tm_year represents
negative years; this is possible with 64-bit time_t values.
| author | Richard M. Stallman <rms@gnu.org> |
|---|---|
| date | Tue, 23 Jul 1996 14:00:08 +0000 |
| parents | 07c1581d1cc5 |
| children | 5c12b862950f |
| rev | line source |
|---|---|
| 305 | 1 /* Lisp functions pertaining to editing. |
| 11235 | 2 Copyright (C) 1985,86,87,89,93,94,95 Free Software Foundation, Inc. |
| 305 | 3 |
| 4 This file is part of GNU Emacs. | |
| 5 | |
| 6 GNU Emacs is free software; you can redistribute it and/or modify | |
| 7 it under the terms of the GNU General Public License as published by | |
| 12244 | 8 the Free Software Foundation; either version 2, or (at your option) |
| 305 | 9 any later version. |
| 10 | |
| 11 GNU Emacs is distributed in the hope that it will be useful, | |
| 12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 GNU General Public License for more details. | |
| 15 | |
| 16 You should have received a copy of the GNU General Public License | |
| 17 along with GNU Emacs; see the file COPYING. If not, write to | |
| 14862 | 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 19 Boston, MA 02111-1307, USA. */ | |
| 305 | 20 |
| 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 | 25 |
| 26 #ifdef VMS | |
| 577 | 27 #include "vms-pwd.h" |
| 372 | 28 #else |
| 305 | 29 #include <pwd.h> |
| 372 | 30 #endif |
| 31 | |
| 305 | 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 | 34 #include "buffer.h" |
| 35 #include "window.h" | |
| 36 | |
| 577 | 37 #include "systime.h" |
| 305 | 38 |
| 39 #define min(a, b) ((a) < (b) ? (a) : (b)) | |
| 40 #define max(a, b) ((a) > (b) ? (a) : (b)) | |
| 41 | |
|
13025
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
42 extern char **environ; |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
43 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
|
44 extern void insert_from_buffer (); |
|
9812
bc352c8f079c
(Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents:
9809
diff
changeset
|
45 static long difftm (); |
|
13767
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
46 static void update_buffer_properties (); |
|
14201
ff372902386d
(set_time_zone_rule): No longer static.
Richard M. Stallman <rms@gnu.org>
parents:
14126
diff
changeset
|
47 void set_time_zone_rule (); |
|
13767
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
48 |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
49 Lisp_Object Vbuffer_access_fontify_functions; |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
50 Lisp_Object Qbuffer_access_fontify_functions; |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
51 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
|
52 |
| 305 | 53 /* Some static data, and a function to initialize it for each run */ |
| 54 | |
| 55 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
|
56 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
|
57 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
|
58 Lisp_Object Vuser_login_name; /* user name from LOGNAME or USER */ |
| 305 | 59 |
| 60 void | |
| 61 init_editfns () | |
| 62 { | |
| 330 | 63 char *user_name; |
| 305 | 64 register unsigned char *p, *q, *r; |
| 65 struct passwd *pw; /* password entry for the current user */ | |
| 66 extern char *index (); | |
| 67 Lisp_Object tem; | |
| 68 | |
| 69 /* 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
|
70 init_system_name (); |
| 305 | 71 |
| 72 #ifndef CANNOT_DUMP | |
| 73 /* Don't bother with this on initial start when just dumping out */ | |
| 74 if (!initialized) | |
| 75 return; | |
| 76 #endif /* not CANNOT_DUMP */ | |
| 77 | |
| 78 pw = (struct passwd *) getpwuid (getuid ()); | |
| 9572 | 79 #ifdef MSDOS |
| 80 /* We let the real user name default to "root" because that's quite | |
| 81 accurate on MSDOG and because it lets Emacs find the init file. | |
| 82 (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
|
83 Vuser_real_login_name = build_string (pw ? pw->pw_name : "root"); |
| 9572 | 84 #else |
|
12026
505a894d943e
(syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents:
11912
diff
changeset
|
85 Vuser_real_login_name = build_string (pw ? pw->pw_name : "unknown"); |
| 9572 | 86 #endif |
| 305 | 87 |
| 330 | 88 /* Get the effective user name, by consulting environment variables, |
| 89 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
|
90 user_name = (char *) getenv ("LOGNAME"); |
| 330 | 91 if (!user_name) |
|
9801
7003b5184aec
(init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents:
9657
diff
changeset
|
92 #ifdef WINDOWSNT |
|
7003b5184aec
(init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents:
9657
diff
changeset
|
93 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
|
94 #else /* WINDOWSNT */ |
|
5907
5fdb226fe9a4
(init_editfns): Look at LOGNAME before USER.
Karl Heuer <kwzh@gnu.org>
parents:
5884
diff
changeset
|
95 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
|
96 #endif /* WINDOWSNT */ |
| 305 | 97 if (!user_name) |
| 330 | 98 { |
| 99 pw = (struct passwd *) getpwuid (geteuid ()); | |
| 100 user_name = (char *) (pw ? pw->pw_name : "unknown"); | |
| 101 } | |
|
12026
505a894d943e
(syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents:
11912
diff
changeset
|
102 Vuser_login_name = build_string (user_name); |
| 305 | 103 |
| 330 | 104 /* If the user name claimed in the environment vars differs from |
| 105 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
|
106 tem = Fstring_equal (Vuser_login_name, Vuser_real_login_name); |
| 488 | 107 if (NILP (tem)) |
|
12026
505a894d943e
(syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents:
11912
diff
changeset
|
108 pw = (struct passwd *) getpwnam (XSTRING (Vuser_login_name)->data); |
| 305 | 109 |
| 110 p = (unsigned char *) (pw ? USER_FULL_NAME : "unknown"); | |
| 111 q = (unsigned char *) index (p, ','); | |
| 112 Vuser_full_name = make_string (p, q ? q - p : strlen (p)); | |
| 113 | |
| 114 #ifdef AMPERSAND_FULL_NAME | |
| 115 p = XSTRING (Vuser_full_name)->data; | |
|
11447
d51e912495be
(init_editfns): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
11433
diff
changeset
|
116 q = (unsigned char *) index (p, '&'); |
| 305 | 117 /* Substitute the login name for the &, upcasing the first character. */ |
| 118 if (q) | |
| 119 { | |
|
12026
505a894d943e
(syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents:
11912
diff
changeset
|
120 r = (unsigned char *) alloca (strlen (p) |
|
505a894d943e
(syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents:
11912
diff
changeset
|
121 + XSTRING (Vuser_login_name)->size + 1); |
| 305 | 122 bcopy (p, r, q - p); |
| 123 r[q - p] = 0; | |
|
12026
505a894d943e
(syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents:
11912
diff
changeset
|
124 strcat (r, XSTRING (Vuser_login_name)->data); |
| 305 | 125 r[q - p] = UPCASE (r[q - p]); |
| 126 strcat (r, q + 1); | |
| 127 Vuser_full_name = build_string (r); | |
| 128 } | |
| 129 #endif /* AMPERSAND_FULL_NAME */ | |
|
11135
9ab21ef32537
(init_editfns): Use NAME envvar to init user-full-name.
Richard M. Stallman <rms@gnu.org>
parents:
10480
diff
changeset
|
130 |
|
11447
d51e912495be
(init_editfns): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
11433
diff
changeset
|
131 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
|
132 if (p) |
|
9ab21ef32537
(init_editfns): Use NAME envvar to init user-full-name.
Richard M. Stallman <rms@gnu.org>
parents:
10480
diff
changeset
|
133 Vuser_full_name = build_string (p); |
| 305 | 134 } |
| 135 | |
| 136 DEFUN ("char-to-string", Fchar_to_string, Schar_to_string, 1, 1, 0, | |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
137 "Convert arg CHARACTER to a one-character string containing that character.") |
|
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
138 (character) |
|
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
139 Lisp_Object character; |
| 305 | 140 { |
| 141 char c; | |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
142 CHECK_NUMBER (character, 0); |
| 305 | 143 |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
144 c = XINT (character); |
| 305 | 145 return make_string (&c, 1); |
| 146 } | |
| 147 | |
| 148 DEFUN ("string-to-char", Fstring_to_char, Sstring_to_char, 1, 1, 0, | |
| 149 "Convert arg STRING to a character, the first character of that string.") | |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
150 (string) |
|
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
151 register Lisp_Object string; |
| 305 | 152 { |
| 153 register Lisp_Object val; | |
| 154 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
|
155 CHECK_STRING (string, 0); |
| 305 | 156 |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
157 p = XSTRING (string); |
| 305 | 158 if (p->size) |
|
9305
ac077e2a75f1
(Fstring_to_char, Fpoint, Fbufsize, Fpoint_min, Fpoint_max, Ffollowing_char,
Karl Heuer <kwzh@gnu.org>
parents:
9265
diff
changeset
|
159 XSETFASTINT (val, ((unsigned char *) p->data)[0]); |
| 305 | 160 else |
|
9305
ac077e2a75f1
(Fstring_to_char, Fpoint, Fbufsize, Fpoint_min, Fpoint_max, Ffollowing_char,
Karl Heuer <kwzh@gnu.org>
parents:
9265
diff
changeset
|
161 XSETFASTINT (val, 0); |
| 305 | 162 return val; |
| 163 } | |
| 164 | |
| 165 static Lisp_Object | |
| 166 buildmark (val) | |
| 167 int val; | |
| 168 { | |
| 169 register Lisp_Object mark; | |
| 170 mark = Fmake_marker (); | |
| 171 Fset_marker (mark, make_number (val), Qnil); | |
| 172 return mark; | |
| 173 } | |
| 174 | |
| 175 DEFUN ("point", Fpoint, Spoint, 0, 0, 0, | |
| 176 "Return value of point, as an integer.\n\ | |
| 177 Beginning of buffer is position (point-min)") | |
| 178 () | |
| 179 { | |
| 180 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
|
181 XSETFASTINT (temp, point); |
| 305 | 182 return temp; |
| 183 } | |
| 184 | |
| 185 DEFUN ("point-marker", Fpoint_marker, Spoint_marker, 0, 0, 0, | |
| 186 "Return value of point, as a marker object.") | |
| 187 () | |
| 188 { | |
| 189 return buildmark (point); | |
| 190 } | |
| 191 | |
| 192 int | |
| 193 clip_to_bounds (lower, num, upper) | |
| 194 int lower, num, upper; | |
| 195 { | |
| 196 if (num < lower) | |
| 197 return lower; | |
| 198 else if (num > upper) | |
| 199 return upper; | |
| 200 else | |
| 201 return num; | |
| 202 } | |
| 203 | |
| 204 DEFUN ("goto-char", Fgoto_char, Sgoto_char, 1, 1, "NGoto char: ", | |
| 205 "Set point to POSITION, a number or marker.\n\ | |
| 206 Beginning of buffer is position (point-min), end is (point-max).") | |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
207 (position) |
|
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
208 register Lisp_Object position; |
| 305 | 209 { |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
210 CHECK_NUMBER_COERCE_MARKER (position, 0); |
| 305 | 211 |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
212 SET_PT (clip_to_bounds (BEGV, XINT (position), ZV)); |
|
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
213 return position; |
| 305 | 214 } |
| 215 | |
| 216 static Lisp_Object | |
| 217 region_limit (beginningp) | |
| 218 int beginningp; | |
| 219 { | |
|
4047
e950abdc9ed2
(region_limit): Declare Vmark_even_if_inactive.
Roland McGrath <roland@gnu.org>
parents:
4038
diff
changeset
|
220 extern Lisp_Object Vmark_even_if_inactive; /* Defined in callint.c. */ |
| 305 | 221 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
|
222 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
|
223 && 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
|
224 Fsignal (Qmark_inactive, Qnil); |
| 305 | 225 m = Fmarker_position (current_buffer->mark); |
| 488 | 226 if (NILP (m)) error ("There is no region now"); |
| 305 | 227 if ((point < XFASTINT (m)) == beginningp) |
| 228 return (make_number (point)); | |
| 229 else | |
| 230 return (m); | |
| 231 } | |
| 232 | |
| 233 DEFUN ("region-beginning", Fregion_beginning, Sregion_beginning, 0, 0, 0, | |
| 234 "Return position of beginning of region, as an integer.") | |
| 235 () | |
| 236 { | |
| 237 return (region_limit (1)); | |
| 238 } | |
| 239 | |
| 240 DEFUN ("region-end", Fregion_end, Sregion_end, 0, 0, 0, | |
| 241 "Return position of end of region, as an integer.") | |
| 242 () | |
| 243 { | |
| 244 return (region_limit (0)); | |
| 245 } | |
| 246 | |
| 247 DEFUN ("mark-marker", Fmark_marker, Smark_marker, 0, 0, 0, | |
| 248 "Return this buffer's mark, as a marker object.\n\ | |
| 249 Watch out! Moving this marker changes the mark position.\n\ | |
| 250 If you set the marker not to point anywhere, the buffer will have no mark.") | |
| 251 () | |
| 252 { | |
| 253 return current_buffer->mark; | |
| 254 } | |
| 255 | |
| 256 Lisp_Object | |
| 257 save_excursion_save () | |
| 258 { | |
|
1254
c7e7e3438711
* editfns.c (save_excursion_save, save_excursion_restore):
Jim Blandy <jimb@redhat.com>
parents:
1117
diff
changeset
|
259 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
|
260 == current_buffer); |
| 305 | 261 |
| 262 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
|
263 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
|
264 Fcons (visible ? Qt : Qnil, |
|
a358c97a23e4
(save_excursion_save): Save mark_active of buffer.
Richard M. Stallman <rms@gnu.org>
parents:
1916
diff
changeset
|
265 current_buffer->mark_active))); |
| 305 | 266 } |
| 267 | |
| 268 Lisp_Object | |
| 269 save_excursion_restore (info) | |
|
15075
e8613675066c
(save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents:
15015
diff
changeset
|
270 Lisp_Object info; |
| 305 | 271 { |
|
15075
e8613675066c
(save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents:
15015
diff
changeset
|
272 Lisp_Object tem, tem1, omark, nmark; |
|
e8613675066c
(save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents:
15015
diff
changeset
|
273 struct gcpro gcpro1, gcpro2, gcpro3; |
| 305 | 274 |
| 275 tem = Fmarker_buffer (Fcar (info)); | |
| 276 /* If buffer being returned to is now deleted, avoid error */ | |
| 277 /* Otherwise could get error here while unwinding to top level | |
| 278 and crash */ | |
| 279 /* In that case, Fmarker_buffer returns nil now. */ | |
| 488 | 280 if (NILP (tem)) |
| 305 | 281 return Qnil; |
|
15075
e8613675066c
(save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents:
15015
diff
changeset
|
282 |
|
e8613675066c
(save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents:
15015
diff
changeset
|
283 omark = nmark = Qnil; |
|
e8613675066c
(save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents:
15015
diff
changeset
|
284 GCPRO3 (info, omark, nmark); |
|
e8613675066c
(save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents:
15015
diff
changeset
|
285 |
| 305 | 286 Fset_buffer (tem); |
| 287 tem = Fcar (info); | |
| 288 Fgoto_char (tem); | |
| 289 unchain_marker (tem); | |
| 290 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
|
291 omark = Fmarker_position (current_buffer->mark); |
| 305 | 292 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
|
293 nmark = Fmarker_position (tem); |
| 305 | 294 unchain_marker (tem); |
| 295 tem = Fcdr (Fcdr (info)); | |
|
4420
8113d9ba472e
(save_excursion_restore): Never make the buffer visible.
Richard M. Stallman <rms@gnu.org>
parents:
4358
diff
changeset
|
296 #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
|
297 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
|
298 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
|
299 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
|
300 tem1 = Fcar (tem); |
|
a358c97a23e4
(save_excursion_save): Save mark_active of buffer.
Richard M. Stallman <rms@gnu.org>
parents:
1916
diff
changeset
|
301 if (!NILP (tem1) |
|
1254
c7e7e3438711
* editfns.c (save_excursion_save, save_excursion_restore):
Jim Blandy <jimb@redhat.com>
parents:
1117
diff
changeset
|
302 && current_buffer != XBUFFER (XWINDOW (selected_window)->buffer)) |
| 305 | 303 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
|
304 #endif /* 0 */ |
|
2049
a358c97a23e4
(save_excursion_save): Save mark_active of buffer.
Richard M. Stallman <rms@gnu.org>
parents:
1916
diff
changeset
|
305 |
|
a358c97a23e4
(save_excursion_save): Save mark_active of buffer.
Richard M. Stallman <rms@gnu.org>
parents:
1916
diff
changeset
|
306 tem1 = current_buffer->mark_active; |
|
a358c97a23e4
(save_excursion_save): Save mark_active of buffer.
Richard M. Stallman <rms@gnu.org>
parents:
1916
diff
changeset
|
307 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
|
308 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
|
309 { |
|
7485
a1b7f72e0ea2
(save_excursion_restore): Don't run activate-mark-hook
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
310 /* 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
|
311 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
|
312 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
|
313 { |
|
a1b7f72e0ea2
(save_excursion_restore): Don't run activate-mark-hook
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
314 if (! EQ (omark, nmark)) |
|
a1b7f72e0ea2
(save_excursion_restore): Don't run activate-mark-hook
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
315 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
|
316 } |
|
a1b7f72e0ea2
(save_excursion_restore): Don't run activate-mark-hook
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
317 /* 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
|
318 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
|
319 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
|
320 } |
|
15075
e8613675066c
(save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents:
15015
diff
changeset
|
321 UNGCPRO; |
| 305 | 322 return Qnil; |
| 323 } | |
| 324 | |
| 325 DEFUN ("save-excursion", Fsave_excursion, Ssave_excursion, 0, UNEVALLED, 0, | |
| 326 "Save point, mark, and current buffer; execute BODY; restore those things.\n\ | |
| 327 Executes BODY just like `progn'.\n\ | |
| 328 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
|
329 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
|
330 The state of activation of the mark is also restored.") |
| 305 | 331 (args) |
| 332 Lisp_Object args; | |
| 333 { | |
| 334 register Lisp_Object val; | |
| 335 int count = specpdl_ptr - specpdl; | |
| 336 | |
| 337 record_unwind_protect (save_excursion_restore, save_excursion_save ()); | |
| 338 | |
| 339 val = Fprogn (args); | |
| 340 return unbind_to (count, val); | |
| 341 } | |
| 342 | |
| 343 DEFUN ("buffer-size", Fbufsize, Sbufsize, 0, 0, 0, | |
| 344 "Return the number of characters in the current buffer.") | |
| 345 () | |
| 346 { | |
| 347 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
|
348 XSETFASTINT (temp, Z - BEG); |
| 305 | 349 return temp; |
| 350 } | |
| 351 | |
| 352 DEFUN ("point-min", Fpoint_min, Spoint_min, 0, 0, 0, | |
| 353 "Return the minimum permissible value of point in the current buffer.\n\ | |
| 4943 | 354 This is 1, unless narrowing (a buffer restriction) is in effect.") |
| 305 | 355 () |
| 356 { | |
| 357 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
|
358 XSETFASTINT (temp, BEGV); |
| 305 | 359 return temp; |
| 360 } | |
| 361 | |
| 362 DEFUN ("point-min-marker", Fpoint_min_marker, Spoint_min_marker, 0, 0, 0, | |
| 363 "Return a marker to the minimum permissible value of point in this buffer.\n\ | |
| 4943 | 364 This is the beginning, unless narrowing (a buffer restriction) is in effect.") |
| 305 | 365 () |
| 366 { | |
| 367 return buildmark (BEGV); | |
| 368 } | |
| 369 | |
| 370 DEFUN ("point-max", Fpoint_max, Spoint_max, 0, 0, 0, | |
| 371 "Return the maximum permissible value of point in the current buffer.\n\ | |
| 4943 | 372 This is (1+ (buffer-size)), unless narrowing (a buffer restriction)\n\ |
| 373 is in effect, in which case it is less.") | |
| 305 | 374 () |
| 375 { | |
| 376 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
|
377 XSETFASTINT (temp, ZV); |
| 305 | 378 return temp; |
| 379 } | |
| 380 | |
| 381 DEFUN ("point-max-marker", Fpoint_max_marker, Spoint_max_marker, 0, 0, 0, | |
| 382 "Return a marker to the maximum permissible value of point in this buffer.\n\ | |
| 4943 | 383 This is (1+ (buffer-size)), unless narrowing (a buffer restriction)\n\ |
| 384 is in effect, in which case it is less.") | |
| 305 | 385 () |
| 386 { | |
| 387 return buildmark (ZV); | |
| 388 } | |
| 389 | |
| 512 | 390 DEFUN ("following-char", Ffollowing_char, Sfollowing_char, 0, 0, 0, |
| 391 "Return the character following point, as a number.\n\ | |
| 392 At the end of the buffer or accessible region, return 0.") | |
| 305 | 393 () |
| 394 { | |
| 395 Lisp_Object temp; | |
| 512 | 396 if (point >= ZV) |
|
9305
ac077e2a75f1
(Fstring_to_char, Fpoint, Fbufsize, Fpoint_min, Fpoint_max, Ffollowing_char,
Karl Heuer <kwzh@gnu.org>
parents:
9265
diff
changeset
|
397 XSETFASTINT (temp, 0); |
| 512 | 398 else |
|
9305
ac077e2a75f1
(Fstring_to_char, Fpoint, Fbufsize, Fpoint_min, Fpoint_max, Ffollowing_char,
Karl Heuer <kwzh@gnu.org>
parents:
9265
diff
changeset
|
399 XSETFASTINT (temp, FETCH_CHAR (point)); |
| 305 | 400 return temp; |
| 401 } | |
| 402 | |
| 512 | 403 DEFUN ("preceding-char", Fprevious_char, Sprevious_char, 0, 0, 0, |
| 404 "Return the character preceding point, as a number.\n\ | |
| 405 At the beginning of the buffer or accessible region, return 0.") | |
| 305 | 406 () |
| 407 { | |
| 408 Lisp_Object temp; | |
| 409 if (point <= BEGV) | |
|
9305
ac077e2a75f1
(Fstring_to_char, Fpoint, Fbufsize, Fpoint_min, Fpoint_max, Ffollowing_char,
Karl Heuer <kwzh@gnu.org>
parents:
9265
diff
changeset
|
410 XSETFASTINT (temp, 0); |
| 305 | 411 else |
|
9305
ac077e2a75f1
(Fstring_to_char, Fpoint, Fbufsize, Fpoint_min, Fpoint_max, Ffollowing_char,
Karl Heuer <kwzh@gnu.org>
parents:
9265
diff
changeset
|
412 XSETFASTINT (temp, FETCH_CHAR (point - 1)); |
| 305 | 413 return temp; |
| 414 } | |
| 415 | |
| 416 DEFUN ("bobp", Fbobp, Sbobp, 0, 0, 0, | |
| 417 "Return T if point is at the beginning of the buffer.\n\ | |
| 418 If the buffer is narrowed, this means the beginning of the narrowed part.") | |
| 419 () | |
| 420 { | |
| 421 if (point == BEGV) | |
| 422 return Qt; | |
| 423 return Qnil; | |
| 424 } | |
| 425 | |
| 426 DEFUN ("eobp", Feobp, Seobp, 0, 0, 0, | |
| 427 "Return T if point is at the end of the buffer.\n\ | |
| 428 If the buffer is narrowed, this means the end of the narrowed part.") | |
| 429 () | |
| 430 { | |
| 431 if (point == ZV) | |
| 432 return Qt; | |
| 433 return Qnil; | |
| 434 } | |
| 435 | |
| 436 DEFUN ("bolp", Fbolp, Sbolp, 0, 0, 0, | |
| 437 "Return T if point is at the beginning of a line.") | |
| 438 () | |
| 439 { | |
| 440 if (point == BEGV || FETCH_CHAR (point - 1) == '\n') | |
| 441 return Qt; | |
| 442 return Qnil; | |
| 443 } | |
| 444 | |
| 445 DEFUN ("eolp", Feolp, Seolp, 0, 0, 0, | |
| 446 "Return T if point is at the end of a line.\n\ | |
| 447 `End of a line' includes point being at the end of the buffer.") | |
| 448 () | |
| 449 { | |
| 450 if (point == ZV || FETCH_CHAR (point) == '\n') | |
| 451 return Qt; | |
| 452 return Qnil; | |
| 453 } | |
| 454 | |
| 455 DEFUN ("char-after", Fchar_after, Schar_after, 1, 1, 0, | |
| 456 "Return character in current buffer at position POS.\n\ | |
| 457 POS is an integer or a buffer pointer.\n\ | |
| 458 If POS is out of range, the value is nil.") | |
| 459 (pos) | |
| 460 Lisp_Object pos; | |
| 461 { | |
| 462 register Lisp_Object val; | |
| 463 register int n; | |
| 464 | |
| 465 CHECK_NUMBER_COERCE_MARKER (pos, 0); | |
| 466 | |
| 467 n = XINT (pos); | |
| 468 if (n < BEGV || n >= ZV) return Qnil; | |
| 469 | |
|
9305
ac077e2a75f1
(Fstring_to_char, Fpoint, Fbufsize, Fpoint_min, Fpoint_max, Ffollowing_char,
Karl Heuer <kwzh@gnu.org>
parents:
9265
diff
changeset
|
470 XSETFASTINT (val, FETCH_CHAR (n)); |
| 305 | 471 return val; |
| 472 } | |
| 473 | |
| 9572 | 474 DEFUN ("user-login-name", Fuser_login_name, Suser_login_name, 0, 1, 0, |
| 305 | 475 "Return the name under which the user logged in, as a string.\n\ |
| 476 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
|
477 Also, if the environment variable LOGNAME or USER is set,\n\ |
| 9572 | 478 that determines the value of this function.\n\n\ |
| 479 If optional argument UID is an integer, return the login name of the user\n\ | |
| 480 with that uid, or nil if there is no such user.") | |
| 481 (uid) | |
| 482 Lisp_Object uid; | |
| 305 | 483 { |
| 9572 | 484 struct passwd *pw; |
| 485 | |
|
9520
5187a4159d16
(Fuser_login_name, Fuser_real_login_name):
Richard M. Stallman <rms@gnu.org>
parents:
9305
diff
changeset
|
486 /* 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
|
487 (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
|
488 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
|
489 if (INTEGERP (Vuser_login_name)) |
|
9520
5187a4159d16
(Fuser_login_name, Fuser_real_login_name):
Richard M. Stallman <rms@gnu.org>
parents:
9305
diff
changeset
|
490 init_editfns (); |
| 9572 | 491 |
| 492 if (NILP (uid)) | |
|
12026
505a894d943e
(syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents:
11912
diff
changeset
|
493 return Vuser_login_name; |
| 9572 | 494 |
| 495 CHECK_NUMBER (uid, 0); | |
| 496 pw = (struct passwd *) getpwuid (XINT (uid)); | |
| 497 return (pw ? build_string (pw->pw_name) : Qnil); | |
| 305 | 498 } |
| 499 | |
| 500 DEFUN ("user-real-login-name", Fuser_real_login_name, Suser_real_login_name, | |
| 501 0, 0, 0, | |
| 502 "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
|
503 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
|
504 `user-login-name' when running under `su'.") |
| 305 | 505 () |
| 506 { | |
|
9520
5187a4159d16
(Fuser_login_name, Fuser_real_login_name):
Richard M. Stallman <rms@gnu.org>
parents:
9305
diff
changeset
|
507 /* 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
|
508 (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
|
509 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
|
510 if (INTEGERP (Vuser_login_name)) |
|
9520
5187a4159d16
(Fuser_login_name, Fuser_real_login_name):
Richard M. Stallman <rms@gnu.org>
parents:
9305
diff
changeset
|
511 init_editfns (); |
|
12026
505a894d943e
(syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents:
11912
diff
changeset
|
512 return Vuser_real_login_name; |
| 305 | 513 } |
| 514 | |
| 515 DEFUN ("user-uid", Fuser_uid, Suser_uid, 0, 0, 0, | |
| 516 "Return the effective uid of Emacs, as an integer.") | |
| 517 () | |
| 518 { | |
| 519 return make_number (geteuid ()); | |
| 520 } | |
| 521 | |
| 522 DEFUN ("user-real-uid", Fuser_real_uid, Suser_real_uid, 0, 0, 0, | |
| 523 "Return the real uid of Emacs, as an integer.") | |
| 524 () | |
| 525 { | |
| 526 return make_number (getuid ()); | |
| 527 } | |
| 528 | |
| 529 DEFUN ("user-full-name", Fuser_full_name, Suser_full_name, 0, 0, 0, | |
| 530 "Return the full name of the user logged in, as a string.") | |
| 531 () | |
| 532 { | |
| 533 return Vuser_full_name; | |
| 534 } | |
| 535 | |
| 536 DEFUN ("system-name", Fsystem_name, Ssystem_name, 0, 0, 0, | |
| 537 "Return the name of the machine you are running on, as a string.") | |
| 538 () | |
| 539 { | |
| 540 return Vsystem_name; | |
| 541 } | |
| 542 | |
|
7907
148ad20d6774
(init_editfns): Call init_system_name instead of get_system_name.
Karl Heuer <kwzh@gnu.org>
parents:
7862
diff
changeset
|
543 /* 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
|
544 char * |
|
148ad20d6774
(init_editfns): Call init_system_name instead of get_system_name.
Karl Heuer <kwzh@gnu.org>
parents:
7862
diff
changeset
|
545 get_system_name () |
|
148ad20d6774
(init_editfns): Call init_system_name instead of get_system_name.
Karl Heuer <kwzh@gnu.org>
parents:
7862
diff
changeset
|
546 { |
|
8333
e23908a4fa09
(get_system_name): Add a cast.
Richard M. Stallman <rms@gnu.org>
parents:
7907
diff
changeset
|
547 return (char *) XSTRING (Vsystem_name)->data; |
|
7907
148ad20d6774
(init_editfns): Call init_system_name instead of get_system_name.
Karl Heuer <kwzh@gnu.org>
parents:
7862
diff
changeset
|
548 } |
|
148ad20d6774
(init_editfns): Call init_system_name instead of get_system_name.
Karl Heuer <kwzh@gnu.org>
parents:
7862
diff
changeset
|
549 |
|
5373
a70b89d2d6bb
(Femacs_pid): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5242
diff
changeset
|
550 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
|
551 "Return the process ID of Emacs, as an integer.") |
|
a70b89d2d6bb
(Femacs_pid): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5242
diff
changeset
|
552 () |
|
a70b89d2d6bb
(Femacs_pid): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5242
diff
changeset
|
553 { |
|
a70b89d2d6bb
(Femacs_pid): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5242
diff
changeset
|
554 return make_number (getpid ()); |
|
a70b89d2d6bb
(Femacs_pid): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5242
diff
changeset
|
555 } |
|
a70b89d2d6bb
(Femacs_pid): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5242
diff
changeset
|
556 |
| 448 | 557 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
|
558 "Return the current time, as the number of seconds since 1970-01-01 00:00:00.\n\ |
| 577 | 559 The time is returned as a list of three integers. The first has the\n\ |
| 560 most significant 16 bits of the seconds, while the second has the\n\ | |
| 561 least significant 16 bits. The third integer gives the microsecond\n\ | |
| 562 count.\n\ | |
| 563 \n\ | |
| 564 The microsecond count is zero on systems that do not provide\n\ | |
| 565 resolution finer than a second.") | |
| 448 | 566 () |
| 567 { | |
| 577 | 568 EMACS_TIME t; |
| 569 Lisp_Object result[3]; | |
| 570 | |
| 571 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
|
572 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
|
573 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
|
574 XSETINT (result[2], EMACS_USECS (t)); |
| 577 | 575 |
| 576 return Flist (3, result); | |
| 448 | 577 } |
| 578 | |
| 579 | |
|
2921
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
580 static int |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
581 lisp_time_argument (specified_time, result) |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
582 Lisp_Object specified_time; |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
583 time_t *result; |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
584 { |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
585 if (NILP (specified_time)) |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
586 return time (result) != -1; |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
587 else |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
588 { |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
589 Lisp_Object high, low; |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
590 high = Fcar (specified_time); |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
591 CHECK_NUMBER (high, 0); |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
592 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
|
593 if (CONSP (low)) |
|
2921
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
594 low = Fcar (low); |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
595 CHECK_NUMBER (low, 0); |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
596 *result = (XINT (high) << 16) + (XINT (low) & 0xffff); |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
597 return *result >> 16 == XINT (high); |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
598 } |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
599 } |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
600 |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
601 DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string, 1, 2, 0, |
|
9154
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
602 "Use FORMAT-STRING to format the time TIME.\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
603 TIME is specified as (HIGH LOW . IGNORED) or (HIGH . LOW), as from\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
604 `current-time' and `file-attributes'.\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
605 FORMAT-STRING may contain %-sequences to substitute parts of the time.\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
606 %a is replaced by the abbreviated name of the day of week.\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
607 %A is replaced by the full name of the day of week.\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
608 %b is replaced by the abbreviated name of the month.\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
609 %B is replaced by the full name of the month.\n\ |
|
15241
9304a470dd2d
(Fformat_time_string): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
15180
diff
changeset
|
610 %c stands for the preferred date/time format of the C locale.\n\ |
|
9154
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
611 %d is replaced by the day of month, zero-padded.\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
612 %D is a synonym for \"%m/%d/%y\".\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
613 %e is replaced by the day of month, blank-padded.\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
614 %h is a synonym for \"%b\".\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
615 %H is replaced by the hour (00-23).\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
616 %I is replaced by the hour (00-12).\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
617 %j is replaced by the day of the year (001-366).\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
618 %k is replaced by the hour (0-23), blank padded.\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
619 %l is replaced by the hour (1-12), blank padded.\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
620 %m is replaced by the month (01-12).\n\ |
|
14237
dcb3d2fa5afc
(Fformat_time_string): Don't crash if the resulting string is empty.
Paul Eggert <eggert@twinsun.com>
parents:
14220
diff
changeset
|
621 %M is replaced by the minute (00-59).\n\ |
|
9154
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
622 %n is a synonym for \"\\n\".\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
623 %p is replaced by AM or PM, as appropriate.\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
624 %r is a synonym for \"%I:%M:%S %p\".\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
625 %R is a synonym for \"%H:%M\".\n\ |
|
14237
dcb3d2fa5afc
(Fformat_time_string): Don't crash if the resulting string is empty.
Paul Eggert <eggert@twinsun.com>
parents:
14220
diff
changeset
|
626 %S is replaced by the second (00-60).\n\ |
|
9154
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
627 %t is a synonym for \"\\t\".\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
628 %T is a synonym for \"%H:%M:%S\".\n\ |
|
15004
5e3570680687
(Fformat_time_string): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14862
diff
changeset
|
629 %U is replaced by the week of the year (00-53), first day of week is Sunday.\n\ |
|
9154
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
630 %w is replaced by the day of week (0-6), Sunday is day 0.\n\ |
|
15004
5e3570680687
(Fformat_time_string): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14862
diff
changeset
|
631 %W is replaced by the week of the year (00-53), first day of week is Monday.\n\ |
|
9154
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
632 %x is a locale-specific synonym, which defaults to \"%D\" in the C locale.\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
633 %X is a locale-specific synonym, which defaults to \"%T\" in the C locale.\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
634 %y is replaced by the year without century (00-99).\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
635 %Y is replaced by the year with century.\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
636 %Z is replaced by the time zone abbreviation.\n\ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
637 \n\ |
|
11263
56feeecbb05a
(Fformat): Cast int to pointer by way of EMACS_INT.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
638 The number of options reflects the `strftime' function.") |
|
9154
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
639 (format_string, time) |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
640 Lisp_Object format_string, time; |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
641 { |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
642 time_t value; |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
643 int size; |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
644 |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
645 CHECK_STRING (format_string, 1); |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
646 |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
647 if (! lisp_time_argument (time, &value)) |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
648 error ("Invalid time specification"); |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
649 |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
650 /* This is probably enough. */ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
651 size = XSTRING (format_string)->size * 6 + 50; |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
652 |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
653 while (1) |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
654 { |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
655 char *buf = (char *) alloca (size); |
|
14237
dcb3d2fa5afc
(Fformat_time_string): Don't crash if the resulting string is empty.
Paul Eggert <eggert@twinsun.com>
parents:
14220
diff
changeset
|
656 *buf = 1; |
|
11263
56feeecbb05a
(Fformat): Cast int to pointer by way of EMACS_INT.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
657 if (emacs_strftime (buf, size, XSTRING (format_string)->data, |
|
14237
dcb3d2fa5afc
(Fformat_time_string): Don't crash if the resulting string is empty.
Paul Eggert <eggert@twinsun.com>
parents:
14220
diff
changeset
|
658 localtime (&value)) |
|
dcb3d2fa5afc
(Fformat_time_string): Don't crash if the resulting string is empty.
Paul Eggert <eggert@twinsun.com>
parents:
14220
diff
changeset
|
659 || !*buf) |
|
9154
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
660 return build_string (buf); |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
661 /* If buffer was too small, make it bigger. */ |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
662 size *= 2; |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
663 } |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
664 } |
|
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
665 |
|
9801
7003b5184aec
(init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents:
9657
diff
changeset
|
666 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
|
667 "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
|
668 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
|
669 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
|
670 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
|
671 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
|
672 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
|
673 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
|
674 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
|
675 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
|
676 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
|
677 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
|
678 \(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
|
679 (specified_time) |
|
7003b5184aec
(init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents:
9657
diff
changeset
|
680 Lisp_Object specified_time; |
|
7003b5184aec
(init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents:
9657
diff
changeset
|
681 { |
|
7003b5184aec
(init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents:
9657
diff
changeset
|
682 time_t time_spec; |
|
9812
bc352c8f079c
(Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents:
9809
diff
changeset
|
683 struct tm save_tm; |
|
9801
7003b5184aec
(init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents:
9657
diff
changeset
|
684 struct tm *decoded_time; |
|
7003b5184aec
(init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents:
9657
diff
changeset
|
685 Lisp_Object list_args[9]; |
|
7003b5184aec
(init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents:
9657
diff
changeset
|
686 |
|
7003b5184aec
(init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents:
9657
diff
changeset
|
687 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
|
688 error ("Invalid time specification"); |
|
7003b5184aec
(init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents:
9657
diff
changeset
|
689 |
|
7003b5184aec
(init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents:
9657
diff
changeset
|
690 decoded_time = localtime (&time_spec); |
|
9812
bc352c8f079c
(Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents:
9809
diff
changeset
|
691 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
|
692 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
|
693 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
|
694 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
|
695 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
|
696 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
|
697 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
|
698 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
|
699 |
|
bc352c8f079c
(Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents:
9809
diff
changeset
|
700 /* 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
|
701 save_tm = *decoded_time; |
|
bc352c8f079c
(Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents:
9809
diff
changeset
|
702 decoded_time = gmtime (&time_spec); |
|
bc352c8f079c
(Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents:
9809
diff
changeset
|
703 if (decoded_time == 0) |
|
bc352c8f079c
(Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents:
9809
diff
changeset
|
704 list_args[8] = Qnil; |
|
bc352c8f079c
(Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents:
9809
diff
changeset
|
705 else |
|
bc352c8f079c
(Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents:
9809
diff
changeset
|
706 XSETINT (list_args[8], difftm (&save_tm, decoded_time)); |
|
9801
7003b5184aec
(init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents:
9657
diff
changeset
|
707 return Flist (9, list_args); |
|
7003b5184aec
(init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents:
9657
diff
changeset
|
708 } |
|
7003b5184aec
(init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents:
9657
diff
changeset
|
709 |
|
15180
9a22c72359c1
(Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents:
15075
diff
changeset
|
710 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
|
711 "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
|
712 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
|
713 ZONE defaults to the current time zone rule. This can\n\ |
|
13025
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
714 be a string (as from `set-time-zone-rule'), or it can be a list\n\ |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
715 (as from `current-time-zone') or an integer (as from `decode-time')\n\ |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
716 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
|
717 \n\ |
|
9a22c72359c1
(Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents:
15075
diff
changeset
|
718 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
|
719 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
|
720 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
|
721 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
|
722 \n\ |
|
13025
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
723 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
|
724 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
|
725 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
|
726 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
|
727 (nargs, args) |
|
9a22c72359c1
(Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents:
15075
diff
changeset
|
728 int nargs; |
|
9a22c72359c1
(Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents:
15075
diff
changeset
|
729 register Lisp_Object *args; |
|
11402
66d935214d8e
(Fencode_time): Use XINT to examine `zone'.
Richard M. Stallman <rms@gnu.org>
parents:
11263
diff
changeset
|
730 { |
|
11468
772f49d1969d
(Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents:
11451
diff
changeset
|
731 time_t time; |
|
13025
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
732 struct tm tm; |
|
15180
9a22c72359c1
(Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents:
15075
diff
changeset
|
733 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
|
734 |
|
15180
9a22c72359c1
(Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents:
15075
diff
changeset
|
735 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
|
736 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
|
737 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
|
738 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
|
739 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
|
740 CHECK_NUMBER (args[5], 5); /* year */ |
|
11468
772f49d1969d
(Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents:
11451
diff
changeset
|
741 |
|
15180
9a22c72359c1
(Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents:
15075
diff
changeset
|
742 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
|
743 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
|
744 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
|
745 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
|
746 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
|
747 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
|
748 tm.tm_isdst = -1; |
|
11468
772f49d1969d
(Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents:
11451
diff
changeset
|
749 |
|
13025
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
750 if (CONSP (zone)) |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
751 zone = Fcar (zone); |
|
11468
772f49d1969d
(Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents:
11451
diff
changeset
|
752 if (NILP (zone)) |
|
13025
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
753 time = mktime (&tm); |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
754 else |
|
11468
772f49d1969d
(Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents:
11451
diff
changeset
|
755 { |
|
13025
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
756 char tzbuf[100]; |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
757 char *tzstring; |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
758 char **oldenv = environ, **newenv; |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
759 |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
760 if (STRINGP (zone)) |
|
13347
186d80572f4f
(Fencode_time): Add cast.
Richard M. Stallman <rms@gnu.org>
parents:
13238
diff
changeset
|
761 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
|
762 else if (INTEGERP (zone)) |
|
11468
772f49d1969d
(Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents:
11451
diff
changeset
|
763 { |
|
13025
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
764 int abszone = abs (XINT (zone)); |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
765 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
|
766 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
|
767 tzstring = tzbuf; |
|
11468
772f49d1969d
(Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents:
11451
diff
changeset
|
768 } |
|
13025
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
769 else |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
770 error ("Invalid time zone specification"); |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
771 |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
772 /* 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
|
773 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
|
774 set_time_zone_rule (tzstring); |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
775 |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
776 time = mktime (&tm); |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
777 |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
778 /* Restore TZ to previous value. */ |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
779 newenv = environ; |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
780 environ = oldenv; |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
781 free (newenv); |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
782 #ifdef LOCALTIME_CACHE |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
783 tzset (); |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
784 #endif |
|
11468
772f49d1969d
(Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents:
11451
diff
changeset
|
785 } |
|
11402
66d935214d8e
(Fencode_time): Use XINT to examine `zone'.
Richard M. Stallman <rms@gnu.org>
parents:
11263
diff
changeset
|
786 |
|
13025
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
787 if (time == (time_t) -1) |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
788 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
|
789 |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
790 return make_time (time); |
|
11402
66d935214d8e
(Fencode_time): Use XINT to examine `zone'.
Richard M. Stallman <rms@gnu.org>
parents:
11263
diff
changeset
|
791 } |
|
66d935214d8e
(Fencode_time): Use XINT to examine `zone'.
Richard M. Stallman <rms@gnu.org>
parents:
11263
diff
changeset
|
792 |
|
2154
69c58e548ca5
(Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents:
2049
diff
changeset
|
793 DEFUN ("current-time-string", Fcurrent_time_string, Scurrent_time_string, 0, 1, 0, |
| 305 | 794 "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
|
795 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
|
796 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
|
797 The format is `Sun Sep 16 01:03:52 1973'.\n\ |
|
69c58e548ca5
(Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents:
2049
diff
changeset
|
798 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
|
799 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
|
800 (HIGH . LOW)\n\ |
|
69c58e548ca5
(Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents:
2049
diff
changeset
|
801 or the form:\n\ |
|
69c58e548ca5
(Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents:
2049
diff
changeset
|
802 (HIGH LOW . IGNORED).\n\ |
|
69c58e548ca5
(Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents:
2049
diff
changeset
|
803 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
|
804 and from `file-attributes'.") |
|
69c58e548ca5
(Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents:
2049
diff
changeset
|
805 (specified_time) |
|
69c58e548ca5
(Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents:
2049
diff
changeset
|
806 Lisp_Object specified_time; |
| 305 | 807 { |
|
2921
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
808 time_t value; |
| 305 | 809 char buf[30]; |
|
2154
69c58e548ca5
(Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents:
2049
diff
changeset
|
810 register char *tem; |
|
69c58e548ca5
(Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents:
2049
diff
changeset
|
811 |
|
2921
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
812 if (! lisp_time_argument (specified_time, &value)) |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
813 value = -1; |
|
2154
69c58e548ca5
(Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents:
2049
diff
changeset
|
814 tem = (char *) ctime (&value); |
| 305 | 815 |
| 816 strncpy (buf, tem, 24); | |
| 817 buf[24] = 0; | |
| 818 | |
| 819 return build_string (buf); | |
| 820 } | |
|
962
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
821 |
|
2921
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
822 #define TM_YEAR_ORIGIN 1900 |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
823 |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
824 /* Yield A - B, measured in seconds. */ |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
825 static long |
| 5882 | 826 difftm (a, b) |
|
2921
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
827 struct tm *a, *b; |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
828 { |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
829 int ay = a->tm_year + (TM_YEAR_ORIGIN - 1); |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
830 int by = b->tm_year + (TM_YEAR_ORIGIN - 1); |
|
15757
5ddb082ffebb
(Fdecode_time, difftm): Work even if tm_year represents
Richard M. Stallman <rms@gnu.org>
parents:
15334
diff
changeset
|
831 /* Divide years by 100, rounding towards minus infinity. */ |
|
5ddb082ffebb
(Fdecode_time, difftm): Work even if tm_year represents
Richard M. Stallman <rms@gnu.org>
parents:
15334
diff
changeset
|
832 int ac = ay / 100 - (ay % 100 < 0); |
|
5ddb082ffebb
(Fdecode_time, difftm): Work even if tm_year represents
Richard M. Stallman <rms@gnu.org>
parents:
15334
diff
changeset
|
833 int bc = by / 100 - (by % 100 < 0); |
| 5882 | 834 /* Some compilers can't handle this as a single return statement. */ |
|
7710
36420d9e4b41
(difftm): Don't store a long value into an int variable.
Richard M. Stallman <rms@gnu.org>
parents:
7519
diff
changeset
|
835 long days = ( |
| 5882 | 836 /* difference in day of year */ |
| 837 a->tm_yday - b->tm_yday | |
| 838 /* + intervening leap days */ | |
| 839 + ((ay >> 2) - (by >> 2)) | |
|
15757
5ddb082ffebb
(Fdecode_time, difftm): Work even if tm_year represents
Richard M. Stallman <rms@gnu.org>
parents:
15334
diff
changeset
|
840 - (ac - bc) |
|
5ddb082ffebb
(Fdecode_time, difftm): Work even if tm_year represents
Richard M. Stallman <rms@gnu.org>
parents:
15334
diff
changeset
|
841 + ((ac >> 2) - (bc >> 2)) |
| 5882 | 842 /* + difference in years * 365 */ |
| 843 + (long)(ay-by) * 365 | |
| 844 ); | |
| 845 return (60*(60*(24*days + (a->tm_hour - b->tm_hour)) | |
| 846 + (a->tm_min - b->tm_min)) | |
| 847 + (a->tm_sec - b->tm_sec)); | |
|
2921
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
848 } |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
849 |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
850 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
|
851 "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
|
852 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
|
853 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
|
854 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
|
855 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
|
856 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
|
857 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
|
858 (HIGH . LOW)\n\ |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
859 or the form:\n\ |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
860 (HIGH LOW . IGNORED).\n\ |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
861 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
|
862 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
|
863 \n\ |
|
4a7e1c2a2a9e
* editfns.c (Fcurrent_time_zone): Return a list whose elements are
Jim Blandy <jimb@redhat.com>
parents:
2384
diff
changeset
|
864 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
|
865 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
|
866 the data it can't find.") |
|
2921
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
867 (specified_time) |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
868 Lisp_Object specified_time; |
|
962
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
869 { |
|
2921
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
870 time_t value; |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
871 struct tm *t; |
|
962
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
872 |
|
2921
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
873 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
|
874 && (t = gmtime (&value)) != 0) |
|
2921
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
875 { |
|
2976
6fe71a039fce
(Fcurrent_time_zone): Assign gmt, instead of init.
Richard M. Stallman <rms@gnu.org>
parents:
2962
diff
changeset
|
876 struct tm gmt; |
|
2921
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
877 long offset; |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
878 char *s, buf[6]; |
|
2976
6fe71a039fce
(Fcurrent_time_zone): Assign gmt, instead of init.
Richard M. Stallman <rms@gnu.org>
parents:
2962
diff
changeset
|
879 |
|
6fe71a039fce
(Fcurrent_time_zone): Assign gmt, instead of init.
Richard M. Stallman <rms@gnu.org>
parents:
2962
diff
changeset
|
880 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
|
881 t = localtime (&value); |
|
6fe71a039fce
(Fcurrent_time_zone): Assign gmt, instead of init.
Richard M. Stallman <rms@gnu.org>
parents:
2962
diff
changeset
|
882 offset = difftm (t, &gmt); |
|
2921
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
883 s = 0; |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
884 #ifdef HAVE_TM_ZONE |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
885 if (t->tm_zone) |
|
7506
9fa47d36798a
(Fcurrent_time_zone): Add cast.
Richard M. Stallman <rms@gnu.org>
parents:
7485
diff
changeset
|
886 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
|
887 #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
|
888 #ifdef HAVE_TZNAME |
|
dc9f7a107e28
(Fcurrent_time_zone): Add alternative for !HAVE_TM_ZONE.
Richard M. Stallman <rms@gnu.org>
parents:
2994
diff
changeset
|
889 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
|
890 s = tzname[t->tm_isdst]; |
|
962
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
891 #endif |
|
3522
dc9f7a107e28
(Fcurrent_time_zone): Add alternative for !HAVE_TM_ZONE.
Richard M. Stallman <rms@gnu.org>
parents:
2994
diff
changeset
|
892 #endif /* not HAVE_TM_ZONE */ |
|
2921
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
893 if (!s) |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
894 { |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
895 /* 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
|
896 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
|
897 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
|
898 s = buf; |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
899 } |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
900 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
|
901 } |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
902 else |
|
37503f466755
Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents:
2783
diff
changeset
|
903 return Fmake_list (2, Qnil); |
|
962
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
904 } |
|
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
905 |
|
13767
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
906 /* 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
|
907 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
|
908 has never been called. */ |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
909 static char **environbuf; |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
910 |
|
13019
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
911 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
|
912 "Set the local time zone using TZ, a string specifying a time zone rule.\n\ |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
913 If TZ is nil, use implementation-defined default time zone information.") |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
914 (tz) |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
915 Lisp_Object tz; |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
916 { |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
917 char *tzstring; |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
918 |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
919 if (NILP (tz)) |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
920 tzstring = 0; |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
921 else |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
922 { |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
923 CHECK_STRING (tz, 0); |
|
13347
186d80572f4f
(Fencode_time): Add cast.
Richard M. Stallman <rms@gnu.org>
parents:
13238
diff
changeset
|
924 tzstring = (char *) XSTRING (tz)->data; |
|
13019
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
925 } |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
926 |
|
13025
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
927 set_time_zone_rule (tzstring); |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
928 if (environbuf) |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
929 free (environbuf); |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
930 environbuf = environ; |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
931 |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
932 return Qnil; |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
933 } |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
934 |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
935 /* 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
|
936 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
|
937 responsibility to free. */ |
|
14201
ff372902386d
(set_time_zone_rule): No longer static.
Richard M. Stallman <rms@gnu.org>
parents:
14126
diff
changeset
|
938 void |
|
13025
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
939 set_time_zone_rule (tzstring) |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
940 char *tzstring; |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
941 { |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
942 int envptrs; |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
943 char **from, **to, **newenv; |
|
1eab52043f10
(Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents:
13019
diff
changeset
|
944 |
| 15334 | 945 /* 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
|
946 for (from = environ; *from; from++) |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
947 continue; |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
948 envptrs = from - environ + 2; |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
949 newenv = to = (char **) xmalloc (envptrs * sizeof (char *) |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
950 + (tzstring ? strlen (tzstring) + 4 : 0)); |
| 15334 | 951 |
| 952 /* 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
|
953 if (tzstring) |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
954 { |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
955 char *t = (char *) (to + envptrs); |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
956 strcpy (t, "TZ="); |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
957 strcat (t, tzstring); |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
958 *to++ = t; |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
959 } |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
960 |
| 15334 | 961 /* Copy the old environ vector elements into NEWENV, |
| 962 but don't copy the TZ variable. | |
| 963 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
|
964 for (from = environ; *from; from++) |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
965 if (strncmp (*from, "TZ=", 3) != 0) |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
966 *to++ = *from; |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
967 *to = 0; |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
968 |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
969 environ = newenv; |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
970 |
| 15334 | 971 /* If we do have a TZSTRING, NEWENV points to the vector slot where |
| 972 the TZ variable is stored. If we do not have a TZSTRING, | |
| 973 TO points to the vector slot which has the terminating null. */ | |
| 974 | |
|
13019
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
975 #ifdef LOCALTIME_CACHE |
| 15334 | 976 { |
| 977 /* In SunOS 4.1.3_U1 and 4.1.4, if TZ has a value like | |
| 978 "US/Pacific" that loads a tz file, then changes to a value like | |
| 979 "XXX0" that does not load a tz file, and then changes back to | |
| 980 its original value, the last change is (incorrectly) ignored. | |
| 981 Also, if TZ changes twice in succession to values that do | |
| 982 not load a tz file, tzset can dump core (see Sun bug#1225179). | |
| 983 The following code works around these bugs. */ | |
| 984 | |
| 985 /* These two values are known to load tz files in buggy implementations. | |
| 986 Their values shouldn't matter in non-buggy implementations. */ | |
| 987 char *tz1 = "TZ=GMT0"; | |
| 988 char *tz2 = "TZ=GMT1"; | |
| 989 | |
| 990 if (tzstring) | |
| 991 { | |
| 992 /* Temporarily set TZ to a value that loads a tz file | |
| 993 and that differs from tzstring. */ | |
| 994 char *tz = *newenv; | |
| 995 *newenv = strcmp (tzstring, tz1 + 3) == 0 ? tz2 : tz1; | |
| 996 tzset (); | |
| 997 *newenv = tz; | |
| 998 } | |
| 999 else | |
| 1000 { | |
| 1001 /* The implied tzstring is unknown, so temporarily set TZ to | |
| 1002 two different values that each load a tz file. */ | |
| 1003 *to = tz1; | |
| 1004 to[1] = 0; | |
| 1005 tzset (); | |
| 1006 *to = tz2; | |
| 1007 tzset (); | |
| 1008 *to = 0; | |
| 1009 } | |
| 1010 | |
| 1011 /* Now TZ has the desired value, and tzset can be invoked safely. */ | |
| 1012 } | |
| 1013 | |
|
13019
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
1014 tzset (); |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
1015 #endif |
|
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
1016 } |
| 305 | 1017 |
| 1018 void | |
| 1019 insert1 (arg) | |
| 1020 Lisp_Object arg; | |
| 1021 { | |
| 1022 Finsert (1, &arg); | |
| 1023 } | |
| 1024 | |
| 330 | 1025 |
| 1026 /* Callers passing one argument to Finsert need not gcpro the | |
| 1027 argument "array", since the only element of the array will | |
| 1028 not be used after calling insert or insert_from_string, so | |
| 1029 we don't care if it gets trashed. */ | |
| 1030 | |
| 305 | 1031 DEFUN ("insert", Finsert, Sinsert, 0, MANY, 0, |
| 1032 "Insert the arguments, either strings or characters, at point.\n\ | |
| 1033 Point moves forward so that it ends up after the inserted text.\n\ | |
| 1034 Any other markers at the point of insertion remain before the text.") | |
| 1035 (nargs, args) | |
| 1036 int nargs; | |
| 1037 register Lisp_Object *args; | |
| 1038 { | |
| 1039 register int argnum; | |
| 1040 register Lisp_Object tem; | |
| 1041 char str[1]; | |
| 1042 | |
| 1043 for (argnum = 0; argnum < nargs; argnum++) | |
| 1044 { | |
| 1045 tem = args[argnum]; | |
| 1046 retry: | |
|
9163
41fe5f636879
(lisp_time_argument, Finsert, Finsert_and_inherit, Finsert_before_markers,
Karl Heuer <kwzh@gnu.org>
parents:
9154
diff
changeset
|
1047 if (INTEGERP (tem)) |
| 305 | 1048 { |
| 1049 str[0] = XINT (tem); | |
| 1050 insert (str, 1); | |
| 1051 } | |
|
9163
41fe5f636879
(lisp_time_argument, Finsert, Finsert_and_inherit, Finsert_before_markers,
Karl Heuer <kwzh@gnu.org>
parents:
9154
diff
changeset
|
1052 else if (STRINGP (tem)) |
| 305 | 1053 { |
|
4714
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1054 insert_from_string (tem, 0, XSTRING (tem)->size, 0); |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1055 } |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1056 else |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1057 { |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1058 tem = wrong_type_argument (Qchar_or_string_p, tem); |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1059 goto retry; |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1060 } |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1061 } |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1062 |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1063 return Qnil; |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1064 } |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1065 |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1066 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
|
1067 0, MANY, 0, |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1068 "Insert the arguments at point, inheriting properties from adjoining text.\n\ |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1069 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
|
1070 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
|
1071 (nargs, args) |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1072 int nargs; |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1073 register Lisp_Object *args; |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1074 { |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1075 register int argnum; |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1076 register Lisp_Object tem; |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1077 char str[1]; |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1078 |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1079 for (argnum = 0; argnum < nargs; argnum++) |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1080 { |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1081 tem = args[argnum]; |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1082 retry: |
|
9163
41fe5f636879
(lisp_time_argument, Finsert, Finsert_and_inherit, Finsert_before_markers,
Karl Heuer <kwzh@gnu.org>
parents:
9154
diff
changeset
|
1083 if (INTEGERP (tem)) |
|
4714
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1084 { |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1085 str[0] = XINT (tem); |
|
8667
abd7ff9a94da
(Finsert_and_inherit_before_markers):
Richard M. Stallman <rms@gnu.org>
parents:
8646
diff
changeset
|
1086 insert_and_inherit (str, 1); |
|
4714
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1087 } |
|
9163
41fe5f636879
(lisp_time_argument, Finsert, Finsert_and_inherit, Finsert_before_markers,
Karl Heuer <kwzh@gnu.org>
parents:
9154
diff
changeset
|
1088 else if (STRINGP (tem)) |
|
4714
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1089 { |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1090 insert_from_string (tem, 0, XSTRING (tem)->size, 1); |
| 305 | 1091 } |
| 1092 else | |
| 1093 { | |
| 1094 tem = wrong_type_argument (Qchar_or_string_p, tem); | |
| 1095 goto retry; | |
| 1096 } | |
| 1097 } | |
| 1098 | |
| 1099 return Qnil; | |
| 1100 } | |
| 1101 | |
| 1102 DEFUN ("insert-before-markers", Finsert_before_markers, Sinsert_before_markers, 0, MANY, 0, | |
| 1103 "Insert strings or characters at point, relocating markers after the text.\n\ | |
| 1104 Point moves forward so that it ends up after the inserted text.\n\ | |
| 1105 Any other markers at the point of insertion also end up after the text.") | |
| 1106 (nargs, args) | |
| 1107 int nargs; | |
| 1108 register Lisp_Object *args; | |
| 1109 { | |
| 1110 register int argnum; | |
| 1111 register Lisp_Object tem; | |
| 1112 char str[1]; | |
| 1113 | |
| 1114 for (argnum = 0; argnum < nargs; argnum++) | |
| 1115 { | |
| 1116 tem = args[argnum]; | |
| 1117 retry: | |
|
9163
41fe5f636879
(lisp_time_argument, Finsert, Finsert_and_inherit, Finsert_before_markers,
Karl Heuer <kwzh@gnu.org>
parents:
9154
diff
changeset
|
1118 if (INTEGERP (tem)) |
| 305 | 1119 { |
| 1120 str[0] = XINT (tem); | |
| 1121 insert_before_markers (str, 1); | |
| 1122 } | |
|
9163
41fe5f636879
(lisp_time_argument, Finsert, Finsert_and_inherit, Finsert_before_markers,
Karl Heuer <kwzh@gnu.org>
parents:
9154
diff
changeset
|
1123 else if (STRINGP (tem)) |
| 305 | 1124 { |
|
4714
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1125 insert_from_string_before_markers (tem, 0, XSTRING (tem)->size, 0); |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1126 } |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1127 else |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1128 { |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1129 tem = wrong_type_argument (Qchar_or_string_p, tem); |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1130 goto retry; |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1131 } |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1132 } |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1133 |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1134 return Qnil; |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1135 } |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1136 |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1137 DEFUN ("insert-before-markers-and-inherit", |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1138 Finsert_and_inherit_before_markers, Sinsert_and_inherit_before_markers, |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1139 0, MANY, 0, |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1140 "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
|
1141 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
|
1142 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
|
1143 (nargs, args) |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1144 int nargs; |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1145 register Lisp_Object *args; |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1146 { |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1147 register int argnum; |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1148 register Lisp_Object tem; |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1149 char str[1]; |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1150 |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1151 for (argnum = 0; argnum < nargs; argnum++) |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1152 { |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1153 tem = args[argnum]; |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1154 retry: |
|
9163
41fe5f636879
(lisp_time_argument, Finsert, Finsert_and_inherit, Finsert_before_markers,
Karl Heuer <kwzh@gnu.org>
parents:
9154
diff
changeset
|
1155 if (INTEGERP (tem)) |
|
4714
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1156 { |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1157 str[0] = XINT (tem); |
|
8667
abd7ff9a94da
(Finsert_and_inherit_before_markers):
Richard M. Stallman <rms@gnu.org>
parents:
8646
diff
changeset
|
1158 insert_before_markers_and_inherit (str, 1); |
|
4714
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1159 } |
|
9163
41fe5f636879
(lisp_time_argument, Finsert, Finsert_and_inherit, Finsert_before_markers,
Karl Heuer <kwzh@gnu.org>
parents:
9154
diff
changeset
|
1160 else if (STRINGP (tem)) |
|
4714
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1161 { |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
1162 insert_from_string_before_markers (tem, 0, XSTRING (tem)->size, 1); |
| 305 | 1163 } |
| 1164 else | |
| 1165 { | |
| 1166 tem = wrong_type_argument (Qchar_or_string_p, tem); | |
| 1167 goto retry; | |
| 1168 } | |
| 1169 } | |
| 1170 | |
| 1171 return Qnil; | |
| 1172 } | |
| 1173 | |
|
8646
0f05e3e89f87
(Finsert_char): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
8333
diff
changeset
|
1174 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
|
1175 "Insert COUNT (second arg) copies of CHARACTER (first arg).\n\ |
| 305 | 1176 Point and all 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
|
1177 Both arguments are required.\n\ |
|
0f05e3e89f87
(Finsert_char): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
8333
diff
changeset
|
1178 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
|
1179 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
|
1180 (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
|
1181 Lisp_Object character, count, inherit; |
| 305 | 1182 { |
| 1183 register unsigned char *string; | |
| 1184 register int strlen; | |
| 1185 register int i, n; | |
| 1186 | |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1187 CHECK_NUMBER (character, 0); |
| 305 | 1188 CHECK_NUMBER (count, 1); |
| 1189 | |
| 1190 n = XINT (count); | |
| 1191 if (n <= 0) | |
| 1192 return Qnil; | |
| 1193 strlen = min (n, 256); | |
| 1194 string = (unsigned char *) alloca (strlen); | |
| 1195 for (i = 0; i < strlen; i++) | |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1196 string[i] = XFASTINT (character); |
| 305 | 1197 while (n >= strlen) |
| 1198 { | |
|
8646
0f05e3e89f87
(Finsert_char): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
8333
diff
changeset
|
1199 if (!NILP (inherit)) |
|
0f05e3e89f87
(Finsert_char): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
8333
diff
changeset
|
1200 insert_and_inherit (string, strlen); |
|
0f05e3e89f87
(Finsert_char): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
8333
diff
changeset
|
1201 else |
|
0f05e3e89f87
(Finsert_char): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents:
8333
diff
changeset
|
1202 insert (string, strlen); |
| 305 | 1203 n -= strlen; |
| 1204 } | |
| 1205 if (n > 0) | |
|
10382
9738aad59697
(Finsert_char): Check inherit flag for long strings too.
Karl Heuer <kwzh@gnu.org>
parents:
10308
diff
changeset
|
1206 { |
|
9738aad59697
(Finsert_char): Check inherit flag for long strings too.
Karl Heuer <kwzh@gnu.org>
parents:
10308
diff
changeset
|
1207 if (!NILP (inherit)) |
|
9738aad59697
(Finsert_char): Check inherit flag for long strings too.
Karl Heuer <kwzh@gnu.org>
parents:
10308
diff
changeset
|
1208 insert_and_inherit (string, n); |
|
9738aad59697
(Finsert_char): Check inherit flag for long strings too.
Karl Heuer <kwzh@gnu.org>
parents:
10308
diff
changeset
|
1209 else |
|
9738aad59697
(Finsert_char): Check inherit flag for long strings too.
Karl Heuer <kwzh@gnu.org>
parents:
10308
diff
changeset
|
1210 insert (string, n); |
|
9738aad59697
(Finsert_char): Check inherit flag for long strings too.
Karl Heuer <kwzh@gnu.org>
parents:
10308
diff
changeset
|
1211 } |
| 305 | 1212 return Qnil; |
| 1213 } | |
| 1214 | |
| 1215 | |
| 648 | 1216 /* Making strings from buffer contents. */ |
| 1217 | |
| 1218 /* 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
|
1219 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
|
1220 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
|
1221 have them, if PROPS is nonzero. |
| 648 | 1222 |
| 1223 We don't want to use plain old make_string here, because it calls | |
| 1224 make_uninit_string, which can cause the buffer arena to be | |
| 1225 compacted. make_string has no way of knowing that the data has | |
| 1226 been moved, and thus copies the wrong data into the string. This | |
| 1227 doesn't effect most of the other users of make_string, so it should | |
| 1228 be left as is. But we should use this function when conjuring | |
| 1229 buffer substrings. */ | |
|
1285
d50533e23dff
* editfns.c (make_buffer_string): Call copy_intervals_to_string().
Joseph Arceneaux <jla@gnu.org>
parents:
1254
diff
changeset
|
1230 |
| 648 | 1231 Lisp_Object |
|
13767
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1232 make_buffer_string (start, end, props) |
| 648 | 1233 int start, end; |
|
13767
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1234 int props; |
| 648 | 1235 { |
|
6772
6e53158ad17d
(make_buffer_string): Copy properties whenever we have some
Richard M. Stallman <rms@gnu.org>
parents:
6714
diff
changeset
|
1236 Lisp_Object result, tem, tem1; |
| 648 | 1237 |
| 1238 if (start < GPT && GPT < end) | |
| 1239 move_gap (start); | |
| 1240 | |
| 1241 result = make_uninit_string (end - start); | |
| 1242 bcopy (&FETCH_CHAR (start), XSTRING (result)->data, end - start); | |
| 1243 | |
|
13767
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1244 /* 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
|
1245 #ifdef USE_TEXT_PROPERTIES |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1246 if (props) |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1247 { |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1248 update_buffer_properties (start, end); |
|
5130
ddee29e260d2
(make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents:
4943
diff
changeset
|
1249 |
|
13767
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1250 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
|
1251 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
|
1252 |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1253 if (XINT (tem) != end || !NILP (tem1)) |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1254 copy_intervals_to_string (result, current_buffer, start, end - start); |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1255 } |
|
5130
ddee29e260d2
(make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents:
4943
diff
changeset
|
1256 #endif |
|
1285
d50533e23dff
* editfns.c (make_buffer_string): Call copy_intervals_to_string().
Joseph Arceneaux <jla@gnu.org>
parents:
1254
diff
changeset
|
1257 |
| 648 | 1258 return result; |
| 1259 } | |
| 305 | 1260 |
|
13767
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1261 /* 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
|
1262 in the current buffer, if necessary. */ |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1263 |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1264 static void |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1265 update_buffer_properties (start, end) |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1266 int start, end; |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1267 { |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1268 #ifdef USE_TEXT_PROPERTIES |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1269 /* 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
|
1270 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
|
1271 if (!NILP (Vbuffer_access_fontify_functions)) |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1272 { |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1273 Lisp_Object args[3]; |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1274 Lisp_Object tem; |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1275 |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1276 args[0] = Qbuffer_access_fontify_functions; |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1277 XSETINT (args[1], start); |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1278 XSETINT (args[2], end); |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1279 |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1280 /* 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
|
1281 has already been done. */ |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1282 if (!NILP (Vbuffer_access_fontified_property)) |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1283 { |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1284 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
|
1285 Vbuffer_access_fontified_property, |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1286 Qnil, Qnil); |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1287 if (! NILP (tem)) |
|
14126
edc94b82c3b3
(update_buffer_properties): Delete superfluous &'s.
Karl Heuer <kwzh@gnu.org>
parents:
14071
diff
changeset
|
1288 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
|
1289 } |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1290 else |
|
14126
edc94b82c3b3
(update_buffer_properties): Delete superfluous &'s.
Karl Heuer <kwzh@gnu.org>
parents:
14071
diff
changeset
|
1291 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
|
1292 } |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1293 #endif |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1294 } |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1295 |
| 305 | 1296 DEFUN ("buffer-substring", Fbuffer_substring, Sbuffer_substring, 2, 2, 0, |
| 1297 "Return the contents of part of the current buffer as a string.\n\ | |
| 1298 The two arguments START and END are character positions;\n\ | |
| 1299 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
|
1300 (start, end) |
|
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1301 Lisp_Object start, end; |
| 305 | 1302 { |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1303 register int b, e; |
| 305 | 1304 |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1305 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
|
1306 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
|
1307 e = XINT (end); |
| 305 | 1308 |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1309 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
|
1310 } |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1311 |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1312 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
|
1313 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
|
1314 "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
|
1315 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
|
1316 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
|
1317 (start, end) |
|
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1318 Lisp_Object start, end; |
|
13767
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1319 { |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1320 register int b, e; |
|
13767
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1321 |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1322 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
|
1323 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
|
1324 e = XINT (end); |
|
13767
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1325 |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1326 return make_buffer_string (b, e, 0); |
| 305 | 1327 } |
| 1328 | |
| 1329 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
|
1330 "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
|
1331 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
|
1332 of the buffer.") |
| 305 | 1333 () |
| 1334 { | |
|
13767
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1335 return make_buffer_string (BEGV, ZV, 1); |
| 305 | 1336 } |
| 1337 | |
| 1338 DEFUN ("insert-buffer-substring", Finsert_buffer_substring, Sinsert_buffer_substring, | |
| 1339 1, 3, 0, | |
|
3776
301e2dca5fd7
(Finsert_buffer_substring): Doc fix.
Roland McGrath <roland@gnu.org>
parents:
3591
diff
changeset
|
1340 "Insert before point a substring of the contents of buffer BUFFER.\n\ |
| 305 | 1341 BUFFER may be a buffer or a buffer name.\n\ |
| 1342 Arguments START and END are character numbers specifying the substring.\n\ | |
| 1343 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
|
1344 (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
|
1345 Lisp_Object buf, start, end; |
| 305 | 1346 { |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1347 register int b, e, temp; |
|
13767
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1348 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
|
1349 Lisp_Object buffer; |
| 305 | 1350 |
|
1854
5a18c36181fa
(Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents:
1853
diff
changeset
|
1351 buffer = Fget_buffer (buf); |
|
5a18c36181fa
(Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents:
1853
diff
changeset
|
1352 if (NILP (buffer)) |
|
5a18c36181fa
(Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents:
1853
diff
changeset
|
1353 nsberror (buf); |
|
5a18c36181fa
(Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents:
1853
diff
changeset
|
1354 bp = XBUFFER (buffer); |
| 305 | 1355 |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1356 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
|
1357 b = BUF_BEGV (bp); |
| 305 | 1358 else |
| 1359 { | |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1360 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
|
1361 b = XINT (start); |
| 305 | 1362 } |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1363 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
|
1364 e = BUF_ZV (bp); |
| 305 | 1365 else |
| 1366 { | |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1367 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
|
1368 e = XINT (end); |
| 305 | 1369 } |
| 1370 | |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1371 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
|
1372 temp = b, b = e, e = temp; |
| 305 | 1373 |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1374 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
|
1375 args_out_of_range (start, end); |
| 305 | 1376 |
|
13767
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1377 obuf = current_buffer; |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1378 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
|
1379 update_buffer_properties (b, e); |
|
13767
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1380 set_buffer_internal_1 (obuf); |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
1381 |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1382 insert_from_buffer (bp, b, e - b, 0); |
| 305 | 1383 return Qnil; |
| 1384 } | |
|
1853
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1385 |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1386 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
|
1387 6, 6, 0, |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1388 "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
|
1389 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
|
1390 +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
|
1391 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
|
1392 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
|
1393 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
|
1394 determines whether case is significant or ignored.") |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1395 (buffer1, start1, end1, buffer2, start2, end2) |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1396 Lisp_Object buffer1, start1, end1, buffer2, start2, end2; |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1397 { |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1398 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
|
1399 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
|
1400 register Lisp_Object *trt |
|
1853
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1401 = (!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
|
1402 ? XCHAR_TABLE (current_buffer->case_canon_table)->contents : 0); |
|
1853
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1403 |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1404 /* Find the first buffer and its substring. */ |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1405 |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1406 if (NILP (buffer1)) |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1407 bp1 = current_buffer; |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1408 else |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1409 { |
|
1854
5a18c36181fa
(Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents:
1853
diff
changeset
|
1410 Lisp_Object buf1; |
|
5a18c36181fa
(Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents:
1853
diff
changeset
|
1411 buf1 = Fget_buffer (buffer1); |
|
5a18c36181fa
(Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents:
1853
diff
changeset
|
1412 if (NILP (buf1)) |
|
5a18c36181fa
(Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents:
1853
diff
changeset
|
1413 nsberror (buffer1); |
|
5a18c36181fa
(Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents:
1853
diff
changeset
|
1414 bp1 = XBUFFER (buf1); |
|
1853
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1415 } |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1416 |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1417 if (NILP (start1)) |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1418 begp1 = BUF_BEGV (bp1); |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1419 else |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1420 { |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1421 CHECK_NUMBER_COERCE_MARKER (start1, 1); |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1422 begp1 = XINT (start1); |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1423 } |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1424 if (NILP (end1)) |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1425 endp1 = BUF_ZV (bp1); |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1426 else |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1427 { |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1428 CHECK_NUMBER_COERCE_MARKER (end1, 2); |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1429 endp1 = XINT (end1); |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1430 } |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1431 |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1432 if (begp1 > endp1) |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1433 temp = begp1, begp1 = endp1, endp1 = temp; |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1434 |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1435 if (!(BUF_BEGV (bp1) <= begp1 |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1436 && begp1 <= endp1 |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1437 && endp1 <= BUF_ZV (bp1))) |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1438 args_out_of_range (start1, end1); |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1439 |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1440 /* Likewise for second substring. */ |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1441 |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1442 if (NILP (buffer2)) |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1443 bp2 = current_buffer; |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1444 else |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1445 { |
|
1854
5a18c36181fa
(Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents:
1853
diff
changeset
|
1446 Lisp_Object buf2; |
|
5a18c36181fa
(Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents:
1853
diff
changeset
|
1447 buf2 = Fget_buffer (buffer2); |
|
5a18c36181fa
(Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents:
1853
diff
changeset
|
1448 if (NILP (buf2)) |
|
5a18c36181fa
(Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents:
1853
diff
changeset
|
1449 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
|
1450 bp2 = XBUFFER (buf2); |
|
1853
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1451 } |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1452 |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1453 if (NILP (start2)) |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1454 begp2 = BUF_BEGV (bp2); |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1455 else |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1456 { |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1457 CHECK_NUMBER_COERCE_MARKER (start2, 4); |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1458 begp2 = XINT (start2); |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1459 } |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1460 if (NILP (end2)) |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1461 endp2 = BUF_ZV (bp2); |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1462 else |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1463 { |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1464 CHECK_NUMBER_COERCE_MARKER (end2, 5); |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1465 endp2 = XINT (end2); |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1466 } |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1467 |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1468 if (begp2 > endp2) |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1469 temp = begp2, begp2 = endp2, endp2 = temp; |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1470 |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1471 if (!(BUF_BEGV (bp2) <= begp2 |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1472 && begp2 <= endp2 |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1473 && endp2 <= BUF_ZV (bp2))) |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1474 args_out_of_range (start2, end2); |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1475 |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1476 len1 = endp1 - begp1; |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1477 len2 = endp2 - begp2; |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1478 length = len1; |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1479 if (len2 < length) |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1480 length = len2; |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1481 |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1482 for (i = 0; i < length; i++) |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1483 { |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1484 int c1 = *BUF_CHAR_ADDRESS (bp1, begp1 + i); |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1485 int c2 = *BUF_CHAR_ADDRESS (bp2, begp2 + i); |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1486 if (trt) |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1487 { |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1488 c1 = trt[c1]; |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1489 c2 = trt[c2]; |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1490 } |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1491 if (c1 < c2) |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1492 return make_number (- 1 - i); |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1493 if (c1 > c2) |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1494 return make_number (i + 1); |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1495 } |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1496 |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1497 /* The strings match as far as they go. |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1498 If one is shorter, that one is less. */ |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1499 if (length < len1) |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1500 return make_number (length + 1); |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1501 else if (length < len2) |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1502 return make_number (- length - 1); |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1503 |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1504 /* Same length too => they are equal. */ |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1505 return make_number (0); |
|
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
1506 } |
| 305 | 1507 |
|
10480
fbb254882b9f
(subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10383
diff
changeset
|
1508 static Lisp_Object |
|
fbb254882b9f
(subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10383
diff
changeset
|
1509 subst_char_in_region_unwind (arg) |
|
fbb254882b9f
(subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10383
diff
changeset
|
1510 Lisp_Object arg; |
|
fbb254882b9f
(subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10383
diff
changeset
|
1511 { |
|
fbb254882b9f
(subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10383
diff
changeset
|
1512 return current_buffer->undo_list = arg; |
|
fbb254882b9f
(subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10383
diff
changeset
|
1513 } |
|
fbb254882b9f
(subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10383
diff
changeset
|
1514 |
|
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
|
1515 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
|
1516 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
|
1517 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
|
1518 { |
|
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
|
1519 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
|
1520 } |
|
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
|
1521 |
| 305 | 1522 DEFUN ("subst-char-in-region", Fsubst_char_in_region, |
| 1523 Ssubst_char_in_region, 4, 5, 0, | |
| 1524 "From START to END, replace FROMCHAR with TOCHAR each time it occurs.\n\ | |
| 1525 If optional arg NOUNDO is non-nil, don't record this change for undo\n\ | |
| 1526 and don't mark the buffer as really changed.") | |
| 1527 (start, end, fromchar, tochar, noundo) | |
| 1528 Lisp_Object start, end, fromchar, tochar, noundo; | |
| 1529 { | |
| 1530 register int pos, stop, look; | |
|
5130
ddee29e260d2
(make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents:
4943
diff
changeset
|
1531 int changed = 0; |
|
10480
fbb254882b9f
(subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10383
diff
changeset
|
1532 int count = specpdl_ptr - specpdl; |
| 305 | 1533 |
| 1534 validate_region (&start, &end); | |
| 1535 CHECK_NUMBER (fromchar, 2); | |
| 1536 CHECK_NUMBER (tochar, 3); | |
| 1537 | |
| 1538 pos = XINT (start); | |
| 1539 stop = XINT (end); | |
| 1540 look = XINT (fromchar); | |
| 1541 | |
|
10480
fbb254882b9f
(subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10383
diff
changeset
|
1542 /* 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
|
1543 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
|
1544 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
|
1545 Also inhibit locking the file. */ |
|
10480
fbb254882b9f
(subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10383
diff
changeset
|
1546 if (!NILP (noundo)) |
|
fbb254882b9f
(subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10383
diff
changeset
|
1547 { |
|
fbb254882b9f
(subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10383
diff
changeset
|
1548 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
|
1549 current_buffer->undo_list); |
|
fbb254882b9f
(subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10383
diff
changeset
|
1550 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
|
1551 /* 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
|
1552 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
|
1553 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
|
1554 current_buffer->filename = Qnil; |
|
10480
fbb254882b9f
(subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10383
diff
changeset
|
1555 } |
|
fbb254882b9f
(subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10383
diff
changeset
|
1556 |
| 305 | 1557 while (pos < stop) |
| 1558 { | |
| 1559 if (FETCH_CHAR (pos) == look) | |
| 1560 { | |
|
5130
ddee29e260d2
(make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents:
4943
diff
changeset
|
1561 if (! changed) |
|
ddee29e260d2
(make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents:
4943
diff
changeset
|
1562 { |
|
ddee29e260d2
(make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents:
4943
diff
changeset
|
1563 modify_region (current_buffer, XINT (start), stop); |
|
5242
0e99ea9941e2
(Fmessage): Use message2.
Richard M. Stallman <rms@gnu.org>
parents:
5130
diff
changeset
|
1564 |
|
0e99ea9941e2
(Fmessage): Use message2.
Richard M. Stallman <rms@gnu.org>
parents:
5130
diff
changeset
|
1565 if (! NILP (noundo)) |
|
0e99ea9941e2
(Fmessage): Use message2.
Richard M. Stallman <rms@gnu.org>
parents:
5130
diff
changeset
|
1566 { |
|
10308
90784ed0416f
Use SAVE_MODIFF and BUF_SAVE_MODIFF
Richard M. Stallman <rms@gnu.org>
parents:
9812
diff
changeset
|
1567 if (MODIFF - 1 == SAVE_MODIFF) |
|
90784ed0416f
Use SAVE_MODIFF and BUF_SAVE_MODIFF
Richard M. Stallman <rms@gnu.org>
parents:
9812
diff
changeset
|
1568 SAVE_MODIFF++; |
|
5242
0e99ea9941e2
(Fmessage): Use message2.
Richard M. Stallman <rms@gnu.org>
parents:
5130
diff
changeset
|
1569 if (MODIFF - 1 == current_buffer->auto_save_modified) |
|
0e99ea9941e2
(Fmessage): Use message2.
Richard M. Stallman <rms@gnu.org>
parents:
5130
diff
changeset
|
1570 current_buffer->auto_save_modified++; |
|
0e99ea9941e2
(Fmessage): Use message2.
Richard M. Stallman <rms@gnu.org>
parents:
5130
diff
changeset
|
1571 } |
|
0e99ea9941e2
(Fmessage): Use message2.
Richard M. Stallman <rms@gnu.org>
parents:
5130
diff
changeset
|
1572 |
|
0e99ea9941e2
(Fmessage): Use message2.
Richard M. Stallman <rms@gnu.org>
parents:
5130
diff
changeset
|
1573 changed = 1; |
|
5130
ddee29e260d2
(make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents:
4943
diff
changeset
|
1574 } |
|
ddee29e260d2
(make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents:
4943
diff
changeset
|
1575 |
| 488 | 1576 if (NILP (noundo)) |
| 305 | 1577 record_change (pos, 1); |
| 1578 FETCH_CHAR (pos) = XINT (tochar); | |
| 1579 } | |
| 1580 pos++; | |
| 1581 } | |
| 1582 | |
|
5130
ddee29e260d2
(make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents:
4943
diff
changeset
|
1583 if (changed) |
|
ddee29e260d2
(make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents:
4943
diff
changeset
|
1584 signal_after_change (XINT (start), |
|
ddee29e260d2
(make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents:
4943
diff
changeset
|
1585 stop - XINT (start), stop - XINT (start)); |
|
ddee29e260d2
(make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents:
4943
diff
changeset
|
1586 |
|
10480
fbb254882b9f
(subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10383
diff
changeset
|
1587 unbind_to (count, Qnil); |
| 305 | 1588 return Qnil; |
| 1589 } | |
| 1590 | |
| 1591 DEFUN ("translate-region", Ftranslate_region, Stranslate_region, 3, 3, 0, | |
| 1592 "From START to END, translate characters according to TABLE.\n\ | |
| 1593 TABLE is a string; the Nth character in it is the mapping\n\ | |
| 1594 for the character with code N. Returns the number of characters changed.") | |
| 1595 (start, end, table) | |
| 1596 Lisp_Object start; | |
| 1597 Lisp_Object end; | |
| 1598 register Lisp_Object table; | |
| 1599 { | |
| 1600 register int pos, stop; /* Limits of the region. */ | |
| 1601 register unsigned char *tt; /* Trans table. */ | |
| 1602 register int oc; /* Old character. */ | |
| 1603 register int nc; /* New character. */ | |
| 1604 int cnt; /* Number of changes made. */ | |
| 1605 Lisp_Object z; /* Return. */ | |
| 1606 int size; /* Size of translate table. */ | |
| 1607 | |
| 1608 validate_region (&start, &end); | |
| 1609 CHECK_STRING (table, 2); | |
| 1610 | |
| 1611 size = XSTRING (table)->size; | |
| 1612 tt = XSTRING (table)->data; | |
| 1613 | |
| 1614 pos = XINT (start); | |
| 1615 stop = XINT (end); | |
|
2783
789c11177579
The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents:
2462
diff
changeset
|
1616 modify_region (current_buffer, pos, stop); |
| 305 | 1617 |
| 1618 cnt = 0; | |
| 1619 for (; pos < stop; ++pos) | |
| 1620 { | |
| 1621 oc = FETCH_CHAR (pos); | |
| 1622 if (oc < size) | |
| 1623 { | |
| 1624 nc = tt[oc]; | |
| 1625 if (nc != oc) | |
| 1626 { | |
| 1627 record_change (pos, 1); | |
| 1628 FETCH_CHAR (pos) = nc; | |
| 1629 signal_after_change (pos, 1, 1); | |
| 1630 ++cnt; | |
| 1631 } | |
| 1632 } | |
| 1633 } | |
| 1634 | |
|
9305
ac077e2a75f1
(Fstring_to_char, Fpoint, Fbufsize, Fpoint_min, Fpoint_max, Ffollowing_char,
Karl Heuer <kwzh@gnu.org>
parents:
9265
diff
changeset
|
1635 XSETFASTINT (z, cnt); |
| 305 | 1636 return (z); |
| 1637 } | |
| 1638 | |
| 1639 DEFUN ("delete-region", Fdelete_region, Sdelete_region, 2, 2, "r", | |
| 1640 "Delete the text between point and mark.\n\ | |
| 1641 When called from a program, expects two arguments,\n\ | |
| 1642 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
|
1643 (start, end) |
|
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1644 Lisp_Object start, end; |
| 305 | 1645 { |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1646 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
|
1647 del_range (XINT (start), XINT (end)); |
| 305 | 1648 return Qnil; |
| 1649 } | |
| 1650 | |
| 1651 DEFUN ("widen", Fwiden, Swiden, 0, 0, "", | |
| 1652 "Remove restrictions (narrowing) from current buffer.\n\ | |
| 1653 This allows the buffer's full text to be seen and edited.") | |
| 1654 () | |
| 1655 { | |
| 1656 BEGV = BEG; | |
| 1657 SET_BUF_ZV (current_buffer, Z); | |
|
12489
d0f5c21803e1
(Fwiden): Set clip_changed in current buffer.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
1658 current_buffer->clip_changed = 1; |
| 330 | 1659 /* Changing the buffer bounds invalidates any recorded current column. */ |
| 1660 invalidate_current_column (); | |
| 305 | 1661 return Qnil; |
| 1662 } | |
| 1663 | |
| 1664 DEFUN ("narrow-to-region", Fnarrow_to_region, Snarrow_to_region, 2, 2, "r", | |
| 1665 "Restrict editing in this buffer to the current region.\n\ | |
| 1666 The rest of the text becomes temporarily invisible and untouchable\n\ | |
| 1667 but is not deleted; if you save the buffer in a file, the invisible\n\ | |
| 1668 text is included in the file. \\[widen] makes all visible again.\n\ | |
| 1669 See also `save-restriction'.\n\ | |
| 1670 \n\ | |
| 1671 When calling from a program, pass two arguments; positions (integers\n\ | |
| 1672 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
|
1673 (start, end) |
|
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1674 register Lisp_Object start, end; |
| 305 | 1675 { |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1676 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
|
1677 CHECK_NUMBER_COERCE_MARKER (end, 1); |
| 305 | 1678 |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1679 if (XINT (start) > XINT (end)) |
| 305 | 1680 { |
|
10383
a7fe0fb11314
(Fnarrow_to_region): Swap using temp Lisp_Object, not int.
Karl Heuer <kwzh@gnu.org>
parents:
10382
diff
changeset
|
1681 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
|
1682 tem = start; start = end; end = tem; |
| 305 | 1683 } |
| 1684 | |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1685 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
|
1686 args_out_of_range (start, end); |
| 305 | 1687 |
|
14071
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1688 BEGV = XFASTINT (start); |
|
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1689 SET_BUF_ZV (current_buffer, XFASTINT (end)); |
|
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1690 if (point < XFASTINT (start)) |
|
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1691 SET_PT (XFASTINT (start)); |
|
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1692 if (point > XFASTINT (end)) |
|
59906ecd9b92
(Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents:
13878
diff
changeset
|
1693 SET_PT (XFASTINT (end)); |
|
12489
d0f5c21803e1
(Fwiden): Set clip_changed in current buffer.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
1694 current_buffer->clip_changed = 1; |
| 330 | 1695 /* Changing the buffer bounds invalidates any recorded current column. */ |
| 1696 invalidate_current_column (); | |
| 305 | 1697 return Qnil; |
| 1698 } | |
| 1699 | |
| 1700 Lisp_Object | |
| 1701 save_restriction_save () | |
| 1702 { | |
| 1703 register Lisp_Object bottom, top; | |
| 1704 /* Note: I tried using markers here, but it does not win | |
| 1705 because insertion at the end of the saved region | |
| 1706 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
|
1707 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
|
1708 XSETFASTINT (top, Z - ZV); |
| 305 | 1709 |
| 1710 return Fcons (Fcurrent_buffer (), Fcons (bottom, top)); | |
| 1711 } | |
| 1712 | |
| 1713 Lisp_Object | |
| 1714 save_restriction_restore (data) | |
| 1715 Lisp_Object data; | |
| 1716 { | |
| 1717 register struct buffer *buf; | |
| 1718 register int newhead, newtail; | |
| 1719 register Lisp_Object tem; | |
| 1720 | |
| 1721 buf = XBUFFER (XCONS (data)->car); | |
| 1722 | |
| 1723 data = XCONS (data)->cdr; | |
| 1724 | |
| 1725 tem = XCONS (data)->car; | |
| 1726 newhead = XINT (tem); | |
| 1727 tem = XCONS (data)->cdr; | |
| 1728 newtail = XINT (tem); | |
| 1729 if (newhead + newtail > BUF_Z (buf) - BUF_BEG (buf)) | |
| 1730 { | |
| 1731 newhead = 0; | |
| 1732 newtail = 0; | |
| 1733 } | |
| 1734 BUF_BEGV (buf) = BUF_BEG (buf) + newhead; | |
| 1735 SET_BUF_ZV (buf, BUF_Z (buf) - newtail); | |
|
12489
d0f5c21803e1
(Fwiden): Set clip_changed in current buffer.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
1736 current_buffer->clip_changed = 1; |
| 305 | 1737 |
| 1738 /* If point is outside the new visible range, move it inside. */ | |
| 1739 SET_BUF_PT (buf, | |
| 1740 clip_to_bounds (BUF_BEGV (buf), BUF_PT (buf), BUF_ZV (buf))); | |
| 1741 | |
| 1742 return Qnil; | |
| 1743 } | |
| 1744 | |
| 1745 DEFUN ("save-restriction", Fsave_restriction, Ssave_restriction, 0, UNEVALLED, 0, | |
| 1746 "Execute BODY, saving and restoring current buffer's restrictions.\n\ | |
| 1747 The buffer's restrictions make parts of the beginning and end invisible.\n\ | |
| 1748 \(They are set up with `narrow-to-region' and eliminated with `widen'.)\n\ | |
| 1749 This special form, `save-restriction', saves the current buffer's restrictions\n\ | |
| 1750 when it is entered, and restores them when it is exited.\n\ | |
| 1751 So any `narrow-to-region' within BODY lasts only until the end of the form.\n\ | |
| 1752 The old restrictions settings are restored\n\ | |
| 1753 even in case of abnormal exit (throw or error).\n\ | |
| 1754 \n\ | |
| 1755 The value returned is the value of the last form in BODY.\n\ | |
| 1756 \n\ | |
| 1757 `save-restriction' can get confused if, within the BODY, you widen\n\ | |
| 1758 and then make changes outside the area within the saved restrictions.\n\ | |
| 1759 \n\ | |
| 1760 Note: if you are using both `save-excursion' and `save-restriction',\n\ | |
| 1761 use `save-excursion' outermost:\n\ | |
| 1762 (save-excursion (save-restriction ...))") | |
| 1763 (body) | |
| 1764 Lisp_Object body; | |
| 1765 { | |
| 1766 register Lisp_Object val; | |
| 1767 int count = specpdl_ptr - specpdl; | |
| 1768 | |
| 1769 record_unwind_protect (save_restriction_restore, save_restriction_save ()); | |
| 1770 val = Fprogn (body); | |
| 1771 return unbind_to (count, val); | |
| 1772 } | |
| 1773 | |
|
5884
d02095ea13a5
(Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents:
5882
diff
changeset
|
1774 /* 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
|
1775 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
|
1776 |
|
d02095ea13a5
(Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents:
5882
diff
changeset
|
1777 /* 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
|
1778 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
|
1779 |
| 305 | 1780 DEFUN ("message", Fmessage, Smessage, 1, MANY, 0, |
| 1781 "Print a one-line message at the bottom of the screen.\n\ | |
| 12602 | 1782 The first argument is a format control string, and the rest are data\n\ |
| 1783 to be formatted under control of the string. See `format' for details.\n\ | |
| 1784 \n\ | |
|
1426
67fd35416ba3
* * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents:
1285
diff
changeset
|
1785 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
|
1786 minibuffer contents show.") |
| 305 | 1787 (nargs, args) |
| 1788 int nargs; | |
| 1789 Lisp_Object *args; | |
| 1790 { | |
|
1426
67fd35416ba3
* * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents:
1285
diff
changeset
|
1791 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
|
1792 { |
|
e21c1f3e37cb
* editfns.c (Fmessage): Don't forget to return a value when
Jim Blandy <jimb@redhat.com>
parents:
1854
diff
changeset
|
1793 message (0); |
|
e21c1f3e37cb
* editfns.c (Fmessage): Don't forget to return a value when
Jim Blandy <jimb@redhat.com>
parents:
1854
diff
changeset
|
1794 return Qnil; |
|
e21c1f3e37cb
* editfns.c (Fmessage): Don't forget to return a value when
Jim Blandy <jimb@redhat.com>
parents:
1854
diff
changeset
|
1795 } |
|
1426
67fd35416ba3
* * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents:
1285
diff
changeset
|
1796 else |
|
67fd35416ba3
* * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents:
1285
diff
changeset
|
1797 { |
|
67fd35416ba3
* * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents:
1285
diff
changeset
|
1798 register Lisp_Object val; |
|
67fd35416ba3
* * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents:
1285
diff
changeset
|
1799 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
|
1800 /* 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
|
1801 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
|
1802 { |
|
d02095ea13a5
(Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents:
5882
diff
changeset
|
1803 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
|
1804 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
|
1805 } |
|
d02095ea13a5
(Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents:
5882
diff
changeset
|
1806 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
|
1807 { |
|
d02095ea13a5
(Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents:
5882
diff
changeset
|
1808 message_length = XSTRING (val)->size; |
|
d02095ea13a5
(Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents:
5882
diff
changeset
|
1809 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
|
1810 } |
|
d02095ea13a5
(Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents:
5882
diff
changeset
|
1811 bcopy (XSTRING (val)->data, message_text, XSTRING (val)->size); |
|
d02095ea13a5
(Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents:
5882
diff
changeset
|
1812 message2 (message_text, XSTRING (val)->size); |
|
1426
67fd35416ba3
* * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents:
1285
diff
changeset
|
1813 return val; |
|
67fd35416ba3
* * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents:
1285
diff
changeset
|
1814 } |
| 305 | 1815 } |
| 1816 | |
|
8975
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1817 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
|
1818 "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
|
1819 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
|
1820 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
|
1821 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
|
1822 \n\ |
|
8975
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1823 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
|
1824 minibuffer contents show.") |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1825 (nargs, args) |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1826 int nargs; |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1827 Lisp_Object *args; |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1828 { |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1829 if (NILP (args[0])) |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1830 { |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1831 message (0); |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1832 return Qnil; |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1833 } |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1834 else |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1835 { |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1836 register Lisp_Object val; |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1837 val = Fformat (nargs, args); |
|
13878
2a71500dfb93
(Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents:
13767
diff
changeset
|
1838 #ifdef HAVE_MENUS |
|
8975
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1839 { |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1840 Lisp_Object pane, menu, obj; |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1841 struct gcpro gcpro1; |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1842 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
|
1843 GCPRO1 (pane); |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1844 menu = Fcons (val, pane); |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1845 obj = Fx_popup_dialog (Qt, menu); |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1846 UNGCPRO; |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1847 return val; |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1848 } |
|
13878
2a71500dfb93
(Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents:
13767
diff
changeset
|
1849 #else /* not HAVE_MENUS */ |
|
8975
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1850 /* 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
|
1851 if (! message_text) |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1852 { |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1853 message_text = (char *)xmalloc (80); |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1854 message_length = 80; |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1855 } |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1856 if (XSTRING (val)->size > message_length) |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1857 { |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1858 message_length = XSTRING (val)->size; |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1859 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
|
1860 } |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1861 bcopy (XSTRING (val)->data, message_text, XSTRING (val)->size); |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1862 message2 (message_text, XSTRING (val)->size); |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1863 return val; |
|
13878
2a71500dfb93
(Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents:
13767
diff
changeset
|
1864 #endif /* not HAVE_MENUS */ |
|
8975
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1865 } |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1866 } |
|
13878
2a71500dfb93
(Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents:
13767
diff
changeset
|
1867 #ifdef HAVE_MENUS |
|
8975
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1868 extern Lisp_Object last_nonmenu_event; |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1869 #endif |
|
13878
2a71500dfb93
(Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents:
13767
diff
changeset
|
1870 |
|
8975
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1871 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
|
1872 "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
|
1873 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
|
1874 Otherwise, use the echo area.\n\ |
|
13878
2a71500dfb93
(Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents:
13767
diff
changeset
|
1875 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
|
1876 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
|
1877 \n\ |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1878 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
|
1879 minibuffer contents show.") |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1880 (nargs, args) |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1881 int nargs; |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1882 Lisp_Object *args; |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1883 { |
|
13878
2a71500dfb93
(Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents:
13767
diff
changeset
|
1884 #ifdef HAVE_MENUS |
|
8975
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1885 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
|
1886 return Fmessage_box (nargs, args); |
|
8975
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1887 #endif |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1888 return Fmessage (nargs, args); |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1889 } |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
1890 |
| 305 | 1891 DEFUN ("format", Fformat, Sformat, 1, MANY, 0, |
| 1892 "Format a string out of a control-string and arguments.\n\ | |
| 1893 The first argument is a control string.\n\ | |
| 1894 The other arguments are substituted into it to make the result, a string.\n\ | |
| 1895 It may contain %-sequences meaning to substitute the next argument.\n\ | |
| 1896 %s means print a string argument. Actually, prints any object, with `princ'.\n\ | |
| 1897 %d means print as number in decimal (%o octal, %x hex).\n\ | |
| 12623 | 1898 %e means print a number in exponential notation.\n\ |
| 1899 %f means print a number in decimal-point notation.\n\ | |
| 1900 %g means print a number in exponential notation\n\ | |
| 1901 or decimal-point notation, whichever uses fewer characters.\n\ | |
| 305 | 1902 %c means print a number as a single character.\n\ |
| 1903 %S means print any object as an s-expression (using prin1).\n\ | |
| 12623 | 1904 The argument used for %d, %o, %x, %e, %f, %g or %c must be a number.\n\ |
| 330 | 1905 Use %% to put a single % into the output.") |
| 305 | 1906 (nargs, args) |
| 1907 int nargs; | |
| 1908 register Lisp_Object *args; | |
| 1909 { | |
| 1910 register int n; /* The number of the next arg to substitute */ | |
| 1911 register int total = 5; /* An estimate of the final length */ | |
| 1912 char *buf; | |
| 1913 register unsigned char *format, *end; | |
| 1914 int length; | |
| 1915 extern char *index (); | |
| 1916 /* It should not be necessary to GCPRO ARGS, because | |
| 1917 the caller in the interpreter should take care of that. */ | |
| 1918 | |
| 1919 CHECK_STRING (args[0], 0); | |
| 1920 format = XSTRING (args[0])->data; | |
| 1921 end = format + XSTRING (args[0])->size; | |
| 1922 | |
| 1923 n = 0; | |
| 1924 while (format != end) | |
| 1925 if (*format++ == '%') | |
| 1926 { | |
| 1927 int minlen; | |
| 1928 | |
| 1929 /* Process a numeric arg and skip it. */ | |
| 1930 minlen = atoi (format); | |
|
12831
3917c5d131d3
(Fformat): Limit minlen to avoid stack overflow.
Richard M. Stallman <rms@gnu.org>
parents:
12623
diff
changeset
|
1931 if (minlen < 0) |
|
3917c5d131d3
(Fformat): Limit minlen to avoid stack overflow.
Richard M. Stallman <rms@gnu.org>
parents:
12623
diff
changeset
|
1932 minlen = - minlen; |
|
3917c5d131d3
(Fformat): Limit minlen to avoid stack overflow.
Richard M. Stallman <rms@gnu.org>
parents:
12623
diff
changeset
|
1933 |
| 305 | 1934 while ((*format >= '0' && *format <= '9') |
| 1935 || *format == '-' || *format == ' ' || *format == '.') | |
| 1936 format++; | |
| 1937 | |
| 1938 if (*format == '%') | |
| 1939 format++; | |
| 1940 else if (++n >= nargs) | |
|
12831
3917c5d131d3
(Fformat): Limit minlen to avoid stack overflow.
Richard M. Stallman <rms@gnu.org>
parents:
12623
diff
changeset
|
1941 error ("Not enough arguments for format string"); |
| 305 | 1942 else if (*format == 'S') |
| 1943 { | |
| 1944 /* For `S', prin1 the argument and then treat like a string. */ | |
| 1945 register Lisp_Object tem; | |
| 1946 tem = Fprin1_to_string (args[n], Qnil); | |
| 1947 args[n] = tem; | |
| 1948 goto string; | |
| 1949 } | |
|
9163
41fe5f636879
(lisp_time_argument, Finsert, Finsert_and_inherit, Finsert_before_markers,
Karl Heuer <kwzh@gnu.org>
parents:
9154
diff
changeset
|
1950 else if (SYMBOLP (args[n])) |
| 305 | 1951 { |
|
9265
e44908d7323b
(Fcurrent_time, Fformat): Use new accessor macros instead of calling XSET
Karl Heuer <kwzh@gnu.org>
parents:
9163
diff
changeset
|
1952 XSETSTRING (args[n], XSYMBOL (args[n])->name); |
| 305 | 1953 goto string; |
| 1954 } | |
|
9163
41fe5f636879
(lisp_time_argument, Finsert, Finsert_and_inherit, Finsert_before_markers,
Karl Heuer <kwzh@gnu.org>
parents:
9154
diff
changeset
|
1955 else if (STRINGP (args[n])) |
| 305 | 1956 { |
| 1957 string: | |
|
6528
d0f6a386b7cb
(Fformat): Validate number and type of arguments.
Karl Heuer <kwzh@gnu.org>
parents:
6206
diff
changeset
|
1958 if (*format != 's' && *format != 'S') |
|
d0f6a386b7cb
(Fformat): Validate number and type of arguments.
Karl Heuer <kwzh@gnu.org>
parents:
6206
diff
changeset
|
1959 error ("format specifier doesn't match argument type"); |
| 305 | 1960 total += XSTRING (args[n])->size; |
|
12831
3917c5d131d3
(Fformat): Limit minlen to avoid stack overflow.
Richard M. Stallman <rms@gnu.org>
parents:
12623
diff
changeset
|
1961 /* We have to put an arbitrary limit on minlen |
|
3917c5d131d3
(Fformat): Limit minlen to avoid stack overflow.
Richard M. Stallman <rms@gnu.org>
parents:
12623
diff
changeset
|
1962 since otherwise it could make alloca fail. */ |
|
3917c5d131d3
(Fformat): Limit minlen to avoid stack overflow.
Richard M. Stallman <rms@gnu.org>
parents:
12623
diff
changeset
|
1963 if (minlen < XSTRING (args[n])->size + 1000) |
|
3917c5d131d3
(Fformat): Limit minlen to avoid stack overflow.
Richard M. Stallman <rms@gnu.org>
parents:
12623
diff
changeset
|
1964 total += minlen; |
| 305 | 1965 } |
| 1966 /* 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
|
1967 else if (INTEGERP (args[n]) && *format != 's') |
| 305 | 1968 { |
| 621 | 1969 #ifdef LISP_FLOAT_TYPE |
|
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3522
diff
changeset
|
1970 /* The following loop assumes the Lisp type indicates |
| 305 | 1971 the proper way to pass the argument. |
| 1972 So make sure we have a flonum if the argument should | |
| 1973 be a double. */ | |
| 1974 if (*format == 'e' || *format == 'f' || *format == 'g') | |
| 1975 args[n] = Ffloat (args[n]); | |
| 621 | 1976 #endif |
|
11710
0652683b14e6
(Fencode_time): Rename arg from min to minute.
Richard M. Stallman <rms@gnu.org>
parents:
11477
diff
changeset
|
1977 total += 30; |
|
12831
3917c5d131d3
(Fformat): Limit minlen to avoid stack overflow.
Richard M. Stallman <rms@gnu.org>
parents:
12623
diff
changeset
|
1978 /* We have to put an arbitrary limit on minlen |
|
3917c5d131d3
(Fformat): Limit minlen to avoid stack overflow.
Richard M. Stallman <rms@gnu.org>
parents:
12623
diff
changeset
|
1979 since otherwise it could make alloca fail. */ |
|
3917c5d131d3
(Fformat): Limit minlen to avoid stack overflow.
Richard M. Stallman <rms@gnu.org>
parents:
12623
diff
changeset
|
1980 if (minlen < 1000) |
|
3917c5d131d3
(Fformat): Limit minlen to avoid stack overflow.
Richard M. Stallman <rms@gnu.org>
parents:
12623
diff
changeset
|
1981 total += minlen; |
| 305 | 1982 } |
| 621 | 1983 #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
|
1984 else if (FLOATP (args[n]) && *format != 's') |
| 305 | 1985 { |
| 1986 if (! (*format == 'e' || *format == 'f' || *format == 'g')) | |
| 1987 args[n] = Ftruncate (args[n]); | |
|
11710
0652683b14e6
(Fencode_time): Rename arg from min to minute.
Richard M. Stallman <rms@gnu.org>
parents:
11477
diff
changeset
|
1988 total += 30; |
|
12831
3917c5d131d3
(Fformat): Limit minlen to avoid stack overflow.
Richard M. Stallman <rms@gnu.org>
parents:
12623
diff
changeset
|
1989 /* We have to put an arbitrary limit on minlen |
|
3917c5d131d3
(Fformat): Limit minlen to avoid stack overflow.
Richard M. Stallman <rms@gnu.org>
parents:
12623
diff
changeset
|
1990 since otherwise it could make alloca fail. */ |
|
3917c5d131d3
(Fformat): Limit minlen to avoid stack overflow.
Richard M. Stallman <rms@gnu.org>
parents:
12623
diff
changeset
|
1991 if (minlen < 1000) |
|
3917c5d131d3
(Fformat): Limit minlen to avoid stack overflow.
Richard M. Stallman <rms@gnu.org>
parents:
12623
diff
changeset
|
1992 total += minlen; |
| 305 | 1993 } |
| 621 | 1994 #endif |
| 305 | 1995 else |
| 1996 { | |
| 1997 /* Anything but a string, convert to a string using princ. */ | |
| 1998 register Lisp_Object tem; | |
| 1999 tem = Fprin1_to_string (args[n], Qt); | |
| 2000 args[n] = tem; | |
| 2001 goto string; | |
| 2002 } | |
| 2003 } | |
| 2004 | |
| 2005 { | |
| 2006 register int nstrings = n + 1; | |
|
4019
0463aae99f4e
* editfns.c (Fformat): Since floats occupy two elements in the
Jim Blandy <jimb@redhat.com>
parents:
3776
diff
changeset
|
2007 |
|
0463aae99f4e
* editfns.c (Fformat): Since floats occupy two elements in the
Jim Blandy <jimb@redhat.com>
parents:
3776
diff
changeset
|
2008 /* Allocate twice as many strings as we have %-escapes; floats occupy |
|
0463aae99f4e
* editfns.c (Fformat): Since floats occupy two elements in the
Jim Blandy <jimb@redhat.com>
parents:
3776
diff
changeset
|
2009 two slots, and we're not sure how many of those we have. */ |
| 305 | 2010 register unsigned char **strings |
|
4019
0463aae99f4e
* editfns.c (Fformat): Since floats occupy two elements in the
Jim Blandy <jimb@redhat.com>
parents:
3776
diff
changeset
|
2011 = (unsigned char **) alloca (2 * nstrings * sizeof (unsigned char *)); |
|
0463aae99f4e
* editfns.c (Fformat): Since floats occupy two elements in the
Jim Blandy <jimb@redhat.com>
parents:
3776
diff
changeset
|
2012 int i; |
| 305 | 2013 |
|
4019
0463aae99f4e
* editfns.c (Fformat): Since floats occupy two elements in the
Jim Blandy <jimb@redhat.com>
parents:
3776
diff
changeset
|
2014 i = 0; |
| 305 | 2015 for (n = 0; n < nstrings; n++) |
| 2016 { | |
| 2017 if (n >= nargs) | |
|
4019
0463aae99f4e
* editfns.c (Fformat): Since floats occupy two elements in the
Jim Blandy <jimb@redhat.com>
parents:
3776
diff
changeset
|
2018 strings[i++] = (unsigned char *) ""; |
|
9163
41fe5f636879
(lisp_time_argument, Finsert, Finsert_and_inherit, Finsert_before_markers,
Karl Heuer <kwzh@gnu.org>
parents:
9154
diff
changeset
|
2019 else if (INTEGERP (args[n])) |
| 305 | 2020 /* We checked above that the corresponding format effector |
| 2021 isn't %s, which would cause MPV. */ | |
|
4019
0463aae99f4e
* editfns.c (Fformat): Since floats occupy two elements in the
Jim Blandy <jimb@redhat.com>
parents:
3776
diff
changeset
|
2022 strings[i++] = (unsigned char *) XINT (args[n]); |
| 621 | 2023 #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
|
2024 else if (FLOATP (args[n])) |
| 305 | 2025 { |
|
11877
1c98f33055fa
(Fformat): Split double into two pointers, not two ints.
Karl Heuer <kwzh@gnu.org>
parents:
11711
diff
changeset
|
2026 union { double d; char *half[2]; } u; |
| 305 | 2027 |
| 2028 u.d = XFLOAT (args[n])->data; | |
|
11877
1c98f33055fa
(Fformat): Split double into two pointers, not two ints.
Karl Heuer <kwzh@gnu.org>
parents:
11711
diff
changeset
|
2029 strings[i++] = (unsigned char *) u.half[0]; |
|
1c98f33055fa
(Fformat): Split double into two pointers, not two ints.
Karl Heuer <kwzh@gnu.org>
parents:
11711
diff
changeset
|
2030 strings[i++] = (unsigned char *) u.half[1]; |
| 305 | 2031 } |
| 621 | 2032 #endif |
|
13450
9a1e7191803f
(Fformat): Use doprnt_lisp.
Richard M. Stallman <rms@gnu.org>
parents:
13347
diff
changeset
|
2033 else if (i == 0) |
|
9a1e7191803f
(Fformat): Use doprnt_lisp.
Richard M. Stallman <rms@gnu.org>
parents:
13347
diff
changeset
|
2034 /* The first string is treated differently |
|
9a1e7191803f
(Fformat): Use doprnt_lisp.
Richard M. Stallman <rms@gnu.org>
parents:
13347
diff
changeset
|
2035 because it is the format string. */ |
|
9a1e7191803f
(Fformat): Use doprnt_lisp.
Richard M. Stallman <rms@gnu.org>
parents:
13347
diff
changeset
|
2036 strings[i++] = XSTRING (args[n])->data; |
| 305 | 2037 else |
|
13450
9a1e7191803f
(Fformat): Use doprnt_lisp.
Richard M. Stallman <rms@gnu.org>
parents:
13347
diff
changeset
|
2038 strings[i++] = (unsigned char *) XFASTINT (args[n]); |
| 305 | 2039 } |
| 2040 | |
|
12603
6d033c8501d4
(Fformat): Increment total for size of control string.
Richard M. Stallman <rms@gnu.org>
parents:
12602
diff
changeset
|
2041 /* Make room in result for all the non-%-codes in the control string. */ |
|
6d033c8501d4
(Fformat): Increment total for size of control string.
Richard M. Stallman <rms@gnu.org>
parents:
12602
diff
changeset
|
2042 total += XSTRING (args[0])->size; |
|
6d033c8501d4
(Fformat): Increment total for size of control string.
Richard M. Stallman <rms@gnu.org>
parents:
12602
diff
changeset
|
2043 |
| 305 | 2044 /* Format it in bigger and bigger buf's until it all fits. */ |
| 2045 while (1) | |
| 2046 { | |
| 2047 buf = (char *) alloca (total + 1); | |
| 2048 buf[total - 1] = 0; | |
| 2049 | |
|
13450
9a1e7191803f
(Fformat): Use doprnt_lisp.
Richard M. Stallman <rms@gnu.org>
parents:
13347
diff
changeset
|
2050 length = doprnt_lisp (buf, total + 1, strings[0], |
|
9a1e7191803f
(Fformat): Use doprnt_lisp.
Richard M. Stallman <rms@gnu.org>
parents:
13347
diff
changeset
|
2051 end, i-1, strings + 1); |
| 305 | 2052 if (buf[total - 1] == 0) |
| 2053 break; | |
| 2054 | |
| 2055 total *= 2; | |
| 2056 } | |
| 2057 } | |
| 2058 | |
| 2059 /* UNGCPRO; */ | |
| 2060 return make_string (buf, length); | |
| 2061 } | |
| 2062 | |
| 2063 /* VARARGS 1 */ | |
| 2064 Lisp_Object | |
| 2065 #ifdef NO_ARG_ARRAY | |
| 2066 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
|
2067 EMACS_INT arg0, arg1, arg2, arg3, arg4; |
| 305 | 2068 #else |
| 2069 format1 (string1) | |
| 2070 #endif | |
| 2071 char *string1; | |
| 2072 { | |
| 2073 char buf[100]; | |
| 2074 #ifdef NO_ARG_ARRAY | |
|
8824
589f82d1bb32
(Fnarrow_to_region, format1): Use EMACS_INT.
Richard M. Stallman <rms@gnu.org>
parents:
8771
diff
changeset
|
2075 EMACS_INT args[5]; |
| 305 | 2076 args[0] = arg0; |
| 2077 args[1] = arg1; | |
| 2078 args[2] = arg2; | |
| 2079 args[3] = arg3; | |
| 2080 args[4] = arg4; | |
| 11912 | 2081 doprnt (buf, sizeof buf, string1, (char *)0, 5, args); |
| 305 | 2082 #else |
| 11912 | 2083 doprnt (buf, sizeof buf, string1, (char *)0, 5, &string1 + 1); |
| 305 | 2084 #endif |
| 2085 return build_string (buf); | |
| 2086 } | |
| 2087 | |
| 2088 DEFUN ("char-equal", Fchar_equal, Schar_equal, 2, 2, 0, | |
| 2089 "Return t if two characters match, optionally ignoring case.\n\ | |
| 2090 Both arguments must be characters (i.e. integers).\n\ | |
| 2091 Case is ignored if `case-fold-search' is non-nil in the current buffer.") | |
| 2092 (c1, c2) | |
| 2093 register Lisp_Object c1, c2; | |
| 2094 { | |
|
13238
10a489bbf5c3
(Fchar_equal): Handle char-table as case table.
Richard M. Stallman <rms@gnu.org>
parents:
13025
diff
changeset
|
2095 Lisp_Object *downcase = DOWNCASE_TABLE; |
| 305 | 2096 CHECK_NUMBER (c1, 0); |
| 2097 CHECK_NUMBER (c2, 1); | |
| 2098 | |
| 488 | 2099 if (!NILP (current_buffer->case_fold_search) |
|
13238
10a489bbf5c3
(Fchar_equal): Handle char-table as case table.
Richard M. Stallman <rms@gnu.org>
parents:
13025
diff
changeset
|
2100 ? ((XINT (downcase[0xff & XFASTINT (c1)]) |
|
10a489bbf5c3
(Fchar_equal): Handle char-table as case table.
Richard M. Stallman <rms@gnu.org>
parents:
13025
diff
changeset
|
2101 == XINT (downcase[0xff & XFASTINT (c2)])) |
|
2384
5ab51b7300e4
(Fchar_equal): Don't ignore high bits of character.
Richard M. Stallman <rms@gnu.org>
parents:
2154
diff
changeset
|
2102 && (XFASTINT (c1) & ~0xff) == (XFASTINT (c2) & ~0xff)) |
| 305 | 2103 : XINT (c1) == XINT (c2)) |
| 2104 return Qt; | |
| 2105 return Qnil; | |
| 2106 } | |
|
7207
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2107 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2108 /* 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
|
2109 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
|
2110 differ in size). |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2111 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2112 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
|
2113 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
|
2114 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
|
2115 |
|
7862
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2116 It's the caller's job to see that (start1 <= end1 <= start2 <= end2). */ |
|
7207
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2117 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2118 void |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2119 transpose_markers (start1, end1, start2, end2) |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2120 register int start1, end1, start2, end2; |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2121 { |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2122 register int amt1, amt2, diff, mpos; |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2123 register Lisp_Object marker; |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2124 |
|
7862
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2125 /* 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
|
2126 if (PT < start1) |
|
987ab382275c
(Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents:
7506
diff
changeset
|
2127 ; |
|
987ab382275c
(Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents:
7506
diff
changeset
|
2128 else if (PT < end1) |
|
987ab382275c
(Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents:
7506
diff
changeset
|
2129 TEMP_SET_PT (PT + (end2 - end1)); |
|
987ab382275c
(Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents:
7506
diff
changeset
|
2130 else if (PT < start2) |
|
987ab382275c
(Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents:
7506
diff
changeset
|
2131 TEMP_SET_PT (PT + (end2 - start2) - (end1 - start1)); |
|
987ab382275c
(Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents:
7506
diff
changeset
|
2132 else if (PT < end2) |
|
987ab382275c
(Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents:
7506
diff
changeset
|
2133 TEMP_SET_PT (PT - (start2 - start1)); |
|
987ab382275c
(Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents:
7506
diff
changeset
|
2134 |
|
7862
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2135 /* 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
|
2136 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
|
2137 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
|
2138 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
|
2139 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
|
2140 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
|
2141 the dirty work to Fmarker_position, below. */ |
|
7207
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2142 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2143 /* The difference between the region's lengths */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2144 diff = (end2 - start2) - (end1 - start1); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2145 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2146 /* For shifting each marker in a region by the length of the other |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2147 * region plus the distance between the regions. |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2148 */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2149 amt1 = (end2 - start2) + (start2 - end1); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2150 amt2 = (end1 - start1) + (start2 - end1); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2151 |
|
10308
90784ed0416f
Use SAVE_MODIFF and BUF_SAVE_MODIFF
Richard M. Stallman <rms@gnu.org>
parents:
9812
diff
changeset
|
2152 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
|
2153 marker = XMARKER (marker)->chain) |
|
7207
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2154 { |
|
7862
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2155 mpos = Fmarker_position (marker); |
|
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2156 if (mpos >= start1 && mpos < end2) |
|
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2157 { |
|
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2158 if (mpos < end1) |
|
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2159 mpos += amt1; |
|
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2160 else if (mpos < start2) |
|
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2161 mpos += diff; |
|
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2162 else |
|
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2163 mpos -= amt2; |
|
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2164 if (mpos > GPT) mpos += GAP_SIZE; |
|
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2165 XMARKER (marker)->bufpos = mpos; |
|
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2166 } |
|
7207
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2167 } |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2168 } |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2169 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2170 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
|
2171 "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
|
2172 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
|
2173 never changed in a transposition.\n\ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2174 \n\ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2175 Optional fifth arg LEAVE_MARKERS, if non-nil, means don't transpose\n\ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2176 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
|
2177 \n\ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2178 Transposing beyond buffer boundaries is an error.") |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2179 (startr1, endr1, startr2, endr2, leave_markers) |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2180 Lisp_Object startr1, endr1, startr2, endr2, leave_markers; |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2181 { |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2182 register int start1, end1, start2, end2, |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2183 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
|
2184 unsigned char *start1_addr, *start2_addr, *temp; |
|
7207
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2185 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2186 #ifdef USE_TEXT_PROPERTIES |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2187 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
|
2188 cur_intv = BUF_INTERVALS (current_buffer); |
|
7207
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2189 #endif /* USE_TEXT_PROPERTIES */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2190 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2191 validate_region (&startr1, &endr1); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2192 validate_region (&startr2, &endr2); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2193 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2194 start1 = XFASTINT (startr1); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2195 end1 = XFASTINT (endr1); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2196 start2 = XFASTINT (startr2); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2197 end2 = XFASTINT (endr2); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2198 gap = GPT; |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2199 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2200 /* Swap the regions if they're reversed. */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2201 if (start2 < end1) |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2202 { |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2203 register int glumph = start1; |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2204 start1 = start2; |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2205 start2 = glumph; |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2206 glumph = end1; |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2207 end1 = end2; |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2208 end2 = glumph; |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2209 } |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2210 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2211 len1 = end1 - start1; |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2212 len2 = end2 - start2; |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2213 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2214 if (start2 < end1) |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2215 error ("transposed regions not properly ordered"); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2216 else if (start1 == end1 || start2 == end2) |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2217 error ("transposed region may not be of length 0"); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2218 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2219 /* The possibilities are: |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2220 1. Adjacent (contiguous) regions, or separate but equal regions |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2221 (no, really equal, in this case!), or |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2222 2. Separate regions of unequal size. |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2223 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2224 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
|
2225 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
|
2226 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
|
2227 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
|
2228 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2229 /* 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
|
2230 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
|
2231 around it if necessary. This would be extremely efficient, |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2232 especially considering that people are likely to do |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2233 transpositions near where they are working interactively, which |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2234 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
|
2235 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
|
2236 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
|
2237 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
|
2238 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
|
2239 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
|
2240 |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2241 /* 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
|
2242 we will operate on. */ |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2243 if (start1 < gap && gap < end2) |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2244 { |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2245 if (gap - start1 < end2 - gap) |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2246 move_gap (start1); |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2247 else |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2248 move_gap (end2); |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2249 } |
|
7207
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2250 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2251 /* 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
|
2252 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
|
2253 allocation... interesting. Later, don't fool with it now. */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2254 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2255 /* Working without memmove, for portability (sigh), so must be |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2256 careful of overlapping subsections of the array... */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2257 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2258 if (end1 == start2) /* adjacent regions */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2259 { |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2260 modify_region (current_buffer, start1, end2); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2261 record_change (start1, len1 + len2); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2262 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2263 #ifdef USE_TEXT_PROPERTIES |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2264 tmp_interval1 = copy_intervals (cur_intv, start1, len1); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2265 tmp_interval2 = copy_intervals (cur_intv, start2, len2); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2266 Fset_text_properties (start1, end2, Qnil, Qnil); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2267 #endif /* USE_TEXT_PROPERTIES */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2268 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2269 /* First region smaller than second. */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2270 if (len1 < len2) |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2271 { |
|
7250
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2272 /* 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
|
2273 because we want to avoid stack overflow. */ |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2274 if (len2 > 20000) |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2275 temp = (unsigned char *) xmalloc (len2); |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2276 else |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2277 temp = (unsigned char *) alloca (len2); |
|
7862
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2278 |
|
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2279 /* 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
|
2280 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
|
2281 have moved the buffer around during the xmalloc. */ |
|
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2282 start1_addr = BUF_CHAR_ADDRESS (current_buffer, start1); |
|
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2283 start2_addr = BUF_CHAR_ADDRESS (current_buffer, start2); |
|
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2284 |
|
7207
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2285 bcopy (start2_addr, temp, len2); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2286 bcopy (start1_addr, start1_addr + len2, len1); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2287 bcopy (temp, start1_addr, len2); |
|
7250
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2288 if (len2 > 20000) |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2289 free (temp); |
|
7207
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2290 } |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2291 else |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2292 /* First region not smaller than second. */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2293 { |
|
7250
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2294 if (len1 > 20000) |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2295 temp = (unsigned char *) xmalloc (len1); |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2296 else |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2297 temp = (unsigned char *) alloca (len1); |
|
7862
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2298 start1_addr = BUF_CHAR_ADDRESS (current_buffer, start1); |
|
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2299 start2_addr = BUF_CHAR_ADDRESS (current_buffer, start2); |
|
7207
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2300 bcopy (start1_addr, temp, len1); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2301 bcopy (start2_addr, start1_addr, len2); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2302 bcopy (temp, start1_addr + len2, len1); |
|
7250
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2303 if (len1 > 20000) |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2304 free (temp); |
|
7207
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2305 } |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2306 #ifdef USE_TEXT_PROPERTIES |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2307 graft_intervals_into_buffer (tmp_interval1, start1 + len2, |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2308 len1, current_buffer, 0); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2309 graft_intervals_into_buffer (tmp_interval2, start1, |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2310 len2, current_buffer, 0); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2311 #endif /* USE_TEXT_PROPERTIES */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2312 } |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2313 /* Non-adjacent regions, because end1 != start2, bleagh... */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2314 else |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2315 { |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2316 if (len1 == len2) |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2317 /* Regions are same size, though, how nice. */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2318 { |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2319 modify_region (current_buffer, start1, end1); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2320 modify_region (current_buffer, start2, end2); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2321 record_change (start1, len1); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2322 record_change (start2, len2); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2323 #ifdef USE_TEXT_PROPERTIES |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2324 tmp_interval1 = copy_intervals (cur_intv, start1, len1); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2325 tmp_interval2 = copy_intervals (cur_intv, start2, len2); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2326 Fset_text_properties (start1, end1, Qnil, Qnil); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2327 Fset_text_properties (start2, end2, Qnil, Qnil); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2328 #endif /* USE_TEXT_PROPERTIES */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2329 |
|
7250
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2330 if (len1 > 20000) |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2331 temp = (unsigned char *) xmalloc (len1); |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2332 else |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2333 temp = (unsigned char *) alloca (len1); |
|
7862
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2334 start1_addr = BUF_CHAR_ADDRESS (current_buffer, start1); |
|
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2335 start2_addr = BUF_CHAR_ADDRESS (current_buffer, start2); |
|
7207
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2336 bcopy (start1_addr, temp, len1); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2337 bcopy (start2_addr, start1_addr, len2); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2338 bcopy (temp, start2_addr, len1); |
|
7250
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2339 if (len1 > 20000) |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2340 free (temp); |
|
7207
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2341 #ifdef USE_TEXT_PROPERTIES |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2342 graft_intervals_into_buffer (tmp_interval1, start2, |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2343 len1, current_buffer, 0); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2344 graft_intervals_into_buffer (tmp_interval2, start1, |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2345 len2, current_buffer, 0); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2346 #endif /* USE_TEXT_PROPERTIES */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2347 } |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2348 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2349 else if (len1 < len2) /* Second region larger than first */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2350 /* 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
|
2351 { |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2352 len_mid = start2 - end1; |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2353 modify_region (current_buffer, start1, end2); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2354 record_change (start1, (end2 - start1)); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2355 #ifdef USE_TEXT_PROPERTIES |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2356 tmp_interval1 = copy_intervals (cur_intv, start1, len1); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2357 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
|
2358 tmp_interval2 = copy_intervals (cur_intv, start2, len2); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2359 Fset_text_properties (start1, end2, Qnil, Qnil); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2360 #endif /* USE_TEXT_PROPERTIES */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2361 |
|
7250
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2362 /* holds region 2 */ |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2363 if (len2 > 20000) |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2364 temp = (unsigned char *) xmalloc (len2); |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2365 else |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2366 temp = (unsigned char *) alloca (len2); |
|
7862
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2367 start1_addr = BUF_CHAR_ADDRESS (current_buffer, start1); |
|
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2368 start2_addr = BUF_CHAR_ADDRESS (current_buffer, start2); |
|
7250
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2369 bcopy (start2_addr, temp, len2); |
|
7207
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2370 bcopy (start1_addr, start1_addr + len_mid + len2, len1); |
|
7250
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2371 safe_bcopy (start1_addr + len1, start1_addr + len2, len_mid); |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2372 bcopy (temp, start1_addr, len2); |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2373 if (len2 > 20000) |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2374 free (temp); |
|
7207
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2375 #ifdef USE_TEXT_PROPERTIES |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2376 graft_intervals_into_buffer (tmp_interval1, end2 - len1, |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2377 len1, current_buffer, 0); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2378 graft_intervals_into_buffer (tmp_interval_mid, start1 + len2, |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2379 len_mid, current_buffer, 0); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2380 graft_intervals_into_buffer (tmp_interval2, start1, |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2381 len2, current_buffer, 0); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2382 #endif /* USE_TEXT_PROPERTIES */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2383 } |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2384 else |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2385 /* Second region smaller than first. */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2386 { |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2387 len_mid = start2 - end1; |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2388 record_change (start1, (end2 - start1)); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2389 modify_region (current_buffer, start1, end2); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2390 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2391 #ifdef USE_TEXT_PROPERTIES |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2392 tmp_interval1 = copy_intervals (cur_intv, start1, len1); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2393 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
|
2394 tmp_interval2 = copy_intervals (cur_intv, start2, len2); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2395 Fset_text_properties (start1, end2, Qnil, Qnil); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2396 #endif /* USE_TEXT_PROPERTIES */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2397 |
|
7250
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2398 /* holds region 1 */ |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2399 if (len1 > 20000) |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2400 temp = (unsigned char *) xmalloc (len1); |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2401 else |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2402 temp = (unsigned char *) alloca (len1); |
|
7862
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2403 start1_addr = BUF_CHAR_ADDRESS (current_buffer, start1); |
|
0b6f46029ea2
(transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents:
7710
diff
changeset
|
2404 start2_addr = BUF_CHAR_ADDRESS (current_buffer, start2); |
|
7250
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2405 bcopy (start1_addr, temp, len1); |
|
7207
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2406 bcopy (start2_addr, start1_addr, len2); |
|
7250
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2407 bcopy (start1_addr + len1, start1_addr + len2, len_mid); |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2408 bcopy (temp, start1_addr + len2 + len_mid, len1); |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2409 if (len1 > 20000) |
|
67bb3bb1b62d
(Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents:
7207
diff
changeset
|
2410 free (temp); |
|
7207
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2411 #ifdef USE_TEXT_PROPERTIES |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2412 graft_intervals_into_buffer (tmp_interval1, end2 - len1, |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2413 len1, current_buffer, 0); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2414 graft_intervals_into_buffer (tmp_interval_mid, start1 + len2, |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2415 len_mid, current_buffer, 0); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2416 graft_intervals_into_buffer (tmp_interval2, start1, |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2417 len2, current_buffer, 0); |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2418 #endif /* USE_TEXT_PROPERTIES */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2419 } |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2420 } |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2421 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2422 /* todo: this will be slow, because for every transposition, we |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2423 traverse the whole friggin marker list. Possible solutions: |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2424 somehow get a list of *all* the markers across multiple |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2425 transpositions and do it all in one swell phoop. Or maybe modify |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2426 Emacs' marker code to keep an ordered list or tree. This might |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2427 be nicer, and more beneficial in the long run, but would be a |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2428 bunch of work. Plus the way they're arranged now is nice. */ |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2429 if (NILP (leave_markers)) |
|
7519
987ab382275c
(Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents:
7506
diff
changeset
|
2430 { |
|
987ab382275c
(Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents:
7506
diff
changeset
|
2431 transpose_markers (start1, end1, start2, end2); |
|
987ab382275c
(Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents:
7506
diff
changeset
|
2432 fix_overlays_in_range (start1, end2); |
|
987ab382275c
(Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents:
7506
diff
changeset
|
2433 } |
|
7207
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2434 |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2435 return Qnil; |
|
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2436 } |
| 305 | 2437 |
| 2438 | |
| 2439 void | |
| 2440 syms_of_editfns () | |
| 2441 { | |
|
13767
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
2442 environbuf = 0; |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
2443 |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
2444 Qbuffer_access_fontify_functions |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
2445 = intern ("buffer-access-fontify-functions"); |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
2446 staticpro (&Qbuffer_access_fontify_functions); |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
2447 |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
2448 DEFVAR_LISP ("buffer-access-fontify-functions", |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
2449 &Vbuffer_access_fontify_functions, |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
2450 "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
|
2451 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
|
2452 of the buffer being accessed."); |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
2453 Vbuffer_access_fontify_functions = Qnil; |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
2454 |
|
14440
e99b3302c154
(syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents:
14391
diff
changeset
|
2455 { |
|
e99b3302c154
(syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents:
14391
diff
changeset
|
2456 Lisp_Object obuf; |
|
e99b3302c154
(syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents:
14391
diff
changeset
|
2457 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
|
2458 obuf = Fcurrent_buffer (); |
|
e99b3302c154
(syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents:
14391
diff
changeset
|
2459 /* 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
|
2460 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
|
2461 /* 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
|
2462 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
|
2463 Qnil); |
|
e99b3302c154
(syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents:
14391
diff
changeset
|
2464 Fset_buffer (obuf); |
|
e99b3302c154
(syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents:
14391
diff
changeset
|
2465 } |
|
e99b3302c154
(syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents:
14391
diff
changeset
|
2466 |
| 14220 | 2467 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
|
2468 &Vbuffer_access_fontified_property, |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
2469 "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
|
2470 `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
|
2471 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
|
2472 Vbuffer_access_fontified_property = Qnil; |
|
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
2473 |
|
8771
31b8e48045f3
(syms_of_editfns): Make Vsystem_name and Vuser...name lisp variables again.
Karl Heuer <kwzh@gnu.org>
parents:
8667
diff
changeset
|
2474 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
|
2475 "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
|
2476 |
|
31b8e48045f3
(syms_of_editfns): Make Vsystem_name and Vuser...name lisp variables again.
Karl Heuer <kwzh@gnu.org>
parents:
8667
diff
changeset
|
2477 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
|
2478 "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
|
2479 |
|
12026
505a894d943e
(syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents:
11912
diff
changeset
|
2480 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
|
2481 "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
|
2482 |
|
12026
505a894d943e
(syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents:
11912
diff
changeset
|
2483 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
|
2484 "The user's name, based upon the real uid only."); |
| 305 | 2485 |
| 2486 defsubr (&Schar_equal); | |
| 2487 defsubr (&Sgoto_char); | |
| 2488 defsubr (&Sstring_to_char); | |
| 2489 defsubr (&Schar_to_string); | |
| 2490 defsubr (&Sbuffer_substring); | |
|
13767
862fff660446
(Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents:
13618
diff
changeset
|
2491 defsubr (&Sbuffer_substring_no_properties); |
| 305 | 2492 defsubr (&Sbuffer_string); |
| 2493 | |
| 2494 defsubr (&Spoint_marker); | |
| 2495 defsubr (&Smark_marker); | |
| 2496 defsubr (&Spoint); | |
| 2497 defsubr (&Sregion_beginning); | |
| 2498 defsubr (&Sregion_end); | |
| 2499 /* defsubr (&Smark); */ | |
| 2500 /* defsubr (&Sset_mark); */ | |
| 2501 defsubr (&Ssave_excursion); | |
| 2502 | |
| 2503 defsubr (&Sbufsize); | |
| 2504 defsubr (&Spoint_max); | |
| 2505 defsubr (&Spoint_min); | |
| 2506 defsubr (&Spoint_min_marker); | |
| 2507 defsubr (&Spoint_max_marker); | |
| 2508 | |
| 2509 defsubr (&Sbobp); | |
| 2510 defsubr (&Seobp); | |
| 2511 defsubr (&Sbolp); | |
| 2512 defsubr (&Seolp); | |
| 512 | 2513 defsubr (&Sfollowing_char); |
| 2514 defsubr (&Sprevious_char); | |
| 305 | 2515 defsubr (&Schar_after); |
| 2516 defsubr (&Sinsert); | |
| 2517 defsubr (&Sinsert_before_markers); | |
|
4714
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2518 defsubr (&Sinsert_and_inherit); |
|
350231e38e68
(Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2519 defsubr (&Sinsert_and_inherit_before_markers); |
| 305 | 2520 defsubr (&Sinsert_char); |
| 2521 | |
| 2522 defsubr (&Suser_login_name); | |
| 2523 defsubr (&Suser_real_login_name); | |
| 2524 defsubr (&Suser_uid); | |
| 2525 defsubr (&Suser_real_uid); | |
| 2526 defsubr (&Suser_full_name); | |
|
5373
a70b89d2d6bb
(Femacs_pid): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5242
diff
changeset
|
2527 defsubr (&Semacs_pid); |
| 448 | 2528 defsubr (&Scurrent_time); |
|
9154
b4739bcefc44
(Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents:
8981
diff
changeset
|
2529 defsubr (&Sformat_time_string); |
|
9801
7003b5184aec
(init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents:
9657
diff
changeset
|
2530 defsubr (&Sdecode_time); |
|
11402
66d935214d8e
(Fencode_time): Use XINT to examine `zone'.
Richard M. Stallman <rms@gnu.org>
parents:
11263
diff
changeset
|
2531 defsubr (&Sencode_time); |
| 305 | 2532 defsubr (&Scurrent_time_string); |
|
962
3533821d6edc
* editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
690
diff
changeset
|
2533 defsubr (&Scurrent_time_zone); |
|
13019
5381e2022370
(Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13013
diff
changeset
|
2534 defsubr (&Sset_time_zone_rule); |
| 305 | 2535 defsubr (&Ssystem_name); |
| 2536 defsubr (&Smessage); | |
|
8975
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
2537 defsubr (&Smessage_box); |
|
e8a4c71251cb
(Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents:
8824
diff
changeset
|
2538 defsubr (&Smessage_or_box); |
| 305 | 2539 defsubr (&Sformat); |
| 2540 | |
| 2541 defsubr (&Sinsert_buffer_substring); | |
|
1853
8866e36c0ed5
(Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1748
diff
changeset
|
2542 defsubr (&Scompare_buffer_substrings); |
| 305 | 2543 defsubr (&Ssubst_char_in_region); |
| 2544 defsubr (&Stranslate_region); | |
| 2545 defsubr (&Sdelete_region); | |
| 2546 defsubr (&Swiden); | |
| 2547 defsubr (&Snarrow_to_region); | |
| 2548 defsubr (&Ssave_restriction); | |
|
7207
c83b161fe62c
(Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6878
diff
changeset
|
2549 defsubr (&Stranspose_regions); |
| 305 | 2550 } |
