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