LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 902|回复: 5

我想在emacs中gdb模式下键绑定,出错请教

[复制链接]
发表于 2006-2-20 23:03:57 | 显示全部楼层 |阅读模式
在emacs中,gdb mode下键绑定前缀为C-x C-a 然后加键名,敲击起来很烦,我想重新绑定,于是重新写了:
(define-key gdb-mode-map [f7] 'compile)
(define-key gdb-mode-map [f5] 'gud-cont)
(define-key gdb-mode-map [f9] 'gud-break)
(define-key gdb-mode-map [C-f9] 'gud-remove)
(define-key gdb-mode-map [S-f9] 'gud-print)
(define-key gdb-mode-map [f10] 'gud-next)
但运行出来:
Symbol's value as varible is valid:gdb-mode-map
请教该如何改,谢谢
发表于 2006-2-21 10:23:33 | 显示全部楼层
Post by bcjr
在emacs中,gdb mode下键绑定前缀为C-x C-a 然后加键名,敲击起来很烦,我想重新绑定,于是重新写了:
(define-key gdb-mode-map [f7] 'compile)
(define-key gdb-mode-map [f5] 'gud-cont)
(define-key gdb-mode-map [f9] 'gud-break)
(define-key gdb-mode-map [C-f9] 'gud-remove)
(define-key gdb-mode-map [S-f9] 'gud-print)
(define-key gdb-mode-map [f10] 'gud-next)
但运行出来:
Symbol's value as varible is valid:gdb-mode-map
请教该如何改,谢谢
用这个:
  1. (local-set-key (kbd "<f7>") 'some-command)
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-2-21 18:48:06 | 显示全部楼层
herberteuler兄,你能贴一下你的c编程环境的.emacs文件吗?想参考参考
回复 支持 反对

使用道具 举报

发表于 2006-2-22 10:21:24 | 显示全部楼层
Post by bcjr
herberteuler兄,你能贴一下你的c编程环境的.emacs文件吗?想参考参考


下面是我的 .emacs 的全部内容(2006 年 1 月 17 日),其中用到了 Alex Schroeder 和 Jonadab the Unsightly One 的 color-theme.el 中的函数。

  1. ;;; default settings

  2. (global-set-key (kbd "M-/") 'hippie-expand)
  3. (global-font-lock-mode t)
  4. (column-number-mode t)
  5. (require 'generic-x)
  6. (auto-compression-mode t)
  7. (add-to-list 'load-path "~/.emacs.d")
  8. (put 'narrow-to-region 'disabled nil)
  9. (require 'color-theme)
  10. ;;(require 'python-mode)
  11. (require 'printing)
  12. (pr-update-menus)

  13. ;;; custom settings, but only involved system commands

  14. (cond

  15. ((or (eq system-type 'gnu/linux) (eq system-type 'berkeley-unix))
  16.   (term "bash")
  17.   (switch-to-buffer "*scratch*")))

  18. (defun my-c-mode-common-hook ()
  19.   (c-toggle-hungry-state t)
  20.   ;;(hs-minor-mode t)
  21.   (xgp-c-define-local-variables)
  22.   (xgp-c-load-header-files-in-current-buffer)
  23.   (local-set-key (kbd "M-<DEL>") 'backward-kill-sexp)
  24.   (local-set-key (kbd "M-d") 'kill-sexp)
  25.   (local-set-key (kbd "M-n") 'c-end-of-statement)
  26.   (local-set-key (kbd "M-p") 'c-beginning-of-statement)
  27.   (local-set-key (kbd "C-a") 'beginning-of-line)
  28.   (local-set-key (kbd "C-e") 'end-of-line)
  29.   (local-set-key (kbd "M-a") 'backward-sentence)
  30.   (local-set-key (kbd "M-e") 'forward-sentence)
  31.   (local-set-key (kbd "M-k") 'kill-sentence)
  32.   (local-set-key (kbd "C-k") 'kill-line)
  33.   (local-set-key (kbd "C-M-a") 'beginning-of-defun)
  34.   (local-set-key (kbd "C-M-e") 'end-of-defun)
  35.   (local-set-key (kbd "M-<") 'beginning-of-buffer)
  36.   (local-set-key (kbd "M->") 'end-of-buffer)
  37.   (local-set-key (kbd "<f9>") 'xgp-cfsi))

  38. (add-hook 'c-mode-common-hook
  39.           '(lambda ()
  40.              (my-c-mode-common-hook)))

  41. (or window-system (progn (menu-bar-mode 0)
  42.                          (mouse-wheel-mode 0)))

  43. (setq c-default-style "bsd"
  44.       frame-title-format "%b [%m] - GNU Emacs")

  45. (cond

  46. ((eq window-system 'w32)
  47.   (setq printer-name "\\\\bdc\\hp1320n"
  48.         initial-frame-alist '((width . 89) (height . 32)))
  49.   (set-default-font "-outline-lucida sans typewriter-normal-r-normal-normal-19-142-96-96-c-*-fontset-auto2")
  50.   (add-to-list 'default-frame-alist '(font . "-outline-lucida sans typewriter-normal-r-normal-normal-19-142-96-96-c-*-fontset-auto2")))

  51. ((eq window-system 'x)
  52.   (setq xgp-x-fontset
  53.         (create-fontset-from-fontset-spec
  54.          "-adobe-courier-medium-r-normal--17-120-100-100-m-0-fontset-17,iso8859-1:adobe-courier-medium-r-normal--17-120-100-100-m-110-iso8859-1,chinese-gb2312:-misc-simsun-medium-r-normal--14-105-96-96-c-0-gb2312.1980-0"))
  55.   ;; 14-105-96-96
  56.   ;; 16-120-96-96
  57.   ;; 12-90-96-96
  58.   (set-default-font xgp-x-fontset)
  59.   (add-to-list 'default-frame-alist '(font . "fontset-17"))))

  60. (cond

  61. ((<= emacs-major-version 22)
  62.   (prefer-coding-system 'gb2312)
  63.   (set-terminal-coding-system 'gb2312)
  64.   (set-keyboard-coding-system 'gb2312))

  65. ((>= emacs-major-version 23)
  66.   (prefer-coding-system 'gbk)
  67.   (set-terminal-coding-system 'gbk)
  68.   (set-keyboard-coding-system 'gbk)))

  69. ;;; custom commands created by myself

  70. (defgroup xgp-c-header-files nil
  71.   "Group for reading C/C++ header files."
  72.   :group 'c)

  73. (defcustom xgp-c-system-include-paths
  74.   '("/usr/include"
  75.     "/usr/local/include")
  76.   "List of directories where C/C++ header files are found."
  77.   :type '(repeat string)
  78.   :group 'xgp-c-header-files)

  79. (defun xgp-c-define-local-variables ()
  80.   "Make variable XGP-C-USER-INCLUDE-PATHS directory of file in the current buffer."
  81.   (make-local-variable 'xgp-c-user-include-paths)
  82.   (setq xgp-c-user-include-paths (list (file-name-directory (buffer-file-name)))))

  83. (defun xgp-c-load-header-files-in-current-buffer ()
  84.   "Try load C/C++ header files included by file in the current buffer.

  85. First search in the directory relative to the directory of the file
  86. in the current buffer, then user defined directories, then system
  87. wide directory."
  88.   (interactive)
  89.   (save-excursion
  90.     (goto-char (point-min))
  91.     (let (b e f af)
  92.       (while (and (setq b (re-search-forward "#include[ \t]+" nil t))
  93.                   (setq e (re-search-forward "\n" nil t)))
  94.         (setq f (buffer-substring-no-properties (1+ b) (- e 2)))
  95.         (if (eq (char-before (1- e)) ?>)
  96.             (dotimes (n (length xgp-c-system-include-paths))
  97.               (setq af (concat (nth n xgp-c-system-include-paths) "/" f))
  98.               (if (file-exists-p af)
  99.                   (find-file-noselect af t)))
  100.           (dotimes (n (length xgp-c-user-include-paths))
  101.             (setq af (concat (nth n xgp-c-user-include-paths) "/" f))
  102.             (if (file-exists-p af)
  103.                 (find-file-noselect af t))))))))

  104. (defun xgp-execute-program-region (start end program)
  105.   "Execute external program on region in the current buffer.
  106. START and END specifies the region, PROGRAM specifies which
  107. program to be called."
  108.   (interactive "r\nsProgram: ")
  109.   (let ((delete (y-or-n-p "Substitute orignal content: "))
  110.         args
  111.         s)
  112.     (setq s (read-string "Argument (type RET directly to finish): "))
  113.     (while (not (equal s ""))
  114.       (progn (setq args (append args (list s))
  115.                    s (read-string "Argument (type RET directly to finish): ")))
  116.       (apply 'call-process-region start end program delete t nil args))))

  117. (global-set-key (kbd "<f7>") 'xgp-execute-program-region)

  118. ;; C/C++ F? Style Inputing
  119. (defun xgp-cfsi (style)
  120.   "Deciding whether using CFSI."
  121.   (interactive "sStyle: ")

  122.   (if (equal style "bsd")

  123.       (progn  (c-toggle-auto-newline -1)
  124.               (c-set-style "bsd")
  125.               (setq indent-tabs-mode t)
  126.               (local-set-key " " 'self-insert-command))

  127.     (progn (c-toggle-auto-newline 1)
  128.            (c-set-style style)
  129.            (setq indent-tabs-mode nil
  130.                  c-hanging-braces-alist (quote ((defun-open) (defun-close) (brace-list-open before) (brace-entry-open) (statement-cont) (substatement-open before) (block-close) (extern-lang-open) (namespace-open before) (module-open) (composition-open) (inexpr-class-open) (inexpr-class-close before) (class-open before) (class-close)))
  131.                  c-hanging-semi&comma-criteria nil
  132.                  c-hanging-colons-alist nil)
  133.            (local-set-key " " 'xgp-cfsi-SPC))))

  134. (defun xgp-cfsi-SPC ()
  135.   (interactive)
  136.   (if (looking-back "^[ \t]*}[ \t]*$")
  137.       (progn
  138.         (insert "\n")
  139.         (c-indent-command))
  140.     (insert " ")))

  141. ;;; custom commands created by others

  142. ;;; modified color-theme-high-contrast
  143. (defun color-theme-high-contrast-tty ()
  144.   "High contrast color theme, maybe for the visually impaired.
  145. Watch out!  This will set a very large font-size!

  146. If you want to modify the font as well, you should customize variable
  147. `color-theme-legal-frame-parameters' to "\\(color\\|mode\\|font\\|height\\|width\\)$".
  148. The default setting will prevent color themes from installing specific
  149. fonts."
  150.   (interactive)
  151.   (color-theme-standard)
  152.   (let ((color-theme-is-cumulative t))
  153.     (color-theme-install
  154.      '(color-theme-high-contrast
  155.        ((cursor-color . "red")
  156.         (width . 60)
  157.         (height . 25)
  158.         (background . dark))
  159.        (default ((t (:stipple nil :background "black" :foreground "white" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight bold :height 240 :width normal :family "adobe-courier"))))

  160.        (bold ((t (:bold t :underline t))))
  161.        (bold-italic ((t (:bold t :underline t))))
  162.        (font-lock-builtin-face ((t (:bold t :foreground "Red"))))
  163.        (font-lock-comment-face ((t (:bold t :foreground "Firebrick"))))
  164.        (font-lock-constant-face ((t (:bold t :underline t :foreground "Blue"))))
  165.        (font-lock-function-name-face ((t (:bold t :foreground "Blue"))))
  166.        (font-lock-keyword-face ((t (:bold t :foreground "Purple"))))
  167.        (font-lock-string-face ((t (:bold t :foreground "DarkGreen"))))
  168.        (font-lock-type-face ((t (:bold t :foreground "ForestGreen"))))
  169.        (font-lock-variable-name-face ((t (:bold t :foreground "DarkGoldenrod"))))
  170.        (font-lock-warning-face ((t (:bold t :foreground "Red"))))
  171.        (highlight ((t (:background "black" :foreground "white" :bold 1))))
  172.        (info-menu-5 ((t (:underline t :bold t))))
  173.        (info-node ((t (:bold t))))
  174.        (info-xref ((t (:bold t ))))
  175.        (italic ((t (:bold t :underline t))))
  176.        (modeline ((t (:background "black" :foreground "white" :bold 1))))
  177.        (modeline-buffer-id ((t (:background "black" :foreground "white" :bold 1))))
  178.        (modeline-mousable ((t (:background "black" :foreground "white" :bold 1))))
  179.        (modeline-mousable-minor-mode ((t (:background "black" :foreground "white" :bold 1))))
  180.        (region ((t (:background "black" :foreground "white" :bold 1))))
  181.        (secondary-selection ((t (:background "black" :foreground "white" :bold 1))))
  182.        (underline ((t (:bold t :underline t))))))))

  183. (defun color-theme-sitaramv-nt-modified ()
  184.   "Black foreground on white background.
  185. Includes faces for font-lock, widget, custom, speedbar."
  186.   (interactive)
  187.   (color-theme-install
  188.    '(color-theme-sitaramv-nt
  189.      ((foreground-color . "black")
  190.       (background-color . "white")
  191.       (mouse-color . "sienna3")
  192.       (cursor-color . "HotPink")
  193.       (border-color . "Blue")
  194.       (background-mode . light))
  195.      (default ((t (nil))))
  196.      (modeline ((t (:foreground "black" :background "gold2"))))
  197.      (modeline-buffer-id ((t (:foreground "black" :background "gold2"))))
  198.      (modeline-mousable ((t (:foreground "black" :background "gold2"))))
  199.      (modeline-mousable-minor-mode ((t (:foreground "black" :background "gold2"))))
  200.      (highlight ((t (:foreground "black" :background "darkseagreen2"))))
  201.      (bold ((t (:bold t))))
  202.      (italic ((t (:italic t))))
  203.      (bold-italic ((t (:bold t :italic t))))
  204.      (region ((t (:foreground "black" :background "snow3"))))
  205.      (secondary-selection ((t (:background "paleturquoise"))))
  206.      (underline ((t (:underline t))))
  207.      (lazy-highlight-face ((t (:foreground "dark magenta" :bold t))))
  208.      (font-lock-comment-face ((t (:foreground "ForestGreen" :italic t))))
  209.      (font-lock-string-face ((t (:foreground "red"))))
  210.      (font-lock-keyword-face ((t (:foreground "blue" :bold t))))
  211.      (font-lock-builtin-face ((t (:foreground "blue"))))
  212.      (font-lock-function-name-face ((t (:foreground "magenta" :bold t))))
  213.      (font-lock-variable-name-face ((t (:foreground "black"))))
  214.      (font-lock-type-face ((t (:foreground "ForestGreen" :bold t))))
  215.      (font-lock-constant-face ((t (:foreground "blue" :underline t))))
  216.      (font-lock-warning-face ((t (:foreground "Red" :bold t))))
  217.      (widget-documentation-face ((t (:foreground "dark green"))))
  218.      (widget-button-face ((t (:bold t))))
  219.      (widget-field-face ((t (:background "gray85"))))
  220.      (widget-single-line-field-face ((t (:background "gray85"))))
  221.      (widget-inactive-face ((t (:foreground "dim gray"))))
  222.      (widget-button-pressed-face ((t (:foreground "red"))))
  223.      (custom-invalid-face ((t (:foreground "yellow" :background "red"))))
  224.      (custom-rogue-face ((t (:foreground "pink" :background "black"))))
  225.      (custom-modified-face ((t (:foreground "white" :background "blue"))))
  226.      (custom-set-face ((t (:foreground "blue" :background "white"))))
  227.      (custom-changed-face ((t (:foreground "white" :background "blue"))))
  228.      (custom-saved-face ((t (:underline t))))
  229.      (custom-button-face ((t (nil))))
  230.      (custom-documentation-face ((t (nil))))
  231.      (custom-state-face ((t (:foreground "dark green"))))
  232.      (custom-variable-tag-face ((t (:foreground "blue" :underline t))))
  233.      (custom-variable-button-face ((t (:bold t :underline t))))
  234.      (custom-face-tag-face ((t (:underline t))))
  235.      (custom-group-tag-face-1 ((t (:foreground "red" :underline t))))
  236.      (custom-group-tag-face ((t (:foreground "blue" :underline t))))
  237.      (speedbar-button-face ((t (:foreground "green4"))))
  238.      (speedbar-file-face ((t (:foreground "cyan4"))))
  239.      (speedbar-directory-face ((t (:foreground "blue4"))))
  240.      (speedbar-tag-face ((t (:foreground "brown"))))
  241.      (speedbar-selected-face ((t (:foreground "red" :underline t))))
  242.      (speedbar-highlight-face ((t (:background "green"))))
  243.      (ff-paths-non-existant-file-face ((t (:foreground "NavyBlue" :bold t))))
  244.      (show-paren-match-face ((t (:background "light blue"))))
  245.      (show-paren-mismatch-face ((t (:foreground "white" :background "purple")))))))

  246. (if window-system
  247.     (color-theme-sitaramv-nt-modified)
  248.   (color-theme-high-contrast-tty))

  249. ;;; finally, customization by Emacs

  250. (custom-set-variables
  251. ;; custom-set-variables was added by Custom.
  252. ;; If you edit it by hand, you could mess it up, so be careful.
  253. ;; Your init file should contain only one such instance.
  254. ;; If there is more than one, they won't work right.
  255. '(c-offsets-alist (quote ((block-open . 0) (block-close . 0) (statement-block-intro . +) (substatement . +) (substatement-open . 0) (substatement-label . 0) (case-label . 0) (do-while-closure . 0) (else-clause . 0) (catch-clause . 0) (case-label . 0) (access-label . -) (namespace-open . 0) (class-open . 0) (class-close . 0))))
  256. '(dired-recursive-copies (quote always))
  257. '(dired-recursive-deletes (quote top))
  258. '(ps-font-size (quote (8.5 . 10)))
  259. '(tab-width 8)
  260. '(undo-limit 200000))
  261. (custom-set-faces
  262. ;; custom-set-faces was added by Custom.
  263. ;; If you edit it by hand, you could mess it up, so be careful.
  264. ;; Your init file should contain only one such instance.
  265. ;; If there is more than one, they won't work right.
  266. )

复制代码


我是一个传统的 UNIX C 程序员,所以大多数内容都和 C 编程有关。无论何时,请注意每个人的背景和所处的环境不同,因此他的需要也不一样。所以,请针对自己的需要对配置作出修改。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-2-26 08:15:11 | 显示全部楼层
谢谢,herberteuler
在你的.emacs中我没看到调试的相关快捷设定,那你的程序是使用什么调试的呢?我最近尝试着用emacs编辑,调试程序,感觉比window下的IDE复杂多了,还请兄多指点。
回复 支持 反对

使用道具 举报

发表于 2006-2-26 11:59:10 | 显示全部楼层
一般我都是在 *gud* 的窗口里使用 gdb 的。在更多的情况下,正如 Kernighan 和 Pike 在 The Practice of Programming 中所说,使用打印中间变量的方式都更好一些。

我曾经试着将 Emacs 中调试的快捷键定义得与 VC 一样,但发现那样做并没有使我的效率有多少长进,于是就将这些键绑定删掉了。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表