English 中文(简体)
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

最佳回答

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).

问题回答

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.

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.

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

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.




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签