Ruby on rails 带yasnippets的emacs智能标签

Ruby on rails 带yasnippets的emacs智能标签,ruby-on-rails,emacs,lisp,yasnippet,Ruby On Rails,Emacs,Lisp,Yasnippet,我试图在所有打开的缓冲区内完成tab,并且yasnippet都使用tab键。现在我可以有一个或另一个。下面的代码是我如何处理yasnippet扩展的,但是由于我不是一个lisp程序员,所以我看不出这里的错误 如果无法展开代码段,我希望它尝试从缓冲区展开 ;; Auto complete settings / tab settings ;; http://emacsblog.org/2007/03/12/tab-completion-everywhere/ <-- in the commen

我试图在所有打开的缓冲区内完成tab,并且yasnippet都使用tab键。现在我可以有一个或另一个。下面的代码是我如何处理yasnippet扩展的,但是由于我不是一个lisp程序员,所以我看不出这里的错误

如果无法展开代码段,我希望它尝试从缓冲区展开

;; Auto complete settings / tab settings
;; http://emacsblog.org/2007/03/12/tab-completion-everywhere/ <-- in the comments
(global-set-key [(tab)] 'smart-tab)
(defun smart-tab ()
  "This smart tab is minibuffer compliant: it acts as usual in
    the minibuffer. Else, if mark is active, indents region. Else if
    point is at the end of a symbol, expands it. Else indents the
    current line."
  (interactive)
  (if (minibufferp)
      (unless (minibuffer-complete)
        (dabbrev-expand nil))
    (if mark-active
        (indent-region (region-beginning)
                       (region-end))
      (if (looking-at "\\_>")
          (unless (yas/expand)
            (dabbrev-expand nil))
        (indent-for-tab-command)))))
;;自动完成设置/选项卡设置

;; http://emacsblog.org/2007/03/12/tab-completion-everywhere/ 首先,我试图理解代码的作用,以及您希望它做什么

你的代码

  • 首先检查
    点是否在
    小缓冲区中

    • 如果是这样,那么它将尝试完成微型缓冲区

      • 如果(在minibuffer中)无法完成它,它将调用dabbrev expand
  • 否则,如果点
    不在微型缓冲区中

    • 如果标记了某个区域,则会缩进该区域

    • 如果
      没有标记处于活动状态
      ,它将检查该点是否位于某个单词的
      末尾

      • 如果是这样,它检查yasnippet是否可以扩展

        • 如果yas无法扩展,则称为dabbrev expand
      • 如果没有,它将尝试缩进当前行

这就是你的代码所做的

由于yas/expand,您的代码失败。如果扩展失败,此命令不会返回

如果此命令失败,它将检查变量
yas/回退行为的状态。如果此变量的值为
callother command
,则失败的yas扩展将调用绑定到变量
yas/trigger key
中保留的键的命令

在您的情况下,此变量是
选项卡

因此:您在单词的末尾,按TAB键完成,这将触发交互式
智能选项卡
,它调用yas/expand,如果扩展失败,则调用
选项卡
的绑定函数,这是无限循环

您的问题的解决方案是在此
智能选项卡
函数中将
nil临时绑定到yas/回退行为

以下是如何修复它:

(if (looking-at "\\_>")
      (let ((yas/fallback-behavior nil))
        (unless (yas/expand)
          (dabbrev-expand nil)))
    (indent-for-tab-command))

当前,如果它无法使用yasnippet进行扩展,则会出现错误“变量绑定深度超过了最大specpdl大小”,并且它不会使用dabbrev expand进行扩展