在 .emacs 文件中更改字符强调后,无法识别 .org 文件。为什么?

.org file not recognized after character-emphasis changes in the .emacs file. Why?

我正在写一些法语,我需要将一个单词中的几个字母加粗,以突出显示一个特定的音节或两个非常相似的单词之间的区别,所以我按照这个线程的说明进行操作“How to make part of a word bold in org-mode ”。我在 .emacs 文件的底部添加了以下行(我在 Windows 7 32 位)

(setcar org-emphasis-regexp-components " \t('\"{[:alpha:]")
(setcar (nthcdr 1 org-emphasis-regexp-components) "[:alpha:]- \t.,:!?;'\")}\")
(org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)

我保存并重新启动了系统,但是现在,当我打开 .org 文件时,emacs 无法将其识别为 .org 文件并且不会应用任何样式或格式。它把它看作一个 LaTeX 文件,不允许我用 C-c C-e 导出内容。我是否必须按任何特定顺序放置这些行,才能与 org-mode 一起使用?我不是 elisp 专家,我只是按需复制粘贴配置代码。

请看下图。打字都是白色的,我如何让它响应?我是否应该将这些新代码行移到我的 .emacs 文件中?

当前 .emacs 文件

;;; Schlosser's .emacs
 (server-start)
 (add-hook 'LaTeX-mode-hook 'turn-on-reftex)
 (setq reftex-plug-into-AUCTeX t)

;;; a key for tilde symbol
(define-key key-translation-map (kbd "M-2") (kbd "~"))
;;; a key for backtick symbol
(define-key key-translation-map (kbd "M-6") "")
(define-key key-translation-map (kbd "M-9") (kbd "`"))

;; visual line word wrapping
 (global-visual-line-mode t)

;; ;;; Brent.Longborough's .emacs
 (setq inhibit-splash-screen t); Disable splash screen
 (setq visible-bell t); Flashes on error
 (show-paren-mode 1); Matches parentheses and such in every mode


;;; AUCTeX
;; Customary Customization, p. 1 and 16 in the manual, and http://www.emacswiki.org/emacs/AUCTeX#toc2
 (setq TeX-parse-self t); Enable parse on load.
 (setq TeX-auto-save t); Enable parse on save.
 (setq-default TeX-master nil)

 (setq TeX-PDF-mode t); PDF mode (rather than DVI-mode)

;activate Aspell, for all modes(?), not just TeX;
(add-to-list 'exec-path "C:/Program Files/Aspell/bin/")
(setq-default ispell-program-name "C:/Program Files/Aspell/bin/aspell.exe"); M-x ispell-change-dictionary RET to change dictionary
(setq ispell-dictionary "italiano"); Default dictionary. To change do M-x ispell-change-dictionary RET.
(require 'ispell) ;turn on dictionary check


;; (add-hook 'TeX-mode-hook 'flyspell-mode); Enable Flyspell mode for TeX modes such as AUCTeX. Highlights all misspelled words.
;; (add-hook 'emacs-lisp-mode-hook 'flyspell-prog-mode); Enable Flyspell program mode for emacs lisp mode, which highlights all misspelled words in comments and strings.

 (add-hook 'TeX-mode-hook
           (lambda () (TeX-fold-mode 1))); Automatically activate TeX-fold-mode.
;; (setq LaTeX-babel-hyphen nil); Disable language-specific hyphen insertion.

;; " expands into csquotes macros (for this to work babel must be loaded after csquotes).
;; (setq LaTeX-csquotes-close-quote "}"
;;       LaTeX-csquotes-open-quote "\enquote{")

;from StackExchange question "AUCTeX preview font size too small"
 (set-default 'preview-scale-function 1.2)

;; LaTeX-math-mode http://www.gnu.org/s/auctex/manual/auctex/Mathematics.html
 (add-hook 'TeX-mode-hook 'LaTeX-math-mode)


(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(ansi-color-faces-vector
   [default default default italic underline success warning error])
 '(custom-enabled-themes (quote (tango-dark)))
 '(org-format-latex-options
   (quote
    (:foreground default :background default :scale 1.2 :html-foreground "Black" :html-background "Transparent" :html-scale 1.0 :matchers
         ("begin" "" "$" "$$" "\(" "\["))))
 '(org-startup-with-latex-preview nil)
 '(preview-default-document-pt 10)
 '(show-paren-mode t)
 '(transient-mark-mode (quote (only . t))))

(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )


;; yasnippet
(add-to-list 'load-path "~/.emacs.d/elpa/yasnippet-0.8.0")
(require 'yasnippet)
(setq yas-snippet-dirs '("~/.emacs.d/elpa/yasnippet-0.8.0/snippets"))
  ;(setq-default mode-require-final-newline nil) 
(yas-global-mode 1)
(defun disable-final-newline () (interactive) (set (make-local-variable 'require-final-newline) nil))

;; solving yasnippet and org-mode conflict as per manual
 (defun yas/org-very-safe-expand ()
   (let ((yas/fallback-behavior 'return-nil)) (yas/expand)))
(add-hook 'org-mode-hook
                    (lambda ()
                      (make-variable-buffer-local 'yas/trigger-key)
                      (setq yas/trigger-key [tab])
                      (add-to-list 'org-tab-first-hook 'yas/org-very-safe-expand)
                      (define-key yas/keymap [tab] 'yas/next-field)))

;;emacs and SumatraPDF sync as per Whosebug question "sync emacs auctex with SumatraPDF"
(setq TeX-PDF-mode t)
(setq TeX-source-correlate-mode t)
(setq TeX-source-correlate-method 'synctex)
(setq TeX-view-program-list
   '(("Sumatra PDF" ("\"C:/Program Files/SumatraPDF/SumatraPDF.exe\" -reuse-instance" (mode-io-correlate " -forward-search %b %n ") " %o"))))

(eval-after-load 'tex
  '(progn
     (assq-delete-all 'output-pdf TeX-view-program-selection)
     (add-to-list 'TeX-view-program-selection '(output-pdf "Sumatra PDF"))))


;code taken from SX "Cleveref: AUCTeX and RefTeX set-up"
(eval-after-load
    "latex"
  '(TeX-add-style-hook
    "cleveref"
    (lambda ()
      (if (boundp 'reftex-ref-style-alist)
      (add-to-list
       'reftex-ref-style-alist
       '("Cleveref" "cleveref"
         (("\cref" ?c) ("\Cref" ?C) ("\cpageref" ?d) ("\Cpageref" ?D)))))
      (reftex-ref-style-activate "Cleveref")
      (TeX-add-symbols
       '("cref" TeX-arg-ref)
       '("Cref" TeX-arg-ref)
       '("cpageref" TeX-arg-ref)
       '("Cpageref" TeX-arg-ref)))))


;; Org mode and Beamer export
(require 'ox-beamer)
(setq org-latex-to-pdf-process 
  '("pdflatex --shell-escape -interaction nonstopmode -output-directory %o %f"
"pdflatex --shell-escape -interaction nonstopmode -output-directory %o %f"
"pdflatex --shell-escape -interaction nonstopmode -output-directory %o %f"))


(defun my-beamer-bold (contents backend info)
 (when (eq backend 'beamer)
  (replace-regexp-in-string "\`\\[A-Za-z0-9]+" "\\textbf" contents)))

(add-to-list 'org-export-filter-bold-functions 'my-beamer-bold)

(setq org-src-fontify-natively t)
(org-babel-do-load-languages
 'org-babel-load-languages
 '((python . t)
  (latex . t)))
(setq org-confirm-babel-evaluate nil)
(setq org-babel-python-command "ipython --pylab --pdb --nosep --classic --no-banner --no-confirm-exit")

(setq org-latex-listings 'minted)
(setq org-latex-minted-options
   '(("fontsize" "\footnotesize")("bgcolor" "black")("obeytabs" "true")))

(require 'ox-latex)
(setq org-src-fontify-natively t)
(setq org-latex-pdf-process
   '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
    "pdflatex -shell-escape -interaction nonstopmode -output-directory %o   %f"
    "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
(setq org-src-preserve-indentation t)

;Python
(setq python-shell-interpreter "C:\Python27")


; allow bold or italics for parts of a word, from StakOverflow discussion "How to make part of a word bold in org-mode?"
 (setcar org-emphasis-regexp-components " \t('\"{[:alpha:]")
 (setcar (nthcdr 1 org-emphasis-regexp-components) "[:alpha:]- \t.,:!?;'\")}\")
 (org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)

新截图

我正在做的是在 Org 模式下编写和编辑一些法语笔记。当我完成一组课程时,导出带有 C-c C-evocab.org 文件,选择仅导出正文 (C-b),并把它变成 vocab.texl l。生成 vocab.tex 后,我在 vocab-main.tex 中输入 \input{vocab} 我之前准备的包含所有页面和字体格式(在 LaTeX 中)。最后我用 pdfLaTeX 编译 vocab-main.tex 并得到 pdf!

我不知道这是否是生成好看的 pdf 的最佳方式,我愿意接受建议。无论如何,如您所见,在 vocab.org 的底部,我有 LaTeX "tags" 允许 vocab.tex 使用 vocab-main.tex 作为主文件。

您添加的代码不应该改变 emacs 将 *.org 文件解释为 org 模式文件。我怀疑您的 .emacs init 中有其他问题。

  1. 尝试使用 运行 emacs --debug-init。这应该显示您的初始化文件是否有任何问题

  2. 删除您添加的行并查看 return 是否正常。

  3. Post 您当前的组织模式配置。您可能需要确保添加的行作为 org-mode 启动挂钩的一部分添加 - 至少,您可能需要确保在您的组织启动后调用 org-set-emph-re已加载并初始化。

  4. 创建一个非常基本的 org-mode 文件,仅包含您所需要的内容 - 删除所有额外的 #+ 选项内容。首先让基本的组织重点功能发挥作用,然后再添加此人员。

编辑:关于 org-reload 的建议,我好像找错了树。抱歉。

"Local variables list is not properly terminated" 错误表明它与最终 LaTeX 块中的局部变量块有关。因此,在没有您的自定义的情况下,我创建了一个带有 .org 后缀和以下文本的文件:

#+BEGIN_LATEX
%%% Local Variables:
%%% mode: latex
%%% End:
#+END_LATEX

我看到的行为与您报告的完全相同,使用的是 latex-mode 而不是 org-mode。所以发生的事情是 Emacs 看到局部变量块,即使您只希望它应用于导出的文件,并覆盖基于文件后缀的主要模式的通常确定。有关详细信息,请参阅手册 (here and here)。

作为变通方法,我可以在此块之后添加一个换页符 (^L) 以使 Emacs 忽略此块(因为它只会搜索文件的最后一页),但我没有这样做知道这将如何影响出口。或者,由于 export 应该生成一个 .tex 文件,因此您可能不需要此处的 mode 行。 TeX-master 行在任何情况下都不是问题。

当然,none 这解释了你的实际错误,因为我没有得到那个错误,所有这些在我看来就像一个完美的 well-formed 局部变量块。可能还会发生其他事情。

结束编辑


我不知道这会如何导致您所看到的行为,但我确实注意到 org-emphasis-regexp-components 在其文档中说:

You need to reload Org or to restart Emacs after customizing this.

我自己的初始化文件中有一些代码修改 org-emphasis-alist,它有相同的警告,我发现我确实需要在进行更改后调用 org-reload 才能使一切正常工作。 (这些天我打算四处寻找源代码,看看我是否可以避免每次重新启动 Emacs 时两次加载 Org 模式,但我还没有解决这个问题。)我认为可以避免这种情况自定义工具的事情,但是当你想改变一个变量相对于它的默认值时,它不能很好地工作,就像这里一样。

我会尝试在您的更改后插入 (org-reload),看看是否可以解决问题。如果没有,Tim 的建议很好,我还建议查看您的消息缓冲区,看看是否报告了任何可能给您一个起点的错误。