gpt4 book ai didi

emacs - org-mode 和 yasnippet 之间的冲突

转载 作者:行者123 更新时间:2023-12-02 17:50:07 26 4
gpt4 key购买 nike

编辑 我的问题一直与片段语法有关...下面的配置完全有效。


我正在尝试同时使用 org-mode 和 yasnippet,但它甚至无法与 workarounds 中的一些一起使用在 org-mode FAQ 上。每当我在片段缩写上点击 TAB 时,这个词就会被删除。 TAB 如果我没有超过一个片段单词,则表现正常,所以发生了一些事情......

我正在使用 Org-mode 7.7 版yasnippet(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)))

而且我非常确定 Hook 正在按预期运行,因为组织缓冲区中的 C-h v org-tab-first-hook 输出如下:

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'.

编辑

在对我的 yas/org-very-safe-expand 函数执行 edebug-defun 后,我看到了以下消息

Result: "[yas] elisp error! Symbol's value as variable is void: err"

所以 yas 在某处出错了...我的 edebug foo 不太符合标准,但如果我有时间,我会尝试单步执行并查看错误在哪里.我的完整 emacs 配置在 github 上 here .

最佳答案

原来我的问题与片段语法有关,而不是设置。傻傻的我...

换句话说,这完全有效:

;; 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)))

关于emacs - org-mode 和 yasnippet 之间的冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9418148/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com