annotate src/indent.c @ 16:0293115a14e9 r19-15b91

Import from CVS: tag r19-15b91
author cvs
date Mon, 13 Aug 2007 08:49:20 +0200
parents 376386a54a3c
children 859a2309aef8
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. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
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 */
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
169 col ++;
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
170 #endif /* XEmacs */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 if (tab_seen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 col = ((col + tab_width) / tab_width) * tab_width;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 col += post_tab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 if (cur_col)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 last_known_column_buffer = buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 last_known_column = col;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 last_known_column_point = BUF_PT (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 last_known_column_modified = BUF_MODIFF (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 return col;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 current_column (struct buffer *buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 if (buf == last_known_column_buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 && BUF_PT (buf) == last_known_column_point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 && BUF_MODIFF (buf) == last_known_column_modified)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 return last_known_column;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 return column_at_point (buf, BUF_PT (buf), 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 DEFUN ("current-column", Fcurrent_column, Scurrent_column, 0, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 Return the horizontal position of point. Beginning of line is column 0.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 This is calculated by adding together the widths of all the displayed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 representations of the character between the start of the previous line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 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
207 will have a variable width.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 Ignores finite width of frame, which means that this function may return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 values greater than (frame-width).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 Whether the line is visible (if `selective-display' is t) has no effect;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 however, ^M is treated as end of line when `selective-display' is t.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 If BUFFER is nil, the current buffer is assumed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 Lisp_Object buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 return (make_int (current_column (decode_buffer (buffer, 0))));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 DEFUN ("indent-to", Findent_to, Sindent_to, 1, 3, "NIndent to column: " /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 Indent from point with tabs and spaces until COLUMN is reached.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 Optional second argument MIN says always do at least MIN spaces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 even if that goes past COLUMN; by default, MIN is zero.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 If BUFFER is nil, the current buffer is assumed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (col, minimum, buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 Lisp_Object col, minimum, buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 int mincol;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 int fromcol;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 struct buffer *buf = decode_buffer (buffer, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 int tab_width = XINT (buf->tab_width);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 Bufpos opoint = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 CHECK_INT (col);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 if (NILP (minimum))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 minimum = Qzero;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 CHECK_INT (minimum);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 XSETBUFFER (buffer, buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 fromcol = current_column (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 mincol = fromcol + XINT (minimum);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 if (mincol < XINT (col)) mincol = XINT (col);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 if (fromcol == mincol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 return make_int (mincol);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
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 (!NILP (Fextent_at (make_int (BUF_PT (buf)), buffer, Qinvisible,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 Qnil, Qnil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 Bufpos last_visible = last_visible_position (BUF_PT (buf), buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 opoint = BUF_PT (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 if (last_visible >= BUF_BEGV (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 BUF_SET_PT (buf, last_visible);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 error ("Visible portion of buffer not modifiable");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 if (indent_tabs_mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 int n = mincol / tab_width - fromcol / tab_width;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 if (n != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 Finsert_char (make_char ('\t'), make_int (n), Qnil, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 fromcol = (mincol / tab_width) * tab_width;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 Finsert_char (make_char (' '), make_int (mincol - fromcol), Qnil, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 last_known_column_buffer = buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 last_known_column = mincol;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 last_known_column_point = BUF_PT (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 last_known_column_modified = BUF_MODIFF (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 /* Not in FSF: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 if (opoint > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 BUF_SET_PT (buf, opoint);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 return (make_int (mincol));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 bi_spaces_at_point (struct buffer *b, Bytind bi_pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 Bytind bi_end = BI_BUF_ZV (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 int col = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 Emchar c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 int tab_width = XINT (b->tab_width);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 if (tab_width <= 0 || tab_width > 1000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 tab_width = 8;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 while (bi_pos < bi_end &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (c = BI_BUF_FETCH_CHAR (b, bi_pos),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (c == '\t'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 ? (col += tab_width - col % tab_width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 : (c == ' ' ? ++col : 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 INC_BYTIND (b, bi_pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 return col;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 DEFUN ("current-indentation", Fcurrent_indentation, Scurrent_indentation,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 0, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 Return the indentation of the current line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 This is the horizontal position of the character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 following any initial whitespace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 Lisp_Object buffer;
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 DEFUN ("move-to-column", Fmove_to_column, Smove_to_column, 1, 3, 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.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (column, force, buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 Lisp_Object column, force, buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 Bufpos pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 struct buffer *buf = decode_buffer (buffer, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 int col = current_column (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 int goal;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 Bufpos end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 int tab_width = XINT (buf->tab_width);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 int prev_col = 0;
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
362 Emchar c;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 XSETBUFFER (buffer, buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 CHECK_NATNUM (column);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 goal = XINT (column);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 retry:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 pos = BUF_PT (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 end = BUF_ZV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 /* If we're starting past the desired column,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 back up to beginning of line and scan from there. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 if (col > goal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 pos = find_next_newline (buf, pos, -1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 col = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 while (col < goal && pos < end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 c = BUF_FETCH_CHAR (buf, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 if (c == '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 if (c == '\r' && EQ (buf->selective_display, Qt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 if (c == '\t')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 prev_col = col;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 col += tab_width;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 col = col / tab_width * tab_width;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 /* #### oh for the days of the complete new redisplay */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 /* #### FSFmacs looks at ctl_arrow, display tables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 We need to do similar. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 displayed_glyphs = glyphs_from_bufpos (selected_frame (),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 buf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 XWINDOW (Fselected_window (Qnil)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 pos, dp, 0, col, 0, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 col += (displayed_glyphs->columns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 - (displayed_glyphs->begin_columns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 + displayed_glyphs->end_columns));
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
407 #else /* XEmacs */
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
408 col ++;
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
409 #endif /* XEmacs */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 pos++;
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 BUF_SET_PT (buf, 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 /* If a tab char made us overshoot, change it to spaces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 and scan through it again. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 if (!NILP (force) && col > goal && c == '\t' && prev_col < goal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 buffer_delete_range (buf, BUF_PT (buf) - 1, BUF_PT (buf), 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 Findent_to (make_int (col - 1), Qzero, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 buffer_insert_emacs_char (buf, ' ');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 goto retry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 /* If line ends prematurely, add space to the end. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 if (col < goal && !NILP (force))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 col = goal;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 Findent_to (make_int (col), Qzero, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 last_known_column_buffer = buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 last_known_column = col;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 last_known_column_point = BUF_PT (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 last_known_column_modified = BUF_MODIFF (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 return (make_int (col));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 #if 0 /* #### OK boys, this function needs to be present, I think.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 It was there before the 19.12 redisplay rewrite. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 xxDEFUN ("compute-motion", Fcompute_motion, Scompute_motion, 7, 7, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 "Scan through the current buffer, calculating screen position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 Scan the current buffer forward from offset FROM,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 assuming it is at position FROMPOS--a cons of the form (HPOS . VPOS)--
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 to position TO or position TOPOS--another cons of the form (HPOS . VPOS)--
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 and return the ending buffer position and screen location.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 There are three additional arguments:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 WIDTH is the number of columns available to display text;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 this affects handling of continuation lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 This is usually the value returned by `window-width', less one (to allow
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 for the continuation glyph).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 OFFSETS is either nil or a cons cell (HSCROLL . TAB-OFFSET).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 HSCROLL is the number of columns not being displayed at the left
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 margin; this is usually taken from a window's hscroll member.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 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
463 being displayed, perhaps because the line was continued within it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 If OFFSETS is nil, HSCROLL and TAB-OFFSET are assumed to be zero.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 WINDOW is the window to operate on. Currently this is used only to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 find the display table. It does not matter what buffer WINDOW displays;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 `compute-motion' always operates on the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 The value is a list of five elements:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (POS HPOS VPOS PREVHPOS CONTIN)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 POS is the buffer position where the scan stopped.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 VPOS is the vertical position where the scan stopped.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 HPOS is the horizontal position where the scan stopped.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 PREVHPOS is the horizontal position one character back from POS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 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
478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 For example, to find the buffer position of column COL of line LINE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 of a certain window, pass the window's starting location as FROM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 and the window's upper-left coordinates as FROMPOS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 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
483 visible section of the buffer, and pass LINE and COL as TOPOS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (from, frompos, to, topos, width, offsets, window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 Lisp_Object from, frompos, to, topos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 Lisp_Object width, offsets, window;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 Lisp_Object bufpos, hpos, vpos, prevhpos, contin;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 struct position *pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 int hscroll, tab_offset;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 struct window *w = decode_window (window);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 CHECK_INT_COERCE_MARKER (from);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 CHECK_CONS (frompos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 CHECK_INT (XCAR (frompos));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 CHECK_INT (XCDR (frompos));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 CHECK_INT_COERCE_MARKER (to);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 CHECK_CONS (topos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 CHECK_INT (XCAR (topos));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 CHECK_INT (XCDR (topos));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 CHECK_INT (width);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 if (!NILP (offsets))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 CHECK_CONS (offsets);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 CHECK_INT (XCAR (offsets));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 CHECK_INT (XCDR (offsets));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 hscroll = XINT (XCAR (offsets));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 tab_offset = XINT (XCDR (offsets));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 hscroll = tab_offset = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 pos = compute_motion (XINT (from), XINT (XCDR (frompos)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 XINT (XCAR (frompos)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 XINT (to), XINT (XCDR (topos)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 XINT (XCAR (topos)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 XINT (width), hscroll, tab_offset, w);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 XSETINT (bufpos, pos->bufpos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 XSETINT (hpos, pos->hpos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 XSETINT (vpos, pos->vpos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 XSETINT (prevhpos, pos->prevhpos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 return list5 (bufpos,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 hpos,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 vpos,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 prevhpos,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 pos->contin ? Qt : Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
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 #endif /* 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 /*****************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 vmotion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 Given a starting position ORIG, move point VTARGET lines in WINDOW.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 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
540 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
541 returned in it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 ****************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 vmotion (struct window *w, Bufpos orig, int vtarget, int *ret_vpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 struct buffer *b = XBUFFER (w->buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 int elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 elt = point_in_line_start_cache (w, orig, (vtarget < 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 ? -vtarget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 : vtarget));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 /* #### This assertion must be true before the if statements are hit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 but may possibly be wrong after the call to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 point_in_line_start_cache if orig is outside of the visible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 region of the buffer. Handle this. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 assert (elt >= 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 /* Moving downward. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 if (vtarget > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 int cur_line = Dynarr_length (w->line_start_cache) - 1 - elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 Bufpos ret_pt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 if (cur_line > vtarget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 cur_line = vtarget;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 /* The traditional FSF behavior is to return the end of buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 position if we couldn't move far enough because we hit it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 if (cur_line < vtarget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 ret_pt = BUF_ZV (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 ret_pt = Dynarr_atp (w->line_start_cache, cur_line + elt)->start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 while (ret_pt > BUF_ZV (b) && cur_line > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 cur_line--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 ret_pt = Dynarr_atp (w->line_start_cache, cur_line + elt)->start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 if (ret_vpos) *ret_vpos = cur_line;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 return (ret_pt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 else if (vtarget < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 if (elt < -vtarget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 if (ret_vpos) *ret_vpos = -elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 /* #### This should be BUF_BEGV (b), right? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 return (Dynarr_atp (w->line_start_cache, 0)->start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 if (ret_vpos) *ret_vpos = vtarget;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 return (Dynarr_atp (w->line_start_cache, elt + vtarget)->start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 /* No vertical motion requested so we just return the position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 of the beginning of the current line. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 if (ret_vpos) *ret_vpos = 0;
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 (Dynarr_atp (w->line_start_cache, elt)->start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 RETURN_NOT_REACHED(0) /* shut up compiler */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 DEFUN ("vertical-motion", Fvertical_motion, Svertical_motion, 1, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 Move to start of frame line LINES lines down.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 If LINES is negative, this is moving up.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 The optional second argument WINDOW specifies the window to use for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 parameters such as width, horizontal scrolling, and so on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 the default is the selected window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 Note that `vertical-motion' sets WINDOW's buffer's point, not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 WINDOW's point. (This differs from FSF Emacs, which buggily always
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 sets current buffer's point, regardless of WINDOW.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 Sets point to position found; this may be start of line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 or just the start of a continuation line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 Returns number of lines moved; may be closer to zero than LINES
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 if beginning or end of buffer was reached.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 Optional second argument is WINDOW to move in.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (lines, window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 Lisp_Object lines, 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 if (NILP (window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 window = Fselected_window (Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 CHECK_WINDOW (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 Bufpos bufpos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 int vpos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 struct window *w = XWINDOW (window);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 CHECK_INT (lines);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 bufpos = vmotion (XWINDOW (window), BUF_PT (XBUFFER (w->buffer)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 XINT (lines), &vpos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 /* Note that the buffer's point is set, not the window's point. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 BUF_SET_PT (XBUFFER (w->buffer), bufpos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 return make_int (vpos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 syms_of_indent (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 defsubr (&Scurrent_indentation);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 defsubr (&Sindent_to);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 defsubr (&Scurrent_column);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 defsubr (&Smove_to_column);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 #if 0 /* #### */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 defsubr (&Scompute_motion);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 defsubr (&Svertical_motion);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 vars_of_indent (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 DEFVAR_BOOL ("indent-tabs-mode", &indent_tabs_mode /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 *Indentation can insert tabs if this is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 Setting this variable automatically makes it local to the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 indent_tabs_mode = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 }