elb*_*rez 8 python emacs elisp gud pdb
我已经开始在emacs 23.3中通过gud使用pdb,如何从缓冲区挂钩发送到调试器的命令消息?我写了下面的建议与gdb一起使用,以便持久化comint的响铃,但找不到与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)))))
Run Code Online (Sandbox Code Playgroud)
我想我可能可以通过更多的挖掘来回答我当时的问题,但是第一个 gdb 解决方案却让我在旧的学习方面失去了它。我康复了,所以..
Ch b Cs专业
经过一番滚动后,我们可以将“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)))
)
Run Code Online (Sandbox Code Playgroud)
仅供参考,我有这些来启动调试会话的输入环
;#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))))
Run Code Online (Sandbox Code Playgroud)
..如果调试缓冲区被杀死,则写入历史文件
(add-hook 'kill-buffer-hook 'comint-write-input-ring)
Run Code Online (Sandbox Code Playgroud)
干杯。