编辑我的问题一直与片段语法有关......下面的配置完全有效。
我正在尝试将 org-mode 和 yasnippet 一起使用,即使使用 org-mode FAQ 中的一些解决方法,它也无法正常工作。每当我点击TAB一个片段缩写时,这个词就会被删除。TAB如果我没有超过一个片段词,则表现正常,所以发生了一些事情......
我正在使用Org-mode version 7.7
,yasnippet (version 0.7.0)
和GNU Emacs 23.4.1
.
这是我的设置:
(setq load-path
(append (list nil
"~/.emacs.d/site-lisp/yasnippet"
"~/.emacs.d/site-lisp/org-7.7/lisp")
load-path))
;; set up yasnippet
(require 'yasnippet)
(yas/initialize)
(setq yas/snippet-dirs '("~/.emacs.d/mysnippets"
"~/.emacs.d/site-lisp/yasnippet/snippets"))
(mapc 'yas/load-directory yas/snippet-dirs)
;; set up org mode
(require 'org-install)
;; fix some org-mode + yasnippet conflicts:
(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)))
而且我很确定钩子正在按预期运行,因为C-h v org-tab-first-hookorg 缓冲区中的以下输出:
org-tab-first-hook is a variable defined in `org.el'.
Its value is
(yas/org-very-safe-expand org-hide-block-toggle-maybe org-src-native-tab-command-maybe org-babel-hide-result-toggle-maybe)
这是C-h k TAB在一个组织缓冲区中:
<tab> runs the command org-cycle, which is an interactive Lisp
function in `org.el'.
编辑
edebug-defun
在我的功能上执行后,yas/org-very-safe-expand
我看到以下消息
Result: "[yas] elisp error! Symbol's value as variable is void: err"
所以 yas 在某个地方出错了……我的edebug
foo 没有达到标准,但是如果我有时间,我会尝试单步执行并查看错误在哪里。我完整的 emacs 配置在github 上。