代码之家  ›  专栏  ›  技术社区  ›  incandescentman

如何控制Emacs缩写展开中的光标位置?

  •  2
  • incandescentman  · 技术社区  · 12 年前

    在Emacs中,有没有一种方法可以控制光标/点在缩写模式扩展中的位置?

    你知道吗,像这样的事情?

    ("orgfootnote" "[fn:: %?]" nil 0)
    
    3 回复  |  直到 12 年前
        1
  •  3
  •   Rudolf Adamkovič    2 年前

    Abbrev自己并不提供这一功能,但他们提供了足够的钩子来实现外部功能。 例如。

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

    然后用一个类似缩写的词

    ("orgfootnote" "" 'my-orgfootnote)
    
        2
  •  2
  •   Tom    12 年前

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

     (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
  •  1
  •   event_jr    12 年前

    如果你需要填写一个模板,那么 abbrev 是错误的设施。我强烈推荐 yasnippet . 缩写 对于纠正频繁的打字错误非常有用。

    推荐文章