Coder Social home page Coder Social logo

Suggestions about yasnippet HOT 21 CLOSED

joaotavora avatar joaotavora commented on August 15, 2024
Suggestions

from yasnippet.

Comments (21)

joaotavora avatar joaotavora commented on August 15, 2024
  1. Really? Works fine for me. If you don't put a newline at the end of the file (for
    the snippet), it won't get inserted:

if (${condition})\n
^^^ If there's no such newline

Please check there's any hook that automatically insert a newline at the end of the
buffer when you save the file. You can try to move the cursor to the end of the file
after save it to see whether there's a newline added. I found the other day that Vim
will add a newline by default. But I'm not a Vim expert, don't know how to disable
it. And in Emacs in some mode there's hook to do this. I'm editing this in
fundamental-mode, it works fine.

  1. Sorry to say that might be impossible. The popup menu belongs to the host GUI
    widgets. Emacs often have no or litter control over them. Even the conventional
    keybinding like C-n C-p won't works in those widgets.

  2. Same as 1)

  3. Also fine for me. I tried Emacs 23 and 22. Everything is OK. Maybe there's a hook
    that clear empty lines automatically for you? Have you tried it in "emacs -q" or will
    you give me the exactly steps to reproduce this?

Google Code Info:
Author: [email protected]
Created On: 2008-03-08T01:39:44.000Z

from yasnippet.

joaotavora avatar joaotavora commented on August 15, 2024

It's seems to be very important that you restart Emacs after changing in your snippet
files. Now 1 and 3 works just fine...

About number 4. I have now tried with a clean .emacs file and it's the same. I have
tried it in both ruby-mode and java-mode. I can solve this in another way but I guess
you want to solve it so why don't you tell me what you need from me and I'll provide it.

Google Code Info:
Author: [email protected]
Created On: 2008-03-08T07:12:05.000Z

from yasnippet.

joaotavora avatar joaotavora commented on August 15, 2024

OK. I have no idea now. :( Maybe you can follow the steps and see if it works for you:

  1. download the bundle file from
    http://yasnippet.googlecode.com/files/yasnippet-bundle-0.1.1.el.tgz
  2. open a new Emacs through "emacs -q"
  3. tar xzf the bundle file
  4. drag the unpacked .el file to emacs
  5. M-x eval-buffer
  6. go to some buffer like scratch
  7. select from the menu-bar a snippet
  8. see if it works?

Google Code Info:
Author: [email protected]
Created On: 2008-03-08T08:32:10.000Z

from yasnippet.

joaotavora avatar joaotavora commented on August 15, 2024

Didn't work either... But I can fix this by putting the correct indentation in the
snippet files.

Thanks!

Google Code Info:
Author: [email protected]
Created On: 2008-03-08T08:44:57.000Z

from yasnippet.

joaotavora avatar joaotavora commented on August 15, 2024

What a pity. But I'm also interested in how do you solve it. What do you mean by
"putting the correct indentation in the snippet files"? You mean it works when
defined from a file, but don't work when use (yas/define ...) ?

Google Code Info:
Author: [email protected]
Created On: 2008-03-08T09:25:19.000Z

from yasnippet.

joaotavora avatar joaotavora commented on August 15, 2024

I use spaces instead of tabs: (setq-default indent-tabs-mode nil)
And the number of spaces when I do a tab is 2. So instead of do a tab in the snippet
definition I do two spaces.

Google Code Info:
Author: [email protected]
Created On: 2008-03-08T13:03:17.000Z

from yasnippet.

joaotavora avatar joaotavora commented on August 15, 2024

I also discovered a problem when defining some snippets for Java.

Can you first of all confirm that this snippet definition is correct:
#name : while(condition) {...}

--

${1:count} = ${2:0};
while($1 ${3:<} ${4:var})
{
$0
$1++
}

If it is. Then I have a problem with it.

If I expand this I will get the following, where a word in (word) are a changeable "green" word: count=0; while(count < var`)
{

count++
}

It cycles through all green areas correct. But if I try to change "count" to
something else it will only put that word before "count" (on all places where count
is). So if I where to change the name "count" to "temp" I would get this:
tempcount = 0;
while(tempcount < var)
{

tempcount++
}

Note that this is only for "count". For example does "var" work just fine!

Google Code Info:
Author: [email protected]
Created On: 2008-03-08T13:43:51.000Z

from yasnippet.

joaotavora avatar joaotavora commented on August 15, 2024

About the post above. I have noticed that it's only the first time this happens. If I
do the while above right after I have start Emacs it will behave like I described
above. But if I use another snippet before I use the while snippet, the while snippet
will work after that... And the while snippet seems to be the only snippet that does
this... For
example does this snippet work right after Emacs starts (which has pretty much same
snippet
features as the while one):
#name : for

--

for(int ${1:i} = ${2:0}; $1 ${3:<} ${4:variable}.length; $1${5:++})
{
$0
}

Weird...

Google Code Info:
Author: [email protected]
Created On: 2008-03-08T15:03:44.000Z

from yasnippet.

joaotavora avatar joaotavora commented on August 15, 2024

Hi again... There seems to be many differences between your Emacs version and mine. I
found a new bug now.

For example it appears when I use this snippet:
#name : class without constructor

--

/**

*/
public class ${1:Name}
{
$0
}

If expand this I will get this (where a word in (word`) is a
changeable "green" word):
/**

*/
public class Name
{

}

