Back to index

texmacs  1.0.7.15
complete.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : complete.cpp
00004 * DESCRIPTION: Shows how to program tab-completion
00005 * COPYRIGHT  : (C) 2003  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include <iostream>
00013 using namespace std;
00014 
00015 #define DATA_BEGIN   ((char) 2)
00016 #define DATA_END     ((char) 5)
00017 #define DATA_COMMAND ((char) 16)
00018 #define DATA_ESCAPE  ((char) 27)
00019 
00020 void
00021 format_plugin () {
00022   // The configuration of a plugin can be completed at startup time.
00023   // This is for instance interesting if you add tab-completion a posteriori.
00024   cout << DATA_BEGIN << "command:";
00025   cout << "(plugin-configure complete (:tab-completion #t))";
00026   cout << DATA_END;
00027 }
00028 
00029 int
00030 main () {
00031   cout << DATA_BEGIN << "verbatim:";
00032   format_plugin ();
00033   cout << "We know how to complete 'h'";
00034   cout << DATA_END;
00035   cout.flush ();
00036 
00037   while (true) {
00038     char buffer[100];
00039     cin.getline (buffer, 100, '\n');
00040     if (buffer[0] != DATA_COMMAND) {
00041       cout << DATA_BEGIN << "verbatim:";
00042       cout << "You typed " << buffer;
00043       cout << DATA_END;
00044     }
00045     else {
00046       cout << DATA_BEGIN << "scheme:";
00047       cout << "(tuple \"h\" \"ello\" \"i there\" \"ola\" \"opsakee\")";
00048       cout << DATA_END;
00049     }
00050     cout.flush ();
00051   }
00052   return 0;
00053 }