Tags:
create new tag
, view all tags
Do not bookmark or link to this page under it's current name, I couldn't think of a good name (concise, meaningful) but wanted to start the page anyway, and feel like I'll almost certainly change the name in the next day or two.

I've finally done some Nedit key bindings by modifying the X resources translation table. I ran into several problems along the way and the purpose of this page is to record my learnings.

BTW, making the key bindings via the translation table is very useful (to me, at least) because I can create multiple key shortcuts (I tried a 3 key assignment just for kicks). I also made the assignments so that the "Win" (mod4, Mod4, Super_L, Super_R) key is the modifier key, which is very nice because it's pretty much a virgin namespace (with one interesting exception, so far).

%SECTION{summary}%

%SECTION{last_update}%

%SECTION{summary}%How to assign key bindings in Nedit using the X resources translation table, which gives you the benefit of greater flexibility (multiple key bindings, for example).

I had hoped to make this the perfect authoritative yet concise page summarizing how to do this (for "experts") and explaining how (for "beginners"). Unfortunately, I found more confusion than I hoped to (which could probably be resolved by more research (reading) and testing. However, I don't think I'm going to do all that, so I will probably resort to including some "good" and "bad" examples with some commentary.

See also:

This second draft of this page will present the material more completely than I intended, as, in the future (as time allows, the situation arises, ...), I will remove stuff from this page and move it to the relevant page listed above.

As opposed to my normal writing practice, and partly because I'm at a computer away from some of the resources (emails) I planned to use on this page, I'm going to try to write an outline first:

  • Introduction (generally what I've written above, already)
  • List of steps to assign a key using the translation table approach (can I remember them while I'm here??):
    • Find your ~/.Xdefaults or ~/.Xresources file
    • (Put the file under RCS?)
    • Add one translation table line, and one key assignment line for each key binding
      • Cover the file format (the /n/ gotcha)
      • Show some examples
    • run the merge utility
    • test (start a new instance of Nedit)
    • check the file back into RCS

  • Must some of these commands be rerun on each bootup
    • If you make modifications to (via) xmodmap they are not sticky (must be redone at each reboot)
    • The changes to the ~/.Xdefaults file should be permanent, I don't know if the merge utility has to be repeated after a reboot (or X restart)

  • Aside: what if the Win key (Mod4) is not set up as a modifier key (mods to xmodmap) (And a list of allowed modifiers, why are they capitalized and why they don't match what I see with xmodmap)

  • Other useful programs, appres, xev

  • Aside: mention the <Mod4>w (<Win>w) "anomaly"

See:

Contents

Introduction

This page is intended to discuss and explain how to edit your system's X resources file (~/.Xdefaults or ~/.Xresources) to bind ("shortcut") keys to various actions (including your own programmed "macros") in Nedit.

By editing the X resources file you can change things like colors, fonts, and key bindings for (almost?) any application that runs "under" ("on top of"?) X. To learn more, see X Resource Manager.

In the course of assigning key bindings to actions in Nedit, you may have to find out specific things about how your keystrokes are currently being interpreted. I will touch on those things on this page, but you may want to see these pages to learn more:

I won't (don't plan to) hold your hand every step of the way through this trying to instill good working practices, but I will remind you (more than once, probably) of some. In particular, back up the original X resources file before you start.

Steps

Before You Start

Find either your ~/.Xdefaults or ~/.Xresources file (whichever your system uses) and back it up. My current preference is to back up such files by putting them under RCS control.

Modify the File

Edit either your ~/.Xdefaults or ~/.Xresources file adding lines something like this:

NEdit*text.Translations: #override \
       Mod4<Key>g: insert_string("<Win>g") \n\
       Mod4<Key>y,Mod4<Key>g: insert_string("<Win>y,g") \n\
       Mod4<Key>w: macro_menu_command("TWiki>template>base") \n\
       Mod4<Key>x: macro_menu_command("Text>Remove Hard Wrap") \n\
       Ctrl Alt<Key>w: insert_string("Hi5!")

Notes:

  • Some of the formatting of those lines is very critical some is meaningless. In particular:
    • The first line must end with a \, all subsequent lines except the last must end with a \n\, and there can be no trailing spaces on any of the lines (except perhaps the last??). The reason for this is explained [[][#here]].
    • There must be a space (??) after the : separating the "shortcut key" from the action.
    • Other than that, whitespace (spaces and tabs) can be added as desired for readability.

Lets examine each of these lines to see what they do:

  • "NEdit*text.Translations: #override \"
    • Without knowing all the details, this basically says that the following modifications are for the translation table associated with any text "widget" in Nedit.
    • The #override keyword says that the definitions specified here will override any definition already existing in the translation table for Nedit text widgets. Alternate keywords (for #override) are #augment and . I can guess at their meaning, but have no first hand experience.
    • It is helpful to have some background on how the resource manager works, see [[][# ]].

  • "Mod4g: insert_string("g") \n\"
    • On my system, Mod4 is the modifier related to the Win key. On your system, there might be no modifier assigned to the Win key, or it may be some different modifier. See [[][# ]] for information on how to test and modify your system if necessary.
    • Thus, this line says that if the g key is pressed while the Win key is held down, the Nedit function insert_string() will be invoked to insert "<Win>g" at the current location of the cursor in the current text area / window.
    • Aside:

  • "Mod4y,Mod4g: insert_string("y,g") \n\"
    • This line says that if you hold down the Win key and press y and then g, the Nedit function insert_string() will be invoked to print "<Win>y<Win>g" at the current location of the cursor in the current text area / window.
    • We will come back to the previous two assignments several times, the assignments do not quite match my preference, but this may be the best possible compromise within the limits of how X and the translation table work.

* "Mod4w: macro_menu_command("TWiki>template>base") \n\" * If the Win key is held while the w key is pressed, Nedit will invoke a macro that I wrote and can be reached on the macro menu by pointing to Macro -> TWiki -> template -> base.

* " Mod4x: macro_menu_command("Text>Remove Hard Wrap") \n\" * If the Win key is held while the x key is pressed, Nedit will invoke a macro that I wrote and can be reached on the macro menu by pointing to Macro -> Remove Hard Wrap (the macro name on the menu includes spaces.

* "Ctrl Altw: insert_string("Hi5!")" * If the Ctrl and Alt keys are held while the w key is depressed, Nedit will invoke insert_string() to print "Hi5!" at the current location of the cursor in the current text area / window.

Now I want to get into some of the subtleties (oftentimes involving things I tried to do but did not work). An underlying theme of this discussion will be that I recommend you use the Win key for the modifier for most of your key bindings, you will run into fewer gotchas.

Also, I'll point out that I got confused at several points in doing this testing (initially) — one reason was that several times I tried an assignment, the syntax was wrong so the assignment was not really effective, but I didn't notice the error message. The way I found that was best for me was, after revising .Xdefaults and merging it, to invoke Nedit as Nedit & from something like a (KDE) konsole (or xterm). Then as Nedit starts up and reads the resource file (if that's an accurate description of what it does), any errors that occur will be printed in the konsole. Look for those, and react appropriately. (More discussion later??)

Anyway, lets go back to the first two lines of the assignment we just reviewed (with the final \n\ removed, so this is the complete _):

NEdit*text.Translations: #override \
       Mod4g: insert_string("g") \n\
       Mod4y,Mod4g: insert_string("y,g")

If we make those assignments, here's what will happen in Nedit as we press selected keys:

Press Displayed
g g
<shift>g G
<Win>g "<Win>g"
<Win>y<Win>g "<Win>y<Win>g"

Seems reasonable, and except for the last, which is not my normal preference, is perfectly acceptable.

Now let's try this:

nedit*text.Translations: #override Mod4g: insert_string("g") \n Mod4y,g: insert_string("y,g")

I'm hoping that this will let me use my preferred binding to invoke the last function: <Win>y,g (hold Win while pressing y, then release both and press g). Here's what actually happens:

Press Displayed
g <nothing>
<shift>g <nothing>
<Win>g "<Win>g"
<Win>y<Win>g "<Win>y,g"

Oops, a little bit of a problem there (unless you can write everything you need to write without any g's).

Ok, let't try to fix it, maybe try (it looks a little kludgy, but hey, if it solves the problem):

nedit*text.Translations: #override \
 g: insert_string("g") \n\
 Mod4g: insert_string("g") \n\
 Mod4y,g: insert_string("y,g") 

Here's what actually happens:

Press Displayed
g g
<shift>g g
<Win>g g
<Win>y<Win>g "<Win>y,g"

Hmm, I got my preferred key binding for the last item, but there are a few other problems wink

Ok, let's try again:

nedit*text.Translations: #override \
 ~Mod4g: insert_string("g") \n\
 Mod4g: insert_string("g") \n\
 Mod4y,g: insert_string("y,g")

The "~" in front of Mod4 on the second line means not, in other words, if you press g without the Win key, Nedit will invoke insert_string() to print "g" in your document.

Here's what actually happens:

Press Displayed
g g
<shift>g g
<Win>g "<Win>g"g
<Win>y<Win>g "<Win>y,g"

So, now I have 3 out of 4, but wink

Ok, another try:

nedit*text.Translations: #override \
 Shiftg: insert_string("G") \n\
 ~Mod4g: insert_string("g") \n\
 Mod4g: insert_string("g") \n\
 Mod4y,g: insert_string("y,g")

Press Displayed
g g
<shift>g G
<Win>g "<Win>g"g
<Win>y<Win>g "<Win>y,g"

Ok, an alternate solution that seems reasonable, and accomplishes my preferred shortcut style of <Win>y,g, but seems a great deal more kludgy (and more work) than the first reasonable solution (which sacrifices my preferred shortcut style).

So, what was the purpose of this exercise? I wanted you to see some of the problems that can arise as you assign keyboard bindings. Note that these problems occur in what I will call a "clean" "shortcut namespace", the Win "namespace", as opposed to a "dirty" namespace like "Ctrl" or "Alt".

Let me give you just one example of the problems that can occur in one of those dirtier "namespaces". (Sorry for switching from g to a, it's just a consequence of some of the trial and error I went through, and I'm getting bored. (If I was getting paid for this ...))

nedit*text.Translations: #override Alta: insert_string("a") \n Alty,Alta: insert_string("y,a")

Results:

Press Displayed
a a
<shift>a A
<Alt>a toggles the Nedit status line appear
<Alt>y<Alt>a toggles the Nedit status line appear

The problem here is that Nedit has two mechanisms for assigning keyboard shortcuts, this approach using the translation table, and the other approach using (menu) accelerators. Unfortunately (or maybe fortunately??), the accelerator keys take precedence and lead to an extra level of interaction and potential confusion.

So, my recommendation is to stick with a "virgin" shortcut namespace, e.g. use the Win key rather than the Ctrl or Alt keys as the modifier for your keyboard shortcuts assigned via the translation table.

Contributors

  • () Main.RandyKramer - 30 Jan 2004
  • If you edit this page: add your name here; move this to the next line; and if you've used a comment marker (your initials in parenthesis), include it before your TWiki.WikiName.

Revision Comment

%SECTION{last_revision}%
  • %DATE% —

Page Ratings

Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2004-02-04 - RandyKramer
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by PerlCopyright 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding WikiLearn? WebBottomBar">Send feedback
See TWiki's New Look