comparison src/indent.c @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents 74fd4e045ea6
children da8ed4261e83
comparison
equal deleted inserted replaced
411:12e008d41344 412:697ef44129c6
37 #include "insdel.h" 37 #include "insdel.h"
38 #ifdef REGION_CACHE_NEEDS_WORK 38 #ifdef REGION_CACHE_NEEDS_WORK
39 #include "region-cache.h" 39 #include "region-cache.h"
40 #endif 40 #endif
41 #include "window.h" 41 #include "window.h"
42
43 Lisp_Object Qcoerce;
44 42
45 /* Indentation can insert tabs if this is non-zero; 43 /* Indentation can insert tabs if this is non-zero;
46 otherwise always uses spaces */ 44 otherwise always uses spaces */
47 int indent_tabs_mode; 45 int indent_tabs_mode;
48 46
193 191
194 return col; 192 return col;
195 } 193 }
196 194
197 int 195 int
198 string_column_at_point (Lisp_String* s, Bufpos init_pos, int tab_width)
199 {
200 int col;
201 int tab_seen;
202 int post_tab;
203 Bufpos pos = init_pos;
204 Emchar c;
205
206 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
207 col = tab_seen = post_tab = 0;
208
209 while (1)
210 {
211 if (pos <= 0)
212 break;
213
214 pos--;
215 c = string_char (s, pos);
216 if (c == '\t')
217 {
218 if (tab_seen)
219 col = ((col + tab_width) / tab_width) * tab_width;
220
221 post_tab += col;
222 col = 0;
223 tab_seen = 1;
224 }
225 else if (c == '\n')
226 break;
227 else
228 #ifdef MULE
229 col += XCHARSET_COLUMNS (CHAR_CHARSET (c));
230 #else
231 col ++;
232 #endif /* MULE */
233 }
234
235 if (tab_seen)
236 {
237 col = ((col + tab_width) / tab_width) * tab_width;
238 col += post_tab;
239 }
240
241 return col;
242 }
243
244 int
245 current_column (struct buffer *buf) 196 current_column (struct buffer *buf)
246 { 197 {
247 if (buf == last_known_column_buffer 198 if (buf == last_known_column_buffer
248 && BUF_PT (buf) == last_known_column_point 199 && BUF_PT (buf) == last_known_column_point
249 && BUF_MODIFF (buf) == last_known_column_modified) 200 && BUF_MODIFF (buf) == last_known_column_modified)
389 and horizontal scrolling has no effect. 340 and horizontal scrolling has no effect.
390 341
391 If specified column is within a character, point goes after that character. 342 If specified column is within a character, point goes after that character.
392 If it's past end of line, point goes to end of line. 343 If it's past end of line, point goes to end of line.
393 344
394 A value of 'coerce for the second (optional) argument FORCE means if 345 A non-nil second (optional) argument FORCE means, if the line
395 COLUMN is in the middle of a tab character, change it to spaces. 346 is too short to reach column COLUMN then add spaces/tabs to get there,
396 Any other non-nil value means the same, plus if the line is too short to 347 and if COLUMN is in the middle of a tab character, change it to spaces.
397 reach column COLUMN, then add spaces/tabs to get there.
398
399 Returns the actual column that it moved to. 348 Returns the actual column that it moved to.
400 */ 349 */
401 (column, force, buffer)) 350 (column, force, buffer))
402 { 351 {
403 /* This function can GC */ 352 /* This function can GC */
477 buffer_insert_emacs_char (buf, ' '); 426 buffer_insert_emacs_char (buf, ' ');
478 goto retry; 427 goto retry;
479 } 428 }
480 429
481 /* If line ends prematurely, add space to the end. */ 430 /* If line ends prematurely, add space to the end. */
482 if (col < goal && !NILP (force) && !EQ (force, Qcoerce)) 431 if (col < goal && !NILP (force))
483 { 432 {
484 col = goal; 433 col = goal;
485 Findent_to (make_int (col), Qzero, buffer); 434 Findent_to (make_int (col), Qzero, buffer);
486 } 435 }
487 436
590 int i, vpix; 539 int i, vpix;
591 540
592 assert (start <= end); 541 assert (start <= end);
593 assert (start >= 0); 542 assert (start >= 0);
594 assert (end < Dynarr_length (cache)); 543 assert (end < Dynarr_length (cache));
595 544
596 vpix = 0; 545 vpix = 0;
597 for (i = start; i <= end; i++) 546 for (i = start; i <= end; i++)
598 vpix += Dynarr_atp (cache, i)->height; 547 vpix += Dynarr_atp (cache, i)->height;
599 548
600 return vpix; 549 return vpix;
714 struct window *w; 663 struct window *w;
715 664
716 if (NILP (window)) 665 if (NILP (window))
717 window = Fselected_window (Qnil); 666 window = Fselected_window (Qnil);
718 667
719 CHECK_LIVE_WINDOW (window); 668 CHECK_WINDOW (window);
720 CHECK_INT (lines); 669 CHECK_INT (lines);
721 670
722 selected = (EQ (window, Fselected_window (Qnil))); 671 selected = (EQ (window, Fselected_window (Qnil)));
723 672
724 w = XWINDOW (window); 673 w = XWINDOW (window);
730 vpix = pixels ? &value : NULL; 679 vpix = pixels ? &value : NULL;
731 680
732 bufpos = vmotion_1 (w, orig, XINT (lines), vpos, vpix); 681 bufpos = vmotion_1 (w, orig, XINT (lines), vpos, vpix);
733 682
734 /* Note that the buffer's point is set, not the window's point. */ 683 /* Note that the buffer's point is set, not the window's point. */
735 if (selected) 684 if (selected)
736 BUF_SET_PT (XBUFFER (w->buffer), bufpos); 685 BUF_SET_PT (XBUFFER (w->buffer), bufpos);
737 else 686 else
738 set_marker_restricted (w->pointm[CURRENT_DISP], 687 set_marker_restricted (w->pointm[CURRENT_DISP],
739 make_int(bufpos), 688 make_int(bufpos),
740 w->buffer); 689 w->buffer);
788 int lines; 737 int lines;
789 738
790 if (NILP (window)) 739 if (NILP (window))
791 window = Fselected_window (Qnil); 740 window = Fselected_window (Qnil);
792 741
793 CHECK_LIVE_WINDOW (window); 742 CHECK_WINDOW (window);
794 w = XWINDOW (window); 743 w = XWINDOW (window);
795 744
796 eobuf = BUF_ZV (XBUFFER (w->buffer)); 745 eobuf = BUF_ZV (XBUFFER (w->buffer));
797 bobuf = BUF_BEGV (XBUFFER (w->buffer)); 746 bobuf = BUF_BEGV (XBUFFER (w->buffer));
798 747
891 struct window *w; 840 struct window *w;
892 841
893 if (NILP (window)) 842 if (NILP (window))
894 window = Fselected_window (Qnil); 843 window = Fselected_window (Qnil);
895 844
896 CHECK_LIVE_WINDOW (window); 845 CHECK_WINDOW (window);
897 CHECK_INT (pixels); 846 CHECK_INT (pixels);
898 847
899 selected = (EQ (window, Fselected_window (Qnil))); 848 selected = (EQ (window, Fselected_window (Qnil)));
900 849
901 w = XWINDOW (window); 850 w = XWINDOW (window);
905 854
906 howto = INTP (how) ? XINT (how) : 0; 855 howto = INTP (how) ? XINT (how) : 0;
907 856
908 bufpos = vmotion_pixels (window, orig, XINT (pixels), howto, &motion); 857 bufpos = vmotion_pixels (window, orig, XINT (pixels), howto, &motion);
909 858
910 if (selected) 859 if (selected)
911 BUF_SET_PT (XBUFFER (w->buffer), bufpos); 860 BUF_SET_PT (XBUFFER (w->buffer), bufpos);
912 else 861 else
913 set_marker_restricted (w->pointm[CURRENT_DISP], 862 set_marker_restricted (w->pointm[CURRENT_DISP],
914 make_int(bufpos), 863 make_int(bufpos),
915 w->buffer); 864 w->buffer);
928 #if 0 /* #### */ 877 #if 0 /* #### */
929 DEFSUBR (Fcompute_motion); 878 DEFSUBR (Fcompute_motion);
930 #endif 879 #endif
931 DEFSUBR (Fvertical_motion); 880 DEFSUBR (Fvertical_motion);
932 DEFSUBR (Fvertical_motion_pixels); 881 DEFSUBR (Fvertical_motion_pixels);
933
934 defsymbol (&Qcoerce, "coerce");
935 } 882 }
936 883
937 void 884 void
938 vars_of_indent (void) 885 vars_of_indent (void)
939 { 886 {