unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Including Yasnippet to Emacs
@ 2014-03-17  4:10 Danil Orlov
  2014-03-17 14:45 ` Stefan
  0 siblings, 1 reply; 9+ messages in thread
From: Danil Orlov @ 2014-03-17  4:10 UTC (permalink / raw)
  To: emacs-devel

I know that everybody want to push to Emacs standard distro something what he needs. But snippets is another
question - it is too wide used technology to be ignored. Sublime Text Editor, TextMate has it, all Jetbrains IDEs has it, I even
think that every IDE nowdays has it. That's bad argument, but I have another one - lots of modes creates its own wheel to support snippets.

html-mode uses own snippets for tags
web-mode uses own snippets "C-c C-s"
markdown-mode uses own snippets for headers

and that's only modes I use.

I think that if Emacs will have unified mechanism for managing snippets, it will be useful not only for end users, but also for mode creators. 
And those snippets-for-each-mode also steal keybindings. And many of us uses Yasnippet too, so we in fact always have two different snippet engines.

Of course now Yasnippet probably a bit clumsy for usage via API. Maybe something like this must be supported, to migrate mode snippets easily.

(yas/api-add-snippet 
                     "html-mode"   ; mode
                     "h1"          ; name and key
                     "C-x n 1"     ; keyboard shortcut
                     "<h1>$1</h1>" ; snippet body
                     )

So you, as mode author, must not think about bindings, creating function for each snippet.

What do you think about it?



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Including Yasnippet to Emacs
  2014-03-17  4:10 Including Yasnippet to Emacs Danil Orlov
@ 2014-03-17 14:45 ` Stefan
  2014-03-17 14:53   ` joakim
                     ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Stefan @ 2014-03-17 14:45 UTC (permalink / raw)
  To: Danil Orlov; +Cc: João Távora, emacs-devel

> one - lots of modes creates its own wheel to support snippets.

> html-mode uses own snippets for tags
> web-mode uses own snippets "C-c C-s"
> markdown-mode uses own snippets for headers

> and that's only modes I use.

Emacs already has several "snippet" systems builtin:
tempo.el, skeleton.el, expand.el, and I'm sure I'm forgetting some.

> What do you think about it?

João has a snippet.el in the works, which is yet-another of those
snippet systems, but this one is designed as a "Lispish core, such that
yasnippet.el can be provided as a layer on top of it.  He's been writing
it with a fair bit a bitching^H^H^H^H^H^H^Hreview from me, and if all
goes well it could be included in 24.5.


        Stefan



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Including Yasnippet to Emacs
  2014-03-17 14:45 ` Stefan
@ 2014-03-17 14:53   ` joakim
  2014-03-17 17:15   ` João Távora
  2014-03-17 17:42   ` Danil Orlov
  2 siblings, 0 replies; 9+ messages in thread
From: joakim @ 2014-03-17 14:53 UTC (permalink / raw)
  To: Stefan; +Cc: Danil Orlov, João Távora, emacs-devel

Stefan <monnier@iro.umontreal.ca> writes:

>> one - lots of modes creates its own wheel to support snippets.
>
>> html-mode uses own snippets for tags
>> web-mode uses own snippets "C-c C-s"
>> markdown-mode uses own snippets for headers
>
>> and that's only modes I use.
>
> Emacs already has several "snippet" systems builtin:
> tempo.el, skeleton.el, expand.el, and I'm sure I'm forgetting some.

Srecode in Cedet, thus already in Emacs, is nice and useful as well.


>> What do you think about it?
>
> João has a snippet.el in the works, which is yet-another of those
> snippet systems, but this one is designed as a "Lispish core, such that
> yasnippet.el can be provided as a layer on top of it.  He's been writing
> it with a fair bit a bitching^H^H^H^H^H^H^Hreview from me, and if all
> goes well it could be included in 24.5.
>
>
>         Stefan
>

-- 
Joakim Verona



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Including Yasnippet to Emacs
  2014-03-17 14:45 ` Stefan
  2014-03-17 14:53   ` joakim
@ 2014-03-17 17:15   ` João Távora
  2014-03-17 17:42   ` Danil Orlov
  2 siblings, 0 replies; 9+ messages in thread
From: João Távora @ 2014-03-17 17:15 UTC (permalink / raw)
  To: Stefan; +Cc: Danil Orlov, emacs-devel

Stefan <monnier@iro.umontreal.ca> writes:

> João has a snippet.el in the works, which is yet-another of those
> snippet systems, but this one is designed as a "Lispish core, such that
> yasnippet.el can be provided as a layer on top of it.  He's been writing
> it with a fair bit a bitching^H^H^H^H^H^H^Hreview from me, and if all
> goes well it could be included in 24.5.

Yes, check out the `snippet-engine' branch of
github.com/capitaomorte/yasnippet. Look for files snippet.el and
snippet-tests.el.

