6

私の目標は、Emacs 24 を Python エディターとして使用することです (Matlab および R エディターもありますが、それは私の質問の対象ではありません)。

(情報を省略したり、明確に述べていなかったりした場合はお知らせください。)

Python のタブ補完、正しい強調表示、およびスニペットを取得できるように、パッケージと init.el ファイルをセットアップすることができました。Python モードとして python-mode.el を使用しています。 問題はすべてこれを中心に展開しています。スクリプトをデバッグするときにタブ補完機能を使用するために、ipython を Python シェルとして使用したいと考えています。

  • ただし、(Mx ipython を使用して) ipython を起動すると、タブ補完がありません。さらに、「[1] in:」は表示されませんが、「[1] out:」は表示されます。
  • ipython を Emacs のデフォルト シェルにしたいと思います。ただし、この試みは失敗しました (たとえば、C:\PATH\TO\IPython.exe を py-python-command に設定します)。
  • Cc Cc を使用して Python スクリプトを実行しようとすると、通常の Python を使用して実行され、デバッガーに停止するように指示した位置で実際に停止します (ipdb.set_trace を使用します)。ただし、IPython を起動する別のタイプのコマンドを使用すると (リージョンをスクリプト全体に設定して py-execute-region-ipython を実行するなど)、IPython は機能しません。IPython シェルを開始するか、少なくとも開始するようですが、テキスト エディターのようにシェルを入力するだけです (fyi: ミニ バッファーでは、「Comint:run shell-compile」と表示されます)。

私の質問は次のとおりです: init.el ファイル内のパッケージ バージョンと Lisp コードのどの組み合わせを使用すると、Emacs のデフォルト シェルとしてタブ補完で ipython を使用できるようになりますか? 必要に応じて、一部のパッケージをダウングレードします。

追加情報:

Python-mode.el のプロジェクト ページで読んだことから、このパッケージの最新バージョンの IPython にはまだいくつかのバグがあることを理解しているため、おそらく古いバージョンを使用する必要があります。解決策を探すために何度もグーグルで検索してきましたが、自分に合った解決策を見つけることができませんでした。

私は走っています

私のinit.elは次のようになります(pythonのものは一番下にあります):

