在Emacs中重复输入变量名的快速方法? [英] A quick way to repeatedly enter a variable name in Emacs?

查看:80
本文介绍了在Emacs中重复输入变量名的快速方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚输入了第N次这样的代码:

I was just typing in this sort of code for Nth time:

menu.add_item(spamspamspam, "spamspamspam");

我想知道是否有更快的方法。

And I'm wondering if there's a faster way to do it.

我想要一个类似于yasnippet镜像的行为,除了
我不想创建一个代码段:参数顺序从
项目到项目和从语言到

I'd like a behavior similar to yasnippet's mirrors, except I don't want to create a snippet: the argument order varies from project to project and from language to language.

唯一不变的是在同一行需要重复多次
的变量名。

The only thing that's constant is the variable name that needs to be repeated several times on the same line.

我想输入

menu.add_item($,"")

与引号之间的点,调用快捷方式并开始输入
,最后退出< kbd> Ce 。

and with the point between the quotes, call the shortcut and start typing, and finally exit with C-e.

这似乎对我有好处,因为有零个额外的光标移动。
我有一个如何做到这一点的想法,但我想知道如果已经完成,
或者如果更好/更快的事情可以完成。

This seems advantageous to me, since there's zero extra cursor movement. I have an idea of how to do this, but I'm wondering if it's already done, or if something better/faster can be done.

感谢这个答案。这确实是我最初想到的 yasnippet 代码:

Thanks to thisirs for the answer. This is indeed the yasnippet code I had initially in mind:

(defun yas-one-line ()
  (interactive)
  (insert "$")
  (let ((snippet 
         (replace-regexp-in-string 
          "\\$" "$1"
          (substring-no-properties
           (delete-and-extract-region
            (line-beginning-position)
            (line-end-position))))))
    (yas/expand-snippet snippet)))

但是我仍然希望看到更好/更快的东西。

But I'm still hoping to see something better/faster.

推荐答案

yasnippet 实际上可以用于即时创建代码片段:

yasnippet can actually be used to create a snippet on-the-fly:

(defun yas-one-line ()
  (interactive)
  (let ((snippet (delete-and-extract-region
                  (line-beginning-position)
                  (line-end-position))))
    (yas-expand-snippet snippet)))

现在只需键入:

menu.add_item($1,"$1")

并调用 yas-one-line 。上面的代码段由yasnippet扩展!

and call yas-one-line. The above snippet is expanded by yasnippet!

这篇关于在Emacs中重复输入变量名的快速方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