Mercurial > hg > octave-nkf
annotate liboctave/oct-rl-edit.c @ 12747:901d466ee55a stable release-3-4-1
Version 3.4.1 released.
* configure.ac (AC_INIT): Version is now 3.4.1.
(OCTAVE_API_VERSION_NUMBER): Now 45.
(OCTAVE_RELEASE_DATE): Now 2011-06-15.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 15 Jun 2011 10:35:37 -0400 |
parents | fd0a3ac60b0e |
children | 72c96de7a403 |
rev | line source |
---|---|
3519 | 1 /* |
2 | |
11523 | 3 Copyright (C) 2000-2011 John W. Eaton |
3519 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
3519 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
3519 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #if defined (USE_READLINE) | |
28 | |
29 #include <stdio.h> | |
30 #include <stdlib.h> | |
31 | |
32 #include <readline/readline.h> | |
33 | |
34 #include "oct-rl-edit.h" | |
35 | |
3933 | 36 #define OCTAVE_RL_SAVE_STRING(ss, s) \ |
37 static char *ss = 0; \ | |
38 \ | |
39 if (ss) \ | |
40 { \ | |
41 free (ss); \ | |
42 ss = 0; \ | |
43 } \ | |
44 \ | |
45 ss = malloc (strlen (s) + 1); \ | |
46 \ | |
47 strcpy (ss, s) | |
48 | |
6979 | 49 void |
50 octave_rl_redisplay (void) | |
51 { | |
52 rl_redisplay (); | |
53 } | |
54 | |
3519 | 55 int |
56 octave_rl_screen_height (void) | |
57 { | |
3779 | 58 int rows, cols; |
59 rl_get_screen_size (&rows, &cols); | |
60 return rows; | |
3519 | 61 } |
62 | |
63 int | |
64 octave_rl_screen_width (void) | |
65 { | |
3779 | 66 int rows, cols; |
67 rl_get_screen_size (&rows, &cols); | |
68 return cols; | |
3519 | 69 } |
70 | |
71 void | |
3779 | 72 octave_rl_enable_paren_matching (int val) |
3519 | 73 { |
3779 | 74 rl_variable_bind ("blink-matching-paren", val ? "1" : "0"); |
3519 | 75 } |
76 | |
3946 | 77 /* It would be much simpler if we could just call _rl_clear_screen to |
78 only clear the screen, but it is not a public function, and on some | |
79 systems, it is not exported from shared library versions of | |
80 readline, so we can't use it. | |
81 | |
82 Instead, temporarily redefine the redisplay function to do nothing. | |
83 | |
5775 | 84 FIXME -- It would be safer to do this when protected from |
3946 | 85 interrupts... */ |
3856 | 86 |
87 static void | |
5394 | 88 flush_stdout (void) |
3856 | 89 { |
5394 | 90 fflush (stdout); |
3856 | 91 } |
92 | |
3519 | 93 void |
94 octave_rl_clear_screen (void) | |
95 { | |
3855 | 96 int ignore1 = 0; |
97 int ignore2 = 0; | |
98 | |
3856 | 99 rl_voidfunc_t *saved_redisplay_function = rl_redisplay_function; |
5394 | 100 rl_redisplay_function = flush_stdout; |
3855 | 101 |
102 rl_clear_screen (ignore1, ignore2); | |
3856 | 103 |
104 rl_redisplay_function = saved_redisplay_function; | |
3519 | 105 } |
106 | |
107 void | |
108 octave_rl_resize_terminal (void) | |
109 { | |
110 rl_resize_terminal (); | |
111 } | |
112 | |
113 void | |
114 octave_rl_restore_terminal_state () | |
115 { | |
116 if (rl_deprep_term_function) | |
117 rl_deprep_term_function (); | |
118 } | |
119 | |
120 void | |
121 octave_rl_insert_text (const char *s) | |
122 { | |
123 rl_insert_text (s); | |
124 } | |
125 | |
6979 | 126 int |
127 octave_rl_newline (int count, int key) | |
3519 | 128 { |
6979 | 129 return rl_newline (count, key); |
130 } | |
131 | |
132 const char * | |
133 octave_rl_line_buffer (void) | |
134 { | |
135 return rl_line_buffer; | |
3519 | 136 } |
137 | |
138 void | |
139 octave_rl_clear_undo_list (void) | |
140 { | |
141 if (rl_undo_list) | |
142 { | |
3779 | 143 rl_free_undo_list (); |
3519 | 144 |
145 rl_undo_list = 0; | |
146 } | |
147 } | |
148 | |
149 void | |
150 octave_rl_set_name (const char *n) | |
151 { | |
3933 | 152 OCTAVE_RL_SAVE_STRING (nm, n); |
3519 | 153 |
154 rl_readline_name = nm; | |
155 | |
156 /* Since we've already called rl_initialize, we need to re-read the | |
157 init file to take advantage of the conditional parsing feature | |
158 based on rl_readline_name; */ | |
159 | |
3779 | 160 rl_re_read_init_file (0, 0); |
3519 | 161 } |
162 | |
163 char * | |
164 octave_rl_readline (const char *prompt) | |
165 { | |
166 return readline (prompt); | |
167 } | |
168 | |
169 void | |
170 octave_rl_set_input_stream (FILE *f) | |
171 { | |
172 rl_instream = f; | |
173 } | |
174 | |
175 FILE * | |
176 octave_rl_get_input_stream (void) | |
177 { | |
178 return rl_instream; | |
179 } | |
180 | |
181 void | |
182 octave_rl_set_output_stream (FILE *f) | |
183 { | |
184 rl_outstream = f; | |
185 } | |
186 | |
187 FILE * | |
188 octave_rl_get_output_stream (void) | |
189 { | |
190 return rl_outstream; | |
191 } | |
192 | |
193 void | |
194 octave_rl_read_init_file (const char *f) | |
195 { | |
7757
4ff9a6fdde42
Load the default inputrc when calling read_readline_init_file()
Rafael Laboissiere <rafael@debian.org>
parents:
7017
diff
changeset
|
196 rl_read_init_file (f); |
3519 | 197 } |
198 | |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7757
diff
changeset
|
199 void |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7757
diff
changeset
|
200 octave_rl_re_read_init_file (void) |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7757
diff
changeset
|
201 { |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7757
diff
changeset
|
202 rl_re_read_init_file (0, 0); |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7757
diff
changeset
|
203 } |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7757
diff
changeset
|
204 |
4143 | 205 int |
206 octave_rl_filename_completion_desired (int arg) | |
207 { | |
208 int retval = rl_filename_completion_desired; | |
209 rl_filename_completion_desired = arg; | |
210 return retval; | |
211 } | |
212 | |
6979 | 213 int |
214 octave_rl_filename_quoting_desired (int arg) | |
215 { | |
216 int retval = rl_filename_quoting_desired; | |
217 rl_filename_quoting_desired = arg; | |
218 return retval; | |
219 } | |
220 | |
4604 | 221 char * |
222 octave_rl_filename_completion_function (const char *text, int state) | |
223 { | |
224 return rl_filename_completion_function (text, state); | |
225 } | |
226 | |
3519 | 227 void |
3933 | 228 octave_rl_set_basic_word_break_characters (const char *s) |
229 { | |
230 OCTAVE_RL_SAVE_STRING (ss, s); | |
231 | |
232 rl_basic_word_break_characters = ss; | |
233 } | |
234 | |
235 void | |
236 octave_rl_set_completer_word_break_characters (const char *s) | |
237 { | |
238 OCTAVE_RL_SAVE_STRING (ss, s); | |
239 | |
240 rl_completer_word_break_characters = ss; | |
241 } | |
242 | |
243 void | |
3519 | 244 octave_rl_set_basic_quote_characters (const char *s) |
245 { | |
3933 | 246 OCTAVE_RL_SAVE_STRING (ss, s); |
3519 | 247 |
248 rl_basic_quote_characters = ss; | |
249 } | |
250 | |
251 void | |
6979 | 252 octave_rl_set_filename_quote_characters (const char *s) |
253 { | |
254 OCTAVE_RL_SAVE_STRING (ss, s); | |
255 | |
256 rl_filename_quote_characters = ss; | |
257 } | |
258 | |
259 void | |
260 octave_rl_set_completer_quote_characters (const char *s) | |
261 { | |
262 OCTAVE_RL_SAVE_STRING (ss, s); | |
263 | |
264 rl_completer_quote_characters = ss; | |
265 } | |
266 | |
267 void | |
3519 | 268 octave_rl_set_completion_append_character (char c) |
269 { | |
270 rl_completion_append_character = c; | |
271 } | |
272 | |
273 void | |
274 octave_rl_set_completion_function (rl_attempted_completion_fcn_ptr f) | |
275 { | |
276 rl_attempted_completion_function = f; | |
277 } | |
278 | |
279 void | |
6979 | 280 octave_rl_set_quoting_function (rl_quoting_fcn_ptr f) |
281 { | |
282 rl_filename_quoting_function = f; | |
283 } | |
284 | |
285 void | |
286 octave_rl_set_dequoting_function (rl_dequoting_fcn_ptr f) | |
287 { | |
288 rl_filename_dequoting_function = f; | |
289 } | |
290 | |
291 void | |
292 octave_rl_set_char_is_quoted_function (rl_char_is_quoted_fcn_ptr f) | |
293 { | |
294 rl_char_is_quoted_p = f; | |
295 } | |
296 | |
297 void | |
3519 | 298 octave_rl_set_startup_hook (rl_startup_hook_fcn_ptr f) |
299 { | |
4802 | 300 rl_startup_hook = f; |
3519 | 301 } |
302 | |
303 rl_startup_hook_fcn_ptr | |
304 octave_rl_get_startup_hook (void) | |
305 { | |
4802 | 306 return rl_startup_hook; |
3519 | 307 } |
308 | |
309 void | |
310 octave_rl_set_event_hook (rl_event_hook_fcn_ptr f) | |
311 { | |
4802 | 312 rl_event_hook = f; |
3519 | 313 } |
314 | |
315 rl_event_hook_fcn_ptr | |
316 octave_rl_get_event_hook (void) | |
317 { | |
4802 | 318 return rl_event_hook; |
3519 | 319 } |
320 | |
321 char ** | |
322 octave_rl_completion_matches (const char *text, rl_completer_fcn_ptr f) | |
323 { | |
3779 | 324 return rl_completion_matches (text, f); |
3519 | 325 } |
326 | |
327 char | |
328 octave_rl_prompt_start_ignore (void) | |
329 { | |
330 return RL_PROMPT_START_IGNORE; | |
331 } | |
332 | |
333 char | |
334 octave_rl_prompt_end_ignore (void) | |
335 { | |
336 return RL_PROMPT_END_IGNORE; | |
337 } | |
338 | |
339 void | |
340 octave_rl_add_defun (const char *name, rl_fcn_ptr f, char key) | |
341 { | |
342 rl_add_defun (name, f, key); | |
343 } | |
344 | |
345 void | |
346 octave_rl_set_terminal_name (const char *term) | |
347 { | |
10102
8b4e3388a254
oct-rl-edit.c (octave_rl_set_terminal_name): save term string before setting rl_terminal_name
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
348 OCTAVE_RL_SAVE_STRING (saved_term, term); |
8b4e3388a254
oct-rl-edit.c (octave_rl_set_terminal_name): save term string before setting rl_terminal_name
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
349 |
8b4e3388a254
oct-rl-edit.c (octave_rl_set_terminal_name): save term string before setting rl_terminal_name
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
350 rl_terminal_name = saved_term; |
3519 | 351 } |
352 | |
353 void | |
354 octave_rl_initialize (void) | |
355 { | |
356 rl_initialize (); | |
357 } | |
358 | |
359 int | |
360 octave_rl_history_search_forward (int count, int ignore) | |
361 { | |
362 return rl_history_search_forward (count, ignore); | |
363 } | |
364 | |
365 int | |
366 octave_rl_history_search_backward (int count, int ignore) | |
367 { | |
368 return rl_history_search_backward (count, ignore); | |
369 } | |
370 | |
371 char | |
372 octave_rl_ctrl (char c) | |
373 { | |
374 return CTRL (c); | |
375 } | |
376 | |
377 char | |
378 octave_rl_meta (char c) | |
379 { | |
380 return META (c); | |
381 } | |
382 | |
383 #endif |