Emacs - tab-completion of local Python variables

前端 未结 6 1712
失恋的感觉
失恋的感觉 2020-12-04 12:31

Is there a good emacs mode that will allow tab-completion of local python variables? I set up ipython.el but it will only tab-complete things in the scope of the interpreter

相关标签:
6条回答
  • 2020-12-04 13:11

    Use Jedi!

    It really understands Python better than any other autocompletion library:

    • builtins
    • multiple returns or yields
    • tuple assignments / array indexing / dictionary indexing
    • with-statement / exception handling
    • *args / **kwargs
    • decorators / lambdas / closures
    • generators / iterators
    • some descriptors: property / staticmethod / classmethod
    • some magic methods: __call__, __iter__, __next__, __get__, __getitem__, __init__
    • list.append(), set.add(), list.extend(), etc.
    • (nested) list comprehensions / ternary expressions
    • relative imports
    • getattr() / __getattr__ / __getattribute__
    • simple/usual sys.path modifications
    • isinstance checks for if/while/assert
    0 讨论(0)
  • 2020-12-04 13:14

    I think that you may be looking for something like this. It uses Pymacs and python-mode to do just what you are looking for.

    Let us know how it works out for you?

    0 讨论(0)
  • 2020-12-04 13:15

    I use emacs-autocomplete.el (version 0.2.0) together with yasnippet. Works ok for me, although it isn't a complete auto-completion environment like eclipse+java is. But enough for a common emacs hacker like me :)

    1) Download autocomplete from here (first link) and put it in your load-path directory. Also download the extensions you want to use (Attention: Ruby and etags extensions need additional stuff). Put them also in yout load-path dir.

    2) Download yasnippet and install it like the instruction on that page says (including the (require ...) part).

    3) Put these lines in your .emacs file and edit them for your needs (like all the extensions you want to use):

    (require 'auto-complete)
    (global-auto-complete-mode t)
    
    (when (require 'auto-complete nil t)
      (require 'auto-complete-yasnippet)
      (require 'auto-complete-python)
      (require 'auto-complete-css) 
      (require 'auto-complete-cpp)  
      (require 'auto-complete-emacs-lisp)  
      (require 'auto-complete-semantic)  
      (require 'auto-complete-gtags)
    
      (global-auto-complete-mode t)
      (setq ac-auto-start 3)
      (setq ac-dwim t)
      (set-default 'ac-sources '(ac-source-yasnippet ac-source-abbrev ac-source-words-in-buffer ac-source-files-in-current-dir ac-source-symbols))
    

    For more informations on options see the auto-complete.el file.

    4) Restart emacs or do a M-x load-file with your .emacs file. Write some code and press TAB for auto completion.

    0 讨论(0)
  • 2020-12-04 13:18

    If you just want to get it up and running with minimal fuss, try the emacs-for-python package.

    Happy coding!

    0 讨论(0)
  • 2020-12-04 13:20

    The blog post describing kind of tab completion you want can be found at Python code completion in Emacs. There is a bit of installing packages, pymacs, AutoComplete, rope, ropemacs, rope mode, yasnippet and setting up, but in the end I hope it will pay off.

    0 讨论(0)
  • 2020-12-04 13:21

    M-/ runs the command dabbrev-expand . This will complete local names in any mode. Also I bind meta f1 to hippie expand from all open buffers. This is very useful for me.

    ;; Bind hippie-expand
    (global-set-key [(meta f1)] (make-hippie-expand-function
                                   '(try-expand-dabbrev-visible
                                     try-expand-dabbrev
                                     try-expand-dabbrev-all-buffers) t))
    

    Hope this is useful.

    0 讨论(0)
提交回复
热议问题