Org-mode cannot edit C source code

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

#+begin_src c #define MAX 100 #+end_src 

and after calling the org-edit-src-code function to edit the C code in a new buffer, an error occurs:

Language mode `c-mode 'fails: stringp

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

All other languages ​​can work without any problems, including C ++, elisp, sh.

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

full debugging info (follow the Noufal Ibrahim 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 Cc ' (Cc 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 newbie and I do not know what the problem is. Any tips?

+4
source share
1 answer

As was discovered in the comments, this is caused by accessing buffer-file-name in a temporary buffer that is not supported by the file, and therefore, buffer-file-name is zero, which causes stringp to fail. Anyway, one way to fix this is to replace the buffer-file-name instances with

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

if you need to use it, or 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 on what you do.

+1
source

Source: https://habr.com/ru/post/1383865/


All Articles