And then when I try to change the name of the class and then press TAB this happens:
/**

*/
public class ClassName
{

}
Note that the "C" still "green". And the cursor does not move to the next snippet
field if I press TAB. It will stay after "ClassName". So the snippet is stuck and I
have to trix a bit to restore it to be as usual. When the cursor is stuck and I press
TAB I get this message in the Messages buffer:
Not in a snippet field.

I have tried this with emacs -q and it's the same.

Google Code Info:
Author: [email protected]
Created On: 2008-03-08T15:23:16.000Z

from yasnippet.

joaotavora avatar joaotavora commented on August 15, 2024

Still no idea... :(
For the "while" problem, I tried it my self. No problem.

For the "class" problem. There's also another person report this bug. But I can't
reproduce it. I tried Emacs 21, 22 and 23. All works. Don't know what's the problem... :(

Google Code Info:
Author: [email protected]
Created On: 2008-03-10T04:00:51.000Z

from yasnippet.

joaotavora avatar joaotavora commented on August 15, 2024

OK. Find all problems now. They only occur in Emacs 22 under Linux. I think that a
bug of Emacs -- Emacs 23 under Linux works fine. However, I changed my implementation
to solve the problem with "class". You can download the new version (0.2.0, also
there's a big change in the snippets directory hierarchy -- good change to let
snippets to be shared between modes, but still compatible with old version) and try it.

With the "while" problem. I find it only happens when:

  1. at the beginning of buffer
  2. The first character of the snippet is a field

This is not a common scenario and to make changes to the implementation is just
costly -- it make the code rather complex. So I decide not to "fix" this. In fact,
this is fixed in newer version of Emacs. Hope Emacs will release a newer version soon.

Google Code Info:
Author: [email protected]
Created On: 2008-03-10T14:04:38.000Z

from yasnippet.

joaotavora avatar joaotavora commented on August 15, 2024

Well done, I'm really happy about how it works now!

Thanks a lot for fixing the problems so soon!

Google Code Info:
Author: [email protected]
Created On: 2008-03-10T19:03:15.000Z

from yasnippet.

joaotavora avatar joaotavora commented on August 15, 2024

Just thought of a feature enhancement when I made some snippet for css-mode.

Say that you want to specify a snippet for "color". Then you'd probably do something
like this:
#name : color

--

color: $1;

But say you often do this and want a quick way to different colors. With the current
version of yasnippet you would probably create different files for each color:
color.red, color.blue, color.green, etc... But wouldn't it in this case be better to
have some kind of "autocompletion" for this, without a menu (kind of like ido-mode).
So instead of many files you should do the color snippet something like this:
#name : color

--

color: ${1:[red,blue,green]};

I'm not saying that I don't like that you can specify different snippet through
filenames. But... This I only want to do when it's a different "option", and the
completion thing for different values for the same option. So for css's "margin" the
yasnippet "file-feature" is be perfect. With that I mean one file for each margin
(which I consider a different option): margin, margin-left, margin-right, margin-top
and margin-bottom.

So basicly you should think of an option and a value as two differnent things.

To give one more example for another language where this would have been great is for
Java's List.
Say you want one snippet for ArrayList and one for LinkedList. Then you would create
two different files. One for each type: list.array and list.linked
But also say that you want a quickway of specifying the different types these lists
can take. As yasnippet looks now you would have to create many files for this:
list.array_string, list.array_integer, list.array_e, etc... This becomes a lot
repeation of the same thing. How you would want to solve this is like this:
#name : ArrayList

--

List<${1:[String,Integer,E,Object]}> ${2:var} = new ArrayList<$1>();

So one file for every type of List and in every of these files you specify the types
you want.

What do you think about this?

Google Code Info:
Author: [email protected]
Created On: 2008-03-10T21:37:09.000Z

from yasnippet.

joaotavora avatar joaotavora commented on August 15, 2024

Sounds a good idea. msf-abbrev has similar feature. Maybe I could consider it in the
next major version. :)

Google Code Info:
Author: [email protected]
Created On: 2008-03-11T04:04:37.000Z

from yasnippet.

joaotavora avatar joaotavora commented on August 15, 2024

Hello, I have some suggestions too. Most of them are copying TextMate's
implementation of snippets:

  1. Allow snippets to have an "understanding" of their surroundings. The basic example
    are python methods/functions. When you expand a def inside a class, it should have
    "self" as the first argument, whereas if you expand a def outside a class, it
    shouldn't. This could be possible now with some custom elisp code, I'll look into it.

  2. Another Python thing. Consider the following:

class ${1:cname}(${2:object}):
"docstring for $1"
def init(self, ${3:arg}):
self.$3 = $3
$0

In TextMate, if you add a comma in ${3:arg}, it will actually add a "self.$4 = $4"
(specifically the behaviour of it) underneath the first one and mirror it. So,
basically, you can define the arguments and initialize a whole class in one step.

This probably is a big one.

Google Code Info:
Author: orestis
Created On: 2008-03-11T15:34:59.000Z

from yasnippet.

joaotavora avatar joaotavora commented on August 15, 2024

For 1) this might be interesting -- do you know smart-snippet ? It just has a
condition attached to each snippet. The snippet expands only if and only if the
condition meets. Basically I can add similar support in yasnippet. But the difficult
here is that those modes for each file type in Emacs is not uniformed developed. The
condition is just difficult to specify except for a Emacs geek. You can use sth. like
c-in-method-def-p' in c-mode, but in python-mode, you should need to use another function (or even write one yourself). That's why many people just set the condition for every snippet in smart-snippet tot'.

