【问题标题】:Emacs predictive mode and cycling with TABEmacs 预测模式和使用 TAB 循环
【发布时间】:2013-03-31 13:12:45
【问题描述】:

我正在尝试在 Emacs 中使用预测模式来自动完成 LaTeX 文档。按下 TAB 时,我希望它执行以下操作

  • 如果只有一种可能,请完成单词。 (这通常不会发生。单词的其余部分以蓝色突出显示,我必须按 [Ctrl]-Enter 才能完成。)

  • 如果有很多备选方案,请循环使用。 (我不知道如何让它做到这一点。)

【问题讨论】:

    标签: emacs autocomplete


    【解决方案1】:

    您需要检查有多少完成候选,并相应地调用completion-acceptcompletion-cycle

    以下应该可以解决问题:

    (defun completion-accept-or-cycle (&optional n)
      "Accept current completion if there's only one possible candidate.
    Otherwise, cycle the completion candidates. A numerical prefix argument
    N specifies the number of candidates to cycle forwards (or backwards if
    N is negative)."
      (interactive)
      (let ((overlay (completion-ui-overlay-at-point)))
        (when overlay 
          (if (= (length (overlay-get overlay 'completions)) 1)
          (completion-accept)
        (completion-cycle n)))))
    

    现在将 TAB 绑定到 .emacs 中 completion-overlay-map 键盘映射中的这个新的 completion-accept-or-cycle 命令:

    (define-key completion-overlay-map "\t" 'completion-accept-or-cycle)
    

    【讨论】:

    • 感谢您花时间写这篇文章。
    猜你喜欢
    • 2013-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-17
    • 1970-01-01
    • 1970-01-01
    • 2013-09-08
    • 1970-01-01
    相关资源
    最近更新 更多