一次emacs调试经历

上午都在看emacs中关于版本控制的文档。下午写程序的时候,又遇到了别的问题。

还是在前两天从网上找到自定义emacs的编译命令的方法,代码如下:

1. (defun sucha-smart-compile ()

2.   "Simply compile your file according to the file type."

3.   (interactive)

4.   (save-some-buffers t)

5.   (let

6.       ((compile-command nil)

7.        (alist

8.         (list '("//.c$" .  "c:/mingw/bin/gcc")

9.               '("//.cc$" . "c:/mingw/bin/g++")

10.                '("//.cpp$" . "c:/mingw/bin/g++"))))

11.      (while (not (null alist))

12.        (if (string-match (caar alist) (buffer-file-name))

13.            (setq compile-command

14.                  (concat (cdar alist) " " "/"" (buffer-file-name) "/"")))

15.          (setq alist (cdr alist)))

16.   

17.      (if (null compile-command)

18.           (setq compile-command

19.                 (read-from-minibuffer "Compile command: ")))

20.      (compile compile-command)))

21.  (global-set-key [C-f5] 'compile)

22.  (global-set-key [f5] 'sucha-smart-compile)

其中,c:/mingw/bin是我的电脑上的编译器所在目录,这样写完程序一按f5键就会自动编译连接,但令人不爽的是它总是生成一个默认的a.exe,而不是我所希望的名字。生成一个a.exe的话,再使用gdb调试这个a.exe,就会得到一个:error process filter,:wrong argument type:stringp nil的错误信息。郁闷至极。当时猜想可以是gdbemacs下有特殊的规定,而且猜想可能就是因为可执行文件与源代码文件的文件名不一样。于是今天把上述代码修改成下面的样子:

(defun sucha-smart-compile ()

  "Simply compile your file according to the file type."

  (interactive)

  (save-some-buffers t)

  (let

      ((compile-command nil)

       (alist

        (list '("//.c$" .  "c:/mingw/bin/gcc -g ")

              '("//.cc$" . "c:/mingw/bin/g++ -g ")

              '("//.cpp$" . "c:/mingw/bin/g++ -g "))))

    (while (not (null alist))

      (if (string-match (caar alist) (buffer-file-name))

          (setq compile-command

                (concat (cdar alist) (file-name-nondirectory buffer-file-name)

                     " -o  "

                     (file-name-sans-extension (file-name-nondirectory buffer-file-name)) ".exe")))

        (setq alist (cdr alist)))

 

    (if (null compile-command)

         (setq compile-command

               (read-from-minibuffer "Compile command: ")))

    (compile compile-command)))

(global-set-key [C-f5] 'compile)

(global-set-key [f5] 'sucha-smart-compile)

主要是修改了上面高亮显示的那部分代码,其中file-name-nondirectory函数用来取得路径名抛掉目录后的纯文件名,file-name-sans-extension用来取得文件名去掉扩展名后的名字。这样终于达成所愿。

但是,使用gdb调试仍然是那个错误信息,google了一下,没有任何关于这个错误信息的消息。

突然间注意到,使用自动编译时和手动输入编译命令进行编译时-o参数后面的生成文件的名字在emacs下的显示是不一样的。自动编译时没有什么特别,而手动输入时生成文件的名字是被高亮显示的,很有可能就是使用自动编译命令生成的可执行文件在emacs中调试时不被看做具有可执行文件属性,因此导致了错误。如果真是这样的话,应该有两个方法可以改正,一个是使用emacs中的命令在编译后将生成的文件加上可执行文件属性,另一个是看看gdb是否提供了相应的选项在调试前不检查文件的属性。

另外,自己曾经费了好大功夫去猜一个可能的功能的命令,然后去emacs中使用C-h f或者C-h v去验证并从中得到一些emacs命名的规则的一点规律。但其实这些都在elisp的文档中,讲解的相当明白。

emacs中,函数以-p结尾的通常是一个返回bool值的函数。这是一点猜测。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值