0
|
1 /* Indentation functions.
|
|
2 Copyright (C) 1995 Board of Trustees, University of Illinois.
|
|
3 Copyright (C) 1985, 1986, 1987, 1988, 1992, 1993, 1994, 1995
|
|
4 Free Software Foundation, Inc.
|
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* This file has been Mule-ized. */
|
|
24
|
|
25 /* Synched up with: 19.30. Diverges significantly from FSF. */
|
|
26
|
|
27
|
|
28 #include <config.h>
|
|
29 #include "lisp.h"
|
|
30
|
|
31 #include "buffer.h"
|
|
32 #include "device.h"
|
|
33 #include "extents.h"
|
|
34 #include "faces.h"
|
|
35 #include "frame.h"
|
|
36 #include "glyphs.h"
|
|
37 #include "insdel.h"
|
|
38 #ifdef REGION_CACHE_NEEDS_WORK
|
|
39 #include "region-cache.h"
|
|
40 #endif
|
|
41 #include "window.h"
|
|
42
|
|
43 /* Indentation can insert tabs if this is non-zero;
|
|
44 otherwise always uses spaces */
|
|
45 int indent_tabs_mode;
|
|
46
|
|
47 /* Avoid recalculation by remembering things in these variables. */
|
|
48
|
|
49 /* Last value returned by current_column.
|
|
50
|
|
51 Some things set last_known_column_point to -1
|
|
52 to mark the memoized value as invalid */
|
|
53 static int last_known_column;
|
|
54
|
|
55 /* Last buffer searched by current_column */
|
|
56 static struct buffer *last_known_column_buffer;
|
|
57
|
|
58 /* Value of point when current_column was called */
|
|
59 static Bufpos last_known_column_point;
|
|
60
|
|
61 /* Value of MODIFF when current_column was called */
|
|
62 static int last_known_column_modified;
|
|
63
|
|
64 static Bufpos
|
|
65 last_visible_position (Bufpos pos, struct buffer *buf)
|
|
66 {
|
|
67 Lisp_Object buffer;
|
|
68 Lisp_Object value;
|
|
69
|
|
70 XSETBUFFER (buffer, buf);
|
|
71 value = Fprevious_single_property_change (make_int (pos), Qinvisible,
|
|
72 buffer, Qnil);
|
|
73 if (NILP (value))
|
|
74 return 0; /* no visible position found */
|
|
75 else
|
|
76 /* #### bug bug bug!!! This will return the position of the beginning
|
|
77 of an invisible extent; this extent is very likely to be start-closed,
|
|
78 and thus the spaces inserted in `indent-to' will go inside the
|
|
79 invisible extent.
|
|
80
|
|
81 Not sure what the correct solution is here. Rethink indent-to? */
|
|
82 return XINT (value);
|
|
83 }
|
|
84
|
|
85 #ifdef REGION_CACHE_NEEDS_WORK
|
|
86
|
|
87 /* Allocate or free the width run cache, as requested by the current
|
|
88 state of current_buffer's cache_long_line_scans variable. */
|
|
89 static void
|
|
90 width_run_cache_on_off (struct buffer *buf)
|
|
91 {
|
|
92 if (NILP (buf->cache_long_line_scans))
|
|
93 {
|
|
94 /* It should be off. */
|
|
95 if (buf->width_run_cache)
|
|
96 {
|
|
97 free_region_cache (buf->width_run_cache);
|
|
98 buf->width_run_cache = 0;
|
|
99 buf->width_table = Qnil;
|
|
100 }
|
|
101 }
|
|
102 else
|
|
103 {
|
|
104 /* It should be on. */
|
|
105 if (buf->width_run_cache == 0)
|
|
106 {
|
|
107 buf->width_run_cache = new_region_cache ();
|
|
108 recompute_width_table (buf, buffer_display_table ());
|
|
109 }
|
|
110 }
|
|
111 }
|
|
112
|
|
113 #endif /* REGION_CACHE_NEEDS_WORK */
|
|
114
|
|
115
|
|
116 /* Cancel any recorded value of the horizontal position. */
|
|
117
|
|
118 void
|
|
119 invalidate_current_column (void)
|
|
120 {
|
|
121 last_known_column_point = -1;
|
|
122 }
|
|
123
|
|
124 int
|
|
125 column_at_point (struct buffer *buf, Bufpos init_pos, int cur_col)
|
|
126 {
|
|
127 int col;
|
|
128 int tab_seen;
|
|
129 int tab_width = XINT (buf->tab_width);
|
|
130 int post_tab;
|
|
131 Bufpos pos = init_pos;
|
16
|
132 Emchar c;
|
0
|
133
|
|
134 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
|
|
135 col = tab_seen = post_tab = 0;
|
|
136
|
|
137 while (1)
|
|
138 {
|
|
139 if (pos <= BUF_BEGV (buf))
|
|
140 break;
|
|
141
|
|
142 pos--;
|
16
|
143 c = BUF_FETCH_CHAR (buf, pos);
|
|
144 if (c == '\t')
|
0
|
145 {
|
|
146 if (tab_seen)
|
|
147 col = ((col + tab_width) / tab_width) * tab_width;
|
|
148
|
|
149 post_tab += col;
|
|
150 col = 0;
|
|
151 tab_seen = 1;
|
|
152 }
|
16
|
153 else if (c == '\n' ||
|
|
154 (EQ (buf->selective_display, Qt) && c == '\r'))
|
0
|
155 break;
|
|
156 else
|
|
157 {
|
|
158 /* #### This needs updating to handle the new redisplay. */
|
|
159 /* #### FSFmacs looks at ctl_arrow, display tables.
|
|
160 We need to do similar. */
|
|
161 #if 0
|
|
162 displayed_glyphs = glyphs_from_bufpos (sel_frame, buf,
|
|
163 XWINDOW (selected_window),
|
|
164 pos, dp, 0, col, 0, 0, 0);
|
|
165 col += (displayed_glyphs->columns
|
|
166 - (displayed_glyphs->begin_columns
|
|
167 + displayed_glyphs->end_columns));
|
16
|
168 #else /* XEmacs */
|
|
169 col ++;
|
|
170 #endif /* XEmacs */
|
0
|
171 }
|
|
172 }
|
|
173
|
|
174 if (tab_seen)
|
|
175 {
|
|
176 col = ((col + tab_width) / tab_width) * tab_width;
|
|
177 col += post_tab;
|
|
178 }
|
|
179
|
|
180 if (cur_col)
|
|
181 {
|
|
182 last_known_column_buffer = buf;
|
|
183 last_known_column = col;
|
|
184 last_known_column_point = BUF_PT (buf);
|
|
185 last_known_column_modified = BUF_MODIFF (buf);
|
|
186 }
|
|
187
|
|
188 return col;
|
|
189 }
|
|
190
|
|
191 int
|
|
192 current_column (struct buffer *buf)
|
|
193 {
|
|
194 if (buf == last_known_column_buffer
|
|
195 && BUF_PT (buf) == last_known_column_point
|
|
196 && BUF_MODIFF (buf) == last_known_column_modified)
|
|
197 return last_known_column;
|
|
198
|
|
199 return column_at_point (buf, BUF_PT (buf), 1);
|
|
200 }
|
|
201
|
20
|
202 DEFUN ("current-column", Fcurrent_column, 0, 1, 0, /*
|
0
|
203 Return the horizontal position of point. Beginning of line is column 0.
|
|
204 This is calculated by adding together the widths of all the displayed
|
|
205 representations of the character between the start of the previous line
|
|
206 and point. (e.g. control characters will have a width of 2 or 4, tabs
|
|
207 will have a variable width.)
|
|
208 Ignores finite width of frame, which means that this function may return
|
|
209 values greater than (frame-width).
|
|
210 Whether the line is visible (if `selective-display' is t) has no effect;
|
|
211 however, ^M is treated as end of line when `selective-display' is t.
|
|
212 If BUFFER is nil, the current buffer is assumed.
|
20
|
213 */
|
|
214 (buffer))
|
0
|
215 {
|
|
216 return (make_int (current_column (decode_buffer (buffer, 0))));
|
|
217 }
|
|
218
|
|
219
|
20
|
220 DEFUN ("indent-to", Findent_to, 1, 3, "NIndent to column: ", /*
|
0
|
221 Indent from point with tabs and spaces until COLUMN is reached.
|
|
222 Optional second argument MIN says always do at least MIN spaces
|
|
223 even if that goes past COLUMN; by default, MIN is zero.
|
|
224 If BUFFER is nil, the current buffer is assumed.
|
20
|
225 */
|
|
226 (col, minimum, buffer))
|
0
|
227 {
|
|
228 /* This function can GC */
|
|
229 int mincol;
|
|
230 int fromcol;
|
|
231 struct buffer *buf = decode_buffer (buffer, 0);
|
|
232 int tab_width = XINT (buf->tab_width);
|
|
233 Bufpos opoint = 0;
|
|
234
|
|
235 CHECK_INT (col);
|
|
236 if (NILP (minimum))
|
|
237 minimum = Qzero;
|
|
238 else
|
|
239 CHECK_INT (minimum);
|
|
240
|
|
241 XSETBUFFER (buffer, buf);
|
|
242
|
|
243 fromcol = current_column (buf);
|
|
244 mincol = fromcol + XINT (minimum);
|
|
245 if (mincol < XINT (col)) mincol = XINT (col);
|
|
246
|
|
247 if (fromcol == mincol)
|
|
248 return make_int (mincol);
|
|
249
|
|
250 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
|
|
251
|
|
252 if (!NILP (Fextent_at (make_int (BUF_PT (buf)), buffer, Qinvisible,
|
|
253 Qnil, Qnil)))
|
|
254 {
|
|
255 Bufpos last_visible = last_visible_position (BUF_PT (buf), buf);
|
|
256
|
|
257 opoint = BUF_PT (buf);
|
|
258 if (last_visible >= BUF_BEGV (buf))
|
|
259 BUF_SET_PT (buf, last_visible);
|
|
260 else
|
|
261 error ("Visible portion of buffer not modifiable");
|
|
262 }
|
|
263
|
|
264 if (indent_tabs_mode)
|
|
265 {
|
|
266 int n = mincol / tab_width - fromcol / tab_width;
|
|
267 if (n != 0)
|
|
268 {
|
|
269 Finsert_char (make_char ('\t'), make_int (n), Qnil, buffer);
|
|
270
|
|
271 fromcol = (mincol / tab_width) * tab_width;
|
|
272 }
|
|
273 }
|
|
274
|
|
275 Finsert_char (make_char (' '), make_int (mincol - fromcol), Qnil, buffer);
|
|
276
|
|
277 last_known_column_buffer = buf;
|
|
278 last_known_column = mincol;
|
|
279 last_known_column_point = BUF_PT (buf);
|
|
280 last_known_column_modified = BUF_MODIFF (buf);
|
|
281
|
|
282 /* Not in FSF: */
|
|
283 if (opoint > 0)
|
|
284 BUF_SET_PT (buf, opoint);
|
|
285
|
|
286 return (make_int (mincol));
|
|
287 }
|
|
288
|
|
289 int
|
|
290 bi_spaces_at_point (struct buffer *b, Bytind bi_pos)
|
|
291 {
|
|
292 Bytind bi_end = BI_BUF_ZV (b);
|
|
293 int col = 0;
|
|
294 Emchar c;
|
|
295 int tab_width = XINT (b->tab_width);
|
|
296
|
|
297 if (tab_width <= 0 || tab_width > 1000)
|
|
298 tab_width = 8;
|
|
299
|
|
300 while (bi_pos < bi_end &&
|
|
301 (c = BI_BUF_FETCH_CHAR (b, bi_pos),
|
|
302 (c == '\t'
|
|
303 ? (col += tab_width - col % tab_width)
|
|
304 : (c == ' ' ? ++col : 0))))
|
|
305 INC_BYTIND (b, bi_pos);
|
|
306
|
|
307 return col;
|
|
308 }
|
|
309
|
|
310
|
20
|
311 DEFUN ("current-indentation", Fcurrent_indentation, 0, 1, 0, /*
|
0
|
312 Return the indentation of the current line.
|
|
313 This is the horizontal position of the character
|
|
314 following any initial whitespace.
|
20
|
315 */
|
|
316 (buffer))
|
0
|
317 {
|
|
318 struct buffer *buf = decode_buffer (buffer, 0);
|
|
319 Bufpos pos = find_next_newline (buf, BUF_PT (buf), -1);
|
|
320
|
|
321 XSETBUFFER (buffer, buf);
|
|
322
|
|
323 if (!NILP (Fextent_at (make_int (pos), buffer, Qinvisible, Qnil, Qnil)))
|
|
324 return Qzero;
|
|
325
|
|
326 return make_int (bi_spaces_at_point (buf, bufpos_to_bytind (buf, pos)));
|
|
327 }
|
|
328
|
|
329
|
20
|
330 DEFUN ("move-to-column", Fmove_to_column, 1, 3, 0, /*
|
0
|
331 Move point to column COLUMN in the current line.
|
|
332 The column of a character is calculated by adding together the widths
|
|
333 as displayed of the previous characters in the line.
|
|
334 This function ignores line-continuation;
|
|
335 there is no upper limit on the column number a character can have
|
|
336 and horizontal scrolling has no effect.
|
|
337
|
|
338 If specified column is within a character, point goes after that character.
|
|
339 If it's past end of line, point goes to end of line.
|
|
340
|
|
341 A non-nil second (optional) argument FORCE means, if the line
|
|
342 is too short to reach column COLUMN then add spaces/tabs to get there,
|
|
343 and if COLUMN is in the middle of a tab character, change it to spaces.
|
|
344 Returns the actual column that it moved to.
|
20
|
345 */
|
|
346 (column, force, buffer))
|
0
|
347 {
|
|
348 /* This function can GC */
|
|
349 Bufpos pos;
|
|
350 struct buffer *buf = decode_buffer (buffer, 0);
|
|
351 int col = current_column (buf);
|
|
352 int goal;
|
|
353 Bufpos end;
|
|
354 int tab_width = XINT (buf->tab_width);
|
|
355
|
|
356 int prev_col = 0;
|
16
|
357 Emchar c;
|
0
|
358
|
|
359 XSETBUFFER (buffer, buf);
|
|
360 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
|
|
361 CHECK_NATNUM (column);
|
|
362 goal = XINT (column);
|
|
363
|
|
364 retry:
|
|
365 pos = BUF_PT (buf);
|
|
366 end = BUF_ZV (buf);
|
|
367
|
|
368 /* If we're starting past the desired column,
|
|
369 back up to beginning of line and scan from there. */
|
|
370 if (col > goal)
|
|
371 {
|
|
372 pos = find_next_newline (buf, pos, -1);
|
|
373 col = 0;
|
|
374 }
|
|
375
|
|
376 while (col < goal && pos < end)
|
|
377 {
|
|
378 c = BUF_FETCH_CHAR (buf, pos);
|
|
379 if (c == '\n')
|
|
380 break;
|
|
381 if (c == '\r' && EQ (buf->selective_display, Qt))
|
|
382 break;
|
|
383 if (c == '\t')
|
|
384 {
|
|
385 prev_col = col;
|
|
386 col += tab_width;
|
|
387 col = col / tab_width * tab_width;
|
|
388 }
|
|
389 else
|
|
390 {
|
|
391 /* #### oh for the days of the complete new redisplay */
|
|
392 /* #### FSFmacs looks at ctl_arrow, display tables.
|
|
393 We need to do similar. */
|
|
394 #if 0
|
|
395 displayed_glyphs = glyphs_from_bufpos (selected_frame (),
|
|
396 buf,
|
|
397 XWINDOW (Fselected_window (Qnil)),
|
|
398 pos, dp, 0, col, 0, 0, 0);
|
|
399 col += (displayed_glyphs->columns
|
|
400 - (displayed_glyphs->begin_columns
|
|
401 + displayed_glyphs->end_columns));
|
16
|
402 #else /* XEmacs */
|
|
403 col ++;
|
|
404 #endif /* XEmacs */
|
0
|
405 }
|
|
406
|
|
407 pos++;
|
|
408 }
|
|
409
|
|
410 BUF_SET_PT (buf, pos);
|
|
411
|
|
412 /* If a tab char made us overshoot, change it to spaces
|
|
413 and scan through it again. */
|
|
414 if (!NILP (force) && col > goal && c == '\t' && prev_col < goal)
|
|
415 {
|
|
416 buffer_delete_range (buf, BUF_PT (buf) - 1, BUF_PT (buf), 0);
|
|
417 Findent_to (make_int (col - 1), Qzero, buffer);
|
|
418 buffer_insert_emacs_char (buf, ' ');
|
|
419 goto retry;
|
|
420 }
|
|
421
|
|
422 /* If line ends prematurely, add space to the end. */
|
|
423 if (col < goal && !NILP (force))
|
|
424 {
|
|
425 col = goal;
|
|
426 Findent_to (make_int (col), Qzero, buffer);
|
|
427 }
|
|
428
|
|
429 last_known_column_buffer = buf;
|
|
430 last_known_column = col;
|
|
431 last_known_column_point = BUF_PT (buf);
|
|
432 last_known_column_modified = BUF_MODIFF (buf);
|
|
433
|
|
434 return (make_int (col));
|
|
435 }
|
|
436
|
|
437 #if 0 /* #### OK boys, this function needs to be present, I think.
|
|
438 It was there before the 19.12 redisplay rewrite. */
|
|
439
|
|
440 xxDEFUN ("compute-motion", Fcompute_motion, Scompute_motion, 7, 7, 0 /*
|
|
441 "Scan through the current buffer, calculating screen position.
|
|
442 Scan the current buffer forward from offset FROM,
|
|
443 assuming it is at position FROMPOS--a cons of the form (HPOS . VPOS)--
|
|
444 to position TO or position TOPOS--another cons of the form (HPOS . VPOS)--
|
|
445 and return the ending buffer position and screen location.
|
|
446
|
|
447 There are three additional arguments:
|
|
448
|
|
449 WIDTH is the number of columns available to display text;
|
|
450 this affects handling of continuation lines.
|
|
451 This is usually the value returned by `window-width', less one (to allow
|
|
452 for the continuation glyph).
|
|
453
|
|
454 OFFSETS is either nil or a cons cell (HSCROLL . TAB-OFFSET).
|
|
455 HSCROLL is the number of columns not being displayed at the left
|
|
456 margin; this is usually taken from a window's hscroll member.
|
|
457 TAB-OFFSET is the number of columns of the first tab that aren't
|
|
458 being displayed, perhaps because the line was continued within it.
|
|
459 If OFFSETS is nil, HSCROLL and TAB-OFFSET are assumed to be zero.
|
|
460
|
|
461 WINDOW is the window to operate on. Currently this is used only to
|
|
462 find the display table. It does not matter what buffer WINDOW displays;
|
|
463 `compute-motion' always operates on the current buffer.
|
|
464
|
|
465 The value is a list of five elements:
|
|
466 (POS HPOS VPOS PREVHPOS CONTIN)
|
|
467 POS is the buffer position where the scan stopped.
|
|
468 VPOS is the vertical position where the scan stopped.
|
|
469 HPOS is the horizontal position where the scan stopped.
|
|
470
|
|
471 PREVHPOS is the horizontal position one character back from POS.
|
|
472 CONTIN is t if a line was continued after (or within) the previous character.
|
|
473
|
|
474 For example, to find the buffer position of column COL of line LINE
|
|
475 of a certain window, pass the window's starting location as FROM
|
|
476 and the window's upper-left coordinates as FROMPOS.
|
|
477 Pass the buffer's (point-max) as TO, to limit the scan to the end of the
|
|
478 visible section of the buffer, and pass LINE and COL as TOPOS.
|
|
479 */ )
|
|
480 (from, frompos, to, topos, width, offsets, window)
|
|
481 Lisp_Object from, frompos, to, topos;
|
|
482 Lisp_Object width, offsets, window;
|
|
483 {
|
|
484 Lisp_Object bufpos, hpos, vpos, prevhpos, contin;
|
|
485 struct position *pos;
|
|
486 int hscroll, tab_offset;
|
|
487 struct window *w = decode_window (window);
|
|
488
|
|
489 CHECK_INT_COERCE_MARKER (from);
|
|
490 CHECK_CONS (frompos);
|
|
491 CHECK_INT (XCAR (frompos));
|
|
492 CHECK_INT (XCDR (frompos));
|
|
493 CHECK_INT_COERCE_MARKER (to);
|
|
494 CHECK_CONS (topos);
|
|
495 CHECK_INT (XCAR (topos));
|
|
496 CHECK_INT (XCDR (topos));
|
|
497 CHECK_INT (width);
|
|
498 if (!NILP (offsets))
|
|
499 {
|
|
500 CHECK_CONS (offsets);
|
|
501 CHECK_INT (XCAR (offsets));
|
|
502 CHECK_INT (XCDR (offsets));
|
|
503 hscroll = XINT (XCAR (offsets));
|
|
504 tab_offset = XINT (XCDR (offsets));
|
|
505 }
|
|
506 else
|
|
507 hscroll = tab_offset = 0;
|
|
508
|
|
509 pos = compute_motion (XINT (from), XINT (XCDR (frompos)),
|
|
510 XINT (XCAR (frompos)),
|
|
511 XINT (to), XINT (XCDR (topos)),
|
|
512 XINT (XCAR (topos)),
|
|
513 XINT (width), hscroll, tab_offset, w);
|
|
514
|
|
515 XSETINT (bufpos, pos->bufpos);
|
|
516 XSETINT (hpos, pos->hpos);
|
|
517 XSETINT (vpos, pos->vpos);
|
|
518 XSETINT (prevhpos, pos->prevhpos);
|
|
519
|
|
520 return list5 (bufpos,
|
|
521 hpos,
|
|
522 vpos,
|
|
523 prevhpos,
|
|
524 pos->contin ? Qt : Qnil);
|
|
525
|
|
526 }
|
|
527
|
|
528 #endif /* 0 */
|
|
529
|
|
530 /*****************************************************************************
|
|
531 vmotion
|
|
532
|
|
533 Given a starting position ORIG, move point VTARGET lines in WINDOW.
|
|
534 Returns the new value for point. If the arg ret_vpos is not nil, it is
|
|
535 taken to be a pointer to an int and the number of lines actually moved is
|
|
536 returned in it.
|
|
537 ****************************************************************************/
|
|
538 Bufpos
|
|
539 vmotion (struct window *w, Bufpos orig, int vtarget, int *ret_vpos)
|
|
540 {
|
|
541 struct buffer *b = XBUFFER (w->buffer);
|
|
542 int elt;
|
|
543
|
|
544 elt = point_in_line_start_cache (w, orig, (vtarget < 0
|
|
545 ? -vtarget
|
|
546 : vtarget));
|
|
547
|
|
548 /* #### This assertion must be true before the if statements are hit
|
|
549 but may possibly be wrong after the call to
|
|
550 point_in_line_start_cache if orig is outside of the visible
|
|
551 region of the buffer. Handle this. */
|
|
552 assert (elt >= 0);
|
|
553
|
|
554 /* Moving downward. */
|
|
555 if (vtarget > 0)
|
|
556 {
|
|
557 int cur_line = Dynarr_length (w->line_start_cache) - 1 - elt;
|
|
558 Bufpos ret_pt;
|
|
559
|
|
560 if (cur_line > vtarget)
|
|
561 cur_line = vtarget;
|
|
562
|
|
563 /* The traditional FSF behavior is to return the end of buffer
|
|
564 position if we couldn't move far enough because we hit it. */
|
|
565 if (cur_line < vtarget)
|
|
566 ret_pt = BUF_ZV (b);
|
|
567 else
|
|
568 ret_pt = Dynarr_atp (w->line_start_cache, cur_line + elt)->start;
|
|
569
|
|
570 while (ret_pt > BUF_ZV (b) && cur_line > 0)
|
|
571 {
|
|
572 cur_line--;
|
|
573 ret_pt = Dynarr_atp (w->line_start_cache, cur_line + elt)->start;
|
|
574 }
|
|
575
|
|
576 if (ret_vpos) *ret_vpos = cur_line;
|
|
577 return (ret_pt);
|
|
578 }
|
|
579 else if (vtarget < 0)
|
|
580 {
|
|
581 if (elt < -vtarget)
|
|
582 {
|
|
583 if (ret_vpos) *ret_vpos = -elt;
|
|
584 /* #### This should be BUF_BEGV (b), right? */
|
|
585 return (Dynarr_atp (w->line_start_cache, 0)->start);
|
|
586 }
|
|
587 else
|
|
588 {
|
|
589 if (ret_vpos) *ret_vpos = vtarget;
|
|
590 return (Dynarr_atp (w->line_start_cache, elt + vtarget)->start);
|
|
591 }
|
|
592 }
|
|
593 else
|
|
594 {
|
|
595 /* No vertical motion requested so we just return the position
|
|
596 of the beginning of the current line. */
|
|
597 if (ret_vpos) *ret_vpos = 0;
|
|
598
|
|
599 return (Dynarr_atp (w->line_start_cache, elt)->start);
|
|
600 }
|
|
601
|
|
602 RETURN_NOT_REACHED(0) /* shut up compiler */
|
|
603 }
|
|
604
|
20
|
605 DEFUN ("vertical-motion", Fvertical_motion, 1, 2, 0, /*
|
0
|
606 Move to start of frame line LINES lines down.
|
|
607 If LINES is negative, this is moving up.
|
|
608
|
|
609 The optional second argument WINDOW specifies the window to use for
|
|
610 parameters such as width, horizontal scrolling, and so on.
|
|
611 the default is the selected window.
|
|
612 Note that `vertical-motion' sets WINDOW's buffer's point, not
|
|
613 WINDOW's point. (This differs from FSF Emacs, which buggily always
|
|
614 sets current buffer's point, regardless of WINDOW.)
|
|
615
|
|
616 Sets point to position found; this may be start of line
|
|
617 or just the start of a continuation line.
|
|
618 Returns number of lines moved; may be closer to zero than LINES
|
|
619 if beginning or end of buffer was reached.
|
|
620 Optional second argument is WINDOW to move in.
|
20
|
621 */
|
|
622 (lines, window))
|
0
|
623 {
|
|
624 if (NILP (window))
|
|
625 window = Fselected_window (Qnil);
|
|
626 CHECK_WINDOW (window);
|
|
627 {
|
|
628 Bufpos bufpos;
|
|
629 int vpos;
|
|
630 struct window *w = XWINDOW (window);
|
|
631
|
|
632 CHECK_INT (lines);
|
|
633
|
|
634 bufpos = vmotion (XWINDOW (window), BUF_PT (XBUFFER (w->buffer)),
|
|
635 XINT (lines), &vpos);
|
|
636
|
|
637 /* Note that the buffer's point is set, not the window's point. */
|
|
638 BUF_SET_PT (XBUFFER (w->buffer), bufpos);
|
|
639
|
|
640 return make_int (vpos);
|
|
641 }
|
|
642 }
|
|
643
|
|
644
|
|
645 void
|
|
646 syms_of_indent (void)
|
|
647 {
|
20
|
648 DEFSUBR (Fcurrent_indentation);
|
|
649 DEFSUBR (Findent_to);
|
|
650 DEFSUBR (Fcurrent_column);
|
|
651 DEFSUBR (Fmove_to_column);
|
0
|
652 #if 0 /* #### */
|
20
|
653 DEFSUBR (Fcompute_motion);
|
0
|
654 #endif
|
20
|
655 DEFSUBR (Fvertical_motion);
|
0
|
656 }
|
|
657
|
|
658 void
|
|
659 vars_of_indent (void)
|
|
660 {
|
|
661 DEFVAR_BOOL ("indent-tabs-mode", &indent_tabs_mode /*
|
|
662 *Indentation can insert tabs if this is non-nil.
|
|
663 Setting this variable automatically makes it local to the current buffer.
|
|
664 */ );
|
|
665 indent_tabs_mode = 1;
|
|
666 }
|