annotate src/indent.c @ 428:3ecd8885ac67 r21-2-22

Import from CVS: tag r21-2-22
author cvs
date Mon, 13 Aug 2007 11:28:15 +0200
parents
children 8de8e3f6228a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Indentation functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1995 Board of Trustees, University of Illinois.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Copyright (C) 1985, 1986, 1987, 1988, 1992, 1993, 1994, 1995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 /* This file has been Mule-ized. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 /* Synched up with: 19.30. Diverges significantly from FSF. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #include "device.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 #include "extents.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 #include "faces.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 #include "frame.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 #include "glyphs.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 #include "insdel.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 #ifdef REGION_CACHE_NEEDS_WORK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 #include "region-cache.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 #include "window.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 Lisp_Object Qcoerce;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 /* Indentation can insert tabs if this is non-zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 otherwise always uses spaces */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 int indent_tabs_mode;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 /* Avoid recalculation by remembering things in these variables. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 /* Last value returned by current_column.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 Some things set last_known_column_point to -1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 to mark the memoized value as invalid */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 static int last_known_column;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 /* Last buffer searched by current_column */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 static struct buffer *last_known_column_buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 /* Value of point when current_column was called */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 static Bufpos last_known_column_point;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 /* Value of MODIFF when current_column was called */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 static int last_known_column_modified;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 static Bufpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 last_visible_position (Bufpos pos, struct buffer *buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 Lisp_Object buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 Lisp_Object value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 XSETBUFFER (buffer, buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 value = Fprevious_single_property_change (make_int (pos), Qinvisible,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 buffer, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 if (NILP (value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 return 0; /* no visible position found */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 /* #### bug bug bug!!! This will return the position of the beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 of an invisible extent; this extent is very likely to be start-closed,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 and thus the spaces inserted in `indent-to' will go inside the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 invisible extent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 Not sure what the correct solution is here. Rethink indent-to? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 return XINT (value);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 #ifdef REGION_CACHE_NEEDS_WORK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 /* Allocate or free the width run cache, as requested by the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 state of current_buffer's cache_long_line_scans variable. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 width_run_cache_on_off (struct buffer *buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 if (NILP (buf->cache_long_line_scans))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 /* It should be off. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 if (buf->width_run_cache)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 free_region_cache (buf->width_run_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 buf->width_run_cache = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 buf->width_table = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 /* It should be on. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 if (buf->width_run_cache == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 buf->width_run_cache = new_region_cache ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 recompute_width_table (buf, buffer_display_table ());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 #endif /* REGION_CACHE_NEEDS_WORK */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 /* Cancel any recorded value of the horizontal position. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 invalidate_current_column (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 last_known_column_point = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 column_at_point (struct buffer *buf, Bufpos init_pos, int cur_col)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 int col;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 int tab_seen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 int tab_width = XINT (buf->tab_width);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 int post_tab;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 Bufpos pos = init_pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 Emchar c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 col = tab_seen = post_tab = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 if (pos <= BUF_BEGV (buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 pos--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 c = BUF_FETCH_CHAR (buf, pos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 if (c == '\t')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 if (tab_seen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 col = ((col + tab_width) / tab_width) * tab_width;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 post_tab += col;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 col = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 tab_seen = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 else if (c == '\n' ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 (EQ (buf->selective_display, Qt) && c == '\r'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 /* #### This needs updating to handle the new redisplay. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 /* #### FSFmacs looks at ctl_arrow, display tables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 We need to do similar. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 displayed_glyphs = glyphs_from_bufpos (sel_frame, buf,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 XWINDOW (selected_window),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 pos, dp, 0, col, 0, 0, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 col += (displayed_glyphs->columns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 - (displayed_glyphs->begin_columns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 + displayed_glyphs->end_columns));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 #else /* XEmacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 col += XCHARSET_COLUMNS (CHAR_CHARSET (c));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 col ++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 #endif /* XEmacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 if (tab_seen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 col = ((col + tab_width) / tab_width) * tab_width;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 col += post_tab;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 if (cur_col)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 last_known_column_buffer = buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 last_known_column = col;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 last_known_column_point = init_pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 last_known_column_modified = BUF_MODIFF (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 return col;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 string_column_at_point (struct Lisp_String* s, Bufpos init_pos, int tab_width)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 int col;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 int tab_seen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 int post_tab;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 Bufpos pos = init_pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 Emchar c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 col = tab_seen = post_tab = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 if (pos <= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 pos--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 c = string_char (s, pos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 if (c == '\t')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 if (tab_seen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 col = ((col + tab_width) / tab_width) * tab_width;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 post_tab += col;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 col = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 tab_seen = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 else if (c == '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 col += XCHARSET_COLUMNS (CHAR_CHARSET (c));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 col ++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 if (tab_seen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 col = ((col + tab_width) / tab_width) * tab_width;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 col += post_tab;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 return col;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 current_column (struct buffer *buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 if (buf == last_known_column_buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 && BUF_PT (buf) == last_known_column_point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 && BUF_MODIFF (buf) == last_known_column_modified)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 return last_known_column;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 return column_at_point (buf, BUF_PT (buf), 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 DEFUN ("current-column", Fcurrent_column, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 Return the horizontal position of point. Beginning of line is column 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 This is calculated by adding together the widths of all the displayed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 representations of the character between the start of the previous line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 and point. (e.g. control characters will have a width of 2 or 4, tabs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 will have a variable width.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 Ignores finite width of frame, which means that this function may return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 values greater than (frame-width).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 Whether the line is visible (if `selective-display' is t) has no effect;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 however, ^M is treated as end of line when `selective-display' is t.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 If BUFFER is nil, the current buffer is assumed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 return make_int (current_column (decode_buffer (buffer, 0)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 DEFUN ("indent-to", Findent_to, 1, 3, "NIndent to column: ", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 Indent from point with tabs and spaces until COLUMN is reached.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 Optional second argument MIN says always do at least MIN spaces
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 even if that goes past COLUMN; by default, MIN is zero.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 If BUFFER is nil, the current buffer is assumed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 (col, minimum, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 int mincol;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 int fromcol;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 int tab_width = XINT (buf->tab_width);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 Bufpos opoint = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 CHECK_INT (col);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 if (NILP (minimum))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 minimum = Qzero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 CHECK_INT (minimum);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 XSETBUFFER (buffer, buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 fromcol = current_column (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 mincol = fromcol + XINT (minimum);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 if (mincol < XINT (col)) mincol = XINT (col);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 if (fromcol == mincol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 return make_int (mincol);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 if (!NILP (Fextent_at (make_int (BUF_PT (buf)), buffer, Qinvisible,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 Qnil, Qnil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 Bufpos last_visible = last_visible_position (BUF_PT (buf), buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 opoint = BUF_PT (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 if (last_visible >= BUF_BEGV (buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 BUF_SET_PT (buf, last_visible);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 error ("Visible portion of buffer not modifiable");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 if (indent_tabs_mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 int n = mincol / tab_width - fromcol / tab_width;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 if (n != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 Finsert_char (make_char ('\t'), make_int (n), Qnil, buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 fromcol = (mincol / tab_width) * tab_width;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 Finsert_char (make_char (' '), make_int (mincol - fromcol), Qnil, buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 last_known_column_buffer = buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 last_known_column = mincol;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 last_known_column_point = BUF_PT (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 last_known_column_modified = BUF_MODIFF (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 /* Not in FSF: */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 if (opoint > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 BUF_SET_PT (buf, opoint);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 return make_int (mincol);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 bi_spaces_at_point (struct buffer *b, Bytind bi_pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 Bytind bi_end = BI_BUF_ZV (b);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 int col = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 Emchar c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 int tab_width = XINT (b->tab_width);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 if (tab_width <= 0 || tab_width > 1000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 tab_width = 8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 while (bi_pos < bi_end &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 (c = BI_BUF_FETCH_CHAR (b, bi_pos),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 (c == '\t'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 ? (col += tab_width - col % tab_width)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 : (c == ' ' ? ++col : 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 INC_BYTIND (b, bi_pos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 return col;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 DEFUN ("current-indentation", Fcurrent_indentation, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 Return the indentation of the current line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 This is the horizontal position of the character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 following any initial whitespace.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 Bufpos pos = find_next_newline (buf, BUF_PT (buf), -1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 XSETBUFFER (buffer, buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 if (!NILP (Fextent_at (make_int (pos), buffer, Qinvisible, Qnil, Qnil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 return Qzero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 return make_int (bi_spaces_at_point (buf, bufpos_to_bytind (buf, pos)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 DEFUN ("move-to-column", Fmove_to_column, 1, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 Move point to column COLUMN in the current line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 The column of a character is calculated by adding together the widths
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 as displayed of the previous characters in the line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 This function ignores line-continuation;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 there is no upper limit on the column number a character can have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 and horizontal scrolling has no effect.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 If specified column is within a character, point goes after that character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 If it's past end of line, point goes to end of line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 A value of 'coerce for the second (optional) argument FORCE means if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 COLUMN is in the middle of a tab character, change it to spaces.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 Any other non-nil value means the same, plus if the line is too short to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 reach column COLUMN, then add spaces/tabs to get there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 Returns the actual column that it moved to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 (column, force, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 Bufpos pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 int col = current_column (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 int goal;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 Bufpos end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 int tab_width = XINT (buf->tab_width);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 int prev_col = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 Emchar c = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 XSETBUFFER (buffer, buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 CHECK_NATNUM (column);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 goal = XINT (column);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 pos = BUF_PT (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 end = BUF_ZV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 /* If we're starting past the desired column,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 back up to beginning of line and scan from there. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 if (col > goal)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 pos = find_next_newline (buf, pos, -1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 col = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 while (col < goal && pos < end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 c = BUF_FETCH_CHAR (buf, pos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 if (c == '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 if (c == '\r' && EQ (buf->selective_display, Qt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 if (c == '\t')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 prev_col = col;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 col += tab_width;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 col = col / tab_width * tab_width;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 /* #### oh for the days of the complete new redisplay */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 /* #### FSFmacs looks at ctl_arrow, display tables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 We need to do similar. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 displayed_glyphs = glyphs_from_bufpos (selected_frame (),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 buf,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 XWINDOW (Fselected_window (Qnil)),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 pos, dp, 0, col, 0, 0, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 col += (displayed_glyphs->columns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 - (displayed_glyphs->begin_columns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 + displayed_glyphs->end_columns));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 #else /* XEmacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 col += XCHARSET_COLUMNS (CHAR_CHARSET (c));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 col ++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 #endif /* XEmacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 pos++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 BUF_SET_PT (buf, pos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 /* If a tab char made us overshoot, change it to spaces
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 and scan through it again. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 if (!NILP (force) && col > goal && c == '\t' && prev_col < goal)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 buffer_delete_range (buf, BUF_PT (buf) - 1, BUF_PT (buf), 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 Findent_to (make_int (col - 1), Qzero, buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 buffer_insert_emacs_char (buf, ' ');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 /* If line ends prematurely, add space to the end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 if (col < goal && !NILP (force) && !EQ (force, Qcoerce))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 col = goal;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 Findent_to (make_int (col), Qzero, buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 last_known_column_buffer = buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 last_known_column = col;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 last_known_column_point = BUF_PT (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 last_known_column_modified = BUF_MODIFF (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 return make_int (col);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 #if 0 /* #### OK boys, this function needs to be present, I think.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 It was there before the 19.12 redisplay rewrite. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 xxDEFUN ("compute-motion", Fcompute_motion, 7, 7, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 "Scan through the current buffer, calculating screen position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 Scan the current buffer forward from offset FROM,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 assuming it is at position FROMPOS--a cons of the form (HPOS . VPOS)--
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 to position TO or position TOPOS--another cons of the form (HPOS . VPOS)--
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 and return the ending buffer position and screen location.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 There are three additional arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 WIDTH is the number of columns available to display text;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 this affects handling of continuation lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 This is usually the value returned by `window-width', less one (to allow
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 for the continuation glyph).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 OFFSETS is either nil or a cons cell (HSCROLL . TAB-OFFSET).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 HSCROLL is the number of columns not being displayed at the left
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 margin; this is usually taken from a window's hscroll member.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 TAB-OFFSET is the number of columns of the first tab that aren't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 being displayed, perhaps because the line was continued within it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 If OFFSETS is nil, HSCROLL and TAB-OFFSET are assumed to be zero.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 WINDOW is the window to operate on. Currently this is used only to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 find the display table. It does not matter what buffer WINDOW displays;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 `compute-motion' always operates on the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 The value is a list of five elements:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 (POS HPOS VPOS PREVHPOS CONTIN)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 POS is the buffer position where the scan stopped.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 VPOS is the vertical position where the scan stopped.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 HPOS is the horizontal position where the scan stopped.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 PREVHPOS is the horizontal position one character back from POS.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 CONTIN is t if a line was continued after (or within) the previous character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 For example, to find the buffer position of column COL of line LINE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 of a certain window, pass the window's starting location as FROM
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 and the window's upper-left coordinates as FROMPOS.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 Pass the buffer's (point-max) as TO, to limit the scan to the end of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 visible section of the buffer, and pass LINE and COL as TOPOS.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 (from, frompos, to, topos, width, offsets, window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 Lisp_Object bufpos, hpos, vpos, prevhpos, contin;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 struct position *pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 int hscroll, tab_offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 struct window *w = decode_window (window);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 CHECK_INT_COERCE_MARKER (from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 CHECK_CONS (frompos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 CHECK_INT (XCAR (frompos));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 CHECK_INT (XCDR (frompos));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 CHECK_INT_COERCE_MARKER (to);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 CHECK_CONS (topos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 CHECK_INT (XCAR (topos));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 CHECK_INT (XCDR (topos));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 CHECK_INT (width);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 if (!NILP (offsets))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 CHECK_CONS (offsets);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 CHECK_INT (XCAR (offsets));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 CHECK_INT (XCDR (offsets));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 hscroll = XINT (XCAR (offsets));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 tab_offset = XINT (XCDR (offsets));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 hscroll = tab_offset = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 pos = compute_motion (XINT (from), XINT (XCDR (frompos)),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 XINT (XCAR (frompos)),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 XINT (to), XINT (XCDR (topos)),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 XINT (XCAR (topos)),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 XINT (width), hscroll, tab_offset, w);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 XSETINT (bufpos, pos->bufpos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 XSETINT (hpos, pos->hpos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 XSETINT (vpos, pos->vpos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 XSETINT (prevhpos, pos->prevhpos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 return list5 (bufpos, hpos, vpos, prevhpos,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 pos->contin ? Qt : Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 #endif /* 0 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 /* Helper for vmotion_1 - compute vertical pixel motion between
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 START and END in the line start cache CACHE. This just sums
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 the line heights, including both the starting and ending lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 vpix_motion (line_start_cache_dynarr *cache, int start, int end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 int i, vpix;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 assert (start <= end);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 assert (start >= 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 assert (end < Dynarr_length (cache));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 vpix = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 for (i = start; i <= end; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 vpix += Dynarr_atp (cache, i)->height;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 return vpix;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 /*****************************************************************************
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 vmotion_1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 Given a starting position ORIG, move point VTARGET lines in WINDOW.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 Returns the new value for point. If the arg ret_vpos is not nil, it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 taken to be a pointer to an int and the number of lines actually moved is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 returned in it. If the arg ret_vpix is not nil, it is taken to be a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 pointer to an int and the vertical pixel height of the motion which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 took place is returned in it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 ****************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 static Bufpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 vmotion_1 (struct window *w, Bufpos orig, int vtarget,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 int *ret_vpos, int *ret_vpix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 struct buffer *b = XBUFFER (w->buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 int elt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 elt = point_in_line_start_cache (w, orig, (vtarget < 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 ? -vtarget
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 : vtarget));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 /* #### This assertion must be true before the if statements are hit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 but may possibly be wrong after the call to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 point_in_line_start_cache if orig is outside of the visible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 region of the buffer. Handle this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 assert (elt >= 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 /* Moving downward. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 if (vtarget > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 int cur_line = Dynarr_length (w->line_start_cache) - 1 - elt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 Bufpos ret_pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 if (cur_line > vtarget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 cur_line = vtarget;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 /* The traditional FSF behavior is to return the end of buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 position if we couldn't move far enough because we hit it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 if (cur_line < vtarget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 ret_pt = BUF_ZV (b);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 ret_pt = Dynarr_atp (w->line_start_cache, cur_line + elt)->start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 while (ret_pt > BUF_ZV (b) && cur_line > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 cur_line--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 ret_pt = Dynarr_atp (w->line_start_cache, cur_line + elt)->start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 if (ret_vpos) *ret_vpos = cur_line;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 if (ret_vpix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 *ret_vpix = vpix_motion (w->line_start_cache, elt, cur_line + elt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 return ret_pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 else if (vtarget < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 if (elt < -vtarget)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 if (ret_vpos) *ret_vpos = -elt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 if (ret_vpix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 *ret_vpix = vpix_motion (w->line_start_cache, 0, elt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 /* #### This should be BUF_BEGV (b), right? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 return Dynarr_atp (w->line_start_cache, 0)->start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 if (ret_vpos) *ret_vpos = vtarget;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 if (ret_vpix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 *ret_vpix = vpix_motion (w->line_start_cache, elt + vtarget, elt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 return Dynarr_atp (w->line_start_cache, elt + vtarget)->start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 /* No vertical motion requested so we just return the position
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 of the beginning of the current line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 if (ret_vpos) *ret_vpos = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 if (ret_vpix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 *ret_vpix = vpix_motion (w->line_start_cache, elt, elt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 return Dynarr_atp (w->line_start_cache, elt)->start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 RETURN_NOT_REACHED(0) /* shut up compiler */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 /*****************************************************************************
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 vmotion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 Given a starting position ORIG, move point VTARGET lines in WINDOW.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 Returns the new value for point. If the arg ret_vpos is not nil, it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 taken to be a pointer to an int and the number of lines actually moved is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 returned in it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 ****************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 Bufpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 vmotion (struct window *w, Bufpos orig, int vtarget, int *ret_vpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 return vmotion_1 (w, orig, vtarget, ret_vpos, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 /* Helper for Fvertical_motion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 static
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 Lisp_Object vertical_motion_1 (Lisp_Object lines, Lisp_Object window,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 int pixels)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 Bufpos bufpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 Bufpos orig;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 int selected;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 int *vpos, *vpix;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 int value=0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 struct window *w;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 if (NILP (window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 window = Fselected_window (Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 CHECK_LIVE_WINDOW (window);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 CHECK_INT (lines);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 selected = (EQ (window, Fselected_window (Qnil)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 w = XWINDOW (window);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 orig = selected ? BUF_PT (XBUFFER (w->buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 : marker_position (w->pointm[CURRENT_DISP]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 vpos = pixels ? NULL : &value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 vpix = pixels ? &value : NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 bufpos = vmotion_1 (w, orig, XINT (lines), vpos, vpix);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 /* Note that the buffer's point is set, not the window's point. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 if (selected)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 BUF_SET_PT (XBUFFER (w->buffer), bufpos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 set_marker_restricted (w->pointm[CURRENT_DISP],
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 make_int(bufpos),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 w->buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 return make_int (value);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 DEFUN ("vertical-motion", Fvertical_motion, 1, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 Move to start of frame line LINES lines down.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 If LINES is negative, this is moving up.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 Optional second argument is WINDOW to move in,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 the default is the selected window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 Sets point to position found; this may be start of line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 or just the start of a continuation line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 If optional third argument PIXELS is nil, returns number
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 of lines moved; may be closer to zero than LINES if beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 or end of buffer was reached. If PIXELS is non-nil, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 vertical pixel height of the motion which took place is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 returned instead of the actual number of lines moved. A
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 motion of zero lines returns the height of the current line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 Note that `vertical-motion' sets WINDOW's buffer's point, not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 WINDOW's point. (This differs from FSF Emacs, which buggily always
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 sets current buffer's point, regardless of WINDOW.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 (lines, window, pixels))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 return vertical_motion_1 (lines, window, !NILP (pixels));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 * Like vmotion() but requested and returned movement is in pixels.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 * HOW specifies the stopping condition. Positive means move at least
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 * PIXELS. Negative means at most. Zero means as close as possible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 Bufpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 vmotion_pixels (Lisp_Object window, Bufpos start, int pixels, int how,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 int *motion)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 struct window *w;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 Bufpos eobuf, bobuf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 int defheight;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 int needed;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 int line, next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 int remain, abspix, dirn;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 int elt, nelt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 line_start_cache_dynarr *cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 int previous = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 int lines;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 if (NILP (window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 window = Fselected_window (Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 CHECK_LIVE_WINDOW (window);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 w = XWINDOW (window);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 eobuf = BUF_ZV (XBUFFER (w->buffer));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 bobuf = BUF_BEGV (XBUFFER (w->buffer));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 default_face_height_and_width (window, &defheight, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 /* guess num lines needed in line start cache + a few extra */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 abspix = abs (pixels);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 needed = (abspix + defheight-1)/defheight + 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 dirn = (pixels >= 0) ? 1 : -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 elt = point_in_line_start_cache (w, start, needed);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 assert (elt >= 0); /* in the cache */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 cache = w->line_start_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 nelt = Dynarr_length (cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 *motion = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 if (pixels == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 /* No vertical motion requested so we just return the position
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 of the beginning of the current display line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 return Dynarr_atp (cache, elt)->start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 if ((dirn < 0 && elt == 0 &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 Dynarr_atp (cache, elt)->start <= bobuf) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 (dirn > 0 && elt == nelt-1 &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 Dynarr_atp (cache, elt)->end >= eobuf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 return Dynarr_atp (cache, elt)->start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 remain = abspix;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 for (i = elt; (dirn > 0) ? (i < nelt) : (i > 0); i += dirn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 /* cache line we're considering moving over */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 int ii = (dirn > 0) ? i : i-1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 if (remain < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 return Dynarr_atp (cache, i)->start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 line = Dynarr_atp (cache, ii)->height;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 next = remain - line;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 /* is stopping condition satisfied? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 if ((how > 0 && remain <= 0) || /* at least */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 (how < 0 && next < 0) || /* at most */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 (how == 0 && remain <= abs (next))) /* closest */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 return Dynarr_atp (cache, i)->start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 /* moving down and nowhere left to go? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 if (dirn > 0 && Dynarr_atp (cache, ii)->end >= eobuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 return Dynarr_atp (cache, ii)->start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 /* take the step */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 remain = next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 *motion += dirn * line;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 /* moving up and nowhere left to go? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 if (dirn < 0 && Dynarr_atp (cache, ii)->start <= bobuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 return Dynarr_atp (cache, ii)->start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 /* get here => need more cache lines. try again. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 assert (abs (*motion) > previous); /* progress? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 previous = abs (*motion);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 lines = (pixels < 0) ? elt : (nelt - elt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 needed += (remain*lines + abspix-1)/abspix + 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 RETURN_NOT_REACHED(0) /* shut up compiler */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 DEFUN ("vertical-motion-pixels", Fvertical_motion_pixels, 1, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 Move to start of frame line PIXELS vertical pixels down.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 If PIXELS is negative, this is moving up.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 The actual vertical motion in pixels is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 Optional second argument is WINDOW to move in,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 the default is the selected window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 Optional third argument HOW specifies when to stop. A value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 less than zero indicates that the motion should be no more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 than PIXELS. A value greater than zero indicates that the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 motion should be at least PIXELS. Any other value indicates
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 that the motion should be as close as possible to PIXELS.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 (pixels, window, how))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 Bufpos bufpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 Bufpos orig;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 int selected;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 int motion;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 int howto;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 struct window *w;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 if (NILP (window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 window = Fselected_window (Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 CHECK_LIVE_WINDOW (window);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 CHECK_INT (pixels);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 selected = (EQ (window, Fselected_window (Qnil)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 w = XWINDOW (window);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 orig = selected ? BUF_PT (XBUFFER (w->buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 : marker_position (w->pointm[CURRENT_DISP]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 howto = INTP (how) ? XINT (how) : 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 bufpos = vmotion_pixels (window, orig, XINT (pixels), howto, &motion);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 if (selected)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 BUF_SET_PT (XBUFFER (w->buffer), bufpos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 set_marker_restricted (w->pointm[CURRENT_DISP],
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 make_int(bufpos),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 w->buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 return make_int (motion);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 syms_of_indent (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 DEFSUBR (Fcurrent_indentation);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 DEFSUBR (Findent_to);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 DEFSUBR (Fcurrent_column);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 DEFSUBR (Fmove_to_column);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 #if 0 /* #### */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 DEFSUBR (Fcompute_motion);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 DEFSUBR (Fvertical_motion);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 DEFSUBR (Fvertical_motion_pixels);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 defsymbol (&Qcoerce, "coerce");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 vars_of_indent (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 DEFVAR_BOOL ("indent-tabs-mode", &indent_tabs_mode /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 *Indentation can insert tabs if this is non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 Setting this variable automatically makes it local to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 indent_tabs_mode = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 }