"Linux Gazette...making Linux just a little more fun! "


About Linux text editors / product announcement

By Oleg L. Machulskiy machulsk@shade.msu.ru



Generally about UNIX text editors

All of my friends who use Linux always told me that text editors is very important problem under this OS (I mean text-mode editors with 100K executable for writing programs). As I understand, this problem is not a problem of Linux itself, but it's a problem of every UNIX. What's more I know which reasons cause this trouble. There is two reasons: putc output to screen and getc input from keyboard. In other OS-es user (programmer) can catch Alt+<letter> or Shift+<letter> keystrokes and use it as a commands of editor. In UNIX user has only 256 ASCII-codes avialable (really, much less than 256) and because of it every UNIX editor uses either very long sequences of keystrokes as editing commands (as emacs or joe) or it has two editing modes (command mode and typing mode in VI for example). On X-s everything is better, because here we can get scan code (not real scan, but this code is anough for all my needs) of the key pressed and status of Shift-keys (Alt, Caps, Shift, Ctrl and mouse buttons), so we can use functional keys, arrow-keys and everything else You can find on Your keyboard (everybody knows how to do that).

But even with text mode editors under Linux everything is not so bad: You can switch keyboard to RAW mode and do with it all You want (don't forget to get another console from which You will execute shutdown -r now command during beta-testing Your program). But it's very important to understand that RAW-keyboard programs will not work through telnet. Also is very important to set SIGSEGV and SIGKILL signal handlers so that they'll switch keyboard back to normal mode from RAW when something happens. Once I heard about kernel patching so that You can use ScrollLock key to switch between raw and normal mode, but I don't know how to apply this patch.


What I'd like to have in text editor

Caution : This section is very private. Maybe someone will find something useful for him(here) here, but probably not. This section is mostly about my own text editor, so, if You got used to Turbo-Vision-like editors and You're satisfied, then probably You will find the follwing not interesting. So don't read it, don't waste Your time.

  1. Editor must be the same on every operating system (multi-platform).

  2. Editor must handle advanced search feature: I need not only case sensetive/insensetive search, but as a minimum a wildcard searh or regular expressions search (this type of search includes wildcards).

  3. Editor must support projects: user must be able to create a list of files (sources of some program) and walk through these files freely (enter into file, quit from file, switch to another file, ...). The possible solution is to assign some keystroke as an "enter-into-file" command, and then, when user invokes "enter-into-file", open a file with a name similar to the word under cursor (For example, you can enter in h-file from the text of c-program; just move cursor to the #include "..." statement and press the "enter-into-file" key).

  4. Editor must handle many files opened at the same time so that user can freely move from one text to another (very often I need to read declarations of functions in .h files)

  5. Editor must support compiling, make etc. from within text editor (generally: execution OS command from within editor)

  6. Commands must be rather simultaneous pressings of a few keys than sequences of keystrokes. It seems to me, it isn't comfortable to type (F10, 'F', 'O' , filename) every time You need to open a new file. Besides, with such a keyboard layout it's impossible to work fast. This requirement causes a problem: text editor cannot work through telnet, because telnet protocol transfers only ASCII-codes, but not scan-codes.

  7. Text editor must consider a text not as a sequence of chars but as a sequence of lines, where each line is a sequence of chars. There is a lot of text editors in which text is a vector (For example ME (MSDOS MultiEdit) , Turbo Editor (Borland Programming Environments), JOE (linux), etc.), But I don't know how to work with tables in these editors or how to set // (C++ comment) at the beginning of 10 lines of program on the screen.

  8. Editor must support macrocommands as a recordable sequences of keystrokes.

  9. If editor supports programming language, so that I can write my own commands, it would be fine.

  10. I think programs-structurizing is very useful feature. I'll explain: I'd like to have text of my program in pre-hypertext form so that I see a list of functions on the screen, I put cursor on the name of desired function, press "open"-key and now I can edit source of that function, but besides that I must be able to edit this file with usual text editor and I must be able to compile that file without errors, hence all additional info about hypertext structure of program must be placed into comments (comments are specific for each file type, but in most cases it depends on file extension).

  11. Keyboard layout must be as much tunable as possible (if my End key is broken, I can use F11 key instead). Besides I often need keyboard layout for second language (cyrillic).

  12. I don't like when editor wastes screen space on frames of windows or any other unuseful things (80 * 25 isn't very roomy)

  13. Font on the screen must be fixed (I hate proportional fonts).

If You're interested in all that, You can try our example of such a text editor. I think it isn't the best editor, but I got used to it. May It will be useful for someone. To get it, go to http://shade.msu.ru/~machulsk and download 330K zip file, which contains sources and 5 executables for Linux console, Linux X11, OS/2, DOS and Win32 (95/nt). Docs are also included in HTML / plainTeX format.


Example of switching to RAW keyboard mode (C++ syntax)

  
   #include < stdio.h >
   #include < stdlib.h >
   #include < unistd.h >
   #include < errno.h >
   #include < linux/kd.h >
   #include < signal.h >
   #include < sys/ioctl.h >
   /*.................*/
   void Terminate(int a) {
       if( ioctl(con_fd,KDSKBMODE,om)<0 ) {puts("Press RESET?");exit(-1);}
                  /*trying to set old keydoard mode*/
       }
   /*.................*/
  class TKeyboard{
     int om; /* old keyboard mode descriptor */
     int con_fd; /* console descriptor */
     TKeyboard(){
         signal(SIGKILL, Terminate ); /*setting SIGKILL signal handler*/
         signal(SIGQUIT, Terminate ); /*setting SIGQUIT signal handler*/
         signal(SIGSEGV, Terminate ); /*setting SIGSEGV signal handler*/
         if( 0==(con_fd=open("/dev/tty",O_RDWR)) ) {puts("error");exit(-1);}
                           /*getting console descriptor*/
         if( ioctl(con_fd,KDGKBMODE,&om)<0 ) {puts("error");exit(-1);}
                           /*getting old keydoard mode*/
         if( ioctl(con_fd,KDSKBMODE,K_RAW)<0 ) {puts("error");exit(-1);}
                           /*setting RAW keydoard mode*/
         }
     ~TKeyboard(){
         Terminate(0);
         }
     int GetScanCode(){
         int c;
         ioctl(con_fd,TIOCINQ,&cd); /*query*/
         if(cd==0) /*keyboard buffer is empty*/
         read(con_fd,&c,1); /*get next scancode from console*/
         }
     } KBD;
   /*.................*/
   void main() {
       /*.................*/
       /*................. program body */
       /*.................*/
       }

Thank You!

My addresses: machulsk@shade.msu.ru
homepage on(in?) Shade

scuze me for bad english, but my native language is Russian


Copyright © 1997, Oleg L. Machulskiy
Published in Issue 13 of the Linux Gazette


[ TABLE OF CONTENTS ] [ FRONT PAGE ]  Back  Next