annotate src/editfns.c @ 40046:5858ea32e564

(text_property_stickiness): Really fix it this time.
author Miles Bader <miles@gnu.org>
date Fri, 19 Oct 2001 07:45:58 +0000
parents 7a0668d72687
children de086e415fa2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /* Lisp functions pertaining to editing.
37046
a9b2639dd045 (Ffloat_time): Fix off-by-factor-of-10 bug in the
Gerd Moellmann <gerd@gnu.org>
parents: 36479
diff changeset
2 Copyright (C) 1985,86,87,89,93,94,95,96,97,98, 1999, 2000, 2001
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
3 Free Software Foundation, Inc.
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5 This file is part of GNU Emacs.
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 GNU Emacs is free software; you can redistribute it and/or modify
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
12244
ac7375e60931 Update GPL to version 2.
Karl Heuer <kwzh@gnu.org>
parents: 12063
diff changeset
9 the Free Software Foundation; either version 2, or (at your option)
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 any later version.
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 GNU Emacs is distributed in the hope that it will be useful,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 GNU General Public License for more details.
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 along with GNU Emacs; see the file COPYING. If not, write to
14862
e368c0d12356 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 14440
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
e368c0d12356 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 14440
diff changeset
20 Boston, MA 02111-1307, USA. */
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22
26088
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
23 #include <config.h>
39675
a4def4204419 *** empty log message ***
Pavel Janík <Pavel@Janik.cz>
parents: 38519
diff changeset
24 #include <ctype.h>
2962
79314d830f7d * editfns.c: #include <sys/types.h>, to get time_t for Eggert's
Jim Blandy <jimb@redhat.com>
parents: 2921
diff changeset
25 #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
26
372
481e29c1e27e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 330
diff changeset
27 #ifdef VMS
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
28 #include "vms-pwd.h"
372
481e29c1e27e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 330
diff changeset
29 #else
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 #include <pwd.h>
372
481e29c1e27e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 330
diff changeset
31 #endif
481e29c1e27e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 330
diff changeset
32
21514
fa9ff387d260 Fix -Wimplicit warnings.
Andreas Schwab <schwab@suse.de>
parents: 21381
diff changeset
33 #ifdef HAVE_UNISTD_H
fa9ff387d260 Fix -Wimplicit warnings.
Andreas Schwab <schwab@suse.de>
parents: 21381
diff changeset
34 #include <unistd.h>
fa9ff387d260 Fix -Wimplicit warnings.
Andreas Schwab <schwab@suse.de>
parents: 21381
diff changeset
35 #endif
fa9ff387d260 Fix -Wimplicit warnings.
Andreas Schwab <schwab@suse.de>
parents: 21381
diff changeset
36
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 #include "lisp.h"
1285
d50533e23dff * editfns.c (make_buffer_string): Call copy_intervals_to_string().
Joseph Arceneaux <jla@gnu.org>
parents: 1254
diff changeset
38 #include "intervals.h"
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 #include "buffer.h"
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
40 #include "charset.h"
26088
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
41 #include "coding.h"
38059
0b34b024286d (Fmessage_box): If the frame is not under a window
Eli Zaretskii <eliz@gnu.org>
parents: 37916
diff changeset
42 #include "frame.h"
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 #include "window.h"
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
45 #include "systime.h"
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46
38519
200c049178cc (toplevel) [STDC_HEADERS]: Include float.h.
Gerd Moellmann <gerd@gnu.org>
parents: 38059
diff changeset
47 #ifdef STDC_HEADERS
200c049178cc (toplevel) [STDC_HEADERS]: Include float.h.
Gerd Moellmann <gerd@gnu.org>
parents: 38059
diff changeset
48 #include <float.h>
200c049178cc (toplevel) [STDC_HEADERS]: Include float.h.
Gerd Moellmann <gerd@gnu.org>
parents: 38059
diff changeset
49 #define MAX_10_EXP DBL_MAX_10_EXP
200c049178cc (toplevel) [STDC_HEADERS]: Include float.h.
Gerd Moellmann <gerd@gnu.org>
parents: 38059
diff changeset
50 #else
200c049178cc (toplevel) [STDC_HEADERS]: Include float.h.
Gerd Moellmann <gerd@gnu.org>
parents: 38059
diff changeset
51 #define MAX_10_EXP 310
200c049178cc (toplevel) [STDC_HEADERS]: Include float.h.
Gerd Moellmann <gerd@gnu.org>
parents: 38059
diff changeset
52 #endif
200c049178cc (toplevel) [STDC_HEADERS]: Include float.h.
Gerd Moellmann <gerd@gnu.org>
parents: 38059
diff changeset
53
19441
2e2b54ae9b9d (NULL): Define, if not defined.
Richard M. Stallman <rms@gnu.org>
parents: 19416
diff changeset
54 #ifndef NULL
2e2b54ae9b9d (NULL): Define, if not defined.
Richard M. Stallman <rms@gnu.org>
parents: 19416
diff changeset
55 #define NULL 0
2e2b54ae9b9d (NULL): Define, if not defined.
Richard M. Stallman <rms@gnu.org>
parents: 19416
diff changeset
56 #endif
2e2b54ae9b9d (NULL): Define, if not defined.
Richard M. Stallman <rms@gnu.org>
parents: 19416
diff changeset
57
31095
e19d38e14720 [USE_CRT_DLL]: Remove unnecessary extern, which screws
Andrew Innes <andrewi@gnu.org>
parents: 31016
diff changeset
58 #ifndef USE_CRT_DLL
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
59 extern char **environ;
31095
e19d38e14720 [USE_CRT_DLL]: Remove unnecessary extern, which screws
Andrew Innes <andrewi@gnu.org>
parents: 31016
diff changeset
60 #endif
e19d38e14720 [USE_CRT_DLL]: Remove unnecessary extern, which screws
Andrew Innes <andrewi@gnu.org>
parents: 31016
diff changeset
61
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
62 extern Lisp_Object make_time P_ ((time_t));
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
63 extern size_t emacs_strftimeu P_ ((char *, size_t, const char *,
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
64 const struct tm *, int));
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
65 static int tm_diff P_ ((struct tm *, struct tm *));
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
66 static void find_field P_ ((Lisp_Object, Lisp_Object, int *, int *));
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
67 static void update_buffer_properties P_ ((int, int));
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
68 static Lisp_Object region_limit P_ ((int));
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
69 static int lisp_time_argument P_ ((Lisp_Object, time_t *, int *));
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
70 static size_t emacs_memftimeu P_ ((char *, size_t, const char *,
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
71 size_t, const struct tm *, int));
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
72 static void general_insert_function P_ ((void (*) (unsigned char *, int),
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
73 void (*) (Lisp_Object, int, int, int,
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
74 int, int),
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
75 int, int, Lisp_Object *));
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
76 static Lisp_Object subst_char_in_region_unwind P_ ((Lisp_Object));
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
77 static Lisp_Object subst_char_in_region_unwind_1 P_ ((Lisp_Object));
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
78 static void transpose_markers P_ ((int, int, int, int, int, int, int, int));
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
79
31336
3ecef4a7b3cd Remove includes of
Gerd Moellmann <gerd@gnu.org>
parents: 31225
diff changeset
80 #ifdef HAVE_INDEX
3ecef4a7b3cd Remove includes of
Gerd Moellmann <gerd@gnu.org>
parents: 31225
diff changeset
81 extern char *index P_ ((const char *, int));
3ecef4a7b3cd Remove includes of
Gerd Moellmann <gerd@gnu.org>
parents: 31225
diff changeset
82 #endif
3ecef4a7b3cd Remove includes of
Gerd Moellmann <gerd@gnu.org>
parents: 31225
diff changeset
83
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
84 Lisp_Object Vbuffer_access_fontify_functions;
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
85 Lisp_Object Qbuffer_access_fontify_functions;
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
86 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
87
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
88 Lisp_Object Fuser_full_name P_ ((Lisp_Object));
17829
2d98572c57ab Declare Fuser_full_name as Lisp_Object in advance to
Kenichi Handa <handa@m17n.org>
parents: 17115
diff changeset
89
27077
19a664c654ab (Vinhibit_field_text_motion): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 26853
diff changeset
90 /* Non-nil means don't stop at field boundary in text motion commands. */
19a664c654ab (Vinhibit_field_text_motion): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 26853
diff changeset
91
19a664c654ab (Vinhibit_field_text_motion): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 26853
diff changeset
92 Lisp_Object Vinhibit_field_text_motion;
19a664c654ab (Vinhibit_field_text_motion): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 26853
diff changeset
93
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 /* Some static data, and a function to initialize it for each run */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 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
97 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
98 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
99 Lisp_Object Vuser_login_name; /* user name from LOGNAME or USER */
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
101 /* Symbol for the text property used to mark fields. */
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
102
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
103 Lisp_Object Qfield;
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
104
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
105 /* A special value for Qfield properties. */
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
106
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
107 Lisp_Object Qboundary;
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
108
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
109
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 void
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 init_editfns ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 {
330
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
113 char *user_name;
25782
8f59abd3a02b (init_editfns): Remove unused variables.
Gerd Moellmann <gerd@gnu.org>
parents: 25662
diff changeset
114 register unsigned char *p;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 struct passwd *pw; /* password entry for the current user */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 Lisp_Object tem;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 /* 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
119 init_system_name ();
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 #ifndef CANNOT_DUMP
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 /* Don't bother with this on initial start when just dumping out */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 if (!initialized)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 return;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 #endif /* not CANNOT_DUMP */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 pw = (struct passwd *) getpwuid (getuid ());
9572
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
128 #ifdef MSDOS
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
129 /* We let the real user name default to "root" because that's quite
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
130 accurate on MSDOG and because it lets Emacs find the init file.
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
131 (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
132 Vuser_real_login_name = build_string (pw ? pw->pw_name : "root");
9572
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
133 #else
12026
505a894d943e (syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents: 11912
diff changeset
134 Vuser_real_login_name = build_string (pw ? pw->pw_name : "unknown");
9572
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
135 #endif
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136
330
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
137 /* Get the effective user name, by consulting environment variables,
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
138 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
139 user_name = (char *) getenv ("LOGNAME");
330
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
140 if (!user_name)
9801
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
141 #ifdef WINDOWSNT
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
142 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
143 #else /* WINDOWSNT */
5907
5fdb226fe9a4 (init_editfns): Look at LOGNAME before USER.
Karl Heuer <kwzh@gnu.org>
parents: 5884
diff changeset
144 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
145 #endif /* WINDOWSNT */
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 if (!user_name)
330
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
147 {
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
148 pw = (struct passwd *) getpwuid (geteuid ());
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
149 user_name = (char *) (pw ? pw->pw_name : "unknown");
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
150 }
12026
505a894d943e (syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents: 11912
diff changeset
151 Vuser_login_name = build_string (user_name);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152
330
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
153 /* If the user name claimed in the environment vars differs from
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
154 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
155 tem = Fstring_equal (Vuser_login_name, Vuser_real_login_name);
16641
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
156 Vuser_full_name = Fuser_full_name (NILP (tem)? make_number (geteuid())
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
157 : Vuser_login_name);
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
158
11447
d51e912495be (init_editfns): Add casts.
Richard M. Stallman <rms@gnu.org>
parents: 11433
diff changeset
159 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
160 if (p)
9ab21ef32537 (init_editfns): Use NAME envvar to init user-full-name.
Richard M. Stallman <rms@gnu.org>
parents: 10480
diff changeset
161 Vuser_full_name = build_string (p);
16683
6802dbd07a80 (Fuser_full_name): Return nil if the specified user doesn't exist.
Richard M. Stallman <rms@gnu.org>
parents: 16648
diff changeset
162 else if (NILP (Vuser_full_name))
6802dbd07a80 (Fuser_full_name): Return nil if the specified user doesn't exist.
Richard M. Stallman <rms@gnu.org>
parents: 16648
diff changeset
163 Vuser_full_name = build_string ("unknown");
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 DEFUN ("char-to-string", Fchar_to_string, Schar_to_string, 1, 1, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
167 doc: /* Convert arg CHARACTER to a string containing that character. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
168 (character)
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
169 Lisp_Object character;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 {
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
171 int len;
26853
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
172 unsigned char str[MAX_MULTIBYTE_LENGTH];
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
173
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
174 CHECK_NUMBER (character, 0);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175
35998
5cf8398ba424 (Fchar_to_string): If CHARACTER is less than 256,
Kenichi Handa <handa@m17n.org>
parents: 35845
diff changeset
176 len = (SINGLE_BYTE_CHAR_P (XFASTINT (character))
5cf8398ba424 (Fchar_to_string): If CHARACTER is less than 256,
Kenichi Handa <handa@m17n.org>
parents: 35845
diff changeset
177 ? (*str = (unsigned char)(XFASTINT (character)), 1)
5cf8398ba424 (Fchar_to_string): If CHARACTER is less than 256,
Kenichi Handa <handa@m17n.org>
parents: 35845
diff changeset
178 : char_to_string (XFASTINT (character), str));
21257
205a5aa4aa2f (Fchar_to_string): Use make_string_from_bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21245
diff changeset
179 return make_string_from_bytes (str, 1, len);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 DEFUN ("string-to-char", Fstring_to_char, Sstring_to_char, 1, 1, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
183 doc: /* Convert arg STRING to a character, the first character of that string.
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
184 A multibyte character is handled correctly. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
185 (string)
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
186 register Lisp_Object string;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 register Lisp_Object val;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 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
190 CHECK_STRING (string, 0);
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
191 p = XSTRING (string);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 if (p->size)
23650
3cc42e65f25b (Fstring_to_char): Don't return a multibyte character
Kenichi Handa <handa@m17n.org>
parents: 23596
diff changeset
193 {
3cc42e65f25b (Fstring_to_char): Don't return a multibyte character
Kenichi Handa <handa@m17n.org>
parents: 23596
diff changeset
194 if (STRING_MULTIBYTE (string))
3cc42e65f25b (Fstring_to_char): Don't return a multibyte character
Kenichi Handa <handa@m17n.org>
parents: 23596
diff changeset
195 XSETFASTINT (val, STRING_CHAR (p->data, STRING_BYTES (p)));
3cc42e65f25b (Fstring_to_char): Don't return a multibyte character
Kenichi Handa <handa@m17n.org>
parents: 23596
diff changeset
196 else
3cc42e65f25b (Fstring_to_char): Don't return a multibyte character
Kenichi Handa <handa@m17n.org>
parents: 23596
diff changeset
197 XSETFASTINT (val, p->data[0]);
3cc42e65f25b (Fstring_to_char): Don't return a multibyte character
Kenichi Handa <handa@m17n.org>
parents: 23596
diff changeset
198 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 else
9305
ac077e2a75f1 (Fstring_to_char, Fpoint, Fbufsize, Fpoint_min, Fpoint_max, Ffollowing_char,
Karl Heuer <kwzh@gnu.org>
parents: 9265
diff changeset
200 XSETFASTINT (val, 0);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 return val;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 static Lisp_Object
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
205 buildmark (charpos, bytepos)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
206 int charpos, bytepos;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 register Lisp_Object mark;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 mark = Fmake_marker ();
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
210 set_marker_both (mark, Qnil, charpos, bytepos);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 return mark;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 DEFUN ("point", Fpoint, Spoint, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
215 doc: /* Return value of point, as an integer.
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
216 Beginning of buffer is position (point-min). */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
217 ()
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 Lisp_Object temp;
16039
855c8d8ba0f0 Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents: 15910
diff changeset
220 XSETFASTINT (temp, PT);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 return temp;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 DEFUN ("point-marker", Fpoint_marker, Spoint_marker, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
225 doc: /* Return value of point, as a marker object. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
226 ()
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
228 return buildmark (PT, PT_BYTE);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 int
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 clip_to_bounds (lower, num, upper)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 int lower, num, upper;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 if (num < lower)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 return lower;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 else if (num > upper)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 return upper;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 else
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 return num;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 DEFUN ("goto-char", Fgoto_char, Sgoto_char, 1, 1, "NGoto char: ",
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
244 doc: /* Set point to POSITION, a number or marker.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
245 Beginning of buffer is position (point-min), end is (point-max).
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
246 If the position is in the middle of a multibyte form,
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
247 the actual point is set at the head of the multibyte form
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
248 except in the case that `enable-multibyte-characters' is nil. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
249 (position)
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
250 register Lisp_Object position;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 {
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
252 int pos;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
253
21226
c8d0df2cbd3d (Fgoto_char): If POSITION is a marker pointing a
Richard M. Stallman <rms@gnu.org>
parents: 21225
diff changeset
254 if (MARKERP (position)
c8d0df2cbd3d (Fgoto_char): If POSITION is a marker pointing a
Richard M. Stallman <rms@gnu.org>
parents: 21225
diff changeset
255 && current_buffer == XMARKER (position)->buffer)
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
256 {
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
257 pos = marker_position (position);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
258 if (pos < BEGV)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
259 SET_PT_BOTH (BEGV, BEGV_BYTE);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
260 else if (pos > ZV)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
261 SET_PT_BOTH (ZV, ZV_BYTE);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
262 else
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
263 SET_PT_BOTH (pos, marker_byte_position (position));
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
264
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
265 return position;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
266 }
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
267
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
268 CHECK_NUMBER_COERCE_MARKER (position, 0);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
270 pos = clip_to_bounds (BEGV, XINT (position), ZV);
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
271 SET_PT (pos);
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
272 return position;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
275
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
276 /* Return the start or end position of the region.
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
277 BEGINNINGP non-zero means return the start.
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
278 If there is no region active, signal an error. */
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
279
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 static Lisp_Object
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 region_limit (beginningp)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 int beginningp;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 {
4047
e950abdc9ed2 (region_limit): Declare Vmark_even_if_inactive.
Roland McGrath <roland@gnu.org>
parents: 4038
diff changeset
284 extern Lisp_Object Vmark_even_if_inactive; /* Defined in callint.c. */
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
285 Lisp_Object m;
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
286
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
287 if (!NILP (Vtransient_mark_mode)
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
288 && NILP (Vmark_even_if_inactive)
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
289 && 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
290 Fsignal (Qmark_inactive, Qnil);
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
291
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 m = Fmarker_position (current_buffer->mark);
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
293 if (NILP (m))
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
294 error ("There is no region now");
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
295
16039
855c8d8ba0f0 Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents: 15910
diff changeset
296 if ((PT < XFASTINT (m)) == beginningp)
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
297 m = make_number (PT);
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
298 return m;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 DEFUN ("region-beginning", Fregion_beginning, Sregion_beginning, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
302 doc: /* Return position of beginning of region, as an integer. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
303 ()
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 {
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
305 return region_limit (1);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 DEFUN ("region-end", Fregion_end, Sregion_end, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
309 doc: /* Return position of end of region, as an integer. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
310 ()
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 {
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
312 return region_limit (0);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 DEFUN ("mark-marker", Fmark_marker, Smark_marker, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
316 doc: /* Return this buffer's mark, as a marker object.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
317 Watch out! Moving this marker changes the mark position.
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
318 If you set the marker not to point anywhere, the buffer will have no mark. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
319 ()
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 return current_buffer->mark;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 }
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
323
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
324
37916
0b5642b0d6e4 (char_property_eq): Put in #if 0.
Gerd Moellmann <gerd@gnu.org>
parents: 37492
diff changeset
325 #if 0 /* Not used. */
0b5642b0d6e4 (char_property_eq): Put in #if 0.
Gerd Moellmann <gerd@gnu.org>
parents: 37492
diff changeset
326
26389
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
327 /* Return nonzero if POS1 and POS2 have the same value
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
328 for the text property PROP. */
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
329
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
330 static int
30244
bfc202f38a22 (char_property_eq, char_property_stickiness):
Miles Bader <miles@gnu.org>
parents: 30023
diff changeset
331 char_property_eq (prop, pos1, pos2)
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
332 Lisp_Object prop;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
333 Lisp_Object pos1, pos2;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
334 {
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
335 Lisp_Object pval1, pval2;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
336
30244
bfc202f38a22 (char_property_eq, char_property_stickiness):
Miles Bader <miles@gnu.org>
parents: 30023
diff changeset
337 pval1 = Fget_char_property (pos1, prop, Qnil);
bfc202f38a22 (char_property_eq, char_property_stickiness):
Miles Bader <miles@gnu.org>
parents: 30023
diff changeset
338 pval2 = Fget_char_property (pos2, prop, Qnil);
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
339
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
340 return EQ (pval1, pval2);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
341 }
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
342
37916
0b5642b0d6e4 (char_property_eq): Put in #if 0.
Gerd Moellmann <gerd@gnu.org>
parents: 37492
diff changeset
343 #endif /* 0 */
0b5642b0d6e4 (char_property_eq): Put in #if 0.
Gerd Moellmann <gerd@gnu.org>
parents: 37492
diff changeset
344
32850
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
345 /* Return the direction from which the text-property PROP would be
26389
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
346 inherited by any new text inserted at POS: 1 if it would be
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
347 inherited from the char after POS, -1 if it would be inherited from
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
348 the char before POS, and 0 if from neither. */
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
349
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
350 static int
32850
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
351 text_property_stickiness (prop, pos)
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
352 Lisp_Object prop;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
353 Lisp_Object pos;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
354 {
40046
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
355 Lisp_Object prev_pos, front_sticky;
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
356 int is_rear_sticky = 1, is_front_sticky = 0; /* defaults */
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
357
26389
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
358 if (XINT (pos) > BEGV)
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
359 /* Consider previous character. */
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
360 {
40046
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
361 Lisp_Object rear_non_sticky;
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
362
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
363 prev_pos = make_number (XINT (pos) - 1);
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
364 rear_non_sticky = Fget_text_property (prev_pos, Qrear_nonsticky, Qnil);
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
365
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
366 if (CONSP (rear_non_sticky)
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
367 ? Fmemq (prop, rear_non_sticky)
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
368 : !NILP (rear_non_sticky))
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
369 /* PROP is rear-non-sticky. */
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
370 is_rear_sticky = 0;
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
371 }
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
372
26389
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
373 /* Consider following character. */
32850
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
374 front_sticky = Fget_text_property (pos, Qfront_sticky, Qnil);
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
375
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
376 if (EQ (front_sticky, Qt)
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
377 || (CONSP (front_sticky)
28470
93996c44b23a * editfns.c (text_property_stickiness, Fmessage_or_box): Use NILP to test
Ken Raeburn <raeburn@raeburn.org>
parents: 28358
diff changeset
378 && !NILP (Fmemq (prop, front_sticky))))
26389
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
379 /* PROP is inherited from after. */
40046
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
380 is_front_sticky = 1;
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
381
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
382 /* Simple cases, where the properties are consistent. */
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
383 if (is_rear_sticky && !is_front_sticky)
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
384 return -1;
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
385 else if (!is_rear_sticky && is_front_sticky)
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
386 return 1;
40046
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
387 else if (!is_rear_sticky && !is_front_sticky)
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
388 return 0;
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
389
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
390 /* The stickiness properties are inconsistent, so we have to
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
391 disambiguate. Basically, rear-sticky wins, _except_ if the
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
392 property that would be inherited has a value of nil, in which case
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
393 front-sticky wins. */
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
394 if (XINT (pos) == BEGV || NILP (Fget_text_property (prev_pos, prop, Qnil)))
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
395 return 1;
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
396 else
5858ea32e564 (text_property_stickiness): Really fix it this time.
Miles Bader <miles@gnu.org>
parents: 40044
diff changeset
397 return -1;
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
398 }
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
399
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
400
26389
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
401 /* Find the field surrounding POS in *BEG and *END. If POS is nil,
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
402 the value of point is used instead. If BEG or END null,
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
403 means don't store the beginning or end of the field.
26389
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
404
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
405 If MERGE_AT_BOUNDARY is nonzero, then if POS is at the very first
30439
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
406 position of a field, then the beginning of the previous field is
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
407 returned instead of the beginning of POS's field (since the end of a
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
408 field is actually also the beginning of the next input field, this
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
409 behavior is sometimes useful). Additionally in the MERGE_AT_BOUNDARY
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
410 true case, if two fields are separated by a field with the special
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
411 value `boundary', and POS lies within it, then the two separated
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
412 fields are considered to be adjacent, and POS between them, when
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
413 finding the beginning and ending of the "merged" field.
26389
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
414
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
415 Either BEG or END may be 0, in which case the corresponding value
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
416 is not stored. */
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
417
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
418 static void
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
419 find_field (pos, merge_at_boundary, beg, end)
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
420 Lisp_Object pos;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
421 Lisp_Object merge_at_boundary;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
422 int *beg, *end;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
423 {
30439
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
424 /* Fields right before and after the point. */
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
425 Lisp_Object before_field, after_field;
32850
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
426 /* If the fields came from overlays, the associated overlays.
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
427 Qnil means they came from text-properties. */
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
428 Lisp_Object before_overlay = Qnil, after_overlay = Qnil;
26389
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
429 /* 1 if POS counts as the start of a field. */
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
430 int at_field_start = 0;
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
431 /* 1 if POS counts as the end of a field. */
e2acf63b5403 (Fline_beginning_position): If N is not 1,
Richard M. Stallman <rms@gnu.org>
parents: 26372
diff changeset
432 int at_field_end = 0;
30439
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
433
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
434 if (NILP (pos))
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
435 XSETFASTINT (pos, PT);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
436 else
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
437 CHECK_NUMBER_COERCE_MARKER (pos, 0);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
438
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
439 after_field
32850
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
440 = get_char_property_and_overlay (pos, Qfield, Qnil, &after_overlay);
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
441 before_field
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
442 = (XFASTINT (pos) > BEGV
32850
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
443 ? get_char_property_and_overlay (make_number (XINT (pos) - 1),
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
444 Qfield, Qnil,
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
445 &before_overlay)
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
446 : Qnil);
30439
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
447
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
448 /* See if we need to handle the case where MERGE_AT_BOUNDARY is nil
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
449 and POS is at beginning of a field, which can also be interpreted
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
450 as the end of the previous field. Note that the case where if
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
451 MERGE_AT_BOUNDARY is non-nil (see function comment) is actually the
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
452 more natural one; then we avoid treating the beginning of a field
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
453 specially. */
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
454 if (NILP (merge_at_boundary) && !EQ (after_field, before_field))
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
455 /* We are at a boundary, see which direction is inclusive. We
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
456 decide by seeing which field the `field' property sticks to. */
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
457 {
32850
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
458 /* -1 means insertions go into before_field, 1 means they go
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
459 into after_field, 0 means neither. */
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
460 int stickiness;
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
461 /* Whether the before/after_field come from overlays. */
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
462 int bop = !NILP (before_overlay);
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
463 int aop = !NILP (after_overlay);
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
464
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
465 if (bop && XMARKER (OVERLAY_END (before_overlay))->insertion_type == 1)
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
466 /* before_field is from an overlay, which expands upon
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
467 end-insertions. Note that it's possible for after_overlay to
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
468 also eat insertions here, but then they will overlap, and
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
469 there's not much we can do. */
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
470 stickiness = -1;
32857
e3c81dc17582 (find_field):
Miles Bader <miles@gnu.org>
parents: 32850
diff changeset
471 else if (aop
e3c81dc17582 (find_field):
Miles Bader <miles@gnu.org>
parents: 32850
diff changeset
472 && XMARKER (OVERLAY_START (after_overlay))->insertion_type == 0)
32850
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
473 /* after_field is from an overlay, which expand to contain
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
474 start-insertions. */
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
475 stickiness = 1;
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
476 else if (bop && aop)
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
477 /* Both fields come from overlays, but neither will contain any
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
478 insertion here. */
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
479 stickiness = 0;
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
480 else if (bop)
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
481 /* before_field is an overlay that won't eat any insertion, but
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
482 after_field is from a text-property. Assume that the
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
483 text-property continues underneath the overlay, and so will
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
484 be inherited by any insertion, regardless of any stickiness
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
485 settings. */
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
486 stickiness = 1;
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
487 else if (aop)
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
488 /* Similarly, when after_field is the overlay. */
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
489 stickiness = -1;
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
490 else
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
491 /* Both fields come from text-properties. Look for explicit
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
492 stickiness properties. */
6958fdfed738 (find_field):
Miles Bader <miles@gnu.org>
parents: 32517
diff changeset
493 stickiness = text_property_stickiness (Qfield, pos);
30439
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
494
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
495 if (stickiness > 0)
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
496 at_field_start = 1;
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
497 else if (stickiness < 0)
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
498 at_field_end = 1;
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
499 else
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
500 /* STICKINESS == 0 means that any inserted text will get a
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
501 `field' char-property of nil, so check to see if that
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
502 matches either of the adjacent characters (this being a
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
503 kind of "stickiness by default"). */
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
504 {
30439
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
505 if (NILP (before_field))
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
506 at_field_end = 1; /* Sticks to the left. */
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
507 else if (NILP (after_field))
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
508 at_field_start = 1; /* Sticks to the right. */
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
509 }
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
510 }
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
511
30439
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
512 /* Note about special `boundary' fields:
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
513
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
514 Consider the case where the point (`.') is between the fields `x' and `y':
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
515
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
516 xxxx.yyyy
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
517
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
518 In this situation, if merge_at_boundary is true, we consider the
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
519 `x' and `y' fields as forming one big merged field, and so the end
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
520 of the field is the end of `y'.
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
521
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
522 However, if `x' and `y' are separated by a special `boundary' field
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
523 (a field with a `field' char-property of 'boundary), then we ignore
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
524 this special field when merging adjacent fields. Here's the same
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
525 situation, but with a `boundary' field between the `x' and `y' fields:
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
526
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
527 xxx.BBBByyyy
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
528
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
529 Here, if point is at the end of `x', the beginning of `y', or
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
530 anywhere in-between (within the `boundary' field), we merge all
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
531 three fields and consider the beginning as being the beginning of
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
532 the `x' field, and the end as being the end of the `y' field. */
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
533
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
534 if (beg)
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
535 {
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
536 if (at_field_start)
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
537 /* POS is at the edge of a field, and we should consider it as
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
538 the beginning of the following field. */
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
539 *beg = XFASTINT (pos);
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
540 else
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
541 /* Find the previous field boundary. */
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
542 {
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
543 if (!NILP (merge_at_boundary) && EQ (before_field, Qboundary))
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
544 /* Skip a `boundary' field. */
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
545 pos = Fprevious_single_char_property_change (pos, Qfield, Qnil,Qnil);
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
546
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
547 pos = Fprevious_single_char_property_change (pos, Qfield, Qnil, Qnil);
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
548 *beg = NILP (pos) ? BEGV : XFASTINT (pos);
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
549 }
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
550 }
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
551
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
552 if (end)
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
553 {
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
554 if (at_field_end)
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
555 /* POS is at the edge of a field, and we should consider it as
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
556 the end of the previous field. */
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
557 *end = XFASTINT (pos);
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
558 else
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
559 /* Find the next field boundary. */
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
560 {
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
561 if (!NILP (merge_at_boundary) && EQ (after_field, Qboundary))
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
562 /* Skip a `boundary' field. */
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
563 pos = Fnext_single_char_property_change (pos, Qfield, Qnil, Qnil);
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
564
30439
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
565 pos = Fnext_single_char_property_change (pos, Qfield, Qnil, Qnil);
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
566 *end = NILP (pos) ? ZV : XFASTINT (pos);
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
567 }
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
568 }
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
569 }
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
570
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
571
26629
05dcbc266797 (Fdelete_field): Make it noninteractive. Return nil.
Richard M. Stallman <rms@gnu.org>
parents: 26526
diff changeset
572 DEFUN ("delete-field", Fdelete_field, Sdelete_field, 0, 1, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
573 doc: /* Delete the field surrounding POS.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
574 A field is a region of text with the same `field' property.
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
575 If POS is nil, the value of point is used for POS. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
576 (pos)
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
577 Lisp_Object pos;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
578 {
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
579 int beg, end;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
580 find_field (pos, Qnil, &beg, &end);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
581 if (beg != end)
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
582 del_range (beg, end);
26629
05dcbc266797 (Fdelete_field): Make it noninteractive. Return nil.
Richard M. Stallman <rms@gnu.org>
parents: 26526
diff changeset
583 return Qnil;
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
584 }
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
585
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
586 DEFUN ("field-string", Ffield_string, Sfield_string, 0, 1, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
587 doc: /* Return the contents of the field surrounding POS as a string.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
588 A field is a region of text with the same `field' property.
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
589 If POS is nil, the value of point is used for POS. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
590 (pos)
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
591 Lisp_Object pos;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
592 {
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
593 int beg, end;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
594 find_field (pos, Qnil, &beg, &end);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
595 return make_buffer_string (beg, end, 1);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
596 }
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
597
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
598 DEFUN ("field-string-no-properties", Ffield_string_no_properties, Sfield_string_no_properties, 0, 1, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
599 doc: /* Return the contents of the field around POS, without text-properties.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
600 A field is a region of text with the same `field' property.
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
601 If POS is nil, the value of point is used for POS. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
602 (pos)
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
603 Lisp_Object pos;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
604 {
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
605 int beg, end;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
606 find_field (pos, Qnil, &beg, &end);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
607 return make_buffer_string (beg, end, 0);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
608 }
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
609
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
610 DEFUN ("field-beginning", Ffield_beginning, Sfield_beginning, 0, 2, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
611 doc: /* Return the beginning of the field surrounding POS.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
612 A field is a region of text with the same `field' property.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
613 If POS is nil, the value of point is used for POS.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
614 If ESCAPE-FROM-EDGE is non-nil and POS is at the beginning of its
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
615 field, then the beginning of the *previous* field is returned. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
616 (pos, escape_from_edge)
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
617 Lisp_Object pos, escape_from_edge;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
618 {
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
619 int beg;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
620 find_field (pos, escape_from_edge, &beg, 0);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
621 return make_number (beg);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
622 }
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
623
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
624 DEFUN ("field-end", Ffield_end, Sfield_end, 0, 2, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
625 doc: /* Return the end of the field surrounding POS.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
626 A field is a region of text with the same `field' property.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
627 If POS is nil, the value of point is used for POS.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
628 If ESCAPE-FROM-EDGE is non-nil and POS is at the end of its field,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
629 then the end of the *following* field is returned. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
630 (pos, escape_from_edge)
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
631 Lisp_Object pos, escape_from_edge;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
632 {
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
633 int end;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
634 find_field (pos, escape_from_edge, 0, &end);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
635 return make_number (end);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
636 }
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
637
30439
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
638 DEFUN ("constrain-to-field", Fconstrain_to_field, Sconstrain_to_field, 2, 5, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
639 doc: /* Return the position closest to NEW-POS that is in the same field as OLD-POS.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
640
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
641 A field is a region of text with the same `field' property.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
642 If NEW-POS is nil, then the current point is used instead, and set to the
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
643 constrained position if that is different.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
644
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
645 If OLD-POS is at the boundary of two fields, then the allowable
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
646 positions for NEW-POS depends on the value of the optional argument
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
647 ESCAPE-FROM-EDGE: If ESCAPE-FROM-EDGE is nil, then NEW-POS is
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
648 constrained to the field that has the same `field' char-property
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
649 as any new characters inserted at OLD-POS, whereas if ESCAPE-FROM-EDGE
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
650 is non-nil, NEW-POS is constrained to the union of the two adjacent
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
651 fields. Additionally, if two fields are separated by another field with
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
652 the special value `boundary', then any point within this special field is
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
653 also considered to be `on the boundary'.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
654
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
655 If the optional argument ONLY-IN-LINE is non-nil and constraining
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
656 NEW-POS would move it to a different line, NEW-POS is returned
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
657 unconstrained. This useful for commands that move by line, like
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
658 \\[next-line] or \\[beginning-of-line], which should generally respect field boundaries
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
659 only in the case where they can still move to the right line.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
660
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
661 If the optional argument INHIBIT-CAPTURE-PROPERTY is non-nil, and OLD-POS has
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
662 a non-nil property of that name, then any field boundaries are ignored.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
663
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
664 Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
665 (new_pos, old_pos, escape_from_edge, only_in_line, inhibit_capture_property)
30439
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
666 Lisp_Object new_pos, old_pos;
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
667 Lisp_Object escape_from_edge, only_in_line, inhibit_capture_property;
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
668 {
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
669 /* If non-zero, then the original point, before re-positioning. */
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
670 int orig_point = 0;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
671
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
672 if (NILP (new_pos))
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
673 /* Use the current point, and afterwards, set it. */
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
674 {
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
675 orig_point = PT;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
676 XSETFASTINT (new_pos, PT);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
677 }
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
678
27081
f068649f1c28 (Fconstrain_to_field): Don't constrain if
Gerd Moellmann <gerd@gnu.org>
parents: 27077
diff changeset
679 if (NILP (Vinhibit_field_text_motion)
f068649f1c28 (Fconstrain_to_field): Don't constrain if
Gerd Moellmann <gerd@gnu.org>
parents: 27077
diff changeset
680 && !EQ (new_pos, old_pos)
32517
78c3fdea490c (Fconstrain_to_field): Check carefully for field boundaries if either
Miles Bader <miles@gnu.org>
parents: 32420
diff changeset
681 && (!NILP (Fget_char_property (new_pos, Qfield, Qnil))
78c3fdea490c (Fconstrain_to_field): Check carefully for field boundaries if either
Miles Bader <miles@gnu.org>
parents: 32420
diff changeset
682 || !NILP (Fget_char_property (old_pos, Qfield, Qnil)))
30439
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
683 && (NILP (inhibit_capture_property)
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
684 || NILP (Fget_char_property(old_pos, inhibit_capture_property, Qnil))))
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
685 /* NEW_POS is not within the same field as OLD_POS; try to
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
686 move NEW_POS so that it is. */
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
687 {
30439
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
688 int fwd, shortage;
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
689 Lisp_Object field_bound;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
690
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
691 CHECK_NUMBER_COERCE_MARKER (new_pos, 0);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
692 CHECK_NUMBER_COERCE_MARKER (old_pos, 0);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
693
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
694 fwd = (XFASTINT (new_pos) > XFASTINT (old_pos));
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
695
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
696 if (fwd)
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
697 field_bound = Ffield_end (old_pos, escape_from_edge);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
698 else
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
699 field_bound = Ffield_beginning (old_pos, escape_from_edge);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
700
30550
73040724e653 (Fconstrain_to_field): Fix the conditions for deciding when to constrain
Miles Bader <miles@gnu.org>
parents: 30503
diff changeset
701 if (/* See if ESCAPE_FROM_EDGE caused FIELD_BOUND to jump to the
73040724e653 (Fconstrain_to_field): Fix the conditions for deciding when to constrain
Miles Bader <miles@gnu.org>
parents: 30503
diff changeset
702 other side of NEW_POS, which would mean that NEW_POS is
73040724e653 (Fconstrain_to_field): Fix the conditions for deciding when to constrain
Miles Bader <miles@gnu.org>
parents: 30503
diff changeset
703 already acceptable, and it's not necessary to constrain it
73040724e653 (Fconstrain_to_field): Fix the conditions for deciding when to constrain
Miles Bader <miles@gnu.org>
parents: 30503
diff changeset
704 to FIELD_BOUND. */
73040724e653 (Fconstrain_to_field): Fix the conditions for deciding when to constrain
Miles Bader <miles@gnu.org>
parents: 30503
diff changeset
705 ((XFASTINT (field_bound) < XFASTINT (new_pos)) ? fwd : !fwd)
73040724e653 (Fconstrain_to_field): Fix the conditions for deciding when to constrain
Miles Bader <miles@gnu.org>
parents: 30503
diff changeset
706 /* NEW_POS should be constrained, but only if either
73040724e653 (Fconstrain_to_field): Fix the conditions for deciding when to constrain
Miles Bader <miles@gnu.org>
parents: 30503
diff changeset
707 ONLY_IN_LINE is nil (in which case any constraint is OK),
73040724e653 (Fconstrain_to_field): Fix the conditions for deciding when to constrain
Miles Bader <miles@gnu.org>
parents: 30503
diff changeset
708 or NEW_POS and FIELD_BOUND are on the same line (in which
73040724e653 (Fconstrain_to_field): Fix the conditions for deciding when to constrain
Miles Bader <miles@gnu.org>
parents: 30503
diff changeset
709 case the constraint is OK even if ONLY_IN_LINE is non-nil). */
73040724e653 (Fconstrain_to_field): Fix the conditions for deciding when to constrain
Miles Bader <miles@gnu.org>
parents: 30503
diff changeset
710 && (NILP (only_in_line)
73040724e653 (Fconstrain_to_field): Fix the conditions for deciding when to constrain
Miles Bader <miles@gnu.org>
parents: 30503
diff changeset
711 /* This is the ONLY_IN_LINE case, check that NEW_POS and
73040724e653 (Fconstrain_to_field): Fix the conditions for deciding when to constrain
Miles Bader <miles@gnu.org>
parents: 30503
diff changeset
712 FIELD_BOUND are on the same line by seeing whether
73040724e653 (Fconstrain_to_field): Fix the conditions for deciding when to constrain
Miles Bader <miles@gnu.org>
parents: 30503
diff changeset
713 there's an intervening newline or not. */
73040724e653 (Fconstrain_to_field): Fix the conditions for deciding when to constrain
Miles Bader <miles@gnu.org>
parents: 30503
diff changeset
714 || (scan_buffer ('\n',
73040724e653 (Fconstrain_to_field): Fix the conditions for deciding when to constrain
Miles Bader <miles@gnu.org>
parents: 30503
diff changeset
715 XFASTINT (new_pos), XFASTINT (field_bound),
73040724e653 (Fconstrain_to_field): Fix the conditions for deciding when to constrain
Miles Bader <miles@gnu.org>
parents: 30503
diff changeset
716 fwd ? -1 : 1, &shortage, 1),
73040724e653 (Fconstrain_to_field): Fix the conditions for deciding when to constrain
Miles Bader <miles@gnu.org>
parents: 30503
diff changeset
717 shortage != 0)))
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
718 /* Constrain NEW_POS to FIELD_BOUND. */
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
719 new_pos = field_bound;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
720
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
721 if (orig_point && XFASTINT (new_pos) != orig_point)
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
722 /* The NEW_POS argument was originally nil, so automatically set PT. */
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
723 SET_PT (XFASTINT (new_pos));
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
724 }
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
725
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
726 return new_pos;
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
727 }
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
728
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
729
40042
c9ad5da1f79d (Fline_beginning_position, Fline_end_position): Clarify documentation.
Miles Bader <miles@gnu.org>
parents: 39988
diff changeset
730 DEFUN ("line-beginning-position",
c9ad5da1f79d (Fline_beginning_position, Fline_end_position): Clarify documentation.
Miles Bader <miles@gnu.org>
parents: 39988
diff changeset
731 Fline_beginning_position, Sline_beginning_position, 0, 1, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
732 doc: /* Return the character position of the first character on the current line.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
733 With argument N not nil or 1, move forward N - 1 lines first.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
734 If scan reaches end of buffer, return that position.
40042
c9ad5da1f79d (Fline_beginning_position, Fline_end_position): Clarify documentation.
Miles Bader <miles@gnu.org>
parents: 39988
diff changeset
735
c9ad5da1f79d (Fline_beginning_position, Fline_end_position): Clarify documentation.
Miles Bader <miles@gnu.org>
parents: 39988
diff changeset
736 The scan does not cross a field boundary unless doing so would move
c9ad5da1f79d (Fline_beginning_position, Fline_end_position): Clarify documentation.
Miles Bader <miles@gnu.org>
parents: 39988
diff changeset
737 beyond there to a different line; if N is nil or 1, and scan starts at a
c9ad5da1f79d (Fline_beginning_position, Fline_end_position): Clarify documentation.
Miles Bader <miles@gnu.org>
parents: 39988
diff changeset
738 field boundary, the scan stops as soon as it starts. To ignore field
c9ad5da1f79d (Fline_beginning_position, Fline_end_position): Clarify documentation.
Miles Bader <miles@gnu.org>
parents: 39988
diff changeset
739 boundaries bind `inhibit-field-text-motion' to t.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
740
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
741 This function does not move point. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
742 (n)
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
743 Lisp_Object n;
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
744 {
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
745 int orig, orig_byte, end;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
746
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
747 if (NILP (n))
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
748 XSETFASTINT (n, 1);
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
749 else
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
750 CHECK_NUMBER (n, 0);
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
751
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
752 orig = PT;
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
753 orig_byte = PT_BYTE;
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
754 Fforward_line (make_number (XINT (n) - 1));
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
755 end = PT;
25647
947cb0e32a1d (Fline_beginning_position): Handle minibuffer prompt here.
Richard M. Stallman <rms@gnu.org>
parents: 25609
diff changeset
756
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
757 SET_PT_BOTH (orig, orig_byte);
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
758
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
759 /* Return END constrained to the current input field. */
27081
f068649f1c28 (Fconstrain_to_field): Don't constrain if
Gerd Moellmann <gerd@gnu.org>
parents: 27077
diff changeset
760 return Fconstrain_to_field (make_number (end), make_number (orig),
f068649f1c28 (Fconstrain_to_field): Don't constrain if
Gerd Moellmann <gerd@gnu.org>
parents: 27077
diff changeset
761 XINT (n) != 1 ? Qt : Qnil,
30439
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
762 Qt, Qnil);
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
763 }
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
764
40042
c9ad5da1f79d (Fline_beginning_position, Fline_end_position): Clarify documentation.
Miles Bader <miles@gnu.org>
parents: 39988
diff changeset
765 DEFUN ("line-end-position", Fline_end_position, Sline_end_position, 0, 1, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
766 doc: /* Return the character position of the last character on the current line.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
767 With argument N not nil or 1, move forward N - 1 lines first.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
768 If scan reaches end of buffer, return that position.
40042
c9ad5da1f79d (Fline_beginning_position, Fline_end_position): Clarify documentation.
Miles Bader <miles@gnu.org>
parents: 39988
diff changeset
769
c9ad5da1f79d (Fline_beginning_position, Fline_end_position): Clarify documentation.
Miles Bader <miles@gnu.org>
parents: 39988
diff changeset
770 The scan does not cross a field boundary unless doing so would move
c9ad5da1f79d (Fline_beginning_position, Fline_end_position): Clarify documentation.
Miles Bader <miles@gnu.org>
parents: 39988
diff changeset
771 beyond there to a different line; if N is nil or 1, and scan starts at a
c9ad5da1f79d (Fline_beginning_position, Fline_end_position): Clarify documentation.
Miles Bader <miles@gnu.org>
parents: 39988
diff changeset
772 field boundary, the scan stops as soon as it starts. To ignore field
c9ad5da1f79d (Fline_beginning_position, Fline_end_position): Clarify documentation.
Miles Bader <miles@gnu.org>
parents: 39988
diff changeset
773 boundaries bind `inhibit-field-text-motion' to t.
c9ad5da1f79d (Fline_beginning_position, Fline_end_position): Clarify documentation.
Miles Bader <miles@gnu.org>
parents: 39988
diff changeset
774
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
775 This function does not move point. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
776 (n)
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
777 Lisp_Object n;
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
778 {
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
779 int end_pos;
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
780 int orig = PT;
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
781
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
782 if (NILP (n))
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
783 XSETFASTINT (n, 1);
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
784 else
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
785 CHECK_NUMBER (n, 0);
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
786
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
787 end_pos = find_before_next_newline (orig, 0, XINT (n) - (XINT (n) <= 0));
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
788
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
789 /* Return END_POS constrained to the current input field. */
27081
f068649f1c28 (Fconstrain_to_field): Don't constrain if
Gerd Moellmann <gerd@gnu.org>
parents: 27077
diff changeset
790 return Fconstrain_to_field (make_number (end_pos), make_number (orig),
30439
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
791 Qnil, Qt, Qnil);
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
792 }
40042
c9ad5da1f79d (Fline_beginning_position, Fline_end_position): Clarify documentation.
Miles Bader <miles@gnu.org>
parents: 39988
diff changeset
793
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
794
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
795 Lisp_Object
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
796 save_excursion_save ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
797 {
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
798 int visible = (XBUFFER (XWINDOW (selected_window)->buffer)
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
799 == current_buffer);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
800
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
801 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
802 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
803 Fcons (visible ? Qt : Qnil,
32420
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
804 Fcons (current_buffer->mark_active,
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
805 selected_window))));
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
806 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
807
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
808 Lisp_Object
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
809 save_excursion_restore (info)
15075
e8613675066c (save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents: 15015
diff changeset
810 Lisp_Object info;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
811 {
15075
e8613675066c (save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents: 15015
diff changeset
812 Lisp_Object tem, tem1, omark, nmark;
e8613675066c (save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents: 15015
diff changeset
813 struct gcpro gcpro1, gcpro2, gcpro3;
32420
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
814 int visible_p;
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
815
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
816 tem = Fmarker_buffer (XCAR (info));
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
817 /* If buffer being returned to is now deleted, avoid error */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
818 /* Otherwise could get error here while unwinding to top level
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
819 and crash */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
820 /* In that case, Fmarker_buffer returns nil now. */
488
4fddd0f0fc33 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 448
diff changeset
821 if (NILP (tem))
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
822 return Qnil;
15075
e8613675066c (save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents: 15015
diff changeset
823
e8613675066c (save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents: 15015
diff changeset
824 omark = nmark = Qnil;
e8613675066c (save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents: 15015
diff changeset
825 GCPRO3 (info, omark, nmark);
e8613675066c (save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents: 15015
diff changeset
826
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
827 Fset_buffer (tem);
32420
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
828
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
829 /* Point marker. */
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
830 tem = XCAR (info);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
831 Fgoto_char (tem);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
832 unchain_marker (tem);
32420
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
833
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
834 /* Mark marker. */
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
835 info = XCDR (info);
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
836 tem = XCAR (info);
7485
a1b7f72e0ea2 (save_excursion_restore): Don't run activate-mark-hook
Richard M. Stallman <rms@gnu.org>
parents: 7307
diff changeset
837 omark = Fmarker_position (current_buffer->mark);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
838 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
839 nmark = Fmarker_position (tem);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
840 unchain_marker (tem);
32420
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
841
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
842 /* visible */
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
843 info = XCDR (info);
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
844 visible_p = !NILP (XCAR (info));
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
845
4420
8113d9ba472e (save_excursion_restore): Never make the buffer visible.
Richard M. Stallman <rms@gnu.org>
parents: 4358
diff changeset
846 #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
847 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
848 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
849 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
850 tem1 = Fcar (tem);
a358c97a23e4 (save_excursion_save): Save mark_active of buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1916
diff changeset
851 if (!NILP (tem1)
1254
c7e7e3438711 * editfns.c (save_excursion_save, save_excursion_restore):
Jim Blandy <jimb@redhat.com>
parents: 1117
diff changeset
852 && current_buffer != XBUFFER (XWINDOW (selected_window)->buffer))
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
853 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
854 #endif /* 0 */
2049
a358c97a23e4 (save_excursion_save): Save mark_active of buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1916
diff changeset
855
32420
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
856 /* Mark active */
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
857 info = XCDR (info);
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
858 tem = XCAR (info);
2049
a358c97a23e4 (save_excursion_save): Save mark_active of buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1916
diff changeset
859 tem1 = current_buffer->mark_active;
32420
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
860 current_buffer->mark_active = tem;
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
861
6206
67c608b0e2f7 (save_excursion_restore): Don't call Vrun_hooks if nil.
Richard M. Stallman <rms@gnu.org>
parents: 5915
diff changeset
862 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
863 {
7485
a1b7f72e0ea2 (save_excursion_restore): Don't run activate-mark-hook
Richard M. Stallman <rms@gnu.org>
parents: 7307
diff changeset
864 /* 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
865 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
866 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
867 {
a1b7f72e0ea2 (save_excursion_restore): Don't run activate-mark-hook
Richard M. Stallman <rms@gnu.org>
parents: 7307
diff changeset
868 if (! EQ (omark, nmark))
a1b7f72e0ea2 (save_excursion_restore): Don't run activate-mark-hook
Richard M. Stallman <rms@gnu.org>
parents: 7307
diff changeset
869 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
870 }
a1b7f72e0ea2 (save_excursion_restore): Don't run activate-mark-hook
Richard M. Stallman <rms@gnu.org>
parents: 7307
diff changeset
871 /* 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
872 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
873 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
874 }
32420
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
875
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
876 /* If buffer was visible in a window, and a different window was
34165
3b3a64fbcb05 (save_excursion_restore): Don't move point
Gerd Moellmann <gerd@gnu.org>
parents: 32857
diff changeset
877 selected, and the old selected window is still showing this
3b3a64fbcb05 (save_excursion_restore): Don't move point
Gerd Moellmann <gerd@gnu.org>
parents: 32857
diff changeset
878 buffer, restore point in that window. */
32420
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
879 tem = XCDR (info);
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
880 if (visible_p
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
881 && !EQ (tem, selected_window)
37492
b9cea35cf91f (save_excursion_restore): Don't use XBUFFER on
Gerd Moellmann <gerd@gnu.org>
parents: 37217
diff changeset
882 && (tem1 = XWINDOW (tem)->buffer,
b9cea35cf91f (save_excursion_restore): Don't use XBUFFER on
Gerd Moellmann <gerd@gnu.org>
parents: 37217
diff changeset
883 (/* Window is live... */
b9cea35cf91f (save_excursion_restore): Don't use XBUFFER on
Gerd Moellmann <gerd@gnu.org>
parents: 37217
diff changeset
884 BUFFERP (tem1)
b9cea35cf91f (save_excursion_restore): Don't use XBUFFER on
Gerd Moellmann <gerd@gnu.org>
parents: 37217
diff changeset
885 /* ...and it shows the current buffer. */
b9cea35cf91f (save_excursion_restore): Don't use XBUFFER on
Gerd Moellmann <gerd@gnu.org>
parents: 37217
diff changeset
886 && XBUFFER (tem1) == current_buffer)))
32420
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
887 Fset_window_point (tem, make_number (PT));
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
888
15075
e8613675066c (save_excursion_restore): Add gcpros.
Richard M. Stallman <rms@gnu.org>
parents: 15015
diff changeset
889 UNGCPRO;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
890 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
891 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
892
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
893 DEFUN ("save-excursion", Fsave_excursion, Ssave_excursion, 0, UNEVALLED, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
894 doc: /* Save point, mark, and current buffer; execute BODY; restore those things.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
895 Executes BODY just like `progn'.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
896 The values of point, mark and the current buffer are restored
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
897 even in case of abnormal exit (throw or error).
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
898 The state of activation of the mark is also restored.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
899
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
900 This construct does not save `deactivate-mark', and therefore
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
901 functions that change the buffer will still cause deactivation
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
902 of the mark at the end of the command. To prevent that, bind
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
903 `deactivate-mark' with `let'. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
904 (args)
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
905 Lisp_Object args;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
906 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
907 register Lisp_Object val;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
908 int count = specpdl_ptr - specpdl;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
909
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
910 record_unwind_protect (save_excursion_restore, save_excursion_save ());
16298
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
911
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
912 val = Fprogn (args);
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
913 return unbind_to (count, val);
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
914 }
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
915
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
916 DEFUN ("save-current-buffer", Fsave_current_buffer, Ssave_current_buffer, 0, UNEVALLED, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
917 doc: /* Save the current buffer; execute BODY; restore the current buffer.
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
918 Executes BODY just like `progn'. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
919 (args)
16298
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
920 Lisp_Object args;
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
921 {
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
922 Lisp_Object val;
16298
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
923 int count = specpdl_ptr - specpdl;
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
924
20696
cdbe4824e7f1 (Fsave_current_buffer): Use set_buffer_if_live.
Richard M. Stallman <rms@gnu.org>
parents: 20688
diff changeset
925 record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ());
16298
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
926
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
927 val = Fprogn (args);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
928 return unbind_to (count, val);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
929 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
930
25608
1cdab17df2b3 (Fbufsize): Accept an extra BUFFER parameter.
Richard M. Stallman <rms@gnu.org>
parents: 25507
diff changeset
931 DEFUN ("buffer-size", Fbufsize, Sbufsize, 0, 1, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
932 doc: /* Return the number of characters in the current buffer.
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
933 If BUFFER, return the number of characters in that buffer instead. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
934 (buffer)
25608
1cdab17df2b3 (Fbufsize): Accept an extra BUFFER parameter.
Richard M. Stallman <rms@gnu.org>
parents: 25507
diff changeset
935 Lisp_Object buffer;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
936 {
25608
1cdab17df2b3 (Fbufsize): Accept an extra BUFFER parameter.
Richard M. Stallman <rms@gnu.org>
parents: 25507
diff changeset
937 if (NILP (buffer))
1cdab17df2b3 (Fbufsize): Accept an extra BUFFER parameter.
Richard M. Stallman <rms@gnu.org>
parents: 25507
diff changeset
938 return make_number (Z - BEG);
25609
157f0e91232e Clear up previous change.
Richard M. Stallman <rms@gnu.org>
parents: 25608
diff changeset
939 else
157f0e91232e Clear up previous change.
Richard M. Stallman <rms@gnu.org>
parents: 25608
diff changeset
940 {
157f0e91232e Clear up previous change.
Richard M. Stallman <rms@gnu.org>
parents: 25608
diff changeset
941 CHECK_BUFFER (buffer, 1);
157f0e91232e Clear up previous change.
Richard M. Stallman <rms@gnu.org>
parents: 25608
diff changeset
942 return make_number (BUF_Z (XBUFFER (buffer))
157f0e91232e Clear up previous change.
Richard M. Stallman <rms@gnu.org>
parents: 25608
diff changeset
943 - BUF_BEG (XBUFFER (buffer)));
157f0e91232e Clear up previous change.
Richard M. Stallman <rms@gnu.org>
parents: 25608
diff changeset
944 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
945 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
946
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
947 DEFUN ("point-min", Fpoint_min, Spoint_min, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
948 doc: /* Return the minimum permissible value of point in the current buffer.
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
949 This is 1, unless narrowing (a buffer restriction) is in effect. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
950 ()
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
951 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
952 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
953 XSETFASTINT (temp, BEGV);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
954 return temp;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
955 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
956
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
957 DEFUN ("point-min-marker", Fpoint_min_marker, Spoint_min_marker, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
958 doc: /* Return a marker to the minimum permissible value of point in this buffer.
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
959 This is the beginning, unless narrowing (a buffer restriction) is in effect. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
960 ()
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
961 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
962 return buildmark (BEGV, BEGV_BYTE);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
963 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
964
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
965 DEFUN ("point-max", Fpoint_max, Spoint_max, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
966 doc: /* Return the maximum permissible value of point in the current buffer.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
967 This is (1+ (buffer-size)), unless narrowing (a buffer restriction)
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
968 is in effect, in which case it is less. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
969 ()
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
970 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
971 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
972 XSETFASTINT (temp, ZV);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
973 return temp;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
974 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
975
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
976 DEFUN ("point-max-marker", Fpoint_max_marker, Spoint_max_marker, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
977 doc: /* Return a marker to the maximum permissible value of point in this buffer.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
978 This is (1+ (buffer-size)), unless narrowing (a buffer restriction)
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
979 is in effect, in which case it is less. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
980 ()
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
981 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
982 return buildmark (ZV, ZV_BYTE);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
983 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
984
21821
9e82920b194d (Fgap_position, Fgap_size): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 21717
diff changeset
985 DEFUN ("gap-position", Fgap_position, Sgap_position, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
986 doc: /* Return the position of the gap, in the current buffer.
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
987 See also `gap-size'. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
988 ()
21821
9e82920b194d (Fgap_position, Fgap_size): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 21717
diff changeset
989 {
9e82920b194d (Fgap_position, Fgap_size): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 21717
diff changeset
990 Lisp_Object temp;
9e82920b194d (Fgap_position, Fgap_size): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 21717
diff changeset
991 XSETFASTINT (temp, GPT);
9e82920b194d (Fgap_position, Fgap_size): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 21717
diff changeset
992 return temp;
9e82920b194d (Fgap_position, Fgap_size): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 21717
diff changeset
993 }
9e82920b194d (Fgap_position, Fgap_size): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 21717
diff changeset
994
9e82920b194d (Fgap_position, Fgap_size): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 21717
diff changeset
995 DEFUN ("gap-size", Fgap_size, Sgap_size, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
996 doc: /* Return the size of the current buffer's gap.
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
997 See also `gap-position'. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
998 ()
21821
9e82920b194d (Fgap_position, Fgap_size): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 21717
diff changeset
999 {
9e82920b194d (Fgap_position, Fgap_size): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 21717
diff changeset
1000 Lisp_Object temp;
9e82920b194d (Fgap_position, Fgap_size): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 21717
diff changeset
1001 XSETFASTINT (temp, GAP_SIZE);
9e82920b194d (Fgap_position, Fgap_size): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 21717
diff changeset
1002 return temp;
9e82920b194d (Fgap_position, Fgap_size): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 21717
diff changeset
1003 }
9e82920b194d (Fgap_position, Fgap_size): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 21717
diff changeset
1004
20861
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
1005 DEFUN ("position-bytes", Fposition_bytes, Sposition_bytes, 1, 1, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1006 doc: /* Return the byte position for character position POSITION.
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1007 If POSITION is out of range, the value is nil. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1008 (position)
20879
64d2baa47498 (Fposition_bytes): Declare arg POSITION as Lips_Object.
Kenichi Handa <handa@m17n.org>
parents: 20878
diff changeset
1009 Lisp_Object position;
20861
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
1010 {
20878
34e0c8eb49eb (Fposition_bytes): Allow marker as arg POSITION. Use
Kenichi Handa <handa@m17n.org>
parents: 20861
diff changeset
1011 CHECK_NUMBER_COERCE_MARKER (position, 1);
23132
1c8e0e09aea1 (Fposition_bytes): If the arg POSITION is out of
Kenichi Handa <handa@m17n.org>
parents: 23063
diff changeset
1012 if (XINT (position) < BEG || XINT (position) > Z)
1c8e0e09aea1 (Fposition_bytes): If the arg POSITION is out of
Kenichi Handa <handa@m17n.org>
parents: 23063
diff changeset
1013 return Qnil;
20878
34e0c8eb49eb (Fposition_bytes): Allow marker as arg POSITION. Use
Kenichi Handa <handa@m17n.org>
parents: 20861
diff changeset
1014 return make_number (CHAR_TO_BYTE (XINT (position)));
20861
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
1015 }
22645
e5b201634497 (Fbyte_to_position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22199
diff changeset
1016
e5b201634497 (Fbyte_to_position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22199
diff changeset
1017 DEFUN ("byte-to-position", Fbyte_to_position, Sbyte_to_position, 1, 1, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1018 doc: /* Return the character position for byte position BYTEPOS.
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1019 If BYTEPOS is out of range, the value is nil. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1020 (bytepos)
22645
e5b201634497 (Fbyte_to_position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22199
diff changeset
1021 Lisp_Object bytepos;
e5b201634497 (Fbyte_to_position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22199
diff changeset
1022 {
e5b201634497 (Fbyte_to_position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22199
diff changeset
1023 CHECK_NUMBER (bytepos, 1);
23132
1c8e0e09aea1 (Fposition_bytes): If the arg POSITION is out of
Kenichi Handa <handa@m17n.org>
parents: 23063
diff changeset
1024 if (XINT (bytepos) < BEG_BYTE || XINT (bytepos) > Z_BYTE)
1c8e0e09aea1 (Fposition_bytes): If the arg POSITION is out of
Kenichi Handa <handa@m17n.org>
parents: 23063
diff changeset
1025 return Qnil;
22645
e5b201634497 (Fbyte_to_position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22199
diff changeset
1026 return make_number (BYTE_TO_CHAR (XINT (bytepos)));
e5b201634497 (Fbyte_to_position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22199
diff changeset
1027 }
20861
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
1028
512
b7a1e4e4e7e6 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 488
diff changeset
1029 DEFUN ("following-char", Ffollowing_char, Sfollowing_char, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1030 doc: /* Return the character following point, as a number.
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1031 At the end of the buffer or accessible region, return 0. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1032 ()
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1033 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1034 Lisp_Object temp;
16039
855c8d8ba0f0 Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents: 15910
diff changeset
1035 if (PT >= ZV)
9305
ac077e2a75f1 (Fstring_to_char, Fpoint, Fbufsize, Fpoint_min, Fpoint_max, Ffollowing_char,
Karl Heuer <kwzh@gnu.org>
parents: 9265
diff changeset
1036 XSETFASTINT (temp, 0);
512
b7a1e4e4e7e6 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 488
diff changeset
1037 else
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1038 XSETFASTINT (temp, FETCH_CHAR (PT_BYTE));
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1039 return temp;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1040 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1041
512
b7a1e4e4e7e6 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 488
diff changeset
1042 DEFUN ("preceding-char", Fprevious_char, Sprevious_char, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1043 doc: /* Return the character preceding point, as a number.
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1044 At the beginning of the buffer or accessible region, return 0. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1045 ()
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1046 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1047 Lisp_Object temp;
16039
855c8d8ba0f0 Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents: 15910
diff changeset
1048 if (PT <= BEGV)
9305
ac077e2a75f1 (Fstring_to_char, Fpoint, Fbufsize, Fpoint_min, Fpoint_max, Ffollowing_char,
Karl Heuer <kwzh@gnu.org>
parents: 9265
diff changeset
1049 XSETFASTINT (temp, 0);
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1050 else if (!NILP (current_buffer->enable_multibyte_characters))
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1051 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1052 int pos = PT_BYTE;
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1053 DEC_POS (pos);
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1054 XSETFASTINT (temp, FETCH_CHAR (pos));
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1055 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1056 else
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1057 XSETFASTINT (temp, FETCH_BYTE (PT_BYTE - 1));
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1058 return temp;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1059 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1060
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1061 DEFUN ("bobp", Fbobp, Sbobp, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1062 doc: /* Return t if point is at the beginning of the buffer.
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1063 If the buffer is narrowed, this means the beginning of the narrowed part. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1064 ()
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1065 {
16039
855c8d8ba0f0 Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents: 15910
diff changeset
1066 if (PT == BEGV)
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1067 return Qt;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1068 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1069 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1070
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1071 DEFUN ("eobp", Feobp, Seobp, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1072 doc: /* Return t if point is at the end of the buffer.
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1073 If the buffer is narrowed, this means the end of the narrowed part. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1074 ()
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1075 {
16039
855c8d8ba0f0 Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents: 15910
diff changeset
1076 if (PT == ZV)
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1077 return Qt;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1078 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1079 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1080
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1081 DEFUN ("bolp", Fbolp, Sbolp, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1082 doc: /* Return t if point is at the beginning of a line. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1083 ()
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1084 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1085 if (PT == BEGV || FETCH_BYTE (PT_BYTE - 1) == '\n')
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1086 return Qt;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1087 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1088 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1089
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1090 DEFUN ("eolp", Feolp, Seolp, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1091 doc: /* Return t if point is at the end of a line.
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1092 `End of a line' includes point being at the end of the buffer. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1093 ()
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1094 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1095 if (PT == ZV || FETCH_BYTE (PT_BYTE) == '\n')
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1096 return Qt;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1097 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1098 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1099
18252
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
1100 DEFUN ("char-after", Fchar_after, Schar_after, 0, 1, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1101 doc: /* Return character in current buffer at position POS.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1102 POS is an integer or a marker.
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1103 If POS is out of range, the value is nil. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1104 (pos)
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1105 Lisp_Object pos;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1106 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1107 register int pos_byte;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1108
18252
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
1109 if (NILP (pos))
22199
edca9002c740 (Fchar_after): Make nil fully equivalent to (point) as arg.
Richard M. Stallman <rms@gnu.org>
parents: 21914
diff changeset
1110 {
edca9002c740 (Fchar_after): Make nil fully equivalent to (point) as arg.
Richard M. Stallman <rms@gnu.org>
parents: 21914
diff changeset
1111 pos_byte = PT_BYTE;
23577
36cccf1ba0a9 (Fchar_after): Fix type clashes.
Andreas Schwab <schwab@suse.de>
parents: 23565
diff changeset
1112 XSETFASTINT (pos, PT);
22199
edca9002c740 (Fchar_after): Make nil fully equivalent to (point) as arg.
Richard M. Stallman <rms@gnu.org>
parents: 21914
diff changeset
1113 }
edca9002c740 (Fchar_after): Make nil fully equivalent to (point) as arg.
Richard M. Stallman <rms@gnu.org>
parents: 21914
diff changeset
1114
edca9002c740 (Fchar_after): Make nil fully equivalent to (point) as arg.
Richard M. Stallman <rms@gnu.org>
parents: 21914
diff changeset
1115 if (MARKERP (pos))
21200
ea520c42a342 (Fchar_after, Fchar_before): Properly check arg type
Richard M. Stallman <rms@gnu.org>
parents: 21064
diff changeset
1116 {
ea520c42a342 (Fchar_after, Fchar_before): Properly check arg type
Richard M. Stallman <rms@gnu.org>
parents: 21064
diff changeset
1117 pos_byte = marker_byte_position (pos);
ea520c42a342 (Fchar_after, Fchar_before): Properly check arg type
Richard M. Stallman <rms@gnu.org>
parents: 21064
diff changeset
1118 if (pos_byte < BEGV_BYTE || pos_byte >= ZV_BYTE)
ea520c42a342 (Fchar_after, Fchar_before): Properly check arg type
Richard M. Stallman <rms@gnu.org>
parents: 21064
diff changeset
1119 return Qnil;
ea520c42a342 (Fchar_after, Fchar_before): Properly check arg type
Richard M. Stallman <rms@gnu.org>
parents: 21064
diff changeset
1120 }
18252
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
1121 else
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
1122 {
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
1123 CHECK_NUMBER_COERCE_MARKER (pos, 0);
21521
354a7085f1d7 (Fchar_after, Fchar_before): Fix mixing of Lisp_Object
Andreas Schwab <schwab@suse.de>
parents: 21514
diff changeset
1124 if (XINT (pos) < BEGV || XINT (pos) >= ZV)
21200
ea520c42a342 (Fchar_after, Fchar_before): Properly check arg type
Richard M. Stallman <rms@gnu.org>
parents: 21064
diff changeset
1125 return Qnil;
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1126
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1127 pos_byte = CHAR_TO_BYTE (XINT (pos));
18252
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
1128 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1129
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1130 return make_number (FETCH_CHAR (pos_byte));
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1131 }
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1132
18252
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
1133 DEFUN ("char-before", Fchar_before, Schar_before, 0, 1, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1134 doc: /* Return character in current buffer preceding position POS.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1135 POS is an integer or a marker.
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1136 If POS is out of range, the value is nil. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1137 (pos)
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1138 Lisp_Object pos;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1139 {
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1140 register Lisp_Object val;
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1141 register int pos_byte;
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1142
18252
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
1143 if (NILP (pos))
22199
edca9002c740 (Fchar_after): Make nil fully equivalent to (point) as arg.
Richard M. Stallman <rms@gnu.org>
parents: 21914
diff changeset
1144 {
edca9002c740 (Fchar_after): Make nil fully equivalent to (point) as arg.
Richard M. Stallman <rms@gnu.org>
parents: 21914
diff changeset
1145 pos_byte = PT_BYTE;
23577
36cccf1ba0a9 (Fchar_after): Fix type clashes.
Andreas Schwab <schwab@suse.de>
parents: 23565
diff changeset
1146 XSETFASTINT (pos, PT);
22199
edca9002c740 (Fchar_after): Make nil fully equivalent to (point) as arg.
Richard M. Stallman <rms@gnu.org>
parents: 21914
diff changeset
1147 }
edca9002c740 (Fchar_after): Make nil fully equivalent to (point) as arg.
Richard M. Stallman <rms@gnu.org>
parents: 21914
diff changeset
1148
edca9002c740 (Fchar_after): Make nil fully equivalent to (point) as arg.
Richard M. Stallman <rms@gnu.org>
parents: 21914
diff changeset
1149 if (MARKERP (pos))
21200
ea520c42a342 (Fchar_after, Fchar_before): Properly check arg type
Richard M. Stallman <rms@gnu.org>
parents: 21064
diff changeset
1150 {
ea520c42a342 (Fchar_after, Fchar_before): Properly check arg type
Richard M. Stallman <rms@gnu.org>
parents: 21064
diff changeset
1151 pos_byte = marker_byte_position (pos);
ea520c42a342 (Fchar_after, Fchar_before): Properly check arg type
Richard M. Stallman <rms@gnu.org>
parents: 21064
diff changeset
1152
ea520c42a342 (Fchar_after, Fchar_before): Properly check arg type
Richard M. Stallman <rms@gnu.org>
parents: 21064
diff changeset
1153 if (pos_byte <= BEGV_BYTE || pos_byte > ZV_BYTE)
ea520c42a342 (Fchar_after, Fchar_before): Properly check arg type
Richard M. Stallman <rms@gnu.org>
parents: 21064
diff changeset
1154 return Qnil;
ea520c42a342 (Fchar_after, Fchar_before): Properly check arg type
Richard M. Stallman <rms@gnu.org>
parents: 21064
diff changeset
1155 }
18252
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
1156 else
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
1157 {
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
1158 CHECK_NUMBER_COERCE_MARKER (pos, 0);
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1159
21521
354a7085f1d7 (Fchar_after, Fchar_before): Fix mixing of Lisp_Object
Andreas Schwab <schwab@suse.de>
parents: 21514
diff changeset
1160 if (XINT (pos) <= BEGV || XINT (pos) > ZV)
21200
ea520c42a342 (Fchar_after, Fchar_before): Properly check arg type
Richard M. Stallman <rms@gnu.org>
parents: 21064
diff changeset
1161 return Qnil;
ea520c42a342 (Fchar_after, Fchar_before): Properly check arg type
Richard M. Stallman <rms@gnu.org>
parents: 21064
diff changeset
1162
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1163 pos_byte = CHAR_TO_BYTE (XINT (pos));
18252
9c4fb902b6eb (Fchar_after, Fchar_before): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents: 18240
diff changeset
1164 }
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1165
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1166 if (!NILP (current_buffer->enable_multibyte_characters))
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1167 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1168 DEC_POS (pos_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1169 XSETFASTINT (val, FETCH_CHAR (pos_byte));
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1170 }
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1171 else
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1172 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1173 pos_byte--;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
1174 XSETFASTINT (val, FETCH_BYTE (pos_byte));
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1175 }
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1176 return val;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1177 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1178
9572
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
1179 DEFUN ("user-login-name", Fuser_login_name, Suser_login_name, 0, 1, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1180 doc: /* Return the name under which the user logged in, as a string.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1181 This is based on the effective uid, not the real uid.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1182 Also, if the environment variable LOGNAME or USER is set,
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1183 that determines the value of this function.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1184
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1185 If optional argument UID is an integer, return the login name of the user
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1186 with that uid, or nil if there is no such user. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1187 (uid)
9572
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
1188 Lisp_Object uid;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1189 {
9572
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
1190 struct passwd *pw;
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
1191
9520
5187a4159d16 (Fuser_login_name, Fuser_real_login_name):
Richard M. Stallman <rms@gnu.org>
parents: 9305
diff changeset
1192 /* 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
1193 (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
1194 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
1195 if (INTEGERP (Vuser_login_name))
9520
5187a4159d16 (Fuser_login_name, Fuser_real_login_name):
Richard M. Stallman <rms@gnu.org>
parents: 9305
diff changeset
1196 init_editfns ();
9572
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
1197
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
1198 if (NILP (uid))
12026
505a894d943e (syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents: 11912
diff changeset
1199 return Vuser_login_name;
9572
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
1200
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
1201 CHECK_NUMBER (uid, 0);
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
1202 pw = (struct passwd *) getpwuid (XINT (uid));
b36d5e88cccc *** empty log message ***
Morten Welinder <terra@diku.dk>
parents: 9520
diff changeset
1203 return (pw ? build_string (pw->pw_name) : Qnil);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1204 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1205
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1206 DEFUN ("user-real-login-name", Fuser_real_login_name, Suser_real_login_name,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1207 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1208 doc: /* Return the name of the user's real uid, as a string.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1209 This ignores the environment variables LOGNAME and USER, so it differs from
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1210 `user-login-name' when running under `su'. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1211 ()
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1212 {
9520
5187a4159d16 (Fuser_login_name, Fuser_real_login_name):
Richard M. Stallman <rms@gnu.org>
parents: 9305
diff changeset
1213 /* 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
1214 (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
1215 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
1216 if (INTEGERP (Vuser_login_name))
9520
5187a4159d16 (Fuser_login_name, Fuser_real_login_name):
Richard M. Stallman <rms@gnu.org>
parents: 9305
diff changeset
1217 init_editfns ();
12026
505a894d943e (syms_of_editfns): user-login-name renamed from user-name.
Karl Heuer <kwzh@gnu.org>
parents: 11912
diff changeset
1218 return Vuser_real_login_name;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1219 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1220
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1221 DEFUN ("user-uid", Fuser_uid, Suser_uid, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1222 doc: /* Return the effective uid of Emacs.
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1223 Value is an integer or float, depending on the value. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1224 ()
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1225 {
39774
b34a792f4234 (Fuser_uid, Fuser_real_uid): Use make_fixnum_or_float.
Gerd Moellmann <gerd@gnu.org>
parents: 39720
diff changeset
1226 return make_fixnum_or_float (geteuid ());
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1227 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1228
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1229 DEFUN ("user-real-uid", Fuser_real_uid, Suser_real_uid, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1230 doc: /* Return the real uid of Emacs.
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1231 Value is an integer or float, depending on the value. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1232 ()
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1233 {
39774
b34a792f4234 (Fuser_uid, Fuser_real_uid): Use make_fixnum_or_float.
Gerd Moellmann <gerd@gnu.org>
parents: 39720
diff changeset
1234 return make_fixnum_or_float (getuid ());
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1235 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1236
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
1237 DEFUN ("user-full-name", Fuser_full_name, Suser_full_name, 0, 1, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1238 doc: /* Return the full name of the user logged in, as a string.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1239 If the full name corresponding to Emacs's userid is not known,
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1240 return "unknown".
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1241
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1242 If optional argument UID is an integer or float, return the full name
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1243 of the user with that uid, or nil if there is no such user.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1244 If UID is a string, return the full name of the user with that login
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1245 name, or nil if there is no such user. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1246 (uid)
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
1247 Lisp_Object uid;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1248 {
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
1249 struct passwd *pw;
18661
537522d5e6d8 (Fuser_full_name): Declare p, q and r as unsigned char *.
Richard M. Stallman <rms@gnu.org>
parents: 18613
diff changeset
1250 register unsigned char *p, *q;
16641
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1251 Lisp_Object full;
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
1252
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
1253 if (NILP (uid))
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1254 return Vuser_full_name;
16641
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1255 else if (NUMBERP (uid))
39774
b34a792f4234 (Fuser_uid, Fuser_real_uid): Use make_fixnum_or_float.
Gerd Moellmann <gerd@gnu.org>
parents: 39720
diff changeset
1256 pw = (struct passwd *) getpwuid ((uid_t) XFLOATINT (uid));
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1257 else if (STRINGP (uid))
16641
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1258 pw = (struct passwd *) getpwnam (XSTRING (uid)->data);
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1259 else
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1260 error ("Invalid UID specification");
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
1261
16641
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1262 if (!pw)
16683
6802dbd07a80 (Fuser_full_name): Return nil if the specified user doesn't exist.
Richard M. Stallman <rms@gnu.org>
parents: 16648
diff changeset
1263 return Qnil;
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1264
16641
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1265 p = (unsigned char *) USER_FULL_NAME;
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1266 /* Chop off everything after the first comma. */
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1267 q = (unsigned char *) index (p, ',');
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1268 full = make_string (p, q ? q - p : strlen (p));
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1269
16641
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1270 #ifdef AMPERSAND_FULL_NAME
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1271 p = XSTRING (full)->data;
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1272 q = (unsigned char *) index (p, '&');
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1273 /* Substitute the login name for the &, upcasing the first character. */
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1274 if (q)
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1275 {
18661
537522d5e6d8 (Fuser_full_name): Declare p, q and r as unsigned char *.
Richard M. Stallman <rms@gnu.org>
parents: 18613
diff changeset
1276 register unsigned char *r;
16641
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1277 Lisp_Object login;
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1278
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1279 login = Fuser_login_name (make_number (pw->pw_uid));
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1280 r = (unsigned char *) alloca (strlen (p) + XSTRING (login)->size + 1);
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1281 bcopy (p, r, q - p);
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1282 r[q - p] = 0;
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1283 strcat (r, XSTRING (login)->data);
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1284 r[q - p] = UPCASE (r[q - p]);
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1285 strcat (r, q + 1);
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1286 full = build_string (r);
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1287 }
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1288 #endif /* AMPERSAND_FULL_NAME */
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1289
2103a88cc61f (Fuser_full_name): Accept a string (the login name) as
Richard M. Stallman <rms@gnu.org>
parents: 16639
diff changeset
1290 return full;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1291 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1292
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1293 DEFUN ("system-name", Fsystem_name, Ssystem_name, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1294 doc: /* Return the name of the machine you are running on, as a string. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1295 ()
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1296 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1297 return Vsystem_name;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1298 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1299
7907
148ad20d6774 (init_editfns): Call init_system_name instead of get_system_name.
Karl Heuer <kwzh@gnu.org>
parents: 7862
diff changeset
1300 /* For the benefit of callers who don't want to include lisp.h */
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
1301
7907
148ad20d6774 (init_editfns): Call init_system_name instead of get_system_name.
Karl Heuer <kwzh@gnu.org>
parents: 7862
diff changeset
1302 char *
148ad20d6774 (init_editfns): Call init_system_name instead of get_system_name.
Karl Heuer <kwzh@gnu.org>
parents: 7862
diff changeset
1303 get_system_name ()
148ad20d6774 (init_editfns): Call init_system_name instead of get_system_name.
Karl Heuer <kwzh@gnu.org>
parents: 7862
diff changeset
1304 {
18756
751f531e5a20 (get_system_name): Don't crash if Vsystem_name does not contain a string.
Richard M. Stallman <rms@gnu.org>
parents: 18745
diff changeset
1305 if (STRINGP (Vsystem_name))
751f531e5a20 (get_system_name): Don't crash if Vsystem_name does not contain a string.
Richard M. Stallman <rms@gnu.org>
parents: 18745
diff changeset
1306 return (char *) XSTRING (Vsystem_name)->data;
751f531e5a20 (get_system_name): Don't crash if Vsystem_name does not contain a string.
Richard M. Stallman <rms@gnu.org>
parents: 18745
diff changeset
1307 else
751f531e5a20 (get_system_name): Don't crash if Vsystem_name does not contain a string.
Richard M. Stallman <rms@gnu.org>
parents: 18745
diff changeset
1308 return "";
7907
148ad20d6774 (init_editfns): Call init_system_name instead of get_system_name.
Karl Heuer <kwzh@gnu.org>
parents: 7862
diff changeset
1309 }
148ad20d6774 (init_editfns): Call init_system_name instead of get_system_name.
Karl Heuer <kwzh@gnu.org>
parents: 7862
diff changeset
1310
5373
a70b89d2d6bb (Femacs_pid): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5242
diff changeset
1311 DEFUN ("emacs-pid", Femacs_pid, Semacs_pid, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1312 doc: /* Return the process ID of Emacs, as an integer. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1313 ()
5373
a70b89d2d6bb (Femacs_pid): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5242
diff changeset
1314 {
a70b89d2d6bb (Femacs_pid): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5242
diff changeset
1315 return make_number (getpid ());
a70b89d2d6bb (Femacs_pid): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5242
diff changeset
1316 }
a70b89d2d6bb (Femacs_pid): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5242
diff changeset
1317
448
129e6320092c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 372
diff changeset
1318 DEFUN ("current-time", Fcurrent_time, Scurrent_time, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1319 doc: /* Return the current time, as the number of seconds since 1970-01-01 00:00:00.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1320 The time is returned as a list of three integers. The first has the
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1321 most significant 16 bits of the seconds, while the second has the
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1322 least significant 16 bits. The third integer gives the microsecond
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1323 count.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1324
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1325 The microsecond count is zero on systems that do not provide
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1326 resolution finer than a second. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1327 ()
448
129e6320092c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 372
diff changeset
1328 {
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
1329 EMACS_TIME t;
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
1330 Lisp_Object result[3];
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
1331
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
1332 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
1333 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
1334 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
1335 XSETINT (result[2], EMACS_USECS (t));
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
1336
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 512
diff changeset
1337 return Flist (3, result);
448
129e6320092c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 372
diff changeset
1338 }
129e6320092c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 372
diff changeset
1339
129e6320092c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 372
diff changeset
1340
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1341 static int
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1342 lisp_time_argument (specified_time, result, usec)
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1343 Lisp_Object specified_time;
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1344 time_t *result;
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1345 int *usec;
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1346 {
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1347 if (NILP (specified_time))
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1348 {
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1349 if (usec)
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1350 {
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1351 EMACS_TIME t;
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1352
30503
fef49230e1aa (lisp_time_argument): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents: 30480
diff changeset
1353 EMACS_GET_TIME (t);
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1354 *usec = EMACS_USECS (t);
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1355 *result = EMACS_SECS (t);
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1356 return 1;
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1357 }
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1358 else
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1359 return time (result) != -1;
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1360 }
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1361 else
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1362 {
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1363 Lisp_Object high, low;
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1364 high = Fcar (specified_time);
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1365 CHECK_NUMBER (high, 0);
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1366 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
1367 if (CONSP (low))
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1368 {
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1369 if (usec)
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1370 {
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1371 Lisp_Object usec_l = Fcdr (low);
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1372 if (CONSP (usec_l))
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1373 usec_l = Fcar (usec_l);
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1374 if (NILP (usec_l))
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1375 *usec = 0;
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1376 else
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1377 {
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1378 CHECK_NUMBER (usec_l, 0);
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1379 *usec = XINT (usec_l);
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1380 }
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1381 }
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1382 low = Fcar (low);
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1383 }
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1384 else if (usec)
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1385 *usec = 0;
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1386 CHECK_NUMBER (low, 0);
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1387 *result = (XINT (high) << 16) + (XINT (low) & 0xffff);
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1388 return *result >> 16 == XINT (high);
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1389 }
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1390 }
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1391
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1392 DEFUN ("float-time", Ffloat_time, Sfloat_time, 0, 1, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1393 doc: /* Return the current time, as a float number of seconds since the epoch.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1394 If an argument is given, it specifies a time to convert to float
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1395 instead of the current time. The argument should have the forms:
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1396 (HIGH . LOW) or (HIGH LOW USEC) or (HIGH LOW . USEC).
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1397 Thus, you can use times obtained from `current-time'
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1398 and from `file-attributes'.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1399
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1400 WARNING: Since the result is floating point, it may not be exact.
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1401 Do not use this function if precise time stamps are required. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1402 (specified_time)
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1403 Lisp_Object specified_time;
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1404 {
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1405 time_t sec;
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1406 int usec;
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1407
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1408 if (! lisp_time_argument (specified_time, &sec, &usec))
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1409 error ("Invalid time specification");
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1410
37046
a9b2639dd045 (Ffloat_time): Fix off-by-factor-of-10 bug in the
Gerd Moellmann <gerd@gnu.org>
parents: 36479
diff changeset
1411 return make_float ((sec * 1e6 + usec) / 1e6);
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1412 }
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1413
23213
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1414 /* Write information into buffer S of size MAXSIZE, according to the
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1415 FORMAT of length FORMAT_LEN, using time information taken from *TP.
26088
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
1416 Default to Universal Time if UT is nonzero, local time otherwise.
23213
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1417 Return the number of bytes written, not including the terminating
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1418 '\0'. If S is NULL, nothing will be written anywhere; so to
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1419 determine how many bytes would be written, use NULL for S and
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1420 ((size_t) -1) for MAXSIZE.
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1421
26088
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
1422 This function behaves like emacs_strftimeu, except it allows null
23213
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1423 bytes in FORMAT. */
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1424 static size_t
26088
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
1425 emacs_memftimeu (s, maxsize, format, format_len, tp, ut)
23213
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1426 char *s;
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1427 size_t maxsize;
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1428 const char *format;
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1429 size_t format_len;
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1430 const struct tm *tp;
26088
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
1431 int ut;
23213
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1432 {
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1433 size_t total = 0;
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1434
23218
90e5d916ebd9 Add a comment to emacs_memftime, explaining why it needs to loop.
Paul Eggert <eggert@twinsun.com>
parents: 23213
diff changeset
1435 /* Loop through all the null-terminated strings in the format
90e5d916ebd9 Add a comment to emacs_memftime, explaining why it needs to loop.
Paul Eggert <eggert@twinsun.com>
parents: 23213
diff changeset
1436 argument. Normally there's just one null-terminated string, but
90e5d916ebd9 Add a comment to emacs_memftime, explaining why it needs to loop.
Paul Eggert <eggert@twinsun.com>
parents: 23213
diff changeset
1437 there can be arbitrarily many, concatenated together, if the
26088
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
1438 format contains '\0' bytes. emacs_strftimeu stops at the first
23218
90e5d916ebd9 Add a comment to emacs_memftime, explaining why it needs to loop.
Paul Eggert <eggert@twinsun.com>
parents: 23213
diff changeset
1439 '\0' byte so we must invoke it separately for each such string. */
23213
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1440 for (;;)
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1441 {
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1442 size_t len;
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1443 size_t result;
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1444
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1445 if (s)
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1446 s[0] = '\1';
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1447
26088
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
1448 result = emacs_strftimeu (s, maxsize, format, tp, ut);
23213
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1449
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1450 if (s)
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1451 {
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1452 if (result == 0 && s[0] != '\0')
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1453 return 0;
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1454 s += result + 1;
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1455 }
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1456
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1457 maxsize -= result + 1;
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1458 total += result;
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1459 len = strlen (format);
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1460 if (len == format_len)
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1461 return total;
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1462 total++;
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1463 format += len + 1;
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1464 format_len -= len + 1;
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1465 }
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1466 }
3bfc1e9b0377 (emacs_memftime): New function.
Paul Eggert <eggert@twinsun.com>
parents: 23211
diff changeset
1467
17907
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
1468 DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string, 1, 3, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1469 doc: /* Use FORMAT-STRING to format the time TIME, or now if omitted.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1470 TIME is specified as (HIGH LOW . IGNORED) or (HIGH . LOW), as returned by
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1471 `current-time' or `file-attributes'.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1472 The third, optional, argument UNIVERSAL, if non-nil, means describe TIME
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1473 as Universal Time; nil means describe TIME in the local time zone.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1474 The value is a copy of FORMAT-STRING, but with certain constructs replaced
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1475 by text that describes the specified date and time in TIME:
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1476
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1477 %Y is the year, %y within the century, %C the century.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1478 %G is the year corresponding to the ISO week, %g within the century.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1479 %m is the numeric month.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1480 %b and %h are the locale's abbreviated month name, %B the full name.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1481 %d is the day of the month, zero-padded, %e is blank-padded.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1482 %u is the numeric day of week from 1 (Monday) to 7, %w from 0 (Sunday) to 6.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1483 %a is the locale's abbreviated name of the day of week, %A the full name.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1484 %U is the week number starting on Sunday, %W starting on Monday,
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1485 %V according to ISO 8601.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1486 %j is the day of the year.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1487
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1488 %H is the hour on a 24-hour clock, %I is on a 12-hour clock, %k is like %H
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1489 only blank-padded, %l is like %I blank-padded.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1490 %p is the locale's equivalent of either AM or PM.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1491 %M is the minute.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1492 %S is the second.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1493 %Z is the time zone name, %z is the numeric form.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1494 %s is the number of seconds since 1970-01-01 00:00:00 +0000.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1495
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1496 %c is the locale's date and time format.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1497 %x is the locale's "preferred" date format.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1498 %D is like "%m/%d/%y".
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1499
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1500 %R is like "%H:%M", %T is like "%H:%M:%S", %r is like "%I:%M:%S %p".
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1501 %X is the locale's "preferred" time format.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1502
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1503 Finally, %n is a newline, %t is a tab, %% is a literal %.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1504
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1505 Certain flags and modifiers are available with some format controls.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1506 The flags are `_', `-', `^' and `#'. For certain characters X,
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1507 %_X is like %X, but padded with blanks; %-X is like %X,
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1508 ut without padding. %^X is like %X but with all textual
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1509 characters up-cased; %#X is like %X but with letter-case of
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1510 all textual characters reversed.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1511 %NX (where N stands for an integer) is like %X,
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1512 but takes up at least N (a number) positions.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1513 The modifiers are `E' and `O'. For certain characters X,
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1514 %EX is a locale's alternative version of %X;
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1515 %OX is like %X, but uses the locale's number symbols.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1516
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1517 For example, to produce full ISO 8601 format, use "%Y-%m-%dT%T%z". */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1518 (format_string, time, universal)
17907
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
1519 Lisp_Object format_string, time, universal;
9154
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
1520 {
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
1521 time_t value;
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
1522 int size;
23198
dddce768cf7a (Fformat_time_string, Fdecode_time, Fcurrent_time_zone):
Paul Eggert <eggert@twinsun.com>
parents: 23197
diff changeset
1523 struct tm *tm;
26088
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
1524 int ut = ! NILP (universal);
9154
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
1525
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
1526 CHECK_STRING (format_string, 1);
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
1527
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1528 if (! lisp_time_argument (time, &value, NULL))
9154
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
1529 error ("Invalid time specification");
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
1530
26088
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
1531 format_string = code_convert_string_norecord (format_string,
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
1532 Vlocale_coding_system, 1);
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
1533
9154
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
1534 /* This is probably enough. */
21245
6cde55b7c9de Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents: 21235
diff changeset
1535 size = STRING_BYTES (XSTRING (format_string)) * 6 + 50;
9154
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
1536
26088
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
1537 tm = ut ? gmtime (&value) : localtime (&value);
23198
dddce768cf7a (Fformat_time_string, Fdecode_time, Fcurrent_time_zone):
Paul Eggert <eggert@twinsun.com>
parents: 23197
diff changeset
1538 if (! tm)
dddce768cf7a (Fformat_time_string, Fdecode_time, Fcurrent_time_zone):
Paul Eggert <eggert@twinsun.com>
parents: 23197
diff changeset
1539 error ("Specified time is not representable");
dddce768cf7a (Fformat_time_string, Fdecode_time, Fcurrent_time_zone):
Paul Eggert <eggert@twinsun.com>
parents: 23197
diff changeset
1540
26526
b7438760079b * callproc.c (strerror): Remove decl.
Paul Eggert <eggert@twinsun.com>
parents: 26415
diff changeset
1541 synchronize_system_time_locale ();
26088
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
1542
9154
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
1543 while (1)
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
1544 {
17907
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
1545 char *buf = (char *) alloca (size + 1);
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
1546 int result;
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
1547
19032
84ae0a03a643 (Fformat_time_string): Don't hang if strftime produces
Richard M. Stallman <rms@gnu.org>
parents: 18937
diff changeset
1548 buf[0] = '\1';
26088
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
1549 result = emacs_memftimeu (buf, size, XSTRING (format_string)->data,
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
1550 STRING_BYTES (XSTRING (format_string)),
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
1551 tm, ut);
19032
84ae0a03a643 (Fformat_time_string): Don't hang if strftime produces
Richard M. Stallman <rms@gnu.org>
parents: 18937
diff changeset
1552 if ((result > 0 && result < size) || (result == 0 && buf[0] == '\0'))
26088
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
1553 return code_convert_string_norecord (make_string (buf, result),
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
1554 Vlocale_coding_system, 0);
17907
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
1555
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
1556 /* If buffer was too small, make it bigger and try again. */
26088
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
1557 result = emacs_memftimeu (NULL, (size_t) -1,
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
1558 XSTRING (format_string)->data,
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
1559 STRING_BYTES (XSTRING (format_string)),
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26058
diff changeset
1560 tm, ut);
17907
a1f8ff84f3f1 (Fformat_time_string): Doc update.
Richard M. Stallman <rms@gnu.org>
parents: 17829
diff changeset
1561 size = result + 1;
9154
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
1562 }
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
1563 }
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
1564
9801
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
1565 DEFUN ("decode-time", Fdecode_time, Sdecode_time, 0, 1, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1566 doc: /* Decode a time value as (SEC MINUTE HOUR DAY MONTH YEAR DOW DST ZONE).
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1567 The optional SPECIFIED-TIME should be a list of (HIGH LOW . IGNORED)
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1568 or (HIGH . LOW), as from `current-time' and `file-attributes', or `nil'
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1569 to use the current time. The list has the following nine members:
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1570 SEC is an integer between 0 and 60; SEC is 60 for a leap second, which
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1571 only some operating systems support. MINUTE is an integer between 0 and 59.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1572 HOUR is an integer between 0 and 23. DAY is an integer between 1 and 31.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1573 MONTH is an integer between 1 and 12. YEAR is an integer indicating the
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1574 four-digit year. DOW is the day of week, an integer between 0 and 6, where
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1575 0 is Sunday. DST is t if daylight savings time is effect, otherwise nil.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1576 ZONE is an integer indicating the number of seconds east of Greenwich.
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1577 (Note that Common Lisp has different meanings for DOW and ZONE.) */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1578 (specified_time)
9801
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
1579 Lisp_Object specified_time;
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
1580 {
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
1581 time_t time_spec;
9812
bc352c8f079c (Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents: 9809
diff changeset
1582 struct tm save_tm;
9801
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
1583 struct tm *decoded_time;
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
1584 Lisp_Object list_args[9];
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1585
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1586 if (! lisp_time_argument (specified_time, &time_spec, NULL))
9801
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
1587 error ("Invalid time specification");
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
1588
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
1589 decoded_time = localtime (&time_spec);
23198
dddce768cf7a (Fformat_time_string, Fdecode_time, Fcurrent_time_zone):
Paul Eggert <eggert@twinsun.com>
parents: 23197
diff changeset
1590 if (! decoded_time)
dddce768cf7a (Fformat_time_string, Fdecode_time, Fcurrent_time_zone):
Paul Eggert <eggert@twinsun.com>
parents: 23197
diff changeset
1591 error ("Specified time is not representable");
9812
bc352c8f079c (Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents: 9809
diff changeset
1592 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
1593 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
1594 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
1595 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
1596 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
1597 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
1598 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
1599 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
1600
bc352c8f079c (Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents: 9809
diff changeset
1601 /* 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
1602 save_tm = *decoded_time;
bc352c8f079c (Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents: 9809
diff changeset
1603 decoded_time = gmtime (&time_spec);
bc352c8f079c (Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents: 9809
diff changeset
1604 if (decoded_time == 0)
bc352c8f079c (Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents: 9809
diff changeset
1605 list_args[8] = Qnil;
bc352c8f079c (Fdecode_time): Fix Lisp_Object vs. integer problems.
Karl Heuer <kwzh@gnu.org>
parents: 9809
diff changeset
1606 else
16269
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1607 XSETINT (list_args[8], tm_diff (&save_tm, decoded_time));
9801
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
1608 return Flist (9, list_args);
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
1609 }
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
1610
15180
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
1611 DEFUN ("encode-time", Fencode_time, Sencode_time, 6, MANY, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1612 doc: /* Convert SECOND, MINUTE, HOUR, DAY, MONTH, YEAR and ZONE to internal time.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1613 This is the reverse operation of `decode-time', which see.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1614 ZONE defaults to the current time zone rule. This can
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1615 be a string or t (as from `set-time-zone-rule'), or it can be a list
40044
7a0668d72687 (text_property_stickiness): Non-rear-non-stickiness doesn't take
Miles Bader <miles@gnu.org>
parents: 40042
diff changeset
1616 \(as from `current-time-zone') or an integer (as from `decode-time')
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1617 applied without consideration for daylight savings time.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1618
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1619 You can pass more than 7 arguments; then the first six arguments
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1620 are used as SECOND through YEAR, and the *last* argument is used as ZONE.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1621 The intervening arguments are ignored.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1622 This feature lets (apply 'encode-time (decode-time ...)) work.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1623
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1624 Out-of-range values for SEC, MINUTE, HOUR, DAY, or MONTH are allowed;
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1625 for example, a DAY of 0 means the day preceding the given month.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1626 Year numbers less than 100 are treated just like other year numbers.
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1627 If you want them to stand for years in this century, you must do that yourself. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1628 (nargs, args)
15180
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
1629 int nargs;
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
1630 register Lisp_Object *args;
11402
66d935214d8e (Fencode_time): Use XINT to examine `zone'.
Richard M. Stallman <rms@gnu.org>
parents: 11263
diff changeset
1631 {
11468
772f49d1969d (Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents: 11451
diff changeset
1632 time_t time;
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1633 struct tm tm;
16874
0b914fcd97a1 Clean up parentheses.
Richard M. Stallman <rms@gnu.org>
parents: 16683
diff changeset
1634 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
1635
15180
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
1636 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
1637 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
1638 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
1639 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
1640 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
1641 CHECK_NUMBER (args[5], 5); /* year */
11468
772f49d1969d (Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents: 11451
diff changeset
1642
15180
9a22c72359c1 (Fencode_time): Accept MANY args, so as to cope
Richard M. Stallman <rms@gnu.org>
parents: 15075
diff changeset
1643 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
1644 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
1645 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
1646 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
1647 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
1648 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
1649 tm.tm_isdst = -1;
11468
772f49d1969d (Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents: 11451
diff changeset
1650
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1651 if (CONSP (zone))
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1652 zone = Fcar (zone);
11468
772f49d1969d (Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents: 11451
diff changeset
1653 if (NILP (zone))
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1654 time = mktime (&tm);
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1655 else
11468
772f49d1969d (Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents: 11451
diff changeset
1656 {
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1657 char tzbuf[100];
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1658 char *tzstring;
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1659 char **oldenv = environ, **newenv;
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1660
18613
614b916ff5bf Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents: 18605
diff changeset
1661 if (EQ (zone, Qt))
15910
8cd4f2fd5525 (Fencode_time, Fset_time_zone_rule): Use UTC if the zone is t.
Erik Naggum <erik@naggum.no>
parents: 15841
diff changeset
1662 tzstring = "UTC0";
8cd4f2fd5525 (Fencode_time, Fset_time_zone_rule): Use UTC if the zone is t.
Erik Naggum <erik@naggum.no>
parents: 15841
diff changeset
1663 else if (STRINGP (zone))
13347
186d80572f4f (Fencode_time): Add cast.
Richard M. Stallman <rms@gnu.org>
parents: 13238
diff changeset
1664 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
1665 else if (INTEGERP (zone))
11468
772f49d1969d (Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents: 11451
diff changeset
1666 {
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1667 int abszone = abs (XINT (zone));
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1668 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
1669 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
1670 tzstring = tzbuf;
11468
772f49d1969d (Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents: 11451
diff changeset
1671 }
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1672 else
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1673 error ("Invalid time zone specification");
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1674
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1675 /* Set TZ before calling mktime; merely adjusting mktime's returned
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1676 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
1677 set_time_zone_rule (tzstring);
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1678
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1679 time = mktime (&tm);
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1680
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1681 /* Restore TZ to previous value. */
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1682 newenv = environ;
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1683 environ = oldenv;
16521
fe9cc0d392dd (Fencode_time): Use xfree, not free.
Richard M. Stallman <rms@gnu.org>
parents: 16485
diff changeset
1684 xfree (newenv);
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1685 #ifdef LOCALTIME_CACHE
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1686 tzset ();
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1687 #endif
11468
772f49d1969d (Fencode_time): Rewrite by Naggum.
Richard M. Stallman <rms@gnu.org>
parents: 11451
diff changeset
1688 }
11402
66d935214d8e (Fencode_time): Use XINT to examine `zone'.
Richard M. Stallman <rms@gnu.org>
parents: 11263
diff changeset
1689
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1690 if (time == (time_t) -1)
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1691 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
1692
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1693 return make_time (time);
11402
66d935214d8e (Fencode_time): Use XINT to examine `zone'.
Richard M. Stallman <rms@gnu.org>
parents: 11263
diff changeset
1694 }
66d935214d8e (Fencode_time): Use XINT to examine `zone'.
Richard M. Stallman <rms@gnu.org>
parents: 11263
diff changeset
1695
2154
69c58e548ca5 (Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents: 2049
diff changeset
1696 DEFUN ("current-time-string", Fcurrent_time_string, Scurrent_time_string, 0, 1, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1697 doc: /* Return the current time, as a human-readable string.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1698 Programs can use this function to decode a time,
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1699 since the number of columns in each field is fixed.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1700 The format is `Sun Sep 16 01:03:52 1973'.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1701 However, see also the functions `decode-time' and `format-time-string'
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1702 which provide a much more powerful and general facility.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1703
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1704 If an argument is given, it specifies a time to format
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1705 instead of the current time. The argument should have the form:
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1706 (HIGH . LOW)
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1707 or the form:
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1708 (HIGH LOW . IGNORED).
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1709 Thus, you can use times obtained from `current-time'
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1710 and from `file-attributes'. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1711 (specified_time)
2154
69c58e548ca5 (Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents: 2049
diff changeset
1712 Lisp_Object specified_time;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1713 {
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1714 time_t value;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1715 char buf[30];
2154
69c58e548ca5 (Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents: 2049
diff changeset
1716 register char *tem;
69c58e548ca5 (Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents: 2049
diff changeset
1717
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1718 if (! lisp_time_argument (specified_time, &value, NULL))
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1719 value = -1;
2154
69c58e548ca5 (Fcurrent_time_string): Optional arg specifies time.
Richard M. Stallman <rms@gnu.org>
parents: 2049
diff changeset
1720 tem = (char *) ctime (&value);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1721
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1722 strncpy (buf, tem, 24);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1723 buf[24] = 0;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1724
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1725 return build_string (buf);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1726 }
962
3533821d6edc * editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents: 690
diff changeset
1727
16269
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1728 #define TM_YEAR_BASE 1900
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1729
16269
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1730 /* Yield A - B, measured in seconds.
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1731 This function is copied from the GNU C Library. */
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1732 static int
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1733 tm_diff (a, b)
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1734 struct tm *a, *b;
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1735 {
16269
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1736 /* Compute intervening leap days correctly even if year is negative.
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1737 Take care to avoid int overflow in leap day calculations,
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1738 but it's OK to assume that A and B are close to each other. */
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1739 int a4 = (a->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (a->tm_year & 3);
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1740 int b4 = (b->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (b->tm_year & 3);
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1741 int a100 = a4 / 25 - (a4 % 25 < 0);
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1742 int b100 = b4 / 25 - (b4 % 25 < 0);
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1743 int a400 = a100 >> 2;
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1744 int b400 = b100 >> 2;
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1745 int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1746 int years = a->tm_year - b->tm_year;
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1747 int days = (365 * years + intervening_leap_days
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1748 + (a->tm_yday - b->tm_yday));
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1749 return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
79e6c47054c5 (tm_diff): Renamed from difftm. Yield int, not long.
Paul Eggert <eggert@twinsun.com>
parents: 16134
diff changeset
1750 + (a->tm_min - b->tm_min))
5882
319a7fcb7609 (difftm): Simplify expression.
Karl Heuer <kwzh@gnu.org>
parents: 5373
diff changeset
1751 + (a->tm_sec - b->tm_sec));
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1752 }
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1753
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1754 DEFUN ("current-time-zone", Fcurrent_time_zone, Scurrent_time_zone, 0, 1, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1755 doc: /* Return the offset and name for the local time zone.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1756 This returns a list of the form (OFFSET NAME).
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1757 OFFSET is an integer number of seconds ahead of UTC (east of Greenwich).
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1758 A negative value means west of Greenwich.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1759 NAME is a string giving the name of the time zone.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1760 If an argument is given, it specifies when the time zone offset is determined
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1761 instead of using the current time. The argument should have the form:
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1762 (HIGH . LOW)
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1763 or the form:
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1764 (HIGH LOW . IGNORED).
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1765 Thus, you can use times obtained from `current-time'
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1766 and from `file-attributes'.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1767
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1768 Some operating systems cannot provide all this information to Emacs;
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1769 in this case, `current-time-zone' returns a list containing nil for
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1770 the data it can't find. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1771 (specified_time)
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1772 Lisp_Object specified_time;
962
3533821d6edc * editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents: 690
diff changeset
1773 {
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1774 time_t value;
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1775 struct tm *t;
23198
dddce768cf7a (Fformat_time_string, Fdecode_time, Fcurrent_time_zone):
Paul Eggert <eggert@twinsun.com>
parents: 23197
diff changeset
1776 struct tm gmt;
962
3533821d6edc * editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents: 690
diff changeset
1777
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1778 if (lisp_time_argument (specified_time, &value, NULL)
23198
dddce768cf7a (Fformat_time_string, Fdecode_time, Fcurrent_time_zone):
Paul Eggert <eggert@twinsun.com>
parents: 23197
diff changeset
1779 && (t = gmtime (&value)) != 0
dddce768cf7a (Fformat_time_string, Fdecode_time, Fcurrent_time_zone):
Paul Eggert <eggert@twinsun.com>
parents: 23197
diff changeset
1780 && (gmt = *t, t = localtime (&value)) != 0)
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1781 {
23198
dddce768cf7a (Fformat_time_string, Fdecode_time, Fcurrent_time_zone):
Paul Eggert <eggert@twinsun.com>
parents: 23197
diff changeset
1782 int offset = tm_diff (t, &gmt);
dddce768cf7a (Fformat_time_string, Fdecode_time, Fcurrent_time_zone):
Paul Eggert <eggert@twinsun.com>
parents: 23197
diff changeset
1783 char *s = 0;
dddce768cf7a (Fformat_time_string, Fdecode_time, Fcurrent_time_zone):
Paul Eggert <eggert@twinsun.com>
parents: 23197
diff changeset
1784 char buf[6];
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1785 #ifdef HAVE_TM_ZONE
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1786 if (t->tm_zone)
7506
9fa47d36798a (Fcurrent_time_zone): Add cast.
Richard M. Stallman <rms@gnu.org>
parents: 7485
diff changeset
1787 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
1788 #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
1789 #ifdef HAVE_TZNAME
dc9f7a107e28 (Fcurrent_time_zone): Add alternative for !HAVE_TM_ZONE.
Richard M. Stallman <rms@gnu.org>
parents: 2994
diff changeset
1790 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
1791 s = tzname[t->tm_isdst];
962
3533821d6edc * editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents: 690
diff changeset
1792 #endif
3522
dc9f7a107e28 (Fcurrent_time_zone): Add alternative for !HAVE_TM_ZONE.
Richard M. Stallman <rms@gnu.org>
parents: 2994
diff changeset
1793 #endif /* not HAVE_TM_ZONE */
36479
ac3ee681e8f9 (Fcurrent_time_zone) [HAVE_TM_ZONE || HAVE_TZNAME]:
Gerd Moellmann <gerd@gnu.org>
parents: 35998
diff changeset
1794
ac3ee681e8f9 (Fcurrent_time_zone) [HAVE_TM_ZONE || HAVE_TZNAME]:
Gerd Moellmann <gerd@gnu.org>
parents: 35998
diff changeset
1795 #if defined HAVE_TM_ZONE || defined HAVE_TZNAME
ac3ee681e8f9 (Fcurrent_time_zone) [HAVE_TM_ZONE || HAVE_TZNAME]:
Gerd Moellmann <gerd@gnu.org>
parents: 35998
diff changeset
1796 if (s)
ac3ee681e8f9 (Fcurrent_time_zone) [HAVE_TM_ZONE || HAVE_TZNAME]:
Gerd Moellmann <gerd@gnu.org>
parents: 35998
diff changeset
1797 {
ac3ee681e8f9 (Fcurrent_time_zone) [HAVE_TM_ZONE || HAVE_TZNAME]:
Gerd Moellmann <gerd@gnu.org>
parents: 35998
diff changeset
1798 /* On Japanese w32, we can get a Japanese string as time
ac3ee681e8f9 (Fcurrent_time_zone) [HAVE_TM_ZONE || HAVE_TZNAME]:
Gerd Moellmann <gerd@gnu.org>
parents: 35998
diff changeset
1799 zone name. Don't accept that. */
ac3ee681e8f9 (Fcurrent_time_zone) [HAVE_TM_ZONE || HAVE_TZNAME]:
Gerd Moellmann <gerd@gnu.org>
parents: 35998
diff changeset
1800 char *p;
39720
e7c5b465528a (Fcurrent_time_zone): Cast isalnum() argument to
Gerd Moellmann <gerd@gnu.org>
parents: 39682
diff changeset
1801 for (p = s; *p && (isalnum ((unsigned char)*p) || *p == ' '); ++p)
36479
ac3ee681e8f9 (Fcurrent_time_zone) [HAVE_TM_ZONE || HAVE_TZNAME]:
Gerd Moellmann <gerd@gnu.org>
parents: 35998
diff changeset
1802 ;
ac3ee681e8f9 (Fcurrent_time_zone) [HAVE_TM_ZONE || HAVE_TZNAME]:
Gerd Moellmann <gerd@gnu.org>
parents: 35998
diff changeset
1803 if (p == s || *p)
ac3ee681e8f9 (Fcurrent_time_zone) [HAVE_TM_ZONE || HAVE_TZNAME]:
Gerd Moellmann <gerd@gnu.org>
parents: 35998
diff changeset
1804 s = NULL;
ac3ee681e8f9 (Fcurrent_time_zone) [HAVE_TM_ZONE || HAVE_TZNAME]:
Gerd Moellmann <gerd@gnu.org>
parents: 35998
diff changeset
1805 }
ac3ee681e8f9 (Fcurrent_time_zone) [HAVE_TM_ZONE || HAVE_TZNAME]:
Gerd Moellmann <gerd@gnu.org>
parents: 35998
diff changeset
1806 #endif
ac3ee681e8f9 (Fcurrent_time_zone) [HAVE_TM_ZONE || HAVE_TZNAME]:
Gerd Moellmann <gerd@gnu.org>
parents: 35998
diff changeset
1807
2921
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1808 if (!s)
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1809 {
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1810 /* 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
1811 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
1812 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
1813 s = buf;
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1814 }
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1815 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
1816 }
37503f466755 Some time-handling patches from Paul Eggert:
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
1817 else
18745
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
1818 return Fmake_list (make_number (2), Qnil);
962
3533821d6edc * editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents: 690
diff changeset
1819 }
3533821d6edc * editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents: 690
diff changeset
1820
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1821 /* 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
1822 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
1823 has never been called. */
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1824 static char **environbuf;
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
1825
13019
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1826 DEFUN ("set-time-zone-rule", Fset_time_zone_rule, Sset_time_zone_rule, 1, 1, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1827 doc: /* Set the local time zone using TZ, a string specifying a time zone rule.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
1828 If TZ is nil, use implementation-defined default time zone information.
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1829 If TZ is t, use Universal Time. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
1830 (tz)
13019
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1831 Lisp_Object tz;
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1832 {
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1833 char *tzstring;
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1834
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1835 if (NILP (tz))
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1836 tzstring = 0;
18613
614b916ff5bf Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents: 18605
diff changeset
1837 else if (EQ (tz, Qt))
15910
8cd4f2fd5525 (Fencode_time, Fset_time_zone_rule): Use UTC if the zone is t.
Erik Naggum <erik@naggum.no>
parents: 15841
diff changeset
1838 tzstring = "UTC0";
13019
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1839 else
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1840 {
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1841 CHECK_STRING (tz, 0);
13347
186d80572f4f (Fencode_time): Add cast.
Richard M. Stallman <rms@gnu.org>
parents: 13238
diff changeset
1842 tzstring = (char *) XSTRING (tz)->data;
13019
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1843 }
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1844
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1845 set_time_zone_rule (tzstring);
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1846 if (environbuf)
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1847 free (environbuf);
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1848 environbuf = environ;
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1849
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1850 return Qnil;
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1851 }
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1852
16918
ab49512bcdff (set_time_zone_rule_tz1, set_time_zone_rule_tz2):
Paul Eggert <eggert@twinsun.com>
parents: 16874
diff changeset
1853 #ifdef LOCALTIME_CACHE
ab49512bcdff (set_time_zone_rule_tz1, set_time_zone_rule_tz2):
Paul Eggert <eggert@twinsun.com>
parents: 16874
diff changeset
1854
ab49512bcdff (set_time_zone_rule_tz1, set_time_zone_rule_tz2):
Paul Eggert <eggert@twinsun.com>
parents: 16874
diff changeset
1855 /* These two values are known to load tz files in buggy implementations,
ab49512bcdff (set_time_zone_rule_tz1, set_time_zone_rule_tz2):
Paul Eggert <eggert@twinsun.com>
parents: 16874
diff changeset
1856 i.e. Solaris 1 executables running under either Solaris 1 or Solaris 2.
15841
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1857 Their values shouldn't matter in non-buggy implementations.
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
1858 We don't use string literals for these strings,
15841
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1859 since if a string in the environment is in readonly
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1860 storage, it runs afoul of bugs in SVR4 and Solaris 2.3.
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1861 See Sun bugs 1113095 and 1114114, ``Timezone routines
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1862 improperly modify environment''. */
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1863
16918
ab49512bcdff (set_time_zone_rule_tz1, set_time_zone_rule_tz2):
Paul Eggert <eggert@twinsun.com>
parents: 16874
diff changeset
1864 static char set_time_zone_rule_tz1[] = "TZ=GMT+0";
ab49512bcdff (set_time_zone_rule_tz1, set_time_zone_rule_tz2):
Paul Eggert <eggert@twinsun.com>
parents: 16874
diff changeset
1865 static char set_time_zone_rule_tz2[] = "TZ=GMT+1";
ab49512bcdff (set_time_zone_rule_tz1, set_time_zone_rule_tz2):
Paul Eggert <eggert@twinsun.com>
parents: 16874
diff changeset
1866
ab49512bcdff (set_time_zone_rule_tz1, set_time_zone_rule_tz2):
Paul Eggert <eggert@twinsun.com>
parents: 16874
diff changeset
1867 #endif
15841
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1868
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1869 /* 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
1870 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
1871 responsibility to free. */
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
1872
14201
ff372902386d (set_time_zone_rule): No longer static.
Richard M. Stallman <rms@gnu.org>
parents: 14126
diff changeset
1873 void
13025
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1874 set_time_zone_rule (tzstring)
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1875 char *tzstring;
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1876 {
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1877 int envptrs;
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1878 char **from, **to, **newenv;
1eab52043f10 (Fencode_time): Use mktime to do the real work;
Paul Eggert <eggert@twinsun.com>
parents: 13019
diff changeset
1879
15334
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1880 /* 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
1881 for (from = environ; *from; from++)
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1882 continue;
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1883 envptrs = from - environ + 2;
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1884 newenv = to = (char **) xmalloc (envptrs * sizeof (char *)
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1885 + (tzstring ? strlen (tzstring) + 4 : 0));
15334
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1886
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1887 /* 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
1888 if (tzstring)
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1889 {
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1890 char *t = (char *) (to + envptrs);
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1891 strcpy (t, "TZ=");
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1892 strcat (t, tzstring);
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1893 *to++ = t;
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1894 }
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1895
15334
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1896 /* Copy the old environ vector elements into NEWENV,
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1897 but don't copy the TZ variable.
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1898 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
1899 for (from = environ; *from; from++)
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1900 if (strncmp (*from, "TZ=", 3) != 0)
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1901 *to++ = *from;
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1902 *to = 0;
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1903
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1904 environ = newenv;
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1905
15334
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1906 /* If we do have a TZSTRING, NEWENV points to the vector slot where
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1907 the TZ variable is stored. If we do not have a TZSTRING,
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1908 TO points to the vector slot which has the terminating null. */
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1909
13019
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1910 #ifdef LOCALTIME_CACHE
15334
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1911 {
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1912 /* In SunOS 4.1.3_U1 and 4.1.4, if TZ has a value like
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1913 "US/Pacific" that loads a tz file, then changes to a value like
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1914 "XXX0" that does not load a tz file, and then changes back to
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1915 its original value, the last change is (incorrectly) ignored.
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1916 Also, if TZ changes twice in succession to values that do
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1917 not load a tz file, tzset can dump core (see Sun bug#1225179).
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1918 The following code works around these bugs. */
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1919
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1920 if (tzstring)
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1921 {
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1922 /* Temporarily set TZ to a value that loads a tz file
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1923 and that differs from tzstring. */
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1924 char *tz = *newenv;
15841
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1925 *newenv = (strcmp (tzstring, set_time_zone_rule_tz1 + 3) == 0
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1926 ? set_time_zone_rule_tz2 : set_time_zone_rule_tz1);
15334
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1927 tzset ();
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1928 *newenv = tz;
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1929 }
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1930 else
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1931 {
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1932 /* The implied tzstring is unknown, so temporarily set TZ to
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1933 two different values that each load a tz file. */
15841
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1934 *to = set_time_zone_rule_tz1;
15334
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1935 to[1] = 0;
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1936 tzset ();
15841
80a852988718 (set_time_zone_rule): Don't put a string literal
Richard M. Stallman <rms@gnu.org>
parents: 15779
diff changeset
1937 *to = set_time_zone_rule_tz2;
15334
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1938 tzset ();
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1939 *to = 0;
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1940 }
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1941
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1942 /* Now TZ has the desired value, and tzset can be invoked safely. */
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1943 }
07c1581d1cc5 (set_time_zone_rule):
Richard M. Stallman <rms@gnu.org>
parents: 15241
diff changeset
1944
13019
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1945 tzset ();
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1946 #endif
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
1947 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1948
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1949 /* Insert NARGS Lisp objects in the array ARGS by calling INSERT_FUNC
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1950 (if a type of object is Lisp_Int) or INSERT_FROM_STRING_FUNC (if a
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1951 type of object is Lisp_String). INHERIT is passed to
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1952 INSERT_FROM_STRING_FUNC as the last argument. */
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1953
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
1954 static void
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1955 general_insert_function (insert_func, insert_from_string_func,
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1956 inherit, nargs, args)
20311
2841215c1cb4 (Fchar_to_string): Declare `workbuf' as unsigned char.
Andreas Schwab <schwab@suse.de>
parents: 20229
diff changeset
1957 void (*insert_func) P_ ((unsigned char *, int));
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1958 void (*insert_from_string_func) P_ ((Lisp_Object, int, int, int, int, int));
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1959 int inherit, nargs;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1960 register Lisp_Object *args;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1961 {
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1962 register int argnum;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1963 register Lisp_Object val;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1964
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1965 for (argnum = 0; argnum < nargs; argnum++)
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1966 {
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1967 val = args[argnum];
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1968 retry:
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1969 if (INTEGERP (val))
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1970 {
26853
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1971 unsigned char str[MAX_MULTIBYTE_LENGTH];
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1972 int len;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1973
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1974 if (!NILP (current_buffer->enable_multibyte_characters))
26853
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1975 len = CHAR_STRING (XFASTINT (val), str);
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1976 else
22929
6dda0a4b882f (general_insert_function): If enable-multibyte-characters is
Kenichi Handa <handa@m17n.org>
parents: 22895
diff changeset
1977 {
26853
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1978 str[0] = (SINGLE_BYTE_CHAR_P (XINT (val))
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1979 ? XINT (val)
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1980 : multibyte_char_to_unibyte (XINT (val), Qnil));
22929
6dda0a4b882f (general_insert_function): If enable-multibyte-characters is
Kenichi Handa <handa@m17n.org>
parents: 22895
diff changeset
1981 len = 1;
6dda0a4b882f (general_insert_function): If enable-multibyte-characters is
Kenichi Handa <handa@m17n.org>
parents: 22895
diff changeset
1982 }
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1983 (*insert_func) (str, len);
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1984 }
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1985 else if (STRINGP (val))
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1986 {
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1987 (*insert_from_string_func) (val, 0, 0,
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1988 XSTRING (val)->size,
21245
6cde55b7c9de Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents: 21235
diff changeset
1989 STRING_BYTES (XSTRING (val)),
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
1990 inherit);
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1991 }
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1992 else
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1993 {
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1994 val = wrong_type_argument (Qchar_or_string_p, val);
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1995 goto retry;
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1996 }
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1997 }
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1998 }
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
1999
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2000 void
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2001 insert1 (arg)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2002 Lisp_Object arg;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2003 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2004 Finsert (1, &arg);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2005 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2006
330
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
2007
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
2008 /* Callers passing one argument to Finsert need not gcpro the
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
2009 argument "array", since the only element of the array will
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
2010 not be used after calling insert or insert_from_string, so
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
2011 we don't care if it gets trashed. */
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
2012
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2013 DEFUN ("insert", Finsert, Sinsert, 0, MANY, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2014 doc: /* Insert the arguments, either strings or characters, at point.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2015 Point and before-insertion markers move forward to end up
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2016 after the inserted text.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2017 Any other markers at the point of insertion remain before the text.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2018
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2019 If the current buffer is multibyte, unibyte strings are converted
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2020 to multibyte for insertion (see `unibyte-char-to-multibyte').
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2021 If the current buffer is unibyte, multibyte strings are converted
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2022 to unibyte for insertion. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2023 (nargs, args)
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2024 int nargs;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2025 register Lisp_Object *args;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2026 {
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2027 general_insert_function (insert, insert_from_string, 0, nargs, args);
4714
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
2028 return Qnil;
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
2029 }
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
2030
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
2031 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
2032 0, MANY, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2033 doc: /* Insert the arguments at point, inheriting properties from adjoining text.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2034 Point and before-insertion markers move forward to end up
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2035 after the inserted text.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2036 Any other markers at the point of insertion remain before the text.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2037
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2038 If the current buffer is multibyte, unibyte strings are converted
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2039 to multibyte for insertion (see `unibyte-char-to-multibyte').
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2040 If the current buffer is unibyte, multibyte strings are converted
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2041 to unibyte for insertion. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2042 (nargs, args)
4714
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
2043 int nargs;
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
2044 register Lisp_Object *args;
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
2045 {
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2046 general_insert_function (insert_and_inherit, insert_from_string, 1,
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2047 nargs, args);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2048 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2049 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2050
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2051 DEFUN ("insert-before-markers", Finsert_before_markers, Sinsert_before_markers, 0, MANY, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2052 doc: /* Insert strings or characters at point, relocating markers after the text.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2053 Point and markers move forward to end up after the inserted text.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2054
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2055 If the current buffer is multibyte, unibyte strings are converted
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2056 to multibyte for insertion (see `unibyte-char-to-multibyte').
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2057 If the current buffer is unibyte, multibyte strings are converted
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2058 to unibyte for insertion. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2059 (nargs, args)
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2060 int nargs;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2061 register Lisp_Object *args;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2062 {
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2063 general_insert_function (insert_before_markers,
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2064 insert_from_string_before_markers, 0,
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2065 nargs, args);
4714
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
2066 return Qnil;
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
2067 }
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
2068
16485
9b919c5464a4 Reorganize function definitions so etags finds them.
Erik Naggum <erik@naggum.no>
parents: 16298
diff changeset
2069 DEFUN ("insert-before-markers-and-inherit", Finsert_and_inherit_before_markers,
9b919c5464a4 Reorganize function definitions so etags finds them.
Erik Naggum <erik@naggum.no>
parents: 16298
diff changeset
2070 Sinsert_and_inherit_before_markers, 0, MANY, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2071 doc: /* Insert text at point, relocating markers and inheriting properties.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2072 Point and markers move forward to end up after the inserted text.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2073
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2074 If the current buffer is multibyte, unibyte strings are converted
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2075 to multibyte for insertion (see `unibyte-char-to-multibyte').
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2076 If the current buffer is unibyte, multibyte strings are converted
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2077 to unibyte for insertion. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2078 (nargs, args)
4714
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
2079 int nargs;
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
2080 register Lisp_Object *args;
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
2081 {
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2082 general_insert_function (insert_before_markers_and_inherit,
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2083 insert_from_string_before_markers, 1,
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2084 nargs, args);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2085 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2086 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2087
8646
0f05e3e89f87 (Finsert_char): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents: 8333
diff changeset
2088 DEFUN ("insert-char", Finsert_char, Sinsert_char, 2, 3, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2089 doc: /* Insert COUNT (second arg) copies of CHARACTER (first arg).
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2090 Both arguments are required.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2091 Point, and before-insertion markers, are relocated as in the function `insert'.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2092 The optional third arg INHERIT, if non-nil, says to inherit text properties
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2093 from adjoining text, if those properties are sticky. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2094 (character, count, inherit)
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2095 Lisp_Object character, count, inherit;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2096 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2097 register unsigned char *string;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2098 register int strlen;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2099 register int i, n;
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2100 int len;
26853
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2101 unsigned char str[MAX_MULTIBYTE_LENGTH];
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2102
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2103 CHECK_NUMBER (character, 0);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2104 CHECK_NUMBER (count, 1);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2105
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2106 if (!NILP (current_buffer->enable_multibyte_characters))
26853
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2107 len = CHAR_STRING (XFASTINT (character), str);
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2108 else
26853
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2109 str[0] = XFASTINT (character), len = 1;
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2110 n = XINT (count) * len;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2111 if (n <= 0)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2112 return Qnil;
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2113 strlen = min (n, 256 * len);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2114 string = (unsigned char *) alloca (strlen);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2115 for (i = 0; i < strlen; i++)
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2116 string[i] = str[i % len];
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2117 while (n >= strlen)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2118 {
18194
c291aa915b85 (Finsert_char): Check QUIT.
Richard M. Stallman <rms@gnu.org>
parents: 18106
diff changeset
2119 QUIT;
8646
0f05e3e89f87 (Finsert_char): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents: 8333
diff changeset
2120 if (!NILP (inherit))
0f05e3e89f87 (Finsert_char): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents: 8333
diff changeset
2121 insert_and_inherit (string, strlen);
0f05e3e89f87 (Finsert_char): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents: 8333
diff changeset
2122 else
0f05e3e89f87 (Finsert_char): New arg INHERIT.
Richard M. Stallman <rms@gnu.org>
parents: 8333
diff changeset
2123 insert (string, strlen);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2124 n -= strlen;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2125 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2126 if (n > 0)
10382
9738aad59697 (Finsert_char): Check inherit flag for long strings too.
Karl Heuer <kwzh@gnu.org>
parents: 10308
diff changeset
2127 {
9738aad59697 (Finsert_char): Check inherit flag for long strings too.
Karl Heuer <kwzh@gnu.org>
parents: 10308
diff changeset
2128 if (!NILP (inherit))
9738aad59697 (Finsert_char): Check inherit flag for long strings too.
Karl Heuer <kwzh@gnu.org>
parents: 10308
diff changeset
2129 insert_and_inherit (string, n);
9738aad59697 (Finsert_char): Check inherit flag for long strings too.
Karl Heuer <kwzh@gnu.org>
parents: 10308
diff changeset
2130 else
9738aad59697 (Finsert_char): Check inherit flag for long strings too.
Karl Heuer <kwzh@gnu.org>
parents: 10308
diff changeset
2131 insert (string, n);
9738aad59697 (Finsert_char): Check inherit flag for long strings too.
Karl Heuer <kwzh@gnu.org>
parents: 10308
diff changeset
2132 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2133 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2134 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2135
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2136
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
2137 /* Making strings from buffer contents. */
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
2138
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
2139 /* 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
2140 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
2141 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
2142 have them, if PROPS is nonzero.
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
2143
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
2144 We don't want to use plain old make_string here, because it calls
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
2145 make_uninit_string, which can cause the buffer arena to be
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
2146 compacted. make_string has no way of knowing that the data has
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
2147 been moved, and thus copies the wrong data into the string. This
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
2148 doesn't effect most of the other users of make_string, so it should
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
2149 be left as is. But we should use this function when conjuring
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
2150 buffer substrings. */
1285
d50533e23dff * editfns.c (make_buffer_string): Call copy_intervals_to_string().
Joseph Arceneaux <jla@gnu.org>
parents: 1254
diff changeset
2151
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
2152 Lisp_Object
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2153 make_buffer_string (start, end, props)
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
2154 int start, end;
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2155 int props;
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
2156 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2157 int start_byte = CHAR_TO_BYTE (start);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2158 int end_byte = CHAR_TO_BYTE (end);
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
2159
21235
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2160 return make_buffer_string_both (start, start_byte, end, end_byte, props);
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2161 }
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2162
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2163 /* Return a Lisp_String containing the text of the current buffer from
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2164 START / START_BYTE to END / END_BYTE.
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2165
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2166 If text properties are in use and the current buffer
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2167 has properties in the range specified, the resulting string will also
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2168 have them, if PROPS is nonzero.
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2169
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2170 We don't want to use plain old make_string here, because it calls
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2171 make_uninit_string, which can cause the buffer arena to be
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2172 compacted. make_string has no way of knowing that the data has
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2173 been moved, and thus copies the wrong data into the string. This
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2174 doesn't effect most of the other users of make_string, so it should
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2175 be left as is. But we should use this function when conjuring
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2176 buffer substrings. */
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2177
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2178 Lisp_Object
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2179 make_buffer_string_both (start, start_byte, end, end_byte, props)
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2180 int start, start_byte, end, end_byte;
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2181 int props;
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2182 {
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2183 Lisp_Object result, tem, tem1;
eba3d61855d0 (make_buffer_string_both): New function.
Richard M. Stallman <rms@gnu.org>
parents: 21226
diff changeset
2184
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
2185 if (start < GPT && GPT < end)
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
2186 move_gap (start);
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
2187
21257
205a5aa4aa2f (Fchar_to_string): Use make_string_from_bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21245
diff changeset
2188 if (! NILP (current_buffer->enable_multibyte_characters))
205a5aa4aa2f (Fchar_to_string): Use make_string_from_bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21245
diff changeset
2189 result = make_uninit_multibyte_string (end - start, end_byte - start_byte);
205a5aa4aa2f (Fchar_to_string): Use make_string_from_bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21245
diff changeset
2190 else
205a5aa4aa2f (Fchar_to_string): Use make_string_from_bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21245
diff changeset
2191 result = make_uninit_string (end - start);
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2192 bcopy (BYTE_POS_ADDR (start_byte), XSTRING (result)->data,
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2193 end_byte - start_byte);
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
2194
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2195 /* 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
2196 if (props)
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2197 {
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2198 update_buffer_properties (start, end);
5130
ddee29e260d2 (make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents: 4943
diff changeset
2199
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2200 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
2201 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
2202
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2203 if (XINT (tem) != end || !NILP (tem1))
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2204 copy_intervals_to_string (result, current_buffer, start,
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2205 end - start);
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2206 }
1285
d50533e23dff * editfns.c (make_buffer_string): Call copy_intervals_to_string().
Joseph Arceneaux <jla@gnu.org>
parents: 1254
diff changeset
2207
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
2208 return result;
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
2209 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2210
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2211 /* 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
2212 in the current buffer, if necessary. */
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2213
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2214 static void
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2215 update_buffer_properties (start, end)
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2216 int start, end;
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2217 {
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2218 /* 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
2219 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
2220 if (!NILP (Vbuffer_access_fontify_functions))
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2221 {
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2222 Lisp_Object args[3];
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2223 Lisp_Object tem;
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2224
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2225 args[0] = Qbuffer_access_fontify_functions;
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2226 XSETINT (args[1], start);
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2227 XSETINT (args[2], end);
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2228
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2229 /* 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
2230 has already been done. */
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2231 if (!NILP (Vbuffer_access_fontified_property))
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2232 {
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2233 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
2234 Vbuffer_access_fontified_property,
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2235 Qnil, Qnil);
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2236 if (! NILP (tem))
14126
edc94b82c3b3 (update_buffer_properties): Delete superfluous &'s.
Karl Heuer <kwzh@gnu.org>
parents: 14071
diff changeset
2237 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
2238 }
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2239 else
14126
edc94b82c3b3 (update_buffer_properties): Delete superfluous &'s.
Karl Heuer <kwzh@gnu.org>
parents: 14071
diff changeset
2240 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
2241 }
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2242 }
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2243
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2244 DEFUN ("buffer-substring", Fbuffer_substring, Sbuffer_substring, 2, 2, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2245 doc: /* Return the contents of part of the current buffer as a string.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2246 The two arguments START and END are character positions;
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2247 they can be in either order.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2248 The string returned is multibyte if the buffer is multibyte.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2249
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2250 This function copies the text properties of that part of the buffer
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2251 into the result string; if you don't want the text properties,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2252 use `buffer-substring-no-properties' instead. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2253 (start, end)
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2254 Lisp_Object start, end;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2255 {
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2256 register int b, e;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2257
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2258 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
2259 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
2260 e = XINT (end);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2261
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2262 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
2263 }
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2264
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2265 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
2266 Sbuffer_substring_no_properties, 2, 2, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2267 doc: /* Return the characters of part of the buffer, without the text properties.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2268 The two arguments START and END are character positions;
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2269 they can be in either order. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2270 (start, end)
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2271 Lisp_Object start, end;
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2272 {
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2273 register int b, e;
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2274
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2275 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
2276 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
2277 e = XINT (end);
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2278
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2279 return make_buffer_string (b, e, 0);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2280 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2281
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2282 DEFUN ("buffer-string", Fbuffer_string, Sbuffer_string, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2283 doc: /* Return the contents of the current buffer as a string.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2284 If narrowing is in effect, this function returns only the visible part
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2285 of the buffer. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2286 ()
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2287 {
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
2288 return make_buffer_string (BEGV, ZV, 1);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2289 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2290
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2291 DEFUN ("insert-buffer-substring", Finsert_buffer_substring, Sinsert_buffer_substring,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2292 1, 3, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2293 doc: /* Insert before point a substring of the contents of buffer BUFFER.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2294 BUFFER may be a buffer or a buffer name.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2295 Arguments START and END are character numbers specifying the substring.
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2296 They default to the beginning and the end of BUFFER. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2297 (buf, start, end)
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2298 Lisp_Object buf, start, end;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2299 {
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2300 register int b, e, temp;
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2301 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
2302 Lisp_Object buffer;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2303
1854
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
2304 buffer = Fget_buffer (buf);
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
2305 if (NILP (buffer))
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
2306 nsberror (buf);
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
2307 bp = XBUFFER (buffer);
16134
7558d82368f9 (Finsert_buffer_substring): Check for deleted buffer.
Karl Heuer <kwzh@gnu.org>
parents: 16097
diff changeset
2308 if (NILP (bp->name))
7558d82368f9 (Finsert_buffer_substring): Check for deleted buffer.
Karl Heuer <kwzh@gnu.org>
parents: 16097
diff changeset
2309 error ("Selecting deleted buffer");
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2310
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2311 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
2312 b = BUF_BEGV (bp);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2313 else
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2314 {
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2315 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
2316 b = XINT (start);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2317 }
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2318 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
2319 e = BUF_ZV (bp);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2320 else
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2321 {
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2322 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
2323 e = XINT (end);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2324 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2325
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2326 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
2327 temp = b, b = e, e = temp;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2328
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2329 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
2330 args_out_of_range (start, end);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2331
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2332 obuf = current_buffer;
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2333 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
2334 update_buffer_properties (b, e);
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2335 set_buffer_internal_1 (obuf);
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
2336
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2337 insert_from_buffer (bp, b, e - b, 0);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2338 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2339 }
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2340
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2341 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
2342 6, 6, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2343 doc: /* Compare two substrings of two buffers; return result as number.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2344 the value is -N if first string is less after N-1 chars,
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2345 +N if first string is greater after N-1 chars, or 0 if strings match.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2346 Each substring is represented as three arguments: BUFFER, START and END.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2347 That makes six args in all, three for each substring.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2348
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2349 The value of `case-fold-search' in the current buffer
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2350 determines whether case is significant or ignored. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2351 (buffer1, start1, end1, buffer2, start2, end2)
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2352 Lisp_Object buffer1, start1, end1, buffer2, start2, end2;
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2353 {
21837
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2354 register int begp1, endp1, begp2, endp2, temp;
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2355 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
2356 register Lisp_Object *trt
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2357 = (!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
2358 ? XCHAR_TABLE (current_buffer->case_canon_table)->contents : 0);
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2359 int chars = 0;
21837
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2360 int i1, i2, i1_byte, i2_byte;
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2361
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2362 /* Find the first buffer and its substring. */
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2363
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2364 if (NILP (buffer1))
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2365 bp1 = current_buffer;
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2366 else
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2367 {
1854
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
2368 Lisp_Object buf1;
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
2369 buf1 = Fget_buffer (buffer1);
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
2370 if (NILP (buf1))
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
2371 nsberror (buffer1);
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
2372 bp1 = XBUFFER (buf1);
16134
7558d82368f9 (Finsert_buffer_substring): Check for deleted buffer.
Karl Heuer <kwzh@gnu.org>
parents: 16097
diff changeset
2373 if (NILP (bp1->name))
7558d82368f9 (Finsert_buffer_substring): Check for deleted buffer.
Karl Heuer <kwzh@gnu.org>
parents: 16097
diff changeset
2374 error ("Selecting deleted buffer");
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2375 }
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2376
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2377 if (NILP (start1))
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2378 begp1 = BUF_BEGV (bp1);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2379 else
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2380 {
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2381 CHECK_NUMBER_COERCE_MARKER (start1, 1);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2382 begp1 = XINT (start1);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2383 }
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2384 if (NILP (end1))
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2385 endp1 = BUF_ZV (bp1);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2386 else
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2387 {
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2388 CHECK_NUMBER_COERCE_MARKER (end1, 2);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2389 endp1 = XINT (end1);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2390 }
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2391
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2392 if (begp1 > endp1)
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2393 temp = begp1, begp1 = endp1, endp1 = temp;
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2394
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2395 if (!(BUF_BEGV (bp1) <= begp1
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2396 && begp1 <= endp1
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2397 && endp1 <= BUF_ZV (bp1)))
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2398 args_out_of_range (start1, end1);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2399
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2400 /* Likewise for second substring. */
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2401
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2402 if (NILP (buffer2))
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2403 bp2 = current_buffer;
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2404 else
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2405 {
1854
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
2406 Lisp_Object buf2;
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
2407 buf2 = Fget_buffer (buffer2);
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
2408 if (NILP (buf2))
5a18c36181fa (Finsert_buffer_substring): Proper error for non-ex buffer.
Richard M. Stallman <rms@gnu.org>
parents: 1853
diff changeset
2409 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
2410 bp2 = XBUFFER (buf2);
16134
7558d82368f9 (Finsert_buffer_substring): Check for deleted buffer.
Karl Heuer <kwzh@gnu.org>
parents: 16097
diff changeset
2411 if (NILP (bp2->name))
7558d82368f9 (Finsert_buffer_substring): Check for deleted buffer.
Karl Heuer <kwzh@gnu.org>
parents: 16097
diff changeset
2412 error ("Selecting deleted buffer");
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2413 }
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2414
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2415 if (NILP (start2))
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2416 begp2 = BUF_BEGV (bp2);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2417 else
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2418 {
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2419 CHECK_NUMBER_COERCE_MARKER (start2, 4);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2420 begp2 = XINT (start2);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2421 }
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2422 if (NILP (end2))
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2423 endp2 = BUF_ZV (bp2);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2424 else
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2425 {
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2426 CHECK_NUMBER_COERCE_MARKER (end2, 5);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2427 endp2 = XINT (end2);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2428 }
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2429
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2430 if (begp2 > endp2)
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2431 temp = begp2, begp2 = endp2, endp2 = temp;
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2432
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2433 if (!(BUF_BEGV (bp2) <= begp2
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2434 && begp2 <= endp2
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2435 && endp2 <= BUF_ZV (bp2)))
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2436 args_out_of_range (start2, end2);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2437
21837
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2438 i1 = begp1;
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2439 i2 = begp2;
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2440 i1_byte = buf_charpos_to_bytepos (bp1, i1);
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2441 i2_byte = buf_charpos_to_bytepos (bp2, i2);
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2442
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2443 while (i1 < endp1 && i2 < endp2)
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2444 {
21837
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2445 /* When we find a mismatch, we must compare the
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2446 characters, not just the bytes. */
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2447 int c1, c2;
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2448
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2449 if (! NILP (bp1->enable_multibyte_characters))
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2450 {
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2451 c1 = BUF_FETCH_MULTIBYTE_CHAR (bp1, i1_byte);
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2452 BUF_INC_POS (bp1, i1_byte);
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2453 i1++;
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2454 }
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2455 else
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2456 {
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2457 c1 = BUF_FETCH_BYTE (bp1, i1);
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2458 c1 = unibyte_char_to_multibyte (c1);
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2459 i1++;
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2460 }
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2461
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2462 if (! NILP (bp2->enable_multibyte_characters))
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2463 {
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2464 c2 = BUF_FETCH_MULTIBYTE_CHAR (bp2, i2_byte);
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2465 BUF_INC_POS (bp2, i2_byte);
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2466 i2++;
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2467 }
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2468 else
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2469 {
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2470 c2 = BUF_FETCH_BYTE (bp2, i2);
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2471 c2 = unibyte_char_to_multibyte (c2);
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2472 i2++;
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2473 }
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2474
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2475 if (trt)
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2476 {
18106
b129c5fd7925 (Fcompare_buffer_substrings): trt contains Lisp_Objects.
Richard M. Stallman <rms@gnu.org>
parents: 18031
diff changeset
2477 c1 = XINT (trt[c1]);
b129c5fd7925 (Fcompare_buffer_substrings): trt contains Lisp_Objects.
Richard M. Stallman <rms@gnu.org>
parents: 18031
diff changeset
2478 c2 = XINT (trt[c2]);
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2479 }
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2480 if (c1 < c2)
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2481 return make_number (- 1 - chars);
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2482 if (c1 > c2)
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2483 return make_number (chars + 1);
21837
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2484
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2485 chars++;
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2486 }
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2487
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2488 /* The strings match as far as they go.
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2489 If one is shorter, that one is less. */
21837
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2490 if (chars < endp1 - begp1)
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2491 return make_number (chars + 1);
21837
ea78758c282e (Fcompare_buffer_substrings): Rewrite to loop by chars.
Richard M. Stallman <rms@gnu.org>
parents: 21821
diff changeset
2492 else if (chars < endp2 - begp2)
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2493 return make_number (- chars - 1);
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2494
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2495 /* Same length too => they are equal. */
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2496 return make_number (0);
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
2497 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2498
10480
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
2499 static Lisp_Object
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
2500 subst_char_in_region_unwind (arg)
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
2501 Lisp_Object arg;
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
2502 {
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
2503 return current_buffer->undo_list = arg;
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
2504 }
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
2505
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
2506 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
2507 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
2508 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
2509 {
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
2510 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
2511 }
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
2512
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2513 DEFUN ("subst-char-in-region", Fsubst_char_in_region,
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2514 Ssubst_char_in_region, 4, 5, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2515 doc: /* From START to END, replace FROMCHAR with TOCHAR each time it occurs.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2516 If optional arg NOUNDO is non-nil, don't record this change for undo
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2517 and don't mark the buffer as really changed.
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2518 Both characters must have the same length of multi-byte form. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2519 (start, end, fromchar, tochar, noundo)
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2520 Lisp_Object start, end, fromchar, tochar, noundo;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2521 {
20834
95a80c1e06c3 (Fsubst_char_in_region): Handle character-base
Kenichi Handa <handa@m17n.org>
parents: 20826
diff changeset
2522 register int pos, pos_byte, stop, i, len, end_byte;
5130
ddee29e260d2 (make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents: 4943
diff changeset
2523 int changed = 0;
26853
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2524 unsigned char fromstr[MAX_MULTIBYTE_LENGTH], tostr[MAX_MULTIBYTE_LENGTH];
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2525 unsigned char *p;
10480
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
2526 int count = specpdl_ptr - specpdl;
25507
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2527 #define COMBINING_NO 0
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2528 #define COMBINING_BEFORE 1
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2529 #define COMBINING_AFTER 2
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2530 #define COMBINING_BOTH (COMBINING_BEFORE | COMBINING_AFTER)
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2531 int maybe_byte_combining = COMBINING_NO;
32420
40df6727225a (save_excursion_save): Additionally record the
Gerd Moellmann <gerd@gnu.org>
parents: 31774
diff changeset
2532 int last_changed = 0;
28358
7ae3851c0a19 (Fsubst_char_in_region): Don't use INC_POS in unibyte
Gerd Moellmann <gerd@gnu.org>
parents: 27727
diff changeset
2533 int multibyte_p = !NILP (current_buffer->enable_multibyte_characters);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2534
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2535 validate_region (&start, &end);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2536 CHECK_NUMBER (fromchar, 2);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2537 CHECK_NUMBER (tochar, 3);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2538
28358
7ae3851c0a19 (Fsubst_char_in_region): Don't use INC_POS in unibyte
Gerd Moellmann <gerd@gnu.org>
parents: 27727
diff changeset
2539 if (multibyte_p)
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2540 {
26853
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2541 len = CHAR_STRING (XFASTINT (fromchar), fromstr);
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2542 if (CHAR_STRING (XFASTINT (tochar), tostr) != len)
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2543 error ("Characters in subst-char-in-region have different byte-lengths");
25507
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2544 if (!ASCII_BYTE_P (*tostr))
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2545 {
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2546 /* If *TOSTR is in the range 0x80..0x9F and TOCHAR is not a
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2547 complete multibyte character, it may be combined with the
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2548 after bytes. If it is in the range 0xA0..0xFF, it may be
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2549 combined with the before and after bytes. */
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2550 if (!CHAR_HEAD_P (*tostr))
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2551 maybe_byte_combining = COMBINING_BOTH;
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2552 else if (BYTES_BY_CHAR_HEAD (*tostr) > len)
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2553 maybe_byte_combining = COMBINING_AFTER;
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2554 }
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2555 }
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2556 else
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2557 {
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2558 len = 1;
26853
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2559 fromstr[0] = XFASTINT (fromchar);
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2560 tostr[0] = XFASTINT (tochar);
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2561 }
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2562
20834
95a80c1e06c3 (Fsubst_char_in_region): Handle character-base
Kenichi Handa <handa@m17n.org>
parents: 20826
diff changeset
2563 pos = XINT (start);
95a80c1e06c3 (Fsubst_char_in_region): Handle character-base
Kenichi Handa <handa@m17n.org>
parents: 20826
diff changeset
2564 pos_byte = CHAR_TO_BYTE (pos);
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2565 stop = CHAR_TO_BYTE (XINT (end));
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2566 end_byte = stop;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2567
10480
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
2568 /* 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
2569 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
2570 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
2571 Also inhibit locking the file. */
10480
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
2572 if (!NILP (noundo))
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
2573 {
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
2574 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
2575 current_buffer->undo_list);
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
2576 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
2577 /* 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
2578 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
2579 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
2580 current_buffer->filename = Qnil;
10480
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
2581 }
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
2582
20834
95a80c1e06c3 (Fsubst_char_in_region): Handle character-base
Kenichi Handa <handa@m17n.org>
parents: 20826
diff changeset
2583 if (pos_byte < GPT_BYTE)
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2584 stop = min (stop, GPT_BYTE);
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2585 while (1)
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2586 {
23554
e06e84c477fa (Fsubst_char_in_region): Correctly handle the case
Kenichi Handa <handa@m17n.org>
parents: 23553
diff changeset
2587 int pos_byte_next = pos_byte;
e06e84c477fa (Fsubst_char_in_region): Correctly handle the case
Kenichi Handa <handa@m17n.org>
parents: 23553
diff changeset
2588
20834
95a80c1e06c3 (Fsubst_char_in_region): Handle character-base
Kenichi Handa <handa@m17n.org>
parents: 20826
diff changeset
2589 if (pos_byte >= stop)
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2590 {
20834
95a80c1e06c3 (Fsubst_char_in_region): Handle character-base
Kenichi Handa <handa@m17n.org>
parents: 20826
diff changeset
2591 if (pos_byte >= end_byte) break;
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2592 stop = end_byte;
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2593 }
20834
95a80c1e06c3 (Fsubst_char_in_region): Handle character-base
Kenichi Handa <handa@m17n.org>
parents: 20826
diff changeset
2594 p = BYTE_POS_ADDR (pos_byte);
28358
7ae3851c0a19 (Fsubst_char_in_region): Don't use INC_POS in unibyte
Gerd Moellmann <gerd@gnu.org>
parents: 27727
diff changeset
2595 if (multibyte_p)
7ae3851c0a19 (Fsubst_char_in_region): Don't use INC_POS in unibyte
Gerd Moellmann <gerd@gnu.org>
parents: 27727
diff changeset
2596 INC_POS (pos_byte_next);
7ae3851c0a19 (Fsubst_char_in_region): Don't use INC_POS in unibyte
Gerd Moellmann <gerd@gnu.org>
parents: 27727
diff changeset
2597 else
7ae3851c0a19 (Fsubst_char_in_region): Don't use INC_POS in unibyte
Gerd Moellmann <gerd@gnu.org>
parents: 27727
diff changeset
2598 ++pos_byte_next;
23554
e06e84c477fa (Fsubst_char_in_region): Correctly handle the case
Kenichi Handa <handa@m17n.org>
parents: 23553
diff changeset
2599 if (pos_byte_next - pos_byte == len
e06e84c477fa (Fsubst_char_in_region): Correctly handle the case
Kenichi Handa <handa@m17n.org>
parents: 23553
diff changeset
2600 && p[0] == fromstr[0]
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2601 && (len == 1
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2602 || (p[1] == fromstr[1]
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2603 && (len == 2 || (p[2] == fromstr[2]
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
2604 && (len == 3 || p[3] == fromstr[3]))))))
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2605 {
5130
ddee29e260d2 (make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents: 4943
diff changeset
2606 if (! changed)
ddee29e260d2 (make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents: 4943
diff changeset
2607 {
26853
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2608 changed = pos;
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2609 modify_region (current_buffer, changed, XINT (end));
5242
0e99ea9941e2 (Fmessage): Use message2.
Richard M. Stallman <rms@gnu.org>
parents: 5130
diff changeset
2610
0e99ea9941e2 (Fmessage): Use message2.
Richard M. Stallman <rms@gnu.org>
parents: 5130
diff changeset
2611 if (! NILP (noundo))
0e99ea9941e2 (Fmessage): Use message2.
Richard M. Stallman <rms@gnu.org>
parents: 5130
diff changeset
2612 {
10308
90784ed0416f Use SAVE_MODIFF and BUF_SAVE_MODIFF
Richard M. Stallman <rms@gnu.org>
parents: 9812
diff changeset
2613 if (MODIFF - 1 == SAVE_MODIFF)
90784ed0416f Use SAVE_MODIFF and BUF_SAVE_MODIFF
Richard M. Stallman <rms@gnu.org>
parents: 9812
diff changeset
2614 SAVE_MODIFF++;
5242
0e99ea9941e2 (Fmessage): Use message2.
Richard M. Stallman <rms@gnu.org>
parents: 5130
diff changeset
2615 if (MODIFF - 1 == current_buffer->auto_save_modified)
0e99ea9941e2 (Fmessage): Use message2.
Richard M. Stallman <rms@gnu.org>
parents: 5130
diff changeset
2616 current_buffer->auto_save_modified++;
0e99ea9941e2 (Fmessage): Use message2.
Richard M. Stallman <rms@gnu.org>
parents: 5130
diff changeset
2617 }
5130
ddee29e260d2 (make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents: 4943
diff changeset
2618 }
ddee29e260d2 (make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents: 4943
diff changeset
2619
22895
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2620 /* Take care of the case where the new character
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
2621 combines with neighboring bytes. */
23554
e06e84c477fa (Fsubst_char_in_region): Correctly handle the case
Kenichi Handa <handa@m17n.org>
parents: 23553
diff changeset
2622 if (maybe_byte_combining
25507
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2623 && (maybe_byte_combining == COMBINING_AFTER
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2624 ? (pos_byte_next < Z_BYTE
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2625 && ! CHAR_HEAD_P (FETCH_BYTE (pos_byte_next)))
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2626 : ((pos_byte_next < Z_BYTE
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2627 && ! CHAR_HEAD_P (FETCH_BYTE (pos_byte_next)))
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2628 || (pos_byte > BEG_BYTE
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2629 && ! ASCII_BYTE_P (FETCH_BYTE (pos_byte - 1))))))
22895
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2630 {
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2631 Lisp_Object tem, string;
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2632
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2633 struct gcpro gcpro1;
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2634
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2635 tem = current_buffer->undo_list;
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2636 GCPRO1 (tem);
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2637
25507
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2638 /* Make a multibyte string containing this single character. */
b9b4581adf36 (Fsubst_char_in_region): Adjust the way to check byte-combining
Kenichi Handa <handa@m17n.org>
parents: 25346
diff changeset
2639 string = make_multibyte_string (tostr, 1, len);
22895
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2640 /* replace_range is less efficient, because it moves the gap,
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2641 but it handles combining correctly. */
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2642 replace_range (pos, pos + 1, string,
23211
d7bd20e02b1d (Fsubst_char_in_region): Call replace_range with the
Kenichi Handa <handa@m17n.org>
parents: 23198
diff changeset
2643 0, 0, 1);
23554
e06e84c477fa (Fsubst_char_in_region): Correctly handle the case
Kenichi Handa <handa@m17n.org>
parents: 23553
diff changeset
2644 pos_byte_next = CHAR_TO_BYTE (pos);
e06e84c477fa (Fsubst_char_in_region): Correctly handle the case
Kenichi Handa <handa@m17n.org>
parents: 23553
diff changeset
2645 if (pos_byte_next > pos_byte)
e06e84c477fa (Fsubst_char_in_region): Correctly handle the case
Kenichi Handa <handa@m17n.org>
parents: 23553
diff changeset
2646 /* Before combining happened. We should not increment
23565
077655e1e014 (Fsubst_char_in_region): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 23554
diff changeset
2647 POS. So, to cancel the later increment of POS,
077655e1e014 (Fsubst_char_in_region): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 23554
diff changeset
2648 decrease it now. */
077655e1e014 (Fsubst_char_in_region): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 23554
diff changeset
2649 pos--;
23554
e06e84c477fa (Fsubst_char_in_region): Correctly handle the case
Kenichi Handa <handa@m17n.org>
parents: 23553
diff changeset
2650 else
23565
077655e1e014 (Fsubst_char_in_region): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 23554
diff changeset
2651 INC_POS (pos_byte_next);
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
2652
22895
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2653 if (! NILP (noundo))
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2654 current_buffer->undo_list = tem;
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2655
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2656 UNGCPRO;
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2657 }
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2658 else
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2659 {
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2660 if (NILP (noundo))
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2661 record_change (pos, 1);
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2662 for (i = 0; i < len; i++) *p++ = tostr[i];
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2663 }
26853
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2664 last_changed = pos + 1;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2665 }
23565
077655e1e014 (Fsubst_char_in_region): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 23554
diff changeset
2666 pos_byte = pos_byte_next;
077655e1e014 (Fsubst_char_in_region): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 23554
diff changeset
2667 pos++;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2668 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2669
5130
ddee29e260d2 (make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents: 4943
diff changeset
2670 if (changed)
26853
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2671 {
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2672 signal_after_change (changed,
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2673 last_changed - changed, last_changed - changed);
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2674 update_compositions (changed, last_changed, CHECK_ALL);
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2675 }
5130
ddee29e260d2 (make_buffer_string): Don't copy intervals
Richard M. Stallman <rms@gnu.org>
parents: 4943
diff changeset
2676
10480
fbb254882b9f (subst_char_in_region_unwind): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10383
diff changeset
2677 unbind_to (count, Qnil);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2678 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2679 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2680
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2681 DEFUN ("translate-region", Ftranslate_region, Stranslate_region, 3, 3, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2682 doc: /* From START to END, translate characters according to TABLE.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2683 TABLE is a string; the Nth character in it is the mapping
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2684 for the character with code N.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2685 This function does not alter multibyte characters.
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2686 It returns the number of characters changed. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2687 (start, end, table)
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2688 Lisp_Object start;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2689 Lisp_Object end;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2690 register Lisp_Object table;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2691 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2692 register int pos_byte, stop; /* Limits of the region. */
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2693 register unsigned char *tt; /* Trans table. */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2694 register int nc; /* New character. */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2695 int cnt; /* Number of changes made. */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2696 int size; /* Size of translate table. */
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2697 int pos;
26415
bda6a3a2bf96 (Ftranslate_region): Check the buffer multibyteness.
Kenichi Handa <handa@m17n.org>
parents: 26389
diff changeset
2698 int multibyte = !NILP (current_buffer->enable_multibyte_characters);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2699
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2700 validate_region (&start, &end);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2701 CHECK_STRING (table, 2);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2702
21245
6cde55b7c9de Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents: 21235
diff changeset
2703 size = STRING_BYTES (XSTRING (table));
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2704 tt = XSTRING (table)->data;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2705
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2706 pos_byte = CHAR_TO_BYTE (XINT (start));
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2707 stop = CHAR_TO_BYTE (XINT (end));
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2708 modify_region (current_buffer, XINT (start), XINT (end));
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2709 pos = XINT (start);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2710
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2711 cnt = 0;
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2712 for (; pos_byte < stop; )
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2713 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2714 register unsigned char *p = BYTE_POS_ADDR (pos_byte);
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2715 int len;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2716 int oc;
23554
e06e84c477fa (Fsubst_char_in_region): Correctly handle the case
Kenichi Handa <handa@m17n.org>
parents: 23553
diff changeset
2717 int pos_byte_next;
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2718
26415
bda6a3a2bf96 (Ftranslate_region): Check the buffer multibyteness.
Kenichi Handa <handa@m17n.org>
parents: 26389
diff changeset
2719 if (multibyte)
bda6a3a2bf96 (Ftranslate_region): Check the buffer multibyteness.
Kenichi Handa <handa@m17n.org>
parents: 26389
diff changeset
2720 oc = STRING_CHAR_AND_LENGTH (p, stop - pos_byte, len);
bda6a3a2bf96 (Ftranslate_region): Check the buffer multibyteness.
Kenichi Handa <handa@m17n.org>
parents: 26389
diff changeset
2721 else
bda6a3a2bf96 (Ftranslate_region): Check the buffer multibyteness.
Kenichi Handa <handa@m17n.org>
parents: 26389
diff changeset
2722 oc = *p, len = 1;
23554
e06e84c477fa (Fsubst_char_in_region): Correctly handle the case
Kenichi Handa <handa@m17n.org>
parents: 23553
diff changeset
2723 pos_byte_next = pos_byte + len;
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
2724 if (oc < size && len == 1)
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2725 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2726 nc = tt[oc];
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2727 if (nc != oc)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2728 {
22895
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2729 /* Take care of the case where the new character
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
2730 combines with neighboring bytes. */
23554
e06e84c477fa (Fsubst_char_in_region): Correctly handle the case
Kenichi Handa <handa@m17n.org>
parents: 23553
diff changeset
2731 if (!ASCII_BYTE_P (nc)
e06e84c477fa (Fsubst_char_in_region): Correctly handle the case
Kenichi Handa <handa@m17n.org>
parents: 23553
diff changeset
2732 && (CHAR_HEAD_P (nc)
e06e84c477fa (Fsubst_char_in_region): Correctly handle the case
Kenichi Handa <handa@m17n.org>
parents: 23553
diff changeset
2733 ? ! CHAR_HEAD_P (FETCH_BYTE (pos_byte + 1))
23596
8dcbcad4482c (Fsubst_char_in_region): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 23577
diff changeset
2734 : (pos_byte > BEG_BYTE
23554
e06e84c477fa (Fsubst_char_in_region): Correctly handle the case
Kenichi Handa <handa@m17n.org>
parents: 23553
diff changeset
2735 && ! ASCII_BYTE_P (FETCH_BYTE (pos_byte - 1)))))
22895
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2736 {
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2737 Lisp_Object string;
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2738
23554
e06e84c477fa (Fsubst_char_in_region): Correctly handle the case
Kenichi Handa <handa@m17n.org>
parents: 23553
diff changeset
2739 string = make_multibyte_string (tt + oc, 1, 1);
22895
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2740 /* This is less efficient, because it moves the gap,
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2741 but it handles combining correctly. */
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2742 replace_range (pos, pos + 1, string,
23554
e06e84c477fa (Fsubst_char_in_region): Correctly handle the case
Kenichi Handa <handa@m17n.org>
parents: 23553
diff changeset
2743 1, 0, 1);
e06e84c477fa (Fsubst_char_in_region): Correctly handle the case
Kenichi Handa <handa@m17n.org>
parents: 23553
diff changeset
2744 pos_byte_next = CHAR_TO_BYTE (pos);
e06e84c477fa (Fsubst_char_in_region): Correctly handle the case
Kenichi Handa <handa@m17n.org>
parents: 23553
diff changeset
2745 if (pos_byte_next > pos_byte)
e06e84c477fa (Fsubst_char_in_region): Correctly handle the case
Kenichi Handa <handa@m17n.org>
parents: 23553
diff changeset
2746 /* Before combining happened. We should not
23565
077655e1e014 (Fsubst_char_in_region): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 23554
diff changeset
2747 increment POS. So, to cancel the later
077655e1e014 (Fsubst_char_in_region): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 23554
diff changeset
2748 increment of POS, we decrease it now. */
077655e1e014 (Fsubst_char_in_region): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 23554
diff changeset
2749 pos--;
23554
e06e84c477fa (Fsubst_char_in_region): Correctly handle the case
Kenichi Handa <handa@m17n.org>
parents: 23553
diff changeset
2750 else
23565
077655e1e014 (Fsubst_char_in_region): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 23554
diff changeset
2751 INC_POS (pos_byte_next);
22895
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2752 }
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2753 else
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2754 {
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2755 record_change (pos, 1);
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2756 *p = nc;
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2757 signal_after_change (pos, 1, 1);
26853
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2758 update_compositions (pos, pos + 1, CHECK_BORDER);
22895
9f800ebc6091 (Fsubst_char_in_region): Use replace_range in the case
Richard M. Stallman <rms@gnu.org>
parents: 22712
diff changeset
2759 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2760 ++cnt;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2761 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2762 }
23565
077655e1e014 (Fsubst_char_in_region): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 23554
diff changeset
2763 pos_byte = pos_byte_next;
077655e1e014 (Fsubst_char_in_region): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 23554
diff changeset
2764 pos++;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2765 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2766
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2767 return make_number (cnt);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2768 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2769
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2770 DEFUN ("delete-region", Fdelete_region, Sdelete_region, 2, 2, "r",
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2771 doc: /* Delete the text between point and mark.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2772 When called from a program, expects two arguments,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2773 positions (integers or markers) specifying the stretch to be deleted. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2774 (start, end)
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2775 Lisp_Object start, end;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2776 {
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2777 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
2778 del_range (XINT (start), XINT (end));
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2779 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2780 }
26742
936b39bd05b4 * editfns.c (Fdelete_and_extract_region): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26699
diff changeset
2781
936b39bd05b4 * editfns.c (Fdelete_and_extract_region): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26699
diff changeset
2782 DEFUN ("delete-and-extract-region", Fdelete_and_extract_region,
936b39bd05b4 * editfns.c (Fdelete_and_extract_region): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26699
diff changeset
2783 Sdelete_and_extract_region, 2, 2, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2784 doc: /* Delete the text between START and END and return it. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2785 (start, end)
26742
936b39bd05b4 * editfns.c (Fdelete_and_extract_region): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26699
diff changeset
2786 Lisp_Object start, end;
936b39bd05b4 * editfns.c (Fdelete_and_extract_region): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26699
diff changeset
2787 {
936b39bd05b4 * editfns.c (Fdelete_and_extract_region): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26699
diff changeset
2788 validate_region (&start, &end);
936b39bd05b4 * editfns.c (Fdelete_and_extract_region): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26699
diff changeset
2789 return del_range_1 (XINT (start), XINT (end), 1, 1);
936b39bd05b4 * editfns.c (Fdelete_and_extract_region): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26699
diff changeset
2790 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2791
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2792 DEFUN ("widen", Fwiden, Swiden, 0, 0, "",
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2793 doc: /* Remove restrictions (narrowing) from current buffer.
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2794 This allows the buffer's full text to be seen and edited. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2795 ()
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2796 {
19207
be370e94fb42 (Fwiden, Fnarrow_to_region, save_restriction_restore):
Richard M. Stallman <rms@gnu.org>
parents: 19032
diff changeset
2797 if (BEG != BEGV || Z != ZV)
be370e94fb42 (Fwiden, Fnarrow_to_region, save_restriction_restore):
Richard M. Stallman <rms@gnu.org>
parents: 19032
diff changeset
2798 current_buffer->clip_changed = 1;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2799 BEGV = BEG;
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2800 BEGV_BYTE = BEG_BYTE;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2801 SET_BUF_ZV_BOTH (current_buffer, Z, Z_BYTE);
330
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
2802 /* Changing the buffer bounds invalidates any recorded current column. */
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
2803 invalidate_current_column ();
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2804 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2805 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2806
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2807 DEFUN ("narrow-to-region", Fnarrow_to_region, Snarrow_to_region, 2, 2, "r",
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2808 doc: /* Restrict editing in this buffer to the current region.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2809 The rest of the text becomes temporarily invisible and untouchable
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2810 but is not deleted; if you save the buffer in a file, the invisible
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2811 text is included in the file. \\[widen] makes all visible again.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2812 See also `save-restriction'.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2813
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2814 When calling from a program, pass two arguments; positions (integers
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2815 or markers) bounding the text that should remain visible. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2816 (start, end)
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2817 register Lisp_Object start, end;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2818 {
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2819 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
2820 CHECK_NUMBER_COERCE_MARKER (end, 1);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2821
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2822 if (XINT (start) > XINT (end))
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2823 {
10383
a7fe0fb11314 (Fnarrow_to_region): Swap using temp Lisp_Object, not int.
Karl Heuer <kwzh@gnu.org>
parents: 10382
diff changeset
2824 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
2825 tem = start; start = end; end = tem;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2826 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2827
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2828 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
2829 args_out_of_range (start, end);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2830
19207
be370e94fb42 (Fwiden, Fnarrow_to_region, save_restriction_restore):
Richard M. Stallman <rms@gnu.org>
parents: 19032
diff changeset
2831 if (BEGV != XFASTINT (start) || ZV != XFASTINT (end))
be370e94fb42 (Fwiden, Fnarrow_to_region, save_restriction_restore):
Richard M. Stallman <rms@gnu.org>
parents: 19032
diff changeset
2832 current_buffer->clip_changed = 1;
be370e94fb42 (Fwiden, Fnarrow_to_region, save_restriction_restore):
Richard M. Stallman <rms@gnu.org>
parents: 19032
diff changeset
2833
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
2834 SET_BUF_BEGV (current_buffer, XFASTINT (start));
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2835 SET_BUF_ZV (current_buffer, XFASTINT (end));
16039
855c8d8ba0f0 Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents: 15910
diff changeset
2836 if (PT < XFASTINT (start))
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2837 SET_PT (XFASTINT (start));
16039
855c8d8ba0f0 Change all references from point to PT.
Karl Heuer <kwzh@gnu.org>
parents: 15910
diff changeset
2838 if (PT > XFASTINT (end))
14071
59906ecd9b92 (Fchar_to_string, Fstring_to_char, Fgoto_char, Fencode_time, Finsert_char,
Erik Naggum <erik@naggum.no>
parents: 13878
diff changeset
2839 SET_PT (XFASTINT (end));
330
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
2840 /* Changing the buffer bounds invalidates any recorded current column. */
9b1e9b496441 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 305
diff changeset
2841 invalidate_current_column ();
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2842 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2843 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2844
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2845 Lisp_Object
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2846 save_restriction_save ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2847 {
30931
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2848 if (BEGV == BEG && ZV == Z)
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2849 /* The common case that the buffer isn't narrowed.
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2850 We return just the buffer object, which save_restriction_restore
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2851 recognizes as meaning `no restriction'. */
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2852 return Fcurrent_buffer ();
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2853 else
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2854 /* We have to save a restriction, so return a pair of markers, one
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2855 for the beginning and one for the end. */
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2856 {
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2857 Lisp_Object beg, end;
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2858
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2859 beg = buildmark (BEGV, BEGV_BYTE);
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2860 end = buildmark (ZV, ZV_BYTE);
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2861
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2862 /* END must move forward if text is inserted at its exact location. */
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2863 XMARKER(end)->insertion_type = 1;
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2864
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2865 return Fcons (beg, end);
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2866 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2867 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2868
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2869 Lisp_Object
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2870 save_restriction_restore (data)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2871 Lisp_Object data;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2872 {
30931
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2873 if (CONSP (data))
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2874 /* A pair of marks bounding a saved restriction. */
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2875 {
30931
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2876 struct Lisp_Marker *beg = XMARKER (XCAR (data));
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2877 struct Lisp_Marker *end = XMARKER (XCDR (data));
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2878 struct buffer *buf = beg->buffer; /* END should have the same buffer. */
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2879
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2880 if (beg->charpos != BUF_BEGV(buf) || end->charpos != BUF_ZV(buf))
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2881 /* The restriction has changed from the saved one, so restore
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2882 the saved restriction. */
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2883 {
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2884 int pt = BUF_PT (buf);
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2885
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2886 SET_BUF_BEGV_BOTH (buf, beg->charpos, beg->bytepos);
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2887 SET_BUF_ZV_BOTH (buf, end->charpos, end->bytepos);
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2888
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2889 if (pt < beg->charpos || pt > end->charpos)
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2890 /* The point is outside the new visible range, move it inside. */
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2891 SET_BUF_PT_BOTH (buf,
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2892 clip_to_bounds (beg->charpos, pt, end->charpos),
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2893 clip_to_bounds (beg->bytepos, BUF_PT_BYTE(buf),
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2894 end->bytepos));
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2895
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2896 buf->clip_changed = 1; /* Remember that the narrowing changed. */
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2897 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2898 }
30931
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2899 else
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2900 /* A buffer, which means that there was no old restriction. */
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2901 {
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2902 struct buffer *buf = XBUFFER (data);
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2903
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2904 if (BUF_BEGV(buf) != BUF_BEG(buf) || BUF_ZV(buf) != BUF_Z(buf))
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2905 /* The buffer has been narrowed, get rid of the narrowing. */
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2906 {
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2907 SET_BUF_BEGV_BOTH (buf, BUF_BEG(buf), BUF_BEG_BYTE(buf));
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2908 SET_BUF_ZV_BOTH (buf, BUF_Z(buf), BUF_Z_BYTE(buf));
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2909
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2910 buf->clip_changed = 1; /* Remember that the narrowing changed. */
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2911 }
35428eaf59e3 (save_restriction_save): Rewrite to use markers.
Miles Bader <miles@gnu.org>
parents: 30677
diff changeset
2912 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2913
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2914 return Qnil;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2915 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2916
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2917 DEFUN ("save-restriction", Fsave_restriction, Ssave_restriction, 0, UNEVALLED, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2918 doc: /* Execute BODY, saving and restoring current buffer's restrictions.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2919 The buffer's restrictions make parts of the beginning and end invisible.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2920 (They are set up with `narrow-to-region' and eliminated with `widen'.)
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2921 This special form, `save-restriction', saves the current buffer's restrictions
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2922 when it is entered, and restores them when it is exited.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2923 So any `narrow-to-region' within BODY lasts only until the end of the form.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2924 The old restrictions settings are restored
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2925 even in case of abnormal exit (throw or error).
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2926
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2927 The value returned is the value of the last form in BODY.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2928
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2929 Note: if you are using both `save-excursion' and `save-restriction',
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2930 use `save-excursion' outermost:
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2931 (save-excursion (save-restriction ...)) */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2932 (body)
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2933 Lisp_Object body;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2934 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2935 register Lisp_Object val;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2936 int count = specpdl_ptr - specpdl;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2937
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2938 record_unwind_protect (save_restriction_restore, save_restriction_save ());
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2939 val = Fprogn (body);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2940 return unbind_to (count, val);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2941 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2942
38059
0b34b024286d (Fmessage_box): If the frame is not under a window
Eli Zaretskii <eliz@gnu.org>
parents: 37916
diff changeset
2943 /* Buffer for the most recent text displayed by Fmessage_box. */
5884
d02095ea13a5 (Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents: 5882
diff changeset
2944 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
2945
d02095ea13a5 (Fmessage): Copy the text to be displayed into a malloc'd buffer.
Karl Heuer <kwzh@gnu.org>
parents: 5882
diff changeset
2946 /* 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
2947 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
2948
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2949 DEFUN ("message", Fmessage, Smessage, 1, MANY, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2950 doc: /* Print a one-line message at the bottom of the screen.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2951 The first argument is a format control string, and the rest are data
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2952 to be formatted under control of the string. See `format' for details.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2953
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2954 If the first argument is nil, clear any existing message; let the
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2955 minibuffer contents show. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2956 (nargs, args)
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2957 int nargs;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2958 Lisp_Object *args;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2959 {
1426
67fd35416ba3 * * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents: 1285
diff changeset
2960 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
2961 {
e21c1f3e37cb * editfns.c (Fmessage): Don't forget to return a value when
Jim Blandy <jimb@redhat.com>
parents: 1854
diff changeset
2962 message (0);
e21c1f3e37cb * editfns.c (Fmessage): Don't forget to return a value when
Jim Blandy <jimb@redhat.com>
parents: 1854
diff changeset
2963 return Qnil;
e21c1f3e37cb * editfns.c (Fmessage): Don't forget to return a value when
Jim Blandy <jimb@redhat.com>
parents: 1854
diff changeset
2964 }
1426
67fd35416ba3 * * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents: 1285
diff changeset
2965 else
67fd35416ba3 * * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents: 1285
diff changeset
2966 {
67fd35416ba3 * * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents: 1285
diff changeset
2967 register Lisp_Object val;
67fd35416ba3 * * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents: 1285
diff changeset
2968 val = Fformat (nargs, args);
25018
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
2969 message3 (val, STRING_BYTES (XSTRING (val)), STRING_MULTIBYTE (val));
1426
67fd35416ba3 * * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents: 1285
diff changeset
2970 return val;
67fd35416ba3 * * editfns.c (Fmessage): With no arguments, clear any active
Jim Blandy <jimb@redhat.com>
parents: 1285
diff changeset
2971 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2972 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2973
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2974 DEFUN ("message-box", Fmessage_box, Smessage_box, 1, MANY, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2975 doc: /* Display a message, in a dialog box if possible.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2976 If a dialog box is not available, use the echo area.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2977 The first argument is a format control string, and the rest are data
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2978 to be formatted under control of the string. See `format' for details.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2979
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
2980 If the first argument is nil, clear any existing message; let the
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2981 minibuffer contents show. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
2982 (nargs, args)
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2983 int nargs;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2984 Lisp_Object *args;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2985 {
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2986 if (NILP (args[0]))
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2987 {
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2988 message (0);
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2989 return Qnil;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2990 }
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2991 else
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2992 {
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2993 register Lisp_Object val;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
2994 val = Fformat (nargs, args);
13878
2a71500dfb93 (Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents: 13767
diff changeset
2995 #ifdef HAVE_MENUS
38059
0b34b024286d (Fmessage_box): If the frame is not under a window
Eli Zaretskii <eliz@gnu.org>
parents: 37916
diff changeset
2996 /* The MS-DOS frames support popup menus even though they are
0b34b024286d (Fmessage_box): If the frame is not under a window
Eli Zaretskii <eliz@gnu.org>
parents: 37916
diff changeset
2997 not FRAME_WINDOW_P. */
0b34b024286d (Fmessage_box): If the frame is not under a window
Eli Zaretskii <eliz@gnu.org>
parents: 37916
diff changeset
2998 if (FRAME_WINDOW_P (XFRAME (selected_frame))
0b34b024286d (Fmessage_box): If the frame is not under a window
Eli Zaretskii <eliz@gnu.org>
parents: 37916
diff changeset
2999 || FRAME_MSDOS_P (XFRAME (selected_frame)))
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3000 {
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3001 Lisp_Object pane, menu, obj;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3002 struct gcpro gcpro1;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3003 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
3004 GCPRO1 (pane);
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3005 menu = Fcons (val, pane);
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3006 obj = Fx_popup_dialog (Qt, menu);
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3007 UNGCPRO;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3008 return val;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3009 }
38059
0b34b024286d (Fmessage_box): If the frame is not under a window
Eli Zaretskii <eliz@gnu.org>
parents: 37916
diff changeset
3010 #endif /* HAVE_MENUS */
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3011 /* 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
3012 if (! message_text)
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3013 {
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3014 message_text = (char *)xmalloc (80);
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3015 message_length = 80;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3016 }
21245
6cde55b7c9de Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents: 21235
diff changeset
3017 if (STRING_BYTES (XSTRING (val)) > message_length)
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3018 {
21245
6cde55b7c9de Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents: 21235
diff changeset
3019 message_length = STRING_BYTES (XSTRING (val));
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3020 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
3021 }
21245
6cde55b7c9de Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents: 21235
diff changeset
3022 bcopy (XSTRING (val)->data, message_text, STRING_BYTES (XSTRING (val)));
21358
e9f7d8708bae (Fmessage_box): Pass the missing third argument
Richard M. Stallman <rms@gnu.org>
parents: 21257
diff changeset
3023 message2 (message_text, STRING_BYTES (XSTRING (val)),
e9f7d8708bae (Fmessage_box): Pass the missing third argument
Richard M. Stallman <rms@gnu.org>
parents: 21257
diff changeset
3024 STRING_MULTIBYTE (val));
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3025 return val;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3026 }
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3027 }
13878
2a71500dfb93 (Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents: 13767
diff changeset
3028 #ifdef HAVE_MENUS
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3029 extern Lisp_Object last_nonmenu_event;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3030 #endif
13878
2a71500dfb93 (Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents: 13767
diff changeset
3031
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3032 DEFUN ("message-or-box", Fmessage_or_box, Smessage_or_box, 1, MANY, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3033 doc: /* Display a message in a dialog box or in the echo area.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3034 If this command was invoked with the mouse, use a dialog box if
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3035 `use-dialog-box' is non-nil.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3036 Otherwise, use the echo area.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3037 The first argument is a format control string, and the rest are data
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3038 to be formatted under control of the string. See `format' for details.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3039
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3040 If the first argument is nil, clear any existing message; let the
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3041 minibuffer contents show. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3042 (nargs, args)
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3043 int nargs;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3044 Lisp_Object *args;
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3045 {
13878
2a71500dfb93 (Fmessage_box, Fmessage_or_box):
Richard M. Stallman <rms@gnu.org>
parents: 13767
diff changeset
3046 #ifdef HAVE_MENUS
26699
ed4ab9d24450 (Fmessage_or_box): Use use_dialog_box.
Dave Love <fx@gnu.org>
parents: 26629
diff changeset
3047 if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
28470
93996c44b23a * editfns.c (text_property_stickiness, Fmessage_or_box): Use NILP to test
Ken Raeburn <raeburn@raeburn.org>
parents: 28358
diff changeset
3048 && use_dialog_box)
8981
6e1a5ff3d795 (Fmessage_or_box): Use Fmessage_box with new name.
Richard M. Stallman <rms@gnu.org>
parents: 8975
diff changeset
3049 return Fmessage_box (nargs, args);
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3050 #endif
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3051 return Fmessage (nargs, args);
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3052 }
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
3053
18937
ddb91108a9d2 (Fcurrent_message): New function.
Richard M. Stallman <rms@gnu.org>
parents: 18756
diff changeset
3054 DEFUN ("current-message", Fcurrent_message, Scurrent_message, 0, 0, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3055 doc: /* Return the string currently displayed in the echo area, or nil if none. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3056 ()
18937
ddb91108a9d2 (Fcurrent_message): New function.
Richard M. Stallman <rms@gnu.org>
parents: 18756
diff changeset
3057 {
25346
15ec35852b48 Remove conditional compilation on NO_PROMPT_IN_BUFFER.
Gerd Moellmann <gerd@gnu.org>
parents: 25018
diff changeset
3058 return current_message ();
18937
ddb91108a9d2 (Fcurrent_message): New function.
Richard M. Stallman <rms@gnu.org>
parents: 18756
diff changeset
3059 }
ddb91108a9d2 (Fcurrent_message): New function.
Richard M. Stallman <rms@gnu.org>
parents: 18756
diff changeset
3060
25815
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3061
25833
65cab65c4a28 (Fpropertize): Renamed from Fproperties.
Gerd Moellmann <gerd@gnu.org>
parents: 25815
diff changeset
3062 DEFUN ("propertize", Fpropertize, Spropertize, 3, MANY, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3063 doc: /* Return a copy of STRING with text properties added.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3064 First argument is the string to copy.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3065 Remaining arguments form a sequence of PROPERTY VALUE pairs for text
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3066 properties to add to the result. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3067 (nargs, args)
25815
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3068 int nargs;
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3069 Lisp_Object *args;
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3070 {
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3071 Lisp_Object properties, string;
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3072 struct gcpro gcpro1, gcpro2;
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3073 int i;
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3074
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3075 /* Number of args must be odd. */
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3076 if ((nargs & 1) == 0 || nargs < 3)
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3077 error ("Wrong number of arguments");
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3078
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3079 properties = string = Qnil;
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3080 GCPRO2 (properties, string);
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
3081
25815
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3082 /* First argument must be a string. */
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3083 CHECK_STRING (args[0], 0);
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3084 string = Fcopy_sequence (args[0]);
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3085
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3086 for (i = 1; i < nargs; i += 2)
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3087 {
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3088 CHECK_SYMBOL (args[i], i);
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3089 properties = Fcons (args[i], Fcons (args[i + 1], properties));
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3090 }
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3091
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3092 Fadd_text_properties (make_number (0),
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3093 make_number (XSTRING (string)->size),
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3094 properties, string);
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3095 RETURN_UNGCPRO (string);
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3096 }
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3097
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3098
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3099 /* Number of bytes that STRING will occupy when put into the result.
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3100 MULTIBYTE is nonzero if the result should be multibyte. */
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3101
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3102 #define CONVERTED_BYTE_SIZE(MULTIBYTE, STRING) \
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3103 (((MULTIBYTE) && ! STRING_MULTIBYTE (STRING)) \
20804
14fa73136e64 (CONVERTED_BYTE_SIZE): Fix the logic.
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
3104 ? count_size_as_multibyte (XSTRING (STRING)->data, \
21245
6cde55b7c9de Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents: 21235
diff changeset
3105 STRING_BYTES (XSTRING (STRING))) \
6cde55b7c9de Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents: 21235
diff changeset
3106 : STRING_BYTES (XSTRING (STRING)))
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3107
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3108 DEFUN ("format", Fformat, Sformat, 1, MANY, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3109 doc: /* Format a string out of a control-string and arguments.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3110 The first argument is a control string.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3111 The other arguments are substituted into it to make the result, a string.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3112 It may contain %-sequences meaning to substitute the next argument.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3113 %s means print a string argument. Actually, prints any object, with `princ'.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3114 %d means print as number in decimal (%o octal, %x hex).
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3115 %X is like %x, but uses upper case.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3116 %e means print a number in exponential notation.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3117 %f means print a number in decimal-point notation.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3118 %g means print a number in exponential notation
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3119 or decimal-point notation, whichever uses fewer characters.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3120 %c means print a number as a single character.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3121 %S means print any object as an s-expression (using `prin1').
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3122 The argument used for %d, %o, %x, %e, %f, %g or %c must be a number.
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3123 Use %% to put a single % into the output. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3124 (nargs, args)
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3125 int nargs;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3126 register Lisp_Object *args;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3127 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3128 register int n; /* The number of the next arg to substitute */
20826
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3129 register int total; /* An estimate of the final length */
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3130 char *buf, *p;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3131 register unsigned char *format, *end;
25782
8f59abd3a02b (init_editfns): Remove unused variables.
Gerd Moellmann <gerd@gnu.org>
parents: 25662
diff changeset
3132 int nchars;
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3133 /* Nonzero if the output should be a multibyte string,
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3134 which is true if any of the inputs is one. */
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3135 int multibyte = 0;
22698
ea6ef56295b4 (Fformat): Pay attention to the byte combining problem.
Kenichi Handa <handa@m17n.org>
parents: 22669
diff changeset
3136 /* When we make a multibyte string, we must pay attention to the
ea6ef56295b4 (Fformat): Pay attention to the byte combining problem.
Kenichi Handa <handa@m17n.org>
parents: 22669
diff changeset
3137 byte combining problem, i.e., a byte may be combined with a
ea6ef56295b4 (Fformat): Pay attention to the byte combining problem.
Kenichi Handa <handa@m17n.org>
parents: 22669
diff changeset
3138 multibyte charcter of the previous string. This flag tells if we
ea6ef56295b4 (Fformat): Pay attention to the byte combining problem.
Kenichi Handa <handa@m17n.org>
parents: 22669
diff changeset
3139 must consider such a situation or not. */
ea6ef56295b4 (Fformat): Pay attention to the byte combining problem.
Kenichi Handa <handa@m17n.org>
parents: 22669
diff changeset
3140 int maybe_combine_byte;
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3141 unsigned char *this_format;
20826
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3142 int longest_format;
20804
14fa73136e64 (CONVERTED_BYTE_SIZE): Fix the logic.
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
3143 Lisp_Object val;
25018
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3144 struct info
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3145 {
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3146 int start, end;
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3147 } *info = 0;
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3148
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3149 /* It should not be necessary to GCPRO ARGS, because
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3150 the caller in the interpreter should take care of that. */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3151
20826
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3152 /* Try to determine whether the result should be multibyte.
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3153 This is not always right; sometimes the result needs to be multibyte
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3154 because of an object that we will pass through prin1,
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3155 and in that case, we won't know it here. */
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3156 for (n = 0; n < nargs; n++)
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3157 if (STRINGP (args[n]) && STRING_MULTIBYTE (args[n]))
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3158 multibyte = 1;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3159
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3160 CHECK_STRING (args[0], 0);
20826
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3161
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3162 /* If we start out planning a unibyte result,
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3163 and later find it has to be multibyte, we jump back to retry. */
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3164 retry:
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3165
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3166 format = XSTRING (args[0])->data;
21245
6cde55b7c9de Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents: 21235
diff changeset
3167 end = format + STRING_BYTES (XSTRING (args[0]));
20826
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3168 longest_format = 0;
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3169
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3170 /* Make room in result for all the non-%-codes in the control string. */
20826
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3171 total = 5 + CONVERTED_BYTE_SIZE (multibyte, args[0]);
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3172
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3173 /* Add to TOTAL enough space to hold the converted arguments. */
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3174
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3175 n = 0;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3176 while (format != end)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3177 if (*format++ == '%')
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3178 {
34566
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3179 int thissize = 0;
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3180 unsigned char *this_format_start = format - 1;
34566
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3181 int field_width, precision;
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3182
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3183 /* General format specifications look like
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3184
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3185 '%' [flags] [field-width] [precision] format
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3186
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3187 where
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3188
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3189 flags ::= [#-* 0]+
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3190 field-width ::= [0-9]+
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3191 precision ::= '.' [0-9]*
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3192
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3193 If a field-width is specified, it specifies to which width
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3194 the output should be padded with blanks, iff the output
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3195 string is shorter than field-width.
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3196
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3197 if precision is specified, it specifies the number of
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3198 digits to print after the '.' for floats, or the max.
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3199 number of chars to print from a string. */
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3200
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3201 precision = field_width = 0;
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3202
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3203 while (index ("-*# 0", *format))
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3204 ++format;
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3205
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3206 if (*format >= '0' && *format <= '9')
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3207 {
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3208 for (field_width = 0; *format >= '0' && *format <= '9'; ++format)
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3209 field_width = 10 * field_width + *format - '0';
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3210 }
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3211
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3212 if (*format == '.')
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3213 {
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3214 ++format;
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3215 for (precision = 0; *format >= '0' && *format <= '9'; ++format)
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3216 precision = 10 * precision + *format - '0';
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3217 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3218
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3219 if (format - this_format_start + 1 > longest_format)
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3220 longest_format = format - this_format_start + 1;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3221
23197
0d3baa5514b7 (Fformat): Detect incomplete format spec at string's end.
Karl Heuer <kwzh@gnu.org>
parents: 23166
diff changeset
3222 if (format == end)
0d3baa5514b7 (Fformat): Detect incomplete format spec at string's end.
Karl Heuer <kwzh@gnu.org>
parents: 23166
diff changeset
3223 error ("Format string ends in middle of format specifier");
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3224 if (*format == '%')
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3225 format++;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3226 else if (++n >= nargs)
12831
3917c5d131d3 (Fformat): Limit minlen to avoid stack overflow.
Richard M. Stallman <rms@gnu.org>
parents: 12623
diff changeset
3227 error ("Not enough arguments for format string");
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3228 else if (*format == 'S')
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3229 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3230 /* For `S', prin1 the argument and then treat like a string. */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3231 register Lisp_Object tem;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3232 tem = Fprin1_to_string (args[n], Qnil);
20826
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3233 if (STRING_MULTIBYTE (tem) && ! multibyte)
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3234 {
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3235 multibyte = 1;
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3236 goto retry;
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3237 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3238 args[n] = tem;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3239 goto string;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3240 }
9163
41fe5f636879 (lisp_time_argument, Finsert, Finsert_and_inherit, Finsert_before_markers,
Karl Heuer <kwzh@gnu.org>
parents: 9154
diff changeset
3241 else if (SYMBOLP (args[n]))
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3242 {
28470
93996c44b23a * editfns.c (text_property_stickiness, Fmessage_or_box): Use NILP to test
Ken Raeburn <raeburn@raeburn.org>
parents: 28358
diff changeset
3243 /* Use a temp var to avoid problems when ENABLE_CHECKING
93996c44b23a * editfns.c (text_property_stickiness, Fmessage_or_box): Use NILP to test
Ken Raeburn <raeburn@raeburn.org>
parents: 28358
diff changeset
3244 is turned on. */
93996c44b23a * editfns.c (text_property_stickiness, Fmessage_or_box): Use NILP to test
Ken Raeburn <raeburn@raeburn.org>
parents: 28358
diff changeset
3245 struct Lisp_String *t = XSYMBOL (args[n])->name;
93996c44b23a * editfns.c (text_property_stickiness, Fmessage_or_box): Use NILP to test
Ken Raeburn <raeburn@raeburn.org>
parents: 28358
diff changeset
3246 XSETSTRING (args[n], t);
20861
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
3247 if (STRING_MULTIBYTE (args[n]) && ! multibyte)
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
3248 {
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
3249 multibyte = 1;
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
3250 goto retry;
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
3251 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3252 goto string;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3253 }
9163
41fe5f636879 (lisp_time_argument, Finsert, Finsert_and_inherit, Finsert_before_markers,
Karl Heuer <kwzh@gnu.org>
parents: 9154
diff changeset
3254 else if (STRINGP (args[n]))
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3255 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3256 string:
6528
d0f6a386b7cb (Fformat): Validate number and type of arguments.
Karl Heuer <kwzh@gnu.org>
parents: 6206
diff changeset
3257 if (*format != 's' && *format != 'S')
23197
0d3baa5514b7 (Fformat): Detect incomplete format spec at string's end.
Karl Heuer <kwzh@gnu.org>
parents: 23166
diff changeset
3258 error ("Format specifier doesn't match argument type");
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3259 thissize = CONVERTED_BYTE_SIZE (multibyte, args[n]);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3260 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3261 /* 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
3262 else if (INTEGERP (args[n]) && *format != 's')
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3263 {
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3522
diff changeset
3264 /* The following loop assumes the Lisp type indicates
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3265 the proper way to pass the argument.
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3266 So make sure we have a flonum if the argument should
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3267 be a double. */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3268 if (*format == 'e' || *format == 'f' || *format == 'g')
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3269 args[n] = Ffloat (args[n]);
23326
df3f641c9ca1 (Fformat): Check format control characters.
Kenichi Handa <handa@m17n.org>
parents: 23292
diff changeset
3270 else
df3f641c9ca1 (Fformat): Check format control characters.
Kenichi Handa <handa@m17n.org>
parents: 23292
diff changeset
3271 if (*format != 'd' && *format != 'o' && *format != 'x'
24505
d6fcaeb4c03c (Fformat): Accept %i format.
Karl Heuer <kwzh@gnu.org>
parents: 24272
diff changeset
3272 && *format != 'i' && *format != 'X' && *format != 'c')
23326
df3f641c9ca1 (Fformat): Check format control characters.
Kenichi Handa <handa@m17n.org>
parents: 23292
diff changeset
3273 error ("Invalid format operation %%%c", *format);
df3f641c9ca1 (Fformat): Check format control characters.
Kenichi Handa <handa@m17n.org>
parents: 23292
diff changeset
3274
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
3275 thissize = 30;
21225
47e189a470d2 (Fformat): Handle padding before or after, for %s etc.
Richard M. Stallman <rms@gnu.org>
parents: 21202
diff changeset
3276 if (*format == 'c'
47e189a470d2 (Fformat): Handle padding before or after, for %s etc.
Richard M. Stallman <rms@gnu.org>
parents: 21202
diff changeset
3277 && (! SINGLE_BYTE_CHAR_P (XINT (args[n]))
47e189a470d2 (Fformat): Handle padding before or after, for %s etc.
Richard M. Stallman <rms@gnu.org>
parents: 21202
diff changeset
3278 || XINT (args[n]) == 0))
21064
90bdbe2754c8 (Fformat): Format multibyte characters by "%c"
Kenichi Handa <handa@m17n.org>
parents: 21052
diff changeset
3279 {
90bdbe2754c8 (Fformat): Format multibyte characters by "%c"
Kenichi Handa <handa@m17n.org>
parents: 21052
diff changeset
3280 if (! multibyte)
90bdbe2754c8 (Fformat): Format multibyte characters by "%c"
Kenichi Handa <handa@m17n.org>
parents: 21052
diff changeset
3281 {
90bdbe2754c8 (Fformat): Format multibyte characters by "%c"
Kenichi Handa <handa@m17n.org>
parents: 21052
diff changeset
3282 multibyte = 1;
90bdbe2754c8 (Fformat): Format multibyte characters by "%c"
Kenichi Handa <handa@m17n.org>
parents: 21052
diff changeset
3283 goto retry;
90bdbe2754c8 (Fformat): Format multibyte characters by "%c"
Kenichi Handa <handa@m17n.org>
parents: 21052
diff changeset
3284 }
90bdbe2754c8 (Fformat): Format multibyte characters by "%c"
Kenichi Handa <handa@m17n.org>
parents: 21052
diff changeset
3285 args[n] = Fchar_to_string (args[n]);
21245
6cde55b7c9de Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents: 21235
diff changeset
3286 thissize = STRING_BYTES (XSTRING (args[n]));
21064
90bdbe2754c8 (Fformat): Format multibyte characters by "%c"
Kenichi Handa <handa@m17n.org>
parents: 21052
diff changeset
3287 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3288 }
9163
41fe5f636879 (lisp_time_argument, Finsert, Finsert_and_inherit, Finsert_before_markers,
Karl Heuer <kwzh@gnu.org>
parents: 9154
diff changeset
3289 else if (FLOATP (args[n]) && *format != 's')
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3290 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3291 if (! (*format == 'e' || *format == 'f' || *format == 'g'))
18605
0567c4086813 (Fformat): Add second argument in call to Ftruncate.
Richard M. Stallman <rms@gnu.org>
parents: 18511
diff changeset
3292 args[n] = Ftruncate (args[n], Qnil);
34566
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3293
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3294 /* Note that we're using sprintf to print floats,
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3295 so we have to take into account what that function
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3296 prints. */
38519
200c049178cc (toplevel) [STDC_HEADERS]: Include float.h.
Gerd Moellmann <gerd@gnu.org>
parents: 38059
diff changeset
3297 thissize = MAX_10_EXP + 100 + precision;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3298 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3299 else
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3300 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3301 /* Anything but a string, convert to a string using princ. */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3302 register Lisp_Object tem;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3303 tem = Fprin1_to_string (args[n], Qt);
21052
eea2c6235bd1 (Fformat): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 21035
diff changeset
3304 if (STRING_MULTIBYTE (tem) & ! multibyte)
20826
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3305 {
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3306 multibyte = 1;
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3307 goto retry;
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3308 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3309 args[n] = tem;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3310 goto string;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3311 }
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
3312
34566
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3313 thissize = max (field_width, thissize);
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3314 total += thissize + 4;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3315 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3316
20826
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3317 /* Now we can no longer jump to retry.
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3318 TOTAL and LONGEST_FORMAT are known for certain. */
cbaa9e50b013 (Fformat): If MULTIBYTE is changed to 1
Richard M. Stallman <rms@gnu.org>
parents: 20804
diff changeset
3319
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3320 this_format = (unsigned char *) alloca (longest_format + 1);
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3321
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3322 /* Allocate the space for the result.
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3323 Note that TOTAL is an overestimate. */
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3324 if (total < 1000)
21914
d1f79bb20a20 (Fformat): Fix casts when assigning buf.
Richard M. Stallman <rms@gnu.org>
parents: 21899
diff changeset
3325 buf = (char *) alloca (total + 1);
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3326 else
21914
d1f79bb20a20 (Fformat): Fix casts when assigning buf.
Richard M. Stallman <rms@gnu.org>
parents: 21899
diff changeset
3327 buf = (char *) xmalloc (total + 1);
4019
0463aae99f4e * editfns.c (Fformat): Since floats occupy two elements in the
Jim Blandy <jimb@redhat.com>
parents: 3776
diff changeset
3328
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3329 p = buf;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3330 nchars = 0;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3331 n = 0;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3332
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3333 /* Scan the format and store result in BUF. */
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3334 format = XSTRING (args[0])->data;
22698
ea6ef56295b4 (Fformat): Pay attention to the byte combining problem.
Kenichi Handa <handa@m17n.org>
parents: 22669
diff changeset
3335 maybe_combine_byte = 0;
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3336 while (format != end)
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3337 {
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3338 if (*format == '%')
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3339 {
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3340 int minlen;
21225
47e189a470d2 (Fformat): Handle padding before or after, for %s etc.
Richard M. Stallman <rms@gnu.org>
parents: 21202
diff changeset
3341 int negative = 0;
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3342 unsigned char *this_format_start = format;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3343
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3344 format++;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3345
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3346 /* Process a numeric arg and skip it. */
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3347 minlen = atoi (format);
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3348 if (minlen < 0)
21225
47e189a470d2 (Fformat): Handle padding before or after, for %s etc.
Richard M. Stallman <rms@gnu.org>
parents: 21202
diff changeset
3349 minlen = - minlen, negative = 1;
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3350
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3351 while ((*format >= '0' && *format <= '9')
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3352 || *format == '-' || *format == ' ' || *format == '.')
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3353 format++;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3354
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3355 if (*format++ == '%')
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3356 {
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3357 *p++ = '%';
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3358 nchars++;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3359 continue;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3360 }
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3361
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3362 ++n;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3363
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3364 if (STRINGP (args[n]))
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3365 {
35461
f0f0e9179ed6 (Fformat): Don't extend text properties from arguments
Gerd Moellmann <gerd@gnu.org>
parents: 35440
diff changeset
3366 int padding, nbytes, start, end;
35440
21817d18668c (Fformat): Use lisp_string_width instead of strwidth.
Kenichi Handa <handa@m17n.org>
parents: 35414
diff changeset
3367 int width = lisp_string_width (args[n], -1, NULL, NULL);
21225
47e189a470d2 (Fformat): Handle padding before or after, for %s etc.
Richard M. Stallman <rms@gnu.org>
parents: 21202
diff changeset
3368
47e189a470d2 (Fformat): Handle padding before or after, for %s etc.
Richard M. Stallman <rms@gnu.org>
parents: 21202
diff changeset
3369 /* If spec requires it, pad on right with spaces. */
47e189a470d2 (Fformat): Handle padding before or after, for %s etc.
Richard M. Stallman <rms@gnu.org>
parents: 21202
diff changeset
3370 padding = minlen - width;
47e189a470d2 (Fformat): Handle padding before or after, for %s etc.
Richard M. Stallman <rms@gnu.org>
parents: 21202
diff changeset
3371 if (! negative)
47e189a470d2 (Fformat): Handle padding before or after, for %s etc.
Richard M. Stallman <rms@gnu.org>
parents: 21202
diff changeset
3372 while (padding-- > 0)
47e189a470d2 (Fformat): Handle padding before or after, for %s etc.
Richard M. Stallman <rms@gnu.org>
parents: 21202
diff changeset
3373 {
47e189a470d2 (Fformat): Handle padding before or after, for %s etc.
Richard M. Stallman <rms@gnu.org>
parents: 21202
diff changeset
3374 *p++ = ' ';
35461
f0f0e9179ed6 (Fformat): Don't extend text properties from arguments
Gerd Moellmann <gerd@gnu.org>
parents: 35440
diff changeset
3375 ++nchars;
21225
47e189a470d2 (Fformat): Handle padding before or after, for %s etc.
Richard M. Stallman <rms@gnu.org>
parents: 21202
diff changeset
3376 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3377
35461
f0f0e9179ed6 (Fformat): Don't extend text properties from arguments
Gerd Moellmann <gerd@gnu.org>
parents: 35440
diff changeset
3378 start = nchars;
f0f0e9179ed6 (Fformat): Don't extend text properties from arguments
Gerd Moellmann <gerd@gnu.org>
parents: 35440
diff changeset
3379
22698
ea6ef56295b4 (Fformat): Pay attention to the byte combining problem.
Kenichi Handa <handa@m17n.org>
parents: 22669
diff changeset
3380 if (p > buf
ea6ef56295b4 (Fformat): Pay attention to the byte combining problem.
Kenichi Handa <handa@m17n.org>
parents: 22669
diff changeset
3381 && multibyte
22712
6f129ed55108 (Fformat): Replace explicit numeric constants with proper macros.
Kenichi Handa <handa@m17n.org>
parents: 22698
diff changeset
3382 && !ASCII_BYTE_P (*((unsigned char *) p - 1))
22698
ea6ef56295b4 (Fformat): Pay attention to the byte combining problem.
Kenichi Handa <handa@m17n.org>
parents: 22669
diff changeset
3383 && STRING_MULTIBYTE (args[n])
22712
6f129ed55108 (Fformat): Replace explicit numeric constants with proper macros.
Kenichi Handa <handa@m17n.org>
parents: 22698
diff changeset
3384 && !CHAR_HEAD_P (XSTRING (args[n])->data[0]))
22698
ea6ef56295b4 (Fformat): Pay attention to the byte combining problem.
Kenichi Handa <handa@m17n.org>
parents: 22669
diff changeset
3385 maybe_combine_byte = 1;
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3386 nbytes = copy_text (XSTRING (args[n])->data, p,
21245
6cde55b7c9de Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents: 21235
diff changeset
3387 STRING_BYTES (XSTRING (args[n])),
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3388 STRING_MULTIBYTE (args[n]), multibyte);
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3389 p += nbytes;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3390 nchars += XSTRING (args[n])->size;
35461
f0f0e9179ed6 (Fformat): Don't extend text properties from arguments
Gerd Moellmann <gerd@gnu.org>
parents: 35440
diff changeset
3391 end = nchars;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3392
21225
47e189a470d2 (Fformat): Handle padding before or after, for %s etc.
Richard M. Stallman <rms@gnu.org>
parents: 21202
diff changeset
3393 if (negative)
47e189a470d2 (Fformat): Handle padding before or after, for %s etc.
Richard M. Stallman <rms@gnu.org>
parents: 21202
diff changeset
3394 while (padding-- > 0)
47e189a470d2 (Fformat): Handle padding before or after, for %s etc.
Richard M. Stallman <rms@gnu.org>
parents: 21202
diff changeset
3395 {
47e189a470d2 (Fformat): Handle padding before or after, for %s etc.
Richard M. Stallman <rms@gnu.org>
parents: 21202
diff changeset
3396 *p++ = ' ';
47e189a470d2 (Fformat): Handle padding before or after, for %s etc.
Richard M. Stallman <rms@gnu.org>
parents: 21202
diff changeset
3397 nchars++;
47e189a470d2 (Fformat): Handle padding before or after, for %s etc.
Richard M. Stallman <rms@gnu.org>
parents: 21202
diff changeset
3398 }
25018
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3399
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3400 /* If this argument has text properties, record where
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3401 in the result string it appears. */
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3402 if (XSTRING (args[n])->intervals)
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3403 {
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3404 if (!info)
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3405 {
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3406 int nbytes = nargs * sizeof *info;
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3407 info = (struct info *) alloca (nbytes);
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3408 bzero (info, nbytes);
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3409 }
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
3410
25018
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3411 info[n].start = start;
35461
f0f0e9179ed6 (Fformat): Don't extend text properties from arguments
Gerd Moellmann <gerd@gnu.org>
parents: 35440
diff changeset
3412 info[n].end = end;
25018
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3413 }
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3414 }
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3415 else if (INTEGERP (args[n]) || FLOATP (args[n]))
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3416 {
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3417 int this_nchars;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3418
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3419 bcopy (this_format_start, this_format,
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3420 format - this_format_start);
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3421 this_format[format - this_format_start] = 0;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3422
21202
ef954087e7b9 (Fformat): Properly print floats.
Richard M. Stallman <rms@gnu.org>
parents: 21200
diff changeset
3423 if (INTEGERP (args[n]))
ef954087e7b9 (Fformat): Properly print floats.
Richard M. Stallman <rms@gnu.org>
parents: 21200
diff changeset
3424 sprintf (p, this_format, XINT (args[n]));
ef954087e7b9 (Fformat): Properly print floats.
Richard M. Stallman <rms@gnu.org>
parents: 21200
diff changeset
3425 else
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25656
diff changeset
3426 sprintf (p, this_format, XFLOAT_DATA (args[n]));
12603
6d033c8501d4 (Fformat): Increment total for size of control string.
Richard M. Stallman <rms@gnu.org>
parents: 12602
diff changeset
3427
22698
ea6ef56295b4 (Fformat): Pay attention to the byte combining problem.
Kenichi Handa <handa@m17n.org>
parents: 22669
diff changeset
3428 if (p > buf
ea6ef56295b4 (Fformat): Pay attention to the byte combining problem.
Kenichi Handa <handa@m17n.org>
parents: 22669
diff changeset
3429 && multibyte
22712
6f129ed55108 (Fformat): Replace explicit numeric constants with proper macros.
Kenichi Handa <handa@m17n.org>
parents: 22698
diff changeset
3430 && !ASCII_BYTE_P (*((unsigned char *) p - 1))
6f129ed55108 (Fformat): Replace explicit numeric constants with proper macros.
Kenichi Handa <handa@m17n.org>
parents: 22698
diff changeset
3431 && !CHAR_HEAD_P (*((unsigned char *) p)))
22698
ea6ef56295b4 (Fformat): Pay attention to the byte combining problem.
Kenichi Handa <handa@m17n.org>
parents: 22669
diff changeset
3432 maybe_combine_byte = 1;
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3433 this_nchars = strlen (p);
29008
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3434 if (multibyte)
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3435 p += str_to_multibyte (p, buf + total - p, this_nchars);
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3436 else
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3437 p += this_nchars;
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3438 nchars += this_nchars;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3439 }
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3440 }
20861
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
3441 else if (STRING_MULTIBYTE (args[0]))
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
3442 {
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
3443 /* Copy a whole multibyte character. */
22698
ea6ef56295b4 (Fformat): Pay attention to the byte combining problem.
Kenichi Handa <handa@m17n.org>
parents: 22669
diff changeset
3444 if (p > buf
ea6ef56295b4 (Fformat): Pay attention to the byte combining problem.
Kenichi Handa <handa@m17n.org>
parents: 22669
diff changeset
3445 && multibyte
22712
6f129ed55108 (Fformat): Replace explicit numeric constants with proper macros.
Kenichi Handa <handa@m17n.org>
parents: 22698
diff changeset
3446 && !ASCII_BYTE_P (*((unsigned char *) p - 1))
6f129ed55108 (Fformat): Replace explicit numeric constants with proper macros.
Kenichi Handa <handa@m17n.org>
parents: 22698
diff changeset
3447 && !CHAR_HEAD_P (*format))
22698
ea6ef56295b4 (Fformat): Pay attention to the byte combining problem.
Kenichi Handa <handa@m17n.org>
parents: 22669
diff changeset
3448 maybe_combine_byte = 1;
20861
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
3449 *p++ = *format++;
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
3450 while (! CHAR_HEAD_P (*format)) *p++ = *format++;
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
3451 nchars++;
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
3452 }
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
3453 else if (multibyte)
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3454 {
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3455 /* Convert a single-byte character to multibyte. */
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3456 int len = copy_text (format, p, 1, 0, 1);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3457
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3458 p += len;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3459 format++;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3460 nchars++;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3461 }
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3462 else
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3463 *p++ = *format++, nchars++;
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3464 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3465
34566
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3466 if (p > buf + total + 1)
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3467 abort ();
0370af7597d2 (Fformat): Prevent a buffer overrun when the format
Gerd Moellmann <gerd@gnu.org>
parents: 34165
diff changeset
3468
22698
ea6ef56295b4 (Fformat): Pay attention to the byte combining problem.
Kenichi Handa <handa@m17n.org>
parents: 22669
diff changeset
3469 if (maybe_combine_byte)
ea6ef56295b4 (Fformat): Pay attention to the byte combining problem.
Kenichi Handa <handa@m17n.org>
parents: 22669
diff changeset
3470 nchars = multibyte_chars_in_text (buf, p - buf);
21257
205a5aa4aa2f (Fchar_to_string): Use make_string_from_bytes.
Richard M. Stallman <rms@gnu.org>
parents: 21245
diff changeset
3471 val = make_specified_string (buf, nchars, p - buf, multibyte);
20804
14fa73136e64 (CONVERTED_BYTE_SIZE): Fix the logic.
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
3472
20606
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3473 /* If we allocated BUF with malloc, free it too. */
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3474 if (total >= 1000)
9331e7e88cf5 (Fformat): Do all the work directly--don't use doprnt.
Richard M. Stallman <rms@gnu.org>
parents: 20564
diff changeset
3475 xfree (buf);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3476
25018
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3477 /* If the format string has text properties, or any of the string
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3478 arguments has text properties, set up text properties of the
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3479 result string. */
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
3480
25018
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3481 if (XSTRING (args[0])->intervals || info)
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3482 {
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3483 Lisp_Object len, new_len, props;
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3484 struct gcpro gcpro1;
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
3485
25018
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3486 /* Add text properties from the format string. */
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3487 len = make_number (XSTRING (args[0])->size);
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3488 props = text_property_list (args[0], make_number (0), len, Qnil);
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3489 GCPRO1 (props);
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
3490
25018
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3491 if (CONSP (props))
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3492 {
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3493 new_len = make_number (XSTRING (val)->size);
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3494 extend_property_ranges (props, len, new_len);
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3495 add_text_properties_from_list (val, props, make_number (0));
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3496 }
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3497
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3498 /* Add text properties from arguments. */
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3499 if (info)
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3500 for (n = 1; n < nargs; ++n)
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3501 if (info[n].end)
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3502 {
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3503 len = make_number (XSTRING (args[n])->size);
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3504 new_len = make_number (info[n].end - info[n].start);
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3505 props = text_property_list (args[n], make_number (0), len, Qnil);
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3506 extend_property_ranges (props, len, new_len);
30023
ec25786e4705 (Fformat): While copying text properties, make each composition
Kenichi Handa <handa@m17n.org>
parents: 29008
diff changeset
3507 /* If successive arguments have properites, be sure that
ec25786e4705 (Fformat): While copying text properties, make each composition
Kenichi Handa <handa@m17n.org>
parents: 29008
diff changeset
3508 the value of `composition' property be the copy. */
ec25786e4705 (Fformat): While copying text properties, make each composition
Kenichi Handa <handa@m17n.org>
parents: 29008
diff changeset
3509 if (n > 1 && info[n - 1].end)
ec25786e4705 (Fformat): While copying text properties, make each composition
Kenichi Handa <handa@m17n.org>
parents: 29008
diff changeset
3510 make_composition_value_copy (props);
25018
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3511 add_text_properties_from_list (val, props,
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3512 make_number (info[n].start));
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3513 }
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3514
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3515 UNGCPRO;
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3516 }
890e8042db8f (Fmessage): Use message3.
Gerd Moellmann <gerd@gnu.org>
parents: 24847
diff changeset
3517
20804
14fa73136e64 (CONVERTED_BYTE_SIZE): Fix the logic.
Kenichi Handa <handa@m17n.org>
parents: 20706
diff changeset
3518 return val;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3519 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3520
25815
768a5bb054df (Fproperties): New.
Gerd Moellmann <gerd@gnu.org>
parents: 25782
diff changeset
3521
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3522 /* VARARGS 1 */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3523 Lisp_Object
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3524 #ifdef NO_ARG_ARRAY
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3525 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
3526 EMACS_INT arg0, arg1, arg2, arg3, arg4;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3527 #else
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3528 format1 (string1)
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3529 #endif
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3530 char *string1;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3531 {
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3532 char buf[100];
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3533 #ifdef NO_ARG_ARRAY
8824
589f82d1bb32 (Fnarrow_to_region, format1): Use EMACS_INT.
Richard M. Stallman <rms@gnu.org>
parents: 8771
diff changeset
3534 EMACS_INT args[5];
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3535 args[0] = arg0;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3536 args[1] = arg1;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3537 args[2] = arg2;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3538 args[3] = arg3;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3539 args[4] = arg4;
21035
5d18067080d0 (general_insert_function): Use
Kenichi Handa <handa@m17n.org>
parents: 20946
diff changeset
3540 doprnt (buf, sizeof buf, string1, (char *)0, 5, (char **) args);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3541 #else
11912
bb03a720fd58 (format1): Cast arg of doprnt.
Karl Heuer <kwzh@gnu.org>
parents: 11877
diff changeset
3542 doprnt (buf, sizeof buf, string1, (char *)0, 5, &string1 + 1);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3543 #endif
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3544 return build_string (buf);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3545 }
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3546
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3547 DEFUN ("char-equal", Fchar_equal, Schar_equal, 2, 2, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3548 doc: /* Return t if two characters match, optionally ignoring case.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3549 Both arguments must be characters (i.e. integers).
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3550 Case is ignored if `case-fold-search' is non-nil in the current buffer. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3551 (c1, c2)
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3552 register Lisp_Object c1, c2;
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3553 {
20688
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
3554 int i1, i2;
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3555 CHECK_NUMBER (c1, 0);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3556 CHECK_NUMBER (c2, 1);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3557
20688
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
3558 if (XINT (c1) == XINT (c2))
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3559 return Qt;
20688
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
3560 if (NILP (current_buffer->case_fold_search))
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
3561 return Qnil;
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
3562
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
3563 /* Do these in separate statements,
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
3564 then compare the variables.
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
3565 because of the way DOWNCASE uses temp variables. */
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
3566 i1 = DOWNCASE (XFASTINT (c1));
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
3567 i2 = DOWNCASE (XFASTINT (c2));
16c458803c32 (Fchar_equal): Fix case-conversion code.
Richard M. Stallman <rms@gnu.org>
parents: 20606
diff changeset
3568 return (i1 == i2 ? Qt : Qnil);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3569 }
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3570
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3571 /* 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
3572 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
3573 differ in size).
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3574
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3575 START1, END1 are the character positions of the first region.
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3576 START1_BYTE, END1_BYTE are the byte positions.
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3577 START2, END2 are the character positions of the second region.
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3578 START2_BYTE, END2_BYTE are the byte positions.
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3579
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3580 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
3581 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
3582 rest untouched. Most of this is copied from adjust_markers in insdel.c.
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
3583
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3584 It's the caller's job to ensure that START1 <= END1 <= START2 <= END2. */
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3585
31016
b26ac1565dd4 (find_field): Formatting changes.
Gerd Moellmann <gerd@gnu.org>
parents: 30931
diff changeset
3586 static void
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3587 transpose_markers (start1, end1, start2, end2,
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3588 start1_byte, end1_byte, start2_byte, end2_byte)
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3589 register int start1, end1, start2, end2;
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3590 register int start1_byte, end1_byte, start2_byte, end2_byte;
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3591 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3592 register int amt1, amt1_byte, amt2, amt2_byte, diff, diff_byte, mpos;
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3593 register Lisp_Object marker;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3594
7862
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
3595 /* 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
3596 if (PT < start1)
987ab382275c (Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents: 7506
diff changeset
3597 ;
987ab382275c (Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents: 7506
diff changeset
3598 else if (PT < end1)
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3599 TEMP_SET_PT_BOTH (PT + (end2 - end1),
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3600 PT_BYTE + (end2_byte - end1_byte));
7519
987ab382275c (Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents: 7506
diff changeset
3601 else if (PT < start2)
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3602 TEMP_SET_PT_BOTH (PT + (end2 - start2) - (end1 - start1),
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3603 (PT_BYTE + (end2_byte - start2_byte)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3604 - (end1_byte - start1_byte)));
7519
987ab382275c (Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents: 7506
diff changeset
3605 else if (PT < end2)
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3606 TEMP_SET_PT_BOTH (PT - (start2 - start1),
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3607 PT_BYTE - (start2_byte - start1_byte));
7519
987ab382275c (Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents: 7506
diff changeset
3608
7862
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
3609 /* 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
3610 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
3611 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
3612 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
3613 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
3614 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
3615 the dirty work to Fmarker_position, below. */
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3616
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3617 /* The difference between the region's lengths */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3618 diff = (end2 - start2) - (end1 - start1);
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3619 diff_byte = (end2_byte - start2_byte) - (end1_byte - start1_byte);
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
3620
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3621 /* For shifting each marker in a region by the length of the other
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3622 region plus the distance between the regions. */
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3623 amt1 = (end2 - start2) + (start2 - end1);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3624 amt2 = (end1 - start1) + (start2 - end1);
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3625 amt1_byte = (end2_byte - start2_byte) + (start2_byte - end1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3626 amt2_byte = (end1_byte - start1_byte) + (start2_byte - end1_byte);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3627
10308
90784ed0416f Use SAVE_MODIFF and BUF_SAVE_MODIFF
Richard M. Stallman <rms@gnu.org>
parents: 9812
diff changeset
3628 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
3629 marker = XMARKER (marker)->chain)
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3630 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3631 mpos = marker_byte_position (marker);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3632 if (mpos >= start1_byte && mpos < end2_byte)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3633 {
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3634 if (mpos < end1_byte)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3635 mpos += amt1_byte;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3636 else if (mpos < start2_byte)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3637 mpos += diff_byte;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3638 else
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3639 mpos -= amt2_byte;
20564
4d06099b7e09 (transpose_markers): Update marker's bytepos.
Richard M. Stallman <rms@gnu.org>
parents: 20561
diff changeset
3640 XMARKER (marker)->bytepos = mpos;
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3641 }
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3642 mpos = XMARKER (marker)->charpos;
7862
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
3643 if (mpos >= start1 && mpos < end2)
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
3644 {
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
3645 if (mpos < end1)
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
3646 mpos += amt1;
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
3647 else if (mpos < start2)
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
3648 mpos += diff;
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
3649 else
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
3650 mpos -= amt2;
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
3651 }
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3652 XMARKER (marker)->charpos = mpos;
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3653 }
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3654 }
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3655
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3656 DEFUN ("transpose-regions", Ftranspose_regions, Stranspose_regions, 4, 5, 0,
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3657 doc: /* Transpose region START1 to END1 with START2 to END2.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3658 The regions may not be overlapping, because the size of the buffer is
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3659 never changed in a transposition.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3660
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3661 Optional fifth arg LEAVE_MARKERS, if non-nil, means don't update
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3662 any markers that happen to be located in the regions.
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3663
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3664 Transposing beyond buffer boundaries is an error. */)
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3665 (startr1, endr1, startr2, endr2, leave_markers)
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3666 Lisp_Object startr1, endr1, startr2, endr2, leave_markers;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3667 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3668 register int start1, end1, start2, end2;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3669 int start1_byte, start2_byte, len1_byte, len2_byte;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3670 int gap, len1, len_mid, len2;
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
3671 unsigned char *start1_addr, *start2_addr, *temp;
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3672
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3673 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
3674 cur_intv = BUF_INTERVALS (current_buffer);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3675
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3676 validate_region (&startr1, &endr1);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3677 validate_region (&startr2, &endr2);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3678
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3679 start1 = XFASTINT (startr1);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3680 end1 = XFASTINT (endr1);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3681 start2 = XFASTINT (startr2);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3682 end2 = XFASTINT (endr2);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3683 gap = GPT;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3684
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3685 /* Swap the regions if they're reversed. */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3686 if (start2 < end1)
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3687 {
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3688 register int glumph = start1;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3689 start1 = start2;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3690 start2 = glumph;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3691 glumph = end1;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3692 end1 = end2;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3693 end2 = glumph;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3694 }
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3695
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3696 len1 = end1 - start1;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3697 len2 = end2 - start2;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3698
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3699 if (start2 < end1)
21245
6cde55b7c9de Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents: 21235
diff changeset
3700 error ("Transposed regions overlap");
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3701 else if (start1 == end1 || start2 == end2)
21245
6cde55b7c9de Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents: 21235
diff changeset
3702 error ("Transposed region has length 0");
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3703
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3704 /* The possibilities are:
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3705 1. Adjacent (contiguous) regions, or separate but equal regions
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3706 (no, really equal, in this case!), or
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3707 2. Separate regions of unequal size.
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
3708
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3709 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
3710 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
3711 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
3712 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
3713
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3714 /* 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
3715 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
3716 around it if necessary. This would be extremely efficient,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3717 especially considering that people are likely to do
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3718 transpositions near where they are working interactively, which
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3719 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
3720 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
3721 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
3722 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
3723 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
3724 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
3725
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
3726 /* 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
3727 we will operate on. */
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
3728 if (start1 < gap && gap < end2)
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
3729 {
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
3730 if (gap - start1 < end2 - gap)
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
3731 move_gap (start1);
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
3732 else
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
3733 move_gap (end2);
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
3734 }
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3735
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3736 start1_byte = CHAR_TO_BYTE (start1);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3737 start2_byte = CHAR_TO_BYTE (start2);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3738 len1_byte = CHAR_TO_BYTE (end1) - start1_byte;
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3739 len2_byte = CHAR_TO_BYTE (end2) - start2_byte;
21245
6cde55b7c9de Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents: 21235
diff changeset
3740
29008
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3741 #ifdef BYTE_COMBINING_DEBUG
21245
6cde55b7c9de Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents: 21235
diff changeset
3742 if (end1 == start2)
6cde55b7c9de Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents: 21235
diff changeset
3743 {
29008
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3744 if (count_combining_before (BYTE_POS_ADDR (start2_byte),
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3745 len2_byte, start1, start1_byte)
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3746 || count_combining_before (BYTE_POS_ADDR (start1_byte),
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3747 len1_byte, end2, start2_byte + len2_byte)
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3748 || count_combining_after (BYTE_POS_ADDR (start1_byte),
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3749 len1_byte, end2, start2_byte + len2_byte))
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3750 abort ();
21245
6cde55b7c9de Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents: 21235
diff changeset
3751 }
6cde55b7c9de Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents: 21235
diff changeset
3752 else
6cde55b7c9de Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents: 21235
diff changeset
3753 {
29008
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3754 if (count_combining_before (BYTE_POS_ADDR (start2_byte),
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3755 len2_byte, start1, start1_byte)
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3756 || count_combining_before (BYTE_POS_ADDR (start1_byte),
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3757 len1_byte, start2, start2_byte)
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3758 || count_combining_after (BYTE_POS_ADDR (start2_byte),
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3759 len2_byte, end1, start1_byte + len1_byte)
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3760 || count_combining_after (BYTE_POS_ADDR (start1_byte),
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3761 len1_byte, end2, start2_byte + len2_byte))
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3762 abort ();
21245
6cde55b7c9de Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents: 21235
diff changeset
3763 }
29008
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3764 #endif
939760ef7379 (Fformat): Be sure to convert 8-bit characters to
Kenichi Handa <handa@m17n.org>
parents: 28545
diff changeset
3765
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3766 /* 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
3767 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
3768 allocation... interesting. Later, don't fool with it now. */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3769
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3770 /* Working without memmove, for portability (sigh), so must be
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3771 careful of overlapping subsections of the array... */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3772
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3773 if (end1 == start2) /* adjacent regions */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3774 {
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3775 modify_region (current_buffer, start1, end2);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3776 record_change (start1, len1 + len2);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3777
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3778 tmp_interval1 = copy_intervals (cur_intv, start1, len1);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3779 tmp_interval2 = copy_intervals (cur_intv, start2, len2);
18745
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
3780 Fset_text_properties (make_number (start1), make_number (end2),
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
3781 Qnil, Qnil);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3782
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3783 /* First region smaller than second. */
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3784 if (len1_byte < len2_byte)
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3785 {
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
3786 /* 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
3787 because we want to avoid stack overflow. */
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3788 if (len2_byte > 20000)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3789 temp = (unsigned char *) xmalloc (len2_byte);
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
3790 else
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3791 temp = (unsigned char *) alloca (len2_byte);
7862
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
3792
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
3793 /* 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
3794 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
3795 have moved the buffer around during the xmalloc. */
23166
6072f28afec9 (Ftranspose_regions): Use BYTE_POS_ADDR to get an
Kenichi Handa <handa@m17n.org>
parents: 23132
diff changeset
3796 start1_addr = BYTE_POS_ADDR (start1_byte);
6072f28afec9 (Ftranspose_regions): Use BYTE_POS_ADDR to get an
Kenichi Handa <handa@m17n.org>
parents: 23132
diff changeset
3797 start2_addr = BYTE_POS_ADDR (start2_byte);
7862
0b6f46029ea2 (transpose_markers): Allow for gap at start of region.
Karl Heuer <kwzh@gnu.org>
parents: 7710
diff changeset
3798
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3799 bcopy (start2_addr, temp, len2_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3800 bcopy (start1_addr, start1_addr + len2_byte, len1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3801 bcopy (temp, start1_addr, len2_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3802 if (len2_byte > 20000)
30606
438ad5366a03 (Ftranspose_regions): Use xfree instead of free.
Gerd Moellmann <gerd@gnu.org>
parents: 30550
diff changeset
3803 xfree (temp);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3804 }
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3805 else
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3806 /* First region not smaller than second. */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3807 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3808 if (len1_byte > 20000)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3809 temp = (unsigned char *) xmalloc (len1_byte);
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
3810 else
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3811 temp = (unsigned char *) alloca (len1_byte);
23166
6072f28afec9 (Ftranspose_regions): Use BYTE_POS_ADDR to get an
Kenichi Handa <handa@m17n.org>
parents: 23132
diff changeset
3812 start1_addr = BYTE_POS_ADDR (start1_byte);
6072f28afec9 (Ftranspose_regions): Use BYTE_POS_ADDR to get an
Kenichi Handa <handa@m17n.org>
parents: 23132
diff changeset
3813 start2_addr = BYTE_POS_ADDR (start2_byte);
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3814 bcopy (start1_addr, temp, len1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3815 bcopy (start2_addr, start1_addr, len2_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3816 bcopy (temp, start1_addr + len2_byte, len1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3817 if (len1_byte > 20000)
30606
438ad5366a03 (Ftranspose_regions): Use xfree instead of free.
Gerd Moellmann <gerd@gnu.org>
parents: 30550
diff changeset
3818 xfree (temp);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3819 }
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3820 graft_intervals_into_buffer (tmp_interval1, start1 + len2,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3821 len1, current_buffer, 0);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3822 graft_intervals_into_buffer (tmp_interval2, start1,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3823 len2, current_buffer, 0);
26853
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3824 update_compositions (start1, start1 + len2, CHECK_BORDER);
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3825 update_compositions (start1 + len2, end2, CHECK_TAIL);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3826 }
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3827 /* Non-adjacent regions, because end1 != start2, bleagh... */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3828 else
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3829 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3830 len_mid = start2_byte - (start1_byte + len1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3831
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3832 if (len1_byte == len2_byte)
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3833 /* Regions are same size, though, how nice. */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3834 {
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3835 modify_region (current_buffer, start1, end1);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3836 modify_region (current_buffer, start2, end2);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3837 record_change (start1, len1);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3838 record_change (start2, len2);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3839 tmp_interval1 = copy_intervals (cur_intv, start1, len1);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3840 tmp_interval2 = copy_intervals (cur_intv, start2, len2);
18745
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
3841 Fset_text_properties (make_number (start1), make_number (end1),
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
3842 Qnil, Qnil);
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
3843 Fset_text_properties (make_number (start2), make_number (end2),
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
3844 Qnil, Qnil);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3845
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3846 if (len1_byte > 20000)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3847 temp = (unsigned char *) xmalloc (len1_byte);
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
3848 else
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3849 temp = (unsigned char *) alloca (len1_byte);
23166
6072f28afec9 (Ftranspose_regions): Use BYTE_POS_ADDR to get an
Kenichi Handa <handa@m17n.org>
parents: 23132
diff changeset
3850 start1_addr = BYTE_POS_ADDR (start1_byte);
6072f28afec9 (Ftranspose_regions): Use BYTE_POS_ADDR to get an
Kenichi Handa <handa@m17n.org>
parents: 23132
diff changeset
3851 start2_addr = BYTE_POS_ADDR (start2_byte);
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3852 bcopy (start1_addr, temp, len1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3853 bcopy (start2_addr, start1_addr, len2_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3854 bcopy (temp, start2_addr, len1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3855 if (len1_byte > 20000)
30606
438ad5366a03 (Ftranspose_regions): Use xfree instead of free.
Gerd Moellmann <gerd@gnu.org>
parents: 30550
diff changeset
3856 xfree (temp);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3857 graft_intervals_into_buffer (tmp_interval1, start2,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3858 len1, current_buffer, 0);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3859 graft_intervals_into_buffer (tmp_interval2, start1,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3860 len2, current_buffer, 0);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3861 }
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3862
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3863 else if (len1_byte < len2_byte) /* Second region larger than first */
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3864 /* 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
3865 {
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3866 modify_region (current_buffer, start1, end2);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3867 record_change (start1, (end2 - start1));
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3868 tmp_interval1 = copy_intervals (cur_intv, start1, len1);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3869 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
3870 tmp_interval2 = copy_intervals (cur_intv, start2, len2);
18745
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
3871 Fset_text_properties (make_number (start1), make_number (end2),
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
3872 Qnil, Qnil);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3873
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
3874 /* holds region 2 */
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3875 if (len2_byte > 20000)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3876 temp = (unsigned char *) xmalloc (len2_byte);
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
3877 else
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3878 temp = (unsigned char *) alloca (len2_byte);
23166
6072f28afec9 (Ftranspose_regions): Use BYTE_POS_ADDR to get an
Kenichi Handa <handa@m17n.org>
parents: 23132
diff changeset
3879 start1_addr = BYTE_POS_ADDR (start1_byte);
6072f28afec9 (Ftranspose_regions): Use BYTE_POS_ADDR to get an
Kenichi Handa <handa@m17n.org>
parents: 23132
diff changeset
3880 start2_addr = BYTE_POS_ADDR (start2_byte);
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3881 bcopy (start2_addr, temp, len2_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3882 bcopy (start1_addr, start1_addr + len_mid + len2_byte, len1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3883 safe_bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3884 bcopy (temp, start1_addr, len2_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3885 if (len2_byte > 20000)
30606
438ad5366a03 (Ftranspose_regions): Use xfree instead of free.
Gerd Moellmann <gerd@gnu.org>
parents: 30550
diff changeset
3886 xfree (temp);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3887 graft_intervals_into_buffer (tmp_interval1, end2 - len1,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3888 len1, current_buffer, 0);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3889 graft_intervals_into_buffer (tmp_interval_mid, start1 + len2,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3890 len_mid, current_buffer, 0);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3891 graft_intervals_into_buffer (tmp_interval2, start1,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3892 len2, current_buffer, 0);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3893 }
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3894 else
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3895 /* Second region smaller than first. */
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3896 {
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3897 record_change (start1, (end2 - start1));
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3898 modify_region (current_buffer, start1, end2);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3899
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3900 tmp_interval1 = copy_intervals (cur_intv, start1, len1);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3901 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
3902 tmp_interval2 = copy_intervals (cur_intv, start2, len2);
18745
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
3903 Fset_text_properties (make_number (start1), make_number (end2),
192b3ebd108e (Fcurrent_time_zone): Convert Fmake_list argument to Lisp_Integer.
Richard M. Stallman <rms@gnu.org>
parents: 18661
diff changeset
3904 Qnil, Qnil);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3905
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
3906 /* holds region 1 */
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3907 if (len1_byte > 20000)
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3908 temp = (unsigned char *) xmalloc (len1_byte);
7250
67bb3bb1b62d (Ftranspose_regions): Take addresses only after move gap.
Richard M. Stallman <rms@gnu.org>
parents: 7207
diff changeset
3909 else
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3910 temp = (unsigned char *) alloca (len1_byte);
23166
6072f28afec9 (Ftranspose_regions): Use BYTE_POS_ADDR to get an
Kenichi Handa <handa@m17n.org>
parents: 23132
diff changeset
3911 start1_addr = BYTE_POS_ADDR (start1_byte);
6072f28afec9 (Ftranspose_regions): Use BYTE_POS_ADDR to get an
Kenichi Handa <handa@m17n.org>
parents: 23132
diff changeset
3912 start2_addr = BYTE_POS_ADDR (start2_byte);
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3913 bcopy (start1_addr, temp, len1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3914 bcopy (start2_addr, start1_addr, len2_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3915 bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3916 bcopy (temp, start1_addr + len2_byte + len_mid, len1_byte);
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3917 if (len1_byte > 20000)
30606
438ad5366a03 (Ftranspose_regions): Use xfree instead of free.
Gerd Moellmann <gerd@gnu.org>
parents: 30550
diff changeset
3918 xfree (temp);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3919 graft_intervals_into_buffer (tmp_interval1, end2 - len1,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3920 len1, current_buffer, 0);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3921 graft_intervals_into_buffer (tmp_interval_mid, start1 + len2,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3922 len_mid, current_buffer, 0);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3923 graft_intervals_into_buffer (tmp_interval2, start1,
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3924 len2, current_buffer, 0);
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3925 }
26853
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3926
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3927 update_compositions (start1, start1 + len2, CHECK_BORDER);
bf700e4957ec (Fchar_to_string): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3928 update_compositions (end2 - len1, end2, CHECK_BORDER);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3929 }
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3930
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3931 /* When doing multiple transpositions, it might be nice
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3932 to optimize this. Perhaps the markers in any one buffer
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3933 should be organized in some sorted data tree. */
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3934 if (NILP (leave_markers))
7519
987ab382275c (Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents: 7506
diff changeset
3935 {
20558
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3936 transpose_markers (start1, end1, start2, end2,
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3937 start1_byte, start1_byte + len1_byte,
d19346dc4453 (Fgoto_char): When arg is a marker, copy char and byte
Richard M. Stallman <rms@gnu.org>
parents: 20338
diff changeset
3938 start2_byte, start2_byte + len2_byte);
7519
987ab382275c (Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents: 7506
diff changeset
3939 fix_overlays_in_range (start1, end2);
987ab382275c (Ftranspose_regions): Fix overlays after moving markers.
Karl Heuer <kwzh@gnu.org>
parents: 7506
diff changeset
3940 }
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3941
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3942 return Qnil;
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
3943 }
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3944
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3945
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3946 void
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3947 syms_of_editfns ()
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3948 {
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
3949 environbuf = 0;
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
3950
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
3951 Qbuffer_access_fontify_functions
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
3952 = intern ("buffer-access-fontify-functions");
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
3953 staticpro (&Qbuffer_access_fontify_functions);
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
3954
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3955 DEFVAR_LISP ("inhibit-field-text-motion", &Vinhibit_field_text_motion,
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3956 doc: /* Non-nil means.text motion commands don't notice fields. */);
27077
19a664c654ab (Vinhibit_field_text_motion): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 26853
diff changeset
3957 Vinhibit_field_text_motion = Qnil;
19a664c654ab (Vinhibit_field_text_motion): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 26853
diff changeset
3958
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
3959 DEFVAR_LISP ("buffer-access-fontify-functions",
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3960 &Vbuffer_access_fontify_functions,
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3961 doc: /* List of functions called by `buffer-substring' to fontify if necessary.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3962 Each function is called with two arguments which specify the range
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3963 of the buffer being accessed. */);
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
3964 Vbuffer_access_fontify_functions = Qnil;
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
3965
14440
e99b3302c154 (syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents: 14391
diff changeset
3966 {
e99b3302c154 (syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents: 14391
diff changeset
3967 Lisp_Object obuf;
e99b3302c154 (syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents: 14391
diff changeset
3968 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
3969 obuf = Fcurrent_buffer ();
e99b3302c154 (syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents: 14391
diff changeset
3970 /* 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
3971 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
3972 /* 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
3973 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
3974 Qnil);
e99b3302c154 (syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents: 14391
diff changeset
3975 Fset_buffer (obuf);
e99b3302c154 (syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents: 14391
diff changeset
3976 }
e99b3302c154 (syms_of_editfns): Make buffer-access-fontify-functions
Richard M. Stallman <rms@gnu.org>
parents: 14391
diff changeset
3977
14220
74d7745bcaa4 sp correction
Simon Marshall <simon@gnu.org>
parents: 14201
diff changeset
3978 DEFVAR_LISP ("buffer-access-fontified-property",
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3979 &Vbuffer_access_fontified_property,
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3980 doc: /* Property which (if non-nil) indicates text has been fontified.
39966
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3981 `buffer-substring' need not call the `buffer-access-fontify-functions'
1c2d486200f3 Put doc strings in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 39962
diff changeset
3982 functions if all the text being accessed has this property. */);
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
3983 Vbuffer_access_fontified_property = Qnil;
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
3984
39988
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3985 DEFVAR_LISP ("system-name", &Vsystem_name,
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3986 doc: /* The name of the machine Emacs is running on. */);
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3987
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3988 DEFVAR_LISP ("user-full-name", &Vuser_full_name,
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3989 doc: /* The full name of the user logged in. */);
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3990
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3991 DEFVAR_LISP ("user-login-name", &Vuser_login_name,
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3992 doc: /* The user's name, taken from environment variables if possible. */);
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3993
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3994 DEFVAR_LISP ("user-real-login-name", &Vuser_real_login_name,
eac4e9ae201c Change doc-string comments to `new style' [w/`doc:' keyword].
Miles Bader <miles@gnu.org>
parents: 39966
diff changeset
3995 doc: /* The user's name, based upon the real uid only. */);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3996
25833
65cab65c4a28 (Fpropertize): Renamed from Fproperties.
Gerd Moellmann <gerd@gnu.org>
parents: 25815
diff changeset
3997 defsubr (&Spropertize);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3998 defsubr (&Schar_equal);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3999 defsubr (&Sgoto_char);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4000 defsubr (&Sstring_to_char);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4001 defsubr (&Schar_to_string);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4002 defsubr (&Sbuffer_substring);
13767
862fff660446 (Fset_time_zone_rule): Move static var environbuf
Karl Heuer <kwzh@gnu.org>
parents: 13618
diff changeset
4003 defsubr (&Sbuffer_substring_no_properties);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4004 defsubr (&Sbuffer_string);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4005
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4006 defsubr (&Spoint_marker);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4007 defsubr (&Smark_marker);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4008 defsubr (&Spoint);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4009 defsubr (&Sregion_beginning);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4010 defsubr (&Sregion_end);
20861
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
4011
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
4012 staticpro (&Qfield);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
4013 Qfield = intern ("field");
30439
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
4014 staticpro (&Qboundary);
c084f49c2a7f (find_field): Honor special `boundary' fields.
Miles Bader <miles@gnu.org>
parents: 30244
diff changeset
4015 Qboundary = intern ("boundary");
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
4016 defsubr (&Sfield_beginning);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
4017 defsubr (&Sfield_end);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
4018 defsubr (&Sfield_string);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
4019 defsubr (&Sfield_string_no_properties);
26347
7fd9f4ecdd29 (Fdelete_field): Renamed from Ferase_field.
Gerd Moellmann <gerd@gnu.org>
parents: 26088
diff changeset
4020 defsubr (&Sdelete_field);
26058
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
4021 defsubr (&Sconstrain_to_field);
c11f0832a7c5 (Fconstrain_to_field): Make sure we don't violate the
Gerd Moellmann <gerd@gnu.org>
parents: 25833
diff changeset
4022
20861
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
4023 defsubr (&Sline_beginning_position);
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
4024 defsubr (&Sline_end_position);
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
4025
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4026 /* defsubr (&Smark); */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4027 /* defsubr (&Sset_mark); */
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4028 defsubr (&Ssave_excursion);
16298
17304eb73f97 (Fsave_current_buffer): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16269
diff changeset
4029 defsubr (&Ssave_current_buffer);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4030
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4031 defsubr (&Sbufsize);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4032 defsubr (&Spoint_max);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4033 defsubr (&Spoint_min);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4034 defsubr (&Spoint_min_marker);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4035 defsubr (&Spoint_max_marker);
21821
9e82920b194d (Fgap_position, Fgap_size): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 21717
diff changeset
4036 defsubr (&Sgap_position);
9e82920b194d (Fgap_position, Fgap_size): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 21717
diff changeset
4037 defsubr (&Sgap_size);
20861
9f9937a74050 (Fformat): Handle a symbol of which name contains
Richard M. Stallman <rms@gnu.org>
parents: 20834
diff changeset
4038 defsubr (&Sposition_bytes);
22645
e5b201634497 (Fbyte_to_position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 22199
diff changeset
4039 defsubr (&Sbyte_to_position);
16639
b6ba5d371c1c (Fline_beginning_position, Fline_end_position): New fns.
Richard M. Stallman <rms@gnu.org>
parents: 16526
diff changeset
4040
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4041 defsubr (&Sbobp);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4042 defsubr (&Seobp);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4043 defsubr (&Sbolp);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4044 defsubr (&Seolp);
512
b7a1e4e4e7e6 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 488
diff changeset
4045 defsubr (&Sfollowing_char);
b7a1e4e4e7e6 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 488
diff changeset
4046 defsubr (&Sprevious_char);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4047 defsubr (&Schar_after);
17031
c612a2cdd83b Include charset.h.
Karl Heuer <kwzh@gnu.org>
parents: 16918
diff changeset
4048 defsubr (&Schar_before);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4049 defsubr (&Sinsert);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4050 defsubr (&Sinsert_before_markers);
4714
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
4051 defsubr (&Sinsert_and_inherit);
350231e38e68 (Finsert_and_inherit): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
4052 defsubr (&Sinsert_and_inherit_before_markers);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4053 defsubr (&Sinsert_char);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4054
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4055 defsubr (&Suser_login_name);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4056 defsubr (&Suser_real_login_name);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4057 defsubr (&Suser_uid);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4058 defsubr (&Suser_real_uid);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4059 defsubr (&Suser_full_name);
5373
a70b89d2d6bb (Femacs_pid): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5242
diff changeset
4060 defsubr (&Semacs_pid);
448
129e6320092c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 372
diff changeset
4061 defsubr (&Scurrent_time);
9154
b4739bcefc44 (Fformat_time_string): Mostly rewritten, to handle
Richard M. Stallman <rms@gnu.org>
parents: 8981
diff changeset
4062 defsubr (&Sformat_time_string);
30480
5ef94127f946 new function: float-time
Sam Steingold <sds@gnu.org>
parents: 30439
diff changeset
4063 defsubr (&Sfloat_time);
9801
7003b5184aec (init_editfns): Get the username from the environment
Richard M. Stallman <rms@gnu.org>
parents: 9657
diff changeset
4064 defsubr (&Sdecode_time);
11402
66d935214d8e (Fencode_time): Use XINT to examine `zone'.
Richard M. Stallman <rms@gnu.org>
parents: 11263
diff changeset
4065 defsubr (&Sencode_time);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4066 defsubr (&Scurrent_time_string);
962
3533821d6edc * editfns.c (Fcurrent_time_zone): Doc fix.
Jim Blandy <jimb@redhat.com>
parents: 690
diff changeset
4067 defsubr (&Scurrent_time_zone);
13019
5381e2022370 (Fset_time_zone_rule): New function.
Richard M. Stallman <rms@gnu.org>
parents: 13013
diff changeset
4068 defsubr (&Sset_time_zone_rule);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4069 defsubr (&Ssystem_name);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4070 defsubr (&Smessage);
8975
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
4071 defsubr (&Smessage_box);
e8a4c71251cb (Fmessage_box): Renamed from Fbox_message.
Richard M. Stallman <rms@gnu.org>
parents: 8824
diff changeset
4072 defsubr (&Smessage_or_box);
18937
ddb91108a9d2 (Fcurrent_message): New function.
Richard M. Stallman <rms@gnu.org>
parents: 18756
diff changeset
4073 defsubr (&Scurrent_message);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4074 defsubr (&Sformat);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4075
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4076 defsubr (&Sinsert_buffer_substring);
1853
8866e36c0ed5 (Fcompare_buffer_substrings): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1748
diff changeset
4077 defsubr (&Scompare_buffer_substrings);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4078 defsubr (&Ssubst_char_in_region);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4079 defsubr (&Stranslate_region);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4080 defsubr (&Sdelete_region);
26742
936b39bd05b4 * editfns.c (Fdelete_and_extract_region): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26699
diff changeset
4081 defsubr (&Sdelete_and_extract_region);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4082 defsubr (&Swiden);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4083 defsubr (&Snarrow_to_region);
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4084 defsubr (&Ssave_restriction);
7207
c83b161fe62c (Ftranspose_regions): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6878
diff changeset
4085 defsubr (&Stranspose_regions);
305
75f54c84f733 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4086 }