;; Requisites: Emacs >= 24
(require 'package)
(package-initialize)

(add-to-list 'package-archives
             '("melpa" . "http://melpa.milkbox.net/packages/"))
(add-to-list 'package-archives
             '("marmalade" . "http://marmalade-repo.org/packages/") t)

(package-refresh-contents)

(defun install-if-needed (package)
  (unless (package-installed-p package)
    (package-install package)))

;; make more packages available with the package installer -->
;; removed python mode since the version I got had errors
(setq to-install
      '(
;python-mode 
magit yasnippet jedi auto-complete autopair find-file-in-repository flycheck))

(mapc 'install-if-needed to-install)


;;------------R STUFF-----------

(add-to-list 'load-path "C:\\emacs-24.3\\site-lisp\\ess-13.09-1")
(setq ess-use-auto-complete t)
(load "ess-site")

;;------------MatLab STUFF-----------
; add folder of matlab-mode.el
(add-to-list 'load-path "C:\\Users\\Rob Ter Horst\\AppData\\Roaming\\.emacs.d\\elpa\\matlab-mode-20130829.142")
(load-library "matlab-load")

(matlab-cedet-setup)


(setq matlab-show-mlint-warnings t)
(add-hook 'matlab-mode-hook 'auto-complete-mode)
(add-hook 'matlab-mode-hook 'mlint-minor-mode)
;;------------GENERAL STUFF-----------

; Ido mode: Ido-powered versions of code. Most ido commands are named ido-xxxxx
; so find-file becomes ido-find-file, and so on.
(setq ido-enable-flex-matching t)
(setq ido-everywhere t)
(ido-mode t)
(global-linum-mode t)
;Use y or n always instead of yes/no
(defalias 'yes-or-no-p 'y-or-n-p)

;; -------------------- extra nice things Andrea Crotti--------------------
;; use shift to move around windows
(windmove-default-keybindings 'shift)
(show-paren-mode t)
 ; Turn beep off
(setq visible-bell nil)
(custom-set-variables
 '(ansi-color-names-vector ["#242424" "#e5786d" "#95e454" "#cae682" "#8ac6f2" "#333366" "#ccaa8f" "#f6f3e8"])
 '(custom-enabled-themes (quote (wheatgrass))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )
(put 'downcase-region 'disabled nil)

;;------------PYTHON STUFF-----------
;(require 'magit)
;(global-set-key "\C-xg" 'magit-status)

(require 'auto-complete)
(require 'autopair)
(require 'yasnippet)
(require 'jedi)

;yasnipped settings
(setq yas-snippet-dirs
      '("C:\\Users\\Rob Ter Horst\\AppData\\Roaming\\.emacs.d\\elpa\\yasnippet-20140106.1009\\snippets"))
(add-to-list 'load-path "C:\\Users\\Rob Ter Horst\\AppData\\Roaming\\.emacs.d\\elpa\\yasnippet-20140106.1009")

(global-set-key [f7] 'find-file-in-repository)

; auto-complete mode extra settings
(setq
 ac-auto-start 2
 ac-override-local-map nil
 ac-use-menu-map t
 ac-candidate-limit 20)

;; ;; Python mode settings
(setq py-install-directory "C:\\Users\\Rob Ter Horst\\AppData\\Roaming\\.emacs.d\\self_installed\\python-mode.el-6.1.3")
(add-to-list 'load-path py-install-directory)
(add-to-list 'auto-mode-alist '("\\.py$" . python-mode))
(when (featurep 'python) (unload-feature 'python t))
(require 'python-mode)

(setq py-electric-colon-active t)
(add-hook 'python-mode-hook 'autopair-mode)
(add-hook 'python-mode-hook 'yas-minor-mode)
(add-hook 'python-mode-hook 'auto-complete-mode)

;; ;; Jedi settings

;; It's also required to run "pip install --user jedi" and "pip
;; install --user epc" to get the Python side of the library work
;; correctly.
;; With the same interpreter you're using.

;; if you need to change your python intepreter, if you want to change it
;; (setq jedi:server-command
;;       '("python2" "/home/andrea/.emacs.d/elpa/jedi-0.1.2/jediepcserver.py"))

(add-hook 'python-mode-hook
          (lambda ()
            (jedi:setup)
            (jedi:ac-setup)
            (local-set-key "\C-cd" 'jedi:show-doc)
            (local-set-key (kbd "M-SPC") 'jedi:complete)
            (local-set-key (kbd "M-.") 'jedi:goto-definition)))

; ipython settings

(setq py-python-command "C:\\Python27\\Scripts\\ipython.exe")
(setq py-complete-function 'ipython-complete 
        py-shell-complete-function 'ipython-complete 
        py-shell-name "ipython" 
        py-which-bufname "IPython") 
;(require 'ipython)

;With tab autocompletion in ipdb I get an error that might be solved by changing this var
;the error: "variable binding depth exceeds max-specpdl-size"
(setq max-specpdl-size 32000)

; Try to add flycheck --> flycheck causes emacs to become incredibly slow on big script with
; many style errors (as present in a lot of my older scripts, so I do not want to activate it 
; by default
;(setq flycheck-highlighting-mode 'lines)
;(add-hook 'python-mode-hook 'global-flycheck-mode)
;(flycheck-select-checker 'python-flake8)
;(provide 'init-flycheck)

(yas-reload-all)

4

3 に答える 3

1

python-mode.el が提供する IPython-shell では、 をTAB呼び出しますpy-indent-line。そうすれば、可能なインデントを循環させることがスクリプト バッファのように機能します。で完了ですM-TAB。そのキーを再定義できます。

于 2014-02-19T15:31:06.710 に答える