【问题标题】:how to control cursor placement in Emacs abbrev expansion?如何控制 Emacs 缩写扩展中的光标位置?
【发布时间】:2013-03-14 02:19:29
【问题描述】:

在 Emacs 中,有没有办法控制光标/点在 abbrev-mode 扩展中的位置?

你知道吗,像这样的?

("orgfootnote" "[fn:: %?]" nil 0)

【问题讨论】:

  • 这是emacs,所以当然可以做一些事情!您能否详细说明一下光标现在结束的位置以及您希望它结束​​的位置?另外,请仔细检查并确保您知道您使用的是哪种缩写模式,因为 emacs 有几种缩写模式。

标签: emacs expansion abbreviation pabbrev


【解决方案1】:

Abbrev 本身不提供此功能,但它们提供了足够的挂钩以在外部完成此功能。 例如

(define-skeleton my-orgfootnote "Docstring." nil
  "fn::" _ "]")

然后使用类似的缩写

("orgfootnote" "" my-orgfootnote)

【讨论】:

  • 完美!如果有人有兴趣将它用于实际的脚注语法,我稍微调整了间距:(define-skeleton my-orgfootnote "Docstring." nil "[fn:: " _ "]\n\n")
【解决方案2】:

如果您指的是内置缩写功能,那么这就是我对这个问题的看法。如果您有一个包含字符串@@ 的缩写词,那么在扩展后,光标将被放置在扩展文本中@@ 出现的那个位置。

 (defadvice expand-abbrev (after my-expand-abbrev activate)
   ;; if there was an expansion
   (if ad-return-value
       ;; start idle timer to ensure insertion of abbrev activator
       ;; character (e.g. space) is finished
       (run-with-idle-timer 0 nil
                            (lambda ()
                              ;; if there is the string "@@" in the
                              ;; expansion then move cursor there and
                              ;; delete the string
                              (let ((cursor "@@"))
                                (if (search-backward cursor last-abbrev-location t)
                                    (delete-char (length cursor))))))))

【讨论】:

【解决方案3】:

如果您需要填写模板,那么abbrev 是错误的工具。我强烈推荐yasnippetabbrev 对于纠正频繁的拼写错误非常有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多