Version 0.99-19  

JED FAQ List

 

Questions

Q1. How can I fix my backspace key?

Q2. How do I make the TAB key work?

Q3. How do I set the tab-width to 4?

Answers

A1. How can I fix my backspace key?

If you are having a problem with the backspace key on a Unix system, then you probably have a misconfigured terminal.

Jed queries the terminal driver to obtain the backspace key setting, You can check terminal driver's settings by using the stty command at your shell prompt, e.g.,

     $ stty -a
     speed 38400 baud; rows 36; columns 80; line = 0;
     intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
     [...]
Here, the backspace key is given by the erase setting. If, as shown in the above example, the erase character is ^? (DELETE) and not ^H (BACKSPACE), then jed will assume that the backspace key generates ^? and not ^H. Hence, as part of its emacs emulation, it will bind ^H to the help functions. However, if pressing the backspace key from within jed causes a help window to pop up, then the character sent by your terminal is most likely a ^H, and not ^? as indicated by the terminal driver. In other words, you have a configuration problem: Your terminal driver thinks ^? is backspace, but your terminal, e.g. xterm, is using ^H.

One way of fixing this is to put the appropriate xterm entries into your .Xdefaults file, e.g.,

     XTerm*ttyModes: erase ^?
     XTerm*VT100.Translations:  #override \
        <Key>BackSpace:       string(0x7f)
The other way is to use the stty program to change the erase character to ^H.

If all else fails, you can put

     map_input (8, 127);
in your .jedrc file to cause jed to map ^H to ^?.

A2. How do I make the TAB key work?

Many modes will set the TAB key to run an indent_line function. The rationale for this is that many people feel that it is better to have the editor determine how to indent a line in a context-sensitive way rather than manually via TABS.

If you really want the TAB key to insert TABs, then put the following in your .jedrc file:

     public define global_mode_hook (hook_name)
     {
        local_setkey ("self_insert_cmd", "\t");
     }
     setkey ("self_insert_cmd", "\t");

One can also define the behavior of the TAB key on a mode-by-mode basis. Consider text_mode, where the TAB key is bound to the text_indent_relative function. Since I find this function to be somewhat non-intuitive, in my .jedrc file, I use:

     define text_mode_hook ()
     {
        local_setkey ("indent_line", "\t");
     }
Of course if you want the TAB key to insert a TAB in text_mode, then bind it to self_insert_cmd as in the global_mode_hook above. If you want to use the TAB to insert so-called simulated TABs through the use of space characters, then instead of binding the TAB key to self_insert_cmd, bind it to the insert_simulated_tab function instead, e.g.,
     public define global_mode_hook (hook_name)
     {
        local_setkey ("insert_simulated_tab", "\t");
     }
Not all versions of jed support the insert_simulated_tab function, which was not introduced until version 0.99-17. If you are using such version, then you will need to define it in your .jedrc file:
     public define insert_simulated_tab ()
     {
        insert_spaces (TAB - (what_column () - 1) mod TAB);
     }

A3. How do I set the tab-width to 4?

Before answering this, do you really understand what you are asking? A TAB in a file is nothing more than a character whose ASCII value is 9. Unlike most other ASCII characters, the displayable representation of the TAB character is device dependent. So, one answer to this question would be to look at your terminal's manual to find out how it handles TAB characters. For this reason, many people feel that it is best to stick to the standard value of 8 for the tab-width, or avoid TABs altogether.

Let's assume that you are aware of this issue but are forced to edit a file written by someone else, or are mandated by some policy requiring the tab-width to be 4. Jed has several variables controlling the use of TABs: TAB, TAB_DEFAULT, and USE_TABS.

The TAB variable is a buffer-local variable controlling the width of a TAB for the current buffer. Its value in one buffer may not be equal to its value for other buffers.

The TAB_DEFAULT variable controls the default value of the TAB variable for new buffers. So, if you read a file, the initial value of the TAB variable for the buffer associated with the file will be equal to the value of TAB_DEFAULT.

The USE_TABS variable controls whether or not TABS should be used when generating whitespace. If you must use a non-standard value for the tab-width, then it is probably best to avoid TABS altogether and set USE_TABS to 0.

With the above in mind, what should you put in your .jedrc file? If you want to display TABS as 4-column, then put

    TAB_DEFAULT = 4;
in your .jedrc file. If you want to "simulate" such tabs with spaces (a good idea if using a non-standard value), then also add
    USE_TABS = 0;
If you want to use standard 8-column tabs for all modes except C mode, then you will need to create a c_mode_hook for that purpose:
    TAB_DEFAULT = 8;
    public define c_mode_hook ()
    {
       TAB = 4;
    }

The use of these variables has no effect upon the action of the TAB key. See the previous FAQ for information about that.


This page was last updated Nov 26, 2017 by John E. Davis.
To comment on it or the material presented here, send email to jed at jedsoft org.
Valid HTML 4.01! Made with JED Viewable With Any Browser