annotate src/indent.c @ 235:85a06df23a9a r20-5b16

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