165
|
1 /* Indentation functions.
|
59710
|
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1998, 2000, 2001,
|
75348
|
3 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
|
165
|
4
|
|
5 This file is part of GNU Emacs.
|
|
6
|
|
7 GNU Emacs is free software; you can redistribute it and/or modify
|
|
8 it under the terms of the GNU General Public License as published by
|
78260
|
9 the Free Software Foundation; either version 3, or (at your option)
|
165
|
10 any later version.
|
|
11
|
|
12 GNU Emacs is distributed in the hope that it will be useful,
|
|
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 GNU General Public License for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with GNU Emacs; see the file COPYING. If not, write to
|
64084
|
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
20 Boston, MA 02110-1301, USA. */
|
165
|
21
|
4696
|
22 #include <config.h>
|
82995
|
23 #include <stdio.h>
|
|
24
|
165
|
25 #include "lisp.h"
|
|
26 #include "buffer.h"
|
17016
|
27 #include "charset.h"
|
20256
|
28 #include "category.h"
|
165
|
29 #include "indent.h"
|
31102
|
30 #include "keyboard.h"
|
764
|
31 #include "frame.h"
|
165
|
32 #include "window.h"
|
|
33 #include "termchar.h"
|
|
34 #include "termopts.h"
|
|
35 #include "disptab.h"
|
4385
|
36 #include "intervals.h"
|
9407
|
37 #include "region-cache.h"
|
165
|
38
|
|
39 /* Indentation can insert tabs if this is non-zero;
|
36846
|
40 otherwise always uses spaces. */
|
|
41
|
85128
8b61a2e5e365
(indent_tabs_mode, last_known_column, last_known_column_modified): Make static.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
42 static int indent_tabs_mode;
|
165
|
43
|
|
44 #define CR 015
|
|
45
|
39904
|
46 /* These three values memorize the current column to avoid recalculation. */
|
36846
|
47
|
|
48 /* Last value returned by current_column.
|
|
49 Some things in set last_known_column_point to -1
|
39904
|
50 to mark the memorized value as invalid. */
|
36846
|
51
|
85128
8b61a2e5e365
(indent_tabs_mode, last_known_column, last_known_column_modified): Make static.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
52 static double last_known_column;
|
36846
|
53
|
|
54 /* Value of point when current_column was called. */
|
|
55
|
84951
|
56 EMACS_INT last_known_column_point;
|
36846
|
57
|
|
58 /* Value of MODIFF when current_column was called. */
|
|
59
|
85128
8b61a2e5e365
(indent_tabs_mode, last_known_column, last_known_column_modified): Make static.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
60 static int last_known_column_modified;
|
165
|
61
|
46303
|
62 static double current_column_1 P_ ((void));
|
|
63 static double position_indentation P_ ((int));
|
15494
|
64
|
17016
|
65 /* Cache of beginning of line found by the last call of
|
|
66 current_column. */
|
36846
|
67
|
84951
|
68 static EMACS_INT current_column_bol_cache;
|
17016
|
69
|
165
|
70 /* Get the display table to use for the current buffer. */
|
|
71
|
13185
|
72 struct Lisp_Char_Table *
|
165
|
73 buffer_display_table ()
|
|
74 {
|
|
75 Lisp_Object thisbuf;
|
|
76
|
|
77 thisbuf = current_buffer->display_table;
|
13185
|
78 if (DISP_TABLE_P (thisbuf))
|
|
79 return XCHAR_TABLE (thisbuf);
|
|
80 if (DISP_TABLE_P (Vstandard_display_table))
|
|
81 return XCHAR_TABLE (Vstandard_display_table);
|
165
|
82 return 0;
|
|
83 }
|
|
84
|
9407
|
85 /* Width run cache considerations. */
|
|
86
|
|
87 /* Return the width of character C under display table DP. */
|
11037
|
88
|
9407
|
89 static int
|
|
90 character_width (c, dp)
|
|
91 int c;
|
13185
|
92 struct Lisp_Char_Table *dp;
|
9407
|
93 {
|
|
94 Lisp_Object elt;
|
|
95
|
|
96 /* These width computations were determined by examining the cases
|
|
97 in display_text_line. */
|
|
98
|
11037
|
99 /* Everything can be handled by the display table, if it's
|
|
100 present and the element is right. */
|
|
101 if (dp && (elt = DISP_CHAR_VECTOR (dp, c), VECTORP (elt)))
|
|
102 return XVECTOR (elt)->size;
|
|
103
|
|
104 /* Some characters are special. */
|
9407
|
105 if (c == '\n' || c == '\t' || c == '\015')
|
|
106 return 0;
|
|
107
|
11037
|
108 /* Printing characters have width 1. */
|
9407
|
109 else if (c >= 040 && c < 0177)
|
|
110 return 1;
|
|
111
|
|
112 /* Everybody else (control characters, metacharacters) has other
|
|
113 widths. We could return their actual widths here, but they
|
|
114 depend on things like ctl_arrow and crud like that, and they're
|
|
115 not very common at all. So we'll just claim we don't know their
|
|
116 widths. */
|
|
117 else
|
|
118 return 0;
|
|
119 }
|
|
120
|
78501
|
121 /* Return true if the display table DISPTAB specifies the same widths
|
9407
|
122 for characters as WIDTHTAB. We use this to decide when to
|
|
123 invalidate the buffer's width_run_cache. */
|
36846
|
124
|
9407
|
125 int
|
|
126 disptab_matches_widthtab (disptab, widthtab)
|
13185
|
127 struct Lisp_Char_Table *disptab;
|
9407
|
128 struct Lisp_Vector *widthtab;
|
|
129 {
|
|
130 int i;
|
|
131
|
|
132 if (widthtab->size != 256)
|
|
133 abort ();
|
|
134
|
|
135 for (i = 0; i < 256; i++)
|
|
136 if (character_width (i, disptab)
|
|
137 != XFASTINT (widthtab->contents[i]))
|
|
138 return 0;
|
|
139
|
|
140 return 1;
|
10538
|
141 }
|
9407
|
142
|
|
143 /* Recompute BUF's width table, using the display table DISPTAB. */
|
36846
|
144
|
9407
|
145 void
|
|
146 recompute_width_table (buf, disptab)
|
|
147 struct buffer *buf;
|
13185
|
148 struct Lisp_Char_Table *disptab;
|
9407
|
149 {
|
|
150 int i;
|
10011
f4f2563057b8
(recompute_width_table): Do the right thing if no previous table existed.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
151 struct Lisp_Vector *widthtab;
|
9407
|
152
|
10011
f4f2563057b8
(recompute_width_table): Do the right thing if no previous table existed.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
153 if (!VECTORP (buf->width_table))
|
f4f2563057b8
(recompute_width_table): Do the right thing if no previous table existed.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
154 buf->width_table = Fmake_vector (make_number (256), make_number (0));
|
f4f2563057b8
(recompute_width_table): Do the right thing if no previous table existed.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
155 widthtab = XVECTOR (buf->width_table);
|
9407
|
156 if (widthtab->size != 256)
|
|
157 abort ();
|
|
158
|
|
159 for (i = 0; i < 256; i++)
|
10011
f4f2563057b8
(recompute_width_table): Do the right thing if no previous table existed.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
160 XSETFASTINT (widthtab->contents[i], character_width (i, disptab));
|
9407
|
161 }
|
|
162
|
|
163 /* Allocate or free the width run cache, as requested by the current
|
|
164 state of current_buffer's cache_long_line_scans variable. */
|
36846
|
165
|
9407
|
166 static void
|
|
167 width_run_cache_on_off ()
|
|
168 {
|
17016
|
169 if (NILP (current_buffer->cache_long_line_scans)
|
|
170 /* And, for the moment, this feature doesn't work on multibyte
|
|
171 characters. */
|
|
172 || !NILP (current_buffer->enable_multibyte_characters))
|
9407
|
173 {
|
|
174 /* It should be off. */
|
|
175 if (current_buffer->width_run_cache)
|
|
176 {
|
|
177 free_region_cache (current_buffer->width_run_cache);
|
|
178 current_buffer->width_run_cache = 0;
|
|
179 current_buffer->width_table = Qnil;
|
|
180 }
|
|
181 }
|
|
182 else
|
|
183 {
|
|
184 /* It should be on. */
|
|
185 if (current_buffer->width_run_cache == 0)
|
10538
|
186 {
|
9407
|
187 current_buffer->width_run_cache = new_region_cache ();
|
|
188 recompute_width_table (current_buffer, buffer_display_table ());
|
|
189 }
|
|
190 }
|
|
191 }
|
|
192
|
|
193
|
15493
|
194 /* Skip some invisible characters starting from POS.
|
|
195 This includes characters invisible because of text properties
|
|
196 and characters invisible because of overlays.
|
|
197
|
|
198 If position POS is followed by invisible characters,
|
|
199 skip some of them and return the position after them.
|
|
200 Otherwise return POS itself.
|
|
201
|
|
202 Set *NEXT_BOUNDARY_P to the next position at which
|
|
203 it will be necessary to call this function again.
|
|
204
|
|
205 Don't scan past TO, and don't set *NEXT_BOUNDARY_P
|
|
206 to a value greater than TO.
|
|
207
|
|
208 If WINDOW is non-nil, and this buffer is displayed in WINDOW,
|
|
209 take account of overlays that apply only in WINDOW.
|
|
210
|
|
211 We don't necessarily skip all the invisible characters after POS
|
|
212 because that could take a long time. We skip a reasonable number
|
|
213 which can be skipped quickly. If there might be more invisible
|
|
214 characters immediately following, then *NEXT_BOUNDARY_P
|
|
215 will equal the return value. */
|
|
216
|
84951
|
217 EMACS_INT
|
15493
|
218 skip_invisible (pos, next_boundary_p, to, window)
|
84951
|
219 EMACS_INT pos;
|
|
220 EMACS_INT *next_boundary_p;
|
|
221 EMACS_INT to;
|
15493
|
222 Lisp_Object window;
|
|
223 {
|
18613
|
224 Lisp_Object prop, position, overlay_limit, proplimit;
|
58451
4fcc66cf0b9c
(skip_invisible): Avoid non-idempotent side-effects in macro arguments.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
225 Lisp_Object buffer, tmp;
|
84951
|
226 EMACS_INT end;
|
|
227 int inv_p;
|
15493
|
228
|
|
229 XSETFASTINT (position, pos);
|
|
230 XSETBUFFER (buffer, current_buffer);
|
|
231
|
|
232 /* Give faster response for overlay lookup near POS. */
|
|
233 recenter_overlay_lists (current_buffer, pos);
|
|
234
|
|
235 /* We must not advance farther than the next overlay change.
|
|
236 The overlay change might change the invisible property;
|
|
237 or there might be overlay strings to be displayed there. */
|
|
238 overlay_limit = Fnext_overlay_change (position);
|
|
239 /* As for text properties, this gives a lower bound
|
|
240 for where the invisible text property could change. */
|
|
241 proplimit = Fnext_property_change (position, buffer, Qt);
|
|
242 if (XFASTINT (overlay_limit) < XFASTINT (proplimit))
|
|
243 proplimit = overlay_limit;
|
|
244 /* PROPLIMIT is now a lower bound for the next change
|
|
245 in invisible status. If that is plenty far away,
|
|
246 use that lower bound. */
|
|
247 if (XFASTINT (proplimit) > pos + 100 || XFASTINT (proplimit) >= to)
|
|
248 *next_boundary_p = XFASTINT (proplimit);
|
|
249 /* Otherwise, scan for the next `invisible' property change. */
|
|
250 else
|
|
251 {
|
|
252 /* Don't scan terribly far. */
|
|
253 XSETFASTINT (proplimit, min (pos + 100, to));
|
|
254 /* No matter what. don't go past next overlay change. */
|
|
255 if (XFASTINT (overlay_limit) < XFASTINT (proplimit))
|
|
256 proplimit = overlay_limit;
|
58451
4fcc66cf0b9c
(skip_invisible): Avoid non-idempotent side-effects in macro arguments.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
257 tmp = Fnext_single_property_change (position, Qinvisible,
|
4fcc66cf0b9c
(skip_invisible): Avoid non-idempotent side-effects in macro arguments.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
258 buffer, proplimit);
|
4fcc66cf0b9c
(skip_invisible): Avoid non-idempotent side-effects in macro arguments.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
259 end = XFASTINT (tmp);
|
20571
|
260 #if 0
|
17016
|
261 /* Don't put the boundary in the middle of multibyte form if
|
|
262 there is no actual property change. */
|
|
263 if (end == pos + 100
|
|
264 && !NILP (current_buffer->enable_multibyte_characters)
|
|
265 && end < ZV)
|
|
266 while (pos < end && !CHAR_HEAD_P (POS_ADDR (end)))
|
|
267 end--;
|
20571
|
268 #endif
|
18613
|
269 *next_boundary_p = end;
|
15493
|
270 }
|
|
271 /* if the `invisible' property is set, we can skip to
|
|
272 the next property change */
|
43735
|
273 prop = Fget_char_property (position, Qinvisible,
|
|
274 (!NILP (window)
|
|
275 && EQ (XWINDOW (window)->buffer, buffer))
|
|
276 ? window : buffer);
|
|
277 inv_p = TEXT_PROP_MEANS_INVISIBLE (prop);
|
|
278 /* When counting columns (window == nil), don't skip over ellipsis text. */
|
|
279 if (NILP (window) ? inv_p == 1 : inv_p)
|
15493
|
280 return *next_boundary_p;
|
|
281 return pos;
|
|
282 }
|
|
283
|
26859
|
284 /* If a composition starts at POS/POS_BYTE and it doesn't stride over
|
29405
|
285 POINT, set *LEN / *LEN_BYTE to the character and byte lengths, *WIDTH
|
26859
|
286 to the width, and return 1. Otherwise, return 0. */
|
|
287
|
|
288 static int
|
|
289 check_composition (pos, pos_byte, point, len, len_byte, width)
|
|
290 int pos, pos_byte, point;
|
|
291 int *len, *len_byte, *width;
|
|
292 {
|
|
293 Lisp_Object prop;
|
|
294 int start, end;
|
|
295 int id;
|
|
296
|
|
297 if (! find_composition (pos, -1, &start, &end, &prop, Qnil)
|
35405
|
298 || pos != start || point < end
|
|
299 || !COMPOSITION_VALID_P (start, end, prop))
|
26859
|
300 return 0;
|
|
301 if ((id = get_composition_id (pos, pos_byte, end - pos, prop, Qnil)) < 0)
|
|
302 return 0;
|
|
303
|
|
304 *len = COMPOSITION_LENGTH (prop);
|
|
305 *len_byte = CHAR_TO_BYTE (end) - pos_byte;
|
|
306 *width = composition_table[id]->width;
|
|
307 return 1;
|
|
308 }
|
|
309
|
20938
|
310 /* Set variables WIDTH and BYTES for a multibyte sequence starting at P.
|
|
311
|
|
312 DP is a display table or NULL.
|
|
313
|
|
314 This macro is used in current_column_1, Fmove_to_column, and
|
|
315 compute_motion. */
|
|
316
|
26859
|
317 #define MULTIBYTE_BYTES_WIDTH(p, dp) \
|
|
318 do { \
|
|
319 int c; \
|
|
320 \
|
|
321 wide_column = 0; \
|
|
322 c = STRING_CHAR_AND_LENGTH (p, MAX_MULTIBYTE_LENGTH, bytes); \
|
|
323 if (BYTES_BY_CHAR_HEAD (*p) != bytes) \
|
|
324 width = bytes * 4; \
|
|
325 else \
|
|
326 { \
|
|
327 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c))) \
|
|
328 width = XVECTOR (DISP_CHAR_VECTOR (dp, c))->size; \
|
|
329 else \
|
|
330 width = WIDTH_BY_CHAR_HEAD (*p); \
|
|
331 if (width > 1) \
|
|
332 wide_column = width; \
|
|
333 } \
|
20938
|
334 } while (0)
|
|
335
|
45622
|
336
|
165
|
337 DEFUN ("current-column", Fcurrent_column, Scurrent_column, 0, 0, 0,
|
40123
|
338 doc: /* Return the horizontal position of point. Beginning of line is column 0.
|
|
339 This is calculated by adding together the widths of all the displayed
|
|
340 representations of the character between the start of the previous line
|
72885
|
341 and point (eg. control characters will have a width of 2 or 4, tabs
|
|
342 will have a variable width).
|
40123
|
343 Ignores finite width of frame, which means that this function may return
|
|
344 values greater than (frame-width).
|
|
345 Whether the line is visible (if `selective-display' is t) has no effect;
|
59710
|
346 however, ^M is treated as end of line when `selective-display' is t.
|
|
347 Text that has an invisible property is considered as having width 0, unless
|
|
348 `buffer-invisibility-spec' specifies that it is replaced by an ellipsis. */)
|
40123
|
349 ()
|
165
|
350 {
|
|
351 Lisp_Object temp;
|
45622
|
352 XSETFASTINT (temp, (int) current_column ()); /* iftc */
|
165
|
353 return temp;
|
|
354 }
|
|
355
|
327
|
356 /* Cancel any recorded value of the horizontal position. */
|
|
357
|
20371
|
358 void
|
327
|
359 invalidate_current_column ()
|
|
360 {
|
|
361 last_known_column_point = 0;
|
|
362 }
|
|
363
|
46303
|
364 double
|
165
|
365 current_column ()
|
|
366 {
|
|
367 register int col;
|
|
368 register unsigned char *ptr, *stop;
|
|
369 register int tab_seen;
|
|
370 int post_tab;
|
|
371 register int c;
|
|
372 register int tab_width = XINT (current_buffer->tab_width);
|
488
|
373 int ctl_arrow = !NILP (current_buffer->ctl_arrow);
|
13185
|
374 register struct Lisp_Char_Table *dp = buffer_display_table ();
|
165
|
375
|
16039
|
376 if (PT == last_known_column_point
|
165
|
377 && MODIFF == last_known_column_modified)
|
|
378 return last_known_column;
|
|
379
|
20694
83a65a1efdaa
(current_column_1): Eliminate argument POS; use PT and PT_BYTE.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
380 /* If the buffer has overlays, text properties,
|
83a65a1efdaa
(current_column_1): Eliminate argument POS; use PT and PT_BYTE.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
381 or multibyte characters, use a more general algorithm. */
|
15493
|
382 if (BUF_INTERVALS (current_buffer)
|
51838
d0e8a670d28d
(current_column): Use new type for overlays_(before|after).
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
383 || current_buffer->overlays_before
|
d0e8a670d28d
(current_column): Use new type for overlays_(before|after).
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
384 || current_buffer->overlays_after
|
20694
83a65a1efdaa
(current_column_1): Eliminate argument POS; use PT and PT_BYTE.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
385 || Z != Z_BYTE)
|
83a65a1efdaa
(current_column_1): Eliminate argument POS; use PT and PT_BYTE.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
386 return current_column_1 ();
|
15493
|
387
|
|
388 /* Scan backwards from point to the previous newline,
|
|
389 counting width. Tab characters are the only complicated case. */
|
|
390
|
165
|
391 /* Make a pointer for decrementing through the chars before point. */
|
20571
|
392 ptr = BYTE_POS_ADDR (PT_BYTE - 1) + 1;
|
165
|
393 /* Make a pointer to where consecutive chars leave off,
|
|
394 going backwards from point. */
|
16039
|
395 if (PT == BEGV)
|
165
|
396 stop = ptr;
|
16039
|
397 else if (PT <= GPT || BEGV > GPT)
|
165
|
398 stop = BEGV_ADDR;
|
|
399 else
|
|
400 stop = GAP_END_ADDR;
|
|
401
|
36846
|
402 if (tab_width <= 0 || tab_width > 1000)
|
|
403 tab_width = 8;
|
165
|
404
|
|
405 col = 0, tab_seen = 0, post_tab = 0;
|
|
406
|
|
407 while (1)
|
|
408 {
|
36846
|
409 EMACS_INT i, n;
|
|
410 Lisp_Object charvec;
|
45622
|
411
|
165
|
412 if (ptr == stop)
|
|
413 {
|
|
414 /* We stopped either for the beginning of the buffer
|
|
415 or for the gap. */
|
|
416 if (ptr == BEGV_ADDR)
|
|
417 break;
|
45622
|
418
|
165
|
419 /* It was the gap. Jump back over it. */
|
|
420 stop = BEGV_ADDR;
|
|
421 ptr = GPT_ADDR;
|
45622
|
422
|
165
|
423 /* Check whether that brings us to beginning of buffer. */
|
36846
|
424 if (BEGV >= GPT)
|
|
425 break;
|
165
|
426 }
|
|
427
|
|
428 c = *--ptr;
|
45622
|
429
|
36846
|
430 if (dp && VECTORP (DISP_CHAR_VECTOR (dp, c)))
|
19208
|
431 {
|
36846
|
432 charvec = DISP_CHAR_VECTOR (dp, c);
|
|
433 n = ASIZE (charvec);
|
165
|
434 }
|
|
435 else
|
36846
|
436 {
|
|
437 charvec = Qnil;
|
|
438 n = 1;
|
|
439 }
|
45622
|
440
|
36846
|
441 for (i = n - 1; i >= 0; --i)
|
|
442 {
|
|
443 if (VECTORP (charvec))
|
|
444 {
|
|
445 /* This should be handled the same as
|
|
446 next_element_from_display_vector does it. */
|
|
447 Lisp_Object entry = AREF (charvec, i);
|
45622
|
448
|
36846
|
449 if (INTEGERP (entry)
|
|
450 && GLYPH_CHAR_VALID_P (XFASTINT (entry)))
|
|
451 c = FAST_GLYPH_CHAR (XFASTINT (entry));
|
|
452 else
|
|
453 c = ' ';
|
|
454 }
|
45622
|
455
|
36846
|
456 if (c >= 040 && c < 0177)
|
|
457 col++;
|
|
458 else if (c == '\n'
|
|
459 || (c == '\r'
|
|
460 && EQ (current_buffer->selective_display, Qt)))
|
|
461 {
|
|
462 ptr++;
|
|
463 goto start_of_line_found;
|
|
464 }
|
|
465 else if (c == '\t')
|
|
466 {
|
|
467 if (tab_seen)
|
|
468 col = ((col + tab_width) / tab_width) * tab_width;
|
45622
|
469
|
36846
|
470 post_tab += col;
|
|
471 col = 0;
|
|
472 tab_seen = 1;
|
|
473 }
|
38530
|
474 else if (VECTORP (charvec))
|
|
475 /* With a display table entry, C is displayed as is, and
|
|
476 not displayed as \NNN or as ^N. If C is a single-byte
|
|
477 character, it takes one column. If C is multi-byte in
|
|
478 an unibyte buffer, it's translated to unibyte, so it
|
|
479 also takes one column. */
|
|
480 ++col;
|
36846
|
481 else
|
|
482 col += (ctl_arrow && c < 0200) ? 2 : 4;
|
|
483 }
|
165
|
484 }
|
|
485
|
36846
|
486 start_of_line_found:
|
|
487
|
165
|
488 if (tab_seen)
|
|
489 {
|
|
490 col = ((col + tab_width) / tab_width) * tab_width;
|
|
491 col += post_tab;
|
|
492 }
|
|
493
|
17016
|
494 if (ptr == BEGV_ADDR)
|
|
495 current_column_bol_cache = BEGV;
|
|
496 else
|
20571
|
497 current_column_bol_cache = BYTE_TO_CHAR (PTR_BYTE_POS (ptr));
|
|
498
|
165
|
499 last_known_column = col;
|
16039
|
500 last_known_column_point = PT;
|
165
|
501 last_known_column_modified = MODIFF;
|
|
502
|
|
503 return col;
|
|
504 }
|
|
505
|
15493
|
506 /* Return the column number of position POS
|
|
507 by scanning forward from the beginning of the line.
|
|
508 This function handles characters that are invisible
|
|
509 due to text properties or overlays. */
|
|
510
|
46303
|
511 static double
|
20694
83a65a1efdaa
(current_column_1): Eliminate argument POS; use PT and PT_BYTE.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
512 current_column_1 ()
|
15493
|
513 {
|
84951
|
514 register EMACS_INT tab_width = XINT (current_buffer->tab_width);
|
15493
|
515 register int ctl_arrow = !NILP (current_buffer->ctl_arrow);
|
|
516 register struct Lisp_Char_Table *dp = buffer_display_table ();
|
20571
|
517 int multibyte = !NILP (current_buffer->enable_multibyte_characters);
|
15493
|
518
|
|
519 /* Start the scan at the beginning of this line with column number 0. */
|
84951
|
520 register EMACS_INT col = 0;
|
|
521 EMACS_INT scan, scan_byte;
|
|
522 EMACS_INT next_boundary;
|
|
523 EMACS_INT opoint = PT, opoint_byte = PT_BYTE;
|
20571
|
524
|
20694
83a65a1efdaa
(current_column_1): Eliminate argument POS; use PT and PT_BYTE.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
525 scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, 1);
|
20571
|
526 current_column_bol_cache = PT;
|
|
527 scan = PT, scan_byte = PT_BYTE;
|
|
528 SET_PT_BOTH (opoint, opoint_byte);
|
|
529 next_boundary = scan;
|
15493
|
530
|
|
531 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
|
|
532
|
|
533 /* Scan forward to the target position. */
|
20694
83a65a1efdaa
(current_column_1): Eliminate argument POS; use PT and PT_BYTE.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
534 while (scan < opoint)
|
15493
|
535 {
|
|
536 int c;
|
|
537
|
|
538 /* Occasionally we may need to skip invisible text. */
|
|
539 while (scan == next_boundary)
|
|
540 {
|
20571
|
541 int old_scan = scan;
|
15493
|
542 /* This updates NEXT_BOUNDARY to the next place
|
|
543 where we might need to skip more invisible text. */
|
20694
83a65a1efdaa
(current_column_1): Eliminate argument POS; use PT and PT_BYTE.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
544 scan = skip_invisible (scan, &next_boundary, opoint, Qnil);
|
83a65a1efdaa
(current_column_1): Eliminate argument POS; use PT and PT_BYTE.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
545 if (scan >= opoint)
|
15493
|
546 goto endloop;
|
20571
|
547 if (scan != old_scan)
|
|
548 scan_byte = CHAR_TO_BYTE (scan);
|
15493
|
549 }
|
|
550
|
26859
|
551 /* Check composition sequence. */
|
|
552 {
|
|
553 int len, len_byte, width;
|
|
554
|
|
555 if (check_composition (scan, scan_byte, opoint,
|
|
556 &len, &len_byte, &width))
|
|
557 {
|
|
558 scan += len;
|
|
559 scan_byte += len_byte;
|
|
560 if (scan <= opoint)
|
|
561 col += width;
|
|
562 continue;
|
|
563 }
|
|
564 }
|
|
565
|
20694
83a65a1efdaa
(current_column_1): Eliminate argument POS; use PT and PT_BYTE.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
566 c = FETCH_BYTE (scan_byte);
|
36846
|
567
|
20938
|
568 if (dp != 0
|
|
569 && ! (multibyte && BASE_LEADING_CODE_P (c))
|
|
570 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
|
15493
|
571 {
|
40720
|
572 Lisp_Object charvec;
|
|
573 EMACS_INT i, n;
|
|
574
|
|
575 /* This character is displayed using a vector of glyphs.
|
|
576 Update the column based on those glyphs. */
|
|
577
|
36846
|
578 charvec = DISP_CHAR_VECTOR (dp, c);
|
|
579 n = ASIZE (charvec);
|
|
580
|
40720
|
581 for (i = 0; i < n; i++)
|
36846
|
582 {
|
|
583 /* This should be handled the same as
|
|
584 next_element_from_display_vector does it. */
|
40720
|
585 Lisp_Object entry;
|
|
586 entry = AREF (charvec, i);
|
|
587
|
36846
|
588 if (INTEGERP (entry)
|
|
589 && GLYPH_CHAR_VALID_P (XFASTINT (entry)))
|
|
590 c = FAST_GLYPH_CHAR (XFASTINT (entry));
|
|
591 else
|
|
592 c = ' ';
|
40720
|
593
|
|
594 if (c == '\n')
|
|
595 goto endloop;
|
|
596 if (c == '\r' && EQ (current_buffer->selective_display, Qt))
|
|
597 goto endloop;
|
|
598 if (c == '\t')
|
|
599 {
|
|
600 col += tab_width;
|
|
601 col = col / tab_width * tab_width;
|
|
602 }
|
|
603 else
|
|
604 ++col;
|
36846
|
605 }
|
40720
|
606 }
|
|
607 else
|
|
608 {
|
|
609 /* The display table says nothing for this character.
|
|
610 Display it as itself. */
|
|
611
|
36846
|
612 if (c == '\n')
|
|
613 goto endloop;
|
|
614 if (c == '\r' && EQ (current_buffer->selective_display, Qt))
|
|
615 goto endloop;
|
|
616 if (c == '\t')
|
|
617 {
|
|
618 col += tab_width;
|
|
619 col = col / tab_width * tab_width;
|
|
620 }
|
|
621 else if (multibyte && BASE_LEADING_CODE_P (c))
|
|
622 {
|
|
623 unsigned char *ptr;
|
|
624 int bytes, width, wide_column;
|
45622
|
625
|
36846
|
626 ptr = BYTE_POS_ADDR (scan_byte);
|
|
627 MULTIBYTE_BYTES_WIDTH (ptr, dp);
|
|
628 scan_byte += bytes;
|
41258
|
629 /* Subtract one to compensate for the increment
|
|
630 that is going to happen below. */
|
|
631 scan_byte--;
|
36846
|
632 col += width;
|
|
633 }
|
|
634 else if (ctl_arrow && (c < 040 || c == 0177))
|
|
635 col += 2;
|
|
636 else if (c < 040 || c >= 0177)
|
|
637 col += 4;
|
|
638 else
|
|
639 col++;
|
15493
|
640 }
|
40720
|
641 scan++;
|
|
642 scan_byte++;
|
|
643
|
15493
|
644 }
|
|
645 endloop:
|
|
646
|
|
647 last_known_column = col;
|
16039
|
648 last_known_column_point = PT;
|
15493
|
649 last_known_column_modified = MODIFF;
|
|
650
|
|
651 return col;
|
|
652 }
|
|
653
|
37917
|
654
|
|
655 #if 0 /* Not used. */
|
|
656
|
11300
|
657 /* Return the width in columns of the part of STRING from BEG to END.
|
|
658 If BEG is nil, that stands for the beginning of STRING.
|
|
659 If END is nil, that stands for the end of STRING. */
|
|
660
|
46303
|
661 static double
|
11704
|
662 string_display_width (string, beg, end)
|
11300
|
663 Lisp_Object string, beg, end;
|
|
664 {
|
|
665 register int col;
|
|
666 register unsigned char *ptr, *stop;
|
|
667 register int tab_seen;
|
|
668 int post_tab;
|
|
669 register int c;
|
|
670 register int tab_width = XINT (current_buffer->tab_width);
|
|
671 int ctl_arrow = !NILP (current_buffer->ctl_arrow);
|
13185
|
672 register struct Lisp_Char_Table *dp = buffer_display_table ();
|
11300
|
673 int b, e;
|
|
674
|
|
675 if (NILP (end))
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
676 e = SCHARS (string);
|
11300
|
677 else
|
|
678 {
|
40656
|
679 CHECK_NUMBER (end);
|
11300
|
680 e = XINT (end);
|
|
681 }
|
|
682
|
|
683 if (NILP (beg))
|
|
684 b = 0;
|
|
685 else
|
|
686 {
|
40656
|
687 CHECK_NUMBER (beg);
|
11300
|
688 b = XINT (beg);
|
|
689 }
|
|
690
|
|
691 /* Make a pointer for decrementing through the chars before point. */
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
692 ptr = SDATA (string) + e;
|
11300
|
693 /* Make a pointer to where consecutive chars leave off,
|
|
694 going backwards from point. */
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
695 stop = SDATA (string) + b;
|
11300
|
696
|
|
697 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
|
|
698
|
|
699 col = 0, tab_seen = 0, post_tab = 0;
|
|
700
|
|
701 while (1)
|
|
702 {
|
|
703 if (ptr == stop)
|
|
704 break;
|
|
705
|
|
706 c = *--ptr;
|
|
707 if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
|
|
708 col += XVECTOR (DISP_CHAR_VECTOR (dp, c))->size;
|
|
709 else if (c >= 040 && c < 0177)
|
|
710 col++;
|
|
711 else if (c == '\n')
|
|
712 break;
|
|
713 else if (c == '\t')
|
|
714 {
|
|
715 if (tab_seen)
|
|
716 col = ((col + tab_width) / tab_width) * tab_width;
|
|
717
|
|
718 post_tab += col;
|
|
719 col = 0;
|
|
720 tab_seen = 1;
|
|
721 }
|
|
722 else
|
|
723 col += (ctl_arrow && c < 0200) ? 2 : 4;
|
|
724 }
|
|
725
|
|
726 if (tab_seen)
|
|
727 {
|
|
728 col = ((col + tab_width) / tab_width) * tab_width;
|
|
729 col += post_tab;
|
|
730 }
|
|
731
|
|
732 return col;
|
|
733 }
|
37917
|
734
|
|
735 #endif /* 0 */
|
|
736
|
11300
|
737
|
165
|
738 DEFUN ("indent-to", Findent_to, Sindent_to, 1, 2, "NIndent to column: ",
|
40123
|
739 doc: /* Indent from point with tabs and spaces until COLUMN is reached.
|
72885
|
740 Optional second argument MINIMUM says always do at least MINIMUM spaces
|
76707
|
741 even if that goes past COLUMN; by default, MINIMUM is zero.
|
|
742
|
|
743 The return value is COLUMN. */)
|
40123
|
744 (column, minimum)
|
14078
|
745 Lisp_Object column, minimum;
|
165
|
746 {
|
|
747 int mincol;
|
|
748 register int fromcol;
|
|
749 register int tab_width = XINT (current_buffer->tab_width);
|
|
750
|
40656
|
751 CHECK_NUMBER (column);
|
488
|
752 if (NILP (minimum))
|
9310
|
753 XSETFASTINT (minimum, 0);
|
40656
|
754 CHECK_NUMBER (minimum);
|
165
|
755
|
|
756 fromcol = current_column ();
|
|
757 mincol = fromcol + XINT (minimum);
|
14078
|
758 if (mincol < XINT (column)) mincol = XINT (column);
|
165
|
759
|
|
760 if (fromcol == mincol)
|
|
761 return make_number (mincol);
|
|
762
|
2325
|
763 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
|
165
|
764
|
|
765 if (indent_tabs_mode)
|
|
766 {
|
|
767 Lisp_Object n;
|
9310
|
768 XSETFASTINT (n, mincol / tab_width - fromcol / tab_width);
|
165
|
769 if (XFASTINT (n) != 0)
|
|
770 {
|
8648
|
771 Finsert_char (make_number ('\t'), n, Qt);
|
165
|
772
|
|
773 fromcol = (mincol / tab_width) * tab_width;
|
|
774 }
|
|
775 }
|
|
776
|
14078
|
777 XSETFASTINT (column, mincol - fromcol);
|
|
778 Finsert_char (make_number (' '), column, Qt);
|
165
|
779
|
|
780 last_known_column = mincol;
|
16039
|
781 last_known_column_point = PT;
|
165
|
782 last_known_column_modified = MODIFF;
|
|
783
|
14078
|
784 XSETINT (column, mincol);
|
|
785 return column;
|
165
|
786 }
|
9407
|
787
|
165
|
788
|
46303
|
789 static double position_indentation P_ ((int));
|
21514
|
790
|
165
|
791 DEFUN ("current-indentation", Fcurrent_indentation, Scurrent_indentation,
|
40123
|
792 0, 0, 0,
|
|
793 doc: /* Return the indentation of the current line.
|
|
794 This is the horizontal position of the character
|
|
795 following any initial whitespace. */)
|
|
796 ()
|
165
|
797 {
|
|
798 Lisp_Object val;
|
20571
|
799 int opoint = PT, opoint_byte = PT_BYTE;
|
165
|
800
|
20571
|
801 scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, 1);
|
|
802
|
45622
|
803 XSETFASTINT (val, (int) position_indentation (PT_BYTE)); /* iftc */
|
20571
|
804 SET_PT_BOTH (opoint, opoint_byte);
|
165
|
805 return val;
|
|
806 }
|
|
807
|
46303
|
808 static double
|
20571
|
809 position_indentation (pos_byte)
|
|
810 register int pos_byte;
|
165
|
811 {
|
84951
|
812 register EMACS_INT column = 0;
|
|
813 register EMACS_INT tab_width = XINT (current_buffer->tab_width);
|
165
|
814 register unsigned char *p;
|
|
815 register unsigned char *stop;
|
15493
|
816 unsigned char *start;
|
84951
|
817 EMACS_INT next_boundary_byte = pos_byte;
|
|
818 EMACS_INT ceiling = next_boundary_byte;
|
10538
|
819
|
2325
|
820 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
|
10538
|
821
|
20571
|
822 p = BYTE_POS_ADDR (pos_byte);
|
15493
|
823 /* STOP records the value of P at which we will need
|
|
824 to think about the gap, or about invisible text,
|
|
825 or about the end of the buffer. */
|
|
826 stop = p;
|
|
827 /* START records the starting value of P. */
|
|
828 start = p;
|
165
|
829 while (1)
|
|
830 {
|
|
831 while (p == stop)
|
|
832 {
|
84951
|
833 EMACS_INT stop_pos_byte;
|
15493
|
834
|
20571
|
835 /* If we have updated P, set POS_BYTE to match.
|
|
836 The first time we enter the loop, POS_BYTE is already right. */
|
15493
|
837 if (p != start)
|
20571
|
838 pos_byte = PTR_BYTE_POS (p);
|
15493
|
839 /* Consider the various reasons STOP might have been set here. */
|
20571
|
840 if (pos_byte == ZV_BYTE)
|
165
|
841 return column;
|
20571
|
842 if (pos_byte == next_boundary_byte)
|
|
843 {
|
84951
|
844 EMACS_INT next_boundary;
|
|
845 EMACS_INT pos = BYTE_TO_CHAR (pos_byte);
|
20571
|
846 pos = skip_invisible (pos, &next_boundary, ZV, Qnil);
|
|
847 pos_byte = CHAR_TO_BYTE (pos);
|
|
848 next_boundary_byte = CHAR_TO_BYTE (next_boundary);
|
|
849 }
|
|
850 if (pos_byte >= ceiling)
|
|
851 ceiling = BUFFER_CEILING_OF (pos_byte) + 1;
|
15493
|
852 /* Compute the next place we need to stop and think,
|
|
853 and set STOP accordingly. */
|
20571
|
854 stop_pos_byte = min (ceiling, next_boundary_byte);
|
15493
|
855 /* The -1 and +1 arrange to point at the first byte of gap
|
20571
|
856 (if STOP_POS_BYTE is the position of the gap)
|
15493
|
857 rather than at the data after the gap. */
|
45622
|
858
|
20571
|
859 stop = BYTE_POS_ADDR (stop_pos_byte - 1) + 1;
|
|
860 p = BYTE_POS_ADDR (pos_byte);
|
165
|
861 }
|
|
862 switch (*p++)
|
|
863 {
|
20256
|
864 case 0240:
|
|
865 if (! NILP (current_buffer->enable_multibyte_characters))
|
|
866 return column;
|
165
|
867 case ' ':
|
|
868 column++;
|
|
869 break;
|
|
870 case '\t':
|
|
871 column += tab_width - column % tab_width;
|
|
872 break;
|
|
873 default:
|
20256
|
874 if (ASCII_BYTE_P (p[-1])
|
|
875 || NILP (current_buffer->enable_multibyte_characters))
|
|
876 return column;
|
|
877 {
|
20571
|
878 int c;
|
|
879 pos_byte = PTR_BYTE_POS (p - 1);
|
|
880 c = FETCH_MULTIBYTE_CHAR (pos_byte);
|
20256
|
881 if (CHAR_HAS_CATEGORY (c, ' '))
|
|
882 {
|
|
883 column++;
|
20571
|
884 INC_POS (pos_byte);
|
|
885 p = BYTE_POS_ADDR (pos_byte);
|
20256
|
886 }
|
|
887 else
|
|
888 return column;
|
|
889 }
|
165
|
890 }
|
|
891 }
|
|
892 }
|
5943
|
893
|
|
894 /* Test whether the line beginning at POS is indented beyond COLUMN.
|
|
895 Blank lines are treated as if they had the same indentation as the
|
|
896 preceding line. */
|
20571
|
897
|
5943
|
898 int
|
20571
|
899 indented_beyond_p (pos, pos_byte, column)
|
45622
|
900 int pos, pos_byte;
|
46303
|
901 double column;
|
5943
|
902 {
|
46303
|
903 double val;
|
20571
|
904 int opoint = PT, opoint_byte = PT_BYTE;
|
|
905
|
|
906 SET_PT_BOTH (pos, pos_byte);
|
|
907 while (PT > BEGV && FETCH_BYTE (PT_BYTE) == '\n')
|
|
908 scan_newline (PT - 1, PT_BYTE - 1, BEGV, BEGV_BYTE, -1, 0);
|
|
909
|
21525
|
910 val = position_indentation (PT_BYTE);
|
20571
|
911 SET_PT_BOTH (opoint, opoint_byte);
|
45622
|
912 return val >= column; /* hmm, float comparison */
|
5943
|
913 }
|
165
|
914
|
13124
|
915 DEFUN ("move-to-column", Fmove_to_column, Smove_to_column, 1, 2, "p",
|
40123
|
916 doc: /* Move point to column COLUMN in the current line.
|
75652
bd6d4488b990
(Fmove_to_column): Document that the argument COLUMN is taken from prefix
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
917 Interactively, COLUMN is the value of prefix numeric argument.
|
40123
|
918 The column of a character is calculated by adding together the widths
|
|
919 as displayed of the previous characters in the line.
|
|
920 This function ignores line-continuation;
|
|
921 there is no upper limit on the column number a character can have
|
|
922 and horizontal scrolling has no effect.
|
|
923
|
|
924 If specified column is within a character, point goes after that character.
|
|
925 If it's past end of line, point goes to end of line.
|
|
926
|
75652
bd6d4488b990
(Fmove_to_column): Document that the argument COLUMN is taken from prefix
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
927 Optional second argument FORCE non-nil means if COLUMN is in the
|
bd6d4488b990
(Fmove_to_column): Document that the argument COLUMN is taken from prefix
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
928 middle of a tab character, change it to spaces.
|
bd6d4488b990
(Fmove_to_column): Document that the argument COLUMN is taken from prefix
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
929 In addition, if FORCE is t, and the line is too short to reach
|
bd6d4488b990
(Fmove_to_column): Document that the argument COLUMN is taken from prefix
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
930 COLUMN, add spaces/tabs to get there.
|
40123
|
931
|
|
932 The return value is the current column. */)
|
|
933 (column, force)
|
165
|
934 Lisp_Object column, force;
|
|
935 {
|
84950
|
936 register EMACS_INT pos;
|
|
937 register EMACS_INT col = current_column ();
|
|
938 register EMACS_INT goal;
|
|
939 register EMACS_INT end;
|
165
|
940 register int tab_width = XINT (current_buffer->tab_width);
|
488
|
941 register int ctl_arrow = !NILP (current_buffer->ctl_arrow);
|
13185
|
942 register struct Lisp_Char_Table *dp = buffer_display_table ();
|
17016
|
943 register int multibyte = !NILP (current_buffer->enable_multibyte_characters);
|
165
|
944
|
|
945 Lisp_Object val;
|
84950
|
946 EMACS_INT prev_col = 0;
|
31829
|
947 int c = 0;
|
84950
|
948 EMACS_INT next_boundary, pos_byte;
|
15493
|
949
|
2325
|
950 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
|
40656
|
951 CHECK_NATNUM (column);
|
165
|
952 goal = XINT (column);
|
|
953
|
16039
|
954 pos = PT;
|
20571
|
955 pos_byte = PT_BYTE;
|
165
|
956 end = ZV;
|
|
957
|
|
958 /* If we're starting past the desired column,
|
|
959 back up to beginning of line and scan from there. */
|
|
960 if (col > goal)
|
|
961 {
|
15493
|
962 end = pos;
|
17016
|
963 pos = current_column_bol_cache;
|
20571
|
964 pos_byte = CHAR_TO_BYTE (pos);
|
165
|
965 col = 0;
|
|
966 }
|
|
967
|
77069
|
968 next_boundary = pos;
|
|
969
|
15554
|
970 while (pos < end)
|
165
|
971 {
|
15493
|
972 while (pos == next_boundary)
|
|
973 {
|
84950
|
974 EMACS_INT prev = pos;
|
15493
|
975 pos = skip_invisible (pos, &next_boundary, end, Qnil);
|
20571
|
976 if (pos != prev)
|
|
977 pos_byte = CHAR_TO_BYTE (pos);
|
15493
|
978 if (pos >= end)
|
|
979 goto endloop;
|
|
980 }
|
|
981
|
15554
|
982 /* Test reaching the goal column. We do this after skipping
|
|
983 invisible characters, so that we put point before the
|
|
984 character on which the cursor will appear. */
|
|
985 if (col >= goal)
|
|
986 break;
|
|
987
|
26859
|
988 /* Check composition sequence. */
|
|
989 {
|
|
990 int len, len_byte, width;
|
|
991
|
|
992 if (check_composition (pos, pos_byte, Z, &len, &len_byte, &width))
|
|
993 {
|
|
994 pos += len;
|
|
995 pos_byte += len_byte;
|
|
996 col += width;
|
|
997 continue;
|
|
998 }
|
|
999 }
|
|
1000
|
20571
|
1001 c = FETCH_BYTE (pos_byte);
|
36846
|
1002
|
40720
|
1003 /* See if there is a display table and it relates
|
|
1004 to this character. */
|
|
1005
|
20938
|
1006 if (dp != 0
|
|
1007 && ! (multibyte && BASE_LEADING_CODE_P (c))
|
|
1008 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
|
11037
|
1009 {
|
40720
|
1010 Lisp_Object charvec;
|
|
1011 EMACS_INT i, n;
|
|
1012
|
|
1013 /* This character is displayed using a vector of glyphs.
|
|
1014 Update the position based on those glyphs. */
|
|
1015
|
36846
|
1016 charvec = DISP_CHAR_VECTOR (dp, c);
|
|
1017 n = ASIZE (charvec);
|
|
1018
|
40720
|
1019 for (i = 0; i < n; i++)
|
36846
|
1020 {
|
|
1021 /* This should be handled the same as
|
|
1022 next_element_from_display_vector does it. */
|
40720
|
1023
|
|
1024 Lisp_Object entry;
|
|
1025 entry = AREF (charvec, i);
|
|
1026
|
36846
|
1027 if (INTEGERP (entry)
|
|
1028 && GLYPH_CHAR_VALID_P (XFASTINT (entry)))
|
|
1029 c = FAST_GLYPH_CHAR (XFASTINT (entry));
|
|
1030 else
|
|
1031 c = ' ';
|
|
1032
|
40720
|
1033 if (c == '\n')
|
|
1034 goto endloop;
|
|
1035 if (c == '\r' && EQ (current_buffer->selective_display, Qt))
|
|
1036 goto endloop;
|
|
1037 if (c == '\t')
|
|
1038 {
|
|
1039 prev_col = col;
|
|
1040 col += tab_width;
|
|
1041 col = col / tab_width * tab_width;
|
|
1042 }
|
|
1043 else
|
|
1044 ++col;
|
|
1045 }
|
|
1046 }
|
|
1047 else
|
|
1048 {
|
|
1049 /* The display table doesn't affect this character;
|
|
1050 it displays as itself. */
|
|
1051
|
36846
|
1052 if (c == '\n')
|
|
1053 goto endloop;
|
|
1054 if (c == '\r' && EQ (current_buffer->selective_display, Qt))
|
|
1055 goto endloop;
|
|
1056 if (c == '\t')
|
|
1057 {
|
|
1058 prev_col = col;
|
|
1059 col += tab_width;
|
|
1060 col = col / tab_width * tab_width;
|
|
1061 }
|
|
1062 else if (ctl_arrow && (c < 040 || c == 0177))
|
|
1063 col += 2;
|
|
1064 else if (c < 040 || c == 0177)
|
|
1065 col += 4;
|
|
1066 else if (c < 0177)
|
|
1067 col++;
|
|
1068 else if (multibyte && BASE_LEADING_CODE_P (c))
|
|
1069 {
|
|
1070 /* Start of multi-byte form. */
|
|
1071 unsigned char *ptr;
|
|
1072 int bytes, width, wide_column;
|
|
1073
|
|
1074 ptr = BYTE_POS_ADDR (pos_byte);
|
|
1075 MULTIBYTE_BYTES_WIDTH (ptr, dp);
|
40720
|
1076 pos_byte += bytes - 1;
|
36846
|
1077 col += width;
|
|
1078 }
|
|
1079 else
|
|
1080 col += 4;
|
|
1081 }
|
40720
|
1082
|
|
1083 pos++;
|
|
1084 pos_byte++;
|
165
|
1085 }
|
15493
|
1086 endloop:
|
165
|
1087
|
20571
|
1088 SET_PT_BOTH (pos, pos_byte);
|
165
|
1089
|
|
1090 /* If a tab char made us overshoot, change it to spaces
|
|
1091 and scan through it again. */
|
488
|
1092 if (!NILP (force) && col > goal && c == '\t' && prev_col < goal)
|
165
|
1093 {
|
84950
|
1094 EMACS_INT goal_pt, goal_pt_byte;
|
28933
|
1095
|
|
1096 /* Insert spaces in front of the tab to reach GOAL. Do this
|
|
1097 first so that a marker at the end of the tab gets
|
|
1098 adjusted. */
|
|
1099 SET_PT_BOTH (PT - 1, PT_BYTE - 1);
|
|
1100 Finsert_char (make_number (' '), make_number (goal - prev_col), Qt);
|
573
|
1101
|
28933
|
1102 /* Now delete the tab, and indent to COL. */
|
|
1103 del_range (PT, PT + 1);
|
|
1104 goal_pt = PT;
|
|
1105 goal_pt_byte = PT_BYTE;
|
573
|
1106 Findent_to (make_number (col), Qnil);
|
28933
|
1107 SET_PT_BOTH (goal_pt, goal_pt_byte);
|
45622
|
1108
|
4385
|
1109 /* Set the last_known... vars consistently. */
|
|
1110 col = goal;
|
165
|
1111 }
|
|
1112
|
|
1113 /* If line ends prematurely, add space to the end. */
|
25073
|
1114 if (col < goal && EQ (force, Qt))
|
1208
|
1115 Findent_to (make_number (col = goal), Qnil);
|
165
|
1116
|
|
1117 last_known_column = col;
|
16039
|
1118 last_known_column_point = PT;
|
165
|
1119 last_known_column_modified = MODIFF;
|
|
1120
|
9310
|
1121 XSETFASTINT (val, col);
|
165
|
1122 return val;
|
|
1123 }
|
|
1124
|
9407
|
1125 /* compute_motion: compute buffer posn given screen posn and vice versa */
|
|
1126
|
165
|
1127 struct position val_compute_motion;
|
|
1128
|
|
1129 /* Scan the current buffer forward from offset FROM, pretending that
|
|
1130 this is at line FROMVPOS, column FROMHPOS, until reaching buffer
|
|
1131 offset TO or line TOVPOS, column TOHPOS (whichever comes first),
|
9407
|
1132 and return the ending buffer position and screen location. If we
|
|
1133 can't hit the requested column exactly (because of a tab or other
|
|
1134 multi-column character), overshoot.
|
165
|
1135
|
11853
|
1136 DID_MOTION is 1 if FROMHPOS has already accounted for overlay strings
|
|
1137 at FROM. This is the case if FROMVPOS and FROMVPOS came from an
|
|
1138 earlier call to compute_motion. The other common case is that FROMHPOS
|
|
1139 is zero and FROM is a position that "belongs" at column zero, but might
|
|
1140 be shifted by overlay strings; in this case DID_MOTION should be 0.
|
|
1141
|
165
|
1142 WIDTH is the number of columns available to display text;
|
|
1143 compute_motion uses this to handle continuation lines and such.
|
56584
|
1144 If WIDTH is -1, use width of window's text area adjusted for
|
|
1145 continuation glyph when needed.
|
|
1146
|
165
|
1147 HSCROLL is the number of columns not being displayed at the left
|
|
1148 margin; this is usually taken from a window's hscroll member.
|
543
|
1149 TAB_OFFSET is the number of columns of the first tab that aren't
|
|
1150 being displayed, perhaps because of a continuation line or
|
|
1151 something.
|
165
|
1152
|
|
1153 compute_motion returns a pointer to a struct position. The bufpos
|
|
1154 member gives the buffer position at the end of the scan, and hpos
|
9407
|
1155 and vpos give its cartesian location. prevhpos is the column at
|
|
1156 which the character before bufpos started, and contin is non-zero
|
|
1157 if we reached the current line by continuing the previous.
|
|
1158
|
|
1159 Note that FROMHPOS and TOHPOS should be expressed in real screen
|
|
1160 columns, taking HSCROLL and the truncation glyph at the left margin
|
|
1161 into account. That is, beginning-of-line moves you to the hpos
|
|
1162 -HSCROLL + (HSCROLL > 0).
|
165
|
1163
|
|
1164 For example, to find the buffer position of column COL of line LINE
|
|
1165 of a certain window, pass the window's starting location as FROM
|
|
1166 and the window's upper-left coordinates as FROMVPOS and FROMHPOS.
|
|
1167 Pass the buffer's ZV as TO, to limit the scan to the end of the
|
|
1168 visible section of the buffer, and pass LINE and COL as TOVPOS and
|
10538
|
1169 TOHPOS.
|
165
|
1170
|
|
1171 When displaying in window w, a typical formula for WIDTH is:
|
|
1172
|
|
1173 window_width - 1
|
1994
|
1174 - (has_vertical_scroll_bars
|
51206
|
1175 ? WINDOW_CONFIG_SCROLL_BAR_COLS (window)
|
|
1176 : (window_width + window_left != frame_cols))
|
165
|
1177
|
|
1178 where
|
51206
|
1179 window_width is XFASTINT (w->total_cols),
|
|
1180 window_left is XFASTINT (w->left_col),
|
1994
|
1181 has_vertical_scroll_bars is
|
51206
|
1182 WINDOW_HAS_VERTICAL_SCROLL_BAR (window)
|
|
1183 and frame_cols = FRAME_COLS (XFRAME (window->frame))
|
165
|
1184
|
51206
|
1185 Or you can let window_box_text_cols do this all for you, and write:
|
|
1186 window_box_text_cols (w) - 1
|
1777
|
1187
|
|
1188 The `-1' accounts for the continuation-line backslashes; the rest
|
5941
|
1189 accounts for window borders if the window is split horizontally, and
|
6400
|
1190 the scroll bars if they are turned on. */
|
165
|
1191
|
|
1192 struct position *
|
11853
|
1193 compute_motion (from, fromvpos, fromhpos, did_motion, to, tovpos, tohpos, width, hscroll, tab_offset, win)
|
84951
|
1194 EMACS_INT from, fromvpos, fromhpos, to, tovpos, tohpos;
|
84952
|
1195 int did_motion;
|
84951
|
1196 EMACS_INT width;
|
|
1197 EMACS_INT hscroll, tab_offset;
|
6691
|
1198 struct window *win;
|
165
|
1199 {
|
84951
|
1200 register EMACS_INT hpos = fromhpos;
|
|
1201 register EMACS_INT vpos = fromvpos;
|
165
|
1202
|
84951
|
1203 register EMACS_INT pos;
|
|
1204 EMACS_INT pos_byte;
|
31829
|
1205 register int c = 0;
|
84951
|
1206 register EMACS_INT tab_width = XFASTINT (current_buffer->tab_width);
|
488
|
1207 register int ctl_arrow = !NILP (current_buffer->ctl_arrow);
|
13185
|
1208 register struct Lisp_Char_Table *dp = window_display_table (win);
|
165
|
1209 int selective
|
9126
e475f8108156
(buffer_display_table, current_column, Fmove_to_column, compute_motion,
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
1210 = (INTEGERP (current_buffer->selective_display)
|
6846
a6803ff29cca
(compute_motion): Do not abort if window shows some other buffer.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1211 ? XINT (current_buffer->selective_display)
|
a6803ff29cca
(compute_motion): Do not abort if window shows some other buffer.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1212 : !NILP (current_buffer->selective_display) ? -1 : 0);
|
165
|
1213 int selective_rlen
|
9126
e475f8108156
(buffer_display_table, current_column, Fmove_to_column, compute_motion,
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
1214 = (selective && dp && VECTORP (DISP_INVIS_VECTOR (dp))
|
2017
|
1215 ? XVECTOR (DISP_INVIS_VECTOR (dp))->size : 0);
|
11853
|
1216 /* The next location where the `invisible' property changes, or an
|
|
1217 overlay starts or ends. */
|
84951
|
1218 EMACS_INT next_boundary = from;
|
165
|
1219
|
9407
|
1220 /* For computing runs of characters with similar widths.
|
|
1221 Invariant: width_run_width is zero, or all the characters
|
10538
|
1222 from width_run_start to width_run_end have a fixed width of
|
9407
|
1223 width_run_width. */
|
84951
|
1224 EMACS_INT width_run_start = from;
|
|
1225 EMACS_INT width_run_end = from;
|
|
1226 EMACS_INT width_run_width = 0;
|
9407
|
1227 Lisp_Object *width_table;
|
10964
|
1228 Lisp_Object buffer;
|
9407
|
1229
|
|
1230 /* The next buffer pos where we should consult the width run cache. */
|
84951
|
1231 EMACS_INT next_width_run = from;
|
15059
|
1232 Lisp_Object window;
|
9407
|
1233
|
17016
|
1234 int multibyte = !NILP (current_buffer->enable_multibyte_characters);
|
21996
|
1235 /* If previous char scanned was a wide character,
|
|
1236 this is the column where it ended. Otherwise, this is 0. */
|
84951
|
1237 EMACS_INT wide_column_end_hpos = 0;
|
|
1238 EMACS_INT prev_pos; /* Previous buffer position. */
|
|
1239 EMACS_INT prev_pos_byte; /* Previous buffer position. */
|
|
1240 EMACS_INT prev_hpos = 0;
|
|
1241 EMACS_INT prev_vpos = 0;
|
|
1242 EMACS_INT contin_hpos; /* HPOS of last column of continued line. */
|
|
1243 EMACS_INT prev_tab_offset; /* Previous tab offset. */
|
|
1244 EMACS_INT continuation_glyph_width;
|
17016
|
1245
|
10964
|
1246 XSETBUFFER (buffer, current_buffer);
|
15059
|
1247 XSETWINDOW (window, win);
|
10964
|
1248
|
9407
|
1249 width_run_cache_on_off ();
|
|
1250 if (dp == buffer_display_table ())
|
|
1251 width_table = (VECTORP (current_buffer->width_table)
|
|
1252 ? XVECTOR (current_buffer->width_table)->contents
|
|
1253 : 0);
|
|
1254 else
|
|
1255 /* If the window has its own display table, we can't use the width
|
|
1256 run cache, because that's based on the buffer's display table. */
|
|
1257 width_table = 0;
|
|
1258
|
28537
|
1259 if (tab_width <= 0 || tab_width > 1000)
|
|
1260 tab_width = 8;
|
|
1261
|
56584
|
1262 /* Negative width means use all available text columns. */
|
|
1263 if (width < 0)
|
|
1264 {
|
|
1265 width = window_box_text_cols (win);
|
|
1266 /* We must make room for continuation marks if we don't have fringes. */
|
|
1267 #ifdef HAVE_WINDOW_SYSTEM
|
|
1268 if (!FRAME_WINDOW_P (XFRAME (win->frame)))
|
|
1269 #endif
|
|
1270 width -= 1;
|
|
1271 }
|
|
1272
|
56594
|
1273 continuation_glyph_width = 1;
|
56593
|
1274 #ifdef HAVE_WINDOW_SYSTEM
|
56594
|
1275 if (FRAME_WINDOW_P (XFRAME (win->frame)))
|
|
1276 continuation_glyph_width = 0; /* In the fringe. */
|
56593
|
1277 #endif
|
|
1278
|
28537
|
1279 immediate_quit = 1;
|
|
1280 QUIT;
|
526
|
1281
|
17016
|
1282 pos = prev_pos = from;
|
20571
|
1283 pos_byte = prev_pos_byte = CHAR_TO_BYTE (from);
|
17016
|
1284 contin_hpos = 0;
|
|
1285 prev_tab_offset = tab_offset;
|
11853
|
1286 while (1)
|
|
1287 {
|
|
1288 while (pos == next_boundary)
|
5085
82bcf2c36929
(compute_motion): Pass new arg to Fnext_single_property_change.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1289 {
|
84951
|
1290 EMACS_INT pos_here = pos;
|
|
1291 EMACS_INT newpos;
|
17966
|
1292
|
22245
|
1293 /* Don't skip invisible if we are already at the margin. */
|
41900
|
1294 if (vpos > tovpos || (vpos == tovpos && hpos >= tohpos))
|
22245
|
1295 {
|
|
1296 if (contin_hpos && prev_hpos == 0
|
|
1297 && hpos > tohpos
|
|
1298 && (contin_hpos == width || wide_column_end_hpos > width))
|
|
1299 { /* Line breaks because we can't put the character at the
|
|
1300 previous line any more. It is not the multi-column
|
|
1301 character continued in middle. Go back to previous
|
|
1302 buffer position, screen position, and set tab offset
|
|
1303 to previous value. It's the beginning of the
|
|
1304 line. */
|
|
1305 pos = prev_pos;
|
|
1306 pos_byte = prev_pos_byte;
|
|
1307 hpos = prev_hpos;
|
54240
|
1308 vpos = prev_vpos;
|
22245
|
1309 tab_offset = prev_tab_offset;
|
|
1310 }
|
|
1311 break;
|
|
1312 }
|
|
1313
|
11853
|
1314 /* If the caller says that the screen position came from an earlier
|
|
1315 call to compute_motion, then we've already accounted for the
|
|
1316 overlay strings at point. This is only true the first time
|
|
1317 through, so clear the flag after testing it. */
|
|
1318 if (!did_motion)
|
|
1319 /* We need to skip past the overlay strings. Currently those
|
17016
|
1320 strings must not contain TAB;
|
11853
|
1321 if we want to relax that restriction, something will have
|
|
1322 to be changed here. */
|
17016
|
1323 {
|
|
1324 unsigned char *ovstr;
|
|
1325 int ovlen = overlay_strings (pos, win, &ovstr);
|
21283
|
1326 hpos += ((multibyte && ovlen > 0)
|
|
1327 ? strwidth (ovstr, ovlen) : ovlen);
|
17016
|
1328 }
|
11853
|
1329 did_motion = 0;
|
10964
|
1330
|
11853
|
1331 if (pos >= to)
|
|
1332 break;
|
10964
|
1333
|
15493
|
1334 /* Advance POS past invisible characters
|
|
1335 (but not necessarily all that there are here),
|
|
1336 and store in next_boundary the next position where
|
|
1337 we need to call skip_invisible. */
|
17966
|
1338 newpos = skip_invisible (pos, &next_boundary, to, window);
|
|
1339
|
|
1340 if (newpos >= to)
|
21919
|
1341 {
|
|
1342 pos = min (to, newpos);
|
33871
|
1343 pos_byte = CHAR_TO_BYTE (pos);
|
21919
|
1344 goto after_loop;
|
|
1345 }
|
17966
|
1346
|
20571
|
1347 if (newpos != pos_here)
|
|
1348 {
|
|
1349 pos = newpos;
|
|
1350 pos_byte = CHAR_TO_BYTE (pos);
|
|
1351 }
|
5085
82bcf2c36929
(compute_motion): Pass new arg to Fnext_single_property_change.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1352 }
|
11853
|
1353
|
|
1354 /* Handle right margin. */
|
17016
|
1355 /* Note on a wide-column character.
|
|
1356
|
|
1357 Characters are classified into the following three categories
|
|
1358 according to the width (columns occupied on screen).
|
|
1359
|
|
1360 (1) single-column character: ex. `a'
|
|
1361 (2) multi-column character: ex. `^A', TAB, `\033'
|
|
1362 (3) wide-column character: ex. Japanese character, Chinese character
|
|
1363 (In the following example, `W_' stands for them.)
|
|
1364
|
|
1365 Multi-column characters can be divided around the right margin,
|
|
1366 but wide-column characters cannot.
|
|
1367
|
|
1368 NOTE:
|
|
1369
|
|
1370 (*) The cursor is placed on the next character after the point.
|
|
1371
|
|
1372 ----------
|
|
1373 abcdefghi\
|
|
1374 j ^---- next after the point
|
|
1375 ^--- next char. after the point.
|
|
1376 ----------
|
|
1377 In case of sigle-column character
|
|
1378
|
|
1379 ----------
|
|
1380 abcdefgh\\
|
|
1381 033 ^---- next after the point, next char. after the point.
|
|
1382 ----------
|
|
1383 In case of multi-column character
|
|
1384
|
|
1385 ----------
|
|
1386 abcdefgh\\
|
|
1387 W_ ^---- next after the point
|
|
1388 ^---- next char. after the point.
|
|
1389 ----------
|
45622
|
1390 In case of wide-column character
|
17016
|
1391
|
|
1392 The problem here is continuation at a wide-column character.
|
|
1393 In this case, the line may shorter less than WIDTH.
|
|
1394 And we find the continuation AFTER it occurs.
|
|
1395
|
|
1396 */
|
|
1397
|
|
1398 if (hpos > width)
|
11853
|
1399 {
|
|
1400 if (hscroll
|
|
1401 || (truncate_partial_width_windows
|
56593
|
1402 && ((width + continuation_glyph_width)
|
|
1403 < FRAME_COLS (XFRAME (WINDOW_FRAME (win)))))
|
11853
|
1404 || !NILP (current_buffer->truncate_lines))
|
|
1405 {
|
20876
|
1406 /* Truncating: skip to newline, unless we are already past
|
|
1407 TO (we need to go back below). */
|
|
1408 if (pos <= to)
|
20571
|
1409 {
|
|
1410 pos = find_before_next_newline (pos, to, 1);
|
|
1411 pos_byte = CHAR_TO_BYTE (pos);
|
20876
|
1412 hpos = width;
|
|
1413 /* If we just skipped next_boundary,
|
|
1414 loop around in the main while
|
|
1415 and handle it. */
|
|
1416 if (pos >= next_boundary)
|
|
1417 next_boundary = pos + 1;
|
|
1418 prev_hpos = width;
|
54240
|
1419 prev_vpos = vpos;
|
20876
|
1420 prev_tab_offset = tab_offset;
|
20571
|
1421 }
|
11853
|
1422 }
|
|
1423 else
|
|
1424 {
|
|
1425 /* Continuing. */
|
17016
|
1426 /* Remember the previous value. */
|
|
1427 prev_tab_offset = tab_offset;
|
|
1428
|
20938
|
1429 if (wide_column_end_hpos > width)
|
17016
|
1430 {
|
|
1431 hpos -= prev_hpos;
|
|
1432 tab_offset += prev_hpos;
|
|
1433 }
|
|
1434 else
|
|
1435 {
|
|
1436 tab_offset += width;
|
|
1437 hpos -= width;
|
|
1438 }
|
|
1439 vpos++;
|
|
1440 contin_hpos = prev_hpos;
|
|
1441 prev_hpos = 0;
|
55311
|
1442 prev_vpos = vpos;
|
11853
|
1443 }
|
|
1444 }
|
|
1445
|
|
1446 /* Stop if past the target buffer position or screen position. */
|
21994
|
1447 if (pos > to)
|
17016
|
1448 {
|
|
1449 /* Go back to the previous position. */
|
|
1450 pos = prev_pos;
|
20571
|
1451 pos_byte = prev_pos_byte;
|
17016
|
1452 hpos = prev_hpos;
|
54240
|
1453 vpos = prev_vpos;
|
17016
|
1454 tab_offset = prev_tab_offset;
|
|
1455
|
|
1456 /* NOTE on contin_hpos, hpos, and prev_hpos.
|
|
1457
|
|
1458 ----------
|
|
1459 abcdefgh\\
|
|
1460 W_ ^---- contin_hpos
|
|
1461 | ^----- hpos
|
|
1462 \---- prev_hpos
|
|
1463 ----------
|
|
1464 */
|
|
1465
|
|
1466 if (contin_hpos && prev_hpos == 0
|
20938
|
1467 && contin_hpos < width && !wide_column_end_hpos)
|
17016
|
1468 {
|
|
1469 /* Line breaking occurs in the middle of multi-column
|
|
1470 character. Go back to previous line. */
|
|
1471 hpos = contin_hpos;
|
|
1472 vpos = vpos - 1;
|
|
1473 }
|
|
1474 break;
|
|
1475 }
|
|
1476
|
41900
|
1477 if (vpos > tovpos || (vpos == tovpos && hpos >= tohpos))
|
21994
|
1478 {
|
|
1479 if (contin_hpos && prev_hpos == 0
|
22000
|
1480 && hpos > tohpos
|
|
1481 && (contin_hpos == width || wide_column_end_hpos > width))
|
21994
|
1482 { /* Line breaks because we can't put the character at the
|
|
1483 previous line any more. It is not the multi-column
|
|
1484 character continued in middle. Go back to previous
|
|
1485 buffer position, screen position, and set tab offset
|
|
1486 to previous value. It's the beginning of the
|
|
1487 line. */
|
|
1488 pos = prev_pos;
|
|
1489 pos_byte = prev_pos_byte;
|
|
1490 hpos = prev_hpos;
|
54240
|
1491 vpos = prev_vpos;
|
21994
|
1492 tab_offset = prev_tab_offset;
|
|
1493 }
|
|
1494 break;
|
|
1495 }
|
17016
|
1496 if (pos == ZV) /* We cannot go beyond ZV. Stop here. */
|
11853
|
1497 break;
|
|
1498
|
|
1499 prev_hpos = hpos;
|
54240
|
1500 prev_vpos = vpos;
|
17016
|
1501 prev_pos = pos;
|
20571
|
1502 prev_pos_byte = pos_byte;
|
20938
|
1503 wide_column_end_hpos = 0;
|
9407
|
1504
|
|
1505 /* Consult the width run cache to see if we can avoid inspecting
|
|
1506 the text character-by-character. */
|
|
1507 if (current_buffer->width_run_cache && pos >= next_width_run)
|
|
1508 {
|
|
1509 int run_end;
|
|
1510 int common_width
|
|
1511 = region_cache_forward (current_buffer,
|
|
1512 current_buffer->width_run_cache,
|
|
1513 pos, &run_end);
|
|
1514
|
|
1515 /* A width of zero means the character's width varies (like
|
|
1516 a tab), is meaningless (like a newline), or we just don't
|
|
1517 want to skip over it for some other reason. */
|
|
1518 if (common_width != 0)
|
|
1519 {
|
|
1520 int run_end_hpos;
|
|
1521
|
|
1522 /* Don't go past the final buffer posn the user
|
|
1523 requested. */
|
|
1524 if (run_end > to)
|
|
1525 run_end = to;
|
|
1526
|
|
1527 run_end_hpos = hpos + (run_end - pos) * common_width;
|
|
1528
|
|
1529 /* Don't go past the final horizontal position the user
|
|
1530 requested. */
|
|
1531 if (vpos == tovpos && run_end_hpos > tohpos)
|
|
1532 {
|
|
1533 run_end = pos + (tohpos - hpos) / common_width;
|
|
1534 run_end_hpos = hpos + (run_end - pos) * common_width;
|
|
1535 }
|
10538
|
1536
|
9407
|
1537 /* Don't go past the margin. */
|
|
1538 if (run_end_hpos >= width)
|
|
1539 {
|
|
1540 run_end = pos + (width - hpos) / common_width;
|
|
1541 run_end_hpos = hpos + (run_end - pos) * common_width;
|
|
1542 }
|
|
1543
|
|
1544 hpos = run_end_hpos;
|
|
1545 if (run_end > pos)
|
|
1546 prev_hpos = hpos - common_width;
|
20571
|
1547 if (pos != run_end)
|
|
1548 {
|
|
1549 pos = run_end;
|
|
1550 pos_byte = CHAR_TO_BYTE (pos);
|
|
1551 }
|
9407
|
1552 }
|
|
1553
|
|
1554 next_width_run = run_end + 1;
|
|
1555 }
|
|
1556
|
|
1557 /* We have to scan the text character-by-character. */
|
165
|
1558 else
|
11853
|
1559 {
|
36846
|
1560 EMACS_INT i, n;
|
|
1561 Lisp_Object charvec;
|
45622
|
1562
|
20571
|
1563 c = FETCH_BYTE (pos_byte);
|
26859
|
1564
|
|
1565 /* Check composition sequence. */
|
|
1566 {
|
|
1567 int len, len_byte, width;
|
|
1568
|
|
1569 if (check_composition (pos, pos_byte, to, &len, &len_byte, &width))
|
|
1570 {
|
|
1571 pos += len;
|
|
1572 pos_byte += len_byte;
|
|
1573 hpos += width;
|
|
1574 continue;
|
|
1575 }
|
|
1576 }
|
|
1577
|
20571
|
1578 pos++, pos_byte++;
|
9407
|
1579
|
11853
|
1580 /* Perhaps add some info to the width_run_cache. */
|
|
1581 if (current_buffer->width_run_cache)
|
|
1582 {
|
|
1583 /* Is this character part of the current run? If so, extend
|
|
1584 the run. */
|
|
1585 if (pos - 1 == width_run_end
|
18109
|
1586 && XFASTINT (width_table[c]) == width_run_width)
|
11853
|
1587 width_run_end = pos;
|
9407
|
1588
|
11853
|
1589 /* The previous run is over, since this is a character at a
|
|
1590 different position, or a different width. */
|
|
1591 else
|
|
1592 {
|
|
1593 /* Have we accumulated a run to put in the cache?
|
|
1594 (Currently, we only cache runs of width == 1). */
|
|
1595 if (width_run_start < width_run_end
|
|
1596 && width_run_width == 1)
|
|
1597 know_region_cache (current_buffer,
|
|
1598 current_buffer->width_run_cache,
|
|
1599 width_run_start, width_run_end);
|
10538
|
1600
|
11853
|
1601 /* Start recording a new width run. */
|
18109
|
1602 width_run_width = XFASTINT (width_table[c]);
|
11853
|
1603 width_run_start = pos - 1;
|
|
1604 width_run_end = pos;
|
|
1605 }
|
|
1606 }
|
9407
|
1607
|
20938
|
1608 if (dp != 0
|
|
1609 && ! (multibyte && BASE_LEADING_CODE_P (c))
|
|
1610 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
|
36846
|
1611 {
|
|
1612 charvec = DISP_CHAR_VECTOR (dp, c);
|
|
1613 n = ASIZE (charvec);
|
|
1614 }
|
|
1615 else
|
|
1616 {
|
|
1617 charvec = Qnil;
|
|
1618 n = 1;
|
|
1619 }
|
|
1620
|
|
1621 for (i = n - 1; i >= 0; --i)
|
11853
|
1622 {
|
36846
|
1623 if (VECTORP (charvec))
|
|
1624 {
|
|
1625 /* This should be handled the same as
|
|
1626 next_element_from_display_vector does it. */
|
|
1627 Lisp_Object entry = AREF (charvec, i);
|
45622
|
1628
|
36846
|
1629 if (INTEGERP (entry)
|
|
1630 && GLYPH_CHAR_VALID_P (XFASTINT (entry)))
|
|
1631 c = FAST_GLYPH_CHAR (XFASTINT (entry));
|
|
1632 else
|
|
1633 c = ' ';
|
|
1634 }
|
45622
|
1635
|
36846
|
1636 if (c >= 040 && c < 0177)
|
|
1637 hpos++;
|
|
1638 else if (c == '\t')
|
|
1639 {
|
|
1640 int tem = ((hpos + tab_offset + hscroll - (hscroll > 0))
|
|
1641 % tab_width);
|
|
1642 if (tem < 0)
|
|
1643 tem += tab_width;
|
|
1644 hpos += tab_width - tem;
|
|
1645 }
|
|
1646 else if (c == '\n')
|
11853
|
1647 {
|
36846
|
1648 if (selective > 0
|
45622
|
1649 && indented_beyond_p (pos, pos_byte,
|
46303
|
1650 (double) selective)) /* iftc */
|
36846
|
1651 {
|
|
1652 /* If (pos == to), we don't have to take care of
|
|
1653 selective display. */
|
|
1654 if (pos < to)
|
|
1655 {
|
|
1656 /* Skip any number of invisible lines all at once */
|
|
1657 do
|
|
1658 {
|
|
1659 pos = find_before_next_newline (pos, to, 1);
|
|
1660 if (pos < to)
|
|
1661 pos++;
|
|
1662 pos_byte = CHAR_TO_BYTE (pos);
|
|
1663 }
|
|
1664 while (pos < to
|
45622
|
1665 && indented_beyond_p (pos, pos_byte,
|
46303
|
1666 (double) selective)); /* iftc */
|
36846
|
1667 /* Allow for the " ..." that is displayed for them. */
|
|
1668 if (selective_rlen)
|
|
1669 {
|
|
1670 hpos += selective_rlen;
|
|
1671 if (hpos >= width)
|
|
1672 hpos = width;
|
|
1673 }
|
|
1674 DEC_BOTH (pos, pos_byte);
|
|
1675 /* We have skipped the invis text, but not the
|
|
1676 newline after. */
|
|
1677 }
|
|
1678 }
|
|
1679 else
|
|
1680 {
|
|
1681 /* A visible line. */
|
|
1682 vpos++;
|
|
1683 hpos = 0;
|
|
1684 hpos -= hscroll;
|
|
1685 /* Count the truncation glyph on column 0 */
|
|
1686 if (hscroll > 0)
|
56593
|
1687 hpos += continuation_glyph_width;
|
36846
|
1688 tab_offset = 0;
|
|
1689 }
|
|
1690 contin_hpos = 0;
|
|
1691 }
|
|
1692 else if (c == CR && selective < 0)
|
|
1693 {
|
|
1694 /* In selective display mode,
|
|
1695 everything from a ^M to the end of the line is invisible.
|
|
1696 Stop *before* the real newline. */
|
17136
|
1697 if (pos < to)
|
11853
|
1698 {
|
36846
|
1699 pos = find_before_next_newline (pos, to, 1);
|
|
1700 pos_byte = CHAR_TO_BYTE (pos);
|
|
1701 }
|
|
1702 /* If we just skipped next_boundary,
|
|
1703 loop around in the main while
|
|
1704 and handle it. */
|
|
1705 if (pos > next_boundary)
|
|
1706 next_boundary = pos;
|
|
1707 /* Allow for the " ..." that is displayed for them. */
|
|
1708 if (selective_rlen)
|
|
1709 {
|
|
1710 hpos += selective_rlen;
|
|
1711 if (hpos >= width)
|
|
1712 hpos = width;
|
11853
|
1713 }
|
|
1714 }
|
36846
|
1715 else if (multibyte && BASE_LEADING_CODE_P (c))
|
|
1716 {
|
|
1717 /* Start of multi-byte form. */
|
|
1718 unsigned char *ptr;
|
|
1719 int bytes, width, wide_column;
|
|
1720
|
|
1721 pos_byte--; /* rewind POS_BYTE */
|
|
1722 ptr = BYTE_POS_ADDR (pos_byte);
|
|
1723 MULTIBYTE_BYTES_WIDTH (ptr, dp);
|
|
1724 pos_byte += bytes;
|
|
1725 if (wide_column)
|
|
1726 wide_column_end_hpos = hpos + wide_column;
|
|
1727 hpos += width;
|
|
1728 }
|
38530
|
1729 else if (VECTORP (charvec))
|
|
1730 ++hpos;
|
11853
|
1731 else
|
36846
|
1732 hpos += (ctl_arrow && c < 0200) ? 2 : 4;
|
11853
|
1733 }
|
165
|
1734 }
|
|
1735 }
|
|
1736
|
17966
|
1737 after_loop:
|
|
1738
|
9407
|
1739 /* Remember any final width run in the cache. */
|
|
1740 if (current_buffer->width_run_cache
|
|
1741 && width_run_width == 1
|
|
1742 && width_run_start < width_run_end)
|
|
1743 know_region_cache (current_buffer, current_buffer->width_run_cache,
|
|
1744 width_run_start, width_run_end);
|
|
1745
|
165
|
1746 val_compute_motion.bufpos = pos;
|
20571
|
1747 val_compute_motion.bytepos = pos_byte;
|
526
|
1748 val_compute_motion.hpos = hpos;
|
|
1749 val_compute_motion.vpos = vpos;
|
20985
|
1750 if (contin_hpos && prev_hpos == 0)
|
|
1751 val_compute_motion.prevhpos = contin_hpos;
|
|
1752 else
|
|
1753 val_compute_motion.prevhpos = prev_hpos;
|
16395
c6b901f809da
(vmotion, compute_motion): Fill in ovstring_chars_done in the return value.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1754 /* We alalways handle all of them here; none of them remain to do. */
|
c6b901f809da
(vmotion, compute_motion): Fill in ovstring_chars_done in the return value.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1755 val_compute_motion.ovstring_chars_done = 0;
|
165
|
1756
|
|
1757 /* Nonzero if have just continued a line */
|
17016
|
1758 val_compute_motion.contin = (contin_hpos && prev_hpos == 0);
|
165
|
1759
|
28537
|
1760 immediate_quit = 0;
|
165
|
1761 return &val_compute_motion;
|
|
1762 }
|
|
1763
|
25028
|
1764
|
40123
|
1765 DEFUN ("compute-motion", Fcompute_motion, Scompute_motion, 7, 7, 0,
|
|
1766 doc: /* Scan through the current buffer, calculating screen position.
|
|
1767 Scan the current buffer forward from offset FROM,
|
|
1768 assuming it is at position FROMPOS--a cons of the form (HPOS . VPOS)--
|
|
1769 to position TO or position TOPOS--another cons of the form (HPOS . VPOS)--
|
|
1770 and return the ending buffer position and screen location.
|
|
1771
|
56584
|
1772 If TOPOS is nil, the actual width and height of the window's
|
|
1773 text area are used.
|
|
1774
|
40123
|
1775 There are three additional arguments:
|
|
1776
|
|
1777 WIDTH is the number of columns available to display text;
|
56584
|
1778 this affects handling of continuation lines. A value of nil
|
|
1779 corresponds to the actual number of available text columns.
|
40123
|
1780
|
|
1781 OFFSETS is either nil or a cons cell (HSCROLL . TAB-OFFSET).
|
|
1782 HSCROLL is the number of columns not being displayed at the left
|
|
1783 margin; this is usually taken from a window's hscroll member.
|
|
1784 TAB-OFFSET is the number of columns of the first tab that aren't
|
|
1785 being displayed, perhaps because the line was continued within it.
|
|
1786 If OFFSETS is nil, HSCROLL and TAB-OFFSET are assumed to be zero.
|
6587
|
1787
|
40123
|
1788 WINDOW is the window to operate on. It is used to choose the display table;
|
|
1789 if it is showing the current buffer, it is used also for
|
|
1790 deciding which overlay properties apply.
|
|
1791 Note that `compute-motion' always operates on the current buffer.
|
|
1792
|
|
1793 The value is a list of five elements:
|
|
1794 (POS HPOS VPOS PREVHPOS CONTIN)
|
|
1795 POS is the buffer position where the scan stopped.
|
|
1796 VPOS is the vertical position where the scan stopped.
|
|
1797 HPOS is the horizontal position where the scan stopped.
|
|
1798
|
|
1799 PREVHPOS is the horizontal position one character back from POS.
|
|
1800 CONTIN is t if a line was continued after (or within) the previous character.
|
|
1801
|
|
1802 For example, to find the buffer position of column COL of line LINE
|
|
1803 of a certain window, pass the window's starting location as FROM
|
|
1804 and the window's upper-left coordinates as FROMPOS.
|
|
1805 Pass the buffer's (point-max) as TO, to limit the scan to the end of the
|
|
1806 visible section of the buffer, and pass LINE and COL as TOPOS. */)
|
|
1807 (from, frompos, to, topos, width, offsets, window)
|
6296
|
1808 Lisp_Object from, frompos, to, topos;
|
6691
|
1809 Lisp_Object width, offsets, window;
|
6296
|
1810 {
|
56584
|
1811 struct window *w;
|
34967
|
1812 Lisp_Object bufpos, hpos, vpos, prevhpos;
|
6296
|
1813 struct position *pos;
|
|
1814 int hscroll, tab_offset;
|
|
1815
|
40656
|
1816 CHECK_NUMBER_COERCE_MARKER (from);
|
|
1817 CHECK_CONS (frompos);
|
|
1818 CHECK_NUMBER_CAR (frompos);
|
|
1819 CHECK_NUMBER_CDR (frompos);
|
|
1820 CHECK_NUMBER_COERCE_MARKER (to);
|
56584
|
1821 if (!NILP (topos))
|
|
1822 {
|
|
1823 CHECK_CONS (topos);
|
|
1824 CHECK_NUMBER_CAR (topos);
|
|
1825 CHECK_NUMBER_CDR (topos);
|
|
1826 }
|
|
1827 if (!NILP (width))
|
|
1828 CHECK_NUMBER (width);
|
|
1829
|
6296
|
1830 if (!NILP (offsets))
|
|
1831 {
|
40656
|
1832 CHECK_CONS (offsets);
|
|
1833 CHECK_NUMBER_CAR (offsets);
|
|
1834 CHECK_NUMBER_CDR (offsets);
|
25645
|
1835 hscroll = XINT (XCAR (offsets));
|
|
1836 tab_offset = XINT (XCDR (offsets));
|
6296
|
1837 }
|
|
1838 else
|
|
1839 hscroll = tab_offset = 0;
|
|
1840
|
6691
|
1841 if (NILP (window))
|
|
1842 window = Fselected_window ();
|
|
1843 else
|
40656
|
1844 CHECK_LIVE_WINDOW (window);
|
56584
|
1845 w = XWINDOW (window);
|
6691
|
1846
|
21496
|
1847 if (XINT (from) < BEGV || XINT (from) > ZV)
|
|
1848 args_out_of_range_3 (from, make_number (BEGV), make_number (ZV));
|
|
1849 if (XINT (to) < BEGV || XINT (to) > ZV)
|
|
1850 args_out_of_range_3 (to, make_number (BEGV), make_number (ZV));
|
|
1851
|
25645
|
1852 pos = compute_motion (XINT (from), XINT (XCDR (frompos)),
|
|
1853 XINT (XCAR (frompos)), 0,
|
56584
|
1854 XINT (to),
|
|
1855 (NILP (topos)
|
|
1856 ? window_internal_height (w)
|
|
1857 : XINT (XCDR (topos))),
|
|
1858 (NILP (topos)
|
|
1859 ? (window_box_text_cols (w)
|
|
1860 - (
|
|
1861 #ifdef HAVE_WINDOW_SYSTEM
|
|
1862 FRAME_WINDOW_P (XFRAME (w->frame)) ? 0 :
|
|
1863 #endif
|
|
1864 1))
|
|
1865 : XINT (XCAR (topos))),
|
|
1866 (NILP (width) ? -1 : XINT (width)),
|
|
1867 hscroll, tab_offset,
|
6691
|
1868 XWINDOW (window));
|
6296
|
1869
|
9310
|
1870 XSETFASTINT (bufpos, pos->bufpos);
|
9269
0f29bb3f784f
(Fcompute_motion): Use new accessor macros instead of calling XSET directly.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
1871 XSETINT (hpos, pos->hpos);
|
0f29bb3f784f
(Fcompute_motion): Use new accessor macros instead of calling XSET directly.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
1872 XSETINT (vpos, pos->vpos);
|
0f29bb3f784f
(Fcompute_motion): Use new accessor macros instead of calling XSET directly.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
1873 XSETINT (prevhpos, pos->prevhpos);
|
6296
|
1874
|
|
1875 return Fcons (bufpos,
|
|
1876 Fcons (hpos,
|
|
1877 Fcons (vpos,
|
|
1878 Fcons (prevhpos,
|
|
1879 Fcons (pos->contin ? Qt : Qnil, Qnil)))));
|
|
1880
|
|
1881 }
|
165
|
1882
|
9407
|
1883 /* Fvertical_motion and vmotion */
|
36846
|
1884
|
165
|
1885 struct position val_vmotion;
|
|
1886
|
|
1887 struct position *
|
11811
|
1888 vmotion (from, vtarget, w)
|
84951
|
1889 register EMACS_INT from, vtarget;
|
11811
|
1890 struct window *w;
|
165
|
1891 {
|
84951
|
1892 EMACS_INT hscroll = XINT (w->hscroll);
|
165
|
1893 struct position pos;
|
|
1894 /* vpos is cumulative vertical position, changed as from is changed */
|
|
1895 register int vpos = 0;
|
84951
|
1896 EMACS_INT prevline;
|
|
1897 register EMACS_INT first;
|
|
1898 EMACS_INT from_byte;
|
|
1899 EMACS_INT lmargin = hscroll > 0 ? 1 - hscroll : 0;
|
165
|
1900 int selective
|
9126
e475f8108156
(buffer_display_table, current_column, Fmove_to_column, compute_motion,
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
1901 = (INTEGERP (current_buffer->selective_display)
|
e475f8108156
(buffer_display_table, current_column, Fmove_to_column, compute_motion,
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
1902 ? XINT (current_buffer->selective_display)
|
e475f8108156
(buffer_display_table, current_column, Fmove_to_column, compute_motion,
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
1903 : !NILP (current_buffer->selective_display) ? -1 : 0);
|
11811
|
1904 Lisp_Object window;
|
84951
|
1905 EMACS_INT start_hpos = 0;
|
11853
|
1906 int did_motion;
|
23039
|
1907 /* This is the object we use for fetching character properties. */
|
|
1908 Lisp_Object text_prop_object;
|
11811
|
1909
|
|
1910 XSETWINDOW (window, w);
|
|
1911
|
23039
|
1912 /* If the window contains this buffer, use it for getting text properties.
|
|
1913 Otherwise use the current buffer as arg for doing that. */
|
|
1914 if (EQ (w->buffer, Fcurrent_buffer ()))
|
|
1915 text_prop_object = window;
|
|
1916 else
|
|
1917 text_prop_object = Fcurrent_buffer ();
|
|
1918
|
11811
|
1919 if (vpos >= vtarget)
|
165
|
1920 {
|
11811
|
1921 /* To move upward, go a line at a time until
|
20571
|
1922 we have gone at least far enough. */
|
11811
|
1923
|
|
1924 first = 1;
|
|
1925
|
|
1926 while ((vpos > vtarget || first) && from > BEGV)
|
165
|
1927 {
|
10964
|
1928 Lisp_Object propval;
|
|
1929
|
57734
|
1930 prevline = find_next_newline_no_quit (from - 1, -1);
|
|
1931 while (prevline > BEGV
|
4385
|
1932 && ((selective > 0
|
57734
|
1933 && indented_beyond_p (prevline,
|
|
1934 CHAR_TO_BYTE (prevline),
|
46303
|
1935 (double) selective)) /* iftc */
|
57734
|
1936 /* Watch out for newlines with `invisible' property.
|
|
1937 When moving upward, check the newline before. */
|
|
1938 || (propval = Fget_char_property (make_number (prevline - 1),
|
10964
|
1939 Qinvisible,
|
23039
|
1940 text_prop_object),
|
26404
|
1941 TEXT_PROP_MEANS_INVISIBLE (propval))))
|
57734
|
1942 prevline = find_next_newline_no_quit (prevline - 1, -1);
|
|
1943 pos = *compute_motion (prevline, 0,
|
|
1944 lmargin + (prevline == BEG ? start_hpos : 0),
|
11853
|
1945 0,
|
45622
|
1946 from,
|
17016
|
1947 /* Don't care for VPOS... */
|
|
1948 1 << (BITS_PER_SHORT - 1),
|
|
1949 /* ... nor HPOS. */
|
|
1950 1 << (BITS_PER_SHORT - 1),
|
56584
|
1951 -1, hscroll,
|
16926
3baea3418dec
(pos_tab_offset): Take the width of the minibuffer prompt into account.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1952 /* This compensates for start_hpos
|
3baea3418dec
(pos_tab_offset): Take the width of the minibuffer prompt into account.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1953 so that a tab as first character
|
3baea3418dec
(pos_tab_offset): Take the width of the minibuffer prompt into account.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1954 still occupies 8 columns. */
|
57734
|
1955 (prevline == BEG ? -start_hpos : 0),
|
16926
3baea3418dec
(pos_tab_offset): Take the width of the minibuffer prompt into account.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1956 w);
|
11811
|
1957 vpos -= pos.vpos;
|
|
1958 first = 0;
|
57734
|
1959 from = prevline;
|
165
|
1960 }
|
|
1961
|
11811
|
1962 /* If we made exactly the desired vertical distance,
|
|
1963 or if we hit beginning of buffer,
|
|
1964 return point found */
|
|
1965 if (vpos >= vtarget)
|
|
1966 {
|
|
1967 val_vmotion.bufpos = from;
|
20571
|
1968 val_vmotion.bytepos = CHAR_TO_BYTE (from);
|
11811
|
1969 val_vmotion.vpos = vpos;
|
|
1970 val_vmotion.hpos = lmargin;
|
|
1971 val_vmotion.contin = 0;
|
|
1972 val_vmotion.prevhpos = 0;
|
16395
c6b901f809da
(vmotion, compute_motion): Fill in ovstring_chars_done in the return value.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1973 val_vmotion.ovstring_chars_done = 0;
|
17016
|
1974 val_vmotion.tab_offset = 0; /* For accumulating tab offset. */
|
11811
|
1975 return &val_vmotion;
|
|
1976 }
|
165
|
1977
|
11811
|
1978 /* Otherwise find the correct spot by moving down */
|
|
1979 }
|
|
1980 /* Moving downward is simple, but must calculate from beg of line
|
|
1981 to determine hpos of starting point */
|
20571
|
1982 from_byte = CHAR_TO_BYTE (from);
|
|
1983 if (from > BEGV && FETCH_BYTE (from_byte - 1) != '\n')
|
165
|
1984 {
|
11853
|
1985 Lisp_Object propval;
|
10964
|
1986
|
57734
|
1987 prevline = find_next_newline_no_quit (from, -1);
|
|
1988 while (prevline > BEGV
|
11811
|
1989 && ((selective > 0
|
57734
|
1990 && indented_beyond_p (prevline,
|
|
1991 CHAR_TO_BYTE (prevline),
|
46303
|
1992 (double) selective)) /* iftc */
|
57734
|
1993 /* Watch out for newlines with `invisible' property.
|
|
1994 When moving downward, check the newline after. */
|
|
1995 || (propval = Fget_char_property (make_number (prevline),
|
|
1996 Qinvisible,
|
23039
|
1997 text_prop_object),
|
26404
|
1998 TEXT_PROP_MEANS_INVISIBLE (propval))))
|
57734
|
1999 prevline = find_next_newline_no_quit (prevline - 1, -1);
|
|
2000 pos = *compute_motion (prevline, 0,
|
|
2001 lmargin + (prevline == BEG
|
8905
|
2002 ? start_hpos : 0),
|
11853
|
2003 0,
|
45622
|
2004 from,
|
17016
|
2005 /* Don't care for VPOS... */
|
|
2006 1 << (BITS_PER_SHORT - 1),
|
|
2007 /* ... nor HPOS. */
|
|
2008 1 << (BITS_PER_SHORT - 1),
|
56584
|
2009 -1, hscroll,
|
57734
|
2010 (prevline == BEG ? -start_hpos : 0),
|
16926
3baea3418dec
(pos_tab_offset): Take the width of the minibuffer prompt into account.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2011 w);
|
11853
|
2012 did_motion = 1;
|
165
|
2013 }
|
11811
|
2014 else
|
165
|
2015 {
|
11811
|
2016 pos.hpos = lmargin + (from == BEG ? start_hpos : 0);
|
|
2017 pos.vpos = 0;
|
17016
|
2018 pos.tab_offset = 0;
|
11853
|
2019 did_motion = 0;
|
165
|
2020 }
|
11853
|
2021 return compute_motion (from, vpos, pos.hpos, did_motion,
|
17016
|
2022 ZV, vtarget, - (1 << (BITS_PER_SHORT - 1)),
|
56584
|
2023 -1, hscroll,
|
17016
|
2024 pos.tab_offset - (from == BEG ? start_hpos : 0),
|
16926
3baea3418dec
(pos_tab_offset): Take the width of the minibuffer prompt into account.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2025 w);
|
165
|
2026 }
|
|
2027
|
6327
|
2028 DEFUN ("vertical-motion", Fvertical_motion, Svertical_motion, 1, 2, 0,
|
40123
|
2029 doc: /* Move point to start of the screen line LINES lines down.
|
|
2030 If LINES is negative, this means moving up.
|
|
2031
|
|
2032 This function is an ordinary cursor motion function
|
|
2033 which calculates the new position based on how text would be displayed.
|
|
2034 The new position may be the start of a line,
|
|
2035 or just the start of a continuation line.
|
|
2036 The function returns number of screen lines moved over;
|
|
2037 that usually equals LINES, but may be closer to zero
|
|
2038 if beginning or end of buffer was reached.
|
|
2039
|
|
2040 The optional second argument WINDOW specifies the window to use for
|
|
2041 parameters such as width, horizontal scrolling, and so on.
|
|
2042 The default is to use the selected window's parameters.
|
|
2043
|
|
2044 `vertical-motion' always uses the current buffer,
|
|
2045 regardless of which buffer is displayed in WINDOW.
|
|
2046 This is consistent with other cursor motion functions
|
|
2047 and makes it possible to use `vertical-motion' in any buffer,
|
|
2048 whether or not it is currently displayed in some window. */)
|
|
2049 (lines, window)
|
6327
|
2050 Lisp_Object lines, window;
|
165
|
2051 {
|
25028
|
2052 struct it it;
|
|
2053 struct text_pos pt;
|
|
2054 struct window *w;
|
28293
|
2055 Lisp_Object old_buffer;
|
|
2056 struct gcpro gcpro1;
|
165
|
2057
|
40656
|
2058 CHECK_NUMBER (lines);
|
6327
|
2059 if (! NILP (window))
|
40656
|
2060 CHECK_WINDOW (window);
|
6327
|
2061 else
|
8905
|
2062 window = selected_window;
|
28293
|
2063 w = XWINDOW (window);
|
165
|
2064
|
28293
|
2065 old_buffer = Qnil;
|
|
2066 GCPRO1 (old_buffer);
|
|
2067 if (XBUFFER (w->buffer) != current_buffer)
|
25028
|
2068 {
|
28293
|
2069 /* Set the window's buffer temporarily to the current buffer. */
|
|
2070 old_buffer = w->buffer;
|
|
2071 XSETBUFFER (w->buffer, current_buffer);
|
25028
|
2072 }
|
45622
|
2073
|
58270
|
2074 if (noninteractive)
|
58260
|
2075 {
|
58270
|
2076 struct position pos;
|
|
2077 pos = *vmotion (PT, XINT (lines), w);
|
|
2078 SET_PT_BOTH (pos.bufpos, pos.bytepos);
|
58260
|
2079 }
|
|
2080 else
|
58270
|
2081 {
|
58396
|
2082 int it_start;
|
59647
|
2083 int oselective;
|
75105
|
2084 int it_overshoot_expected;
|
58396
|
2085
|
58270
|
2086 SET_TEXT_POS (pt, PT, PT_BYTE);
|
|
2087 start_display (&it, w, pt);
|
44837
|
2088
|
58270
|
2089 /* Scan from the start of the line containing PT. If we don't
|
|
2090 do this, we start moving with IT->current_x == 0, while PT is
|
|
2091 really at some x > 0. The effect is, in continuation lines, that
|
|
2092 we end up with the iterator placed at where it thinks X is 0,
|
|
2093 while the end position is really at some X > 0, the same X that
|
|
2094 PT had. */
|
58396
|
2095 it_start = IT_CHARPOS (it);
|
73140
c85ee72ad64b
* indent.c (Fvertical_motion): Do move back if the Lisp string
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
2096
|
c85ee72ad64b
* indent.c (Fvertical_motion): Do move back if the Lisp string
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
2097 /* We expect the call to move_it_to, further down, to overshoot
|
74091
|
2098 if the starting point is on an image, stretch glyph,
|
|
2099 composition, or Lisp string. We won't need to backtrack in
|
|
2100 this situation, except for one corner case: when the Lisp
|
|
2101 string contains a newline. */
|
73140
c85ee72ad64b
* indent.c (Fvertical_motion): Do move back if the Lisp string
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
2102 if (it.method == GET_FROM_STRING)
|
c85ee72ad64b
* indent.c (Fvertical_motion): Do move back if the Lisp string
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
2103 {
|
c85ee72ad64b
* indent.c (Fvertical_motion): Do move back if the Lisp string
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
2104 const char *s = SDATA (it.string);
|
c85ee72ad64b
* indent.c (Fvertical_motion): Do move back if the Lisp string
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
2105 const char *e = s + SBYTES (it.string);
|
c85ee72ad64b
* indent.c (Fvertical_motion): Do move back if the Lisp string
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
2106
|
c85ee72ad64b
* indent.c (Fvertical_motion): Do move back if the Lisp string
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
2107 while (s < e && *s != '\n')
|
c85ee72ad64b
* indent.c (Fvertical_motion): Do move back if the Lisp string
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
2108 ++s;
|
c85ee72ad64b
* indent.c (Fvertical_motion): Do move back if the Lisp string
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
2109
|
75105
|
2110 /* If there is no newline in the string, we need to check
|
|
2111 whether there is a newline immediately after the string
|
|
2112 in move_it_to below. This may happen if there is an
|
|
2113 overlay with an after-string just before the newline. */
|
|
2114 it_overshoot_expected = (s == e) ? -1 : 0;
|
73140
c85ee72ad64b
* indent.c (Fvertical_motion): Do move back if the Lisp string
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
2115 }
|
c85ee72ad64b
* indent.c (Fvertical_motion): Do move back if the Lisp string
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
2116 else
|
75105
|
2117 it_overshoot_expected = (it.method == GET_FROM_IMAGE
|
|
2118 || it.method == GET_FROM_STRETCH
|
|
2119 || it.method == GET_FROM_COMPOSITION);
|
73140
c85ee72ad64b
* indent.c (Fvertical_motion): Do move back if the Lisp string
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
2120
|
58308
|
2121 reseat_at_previous_visible_line_start (&it);
|
|
2122 it.current_x = it.hpos = 0;
|
59647
|
2123 /* Temporarily disable selective display so we don't move too far */
|
|
2124 oselective = it.selective;
|
|
2125 it.selective = 0;
|
58308
|
2126 move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
|
59647
|
2127 it.selective = oselective;
|
45622
|
2128
|
58308
|
2129 /* Move back if we got too far. This may happen if
|
64282
|
2130 truncate-lines is on and PT is beyond right margin.
|
73140
c85ee72ad64b
* indent.c (Fvertical_motion): Do move back if the Lisp string
Chong Yidong <cyd@stupidchicken.com>
diff
changeset
|
2131 Don't go back if the overshoot is expected (see above). */
|
67421
|
2132 if (IT_CHARPOS (it) > it_start && XINT (lines) > 0
|
75105
|
2133 && (!it_overshoot_expected
|
|
2134 || (it_overshoot_expected < 0
|
|
2135 && it.method == GET_FROM_BUFFER
|
|
2136 && it.c == '\n')))
|
58308
|
2137 move_it_by_lines (&it, -1, 0);
|
|
2138
|
|
2139 it.vpos = 0;
|
58909
|
2140 /* Do this even if LINES is 0, so that we move back
|
|
2141 to the beginning of the current line as we ought. */
|
69103
|
2142 if (XINT (lines) >= 0 || IT_CHARPOS (it) > 0)
|
|
2143 move_it_by_lines (&it, XINT (lines), 0);
|
58270
|
2144
|
|
2145 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
|
|
2146 }
|
165
|
2147
|
28293
|
2148 if (BUFFERP (old_buffer))
|
|
2149 w->buffer = old_buffer;
|
45622
|
2150
|
28293
|
2151 RETURN_UNGCPRO (make_number (it.vpos));
|
165
|
2152 }
|
25028
|
2153
|
|
2154
|
165
|
2155
|
36846
|
2156 /* File's initialization. */
|
9407
|
2157
|
21514
|
2158 void
|
165
|
2159 syms_of_indent ()
|
|
2160 {
|
|
2161 DEFVAR_BOOL ("indent-tabs-mode", &indent_tabs_mode,
|
85128
8b61a2e5e365
(indent_tabs_mode, last_known_column, last_known_column_modified): Make static.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
2162 doc: /* *Indentation can insert tabs if this is non-nil. */);
|
165
|
2163 indent_tabs_mode = 1;
|
|
2164
|
|
2165 defsubr (&Scurrent_indentation);
|
|
2166 defsubr (&Sindent_to);
|
|
2167 defsubr (&Scurrent_column);
|
|
2168 defsubr (&Smove_to_column);
|
|
2169 defsubr (&Svertical_motion);
|
6296
|
2170 defsubr (&Scompute_motion);
|
165
|
2171 }
|
52401
|
2172
|
|
2173 /* arch-tag: 9adfea44-71f7-4988-8ee3-96da15c502cc
|
|
2174 (do not change this comment) */
|