组织模式不能编辑C源代码 [英] org-mode can't edit C source code

查看:129
本文介绍了组织模式不能编辑C源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用emacs的组织模式来编辑C程序时,就是在编辑下面的段时:

When I use emacs's org-mode to edit a C program, that is when I edit the below segment:

#+begin_src c
#define MAX 100
#+end_src

调用函数org-edit-src-code来编辑新缓冲区中的C代码,出现错误:

and after I call the function 'org-edit-src-code' to edit the C code in a new buffer, there is an error:


语言模式`c-mode'失败:stringp

Language mode `c-mode' fails with: stringp

我编辑代码后既不能保存也不返回到原始缓冲区在新的缓冲区。

and I can neither save to nor return to the original buffer after I edit the code in the new buffer.

每个其他语言都可以正常工作,包括C ++,elisp,sh。

Every other languages can work without any problem, including C++, elisp, sh.

这个问题?我的组织模式版本是7.6,emacs版本是23.2。

How can I fix this problem? My org-mode version is 7.6 and emacs version is 23.2.

完整的调试信息是(按照Noufal Ibrahim的方法):

the full debug info is (follow Noufal Ibrahim's method):

Debugger entered--Lisp error: (error "Language mode `c-mode' fails with: stringp")
  signal(error ("Language mode `c-mode' fails with: stringp"))
  error("Language mode `%s' fails with: %S" c-mode stringp)
  (condition-case e (funcall lang-f) (error (error "Language mode `%s' fails with: %S" lang-f ...)))
  (let ((org-inhibit-startup t)) (condition-case e (funcall lang-f) (error ...)))
  (if (and (setq buffer ...) (if org-src-ask-before-returning-to-edit-buffer ... t)) (org-src-switch-to-buffer buffer (quote return)) (when buffer (with-current-buffer buffer ...) (kill-buffer buffer)) (setq buffer (generate-new-buffer ...)) (setq ovl (make-overlay beg end)) (overlay-put ovl (quote edit-buffer) buffer) (overlay-put ovl (quote help-echo) "Click with mouse-1 to switch to buffer editing this segment") (overlay-put ovl (quote face) (quote secondary-selection)) (overlay-put ovl (quote keymap) (let ... ... map)) (overlay-put ovl :read-only "Leave me alone") (setq transmitted-variables (append transmitted-variables ...)) (org-src-switch-to-buffer buffer (quote edit)) (if (eq single ...) (setq code ...)) (insert code) (remove-text-properties (point-min) (point-max) (quote ...)) (unless (cadr ...) (setq total-nindent ...)) (let (...) (condition-case e ... ...)) (dolist (pair transmitted-variables) (org-set-local ... ...)) (when org-mode-p (goto-char ...) (while ... ... ...)) (when markline (org-goto-line ...) (org-move-to-column ...) (push-mark ... ... t) (setq deactivate-mark nil)) (org-goto-line (1+ ...)) (org-move-to-column (if org-src-preserve-indentation col ...)) (org-src-mode) (set-buffer-modified-p nil) (and org-edit-src-persistent-message (org-set-local ... msg)) (let (...) (when ... ...)))
  (if (not info) nil (setq beg (move-marker beg ...) end (move-marker end ...) msg (if allow-write-back-p ... "Exit with C-c ' (C-c and single quote)") code (or code ...) lang (or ... ...) lang (if ... ... lang) single (nth 3 info) block-nindent (nth 5 info) lang-f (intern ...) begline (save-excursion ... ...) transmitted-variables (\` ...)) (if (and mark ... ...) (save-excursion ... ...)) (if (equal lang-f ...) (setq lang-f ...)) (unless (functionp lang-f) (error "No such language mode: %s" lang-f)) (save-excursion (if ... ...) (setq line ... col ...)) (if (and ... ...) (org-src-switch-to-buffer buffer ...) (when buffer ... ...) (setq buffer ...) (setq ovl ...) (overlay-put ovl ... buffer) (overlay-put ovl ... "Click with mouse-1 to switch to buffer editing this segment") (overlay-put ovl ... ...) (overlay-put ovl ... ...) (overlay-put ovl :read-only "Leave me alone") (setq transmitted-variables ...) (org-src-switch-to-buffer buffer ...) (if ... ...) (insert code) (remove-text-properties ... ... ...) (unless ... ...) (let ... ...) (dolist ... ...) (when org-mode-p ... ...) (when markline ... ... ... ...) (org-goto-line ...) (org-move-to-column ...) (org-src-mode) (set-buffer-modified-p nil) (and org-edit-src-persistent-message ...) (let ... ...)) t)
  (let ((mark ...) (case-fold-search t) (info ...) (full-info ...) (org-mode-p ...) (beg ...) (end ...) (allow-write-back-p ...) block-nindent total-nindent ovl lang lang-f single lfmt buffer msg begline markline markcol line col transmitted-variables) (if (not info) nil (setq beg ... end ... msg ... code ... lang ... lang ... single ... block-nindent ... lang-f ... begline ... transmitted-variables ...) (if ... ...) (if ... ...) (unless ... ...) (save-excursion ... ...) (if ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...) t))
  org-edit-src-code()
  (cond ((save-excursion ... ...) (find-file ...)) ((org-edit-src-code)) ((org-edit-fixed-width-region)) ((org-at-table\.el-p) (org-edit-src-code)) ((or ... ...) (call-interactively ...)) (t (call-interactively ...)))
  org-edit-special()
  call-interactively(org-edit-special nil nil)

我是一个新手,我不知道是什么问题。任何建议?

I am a novice and I don't know what the problem is. Any advice?

推荐答案

在评论中发现,这是由访问 buffer-file-name 在没有文件支持的临时缓冲区中,因此 buffer-file-name 没有引起它的失败 stringp 。无论如何,一种解决方法是将 buffer-file-name

As discovered in the comments this is caused by accessing buffer-file-name in a temporary buffer which is not backed by a file and hence buffer-file-name is nil giving rise the it's failing stringp. Anyway, one way to fix it is by replacing instances of buffer-file-name with

(or buffer-file-name "DEFAULT-NAME")

如果您需要使用它,或者像下面这样一个块。

if you need to use it, or by a block like the following

(when buffer-file-name
  (code-going-here-will-only-be-executed-if-buffer-file-name-in-non-nil))

哪个更容易/更好,当然取决于你在做什么。

Which is easier/better will of course depend upon what you are doing.

这篇关于组织模式不能编辑C源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