org-mode无法编辑C源代码

时间:2011-11-30 12:11:26

标签: emacs org-mode

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

#+begin_src c
#define MAX 100
#+end_src

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

  

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

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

其他所有语言都可以正常运行,包括C ++,elisp,sh。

如何解决此问题?我的组织模式版本是7.6,emacs版本是23.2。

完整的调试信息是(遵循Noufal Ibrahim的方法):

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)

我是新手,我不知道问题是什么。有什么建议吗?

1 个答案:

答案 0 :(得分:2)

正如在评论中发现的那样,这是由于临时缓冲区中的buffer-file-name访问而没有文件支持,因此buffer-file-name为nil会导致它失败stringp。无论如何,解决这个问题的一种方法是将buffer-file-name的实例替换为

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

如果你需要使用它,或者像下面这样的块

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

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