I'm using MulgaSoft's fantastic Emacs+ Eclipse Plug-in to make Eclipse usable for my emacs'd fingers.
However, I am unable to setup a working Alt+q binding for 'Format Element'. When writing a comment, for example in Java code, I'd like to be able to hit Alt+q from time-to-time to re-flow the current paragraph of text. (Mostly I just want the comment to wrap at ~80 columns.)
So, I went into Preferences -> General -> Keys
and bound Format Element
to Alt+Q
"when" Editing in Structured Text Editors
(category Source
).
If I type Alt+x format-element with the cursor in a long Java comment the correct thing happens (the text reflows). But hitting Alt+q does not do anything.
If I ask Eclipse what Alt+q is bound to (by typing Ctrl+h k Alt+q), I get:
Alt+Q runs format-element Id -org.eclipse.wst.jsdt.ui.edit.text.java.quick.format Key Bindings ALT+Q [org.eclipse.ui.contexts.dialogAndWindow] Description Format enclosing text element
As far as I can tell (by sorting on 'Binding') in the Key preferences nothing else is bound to Alt+Q. (Well, I tried binding it in some additional "When" contexts, but that didn't help ...)
I'm not sure if this is a problem with the Emacs+ plugin or with Eclipse (since "Format Element" is an eclipse primitive?). I've restarted Eclipse more than once with these bindings defined.
Update
With @mfeber's suggestions I've tweaked the key bindings, but am still not having success. I've reduced to just one binding with a "when" of just Editing Text
.
Now when I run Ctrl+h k Alt+q I see:
Alt+Q runs format-element Id -org.eclipse.wst.jsdt.ui.edit.text.java.quick.format Key Bindings ALT+Q [org.eclipse.ui.textEditorScope] Description Format enclosing text element
The difference is the "[org.eclipse.ui.textEditorScope]" in the Key Bindings section. The new value does better match what other key bindings like "Ctrl+O" show.
Oddly, if I run Ctrl+h w format-element I get:
format-element is unbound
But running Ctrl+h w for other commands like forward-character or insert-line-above-current-line does print the correct list of key bindings for that function. So there is something a bit wacky still.
One other thing I noticed is that there is a 'Format Element' entry in the key bindings that has a blank 'When' and 'Binding' (the above screenshot was sorted on 'Binding' so it didn't show this, but I'm pretty sure it was there before):
Are there any tools or logs for debugging key bindings in Eclipse that I can turn on?
Update #2
To figure out which underlying id is being bound (as @mfeber's update suggested), I've tried a couple more things.
I've setup multiple bindings of Alt-Q to format-element in different contexts:
(I've tried with and without the 'Editing Text' binding --- I'm not sure if 'Editing Text' might apply/conflict when editing .java or .py files, or if its purely for .txt files... Anyway I can't see much of a difference....)
The only interesting information I've been able to gather is that the Ctrl+h k Alt+q shows very slightly different results when run in a .java editor and when run in a .js editor:
Here is what I get from Ctrl+h k Alt+q in a Java source editor:
Alt+Q runs format-element Id -org.eclipse.wst.jsdt.ui.edit.text.java.quick.format Key Bindings ALT+Q [org.eclipse.jdt.ui.javaEditorScope] Description Format enclosing text element
And here is what I get from Ctrl+h k Alt+q in a Javascript source editor:
Alt+Q runs format-element Id -org.eclipse.jdt.ui.edit.text.java.quick.format Key Bindings ALT+Q [org.eclipse.wst.jsdt.ui.javaEditorScope] Description Format enclosing text element
The difference is the wst.jsdt
vs jdt
in the package paths. I don't really understand this, but I think it means I'm running the java formatter when in a javascript window, and the javascript formatter in a java window?
Oh ... that's it! If I switch the 'When' for each of those bindings, now Alt-Q works! So, despite all the key bindings looking identical in the UI, there are several different functions being bound underneath....