Mercurial > octave
annotate liboctave/util/oct-rl-edit.c @ 17958:1adf3710bb68
Working CTRL-C handling implementation for Win32.
* libgui/src/thread-manager.cc (sighandlers.h): New include.
(windows_thread_manager::interrupt): Call w32_raise_sigint instead of
::raise.
* libinterp/corefcn/sighandlers.h (w32_raise_sigint): New declatation.
* libinterp/cirefcn/sighandlers.cc (user_abort): Forward declare.
(class w32_interrupt_manager): New singleton helper class.
(w32_raise_sigint): New function.
(user_abort): Call
w32_interrupt_manager::octave_jump_to_enclosing_context instead of
octave_jump_to_enclosing_context on Win32 platform.
(sigint_handler): Call w32_interrupt_manager::user_abort instead of
user_abort on Win32 platform.
(octave_catch_interrupts, octave_ignore_interrupts,
octave_set_interrupt_handler): Call w32_interrupt_manager::init on
Win32 platform.
* liboctave/util/oct-rl-edit.c (octave_rl_initialize): Set
rl_catch_signals to 0 on Win32 platform.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Tue, 19 Nov 2013 14:21:38 -0500 |
parents | d63878346099 |
children | d7f642d68817 ad93e9be78ee |
rev | line source |
---|---|
3519 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
16570
diff
changeset
|
3 Copyright (C) 2000-2013 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 |
16537
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16536
diff
changeset
|
94 octave_rl_clear_screen (int skip_redisplay) |
3519 | 95 { |
3855 | 96 int ignore1 = 0; |
97 int ignore2 = 0; | |
98 | |
16537
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16536
diff
changeset
|
99 if (skip_redisplay) |
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16536
diff
changeset
|
100 { |
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16536
diff
changeset
|
101 rl_voidfunc_t *saved_redisplay_function = rl_redisplay_function; |
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16536
diff
changeset
|
102 |
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16536
diff
changeset
|
103 rl_redisplay_function = flush_stdout; |
3855 | 104 |
16537
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16536
diff
changeset
|
105 rl_clear_screen (ignore1, ignore2); |
3856 | 106 |
16537
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16536
diff
changeset
|
107 rl_redisplay_function = saved_redisplay_function; |
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16536
diff
changeset
|
108 } |
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16536
diff
changeset
|
109 else |
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16536
diff
changeset
|
110 rl_clear_screen (ignore1, ignore2); |
3519 | 111 } |
112 | |
113 void | |
114 octave_rl_resize_terminal (void) | |
115 { | |
116 rl_resize_terminal (); | |
117 } | |
118 | |
119 void | |
120 octave_rl_restore_terminal_state () | |
121 { | |
122 if (rl_deprep_term_function) | |
123 rl_deprep_term_function (); | |
124 } | |
125 | |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
126 char * |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
127 octave_rl_copy_line (void) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
128 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
129 return rl_copy_text (0, rl_end); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
130 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
131 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
132 void |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
133 octave_rl_replace_line (const char *s, int clear_undo) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
134 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
135 rl_replace_line (s, clear_undo); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
136 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
137 |
3519 | 138 void |
139 octave_rl_insert_text (const char *s) | |
140 { | |
141 rl_insert_text (s); | |
142 } | |
143 | |
6979 | 144 int |
145 octave_rl_newline (int count, int key) | |
3519 | 146 { |
6979 | 147 return rl_newline (count, key); |
148 } | |
149 | |
150 const char * | |
151 octave_rl_line_buffer (void) | |
152 { | |
153 return rl_line_buffer; | |
3519 | 154 } |
155 | |
16539
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
156 int |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
157 octave_rl_do_undo (void) |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
158 { |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
159 return rl_do_undo (); |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
160 } |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
161 |
3519 | 162 void |
163 octave_rl_clear_undo_list (void) | |
164 { | |
165 if (rl_undo_list) | |
166 { | |
3779 | 167 rl_free_undo_list (); |
3519 | 168 |
169 rl_undo_list = 0; | |
170 } | |
171 } | |
172 | |
173 void | |
174 octave_rl_set_name (const char *n) | |
175 { | |
3933 | 176 OCTAVE_RL_SAVE_STRING (nm, n); |
3519 | 177 |
178 rl_readline_name = nm; | |
179 | |
180 /* Since we've already called rl_initialize, we need to re-read the | |
181 init file to take advantage of the conditional parsing feature | |
182 based on rl_readline_name; */ | |
183 | |
3779 | 184 rl_re_read_init_file (0, 0); |
3519 | 185 } |
186 | |
187 char * | |
188 octave_rl_readline (const char *prompt) | |
189 { | |
190 return readline (prompt); | |
191 } | |
192 | |
193 void | |
194 octave_rl_set_input_stream (FILE *f) | |
195 { | |
196 rl_instream = f; | |
197 } | |
198 | |
199 FILE * | |
200 octave_rl_get_input_stream (void) | |
201 { | |
202 return rl_instream; | |
203 } | |
204 | |
205 void | |
206 octave_rl_set_output_stream (FILE *f) | |
207 { | |
208 rl_outstream = f; | |
209 } | |
210 | |
211 FILE * | |
212 octave_rl_get_output_stream (void) | |
213 { | |
214 return rl_outstream; | |
215 } | |
216 | |
217 void | |
218 octave_rl_read_init_file (const char *f) | |
219 { | |
7757
4ff9a6fdde42
Load the default inputrc when calling read_readline_init_file()
Rafael Laboissiere <rafael@debian.org>
parents:
7017
diff
changeset
|
220 rl_read_init_file (f); |
3519 | 221 } |
222 | |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7757
diff
changeset
|
223 void |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7757
diff
changeset
|
224 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
|
225 { |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7757
diff
changeset
|
226 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
|
227 } |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7757
diff
changeset
|
228 |
4143 | 229 int |
230 octave_rl_filename_completion_desired (int arg) | |
231 { | |
232 int retval = rl_filename_completion_desired; | |
233 rl_filename_completion_desired = arg; | |
234 return retval; | |
235 } | |
236 | |
6979 | 237 int |
238 octave_rl_filename_quoting_desired (int arg) | |
239 { | |
240 int retval = rl_filename_quoting_desired; | |
241 rl_filename_quoting_desired = arg; | |
242 return retval; | |
243 } | |
244 | |
16382
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
245 void |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
246 octave_rl_done (int arg) |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
247 { |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
248 rl_done = arg; |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
249 } |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
250 |
4604 | 251 char * |
252 octave_rl_filename_completion_function (const char *text, int state) | |
253 { | |
254 return rl_filename_completion_function (text, state); | |
255 } | |
256 | |
3519 | 257 void |
3933 | 258 octave_rl_set_basic_word_break_characters (const char *s) |
259 { | |
260 OCTAVE_RL_SAVE_STRING (ss, s); | |
261 | |
262 rl_basic_word_break_characters = ss; | |
263 } | |
264 | |
265 void | |
266 octave_rl_set_completer_word_break_characters (const char *s) | |
267 { | |
268 OCTAVE_RL_SAVE_STRING (ss, s); | |
269 | |
270 rl_completer_word_break_characters = ss; | |
271 } | |
272 | |
273 void | |
3519 | 274 octave_rl_set_basic_quote_characters (const char *s) |
275 { | |
3933 | 276 OCTAVE_RL_SAVE_STRING (ss, s); |
3519 | 277 |
278 rl_basic_quote_characters = ss; | |
279 } | |
280 | |
281 void | |
6979 | 282 octave_rl_set_filename_quote_characters (const char *s) |
283 { | |
284 OCTAVE_RL_SAVE_STRING (ss, s); | |
285 | |
286 rl_filename_quote_characters = ss; | |
287 } | |
288 | |
289 void | |
290 octave_rl_set_completer_quote_characters (const char *s) | |
291 { | |
292 OCTAVE_RL_SAVE_STRING (ss, s); | |
293 | |
294 rl_completer_quote_characters = ss; | |
295 } | |
296 | |
297 void | |
3519 | 298 octave_rl_set_completion_append_character (char c) |
299 { | |
300 rl_completion_append_character = c; | |
301 } | |
302 | |
303 void | |
304 octave_rl_set_completion_function (rl_attempted_completion_fcn_ptr f) | |
305 { | |
306 rl_attempted_completion_function = f; | |
307 } | |
308 | |
309 void | |
6979 | 310 octave_rl_set_quoting_function (rl_quoting_fcn_ptr f) |
311 { | |
312 rl_filename_quoting_function = f; | |
313 } | |
314 | |
315 void | |
316 octave_rl_set_dequoting_function (rl_dequoting_fcn_ptr f) | |
317 { | |
318 rl_filename_dequoting_function = f; | |
319 } | |
320 | |
321 void | |
322 octave_rl_set_char_is_quoted_function (rl_char_is_quoted_fcn_ptr f) | |
323 { | |
324 rl_char_is_quoted_p = f; | |
325 } | |
326 | |
327 void | |
3519 | 328 octave_rl_set_startup_hook (rl_startup_hook_fcn_ptr f) |
329 { | |
4802 | 330 rl_startup_hook = f; |
3519 | 331 } |
332 | |
333 rl_startup_hook_fcn_ptr | |
334 octave_rl_get_startup_hook (void) | |
335 { | |
4802 | 336 return rl_startup_hook; |
3519 | 337 } |
338 | |
339 void | |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
340 octave_rl_set_pre_input_hook (rl_pre_input_hook_fcn_ptr f) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
341 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
342 rl_pre_input_hook = f; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
343 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
344 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
345 rl_pre_input_hook_fcn_ptr |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
346 octave_rl_get_pre_input_hook (void) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
347 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
348 return rl_pre_input_hook; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
349 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
350 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
351 void |
3519 | 352 octave_rl_set_event_hook (rl_event_hook_fcn_ptr f) |
353 { | |
4802 | 354 rl_event_hook = f; |
3519 | 355 } |
356 | |
357 rl_event_hook_fcn_ptr | |
358 octave_rl_get_event_hook (void) | |
359 { | |
4802 | 360 return rl_event_hook; |
3519 | 361 } |
362 | |
363 char ** | |
364 octave_rl_completion_matches (const char *text, rl_completer_fcn_ptr f) | |
365 { | |
3779 | 366 return rl_completion_matches (text, f); |
3519 | 367 } |
368 | |
369 char | |
370 octave_rl_prompt_start_ignore (void) | |
371 { | |
372 return RL_PROMPT_START_IGNORE; | |
373 } | |
374 | |
375 char | |
376 octave_rl_prompt_end_ignore (void) | |
377 { | |
378 return RL_PROMPT_END_IGNORE; | |
379 } | |
380 | |
381 void | |
382 octave_rl_add_defun (const char *name, rl_fcn_ptr f, char key) | |
383 { | |
384 rl_add_defun (name, f, key); | |
385 } | |
386 | |
387 void | |
388 octave_rl_set_terminal_name (const char *term) | |
389 { | |
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
|
390 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
|
391 |
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
|
392 rl_terminal_name = saved_term; |
3519 | 393 } |
394 | |
395 void | |
396 octave_rl_initialize (void) | |
397 { | |
17958
1adf3710bb68
Working CTRL-C handling implementation for Win32.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17744
diff
changeset
|
398 #if defined (__WIN32__) && ! defined (__CYGWIN__) |
1adf3710bb68
Working CTRL-C handling implementation for Win32.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17744
diff
changeset
|
399 rl_catch_signals = 0; |
1adf3710bb68
Working CTRL-C handling implementation for Win32.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17744
diff
changeset
|
400 #endif |
1adf3710bb68
Working CTRL-C handling implementation for Win32.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17744
diff
changeset
|
401 |
3519 | 402 rl_initialize (); |
403 } | |
404 | |
405 int | |
406 octave_rl_history_search_forward (int count, int ignore) | |
407 { | |
408 return rl_history_search_forward (count, ignore); | |
409 } | |
410 | |
411 int | |
412 octave_rl_history_search_backward (int count, int ignore) | |
413 { | |
414 return rl_history_search_backward (count, ignore); | |
415 } | |
416 | |
417 char | |
418 octave_rl_ctrl (char c) | |
419 { | |
420 return CTRL (c); | |
421 } | |
422 | |
423 char | |
424 octave_rl_meta (char c) | |
425 { | |
426 return META (c); | |
427 } | |
428 | |
429 #endif |