Mercurial > hg > octave-nkf
annotate liboctave/util/cmd-edit.cc @ 16660:cbb1bb7a5c3d
Added tag ss-3-7-5 for changeset 608e307b4914
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 14 May 2013 05:23:53 -0400 |
parents | d5ae5aa80d42 |
children | ca9a9c0740c5 |
rev | line source |
---|---|
2926 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
3 Copyright (C) 1996-2012 John W. Eaton |
2926 | 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. | |
2926 | 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/>. | |
2926 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
10463
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
27 #include <cstdlib> |
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
28 #include <cstring> |
2926 | 29 |
30 #include <string> | |
31 | |
32 #include <sys/types.h> | |
33 #include <unistd.h> | |
34 | |
5247 | 35 #include "quit.h" |
36 | |
2926 | 37 #include "cmd-edit.h" |
38 #include "cmd-hist.h" | |
5872 | 39 #include "file-ops.h" |
2926 | 40 #include "lo-error.h" |
41 #include "lo-utils.h" | |
42 #include "oct-env.h" | |
7936
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
43 #include "oct-mutex.h" |
3260 | 44 #include "oct-time.h" |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
45 #include "singleton-cleanup.h" |
2926 | 46 |
47 command_editor *command_editor::instance = 0; | |
48 | |
6913 | 49 std::set<command_editor::startup_hook_fcn> command_editor::startup_hook_set; |
50 | |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
51 std::set<command_editor::pre_input_hook_fcn> command_editor::pre_input_hook_set; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
52 |
6913 | 53 std::set<command_editor::event_hook_fcn> command_editor::event_hook_set; |
54 | |
7936
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
55 static octave_mutex event_hook_lock; |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
56 |
2926 | 57 #if defined (USE_READLINE) |
58 | |
59 #include <cstdio> | |
60 #include <cstdlib> | |
61 | |
3519 | 62 #include "oct-rl-edit.h" |
2926 | 63 |
64 class | |
65 gnu_readline : public command_editor | |
66 { | |
67 public: | |
68 | |
3519 | 69 typedef command_editor::startup_hook_fcn startup_hook_fcn; |
70 | |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
71 typedef command_editor::pre_input_hook_fcn pre_input_hook_fcn; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
72 |
6913 | 73 typedef command_editor::event_hook_fcn event_hook_fcn; |
2926 | 74 |
2941 | 75 typedef command_editor::completion_fcn completion_fcn; |
76 | |
2926 | 77 gnu_readline (void); |
78 | |
79 ~gnu_readline (void) { } | |
80 | |
3504 | 81 void do_set_name (const std::string& n); |
2926 | 82 |
3504 | 83 std::string do_readline (const std::string& prompt, bool& eof); |
2926 | 84 |
85 void do_set_input_stream (FILE *f); | |
86 | |
87 FILE *do_get_input_stream (void); | |
88 | |
89 void do_set_output_stream (FILE *f); | |
90 | |
91 FILE *do_get_output_stream (void); | |
92 | |
16539
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
93 void do_redisplay (void); |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
94 |
2926 | 95 int do_terminal_rows (void); |
96 | |
97 int do_terminal_cols (void); | |
98 | |
16537
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16535
diff
changeset
|
99 void do_clear_screen (bool skip_redisplay); |
2926 | 100 |
3281 | 101 void do_resize_terminal (void); |
102 | |
3504 | 103 std::string newline_chars (void); |
2926 | 104 |
105 void do_restore_terminal_state (void); | |
106 | |
107 void do_blink_matching_paren (bool flag); | |
108 | |
3933 | 109 void do_set_basic_word_break_characters (const std::string& s); |
110 | |
111 void do_set_completer_word_break_characters (const std::string& s); | |
112 | |
3504 | 113 void do_set_basic_quote_characters (const std::string& s); |
2926 | 114 |
6979 | 115 void do_set_filename_quote_characters (const std::string& s); |
116 | |
117 void do_set_completer_quote_characters (const std::string& s); | |
118 | |
2926 | 119 void do_set_completion_append_character (char c); |
120 | |
2941 | 121 void do_set_completion_function (completion_fcn f); |
122 | |
6979 | 123 void do_set_quoting_function (quoting_fcn f); |
124 | |
125 void do_set_dequoting_function (dequoting_fcn f); | |
126 | |
127 void do_set_char_is_quoted_function (char_is_quoted_fcn f); | |
128 | |
129 void do_set_user_accept_line_function (user_accept_line_fcn f); | |
130 | |
2941 | 131 completion_fcn do_get_completion_function (void) const; |
2926 | 132 |
6979 | 133 quoting_fcn do_get_quoting_function (void) const; |
134 | |
135 dequoting_fcn do_get_dequoting_function (void) const; | |
136 | |
137 char_is_quoted_fcn do_get_char_is_quoted_function (void) const; | |
138 | |
139 user_accept_line_fcn do_get_user_accept_line_function (void) const; | |
140 | |
4604 | 141 string_vector |
142 do_generate_filename_completions (const std::string& text); | |
143 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
144 std::string do_get_line_buffer (void) const; |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
145 |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
146 std::string do_get_current_line (void) const; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
147 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
148 void do_replace_line (const std::string& text, bool clear_undo); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
149 |
3504 | 150 void do_insert_text (const std::string& text); |
2926 | 151 |
152 void do_newline (void); | |
153 | |
6979 | 154 void do_accept_line (void); |
155 | |
16539
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
156 bool do_undo (void); |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
157 |
2926 | 158 void do_clear_undo_list (void); |
159 | |
6913 | 160 void set_startup_hook (startup_hook_fcn f); |
161 | |
162 void restore_startup_hook (void); | |
2926 | 163 |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
164 void set_pre_input_hook (pre_input_hook_fcn f); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
165 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
166 void restore_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
|
167 |
6913 | 168 void set_event_hook (event_hook_fcn f); |
2926 | 169 |
6913 | 170 void restore_event_hook (void); |
3215 | 171 |
172 void do_restore_event_hook (void); | |
173 | |
3504 | 174 void do_read_init_file (const std::string& file); |
3189 | 175 |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
176 void do_re_read_init_file (void); |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
177 |
4143 | 178 bool do_filename_completion_desired (bool); |
179 | |
6979 | 180 bool do_filename_quoting_desired (bool); |
181 | |
16382
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
182 void do_interrupt (bool); |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
183 |
3519 | 184 static int operate_and_get_next (int, int); |
2926 | 185 |
3951 | 186 static int history_search_backward (int, int); |
187 | |
188 static int history_search_forward (int, int); | |
189 | |
2926 | 190 private: |
191 | |
3519 | 192 startup_hook_fcn previous_startup_hook; |
2926 | 193 |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
194 pre_input_hook_fcn previous_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
|
195 |
3519 | 196 event_hook_fcn previous_event_hook; |
3215 | 197 |
2941 | 198 completion_fcn completion_function; |
199 | |
6979 | 200 quoting_fcn quoting_function; |
201 | |
202 dequoting_fcn dequoting_function; | |
203 | |
204 char_is_quoted_fcn char_is_quoted_function; | |
205 | |
206 user_accept_line_fcn user_accept_line_function; | |
207 | |
2941 | 208 static char *command_generator (const char *text, int state); |
209 | |
6979 | 210 static char *command_quoter (char *text, int match_type, char *quote_pointer); |
211 static char *command_dequoter (char *text, int match_type); | |
212 | |
213 static int command_char_is_quoted (char *text, int index); | |
214 | |
215 static int command_accept_line (int count, int key); | |
216 | |
3519 | 217 static char **command_completer (const char *text, int start, int end); |
2926 | 218 }; |
219 | |
220 gnu_readline::gnu_readline () | |
3215 | 221 : command_editor (), previous_startup_hook (0), |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
222 previous_pre_input_hook (0), |
6979 | 223 previous_event_hook (0), completion_function (0), |
224 quoting_function (0), dequoting_function (0), | |
225 char_is_quoted_function (0), user_accept_line_function (0) | |
2926 | 226 { |
5775 | 227 // FIXME -- need interface to rl_add_defun, rl_initialize, and |
3519 | 228 // a function to set rl_terminal_name |
3225 | 229 |
3520 | 230 std::string term = octave_env::getenv ("TERM"); |
3519 | 231 |
232 octave_rl_set_terminal_name (term.c_str ()); | |
233 | |
234 octave_rl_initialize (); | |
2926 | 235 |
236 do_blink_matching_paren (true); | |
237 | |
5452 | 238 // Bind operate-and-get-next. |
2926 | 239 |
3519 | 240 octave_rl_add_defun ("operate-and-get-next", |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
241 gnu_readline::operate_and_get_next, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
242 octave_rl_ctrl ('O')); |
2926 | 243 |
5452 | 244 // And the history search functions. |
2926 | 245 |
3519 | 246 octave_rl_add_defun ("history-search-backward", |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
247 gnu_readline::history_search_backward, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
248 octave_rl_meta ('P')); |
2926 | 249 |
3519 | 250 octave_rl_add_defun ("history-search-forward", |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
251 gnu_readline::history_search_forward, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
252 octave_rl_meta ('N')); |
2926 | 253 } |
254 | |
255 void | |
3519 | 256 gnu_readline::do_set_name (const std::string& nm) |
2926 | 257 { |
3519 | 258 ::octave_rl_set_name (nm.c_str ()); |
2926 | 259 } |
260 | |
3504 | 261 std::string |
262 gnu_readline::do_readline (const std::string& prompt, bool& eof) | |
2926 | 263 { |
3504 | 264 std::string retval; |
2926 | 265 |
3219 | 266 eof = false; |
267 | |
5247 | 268 char *line = 0; |
269 | |
5336 | 270 const char *p = prompt.c_str (); |
271 | |
5452 | 272 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5247 | 273 |
5336 | 274 line = ::octave_rl_readline (p); |
5247 | 275 |
5452 | 276 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
2926 | 277 |
278 if (line) | |
279 { | |
280 retval = line; | |
281 | |
282 free (line); | |
283 } | |
3219 | 284 else |
285 eof = true; | |
2926 | 286 |
287 return retval; | |
288 } | |
289 | |
290 void | |
291 gnu_readline::do_set_input_stream (FILE *f) | |
292 { | |
3519 | 293 ::octave_rl_set_input_stream (f); |
2926 | 294 } |
295 | |
296 FILE * | |
297 gnu_readline::do_get_input_stream (void) | |
298 { | |
3519 | 299 return ::octave_rl_get_input_stream (); |
2926 | 300 } |
301 | |
302 void | |
303 gnu_readline::do_set_output_stream (FILE *f) | |
304 { | |
3519 | 305 ::octave_rl_set_output_stream (f); |
2926 | 306 } |
307 | |
308 FILE * | |
309 gnu_readline::do_get_output_stream (void) | |
310 { | |
3519 | 311 return ::octave_rl_get_output_stream (); |
2926 | 312 } |
313 | |
16539
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
314 void |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
315 gnu_readline::do_redisplay (void) |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
316 { |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
317 ::octave_rl_redisplay (); |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
318 } |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
319 |
2926 | 320 // GNU readline handles SIGWINCH, so these values have a good chance |
321 // of being correct even if the window changes size (they may be | |
322 // wrong if, for example, the luser changes the window size while the | |
323 // pager is running, and the signal is handled by the pager instead of | |
324 // us. | |
325 | |
326 int | |
327 gnu_readline::do_terminal_rows (void) | |
328 { | |
3519 | 329 int sh = ::octave_rl_screen_height (); |
330 | |
331 return sh > 0 ? sh : 24; | |
2926 | 332 } |
333 | |
334 int | |
335 gnu_readline::do_terminal_cols (void) | |
336 { | |
3519 | 337 int sw = ::octave_rl_screen_width (); |
338 | |
339 return sw > 0 ? sw : 80; | |
2926 | 340 } |
341 | |
342 void | |
16537
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16535
diff
changeset
|
343 gnu_readline::do_clear_screen (bool skip_redisplay) |
2926 | 344 { |
16537
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16535
diff
changeset
|
345 ::octave_rl_clear_screen (skip_redisplay); |
2926 | 346 } |
347 | |
3281 | 348 void |
349 gnu_readline::do_resize_terminal (void) | |
350 { | |
3519 | 351 ::octave_rl_resize_terminal (); |
3281 | 352 } |
353 | |
3504 | 354 std::string |
2926 | 355 gnu_readline::newline_chars (void) |
356 { | |
357 return "\r\n"; | |
358 } | |
359 | |
360 void | |
361 gnu_readline::do_restore_terminal_state (void) | |
362 { | |
3519 | 363 ::octave_rl_restore_terminal_state (); |
2926 | 364 } |
365 | |
366 void | |
367 gnu_readline::do_blink_matching_paren (bool flag) | |
368 { | |
3779 | 369 ::octave_rl_enable_paren_matching (flag ? 1 : 0); |
2926 | 370 } |
371 | |
372 void | |
3933 | 373 gnu_readline::do_set_basic_word_break_characters (const std::string& s) |
374 { | |
375 ::octave_rl_set_basic_word_break_characters (s.c_str ()); | |
376 } | |
377 | |
378 void | |
379 gnu_readline::do_set_completer_word_break_characters (const std::string& s) | |
380 { | |
381 ::octave_rl_set_completer_word_break_characters (s.c_str ()); | |
382 } | |
383 | |
384 void | |
3504 | 385 gnu_readline::do_set_basic_quote_characters (const std::string& s) |
2926 | 386 { |
3519 | 387 ::octave_rl_set_basic_quote_characters (s.c_str ()); |
2926 | 388 } |
389 | |
390 void | |
6979 | 391 gnu_readline::do_set_filename_quote_characters (const std::string& s) |
392 { | |
393 ::octave_rl_set_filename_quote_characters (s.c_str ()); | |
394 } | |
395 | |
396 void | |
397 gnu_readline::do_set_completer_quote_characters (const std::string& s) | |
398 { | |
399 ::octave_rl_set_completer_quote_characters (s.c_str ()); | |
400 } | |
401 | |
402 void | |
2926 | 403 gnu_readline::do_set_completion_append_character (char c) |
404 { | |
3519 | 405 ::octave_rl_set_completion_append_character (c); |
2926 | 406 } |
407 | |
408 void | |
2941 | 409 gnu_readline::do_set_completion_function (completion_fcn f) |
2926 | 410 { |
2941 | 411 completion_function = f; |
412 | |
3519 | 413 rl_attempted_completion_fcn_ptr fp |
414 = f ? gnu_readline::command_completer : 0; | |
2941 | 415 |
3519 | 416 ::octave_rl_set_completion_function (fp); |
2941 | 417 } |
418 | |
6979 | 419 void |
420 gnu_readline::do_set_quoting_function (quoting_fcn f) | |
421 { | |
422 quoting_function = f; | |
423 | |
424 rl_quoting_fcn_ptr fp | |
425 = f ? gnu_readline::command_quoter : 0; | |
426 | |
427 ::octave_rl_set_quoting_function (fp); | |
428 } | |
429 | |
430 void | |
431 gnu_readline::do_set_dequoting_function (dequoting_fcn f) | |
432 { | |
433 dequoting_function = f; | |
434 | |
435 rl_dequoting_fcn_ptr fp | |
436 = f ? gnu_readline::command_dequoter : 0; | |
437 | |
438 ::octave_rl_set_dequoting_function (fp); | |
439 } | |
440 | |
441 void | |
442 gnu_readline::do_set_char_is_quoted_function (char_is_quoted_fcn f) | |
443 { | |
444 char_is_quoted_function = f; | |
445 | |
446 rl_char_is_quoted_fcn_ptr fp | |
447 = f ? gnu_readline::command_char_is_quoted : 0; | |
448 | |
449 ::octave_rl_set_char_is_quoted_function (fp); | |
450 } | |
451 | |
452 void | |
453 gnu_readline::do_set_user_accept_line_function (user_accept_line_fcn f) | |
454 { | |
455 user_accept_line_function = f; | |
456 | |
457 if (f) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
458 octave_rl_add_defun ("accept-line", gnu_readline::command_accept_line, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
459 ::octave_rl_ctrl ('M')); |
6979 | 460 else |
461 octave_rl_add_defun ("accept-line", ::octave_rl_newline, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
462 ::octave_rl_ctrl ('M')); |
6979 | 463 } |
464 | |
2941 | 465 gnu_readline::completion_fcn |
466 gnu_readline::do_get_completion_function (void) const | |
467 { | |
468 return completion_function; | |
2926 | 469 } |
470 | |
6979 | 471 gnu_readline::quoting_fcn |
472 gnu_readline::do_get_quoting_function (void) const | |
473 { | |
474 return quoting_function; | |
475 } | |
476 | |
477 gnu_readline::dequoting_fcn | |
478 gnu_readline::do_get_dequoting_function (void) const | |
479 { | |
480 return dequoting_function; | |
481 } | |
482 | |
483 gnu_readline::char_is_quoted_fcn | |
484 gnu_readline::do_get_char_is_quoted_function (void) const | |
485 { | |
486 return char_is_quoted_function; | |
487 } | |
488 | |
489 gnu_readline::user_accept_line_fcn | |
490 gnu_readline::do_get_user_accept_line_function (void) const | |
491 { | |
492 return user_accept_line_function; | |
493 } | |
494 | |
4604 | 495 string_vector |
496 gnu_readline::do_generate_filename_completions (const std::string& text) | |
497 { | |
498 string_vector retval; | |
499 | |
500 int n = 0; | |
501 int count = 0; | |
502 | |
503 char *fn = 0; | |
504 | |
505 while (1) | |
506 { | |
507 fn = ::octave_rl_filename_completion_function (text.c_str (), count); | |
508 | |
509 if (fn) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
510 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
511 if (count == n) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
512 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
513 // Famous last words: Most large directories will not |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
514 // have more than a few hundred files, so we should not |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
515 // resize too many times even if the growth is linear... |
4604 | 516 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
517 n += 100; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
518 retval.resize (n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
519 } |
4604 | 520 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
521 retval[count++] = fn; |
4604 | 522 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
523 free (fn); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
524 } |
4604 | 525 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
526 break; |
4604 | 527 } |
528 | |
529 retval.resize (count); | |
530 | |
531 return retval; | |
532 } | |
533 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
534 std::string |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
535 gnu_readline::do_get_line_buffer (void) const |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
536 { |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
537 return ::octave_rl_line_buffer (); |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
538 } |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
539 |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
540 std::string |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
541 gnu_readline::do_get_current_line (void) const |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
542 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
543 std::string retval; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
544 char *buf = ::octave_rl_copy_line (); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
545 retval = buf; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
546 free (buf); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
547 return retval; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
548 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
549 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
550 void |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
551 gnu_readline::do_replace_line (const std::string& text, bool clear_undo) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
552 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
553 ::octave_rl_replace_line (text.c_str (), clear_undo); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
554 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
555 |
2926 | 556 void |
3504 | 557 gnu_readline::do_insert_text (const std::string& text) |
2926 | 558 { |
3519 | 559 ::octave_rl_insert_text (text.c_str ()); |
2926 | 560 } |
561 | |
562 void | |
563 gnu_readline::do_newline (void) | |
564 { | |
6979 | 565 ::octave_rl_newline (1, '\n'); |
566 } | |
567 | |
568 void | |
569 gnu_readline::do_accept_line (void) | |
570 { | |
571 command_accept_line (1, '\n'); | |
2926 | 572 } |
573 | |
16539
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
574 bool |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
575 gnu_readline::do_undo (void) |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
576 { |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
577 return ::octave_rl_do_undo (); |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
578 } |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
579 |
2926 | 580 void |
581 gnu_readline::do_clear_undo_list () | |
582 { | |
3519 | 583 ::octave_rl_clear_undo_list (); |
2926 | 584 } |
585 | |
586 void | |
6913 | 587 gnu_readline::set_startup_hook (startup_hook_fcn f) |
2926 | 588 { |
3519 | 589 previous_startup_hook = ::octave_rl_get_startup_hook (); |
2926 | 590 |
6917 | 591 if (f != previous_startup_hook) |
592 ::octave_rl_set_startup_hook (f); | |
2926 | 593 } |
594 | |
595 void | |
6913 | 596 gnu_readline::restore_startup_hook (void) |
2926 | 597 { |
3519 | 598 ::octave_rl_set_startup_hook (previous_startup_hook); |
2926 | 599 } |
600 | |
601 void | |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
602 gnu_readline::set_pre_input_hook (pre_input_hook_fcn f) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
603 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
604 previous_pre_input_hook = ::octave_rl_get_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
|
605 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
606 if (f != previous_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
|
607 ::octave_rl_set_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
|
608 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
609 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
610 void |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
611 gnu_readline::restore_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
|
612 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
613 ::octave_rl_set_pre_input_hook (previous_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
|
614 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
615 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
616 void |
6913 | 617 gnu_readline::set_event_hook (event_hook_fcn f) |
3215 | 618 { |
3519 | 619 previous_event_hook = octave_rl_get_event_hook (); |
3215 | 620 |
3519 | 621 ::octave_rl_set_event_hook (f); |
3215 | 622 } |
623 | |
624 void | |
6913 | 625 gnu_readline::restore_event_hook (void) |
3215 | 626 { |
3519 | 627 ::octave_rl_set_event_hook (previous_event_hook); |
3215 | 628 } |
629 | |
630 void | |
3504 | 631 gnu_readline::do_read_init_file (const std::string& file) |
3189 | 632 { |
3519 | 633 ::octave_rl_read_init_file (file.c_str ()); |
3189 | 634 } |
635 | |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
636 void |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
637 gnu_readline::do_re_read_init_file (void) |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
638 { |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
639 ::octave_rl_re_read_init_file (); |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
640 } |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
641 |
4143 | 642 bool |
643 gnu_readline::do_filename_completion_desired (bool arg) | |
644 { | |
645 return ::octave_rl_filename_completion_desired (arg); | |
646 } | |
647 | |
6979 | 648 bool |
649 gnu_readline::do_filename_quoting_desired (bool arg) | |
650 { | |
651 return ::octave_rl_filename_quoting_desired (arg); | |
652 } | |
653 | |
16382
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
654 void |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
655 gnu_readline::do_interrupt (bool arg) |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
656 { |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
657 ::octave_rl_done (arg); |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
658 } |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
659 |
3519 | 660 int |
2926 | 661 gnu_readline::operate_and_get_next (int /* count */, int /* c */) |
662 { | |
663 // Accept the current line. | |
664 | |
6979 | 665 command_editor::accept_line (); |
2926 | 666 |
667 // Find the current line, and find the next line to use. | |
668 | |
669 int x_where = command_history::where (); | |
670 | |
671 int x_length = command_history::length (); | |
672 | |
673 if ((command_history::is_stifled () | |
674 && (x_length >= command_history::max_input_history ())) | |
675 || (x_where >= x_length - 1)) | |
676 command_history::set_mark (x_where); | |
677 else | |
678 command_history::set_mark (x_where + 1); | |
679 | |
6913 | 680 command_editor::add_startup_hook (command_history::goto_mark); |
3519 | 681 |
682 return 0; | |
2926 | 683 } |
684 | |
3951 | 685 int |
686 gnu_readline::history_search_backward (int count, int c) | |
687 { | |
688 return octave_rl_history_search_backward (count, c); | |
689 } | |
690 | |
691 int | |
692 gnu_readline::history_search_forward (int count, int c) | |
693 { | |
694 return octave_rl_history_search_forward (count, c); | |
695 } | |
696 | |
2941 | 697 char * |
698 gnu_readline::command_generator (const char *text, int state) | |
699 { | |
700 char *retval = 0; | |
701 | |
702 completion_fcn f = command_editor::get_completion_function (); | |
703 | |
3504 | 704 std::string tmp = f (text, state); |
2941 | 705 |
706 size_t len = tmp.length (); | |
707 | |
708 if (len > 0) | |
709 { | |
10411 | 710 retval = static_cast<char *> (gnulib::malloc (len+1)); |
2941 | 711 |
712 strcpy (retval, tmp.c_str ()); | |
713 } | |
714 | |
715 return retval; | |
716 } | |
717 | |
6979 | 718 char * |
719 gnu_readline::command_quoter (char *text, int matches, char *qcp) | |
720 { | |
721 char *retval = 0; | |
722 | |
723 quoting_fcn f = command_editor::get_quoting_function (); | |
724 | |
725 std::string tmp = f (text, matches, *qcp); | |
726 | |
727 size_t len = tmp.length (); | |
728 | |
729 if (len > 0) | |
730 { | |
10411 | 731 retval = static_cast<char *> (gnulib::malloc (len+1)); |
6979 | 732 |
733 strcpy (retval, tmp.c_str ()); | |
734 } | |
735 | |
736 return retval; | |
737 } | |
738 | |
739 char * | |
740 gnu_readline::command_dequoter (char *text, int quote) | |
741 { | |
742 char *retval = 0; | |
743 | |
744 dequoting_fcn f = command_editor::get_dequoting_function (); | |
745 | |
746 std::string tmp = f (text, quote); | |
747 | |
748 size_t len = tmp.length (); | |
749 | |
750 if (len > 0) | |
751 { | |
10411 | 752 retval = static_cast<char *> (gnulib::malloc (len+1)); |
6979 | 753 |
754 strcpy (retval, tmp.c_str ()); | |
755 } | |
756 | |
757 return retval; | |
758 } | |
759 | |
760 int | |
761 gnu_readline::command_char_is_quoted (char *text, int quote) | |
762 { | |
763 char_is_quoted_fcn f = command_editor::get_char_is_quoted_function (); | |
764 | |
765 return f (text, quote); | |
766 } | |
767 | |
768 int | |
769 gnu_readline::command_accept_line (int count, int key) | |
770 { | |
771 user_accept_line_fcn f = command_editor::get_user_accept_line_function (); | |
772 | |
773 if (f) | |
774 f (::octave_rl_line_buffer ()); | |
775 | |
776 ::octave_rl_redisplay (); | |
777 | |
778 return ::octave_rl_newline (count, key); | |
779 } | |
780 | |
2941 | 781 char ** |
3519 | 782 gnu_readline::command_completer (const char *text, int, int) |
2941 | 783 { |
784 char **matches = 0; | |
3519 | 785 matches |
786 = ::octave_rl_completion_matches (text, gnu_readline::command_generator); | |
2941 | 787 return matches; |
788 } | |
789 | |
2926 | 790 #endif |
791 | |
792 class | |
793 default_command_editor : public command_editor | |
794 { | |
795 public: | |
796 | |
797 default_command_editor (void) | |
798 : command_editor (), input_stream (stdin), output_stream (stdout) { } | |
799 | |
800 ~default_command_editor (void) { } | |
801 | |
3504 | 802 std::string do_readline (const std::string& prompt, bool& eof); |
2926 | 803 |
804 void do_set_input_stream (FILE *f); | |
805 | |
806 FILE *do_get_input_stream (void); | |
807 | |
808 void do_set_output_stream (FILE *f); | |
809 | |
810 FILE *do_get_output_stream (void); | |
811 | |
4604 | 812 string_vector do_generate_filename_completions (const std::string& text); |
813 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
814 std::string do_get_line_buffer (void) const; |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
815 |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
816 std::string do_get_current_line (void) const; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
817 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
818 void do_replace_line (const std::string& text, bool clear_undo); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
819 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
820 void do_insert_text (const std::string& text); |
2926 | 821 |
822 void do_newline (void); | |
823 | |
6979 | 824 void do_accept_line (void); |
825 | |
2926 | 826 private: |
827 | |
828 FILE *input_stream; | |
829 | |
830 FILE *output_stream; | |
12153
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
831 |
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
832 // No copying! |
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
833 |
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
834 default_command_editor (const default_command_editor&); |
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
835 |
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
836 default_command_editor& operator = (const default_command_editor&); |
2926 | 837 }; |
838 | |
3504 | 839 std::string |
840 default_command_editor::do_readline (const std::string& prompt, bool& eof) | |
2926 | 841 { |
10411 | 842 gnulib::fputs (prompt.c_str (), output_stream); |
12912
e116dd862879
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
12153
diff
changeset
|
843 gnulib::fflush (output_stream); |
2926 | 844 |
4527 | 845 return octave_fgetl (input_stream, eof); |
2926 | 846 } |
847 | |
848 void | |
849 default_command_editor::do_set_input_stream (FILE *f) | |
850 { | |
851 input_stream = f; | |
852 } | |
853 | |
854 FILE * | |
855 default_command_editor::do_get_input_stream (void) | |
856 { | |
857 return input_stream; | |
858 } | |
859 | |
860 void | |
861 default_command_editor::do_set_output_stream (FILE *f) | |
862 { | |
863 output_stream = f; | |
864 } | |
865 | |
866 FILE * | |
867 default_command_editor::do_get_output_stream (void) | |
868 { | |
869 return output_stream; | |
870 } | |
871 | |
4604 | 872 string_vector |
4663 | 873 default_command_editor::do_generate_filename_completions (const std::string&) |
4604 | 874 { |
5775 | 875 // FIXME |
4604 | 876 return string_vector (); |
877 } | |
878 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
879 std::string |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
880 default_command_editor::do_get_line_buffer (void) const |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
881 { |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
882 return ""; |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
883 } |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
884 |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
885 std::string |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
886 default_command_editor::do_get_current_line (void) const |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
887 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
888 // FIXME |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
889 return std::string (); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
890 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
891 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
892 void |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
893 default_command_editor::do_replace_line (const std::string&, bool) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
894 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
895 // FIXME |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
896 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
897 |
2926 | 898 void |
3504 | 899 default_command_editor::do_insert_text (const std::string&) |
2926 | 900 { |
5775 | 901 // FIXME |
2926 | 902 } |
903 | |
904 void | |
905 default_command_editor::do_newline (void) | |
906 { | |
5775 | 907 // FIXME |
2926 | 908 } |
909 | |
6979 | 910 void |
911 default_command_editor::do_accept_line (void) | |
912 { | |
913 // FIXME | |
914 } | |
915 | |
2926 | 916 bool |
917 command_editor::instance_ok (void) | |
918 { | |
919 bool retval = true; | |
920 | |
921 if (! instance) | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
922 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
923 make_command_editor (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
924 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
925 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
926 singleton_cleanup_list::add (cleanup_instance); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
927 } |
2926 | 928 |
929 if (! instance) | |
930 { | |
2941 | 931 current_liboctave_error_handler |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
932 ("unable to create command history object!"); |
2926 | 933 |
934 retval = false; | |
935 } | |
936 | |
937 return retval; | |
938 } | |
939 | |
940 void | |
941 command_editor::make_command_editor (void) | |
942 { | |
943 #if defined (USE_READLINE) | |
944 instance = new gnu_readline (); | |
945 #else | |
946 instance = new default_command_editor (); | |
947 #endif | |
948 } | |
949 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
950 void |
9321
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
951 command_editor::force_default_editor (void) |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
952 { |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
953 delete instance; |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
954 instance = new default_command_editor (); |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
955 } |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
956 |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
957 void |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
958 command_editor::set_initial_input (const std::string& text) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
959 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
960 if (instance_ok ()) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
961 instance->initial_input = text; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
962 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
963 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
964 int |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
965 command_editor::insert_initial_input (void) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
966 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
967 return instance_ok () ? instance->do_insert_initial_input () : 0; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
968 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
969 |
6913 | 970 int |
971 command_editor::startup_handler (void) | |
972 { | |
973 for (startup_hook_set_iterator p = startup_hook_set.begin (); | |
974 p != startup_hook_set.end (); p++) | |
975 { | |
976 startup_hook_fcn f = *p; | |
977 | |
978 if (f) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
979 f (); |
6913 | 980 } |
981 | |
982 return 0; | |
983 } | |
984 | |
985 int | |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
986 command_editor::pre_input_handler (void) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
987 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
988 for (pre_input_hook_set_iterator p = pre_input_hook_set.begin (); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
989 p != pre_input_hook_set.end (); p++) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
990 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
991 pre_input_hook_fcn f = *p; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
992 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
993 if (f) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
994 f (); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
995 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
996 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
997 return 0; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
998 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
999 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1000 int |
6913 | 1001 command_editor::event_handler (void) |
1002 { | |
7936
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1003 event_hook_lock.lock (); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1004 |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1005 std::set<event_hook_fcn> hook_set (event_hook_set); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1006 |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1007 event_hook_lock.unlock (); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1008 |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1009 for (event_hook_set_iterator p = hook_set.begin (); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1010 p != hook_set.end (); p++) |
6913 | 1011 { |
1012 event_hook_fcn f = *p; | |
1013 | |
1014 if (f) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1015 f (); |
6913 | 1016 } |
1017 | |
1018 return 0; | |
1019 } | |
1020 | |
2926 | 1021 void |
3504 | 1022 command_editor::set_name (const std::string& n) |
2926 | 1023 { |
1024 if (instance_ok ()) | |
1025 instance->do_set_name (n); | |
1026 } | |
1027 | |
3504 | 1028 std::string |
1029 command_editor::readline (const std::string& prompt) | |
2926 | 1030 { |
3219 | 1031 bool eof; |
1032 | |
1033 return readline (prompt, eof); | |
1034 } | |
1035 | |
3504 | 1036 std::string |
1037 command_editor::readline (const std::string& prompt, bool& eof) | |
3219 | 1038 { |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1039 std::string retval; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1040 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1041 if (instance_ok ()) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1042 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1043 if (! instance->initial_input.empty ()) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1044 add_pre_input_hook (command_editor::insert_initial_input); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1045 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1046 retval = instance->do_readline (prompt, eof); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1047 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1048 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1049 return retval; |
2926 | 1050 } |
1051 | |
1052 void | |
1053 command_editor::set_input_stream (FILE *f) | |
1054 { | |
1055 if (instance_ok ()) | |
1056 instance->do_set_input_stream (f); | |
1057 } | |
1058 | |
1059 FILE * | |
1060 command_editor::get_input_stream (void) | |
1061 { | |
1062 return (instance_ok ()) | |
1063 ? instance->do_get_input_stream () : 0; | |
1064 } | |
1065 | |
1066 void | |
1067 command_editor::set_output_stream (FILE *f) | |
1068 { | |
1069 if (instance_ok ()) | |
1070 instance->do_set_output_stream (f); | |
1071 } | |
1072 | |
1073 FILE * | |
1074 command_editor::get_output_stream (void) | |
1075 { | |
1076 return (instance_ok ()) | |
1077 ? instance->do_get_output_stream () : 0; | |
1078 } | |
1079 | |
16539
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1080 void |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1081 command_editor::redisplay (void) |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1082 { |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1083 if (instance_ok ()) |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1084 instance->do_redisplay (); |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1085 } |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1086 |
2926 | 1087 int |
1088 command_editor::terminal_rows (void) | |
1089 { | |
1090 return (instance_ok ()) | |
1091 ? instance->do_terminal_rows () : -1; | |
1092 } | |
1093 | |
1094 int | |
1095 command_editor::terminal_cols (void) | |
1096 { | |
1097 return (instance_ok ()) | |
1098 ? instance->do_terminal_cols () : -1; | |
1099 } | |
1100 | |
1101 void | |
16537
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16535
diff
changeset
|
1102 command_editor::clear_screen (bool skip_redisplay) |
2926 | 1103 { |
1104 if (instance_ok ()) | |
16537
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16535
diff
changeset
|
1105 instance->do_clear_screen (skip_redisplay); |
2926 | 1106 } |
1107 | |
3281 | 1108 void |
1109 command_editor::resize_terminal (void) | |
1110 { | |
1111 if (instance_ok ()) | |
1112 instance->do_resize_terminal (); | |
1113 } | |
1114 | |
3504 | 1115 std::string |
1116 command_editor::decode_prompt_string (const std::string& s) | |
2926 | 1117 { |
1118 return (instance_ok ()) | |
3504 | 1119 ? instance->do_decode_prompt_string (s) : std::string (); |
2926 | 1120 } |
1121 | |
1122 int | |
1123 command_editor::current_command_number (void) | |
1124 { | |
1125 return (instance_ok ()) | |
1126 ? instance->command_number : 0; | |
1127 } | |
1128 | |
1129 void | |
1130 command_editor::reset_current_command_number (int n) | |
1131 { | |
1132 if (instance_ok ()) | |
1133 instance->command_number = n; | |
1134 } | |
1135 | |
1136 void | |
2967 | 1137 command_editor::increment_current_command_number (void) |
1138 { | |
1139 if (instance_ok ()) | |
1140 instance->command_number++; | |
1141 } | |
1142 | |
1143 void | |
2926 | 1144 command_editor::restore_terminal_state (void) |
1145 { | |
1146 if (instance_ok ()) | |
1147 instance->do_restore_terminal_state (); | |
1148 } | |
1149 | |
1150 void | |
1151 command_editor::blink_matching_paren (bool flag) | |
1152 { | |
1153 if (instance_ok ()) | |
1154 instance->do_blink_matching_paren (flag); | |
1155 } | |
1156 | |
1157 void | |
3933 | 1158 command_editor::set_basic_word_break_characters (const std::string& s) |
1159 { | |
1160 if (instance_ok ()) | |
1161 instance->do_set_basic_word_break_characters (s); | |
1162 } | |
1163 | |
1164 void | |
1165 command_editor::set_completer_word_break_characters (const std::string& s) | |
1166 { | |
1167 if (instance_ok ()) | |
1168 instance->do_set_completer_word_break_characters (s); | |
1169 } | |
1170 | |
1171 void | |
3504 | 1172 command_editor::set_basic_quote_characters (const std::string& s) |
2926 | 1173 { |
1174 if (instance_ok ()) | |
3004 | 1175 instance->do_set_basic_quote_characters (s); |
2926 | 1176 } |
1177 | |
1178 void | |
6979 | 1179 command_editor::set_filename_quote_characters (const std::string& s) |
1180 { | |
1181 if (instance_ok ()) | |
1182 instance->do_set_filename_quote_characters (s); | |
1183 } | |
1184 | |
1185 void | |
1186 command_editor::set_completer_quote_characters (const std::string& s) | |
1187 { | |
1188 if (instance_ok ()) | |
1189 instance->do_set_completer_quote_characters (s); | |
1190 } | |
1191 | |
1192 void | |
2926 | 1193 command_editor::set_completion_append_character (char c) |
1194 { | |
1195 if (instance_ok ()) | |
1196 instance->do_set_completion_append_character (c); | |
1197 } | |
1198 | |
1199 void | |
2941 | 1200 command_editor::set_completion_function (completion_fcn f) |
2926 | 1201 { |
1202 if (instance_ok ()) | |
2941 | 1203 instance->do_set_completion_function (f); |
1204 } | |
1205 | |
6979 | 1206 void |
1207 command_editor::set_quoting_function (quoting_fcn f) | |
1208 { | |
1209 if (instance_ok ()) | |
1210 instance->do_set_quoting_function (f); | |
1211 } | |
1212 | |
1213 void | |
1214 command_editor::set_dequoting_function (dequoting_fcn f) | |
1215 { | |
1216 if (instance_ok ()) | |
1217 instance->do_set_dequoting_function (f); | |
1218 } | |
1219 | |
1220 void | |
1221 command_editor::set_char_is_quoted_function (char_is_quoted_fcn f) | |
1222 { | |
1223 if (instance_ok ()) | |
1224 instance->do_set_char_is_quoted_function (f); | |
1225 } | |
1226 | |
1227 void | |
1228 command_editor::set_user_accept_line_function (user_accept_line_fcn f) | |
1229 { | |
1230 if (instance_ok ()) | |
1231 instance->do_set_user_accept_line_function (f); | |
1232 } | |
1233 | |
2941 | 1234 command_editor::completion_fcn |
1235 command_editor::get_completion_function (void) | |
1236 { | |
1237 return (instance_ok ()) | |
1238 ? instance->do_get_completion_function () : 0; | |
2926 | 1239 } |
1240 | |
6979 | 1241 command_editor::quoting_fcn |
1242 command_editor::get_quoting_function (void) | |
1243 { | |
1244 return (instance_ok ()) | |
1245 ? instance->do_get_quoting_function () : 0; | |
1246 } | |
1247 | |
1248 command_editor::dequoting_fcn | |
1249 command_editor::get_dequoting_function (void) | |
1250 { | |
1251 return (instance_ok ()) | |
1252 ? instance->do_get_dequoting_function () : 0; | |
1253 } | |
1254 | |
1255 command_editor::char_is_quoted_fcn | |
1256 command_editor::get_char_is_quoted_function (void) | |
1257 { | |
1258 return (instance_ok ()) | |
1259 ? instance->do_get_char_is_quoted_function () : 0; | |
1260 } | |
1261 | |
1262 command_editor::user_accept_line_fcn | |
1263 command_editor::get_user_accept_line_function (void) | |
1264 { | |
1265 return (instance_ok ()) | |
1266 ? instance->do_get_user_accept_line_function () : 0; | |
1267 } | |
1268 | |
4604 | 1269 string_vector |
1270 command_editor::generate_filename_completions (const std::string& text) | |
1271 { | |
1272 return (instance_ok ()) | |
1273 ? instance->do_generate_filename_completions (text) : string_vector (); | |
1274 } | |
1275 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1276 std::string |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1277 command_editor::get_line_buffer (void) |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1278 { |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1279 return (instance_ok ()) ? instance->do_get_line_buffer () : ""; |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1280 } |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1281 |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1282 std::string |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1283 command_editor::get_current_line (void) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1284 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1285 return (instance_ok ()) ? instance->do_get_current_line () : ""; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1286 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1287 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1288 void |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1289 command_editor::replace_line (const std::string& text, bool clear_undo) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1290 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1291 if (instance_ok ()) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1292 instance->do_replace_line (text, clear_undo); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1293 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1294 |
2926 | 1295 void |
3504 | 1296 command_editor::insert_text (const std::string& text) |
2926 | 1297 { |
1298 if (instance_ok ()) | |
1299 instance->do_insert_text (text); | |
1300 } | |
1301 | |
1302 void | |
1303 command_editor::newline (void) | |
1304 { | |
1305 if (instance_ok ()) | |
1306 instance->do_newline (); | |
1307 } | |
1308 | |
1309 void | |
6979 | 1310 command_editor::accept_line (void) |
1311 { | |
1312 if (instance_ok ()) | |
1313 instance->do_accept_line (); | |
1314 } | |
1315 | |
16539
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1316 bool |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1317 command_editor::undo (void) |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1318 { |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1319 return instance_ok () ? instance->do_undo () : false; |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1320 } |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1321 |
6979 | 1322 void |
2926 | 1323 command_editor::clear_undo_list (void) |
1324 { | |
1325 if (instance_ok ()) | |
1326 instance->do_clear_undo_list (); | |
1327 } | |
1328 | |
1329 void | |
6913 | 1330 command_editor::add_startup_hook (startup_hook_fcn f) |
2926 | 1331 { |
1332 if (instance_ok ()) | |
6913 | 1333 { |
1334 startup_hook_set.insert (f); | |
1335 | |
1336 instance->set_startup_hook (startup_handler); | |
1337 } | |
2926 | 1338 } |
1339 | |
1340 void | |
6913 | 1341 command_editor::remove_startup_hook (startup_hook_fcn f) |
2926 | 1342 { |
1343 if (instance_ok ()) | |
6913 | 1344 { |
1345 startup_hook_set_iterator p = startup_hook_set.find (f); | |
1346 | |
1347 if (p != startup_hook_set.end ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1348 startup_hook_set.erase (p); |
6913 | 1349 |
1350 if (startup_hook_set.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1351 instance->restore_startup_hook (); |
6913 | 1352 } |
2926 | 1353 } |
1354 | |
3189 | 1355 void |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1356 command_editor::add_pre_input_hook (pre_input_hook_fcn f) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1357 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1358 if (instance_ok ()) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1359 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1360 pre_input_hook_set.insert (f); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1361 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1362 instance->set_pre_input_hook (pre_input_handler); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1363 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1364 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1365 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1366 void |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1367 command_editor::remove_pre_input_hook (pre_input_hook_fcn f) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1368 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1369 if (instance_ok ()) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1370 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1371 pre_input_hook_set_iterator p = pre_input_hook_set.find (f); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1372 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1373 if (p != pre_input_hook_set.end ()) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1374 pre_input_hook_set.erase (p); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1375 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1376 if (pre_input_hook_set.empty ()) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1377 instance->restore_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
|
1378 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1379 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1380 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1381 void |
6913 | 1382 command_editor::add_event_hook (event_hook_fcn f) |
3215 | 1383 { |
7936
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1384 octave_autolock guard (event_hook_lock); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1385 |
3215 | 1386 if (instance_ok ()) |
6913 | 1387 { |
1388 event_hook_set.insert (f); | |
1389 | |
1390 instance->set_event_hook (event_handler); | |
1391 } | |
3215 | 1392 } |
1393 | |
1394 void | |
6913 | 1395 command_editor::remove_event_hook (event_hook_fcn f) |
3215 | 1396 { |
7936
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1397 octave_autolock guard (event_hook_lock); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1398 |
3215 | 1399 if (instance_ok ()) |
6913 | 1400 { |
1401 event_hook_set_iterator p = event_hook_set.find (f); | |
1402 | |
1403 if (p != event_hook_set.end ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1404 event_hook_set.erase (p); |
6913 | 1405 |
1406 if (event_hook_set.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1407 instance->restore_event_hook (); |
6913 | 1408 } |
3215 | 1409 } |
1410 | |
1411 void | |
13924
3b654a0753b1
Implement waitfor, uiwait and uiresume.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12912
diff
changeset
|
1412 command_editor::run_event_hooks (void) |
3b654a0753b1
Implement waitfor, uiwait and uiresume.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12912
diff
changeset
|
1413 { |
3b654a0753b1
Implement waitfor, uiwait and uiresume.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12912
diff
changeset
|
1414 event_handler (); |
3b654a0753b1
Implement waitfor, uiwait and uiresume.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12912
diff
changeset
|
1415 } |
3b654a0753b1
Implement waitfor, uiwait and uiresume.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12912
diff
changeset
|
1416 |
3b654a0753b1
Implement waitfor, uiwait and uiresume.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12912
diff
changeset
|
1417 void |
5872 | 1418 command_editor::read_init_file (const std::string& file_arg) |
3189 | 1419 { |
1420 if (instance_ok ()) | |
5872 | 1421 { |
1422 std::string file = file_ops::tilde_expand (file_arg); | |
1423 | |
1424 instance->do_read_init_file (file); | |
1425 } | |
3189 | 1426 } |
1427 | |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1428 void |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1429 command_editor::re_read_init_file (void) |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1430 { |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1431 if (instance_ok ()) |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1432 instance->do_re_read_init_file (); |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1433 } |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1434 |
4143 | 1435 bool |
1436 command_editor::filename_completion_desired (bool arg) | |
1437 { | |
1438 return (instance_ok ()) | |
1439 ? instance->do_filename_completion_desired (arg) : false; | |
1440 } | |
1441 | |
6979 | 1442 bool |
1443 command_editor::filename_quoting_desired (bool arg) | |
1444 { | |
1445 return (instance_ok ()) | |
1446 ? instance->do_filename_quoting_desired (arg) : false; | |
1447 } | |
1448 | |
16382
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1449 bool |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1450 command_editor::interrupt (bool arg) |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1451 { |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1452 bool retval; |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1453 |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1454 if (instance_ok ()) |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1455 { |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1456 // Return the current interrupt state. |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1457 retval = instance->interrupted; |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1458 |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1459 instance->do_interrupt (arg); |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1460 |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1461 instance->interrupted = arg; |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1462 } |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1463 else |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1464 retval = false; |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1465 |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1466 return retval; |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1467 } |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1468 |
2926 | 1469 // Return a string which will be printed as a prompt. The string may |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1470 // contain special characters which are decoded as follows: |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1471 // |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1472 // \a bell (ascii 07) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1473 // \d the date |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1474 // \e escape (ascii 033) |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1475 // \h the hostname up to the first '.' |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1476 // \H the hostname |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1477 // \n CRLF |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1478 // \r CR |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1479 // \s the name of the shell (program) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1480 // \t the time |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1481 // \T the time in 12-hour hh:mm:ss format |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1482 // \@ the time in 12-hour hh:mm am/pm format |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1483 // \A the time in 24-hour hh:mm format |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1484 // \u your username |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1485 // \w the current working directory |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1486 // \W the last element of PWD |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1487 // \! the history number of this command |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1488 // \# the command number of this command |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1489 // \$ a $ or a # if you are root |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1490 // \nnn character code nnn in octal |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1491 // \\ a backslash |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1492 // \[ begin a sequence of non-printing chars |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1493 // \] end a sequence of non-printing chars |
2926 | 1494 |
3504 | 1495 std::string |
1496 command_editor::do_decode_prompt_string (const std::string& s) | |
2926 | 1497 { |
3504 | 1498 std::string result; |
1499 std::string temp; | |
2926 | 1500 size_t i = 0; |
1501 size_t slen = s.length (); | |
1502 int c; | |
1503 | |
1504 while (i < slen) | |
1505 { | |
1506 c = s[i]; | |
1507 | |
1508 i++; | |
1509 | |
1510 if (c == '\\') | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1511 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1512 c = s[i]; |
2926 | 1513 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1514 switch (c) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1515 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1516 case '0': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1517 case '1': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1518 case '2': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1519 case '3': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1520 case '4': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1521 case '5': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1522 case '6': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1523 case '7': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1524 // Maybe convert an octal number. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1525 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1526 int n = read_octal (s.substr (i, 3)); |
2926 | 1527 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1528 temp = "\\"; |
2926 | 1529 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1530 if (n != -1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1531 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1532 i += 3; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1533 temp[0] = n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1534 } |
2926 | 1535 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1536 c = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1537 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1538 } |
5442 | 1539 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1540 case 'a': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1541 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1542 temp = '\a'; |
5442 | 1543 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1544 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1545 } |
5442 | 1546 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1547 case 'e': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1548 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1549 temp = '\033'; |
5442 | 1550 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1551 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1552 } |
5442 | 1553 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1554 case 'r': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1555 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1556 temp = '\r'; |
5442 | 1557 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1558 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1559 } |
5442 | 1560 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1561 case 'd': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1562 case 't': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1563 case 'T': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1564 case '@': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1565 case 'A': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1566 // Make the current time/date into a string. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1567 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1568 octave_localtime now; |
2926 | 1569 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1570 if (c == 'd') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1571 temp = now.strftime ("%a %b %d"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1572 else if (c == 't') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1573 temp = now.strftime ("%H:%M:%S"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1574 else if (c == 'T') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1575 temp = now.strftime ("%I:%M:%S"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1576 else if (c == '@') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1577 temp = now.strftime ("%I:%M %p"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1578 else if (c == 'A') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1579 temp = now.strftime ("%H:%M"); |
2926 | 1580 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1581 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1582 } |
2926 | 1583 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1584 case 'n': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1585 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1586 temp = newline_chars (); |
2926 | 1587 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1588 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1589 } |
2926 | 1590 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1591 case 's': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1592 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1593 temp = octave_env::get_program_name (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1594 temp = octave_env::base_pathname (temp); |
2926 | 1595 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1596 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1597 } |
5442 | 1598 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1599 case 'w': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1600 case 'W': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1601 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1602 temp = octave_env::get_current_directory (); |
2926 | 1603 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1604 std::string home_dir = octave_env::get_home_directory (); |
5442 | 1605 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1606 if (c == 'W' && (home_dir.empty () || temp != home_dir)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1607 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1608 if (temp != "/" && temp != "//") |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1609 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1610 size_t pos = temp.rfind ('/'); |
2926 | 1611 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1612 if (pos != std::string::npos && pos != 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1613 temp = temp.substr (pos + 1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1614 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1615 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1616 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1617 temp = octave_env::polite_directory_format (temp); |
2926 | 1618 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1619 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1620 } |
5442 | 1621 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1622 case 'u': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1623 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1624 temp = octave_env::get_user_name (); |
2926 | 1625 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1626 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1627 } |
2926 | 1628 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1629 case 'H': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1630 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1631 temp = octave_env::get_host_name (); |
2926 | 1632 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1633 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1634 } |
2926 | 1635 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1636 case 'h': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1637 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1638 temp = octave_env::get_host_name (); |
2926 | 1639 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1640 size_t pos = temp.find ('.'); |
2926 | 1641 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1642 if (pos != std::string::npos) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1643 temp.resize (pos); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1644 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1645 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1646 } |
2926 | 1647 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1648 case '#': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1649 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1650 char number_buffer[128]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1651 sprintf (number_buffer, "%d", command_number); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1652 temp = number_buffer; |
2926 | 1653 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1654 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1655 } |
2926 | 1656 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1657 case '!': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1658 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1659 char number_buffer[128]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1660 int num = command_history::current_number (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1661 if (num > 0) |
2926 | 1662 sprintf (number_buffer, "%d", num); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1663 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1664 strcpy (number_buffer, "!"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1665 temp = number_buffer; |
2926 | 1666 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1667 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1668 } |
2926 | 1669 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1670 case '$': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1671 { |
4062 | 1672 #if defined (HAVE_GETEUID) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1673 temp = (::geteuid () == 0 ? "#" : "$"); |
4062 | 1674 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1675 temp = "$"; |
4062 | 1676 #endif |
2926 | 1677 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1678 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1679 } |
2926 | 1680 |
1681 #if defined (USE_READLINE) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1682 case '[': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1683 case ']': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1684 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1685 temp.resize (1); |
2926 | 1686 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1687 temp[0] = ((c == '[') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1688 ? ::octave_rl_prompt_start_ignore () |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1689 : ::octave_rl_prompt_end_ignore ()); |
2926 | 1690 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1691 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1692 } |
2926 | 1693 #endif |
1694 | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1695 case '\\': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1696 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1697 temp = "\\"; |
2926 | 1698 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1699 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1700 } |
2926 | 1701 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1702 default: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1703 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1704 temp = "\\ "; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1705 temp[1] = c; |
2926 | 1706 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1707 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1708 } |
2926 | 1709 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1710 add_string: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1711 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1712 if (c) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1713 i++; |
2926 | 1714 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1715 result.append (temp); |
2926 | 1716 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1717 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1718 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1719 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1720 } |
2926 | 1721 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1722 result += c; |
2926 | 1723 } |
1724 | |
1725 return result; | |
1726 } | |
1727 | |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1728 int |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1729 command_editor::do_insert_initial_input (void) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1730 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1731 std::string input = initial_input; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1732 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1733 initial_input = ""; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1734 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1735 do_insert_text (input); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1736 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1737 // Is it really right to redisplay here? |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1738 do_redisplay (); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1739 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1740 return 0; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1741 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1742 |
2926 | 1743 // Return the octal number parsed from STRING, or -1 to indicate that |
1744 // the string contained a bad number. | |
1745 | |
1746 int | |
3504 | 1747 command_editor::read_octal (const std::string& s) |
2926 | 1748 { |
1749 int result = 0; | |
1750 int digits = 0; | |
1751 | |
1752 size_t i = 0; | |
1753 size_t slen = s.length (); | |
1754 | |
1755 while (i < slen && s[i] >= '0' && s[i] < '8') | |
1756 { | |
1757 digits++; | |
1758 result = (result * 8) + s[i] - '0'; | |
1759 i++; | |
1760 } | |
1761 | |
1762 if (! digits || result > 0777 || i < slen) | |
1763 result = -1; | |
1764 | |
1765 return result; | |
1766 } | |
1767 | |
1768 void | |
1769 command_editor::error (int err_num) | |
1770 { | |
10411 | 1771 current_liboctave_error_handler ("%s", gnulib::strerror (err_num)); |
2926 | 1772 } |
1773 | |
1774 void | |
3504 | 1775 command_editor::error (const std::string& s) |
2926 | 1776 { |
2941 | 1777 current_liboctave_error_handler ("%s", s.c_str ()); |
2926 | 1778 } |