rh0dium
rh0dium

Reputation: 7052

Eclipse smart quotes - like in Textmate

Happy Friday — Does anyone know if eclipse has the notion of smart quotes like Textmate. The way it works is to select some words and quote them by simply hitting the " key? I'm a newbie here so be gentle. FWIW - I'm using pydev in Eclipse.

Thanks

Rephrase

What I am looking for is given I have a word or phrase selected on the screen, I would like to simply hit the '"' key and have the entire word or phrase enclosed by quotes. The same would apply to various keys — like ([{"'`.

So say I have the following code

a = {}
a[keyword] = 1

Now (in python) keyword should be in quotes. I should be able to double click (select) keyword and simply type the ' and then viola the whole word is quoted. Right now what happens is that keyword is replaced by a single quote... Sigh..

Thanks

Upvotes: 4

Views: 1001

Answers (5)

Fabio Zadrozny
Fabio Zadrozny

Reputation: 25362

In the latest PyDev, it should work exactly as you want already (tested in PyDev 2.2.3 -- this was actually around for some time already).

Upvotes: 1

PadawanRay
PadawanRay

Reputation: 126

Here is one written in Autohotkey:

#NoEnv
SetWorkingDir %A_ScriptDir%
SendMode Input
#InstallKeybdHook
#UseHook On

(::
    if GetKeyState("ScrollLock","T")
    {
        sel := GetSelection(1)
        if sel
            PasteText("(" sel ")")
        else
            Send (
        sel := ""
    }
    else
        Send (
Return

"::
    if GetKeyState("ScrollLock","T")
    {
        sel := GetSelection(1)
        if sel
            PasteText("""" sel """")
        else
            Send "
        sel := ""
    }
    else
        Send "
Return

'::
    if GetKeyState("ScrollLock","T")
    {
        sel := GetSelection(1)
        if sel
            PasteText("'" sel "'")
        else
            Send '
        sel := ""
    }
    else
        Send '
Return

{::
    if GetKeyState("ScrollLock","T")
    {
        sel := GetSelection(1)
        if sel
            PasteText("{" sel "}")
        else
            Send {{}}
        sel := ""
    }
    else
        SendRaw {
Return

[::
    if GetKeyState("ScrollLock","T")
    {
        sel := GetSelection(1)
        if sel
            PasteText("[" sel "]")
        else
            Send [
        sel := ""
    }
    else
        Send [
Return

<::
    if GetKeyState("ScrollLock","T")
    {
        sel := GetSelection(1)
        if sel
            PasteText("<" sel ">")
        else
            Send <
        sel := ""
    }
    else
        Send <
Return


GetSelection(wait = "")
{
    ClipBack := ClipboardAll
    Clipboard := ""
    Send ^c
    if wait
        ClipWait 0.05
    Selection := Clipboard
    Clipboard := ClipBack
    Return Selection
}

After installing Autohotkey, save this code to a text file, rename the extension to .ahk and run it. It requires the Scroll Lock to be turned on for the code to work.

This code is modified from http://www.autohotkey.net/~Vifon/ to:

  1. Include ' and <
  2. Write ', ", <, {, [, ( instead of '', "", <>, {}, [], () when no text is selected.

Upvotes: 0

mpare
mpare

Reputation: 1

You might check out how one of the comment commands work. For example, if I select say 4 lines of code and I want to line comment all of them I can simply select them then hit ctrl+/ and all of the selected lines of code will be commented.

I'm a long time textmate user and I'm missing it something terrible. I forced myself to make a hard switch away from my mac. I'll investigate as time permits but I can't keep getting stuck on minor tweaks at the moment.

-Matt

Upvotes: 0

Eugene Kuleshov
Eugene Kuleshov

Reputation: 31795

For Java and XML files you can create a new template in Window / Preferences / Java / Editor / Templates. The template text could look something like this:

"${word_selection}${}"${cursor}

Then you can apply this template activate code completion using a standard Ctrl-Space (may have to hit it 2 or 3 times to get to the template selector) and then select your quote template.

Upvotes: 2

jeff porter
jeff porter

Reputation: 6620

I think I know what you are asking, is it that...

if you press X-key it will select the current word that the cursor is in?

If that is the question, then I don't think so. There are lots of possible keybinding that are not set in eclipse. See Window > Preferences > General > Keys

Update:

Sorry I don't think there is a action to do this in eclipse. A plugin may exist that you can attach to a key binding, but I'm not aware of one.

Upvotes: 0

Related Questions