Bear in mind it's a work in progress, but the `define-snippet' macro
which is defined there should give you the full power of yasnippet's
textmate-like templates with a lispy interface, so you can do this

    (define-snippet printf ()
      "printf (\""
      (&field 1 "%s")
      (&mirror 1 (if (string-match "%" field-string) "\"," "\")"))
      (&field 2)
      (&mirror 1 (if (string-match "%" field-string) "\)" "")))

Instead of

     printf ("${1:%s}\\n"${1:$(if (string-match "%" yas-text) "," "\);")
     }$2${1:$(if (string-match "%" yas-text) "\);" "")}

As Stefan said, yasnippet.el will continue to accept the latter, but it
will define snippets on top of the former.

The above is already working more or less nicely, but Stefan's
nags^H^H^H^Hhelp convinced me to provide an even more powerful
alternative, so that you can use a new macro, call it
`expanding-snippet', to introduce a dynamic environment where `&field'
and `&mirror' are local macros. That way you can decide the structure of
your snippet at runtime, with some (minor) disadvantages like losing
compile-time checking of some snippet consistency.

This is what I'm working on right now. There is also a list of TODO's at
the top of snippet.el, and help is welcome.

João





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Including Yasnippet to Emacs
  2014-03-17 14:45 ` Stefan
  2014-03-17 14:53   ` joakim
  2014-03-17 17:15   ` João Távora
@ 2014-03-17 17:42   ` Danil Orlov
  2014-03-17 19:36     ` Stefan
  2 siblings, 1 reply; 9+ messages in thread
From: Danil Orlov @ 2014-03-17 17:42 UTC (permalink / raw)
  To: Stefan; +Cc: João Távora, emacs-devel

I've checked those ones you noted, even snippet.el . They all are not so powerful and user-friendly as yasnippet. And they are all not manage keybindings. And probably not support expansion depending on context in simple way. And docs are really stingy. And snippet language is not so powerful and readable, as in yasnippet.

But you are right - skeleton is totally enough for most modes.

And about snippet.el. I still think, that Yasnippet is better general solution for snippets for Emacs. It has the biggest user community, and lots of ready snippets on github, which can be installed easily. Yasnippet will be better concurrent for snippet systems in other editors and IDEs.

On Mon, Mar 17, 2014 at 10:45:29AM -0400, Stefan wrote:
> > one - lots of modes creates its own wheel to support snippets.
> 
> > html-mode uses own snippets for tags
> > web-mode uses own snippets "C-c C-s"
> > markdown-mode uses own snippets for headers
> 
> > and that's only modes I use.
> 
> Emacs already has several "snippet" systems builtin:
> tempo.el, skeleton.el, expand.el, and I'm sure I'm forgetting some.
> 
> > What do you think about it?
> 
> João has a snippet.el in the works, which is yet-another of those
> snippet systems, but this one is designed as a "Lispish core, such that
> yasnippet.el can be provided as a layer on top of it.  He's been writing
> it with a fair bit a bitching^H^H^H^H^H^H^Hreview from me, and if all
> goes well it could be included in 24.5.
> 
> 
>         Stefan



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Including Yasnippet to Emacs
  2014-03-17 17:42   ` Danil Orlov
@ 2014-03-17 19:36     ` Stefan
  2014-03-17 20:23       ` João Távora
  2014-03-17 21:09       ` Danil Orlov
  0 siblings, 2 replies; 9+ messages in thread
From: Stefan @ 2014-03-17 19:36 UTC (permalink / raw)
  To: Danil Orlov; +Cc: João Távora, emacs-devel

> I've checked those ones you noted, even snippet.el. They all are not so
> powerful and user-friendly as yasnippet.

snippet.el is not designed to be user-friendly, but to be easy to
integrate in a major-mode instead (yasnippet rather sucks in this
regard, you end up needing to distribute umpteen little files instead).

[ BTW, part of the intention behind snippet.el is to make Edebug work
  with them.  Si in some cases they may turn out to be more
  user-friendly, rather than less so.  ]

As for "not so powerful", I'm not sure what you mean: they should be
pretty much as powerful as yasnippet's since yasnippet will be written
on top of them.  And of course, they can run any Lisp code you like.

> And they are all not manage keybindings.

This layer is not provided yet, indeed.  E.g. I want to link snippet.el with
abbrevs, so the "table of snippets" will be an abbrev table.

> And probably not support expansion depending on context in simple way.

Not sure what "in a simple way" means.

> And docs are really stingy.

For skeleton.el, the system is trivial enough that I don't know what
more docs we could provide.  For snippet.el, it's still in flux and
there are indeed no docs yet, IIRC.

> And snippet language is not so powerful and readable, as in yasnippet.

"Readable" here is in the eye of the beholder.  But the whole idea
behind snippet.el is to get rid of this dichotomy: you can write your
snippets using the Lispish snippet.el syntax (i.e. a syntax that
makes sense to me) or you can write them in the yasnippet syntax if
you prefer $ over parentheses.


        Stefan



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Including Yasnippet to Emacs
  2014-03-17 19:36     ` Stefan
@ 2014-03-17 20:23       ` João Távora
  2014-03-17 21:12         ` Danil Orlov
  2014-03-17 21:09       ` Danil Orlov
  1 sibling, 1 reply; 9+ messages in thread
From: João Távora @ 2014-03-17 20:23 UTC (permalink / raw)
  To: emacs-devel

Stefan <monnier@iro.umontreal.ca> writes:

> snippet.el is not designed to be user-friendly, but to be easy to
> integrate in a major-mode instead (yasnippet rather sucks in this
> regard, you end up needing to distribute umpteen little files
> instead).

Actually, you can compile these umpteen little files into one file per
mode. See `yas-compile-directory'. Few use it AFAIK, but it's there and
it should work (at least the tests show it does).

And that's because yasnippet already has an elisp interface to defining
snippets, `yas-define-snippets'. There is definitely some suckage to it,
otherwise I wouldn't be writing snippet.el, but users or distribtors
aren't forced to deal with those million files.

> [ BTW, part of the intention behind snippet.el is to make Edebug work
>   with them.  Si in some cases they may turn out to be more
>   user-friendly, rather than less so.  ]

Indeed, I've answered many bugs from those who don't understand why
snippets don't work as intended, and I don't blame them.

> As for "not so powerful", I'm not sure what you mean: they should be
> pretty much as powerful as yasnippet's since yasnippet will be written
> on top of them.  And of course, they can run any Lisp code you like.

Danil, snippet.el is in its core just as powerful as yasnippet. Just a
few bits are missing like in-snippet expansions and snippet revival
after undo, but I plan to (re)implement them all.

>> And they are all not manage keybindings.
> This layer is not provided yet, indeed.  E.g. I want to link snippet.el with
> abbrevs, so the "table of snippets" will be an abbrev table.

And I intend to keep the familiar yasnippet keying mechanism in
yasnippet.el. In general yasnippet will keep most backward
compatibility.

> more docs we could provide.  For snippet.el, it's still in flux and
> there are indeed no docs yet, IIRC.

`define-snippet's docstring contains the gist of what that main entry
point will be. It's quite heavy at 60 lines, so maybe parts of it belong
to the manual, but it should give you an idea of what the defined
snippets can do. Did you read this docstring, Danil?




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Including Yasnippet to Emacs
  2014-03-17 19:36     ` Stefan
  2014-03-17 20:23       ` João Távora
@ 2014-03-17 21:09       ` Danil Orlov
  1 sibling, 0 replies; 9+ messages in thread
From: Danil Orlov @ 2014-03-17 21:09 UTC (permalink / raw)
  To: Stefan; +Cc: João Távora, emacs-devel

Okay, I've got your point.

On Mon, Mar 17, 2014 at 03:36:42PM -0400, Stefan wrote:
> > I've checked those ones you noted, even snippet.el. They all are not so
> > powerful and user-friendly as yasnippet.
> 
> snippet.el is not designed to be user-friendly, but to be easy to
> integrate in a major-mode instead (yasnippet rather sucks in this
> regard, you end up needing to distribute umpteen little files instead).
> 
> [ BTW, part of the intention behind snippet.el is to make Edebug work
>   with them.  Si in some cases they may turn out to be more
>   user-friendly, rather than less so.  ]
> 
> As for "not so powerful", I'm not sure what you mean: they should be
> pretty much as powerful as yasnippet's since yasnippet will be written
> on top of them.  And of course, they can run any Lisp code you like.
> 
> > And they are all not manage keybindings.
> 
> This layer is not provided yet, indeed.  E.g. I want to link snippet.el with
> abbrevs, so the "table of snippets" will be an abbrev table.
> 
> > And probably not support expansion depending on context in simple way.
> 
> Not sure what "in a simple way" means.
> 
> > And docs are really stingy.
> 
> For skeleton.el, the system is trivial enough that I don't know what
> more docs we could provide.  For snippet.el, it's still in flux and
> there are indeed no docs yet, IIRC.
> 
> > And snippet language is not so powerful and readable, as in yasnippet.
> 
> "Readable" here is in the eye of the beholder.  But the whole idea
> behind snippet.el is to get rid of this dichotomy: you can write your
> snippets using the Lispish snippet.el syntax (i.e. a syntax that
> makes sense to me) or you can write them in the yasnippet syntax if
> you prefer $ over parentheses.
> 
> 
>         Stefan



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Including Yasnippet to Emacs
  2014-03-17 20:23       ` João Távora
@ 2014-03-17 21:12         ` Danil Orlov
  0 siblings, 0 replies; 9+ messages in thread
From: Danil Orlov @ 2014-03-17 21:12 UTC (permalink / raw)
  To: João Távora; +Cc: emacs-devel

Can you explain me about snippet.el ?

I've found this one: http://www.emacswiki.org/emacs/SnippetMode 

But as far as I understand you, you working over some backend engine for yasnippet?

On Mon, Mar 17, 2014 at 08:23:58PM +0000, João Távora wrote:
> Stefan <monnier@iro.umontreal.ca> writes:
> 
> > snippet.el is not designed to be user-friendly, but to be easy to
> > integrate in a major-mode instead (yasnippet rather sucks in this
> > regard, you end up needing to distribute umpteen little files
> > instead).
> 
> Actually, you can compile these umpteen little files into one file per
> mode. See `yas-compile-directory'. Few use it AFAIK, but it's there and
> it should work (at least the tests show it does).
> 
> And that's because yasnippet already has an elisp interface to defining
> snippets, `yas-define-snippets'. There is definitely some suckage to it,
> otherwise I wouldn't be writing snippet.el, but users or distribtors
> aren't forced to deal with those million files.
> 
> > [ BTW, part of the intention behind snippet.el is to make Edebug work
> >   with them.  Si in some cases they may turn out to be more
> >   user-friendly, rather than less so.  ]
> 
> Indeed, I've answered many bugs from those who don't understand why
> snippets don't work as intended, and I don't blame them.
> 
> > As for "not so powerful", I'm not sure what you mean: they should be
> > pretty much as powerful as yasnippet's since yasnippet will be written
> > on top of them.  And of course, they can run any Lisp code you like.
> 
> Danil, snippet.el is in its core just as powerful as yasnippet. Just a
> few bits are missing like in-snippet expansions and snippet revival
> after undo, but I plan to (re)implement them all.
> 
> >> And they are all not manage keybindings.
> > This layer is not provided yet, indeed.  E.g. I want to link snippet.el with
> > abbrevs, so the "table of snippets" will be an abbrev table.
> 
> And I intend to keep the familiar yasnippet keying mechanism in
> yasnippet.el. In general yasnippet will keep most backward
> compatibility.
> 
> > more docs we could provide.  For snippet.el, it's still in flux and
> > there are indeed no docs yet, IIRC.
> 
> `define-snippet's docstring contains the gist of what that main entry
> point will be. It's quite heavy at 60 lines, so maybe parts of it belong
> to the manual, but it should give you an idea of what the defined
> snippets can do. Did you read this docstring, Danil?
> 
> 



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-03-17 21:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-17  4:10 Including Yasnippet to Emacs Danil Orlov
2014-03-17 14:45 ` Stefan
2014-03-17 14:53   ` joakim
2014-03-17 17:15   ` João Távora
2014-03-17 17:42   ` Danil Orlov
2014-03-17 19:36     ` Stefan
2014-03-17 20:23       ` João Távora
2014-03-17 21:12         ` Danil Orlov
2014-03-17 21:09       ` Danil Orlov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).