Tell Eclipse to auto-complete only method name? - eclipse

Let's say I'm editing a line...
obj.fooBar(x, y, z);
I want to change the method name to fooSomethingElse, but keep most of the arguments. If I delete all or part of the name, and then use content assist, it completes the method name, but starts a new arg list...
obj.fooSomethingElse(arg1, arg2)(x, y, z)
^---- this arg is highlighted for editing
I often have to delete "(arg1, arg2)". I can turn off "fill method arguments" in preferences and then I only have to delete "()", but it's still annoying. Is there another command to complete only the method name. Ideally it would just be a separate command and key combo from the general purpose content-assist, so I can invoke either one as needed.

Essentially you are looking for a way to toggle between inserting and replacing via content assist. The default behavior is to insert. You can toggle this behavior while inside the content assist selection dialog by pressing and holding the Ctrl key while selecting the completion.
More inforation - http://blog.deepakazad.com/2012/06/jdt-tip-toggle-between-inserting-and.html

I think you just need to press tab instead of enter to autocomplete it. Then it will keep your existing parameters.

Related

How do I duplicate the cursor in VS code matching text?

I want to be able to select a piece of text in VSCode and hit a button and then have it select the next time that same piece of text appears in the document, then hit it again to select the third etc. What I say select, I want to duplicate the cursor. So I can edit multiple occurrences in one go.
I want to know what the actual command is so I can bind a key to it, not the default keybinding for it.
The command is named "Select all occurrences" and it produces one cursor for each occurrence of the word under cursor (or for each occurrence of the current selection, if a selection exists).
It is, by default, triggered by the keyboard combination Ctrl-Shift-L (Cmd-Shift on macOS) but you can assign a different combination if you need.
Another similar key combination is Ctrl-F2 (Cmd-F2). It is named "Change all occurrences".
Besides adding cursors, both commands also select the current word, if a selection does not exist, so that it can be deleted or replaced easily.

viewing method signatures with parameter highlighting in NetBeans

When the cursor's positioned in the middle of an argument list (making a method call), is there a way to bring up the method's signature with the parameter that that the cursor is on highlighted? Ctrl-space (sort of) brings up the signature, but it includes the huge search list of everything else I can legally type right there, and it's up to me to count through the arguments and the parameters to figure out which one I'm lined up on. (that popup also disappears if I try to move to the next or previous argument).
I've had this struggle with compiled code, and worse with code as I type it in. I typically type the name of the object, then a dot, and then I wait for the signature list to pop up (that filters down as I type). When I see the signature I'm after, I auto-complete with tab or Enter, and then I always end up in a struggle. NB pastes in variable names that are usually about 99% wrong, and I try to navigate the little red, comma-triggered edit boxes, hoping the signature popup will stay in view while I struggle to edit, delete (and stop thinking about) all the (semantic) errors. I usually end up botching it and loose the precious signature window that highlights each parameter as I moved through the argument list.
Any way to get that thing back (with the parameter highlighting)? And/or make the red editing boxes go away? And/or block NB from populating with all the errors?
Super thankful for any help or tips!
Netbeans show popup with method signatures and popup with method documentation only when your cursor is placed at the name of a method. Popup is displayed automatically when writing method name or on demand if you press Ctrl+Space.
When your cursor is placed at the argument list, only parameter names from method signature are displayed in form of a small tooltip. You can force display of this tooltip by Ctrl+P. Unfortunately there is no way how to invoke popup with method documentation in this phase. Instead you will see documentation popups related to arguments which you will type into the method argument list. The only way to display method documentation again is to place the cursor back at the method name and press Ctrl+Space.
When you start writing a method name, popup with method signatures will emerge. When you select one of proposed method signatures by pressing Enter, Netbeans will autocomplete method name as well as its arguments. You find this uncomfortable, because names of autocompleted arguments are usually wrong. You can however easily navigate between autocompleted arguments using Tab and Shift+Tab and overwrite them as you like. Alternatively, you can use Tab instead of Enter when selecting method from method signatures popup. This way Netbeans will autocomplete only the name of the function, not its arguments.
Described Netbeans behavior applies to editing PHP code, and may differ slightly for other languages.

How to trigger documentation popup in vscode

