comparison src/indent.c @ 398:74fd4e045ea6 r21-2-29

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