From be36d42f44d0133fe8b12a6bc6481f8360892709 Mon Sep 17 00:00:00 2001 From: vdhoeven Date: Mon, 23 Aug 2010 12:41:40 +0000 Subject: [PATCH] Fix tab completion git-svn-id: svn://svn.savannah.gnu.org/texmacs/trunk@3041 64cb5145-927a-446d-8aed-2fb7b4773692 --- src/TeXmacs/progs/dynamic/session-edit.scm | 7 ++++++- src/TeXmacs/progs/utils/plugins/plugin-eval.scm | 18 +++++++++++++++--- src/src/Edit/Interface/edit_complete.cpp | 20 ++++++++++---------- src/src/Edit/Interface/edit_interface.hpp | 3 ++- src/src/Edit/editor.hpp | 3 ++- src/src/Guile/Glue/build-glue-basic.scm | 1 + src/src/Guile/Glue/build-glue-editor.scm | 3 ++- src/src/Guile/Glue/glue_basic.cpp | 18 ++++++++++++++++++ src/src/Guile/Glue/glue_editor.cpp | 24 +++++++++++++++++++----- 9 files changed, 75 insertions(+), 22 deletions(-) diff --git a/src/TeXmacs/progs/dynamic/session-edit.scm b/src/TeXmacs/progs/dynamic/session-edit.scm index 24a22e89..b1da22a6 100644 --- a/src/TeXmacs/progs/dynamic/session-edit.scm +++ b/src/TeXmacs/progs/dynamic/session-edit.scm @@ -487,7 +487,12 @@ (:context field-input-context?) (:require (session-supports-completions?)) (with-innermost t field-input-context? - (session-complete-try? t))) + (let* ((lan (get-env "prog-language")) + (ses (get-env "prog-session")) + (cmd (session-complete-command t)) + (ret (lambda (x) (custom-complete (tm->tree x))))) + (when (!= cmd "") + (plugin-command lan ses cmd ret '()))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Structured keyboard movements diff --git a/src/TeXmacs/progs/utils/plugins/plugin-eval.scm b/src/TeXmacs/progs/utils/plugins/plugin-eval.scm index 3c27292d..14947b2d 100644 --- a/src/TeXmacs/progs/utils/plugins/plugin-eval.scm +++ b/src/TeXmacs/progs/utils/plugins/plugin-eval.scm @@ -95,9 +95,11 @@ (tm-define (plugin-write lan ses t) (ahash-set! plugin-started (list lan ses) (texmacs-time)) (if (!= lan "scheme") - (begin - (plugin-set-author lan ses) - (connection-write lan ses t)) + (if (string? t) + (connection-write-string lan ses t) + (begin + (plugin-set-author lan ses) + (connection-write lan ses t))) (delayed (connection-notify-status lan ses 3) (with r (scheme-eval t) @@ -273,3 +275,13 @@ `(with "color" "red" ,(cdr x))) (else (car x))))) (silent-feed lan ses in ret opts))) + +(define (plugin-command-answer x) + (if (tm-func? x 'document 1) (plugin-command-answer (cadr x)) + x)) + +(tm-define (plugin-command lan ses in return opts) + (let* ((cmd (format-command lan in)) + (ret (lambda (x) (return (plugin-command-answer (car x))))) + (x (silent-encode cmd ret opts))) + (apply plugin-feed `(,lan ,ses ,@(car x) ,(cdr x))))) diff --git a/src/src/Edit/Interface/edit_complete.cpp b/src/src/Edit/Interface/edit_complete.cpp index f47a0312..ab8be2ac 100644 --- a/src/src/Edit/Interface/edit_complete.cpp +++ b/src/src/Edit/Interface/edit_complete.cpp @@ -172,11 +172,11 @@ put_cursor (tree t, path p) { } } -bool -edit_interface_rep::session_complete_try (tree tt) { +string +edit_interface_rep::session_complete_command (tree tt) { path p= reverse (obtain_ip (tt)); tree st= subtree (et, p); - if ((N(tp) <= N(p)) || (tp[N(p)] != 1)) return false; + if ((N(tp) <= N(p)) || (tp[N(p)] != 1)) return ""; tree t= put_cursor (st[1], tail (tp, N(p)+1)); // cout << t << LF; @@ -187,14 +187,15 @@ edit_interface_rep::session_complete_try (tree tt) { s= s (0, N(s)-1); int pos= search_forwards (cursor_symbol, s); - if (pos == -1) return false; + if (pos == -1) return ""; s= s (0, pos) * s (pos + N(cursor_symbol), N(s)); // cout << s << ", " << pos << LF; + return "(complete " * scm_quote (s) * " " * as_string (pos) * ")"; +} - string cmd= "(complete " * scm_quote (s) * " " * as_string (pos) * ")"; - tree r= connection_cmd (lan, ses, cmd); - - if (!is_tuple (r)) return false; +void +edit_interface_rep::custom_complete (tree r) { + if (!is_tuple (r)) return; int i, n= N(r); string prefix; array compls; @@ -207,7 +208,6 @@ edit_interface_rep::session_complete_try (tree tt) { } // cout << prefix << ", " << compls << LF; - if ((prefix == "") || (N(compls) == 0)) return false; + if ((prefix == "") || (N(compls) == 0)) return; complete_start (prefix, compls); - return true; } diff --git a/src/src/Edit/Interface/edit_interface.hpp b/src/src/Edit/Interface/edit_interface.hpp index 5f992ea7..572dd746 100644 --- a/src/src/Edit/Interface/edit_interface.hpp +++ b/src/src/Edit/Interface/edit_interface.hpp @@ -134,7 +134,8 @@ public: void complete_message (); void complete_start (string prefix, array compls); bool complete_keypress (string key); - bool session_complete_try (tree t); + string session_complete_command (tree t); + void custom_complete (tree t); /* mouse handling */ void mouse_any (string s, SI x, SI y, int mods, time_t t); diff --git a/src/src/Edit/editor.hpp b/src/src/Edit/editor.hpp index 5bb1fb3e..c223d7fa 100644 --- a/src/src/Edit/editor.hpp +++ b/src/src/Edit/editor.hpp @@ -147,7 +147,8 @@ public: virtual bool complete_try () = 0; virtual void complete_start (string prefix, array compls) = 0; virtual bool complete_keypress (string key) = 0; - virtual bool session_complete_try (tree t) = 0; + virtual string session_complete_command (tree t) = 0; + virtual void custom_complete (tree t) = 0; virtual void mouse_any (string s, SI x, SI y, int mods, time_t t) = 0; virtual void mouse_click (SI x, SI y) = 0; virtual bool mouse_extra_click (SI x, SI y) = 0; diff --git a/src/src/Guile/Glue/build-glue-basic.scm b/src/src/Guile/Glue/build-glue-basic.scm index 3e738910..47b1e731 100644 --- a/src/src/Guile/Glue/build-glue-basic.scm +++ b/src/src/Guile/Glue/build-glue-basic.scm @@ -303,6 +303,7 @@ ;; connections to extern systems (connection-start connection_start (string string string)) (connection-status connection_status (int string string)) + (connection-write-string connection_write (void string string string)) (connection-write connection_write (void string string content)) (connection-cmd connection_cmd (tree string string string)) (connection-eval connection_eval (tree string string content)) diff --git a/src/src/Guile/Glue/build-glue-editor.scm b/src/src/Guile/Glue/build-glue-editor.scm index eeee64ed..2489d2c4 100644 --- a/src/src/Guile/Glue/build-glue-editor.scm +++ b/src/src/Guile/Glue/build-glue-editor.scm @@ -239,7 +239,8 @@ (spell-replace spell_replace (void string)) ;; sessions - (session-complete-try? session_complete_try (bool tree)) + (session-complete-command session_complete_command (string tree)) + (custom-complete custom_complete (void tree)) ;; miscellaneous routines (view-set-property set_property (void scheme_tree scheme_tree)) diff --git a/src/src/Guile/Glue/glue_basic.cpp b/src/src/Guile/Glue/glue_basic.cpp index 97cc09a4..ef180aa7 100644 --- a/src/src/Guile/Glue/glue_basic.cpp +++ b/src/src/Guile/Glue/glue_basic.cpp @@ -3439,6 +3439,23 @@ tmg_connection_status (SCM arg1, SCM arg2) { } SCM +tmg_connection_write_string (SCM arg1, SCM arg2, SCM arg3) { + SCM_ASSERT_STRING (arg1, SCM_ARG1, "connection-write-string"); + SCM_ASSERT_STRING (arg2, SCM_ARG2, "connection-write-string"); + SCM_ASSERT_STRING (arg3, SCM_ARG3, "connection-write-string"); + + string in1= scm_to_string (arg1); + string in2= scm_to_string (arg2); + string in3= scm_to_string (arg3); + + // SCM_DEFER_INTS; + connection_write (in1, in2, in3); + // SCM_ALLOW_INTS; + + return SCM_UNSPECIFIED; +} + +SCM tmg_connection_write (SCM arg1, SCM arg2, SCM arg3) { SCM_ASSERT_STRING (arg1, SCM_ARG1, "connection-write"); SCM_ASSERT_STRING (arg2, SCM_ARG2, "connection-write"); @@ -4139,6 +4156,7 @@ initialize_glue_basic () { scm_new_procedure ("enter-secure-mode", (FN) tmg_enter_secure_mode, 0, 0, 0); scm_new_procedure ("connection-start", (FN) tmg_connection_start, 2, 0, 0); scm_new_procedure ("connection-status", (FN) tmg_connection_status, 2, 0, 0); + scm_new_procedure ("connection-write-string", (FN) tmg_connection_write_string, 3, 0, 0); scm_new_procedure ("connection-write", (FN) tmg_connection_write, 3, 0, 0); scm_new_procedure ("connection-cmd", (FN) tmg_connection_cmd, 3, 0, 0); scm_new_procedure ("connection-eval", (FN) tmg_connection_eval, 3, 0, 0); diff --git a/src/src/Guile/Glue/glue_editor.cpp b/src/src/Guile/Glue/glue_editor.cpp index 9456377a..08cd5241 100644 --- a/src/src/Guile/Glue/glue_editor.cpp +++ b/src/src/Guile/Glue/glue_editor.cpp @@ -2222,16 +2222,29 @@ tmg_spell_replace (SCM arg1) { } SCM -tmg_session_complete_tryP (SCM arg1) { - SCM_ASSERT_TREE (arg1, SCM_ARG1, "session-complete-try?"); +tmg_session_complete_command (SCM arg1) { + SCM_ASSERT_TREE (arg1, SCM_ARG1, "session-complete-command"); tree in1= scm_to_tree (arg1); // SCM_DEFER_INTS; - bool out= get_server()->get_editor()->session_complete_try (in1); + string out= get_server()->get_editor()->session_complete_command (in1); // SCM_ALLOW_INTS; - return bool_to_scm (out); + return string_to_scm (out); +} + +SCM +tmg_custom_complete (SCM arg1) { + SCM_ASSERT_TREE (arg1, SCM_ARG1, "custom-complete"); + + tree in1= scm_to_tree (arg1); + + // SCM_DEFER_INTS; + get_server()->get_editor()->custom_complete (in1); + // SCM_ALLOW_INTS; + + return SCM_UNSPECIFIED; } SCM @@ -2808,7 +2821,8 @@ initialize_glue_editor () { scm_new_procedure ("replace-start", (FN) tmg_replace_start, 3, 0, 0); scm_new_procedure ("spell-start", (FN) tmg_spell_start, 0, 0, 0); scm_new_procedure ("spell-replace", (FN) tmg_spell_replace, 1, 0, 0); - scm_new_procedure ("session-complete-try?", (FN) tmg_session_complete_tryP, 1, 0, 0); + scm_new_procedure ("session-complete-command", (FN) tmg_session_complete_command, 1, 0, 0); + scm_new_procedure ("custom-complete", (FN) tmg_custom_complete, 1, 0, 0); scm_new_procedure ("view-set-property", (FN) tmg_view_set_property, 2, 0, 0); scm_new_procedure ("view-get-property", (FN) tmg_view_get_property, 1, 0, 0); scm_new_procedure ("clear-buffer", (FN) tmg_clear_buffer, 0, 0, 0); -- 2.11.4.GIT