GNU Emacs:骨架模式,还在使用吗?

发布于 2024-09-02 11:10:26 字数 1288 浏览 2 评论 0原文

考虑到使用 GNU Emacs 建立模板系统的所有可能解决方案,人们现在使用什么?我仍在使用骨架模式,但当我到处读到它时,我们一定很少有人这样做。

您正在使用什么以及为什么? (也许我可以改用更流行的工具)。

例如,给定以下代码片段:(

(define-skeleton mwe:cl-defpackage-skeleton
  "Inserts a Common Lisp DEFPACKAGE skeleton."
  (skeleton-read "Package: " (if v1
                                 (file-name-sans-extension
                                  (file-name-nondirectory
                                   (buffer-file-name)))))
  (if (setq v1 (bobp)) ";;; -*- Mode:Lisp; Syntax:ANSI-Common-Lisp;")
  & (if buffer-file-coding-system
        (concat " Coding:"
                (symbol-name 
                 (coding-system-get buffer-file-coding-system 
                                    'mime-charset))))
  & " -*-"
  & \n
  & \n "(defpackage #:" str
  \n "(:nicknames" ("Nickname: " " #:" str) & ")" | '(kill-whole-line -1)
  \n "(:use #:CL" ((slime-read-package-name "USEd package: ") " #:" str) ")"
  ")" \n
  \n
  (if v1 "(in-package #:") & str & ")" & \n &
  \n
  _)

来源:http://www. foldr.org/~michaelw/log/programming/lisp/defpackage-sculpture

哪种(现代)模板模式可以做同样的事情(以及如何做;))?

干杯

given all the possible solutions to have a template system with GNU Emacs, what do people use today ? I am still using skeleton-mode but as I read it here and there, we must be really few to do so.

What are you using and why ? (maybe I could switch to a more popular tool).

For example, given this snippet:

(define-skeleton mwe:cl-defpackage-skeleton
  "Inserts a Common Lisp DEFPACKAGE skeleton."
  (skeleton-read "Package: " (if v1
                                 (file-name-sans-extension
                                  (file-name-nondirectory
                                   (buffer-file-name)))))
  (if (setq v1 (bobp)) ";;; -*- Mode:Lisp; Syntax:ANSI-Common-Lisp;")
  & (if buffer-file-coding-system
        (concat " Coding:"
                (symbol-name 
                 (coding-system-get buffer-file-coding-system 
                                    'mime-charset))))
  & " -*-"
  & \n
  & \n "(defpackage #:" str
  \n "(:nicknames" ("Nickname: " " #:" str) & ")" | '(kill-whole-line -1)
  \n "(:use #:CL" ((slime-read-package-name "USEd package: ") " #:" str) ")"
  ")" \n
  \n
  (if v1 "(in-package #:") & str & ")" & \n &
  \n
  _)

(credits: http://www.foldr.org/~michaelw/log/programming/lisp/defpackage-skeleton)

which (modern) template mode could do the same (and how ;)) ?

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

云雾 2024-09-09 11:10:26

郑重声明:即使又过了 7 年,我仍然对骷髅感到非常满意。我的初始化文件中有很多可用的: https://github.com/ska2342/ska-init-files/blob/master/dot.emacs.d/init.el

For the record: even another 7 years later I am still very happy with skeletons. Lots of them available over there in my init files: https://github.com/ska2342/ska-init-files/blob/master/dot.emacs.d/init.el

一影成城 2024-09-09 11:10:26

我使用 yasnippet

在我的 emacs 中,我有这个:

(require 'yasnippet-bundle)

在我想要使用片段的每种模式的钩子中(例如我的 c 模式钩子等),我有这个:

(yas/minor-mode-on)

我使用的“静态”片段在我使用的目录结构中可用,此处:

http://cheeso.members.winisp .net/srcview.aspx?dir=emacs&file=snippets.zip

当任何代码片段发生更改时,您需要创建一次上述捆绑 .el 文件。这样做:

(require 'yasnippet)
(yas/compile-bundle 
 ; the starting point
 "c:/your/path/yasnippet.el"

 ; the bundle file to generate
 "c:/your/path/yasnippet-bundle.el" 

 ; the snippet dir from which to generate the bundle
 "c:/your/path/snippets")

就是这样!

然后,当我在 C# 文件中输入 for 时,我会得到一个带有 for 循环的模板。等等。


我还使用 yasnippet 和动态片段模板。我编写的 C# 代码完成模块使用动态构造的字符串来调用 yas/expand-snippet ,该字符串定义了要扩展的模板。

因此,您可以键入

  MyType.Method(<COMPLETE>

...其中 是代码完成键,代码完成模块会在 MyType.Method( 上进行查找,然后构建一个选择菜单,当用户从菜单中选择一个选项时,代码完成模块会构建模板,其中包含所选方法的每个参数的字段,然后调用yas/expand-snippet 并且该模板被注入到缓冲区中,就像它是静态模板一样 在动态生成的模板中,该方法的每个参数都会获得一个“typeover”字段,我只需填写它,通过选项卡浏览这些字段。 所示

这个“动态片段”想法适用于任何代码完成引擎,您只需要一种从方法或函数签名映射

  function(int arg1, string arg2, char arg3)

到 yasnippet 模板定义字符串的方法,如下

  function(${1:int arg1}, ${2:string arg2}, ${3:char arg3}) 

:一段相当简单的 elisp。

I use yasnippet.

In my emacs I have this:

(require 'yasnippet-bundle)

In my hook for each mode where I want to use snippets (like my c-mode hook, etc), I have this:

(yas/minor-mode-on)

The "static" snippets I use are available, in the directory structure I use, here:

http://cheeso.members.winisp.net/srcview.aspx?dir=emacs&file=snippets.zip

You need to create the bundle .el file mentioned above, once, when any of the snippets change. do it this way:

(require 'yasnippet)
(yas/compile-bundle 
 ; the starting point
 "c:/your/path/yasnippet.el"

 ; the bundle file to generate
 "c:/your/path/yasnippet-bundle.el" 

 ; the snippet dir from which to generate the bundle
 "c:/your/path/snippets")

That's it!

Then, when I'm in a C# file and type for<TAB>, I get a template with a for loop. And so on.


I also use yasnippet with dynamic snippet templates. A C# code-completion module I wrote calls yas/expand-snippet with a dynamically constructed string that defines the template to expand.

So, you can type

  MyType.Method(<COMPLETE>

...where <COMPLETE> is the code-completion key, and the code-completion module does the lookup on the MyType.Method(, then builds a menu of choices, and pops it up. When the user selects a choice from the menu, the code-completion module builds the template, containing fields for each of the arguments for the selected method. Then it calls yas/expand-snippet and that template is injected into the buffer, just as if it had been a static template. In the dynamically-generated template, each argument to the method gets a "typeover" field, and I just fill it in, tabbing through the fields. Pretty nice.

This "dynamic snippet" idea would work with any code-completion engine. You just need a way to map from a method or function signature, like this:

  function(int arg1, string arg2, char arg3)

to a yasnippet template definition string, which looks like this:

  function(${1:int arg1}, ${2:string arg2}, ${3:char arg3}) 

And that's a pretty trivial piece of elisp.

じее 2024-09-09 11:10:26

我没有太多使用骨架模式,但我在使用 Ruby 和 C 进行编码时使用 YASnippet。它非常有用,但我怀疑骨架模式要强大得多。

I haven't used skeleton mode much, but I use YASnippet while coding in Ruby and C. Its pretty useful, but I suspect skeleton mode is far more powerful.

风透绣罗衣 2024-09-09 11:10:26

emacs wiki 将 Yasnippet 列为骨架的可能替代品。 yasnippet 附带的片段非常好,但您应该真正编写自己的片段,因为真正的力量就在那里。

The emacs wiki lists Yasnippet as a possible replacement for skeleton. The snippets that come with yasnippet are pretty good, but you should really write your own, as the true power lies there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文