LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Smart snippets in emacs (https://www.linuxquestions.org/questions/linux-software-2/smart-snippets-in-emacs-328331/)

Sune Simonsen 05-29-2005 04:08 PM

Smart snippets in emacs
 
Is there a minor mode for emacs, that makes the same behavior available, as smart code snippets in TextMate? (macromates.com I'm new here so I can't make it clickable, eclipse also has this functionality. If not is it possible to program?.

Example of a snippet:
Code:

Iterator ${2:iter} = ${1:list}.iterator();
while (${2:iter}.hasNext()){
  ${3:type} ${element} = (${3:type})${2:iter}.next();
  $5
}

When you insert the snippet you presented with:
Code:

Iterator iter = list.iterator();
while (iter.hasNext()){
  type element = (type)iter.next();
 
}

You can then jump from field to field, and if you change one field, all the
fields with the same name will change at the same time.

I'm not looking for a mode what prompt me for every variable in the snippet, it has to be unobtrusive.
The TextMate editor is really nice, but its not cross platform, and i like using the same editor everywhere.

- Sune Simonsen

Tinkster 05-29-2005 04:22 PM

I don't know TextMate, but ELSE may do what you're looking
for ... if you find it too interactive you can easily tame it by
editing its underlying lse files.

http://www.zipworld.com.au/~peterm/

Cheers,
Tink

foo_bar_foo 05-29-2005 04:31 PM

emacs can do macro commands if that's what you are talking about ?
recorded keystrokes you can easily play over and over ?

Cntrl-x (
type macro
Cntrl-x )

then Cntrl-x e to play the macro

then you can do stuff with it like Esc 6 Cntrl-x e
Cntrl-u Cntrl-x e

and like that

macros can start with any commands or keystrokes like searches or whatever

if you want to save the macro to make it permanent
Esc x name-last-kbd-macro RETURN
give it a name RETURN
from now on your commend is ESC x mancroname

open .emacs and move to it bottom and type ESC x insert-kbd-macro RETURN macroname RETURN
save

this can get very complicated your macros can have pauses and stuff take a look at an emacs manual for more

Sune Simonsen 05-29-2005 04:35 PM

If you have tried ELSE, I would really like you to comment on how it's working.
I seen the website before, but i was a little skeptical about it, because it looked
rather complicated, or say ambitious.

- Sune Simonsen

rose_bud4201 05-29-2005 04:36 PM

Technically, you can tame emacs to do just about anything under the sun if you really want to spend the time to code it. For example, you probably could create a list of things you type a lot, override the 'tab' button to search through that list, looking for the first three or so characters which match the characters that you just typed in the current buffer, and then Insert whatever text is at that matching element of the list. However, that would be pretty static. I'm not entirely sure how hard it would be to make it learn...but it would probably be really tricky, probably messy and inefficient, and would involve reading/writing to some sort of save file each time you open/close a buffer with whatever type of code you're writing if you wanted the snippets to be at all persistent.

Folding, which I also saw touted on the TextMate webpage, is something that emacs ain't so good with. It'll p'bly do it, but it's not quite as nice as it is in say, Vim.

So the short answer is Yes, you could certainly program emacs to do that, if you wanted to spend a lot of time learning the Emacs brand of Lisp. Emacs is a great editor and does some really nifty stuff - you never ever need to touch the mouse once you've opened it, it's fantastic - but it isn't and probably won't ever be an IDE. That's just not what it's supposed to be :-/

(And to create a link, click the "http://" button when you create a post/reply, or use [url="http://www.stuff.com"][/url] tags).

Sune Simonsen 05-29-2005 04:40 PM

Yep macros is nice, but not quite what I was looking for.
I know I didn't explained my self very well at first, but i updated the
question, so it should be clearer was I'm looking for now.

By the way thanks for the answers, the answers came faster than I expected.

- Sune Simonsen

Sune Simonsen 05-29-2005 04:51 PM

rose_bud4201 thank for the answer.
I don't want to make emacs a IDE, what I'm talking about is not that
code sensitive, it's just abbreviation on druks, and it's really useful.
If you go outside the the snippet, it losses it's information. So emacs "only"
has to keep track of the positions of the variables in the current snippet.
The snippets will be created in the .emacs file or in the hook for different
major modes.
I think you are right, of cause i can be done.

(I know about how you make a URL, but they restricted the system, so you can't
before you have made 5 posts, to prevent spamming)

- Sune Simonsen

Tinkster 05-29-2005 05:08 PM

Quote:

Originally posted by Sune Simonsen
If you have tried ELSE, I would really like you to comment on how it's working.
I seen the website before, but i was a little skeptical about it, because it looked
rather complicated, or say ambitious.

- Sune Simonsen

I actually quite like it, even though the C++ definitions
are a bit lacking ... it makes C code a breeze, but it's
most suitable for writing a new program.

Haven't looked at the other lingos, and don't do much coding
these days. In terms of completeness the ADA stuff should
be the best since Peter actually codes in ADA.


Cheers,
Tink

Sune Simonsen 05-29-2005 05:34 PM

I've installed ELSE, but i think it's is a little weird,
but I will definitely give it a change. I think TextMate
and eclipse way is more intuitive, but i might be harder to
program.

- Sune Simonsen

Sune Simonsen 10-26-2005 05:15 PM

I've have implemented this feature in jedit, if anybody is interrested in trying it. You can download it from det plugin manager under the name SuperAbbrevs.

-- Sune Simonsen


All times are GMT -5. The time now is 05:24 AM.