Ipython: νƒ­μ˜ μžλ™ 완성을 ctrl-space둜 λ³€κ²½

에 λ§Œλ“  2017λ…„ 04μ›” 11일  Β·  4μ½”λ©˜νŠΈ  Β·  좜처: ipython/ipython

μ•ˆλ…•ν•˜μ‹­λ‹ˆκΉŒ,

μžλ™ μ™„μ„± ν‚€ 바인딩을 ctrl-space둜 λ³€κ²½ν•˜κ³  μ‹ΆμŠ΅λ‹ˆλ‹€. λ‚˜λŠ” 여기에 λŒ€ν•΄ μ½μ—ˆμŠ΅λ‹ˆλ‹€: http://ipython.readthedocs.io/en/latest/config/details.html#keyboard -shortcuts. ν•˜μ§€λ§Œ μ–΄λ–»κ²Œ ν•΄μ•Ό 할지 잘 λͺ¨λ₯΄κ² μŠ΅λ‹ˆλ‹€.

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

기본적으둜 ν”„λ‘œν•„μ˜ μ‹œμž‘ νŒŒμΌμ— 이 μ½”λ“œλ₯Ό μΆ”κ°€ν•˜κΈ°λ§Œ ν•˜λ©΄ λ©λ‹ˆλ‹€.

from prompt_toolkit.keys import Keys
from prompt_toolkit.key_binding.bindings.completion import generate_completions

ip = get_ipython()
bind_key = ip.pt_cli.application.key_bindings_registry.add_binding
bind_key(Keys.ControlSpace)(generate_completions)

ν•˜μ§€λ§Œ ν•΄λ‹Ή μ½”λ“œλ₯Ό μ‹€ν–‰ν•˜κΈ° 전에 항상 PTK둜 터미널을 μ‹€ν–‰ν•˜κ³  μžˆλŠ”μ§€ 확인해야 ν•©λ‹ˆλ‹€. λ‹€μŒκ³Ό 같이 μž‘λ™ν•΄μ•Ό ν•©λ‹ˆλ‹€.

def register_bindings():

    from prompt_toolkit.keys import Keys
    from prompt_toolkit.key_binding.bindings.completion import generate_completions

    bind_key = ip.pt_cli.application.key_bindings_registry.add_binding
    bind_key(Keys.ControlSpace)(generate_completions)

ip = get_ipython()
if getattr(ip, "pt_cli"): register_bindings()
del register_bindings

μ°Έκ³ : 등둝 논리λ₯Ό if 블둝에 넣을 수 μžˆμ§€λ§Œ ν•¨μˆ˜λ₯Ό μ‚¬μš©ν•˜λ©΄ bind_key 와 같은 이름이 μ„Έμ…˜μ˜ λ„€μž„μŠ€νŽ˜μ΄μŠ€λ‘œ λˆ„μΆœλ˜λŠ” 것을 막을 수 μžˆμŠ΅λ‹ˆλ‹€. λ§Žμ€ 바인딩과 μ‚¬μš©μž μ •μ˜ ν•„ν„°κ°€ μ •μ˜λ˜λ©΄ μˆ˜λ™μœΌλ‘œ μ‚­μ œν•΄μ•Ό ν•˜λŠ” 이름이 μƒλ‹Ήνžˆ 많이 μƒμ„±λ©λ‹ˆλ‹€. ν•¨μˆ˜μ— λͺ¨λ‘ 넣은 λ‹€μŒ ν•¨μˆ˜ 이름을 μ‚­μ œν•˜λŠ” 것이 더 κΉ”λ”ν•©λ‹ˆλ‹€. μœ„μ˜ κ°„λ‹¨ν•œ κ²½μš°μ—λŠ” if 블둝이 더 λ‚˜μ„ κ²ƒμž…λ‹ˆλ‹€.

λͺ¨λ“  4 λŒ“κΈ€

기본적으둜 ν”„λ‘œν•„μ˜ μ‹œμž‘ νŒŒμΌμ— 이 μ½”λ“œλ₯Ό μΆ”κ°€ν•˜κΈ°λ§Œ ν•˜λ©΄ λ©λ‹ˆλ‹€.

