9

emacs 23.3でgudを介してpdbの使用を開始しましたが、バッファーからデバッガーに送信されるコマンドメッセージをフックするにはどうすればよいですか?comintのリングを永続化するために、gdbで使用するためのアドバイスを以下に書きましたが、pdbをフックするための同等の関数が見つかりません。メジャーモードとしてpython-mode.elを使用しています。

ありがとう。

(defadvice gdb-send-item (before gdb-save-history first nil activate)
  "write input ring on quit"
  (if (equal (type-of item) 'string) ; avoid problems with 'unprintable' structures sent to this function..
    (if (string-match "^q\\(u\\|ui\\|uit\\)?$" item)
      (progn (comint-write-input-ring)
             (message "history file '%s' written" comint-input-ring-file-name)))))
4

1 に答える 1

2

当時はもう少し掘り下げて自分の質問に答えることができたと思いますが、最初のgdbソリューションは、古い学習の最前線でそれを取り除いてくれました。回復したので..

ChbCsメジャー

少しスクロールした後、「comint-send-input」をキー「enter」にバインドされた関数として識別できます。この関数のソースを見ると、comint.el:1765は「run-hook-with-args」の呼び出しです。これは、特に「pdb」が必要なことを実行する場所がないことを認識している場所です。

gudは、外部デバッグプロセスを呼び出して結果を返すための汎用ラッパーです。したがって、コントロールはelispにはありません。これはgdbでも同じでしたが、外部呼び出しの周りに優れた(既存の)ラッパーがあり、その関数に「クリーン」な感じを与えるようにアドバイスしていました。

したがって、ハック..「comint-send-input」のすぐ上に「comint-add-to-input-history」があります。

;;save command history
(defadvice comint-add-to-input-history (before pdb-save-history activate compile)
  "write input ring on exit"
  (message "%s" cmd)
  (if (string-match "^e\\(x\\|xi\\|xit\\)?$" cmd)
  (progn (comint-write-input-ring)
     (message "history file '%s' written" comint-input-ring-file-name)))
)

fyi、デバッグセッションの入力リングを開始するためにこれらを持っています

;#debugger history
(defun debug-history-ring (file)
  (comint-read-input-ring t)
  (setq comint-input-ring-file-name file)
  (setq comint-input-ring-size 1000)
  (setq comint-input-ignoredups t))
(let ((hooks '((gdb-mode-hook . (lambda () (debug-history-ring "~/.gdbhist")))
       (pdb-mode-hook . (lambda () (debug-history-ring  "~/.pythonhist"))))))
  (dolist (hook hooks) (print (cdr hook)) (add-hook (car hook) (cdr hook))))

..そして、デバッグバッファが強制終了された場合に履歴ファイルに書き込む

  (add-hook 'kill-buffer-hook 'comint-write-input-ring)

乾杯。

于 2011-07-17T17:59:09.127 に答える