How to trigger a popup with documentation for identifier under the cursor?
Normally it appears when hovering the identifier using the mouse pointer:
I would like to achieve this effect using a command or keyboard shortcut.
The only related commands I found are: trigger completion (which doesn't show the function doc) and trigger parameters hint (which only works when the cursor is inside function call - parameters list).
This is the editor.action.showHover command. It is bound to cmdk cmdi by default.
Note: Shortcut works by holding down the cmd [ctrl in windows], then while holding press k then i
You can change the keyboard shortcut with a keybinding such as:
{
"key": "cmd+k ctrl+space",
"command": "editor.action.showHover",
"when": "editorTextFocus"
}
The default shortcut for Trigger Parameter Hints is Ctrl+Shift+Space
You also have, with VSCode 1.40 (Oct. 2019):
Definition Preview Hover from the keyboard
There is a new command Show Definition Preview Hover for better accessibility of the definition preview hover widget, which can be triggered by hovering a symbol with the mouse and pressing a modifier key dependent on the platform and configuration.
Previously, only the command Show Hover was provided, which is equivalent to hovering the mouse cursor over a symbol.
Now, with Show Definition Preview Hover, the detailed hover information can be shown via the keyboard.
To make this more graphic, check these steps:
In Visual Studio 2019 for Mac, I couldn't find anything about "hover" in the Key Bindings setting. The relevant command seems to be called "Show quick info" and is bound by default to Cmd + F1.
I know this question is about VSCode but I could only find this question when trying to search for an answer. Therefore I would also like to leave the information here in case somebody finds it useful.
There are multiple ways to trigger the documentation popup:
First: Using shortcut ctrl + space
Second: Using vscode extension:
Here is the documentation:
Each answer here demonstrates a different function. Below is a consolidation of every type of helpful popup, the context in which they come up and all the ways I know to trigger them.
These assume default settings.
Function: Display documentation
Shortcut: Ctrlk Ctrli
Scope: Works over named elements - variable and function names (does nothing over literals).
Can display function documentation:
or variable or even property information:
This is the same pop-up you get when you hover over the element briefly.
Function: Display parameter hints.
Shortcut: CtrlShiftSpace
Scope: Works inside a function call.
The cursor must be inside the parenthesis that contain the passed arguments. Does nothing outside that scope.
Can also be triggered by typing a comma, as if passing another argument.
Up/Down arrows can be used to cycle through overloaded definitions (instead of moving the cursor up and down the document).
Function: Display the code completion menu
Shortcut: CtrlSpace
Scope: Anywhere. Will adapt to the context. In strings will display words only. In code will offer symbol hints - function names, variable names within the current scope, known properties, etc.
Is case insensitive.
Matches all contained characters - they do not have to be consecutive (see image above).
Tab or Enter accepts the currently selected suggestion.
Symbol hints can be triggered by just typing letters. Inside strings you must use the keyboard shortcut.

Change default EMACS mouse highlight behaviour

In EMACS the default seems to be to 'copy' any text highlighted with the mouse. I'm attempting to replicate the functionality of modern text editors, where I can highlight a section of text and press 'paste' to replace it. I have so far added
(delete-selection-mode 1)
to my init.el
The problem is, if I copy something, then highlight to paste in its place, I end up pasting what I had just highlighted, changing nothing.
What do I need to change to fix that behaviour?
The most powerful element of emacs is its introspection features, lets have a look at how we can use them to try and solve this problem. We must use the power of the source.
One of the most important tools for introspection in emacs is the describe-key command which is bound to C-h k. It brings up the documentation of whatever keystroke is called after it. So in our case if we press C-h k and then click and drag we will see the documentation for <down-mouse-1> and more importantly for <drag-mouse-1>. The documentation states that "<drag-mouse-1> at that spot runs the command mouse-set-region". Below it then gives some documentation for this command. It says
Set the region to the text dragged over, and copy to kill ring.
This should be bound to a mouse drag event.
See the ‘mouse-drag-copy-region’ variable to control whether this
command alters the kill ring or not.
Now we know that somehow mouse-drag-copy-region controls whether or not the highlighted text is copied.
If we follow the link of that variable it tells us the default value and some documentation:
If non-nil, copy to kill-ring upon mouse adjustments of the region.
Now all we have to do is set the variable to be nil to get the effect that you want. Place the following code at the end of your init file and you should be all set
(setq mouse-drag-copy-region nil)
I hope that this helps you with this problem and that more importantly it helps you with further issues.
By default, selecting a region with the mouse does not copy the text to the kill ring. If your Emacs does this, you probably have set the variable mouse-drag-copy-region.
In a fresh Emacs (24.5 started using -Q), you can do the following:
Start delete-selection-mode.
Mark a region using the mouse. Copy it using M-w.
Mark a second region. Replace it with the first using C-y.
I see two alternatives, neither of which does exactly what you request. (For both, yes, turn on delete-selection-mode.)
Use the secondary selection for the text to copy, and use the primary selection (the region) for the text to be replaced.
You copy text into the secondary selection using the Meta key plus the mouse - for example, press and hold Meta (the Alt key, usually) while dragging or double-clicking mouse-1.
You paste the secondary selection using Meta plus mouse-2.
Select text with the mouse, then copy it to the kill-ring using M-w. Then select the text to replace with the mouse and use C-y to paste the copied text to replace it.

Tab in Emacs-helm (anything) does not autocomplete with current best match

While trying to autocomplete a file (e.g. to open a file with C-x C-f) Emacs-helm shows a list of possible candidates.
If I then press Tab (which I would hope it would help me choose the first/closest match), I get the following in the minibuffer:
It looks like the minibuffer gets confused with escape characters, and it does not choose the file that I actually want to open (the top choice).
Helm requires this conceptual jump from the default Emacs completion, which is not so obvious:
You don't need to press a key to complete. The completion buffer refreshes
with new results after every input.
This is called "incremental" completion.
The normal tab functionality is not needed in "incremental"
completion. So tab was rebound to helm-select-action, which allows you to
choose an alternative action with the selection. But there is only one action
in read-file-name.
The error you're seeing could be clearer though, I've filed this issue on github.
Additionally, note Helm treats each space separated term as a filtering
regular expression. So, pressing space foo will filter
the current list down to those that contain foo in the name.