from prompt_toolkit.keys import Keys
from prompt_toolkit.key_binding.bindings.completion import generate_completions

ip = get_ipython()
bind_key = ip.pt_cli.application.key_bindings_registry.add_binding
bind_key(Keys.ControlSpace)(generate_completions)

ν•˜μ§€λ§Œ ν•΄λ‹Ή μ½”λ“œλ₯Ό μ‹€ν–‰ν•˜κΈ° 전에 항상 PTK둜 터미널을 μ‹€ν–‰ν•˜κ³  μžˆλŠ”μ§€ 확인해야 ν•©λ‹ˆλ‹€. λ‹€μŒκ³Ό 같이 μž‘λ™ν•΄μ•Ό ν•©λ‹ˆλ‹€.

def register_bindings():

    from prompt_toolkit.keys import Keys
    from prompt_toolkit.key_binding.bindings.completion import generate_completions

    bind_key = ip.pt_cli.application.key_bindings_registry.add_binding
    bind_key(Keys.ControlSpace)(generate_completions)

ip = get_ipython()
if getattr(ip, "pt_cli"): register_bindings()
del register_bindings

μ°Έκ³ : 등둝 논리λ₯Ό if 블둝에 넣을 수 μžˆμ§€λ§Œ ν•¨μˆ˜λ₯Ό μ‚¬μš©ν•˜λ©΄ bind_key 와 같은 이름이 μ„Έμ…˜μ˜ λ„€μž„μŠ€νŽ˜μ΄μŠ€λ‘œ λˆ„μΆœλ˜λŠ” 것을 막을 수 μžˆμŠ΅λ‹ˆλ‹€. λ§Žμ€ 바인딩과 μ‚¬μš©μž μ •μ˜ ν•„ν„°κ°€ μ •μ˜λ˜λ©΄ μˆ˜λ™μœΌλ‘œ μ‚­μ œν•΄μ•Ό ν•˜λŠ” 이름이 μƒλ‹Ήνžˆ 많이 μƒμ„±λ©λ‹ˆλ‹€. ν•¨μˆ˜μ— λͺ¨λ‘ 넣은 λ‹€μŒ ν•¨μˆ˜ 이름을 μ‚­μ œν•˜λŠ” 것이 더 κΉ”λ”ν•©λ‹ˆλ‹€. μœ„μ˜ κ°„λ‹¨ν•œ κ²½μš°μ—λŠ” if 블둝이 더 λ‚˜μ„ κ²ƒμž…λ‹ˆλ‹€.

νš¨κ³Όκ°€ μžˆμ—ˆλ‹€! λ„ˆλ¬΄ 빨리 λŒμ•„μ™€ μ£Όμ…”μ„œ κ°μ‚¬ν•©λ‹ˆλ‹€!

μœ„μ˜ λ‚΄μš©μ„ μ‹€ν–‰ν•˜λ €κ³  ν•˜λ©΄ AttributeError: 'TerminalInteractiveShell' object has no attribute 'pt_cli' λ©λ‹ˆλ‹€. μ•Œλ €μ§„ λ¬Έμ œμž…λ‹ˆκΉŒ?

ν‚€λ³΄λ“œ λ‹¨μΆ•ν‚€μ˜ μ‚¬μš©μž κΈ°λ³Έ 섀정에 λ‹€μŒμ„ μž‘μ„±ν•˜μ‹­μ‹œμ˜€.

{
    "shortcuts":[
        {
            "command": "completer:invoke-file",
            "keys": [
                "Ctrl Space"
            ],
            "selector": ".jp-FileEditor .jp-mod-completer-enabled"
        },
        {
            "command": "completer:invoke-file",
            "keys": [
                "Ctrl Space"
            ],
            "selector": ".jp-FileEditor .jp-mod-completer-enabled"
        },
        {
            "command": "completer:invoke-notebook",
            "keys": [
                "Ctrl Space"
            ],
            "selector": ".jp-Notebook.jp-mod-editMode .jp-mod-completer-enabled"
        }

    ]
}
이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