However, this might be an optional feature. I'll add a new issue. Maybe consider it
later.

  1. This is really a big change: to create a field on the fly. I don't have Textmate
    myself, so I can only try my best to guess its behavior from the document. I didn't
    heard this before, so the design and implementation just didn't consider this
    feature. And I'm interested in the Textmate's behavior: Is is treat comma specially
    here? What if I want to just type a comma in this field instead of add a new field?

Google Code Info:
Author: [email protected]
Created On: 2008-03-11T15:59:20.000Z

from yasnippet.

joaotavora avatar joaotavora commented on August 15, 2024

The actual snippet from TextMate is this:

content class ${1:ClassName}(${2:object}): ${3/.+/"""/}${3:docstring for $1}${3/.+/"""\n/}${3/.+/\t/}def **init**(self${4/([^,])?(._)/(?1:, )/}${4:arg}): ${5:super($1, self).**init**()} ${4/(\A\s_,\s_\Z)|,?\s_([A-Za-z_][a-zA-Z0-9_]_)\s_(=[^,]_)?(,\s_|$)/(?2:\t\tself.$2 = $2\n)/g} $0 name New Class scope source.python tabTrigger class uuid 659D189C-EC3E-4C4E-9377-B7F5F5216CBD

from
http://macromates.com/svn/Bundles/trunk/Bundles/Python.tmbundle/Snippets/New%20Class.tmSnippet

It seems to do a complicated regexp to determine what happens, I can't decipher it
from a first pass...

Google Code Info:
Author: orestis
Created On: 2008-03-12T14:11:10.000Z

from yasnippet.

joaotavora avatar joaotavora commented on August 15, 2024

me too... Too complicated...

Google Code Info:
Author: [email protected]
Created On: 2008-03-13T03:01:43.000Z

from yasnippet.

joaotavora avatar joaotavora commented on August 15, 2024

Here's how I immitated python's classsnippets:
two tab is hard-coded for my setting. It would be good if current indentation is available as a variable like
text. Of course, removing *=.* should be removed when formatting. Anyway, it works:p

#name : aa ....

--

class fff:
def init(self, ${1:args}):
${1:$(mapconcat #'identity (loop for a in (split-string text ", *" t) collect (format "self.%s = %s" a a))
"\n\t\t")}

Google Code Info:
Author: [email protected]
Created On: 2008-03-20T06:12:13.000Z

from yasnippet.

joaotavora avatar joaotavora commented on August 15, 2024

I thought I've replied? -.-? I forgot? Hmm, is it possible to use (current-column) ?

Google Code Info:
Author: [email protected]
Created On: 2008-03-21T12:12:39.000Z

from yasnippet.

joaotavora avatar joaotavora commented on August 15, 2024

(current-column) works fine for python-mode, except it is a bit verbose.

Google Code Info:
Author: [email protected]
Created On: 2008-05-07T01:50:09.000Z

from yasnippet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.