Merge from emacs--devo--0
[bpt/emacs.git] / src / indent.c
1 /* Indentation functions.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1998, 2000, 2001,
3 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
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
9 the Free Software Foundation; either version 3, or (at your option)
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
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
21
22 #include <config.h>
23 #include <stdio.h>
24
25 #include "lisp.h"
26 #include "buffer.h"
27 #include "character.h"
28 #include "category.h"
29 #include "indent.h"
30 #include "keyboard.h"
31 #include "frame.h"
32 #include "window.h"
33 #include "termchar.h"
34 #include "termopts.h"
35 #include "disptab.h"
36 #include "intervals.h"
37 #include "region-cache.h"
38
39 /* Indentation can insert tabs if this is non-zero;
40 otherwise always uses spaces. */
41
42 static int indent_tabs_mode;
43
44 #define CR 015
45
46 /* These three values memorize the current column to avoid recalculation. */
47
48 /* Last value returned by current_column.
49 Some things in set last_known_column_point to -1
50 to mark the memorized value as invalid. */
51
52 static double last_known_column;
53
54 /* Value of point when current_column was called. */
55
56 EMACS_INT last_known_column_point;
57
58 /* Value of MODIFF when current_column was called. */
59
60 static int last_known_column_modified;
61
62 static double current_column_1 P_ ((void));
63 static double position_indentation P_ ((int));
64
65 /* Cache of beginning of line found by the last call of
66 current_column. */
67
68 static EMACS_INT current_column_bol_cache;
69
70 /* Get the display table to use for the current buffer. */
71
72 struct Lisp_Char_Table *
73 buffer_display_table ()
74 {
75 Lisp_Object thisbuf;
76
77 thisbuf = current_buffer->display_table;
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);
82 return 0;
83 }
84 \f
85 /* Width run cache considerations. */
86
87 /* Return the width of character C under display table DP. */
88
89 static int
90 character_width (c, dp)
91 int c;
92 struct Lisp_Char_Table *dp;
93 {
94 Lisp_Object elt;
95
96 /* These width computations were determined by examining the cases
97 in display_text_line. */
98
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. */
105 if (c == '\n' || c == '\t' || c == '\015')
106 return 0;
107
108 /* Printing characters have width 1. */
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
121 /* Return true if the display table DISPTAB specifies the same widths
122 for characters as WIDTHTAB. We use this to decide when to
123 invalidate the buffer's width_run_cache. */
124
125 int
126 disptab_matches_widthtab (disptab, widthtab)
127 struct Lisp_Char_Table *disptab;
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;
141 }
142
143 /* Recompute BUF's width table, using the display table DISPTAB. */
144
145 void
146 recompute_width_table (buf, disptab)
147 struct buffer *buf;
148 struct Lisp_Char_Table *disptab;
149 {
150 int i;
151 struct Lisp_Vector *widthtab;
152
153 if (!VECTORP (buf->width_table))
154 buf->width_table = Fmake_vector (make_number (256), make_number (0));
155 widthtab = XVECTOR (buf->width_table);
156 if (widthtab->size != 256)
157 abort ();
158
159 for (i = 0; i < 256; i++)
160 XSETFASTINT (widthtab->contents[i], character_width (i, disptab));
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. */
165
166 static void
167 width_run_cache_on_off ()
168 {
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))
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)
186 {
187 current_buffer->width_run_cache = new_region_cache ();
188 recompute_width_table (current_buffer, buffer_display_table ());
189 }
190 }
191 }
192
193 \f
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
217 EMACS_INT
218 skip_invisible (pos, next_boundary_p, to, window)
219 EMACS_INT pos;
220 EMACS_INT *next_boundary_p;
221 EMACS_INT to;
222 Lisp_Object window;
223 {
224 Lisp_Object prop, position, overlay_limit, proplimit;
225 Lisp_Object buffer, tmp;
226 EMACS_INT end;
227 int inv_p;
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;
257 tmp = Fnext_single_property_change (position, Qinvisible,
258 buffer, proplimit);
259 end = XFASTINT (tmp);
260 #if 0
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--;
268 #endif
269 *next_boundary_p = end;
270 }
271 /* if the `invisible' property is set, we can skip to
272 the next property change */
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)
280 return *next_boundary_p;
281 return pos;
282 }
283 \f
284 /* If a composition starts at POS/POS_BYTE and it doesn't stride over
285 POINT, set *LEN / *LEN_BYTE to the character and byte lengths, *WIDTH
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 EMACS_INT start, end;
295 int id;
296
297 if (! find_composition (pos, -1, &start, &end, &prop, Qnil)
298 || pos != start || point < end
299 || !COMPOSITION_VALID_P (start, end, prop))
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 \f
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
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 = CHAR_WIDTH (c); \
331 if (width > 1) \
332 wide_column = width; \
333 } \
334 } while (0)
335
336
337 DEFUN ("current-column", Fcurrent_column, Scurrent_column, 0, 0, 0,
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
341 and point (eg. control characters will have a width of 2 or 4, tabs
342 will have a variable width).
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;
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. */)
349 ()
350 {
351 Lisp_Object temp;
352 XSETFASTINT (temp, (int) current_column ()); /* iftc */
353 return temp;
354 }
355
356 /* Cancel any recorded value of the horizontal position. */
357
358 void
359 invalidate_current_column ()
360 {
361 last_known_column_point = 0;
362 }
363
364 double
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);
373 int ctl_arrow = !NILP (current_buffer->ctl_arrow);
374 register struct Lisp_Char_Table *dp = buffer_display_table ();
375
376 if (PT == last_known_column_point
377 && MODIFF == last_known_column_modified)
378 return last_known_column;
379
380 /* If the buffer has overlays, text properties,
381 or multibyte characters, use a more general algorithm. */
382 if (BUF_INTERVALS (current_buffer)
383 || current_buffer->overlays_before
384 || current_buffer->overlays_after
385 || Z != Z_BYTE)
386 return current_column_1 ();
387
388 /* Scan backwards from point to the previous newline,
389 counting width. Tab characters are the only complicated case. */
390
391 /* Make a pointer for decrementing through the chars before point. */
392 ptr = BYTE_POS_ADDR (PT_BYTE - 1) + 1;
393 /* Make a pointer to where consecutive chars leave off,
394 going backwards from point. */
395 if (PT == BEGV)
396 stop = ptr;
397 else if (PT <= GPT || BEGV > GPT)
398 stop = BEGV_ADDR;
399 else
400 stop = GAP_END_ADDR;
401
402 if (tab_width <= 0 || tab_width > 1000)
403 tab_width = 8;
404
405 col = 0, tab_seen = 0, post_tab = 0;
406
407 while (1)
408 {
409 EMACS_INT i, n;
410 Lisp_Object charvec;
411
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;
418
419 /* It was the gap. Jump back over it. */
420 stop = BEGV_ADDR;
421 ptr = GPT_ADDR;
422
423 /* Check whether that brings us to beginning of buffer. */
424 if (BEGV >= GPT)
425 break;
426 }
427
428 c = *--ptr;
429
430 if (dp && VECTORP (DISP_CHAR_VECTOR (dp, c)))
431 {
432 charvec = DISP_CHAR_VECTOR (dp, c);
433 n = ASIZE (charvec);
434 }
435 else
436 {
437 charvec = Qnil;
438 n = 1;
439 }
440
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);
448
449 if (INTEGERP (entry)
450 && GLYPH_CHAR_VALID_P (XFASTINT (entry)))
451 c = FAST_GLYPH_CHAR (XFASTINT (entry));
452 else
453 c = ' ';
454 }
455
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;
469
470 post_tab += col;
471 col = 0;
472 tab_seen = 1;
473 }
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;
481 else
482 col += (ctl_arrow && c < 0200) ? 2 : 4;
483 }
484 }
485
486 start_of_line_found:
487
488 if (tab_seen)
489 {
490 col = ((col + tab_width) / tab_width) * tab_width;
491 col += post_tab;
492 }
493
494 if (ptr == BEGV_ADDR)
495 current_column_bol_cache = BEGV;
496 else
497 current_column_bol_cache = BYTE_TO_CHAR (PTR_BYTE_POS (ptr));
498
499 last_known_column = col;
500 last_known_column_point = PT;
501 last_known_column_modified = MODIFF;
502
503 return col;
504 }
505 \f
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
511 static double
512 current_column_1 ()
513 {
514 register EMACS_INT tab_width = XINT (current_buffer->tab_width);
515 register int ctl_arrow = !NILP (current_buffer->ctl_arrow);
516 register struct Lisp_Char_Table *dp = buffer_display_table ();
517 int multibyte = !NILP (current_buffer->enable_multibyte_characters);
518
519 /* Start the scan at the beginning of this line with column number 0. */
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;
524
525 scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, 1);
526 current_column_bol_cache = PT;
527 scan = PT, scan_byte = PT_BYTE;
528 SET_PT_BOTH (opoint, opoint_byte);
529 next_boundary = scan;
530
531 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
532
533 /* Scan forward to the target position. */
534 while (scan < opoint)
535 {
536 int c;
537
538 /* Occasionally we may need to skip invisible text. */
539 while (scan == next_boundary)
540 {
541 int old_scan = scan;
542 /* This updates NEXT_BOUNDARY to the next place
543 where we might need to skip more invisible text. */
544 scan = skip_invisible (scan, &next_boundary, opoint, Qnil);
545 if (scan >= opoint)
546 goto endloop;
547 if (scan != old_scan)
548 scan_byte = CHAR_TO_BYTE (scan);
549 }
550
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
566 c = FETCH_BYTE (scan_byte);
567
568 if (dp != 0
569 && ! (multibyte && BASE_LEADING_CODE_P (c))
570 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
571 {
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
578 charvec = DISP_CHAR_VECTOR (dp, c);
579 n = ASIZE (charvec);
580
581 for (i = 0; i < n; i++)
582 {
583 /* This should be handled the same as
584 next_element_from_display_vector does it. */
585 Lisp_Object entry;
586 entry = AREF (charvec, i);
587
588 if (INTEGERP (entry)
589 && GLYPH_CHAR_VALID_P (XFASTINT (entry)))
590 c = FAST_GLYPH_CHAR (XFASTINT (entry));
591 else
592 c = ' ';
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;
605 }
606 }
607 else
608 {
609 /* The display table says nothing for this character.
610 Display it as itself. */
611
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;
625
626 ptr = BYTE_POS_ADDR (scan_byte);
627 MULTIBYTE_BYTES_WIDTH (ptr, dp);
628 scan_byte += bytes;
629 /* Subtract one to compensate for the increment
630 that is going to happen below. */
631 scan_byte--;
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++;
640 }
641 scan++;
642 scan_byte++;
643
644 }
645 endloop:
646
647 last_known_column = col;
648 last_known_column_point = PT;
649 last_known_column_modified = MODIFF;
650
651 return col;
652 }
653 \f
654
655 #if 0 /* Not used. */
656
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
661 static double
662 string_display_width (string, beg, end)
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);
672 register struct Lisp_Char_Table *dp = buffer_display_table ();
673 int b, e;
674
675 if (NILP (end))
676 e = SCHARS (string);
677 else
678 {
679 CHECK_NUMBER (end);
680 e = XINT (end);
681 }
682
683 if (NILP (beg))
684 b = 0;
685 else
686 {
687 CHECK_NUMBER (beg);
688 b = XINT (beg);
689 }
690
691 /* Make a pointer for decrementing through the chars before point. */
692 ptr = SDATA (string) + e;
693 /* Make a pointer to where consecutive chars leave off,
694 going backwards from point. */
695 stop = SDATA (string) + b;
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 }
734
735 #endif /* 0 */
736
737 \f
738 DEFUN ("indent-to", Findent_to, Sindent_to, 1, 2, "NIndent to column: ",
739 doc: /* Indent from point with tabs and spaces until COLUMN is reached.
740 Optional second argument MINIMUM says always do at least MINIMUM spaces
741 even if that goes past COLUMN; by default, MINIMUM is zero.
742
743 The return value is COLUMN. */)
744 (column, minimum)
745 Lisp_Object column, minimum;
746 {
747 int mincol;
748 register int fromcol;
749 register int tab_width = XINT (current_buffer->tab_width);
750
751 CHECK_NUMBER (column);
752 if (NILP (minimum))
753 XSETFASTINT (minimum, 0);
754 CHECK_NUMBER (minimum);
755
756 fromcol = current_column ();
757 mincol = fromcol + XINT (minimum);
758 if (mincol < XINT (column)) mincol = XINT (column);
759
760 if (fromcol == mincol)
761 return make_number (mincol);
762
763 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
764
765 if (indent_tabs_mode)
766 {
767 Lisp_Object n;
768 XSETFASTINT (n, mincol / tab_width - fromcol / tab_width);
769 if (XFASTINT (n) != 0)
770 {
771 Finsert_char (make_number ('\t'), n, Qt);
772
773 fromcol = (mincol / tab_width) * tab_width;
774 }
775 }
776
777 XSETFASTINT (column, mincol - fromcol);
778 Finsert_char (make_number (' '), column, Qt);
779
780 last_known_column = mincol;
781 last_known_column_point = PT;
782 last_known_column_modified = MODIFF;
783
784 XSETINT (column, mincol);
785 return column;
786 }
787
788 \f
789 static double position_indentation P_ ((int));
790
791 DEFUN ("current-indentation", Fcurrent_indentation, Scurrent_indentation,
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 ()
797 {
798 Lisp_Object val;
799 int opoint = PT, opoint_byte = PT_BYTE;
800
801 scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, 1);
802
803 XSETFASTINT (val, (int) position_indentation (PT_BYTE)); /* iftc */
804 SET_PT_BOTH (opoint, opoint_byte);
805 return val;
806 }
807
808 static double
809 position_indentation (pos_byte)
810 register int pos_byte;
811 {
812 register EMACS_INT column = 0;
813 register EMACS_INT tab_width = XINT (current_buffer->tab_width);
814 register unsigned char *p;
815 register unsigned char *stop;
816 unsigned char *start;
817 EMACS_INT next_boundary_byte = pos_byte;
818 EMACS_INT ceiling = next_boundary_byte;
819
820 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
821
822 p = BYTE_POS_ADDR (pos_byte);
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;
829 while (1)
830 {
831 while (p == stop)
832 {
833 EMACS_INT stop_pos_byte;
834
835 /* If we have updated P, set POS_BYTE to match.
836 The first time we enter the loop, POS_BYTE is already right. */
837 if (p != start)
838 pos_byte = PTR_BYTE_POS (p);
839 /* Consider the various reasons STOP might have been set here. */
840 if (pos_byte == ZV_BYTE)
841 return column;
842 if (pos_byte == next_boundary_byte)
843 {
844 EMACS_INT next_boundary;
845 EMACS_INT pos = BYTE_TO_CHAR (pos_byte);
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;
852 /* Compute the next place we need to stop and think,
853 and set STOP accordingly. */
854 stop_pos_byte = min (ceiling, next_boundary_byte);
855 /* The -1 and +1 arrange to point at the first byte of gap
856 (if STOP_POS_BYTE is the position of the gap)
857 rather than at the data after the gap. */
858
859 stop = BYTE_POS_ADDR (stop_pos_byte - 1) + 1;
860 p = BYTE_POS_ADDR (pos_byte);
861 }
862 switch (*p++)
863 {
864 case 0240:
865 if (! NILP (current_buffer->enable_multibyte_characters))
866 return column;
867 case ' ':
868 column++;
869 break;
870 case '\t':
871 column += tab_width - column % tab_width;
872 break;
873 default:
874 if (ASCII_BYTE_P (p[-1])
875 || NILP (current_buffer->enable_multibyte_characters))
876 return column;
877 {
878 int c;
879 pos_byte = PTR_BYTE_POS (p - 1);
880 c = FETCH_MULTIBYTE_CHAR (pos_byte);
881 if (CHAR_HAS_CATEGORY (c, ' '))
882 {
883 column++;
884 INC_POS (pos_byte);
885 p = BYTE_POS_ADDR (pos_byte);
886 }
887 else
888 return column;
889 }
890 }
891 }
892 }
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. */
897
898 int
899 indented_beyond_p (pos, pos_byte, column)
900 int pos, pos_byte;
901 double column;
902 {
903 double val;
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
910 val = position_indentation (PT_BYTE);
911 SET_PT_BOTH (opoint, opoint_byte);
912 return val >= column; /* hmm, float comparison */
913 }
914 \f
915 DEFUN ("move-to-column", Fmove_to_column, Smove_to_column, 1, 2, "p",
916 doc: /* Move point to column COLUMN in the current line.
917 Interactively, COLUMN is the value of prefix numeric argument.
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
927 Optional second argument FORCE non-nil means if COLUMN is in the
928 middle of a tab character, change it to spaces.
929 In addition, if FORCE is t, and the line is too short to reach
930 COLUMN, add spaces/tabs to get there.
931
932 The return value is the current column. */)
933 (column, force)
934 Lisp_Object column, force;
935 {
936 register EMACS_INT pos;
937 register EMACS_INT col = current_column ();
938 register EMACS_INT goal;
939 register EMACS_INT end;
940 register int tab_width = XINT (current_buffer->tab_width);
941 register int ctl_arrow = !NILP (current_buffer->ctl_arrow);
942 register struct Lisp_Char_Table *dp = buffer_display_table ();
943 register int multibyte = !NILP (current_buffer->enable_multibyte_characters);
944
945 Lisp_Object val;
946 EMACS_INT prev_col = 0;
947 int c = 0;
948 EMACS_INT next_boundary, pos_byte;
949
950 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
951 CHECK_NATNUM (column);
952 goal = XINT (column);
953
954 pos = PT;
955 pos_byte = PT_BYTE;
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 {
962 end = pos;
963 pos = current_column_bol_cache;
964 pos_byte = CHAR_TO_BYTE (pos);
965 col = 0;
966 }
967
968 next_boundary = pos;
969
970 while (pos < end)
971 {
972 while (pos == next_boundary)
973 {
974 EMACS_INT prev = pos;
975 pos = skip_invisible (pos, &next_boundary, end, Qnil);
976 if (pos != prev)
977 pos_byte = CHAR_TO_BYTE (pos);
978 if (pos >= end)
979 goto endloop;
980 }
981
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
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
1001 c = FETCH_BYTE (pos_byte);
1002
1003 /* See if there is a display table and it relates
1004 to this character. */
1005
1006 if (dp != 0
1007 && ! (multibyte && BASE_LEADING_CODE_P (c))
1008 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
1009 {
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
1016 charvec = DISP_CHAR_VECTOR (dp, c);
1017 n = ASIZE (charvec);
1018
1019 for (i = 0; i < n; i++)
1020 {
1021 /* This should be handled the same as
1022 next_element_from_display_vector does it. */
1023
1024 Lisp_Object entry;
1025 entry = AREF (charvec, i);
1026
1027 if (INTEGERP (entry)
1028 && GLYPH_CHAR_VALID_P (XFASTINT (entry)))
1029 c = FAST_GLYPH_CHAR (XFASTINT (entry));
1030 else
1031 c = ' ';
1032
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
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);
1076 pos_byte += bytes - 1;
1077 col += width;
1078 }
1079 else
1080 col += 4;
1081 }
1082
1083 pos++;
1084 pos_byte++;
1085 }
1086 endloop:
1087
1088 SET_PT_BOTH (pos, pos_byte);
1089
1090 /* If a tab char made us overshoot, change it to spaces
1091 and scan through it again. */
1092 if (!NILP (force) && col > goal && c == '\t' && prev_col < goal)
1093 {
1094 EMACS_INT goal_pt, goal_pt_byte;
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);
1101
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;
1106 Findent_to (make_number (col), Qnil);
1107 SET_PT_BOTH (goal_pt, goal_pt_byte);
1108
1109 /* Set the last_known... vars consistently. */
1110 col = goal;
1111 }
1112
1113 /* If line ends prematurely, add space to the end. */
1114 if (col < goal && EQ (force, Qt))
1115 Findent_to (make_number (col = goal), Qnil);
1116
1117 last_known_column = col;
1118 last_known_column_point = PT;
1119 last_known_column_modified = MODIFF;
1120
1121 XSETFASTINT (val, col);
1122 return val;
1123 }
1124 \f
1125 /* compute_motion: compute buffer posn given screen posn and vice versa */
1126
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),
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.
1135
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
1142 WIDTH is the number of columns available to display text;
1143 compute_motion uses this to handle continuation lines and such.
1144 If WIDTH is -1, use width of window's text area adjusted for
1145 continuation glyph when needed.
1146
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.
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.
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
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).
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
1169 TOHPOS.
1170
1171 When displaying in window w, a typical formula for WIDTH is:
1172
1173 window_width - 1
1174 - (has_vertical_scroll_bars
1175 ? WINDOW_CONFIG_SCROLL_BAR_COLS (window)
1176 : (window_width + window_left != frame_cols))
1177
1178 where
1179 window_width is XFASTINT (w->total_cols),
1180 window_left is XFASTINT (w->left_col),
1181 has_vertical_scroll_bars is
1182 WINDOW_HAS_VERTICAL_SCROLL_BAR (window)
1183 and frame_cols = FRAME_COLS (XFRAME (window->frame))
1184
1185 Or you can let window_box_text_cols do this all for you, and write:
1186 window_box_text_cols (w) - 1
1187
1188 The `-1' accounts for the continuation-line backslashes; the rest
1189 accounts for window borders if the window is split horizontally, and
1190 the scroll bars if they are turned on. */
1191
1192 struct position *
1193 compute_motion (from, fromvpos, fromhpos, did_motion, to, tovpos, tohpos, width, hscroll, tab_offset, win)
1194 EMACS_INT from, fromvpos, fromhpos, to, tovpos, tohpos;
1195 int did_motion;
1196 EMACS_INT width;
1197 EMACS_INT hscroll, tab_offset;
1198 struct window *win;
1199 {
1200 register EMACS_INT hpos = fromhpos;
1201 register EMACS_INT vpos = fromvpos;
1202
1203 register EMACS_INT pos;
1204 EMACS_INT pos_byte;
1205 register int c = 0;
1206 register EMACS_INT tab_width = XFASTINT (current_buffer->tab_width);
1207 register int ctl_arrow = !NILP (current_buffer->ctl_arrow);
1208 register struct Lisp_Char_Table *dp = window_display_table (win);
1209 int selective
1210 = (INTEGERP (current_buffer->selective_display)
1211 ? XINT (current_buffer->selective_display)
1212 : !NILP (current_buffer->selective_display) ? -1 : 0);
1213 int selective_rlen
1214 = (selective && dp && VECTORP (DISP_INVIS_VECTOR (dp))
1215 ? XVECTOR (DISP_INVIS_VECTOR (dp))->size : 0);
1216 /* The next location where the `invisible' property changes, or an
1217 overlay starts or ends. */
1218 EMACS_INT next_boundary = from;
1219
1220 /* For computing runs of characters with similar widths.
1221 Invariant: width_run_width is zero, or all the characters
1222 from width_run_start to width_run_end have a fixed width of
1223 width_run_width. */
1224 EMACS_INT width_run_start = from;
1225 EMACS_INT width_run_end = from;
1226 EMACS_INT width_run_width = 0;
1227 Lisp_Object *width_table;
1228 Lisp_Object buffer;
1229
1230 /* The next buffer pos where we should consult the width run cache. */
1231 EMACS_INT next_width_run = from;
1232 Lisp_Object window;
1233
1234 int multibyte = !NILP (current_buffer->enable_multibyte_characters);
1235 /* If previous char scanned was a wide character,
1236 this is the column where it ended. Otherwise, this is 0. */
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;
1245
1246 XSETBUFFER (buffer, current_buffer);
1247 XSETWINDOW (window, win);
1248
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
1259 if (tab_width <= 0 || tab_width > 1000)
1260 tab_width = 8;
1261
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
1273 continuation_glyph_width = 1;
1274 #ifdef HAVE_WINDOW_SYSTEM
1275 if (FRAME_WINDOW_P (XFRAME (win->frame)))
1276 continuation_glyph_width = 0; /* In the fringe. */
1277 #endif
1278
1279 immediate_quit = 1;
1280 QUIT;
1281
1282 pos = prev_pos = from;
1283 pos_byte = prev_pos_byte = CHAR_TO_BYTE (from);
1284 contin_hpos = 0;
1285 prev_tab_offset = tab_offset;
1286 while (1)
1287 {
1288 while (pos == next_boundary)
1289 {
1290 EMACS_INT pos_here = pos;
1291 EMACS_INT newpos;
1292
1293 /* Don't skip invisible if we are already at the margin. */
1294 if (vpos > tovpos || (vpos == tovpos && hpos >= tohpos))
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;
1308 vpos = prev_vpos;
1309 tab_offset = prev_tab_offset;
1310 }
1311 break;
1312 }
1313
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
1320 strings must not contain TAB;
1321 if we want to relax that restriction, something will have
1322 to be changed here. */
1323 {
1324 unsigned char *ovstr;
1325 int ovlen = overlay_strings (pos, win, &ovstr);
1326 hpos += ((multibyte && ovlen > 0)
1327 ? strwidth (ovstr, ovlen) : ovlen);
1328 }
1329 did_motion = 0;
1330
1331 if (pos >= to)
1332 break;
1333
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. */
1338 newpos = skip_invisible (pos, &next_boundary, to, window);
1339
1340 if (newpos >= to)
1341 {
1342 pos = min (to, newpos);
1343 pos_byte = CHAR_TO_BYTE (pos);
1344 goto after_loop;
1345 }
1346
1347 if (newpos != pos_here)
1348 {
1349 pos = newpos;
1350 pos_byte = CHAR_TO_BYTE (pos);
1351 }
1352 }
1353
1354 /* Handle right margin. */
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 ----------
1390 In case of wide-column character
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)
1399 {
1400 if (hscroll
1401 || (truncate_partial_width_windows
1402 && ((width + continuation_glyph_width)
1403 < FRAME_COLS (XFRAME (WINDOW_FRAME (win)))))
1404 || !NILP (current_buffer->truncate_lines))
1405 {
1406 /* Truncating: skip to newline, unless we are already past
1407 TO (we need to go back below). */
1408 if (pos <= to)
1409 {
1410 pos = find_before_next_newline (pos, to, 1);
1411 pos_byte = CHAR_TO_BYTE (pos);
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;
1419 prev_vpos = vpos;
1420 prev_tab_offset = tab_offset;
1421 }
1422 }
1423 else
1424 {
1425 /* Continuing. */
1426 /* Remember the previous value. */
1427 prev_tab_offset = tab_offset;
1428
1429 if (wide_column_end_hpos > width)
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;
1442 prev_vpos = vpos;
1443 }
1444 }
1445
1446 /* Stop if past the target buffer position or screen position. */
1447 if (pos > to)
1448 {
1449 /* Go back to the previous position. */
1450 pos = prev_pos;
1451 pos_byte = prev_pos_byte;
1452 hpos = prev_hpos;
1453 vpos = prev_vpos;
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
1467 && contin_hpos < width && !wide_column_end_hpos)
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
1477 if (vpos > tovpos || (vpos == tovpos && hpos >= tohpos))
1478 {
1479 if (contin_hpos && prev_hpos == 0
1480 && hpos > tohpos
1481 && (contin_hpos == width || wide_column_end_hpos > width))
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;
1491 vpos = prev_vpos;
1492 tab_offset = prev_tab_offset;
1493 }
1494 break;
1495 }
1496 if (pos == ZV) /* We cannot go beyond ZV. Stop here. */
1497 break;
1498
1499 prev_hpos = hpos;
1500 prev_vpos = vpos;
1501 prev_pos = pos;
1502 prev_pos_byte = pos_byte;
1503 wide_column_end_hpos = 0;
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 }
1536
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;
1547 if (pos != run_end)
1548 {
1549 pos = run_end;
1550 pos_byte = CHAR_TO_BYTE (pos);
1551 }
1552 }
1553
1554 next_width_run = run_end + 1;
1555 }
1556
1557 /* We have to scan the text character-by-character. */
1558 else
1559 {
1560 EMACS_INT i, n;
1561 Lisp_Object charvec;
1562
1563 c = FETCH_BYTE (pos_byte);
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
1578 pos++, pos_byte++;
1579
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
1586 && XFASTINT (width_table[c]) == width_run_width)
1587 width_run_end = pos;
1588
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);
1600
1601 /* Start recording a new width run. */
1602 width_run_width = XFASTINT (width_table[c]);
1603 width_run_start = pos - 1;
1604 width_run_end = pos;
1605 }
1606 }
1607
1608 if (dp != 0
1609 && ! (multibyte && BASE_LEADING_CODE_P (c))
1610 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
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)
1622 {
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);
1628
1629 if (INTEGERP (entry)
1630 && GLYPH_CHAR_VALID_P (XFASTINT (entry)))
1631 c = FAST_GLYPH_CHAR (XFASTINT (entry));
1632 else
1633 c = ' ';
1634 }
1635
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')
1647 {
1648 if (selective > 0
1649 && indented_beyond_p (pos, pos_byte,
1650 (double) selective)) /* iftc */
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
1665 && indented_beyond_p (pos, pos_byte,
1666 (double) selective)); /* iftc */
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)
1687 hpos += continuation_glyph_width;
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. */
1697 if (pos < to)
1698 {
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;
1713 }
1714 }
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 }
1729 else if (VECTORP (charvec))
1730 ++hpos;
1731 else
1732 hpos += (ctl_arrow && c < 0200) ? 2 : 4;
1733 }
1734 }
1735 }
1736
1737 after_loop:
1738
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
1746 val_compute_motion.bufpos = pos;
1747 val_compute_motion.bytepos = pos_byte;
1748 val_compute_motion.hpos = hpos;
1749 val_compute_motion.vpos = vpos;
1750 if (contin_hpos && prev_hpos == 0)
1751 val_compute_motion.prevhpos = contin_hpos;
1752 else
1753 val_compute_motion.prevhpos = prev_hpos;
1754 /* We alalways handle all of them here; none of them remain to do. */
1755 val_compute_motion.ovstring_chars_done = 0;
1756
1757 /* Nonzero if have just continued a line */
1758 val_compute_motion.contin = (contin_hpos && prev_hpos == 0);
1759
1760 immediate_quit = 0;
1761 return &val_compute_motion;
1762 }
1763
1764
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
1772 If TOPOS is nil, the actual width and height of the window's
1773 text area are used.
1774
1775 There are three additional arguments:
1776
1777 WIDTH is the number of columns available to display text;
1778 this affects handling of continuation lines. A value of nil
1779 corresponds to the actual number of available text columns.
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.
1787
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)
1808 Lisp_Object from, frompos, to, topos;
1809 Lisp_Object width, offsets, window;
1810 {
1811 struct window *w;
1812 Lisp_Object bufpos, hpos, vpos, prevhpos;
1813 struct position *pos;
1814 int hscroll, tab_offset;
1815
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);
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
1830 if (!NILP (offsets))
1831 {
1832 CHECK_CONS (offsets);
1833 CHECK_NUMBER_CAR (offsets);
1834 CHECK_NUMBER_CDR (offsets);
1835 hscroll = XINT (XCAR (offsets));
1836 tab_offset = XINT (XCDR (offsets));
1837 }
1838 else
1839 hscroll = tab_offset = 0;
1840
1841 if (NILP (window))
1842 window = Fselected_window ();
1843 else
1844 CHECK_LIVE_WINDOW (window);
1845 w = XWINDOW (window);
1846
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
1852 pos = compute_motion (XINT (from), XINT (XCDR (frompos)),
1853 XINT (XCAR (frompos)), 0,
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,
1868 XWINDOW (window));
1869
1870 XSETFASTINT (bufpos, pos->bufpos);
1871 XSETINT (hpos, pos->hpos);
1872 XSETINT (vpos, pos->vpos);
1873 XSETINT (prevhpos, pos->prevhpos);
1874
1875 return Fcons (bufpos,
1876 Fcons (hpos,
1877 Fcons (vpos,
1878 Fcons (prevhpos,
1879 Fcons (pos->contin ? Qt : Qnil, Qnil)))));
1880
1881 }
1882 \f
1883 /* Fvertical_motion and vmotion */
1884
1885 struct position val_vmotion;
1886
1887 struct position *
1888 vmotion (from, vtarget, w)
1889 register EMACS_INT from, vtarget;
1890 struct window *w;
1891 {
1892 EMACS_INT hscroll = XINT (w->hscroll);
1893 struct position pos;
1894 /* vpos is cumulative vertical position, changed as from is changed */
1895 register int vpos = 0;
1896 EMACS_INT prevline;
1897 register EMACS_INT first;
1898 EMACS_INT from_byte;
1899 EMACS_INT lmargin = hscroll > 0 ? 1 - hscroll : 0;
1900 int selective
1901 = (INTEGERP (current_buffer->selective_display)
1902 ? XINT (current_buffer->selective_display)
1903 : !NILP (current_buffer->selective_display) ? -1 : 0);
1904 Lisp_Object window;
1905 EMACS_INT start_hpos = 0;
1906 int did_motion;
1907 /* This is the object we use for fetching character properties. */
1908 Lisp_Object text_prop_object;
1909
1910 XSETWINDOW (window, w);
1911
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
1919 if (vpos >= vtarget)
1920 {
1921 /* To move upward, go a line at a time until
1922 we have gone at least far enough. */
1923
1924 first = 1;
1925
1926 while ((vpos > vtarget || first) && from > BEGV)
1927 {
1928 Lisp_Object propval;
1929
1930 prevline = find_next_newline_no_quit (from - 1, -1);
1931 while (prevline > BEGV
1932 && ((selective > 0
1933 && indented_beyond_p (prevline,
1934 CHAR_TO_BYTE (prevline),
1935 (double) selective)) /* iftc */
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),
1939 Qinvisible,
1940 text_prop_object),
1941 TEXT_PROP_MEANS_INVISIBLE (propval))))
1942 prevline = find_next_newline_no_quit (prevline - 1, -1);
1943 pos = *compute_motion (prevline, 0,
1944 lmargin + (prevline == BEG ? start_hpos : 0),
1945 0,
1946 from,
1947 /* Don't care for VPOS... */
1948 1 << (BITS_PER_SHORT - 1),
1949 /* ... nor HPOS. */
1950 1 << (BITS_PER_SHORT - 1),
1951 -1, hscroll,
1952 /* This compensates for start_hpos
1953 so that a tab as first character
1954 still occupies 8 columns. */
1955 (prevline == BEG ? -start_hpos : 0),
1956 w);
1957 vpos -= pos.vpos;
1958 first = 0;
1959 from = prevline;
1960 }
1961
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;
1968 val_vmotion.bytepos = CHAR_TO_BYTE (from);
1969 val_vmotion.vpos = vpos;
1970 val_vmotion.hpos = lmargin;
1971 val_vmotion.contin = 0;
1972 val_vmotion.prevhpos = 0;
1973 val_vmotion.ovstring_chars_done = 0;
1974 val_vmotion.tab_offset = 0; /* For accumulating tab offset. */
1975 return &val_vmotion;
1976 }
1977
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 */
1982 from_byte = CHAR_TO_BYTE (from);
1983 if (from > BEGV && FETCH_BYTE (from_byte - 1) != '\n')
1984 {
1985 Lisp_Object propval;
1986
1987 prevline = find_next_newline_no_quit (from, -1);
1988 while (prevline > BEGV
1989 && ((selective > 0
1990 && indented_beyond_p (prevline,
1991 CHAR_TO_BYTE (prevline),
1992 (double) selective)) /* iftc */
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,
1997 text_prop_object),
1998 TEXT_PROP_MEANS_INVISIBLE (propval))))
1999 prevline = find_next_newline_no_quit (prevline - 1, -1);
2000 pos = *compute_motion (prevline, 0,
2001 lmargin + (prevline == BEG
2002 ? start_hpos : 0),
2003 0,
2004 from,
2005 /* Don't care for VPOS... */
2006 1 << (BITS_PER_SHORT - 1),
2007 /* ... nor HPOS. */
2008 1 << (BITS_PER_SHORT - 1),
2009 -1, hscroll,
2010 (prevline == BEG ? -start_hpos : 0),
2011 w);
2012 did_motion = 1;
2013 }
2014 else
2015 {
2016 pos.hpos = lmargin + (from == BEG ? start_hpos : 0);
2017 pos.vpos = 0;
2018 pos.tab_offset = 0;
2019 did_motion = 0;
2020 }
2021 return compute_motion (from, vpos, pos.hpos, did_motion,
2022 ZV, vtarget, - (1 << (BITS_PER_SHORT - 1)),
2023 -1, hscroll,
2024 pos.tab_offset - (from == BEG ? start_hpos : 0),
2025 w);
2026 }
2027
2028 DEFUN ("vertical-motion", Fvertical_motion, Svertical_motion, 1, 2, 0,
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)
2050 Lisp_Object lines, window;
2051 {
2052 struct it it;
2053 struct text_pos pt;
2054 struct window *w;
2055 Lisp_Object old_buffer;
2056 struct gcpro gcpro1;
2057
2058 CHECK_NUMBER (lines);
2059 if (! NILP (window))
2060 CHECK_WINDOW (window);
2061 else
2062 window = selected_window;
2063 w = XWINDOW (window);
2064
2065 old_buffer = Qnil;
2066 GCPRO1 (old_buffer);
2067 if (XBUFFER (w->buffer) != current_buffer)
2068 {
2069 /* Set the window's buffer temporarily to the current buffer. */
2070 old_buffer = w->buffer;
2071 XSETBUFFER (w->buffer, current_buffer);
2072 }
2073
2074 if (noninteractive)
2075 {
2076 struct position pos;
2077 pos = *vmotion (PT, XINT (lines), w);
2078 SET_PT_BOTH (pos.bufpos, pos.bytepos);
2079 }
2080 else
2081 {
2082 int it_start;
2083 int oselective;
2084 int it_overshoot_expected;
2085
2086 SET_TEXT_POS (pt, PT, PT_BYTE);
2087 start_display (&it, w, pt);
2088
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. */
2095 it_start = IT_CHARPOS (it);
2096
2097 /* We expect the call to move_it_to, further down, to overshoot
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. */
2102 if (it.method == GET_FROM_STRING)
2103 {
2104 const char *s = SDATA (it.string);
2105 const char *e = s + SBYTES (it.string);
2106
2107 while (s < e && *s != '\n')
2108 ++s;
2109
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;
2115 }
2116 else
2117 it_overshoot_expected = (it.method == GET_FROM_IMAGE
2118 || it.method == GET_FROM_STRETCH
2119 || it.method == GET_FROM_COMPOSITION);
2120
2121 reseat_at_previous_visible_line_start (&it);
2122 it.current_x = it.hpos = 0;
2123 /* Temporarily disable selective display so we don't move too far */
2124 oselective = it.selective;
2125 it.selective = 0;
2126 move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
2127 it.selective = oselective;
2128
2129 /* Move back if we got too far. This may happen if
2130 truncate-lines is on and PT is beyond right margin.
2131 Don't go back if the overshoot is expected (see above). */
2132 if (IT_CHARPOS (it) > it_start && XINT (lines) > 0
2133 && (!it_overshoot_expected
2134 || (it_overshoot_expected < 0
2135 && it.method == GET_FROM_BUFFER
2136 && it.c == '\n')))
2137 move_it_by_lines (&it, -1, 0);
2138
2139 it.vpos = 0;
2140 /* Do this even if LINES is 0, so that we move back
2141 to the beginning of the current line as we ought. */
2142 if (XINT (lines) >= 0 || IT_CHARPOS (it) > 0)
2143 move_it_by_lines (&it, XINT (lines), 0);
2144
2145 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
2146 }
2147
2148 if (BUFFERP (old_buffer))
2149 w->buffer = old_buffer;
2150
2151 RETURN_UNGCPRO (make_number (it.vpos));
2152 }
2153
2154
2155 \f
2156 /* File's initialization. */
2157
2158 void
2159 syms_of_indent ()
2160 {
2161 DEFVAR_BOOL ("indent-tabs-mode", &indent_tabs_mode,
2162 doc: /* *Indentation can insert tabs if this is non-nil. */);
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);
2170 defsubr (&Scompute_motion);
2171 }
2172
2173 /* arch-tag: 9adfea44-71f7-4988-8ee3-96da15c502cc
2174 (do not change this comment) */