1

私はしばらくの間emacsを使用していますが、lispプログラミングにはあまり詳しくありません。私がemacsでPythonのコーディングを始めたのはほんの数日でした。python-modeは非常に便利であることがわかったので、さらに詳しく調べたいと思います。私はインターネット上でいくつかのemacslips関数を見つけ、インターフェースをユーザーフレンドリーにするためにそれらを少し弱めました。私は次の行動を達成しようとしています

私は通常、2つの垂直ウィンドウでemacsを開始します。1つはPythonソースで、もう1つはシェルです。キーボードバインディングを使用して次のことができるはずです

  • バッファを切り替える(動作中)
  • リージョンを実行します(動作中)が、ソースバッファーをシェルバッファーに置き換えます。元のシェルバッファで選択した領域を実行したい。
  • 行を実行します(動作中)が、上記と同じ問題です。私が言うとき、行はバッファを置き換えずにPythonシェルで実行する必要があります。したがって、行をコピーし、Pythonシェルに切り替え、行を実行し、Pythonソースバッファーに戻します。

上記の切り替え動作を実現できません。以下は私のinit.elファイルからの私のコードです

(defun goto-python-shell ()
  "Go to the python command window (start it if needed)"
  (interactive)
  (setq current-python-script-buffer (current-buffer))
  (if (boundp 'current-python-shell-buffer)
    (switch-to-buffer-other-window current-python-shell-buffer)
    (py-shell))
  (end-of-buffer)
 )

 (defun goto-python-source ()
   "switch back to source window"
   (interactive)
  (setq current-python-shell-buffer (current-buffer))
   (switch-to-buffer-other-window current-python-script-buffer)
 )

 (defun py-execute-statement-and-step ()
   "select a statement, submit as a region and then step forward"
   (interactive)
   (beginning-of-line 1)
   (let ((beg (point)))
     (py-next-statement 1)
     ; if last statement.
        (if (= (point) beg) (end-of-buffer ))
 ; (switch-to-buffer-other-window current-python-shell-buffer)
   (py-execute-region beg (point))
   (switch-to-buffer-other-window current-python-script-buffer)
   )
 )

 ; some key bindings
 (define-key python-mode-map (quote [f9]) 'py-execute-statement-and-step)
 ;(define-key python-mode-map (quote [f10]) `py-execute-region)
 ;py-shell-switch-buffers-on-execute
 (define-key python-mode-map (quote [f10]) `py-shell-switch-buffers-on-execute)
 (define-key python-mode-map (quote [f11]) `py-execute-buffer)
 (define-key python-mode-map (quote [f12]) `goto-python-shell)
 (define-key py-shell-map (quote [f12]) `goto-python-source)

ご意見をお聞かせください。

また、私はpython-modeを初めて使用するので、誰かが上記のようなpython-modeを使用するための優れた初期化を共有できますか?

あなたの助けに感謝します。

よろしく、AJ

4

3 に答える 3

3

この質問に対する最初の答えを見て、py-shell-switch-buffers-on-execute変数をカスタマイズする必要があります。

このように、あなたが望むように動作させるためにすべてのカスタム関数を必要としないpython-modeでしょう(すなわち、ソースバッファをアクティブに保つ)

于 2012-03-29T07:31:15.857 に答える
2

あなたはEmacs24で利用できるものを(少なくとも評価用のもので)再発明しようとしていると思います。Emacs 24を試してください。Pythonソースコードを編集しているときに、を押しC-c C-cてバッファを評価し、を押しC-c C-rて領域を評価できます。Pythonシェルを明示的に開始する必要はありません。

ラインとステップを評価するための直接的なサポートはないと思います。キーストロークで実現できますC-SPC C-n C-c C-r。あなたの焦点はソースコードに残り、ソースコードとシェルを明示的に切り替える必要はありません。

FWIW、私はEmacs 24を毎日妥当な時間使用しており、安定性の問題は発生していません。

于 2012-03-29T07:19:49.680 に答える
0

次の変更は魅力のように機能しています。f9は行ごとに実行し、f10は領域ベースの実行を行います。py-shell-switch-buffers-on-executeを無効にした後、curserはスクリプトウィンドウに残ります。

(defun py-execute-statement-and-step ()
  "select a statement, submit as a region and then step forward"
  (interactive)
  (beginning-of-line 1)
  (let ((beg (point)))
    (py-next-statement 1) 
    ; if last statement.
        (if (= (point) beg) (end-of-buffer ))
        (py-execute-region beg (point))
        (next-line)
  )
) 

(custom-set-variables
'(py-shell-switch-buffers-on-execute nil))

(define-key python-mode-map (quote [f9]) 'py-execute-statement-and-step)
(define-key python-mode-map (quote [f10]) `py-execute-region)
于 2012-03-30T01:34:48.963 に答える