我遇到设置markdown-command的问题。我得到符号作为变量是无效的。我最初设置在自定义内部并且一切正常。我想清理我的init.el,我宁愿将所有内容保留在自定义之外并手动设置。
有人能提供这方面的见解吗?我见过的最近的事情就在这里:https://stackoverflow.com/questions/12058717/confusing-about-the-emacs-custom-system
感谢。
;;General Settings
(global-auto-revert-mode t) ;;Refresh Buffers on File Change.
(setq-default indent-tabs-mode nil) ;;Use spaces instead of tabs.
(desktop-save-mode 1) ;;Save session
(show-paren-mode 1) ;;Show matching parenthesis
;;Custom Load Paths
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/") ;;Look here for additional themes.
(add-to-list 'load-path "~/.emacs.d/modes/") ;;Look here for additional modes.
;;Load Specific Them
(load-theme 'solarized-dark t)
;;Marmalade Package Manager
(require 'package)
(add-to-list 'package-archives
'("marmalade" .
"http://marmalade-repo.org/packages/"))
(package-initialize)
;;OSX Specific Settings
;;Add /usr/local/bin and /opt/local/bin to execution path
(if (eq system-type 'darwin)
(setq exec-path
(append
'("/usr/local/bin"
"/opt/local/bin")
exec-path)))
;;Markdown Specific Settings
(autoload 'markdown-mode "markdown-mode"
"Major mode for editing Markdown files" t)
(add-to-list 'auto-mode-alist '("\\.text\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
(if (eq system-type 'darwin)
(setq-default 'markdown-command '("/usr/local/bin/pandoc"))
(setq-default 'markdown-command '("/usr/bin/multimarkdown")))
(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.
)
(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.
)
根据建议,我试过
(eval-after-load "markdown-mode"
(if (eq system-type 'darwin)
(setq markdown-command '("/usr/local/bin/pandoc"))
(setq markdown-command '("/usr/bin/multimarkdown"))))
然后我意识到自己的错误。我没有做过建议。
(eval-after-load "markdown-mode"
(if (eq system-type 'darwin)
'(setq markdown-command ("/usr/local/bin/pandoc"))
'(setq markdown-command ("/usr/bin/multimarkdown"))))
同样如上所述,eval-after-load "markdown-mode"
不需要。
答案 0 :(得分:2)
代码失败,因为变量markdown-command
在markdown-mode
中定义,而markdown-mode尚未加载。通过将此变量添加到init文件,可以在加载markdown-mode
时安排设置变量。
(eval-after-load "markdown-mode"
'(setq markdown-command '("/usr/bin/markdown")))
来自 C-h f eval-after-load
RET
Arrange that if FILE is loaded, FORM will be run immediately afterwards.
If FILE is already loaded, evaluate FORM right now.
<强>更新强>
如果您只想保留init文件中的自定义选项,可以将以下内容添加到init文件中
(setq custom-file "~/your-custom-file")
(load custom-file)
答案 1 :(得分:1)
保存设置的算法如下:如果变量是可自定义的(在变量的You can customize this variable.
缓冲区底部查找*Help*
行),则输入
(custom-set-variables
'(markdown-command '("/usr/local/bin/pandoc"))
'(indent-tabs-mode nil))
进入.emacs
,否则您使用setq
。
当实际加载使用您的自定义的包时,它会根据您的custom-set-variables
来电正确设置变量。
答案 2 :(得分:0)
这通常不是 一个好主意:
我最初设置在自定义内部并且一切正常。我想清理我的init.el,我宁愿将所有内容保留在自定义之外并手动设置。
是的,保持自定义的初始文件。但不意味着你需要放弃使用Customize。用它来做它的好处。并通过定义选项custom-file
将其限制在自己的文件中。
对于您当前的问题,您执行不需要eval-after-load
或任何其他代码,以您希望的方式定义此选项。您只需要执行M-x customize-option RET markdown-command RET
并在更新后保存值 - 在Customize中。
这是正确的方式来自定义用户选项。