Topic: snippets.vdm - Code Snippets (1 of 11), Read 43 times
Conf: VEDIT Macro Library
From: Pauli Lindgren
Date: Tuesday, February 23, 2010 11:50 AM

I made a macro SNIPPETS.VDM that implements code snippets on Vedit.
You can download it from my web page:
http://koti.mbnet.fi/pkl/vedit/misc.htm#snippets

When you call snippets.vdm, a window opens at the right edge of the screen to show a list of snippets.
You can either double-click on the snippet name to execute it, or use cursor keys to select a snippet and then press Numpad-Enter. (I did not find a way to configure the main Enter key for this.)
The snippets list is then closed and the snippet is executed.

The snippets file is a normal macro file, but I have used the extension .snp.
Each snippet is a macro language routine that begins with a label and ends with Return command.
The label is the name of the snippet which is displayed in the snippets window.
In order to allow local subroutines, only those labels are displayed that fulfill the following requirements:
- The label must be at the beginning of line
- The first character must be a capital letter
- Both colons must be used

The snippets window can display additional text labels that can be used to group the snippets.
A comment at the beginning of line and beginning as //[ is displayed as group label.
Double-clicking on a group label has no effect. (Even if I have used [-], it is currently not possible to fold/unfold the groups.)

A snippet may just insert some text in the current document, or it may perform any macro language functions, or it may call an external macro. It is even possible to call snippets.vdm to switch to another snippets file.

Two snippet files are included in the zip file: example.snp and html.snp. By default, the macro uses example.snp. To use another .snp file, put the filename in T-Reg 40 and call the label "FILE_SET", for example:
RS(40, "|(USER_MACRO)\html.snp") Call_File(100,"snippets.vdm", "FILE_SET")

You can use different snippets commands in different user or tools menus for different projects. Since the User and Tools menus are saved with projects, you can have different snippets files e.g. for your HTML project and C project.

However, this macro is mainly for evaluation of the snippets functionality.
In order to be really useful, the snippets should be displayed in the sidebar, and there should be option to fold/unfold groups, and perhaps functions to interactively add snippets, rename, change the order etc.
I think it should not be too difficult to add this functionality to VEDIT.

--
Pauli

 


Topic: snippets.vdm - Code Snippets (2 of 11), Read 33 times
Conf: VEDIT Macro Library
From: Peter Rejto
Date: Thursday, February 25, 2010 12:31 PM

On 2/23/2010 11:50:40 AM, Pauli Lindgren wrote:
>I made a macro SNIPPETS.VDM

>example:
>RS(40,
>"|(USER_MACRO)\html.snp")
>Call_File(100,"snippets.vdm",
>"FILE_SET")
>


Thanks Pauli,

I have a hunch that I shall rewrite some of my .mnu files to .snp files. In other words, I shall end up with many, many .snp files.

Since my (USER_MACRO) directory is already crowded, I would like to put my .snp files into a sub directory. In other words, I would like to use
"|(USER_MACRO)\snippets\html.snp"
in place of your
"|(USER_MACRO)\html.snp"


I do hope that you will consider this minor adjustment to your macro.



Thanks gain,


-peter

 


Topic: snippets.vdm - Code Snippets (3 of 11), Read 32 times
Conf: VEDIT Macro Library
From: Pauli Lindgren
Date: Friday, February 26, 2010 11:56 AM

On 2/25/2010 12:31:11 PM, Peter Rejto wrote:
>
>Since my (USER_MACRO) directory is
>already crowded, I would like to put my
>.snp files into a sub directory. In
>other words, I would like to use
>"|(USER_MACRO)\snippets\html.snp"
>in place of your
> "|(USER_MACRO)\html.snp"
>
>
>I do hope that you will consider this
>minor adjustment to your macro.

You can put the .snp files anywhere you like.
Just give the path in text register 40 before calling the macro, as explained in my original post.
That works whether you call it from your User or Tools menu or from another .snp file.

For example:
RS(40, "|(USER_MACRO)\snippets\html.snp") Call_File(100,"snippets.vdm", "FILE_SET")

--
Pauli

 


Topic: snippets.vdm - Code Snippets (4 of 11), Read 36 times
Conf: VEDIT Macro Library
From: Peter Rejto
Date: Sunday, February 28, 2010 12:49 AM

On 2/23/2010 11:50:40 AM, Pauli Lindgren wrote:


>However, this macro is mainly
>for evaluation of the snippets
>functionality.
>In order to be really useful,
>the snippets should be
>displayed in the sidebar, and
>there should be option to
>fold/unfold groups, and
>perhaps functions to
>interactively add snippets,
>rename, change the order etc.
>I think it should not be too
>difficult to add this
>functionality to VEDIT.


Pauli,

I share your feelings about this issue.
In fact, I do hope that Ted will have a chance to supply this desired fold/unfold operation.

In the meantime, I would like to suggest a poor man's work aroundd for this issue:

Specifically, I have added a snippet to your Example.snp file. This is the snippet
:Load a new {Snippet} file:

My snippet displays the names of the various .snp files in my directory. It is modeled on the Vedit
{Misc,Load {User} menu .. }
menu command. Of course, I shall add this snippet to all of my future snp files.

May be a :Load a new {Snippet} menu file:
or may be a :Load a new {Snippet} menu ..: , would emphasize this similarity more ? What do you think ?

Do I understand it correctly: The .snp files are cousins of the .mnu files. In other words, Ted gave us the {Tool} and {User} menu files and Pauli gave us the {Snipet} menu files.
I would also emphasize the fact that the one line command line restrictions of the menu files has been removed from the {Snipet} menu files. Also, the tewntyitem per .mnu file has also been removed.


I also would like to add cosmetic comment: I have tried to run the various macros in your Example.snp file. I did not succeed, since I did not have your macros. However, I did succeed in downloading them from either your website or from the Vedit User Forum. The only exception was FindFile.vdm. I could not find it. In any case, the rest of your macros run like a charm.


Thanks again for showing the rest of us what is under the hood of a menu file.


-peter

 


Topic: snippets.vdm - Code Snippets (5 of 11), Read 38 times, 1 File Attachment
Conf: VEDIT Macro Library
From: Peter Rejto
Date: Sunday, February 28, 2010 12:51 AM

Oops, here is the upload.

-peter

 
Edited version of Example.snp

 


Topic: snippets.vdm - Code Snippets (6 of 11), Read 41 times
Conf: VEDIT Macro Library
From: Pauli Lindgren
Date: Monday, March 01, 2010 07:36 AM

On 2/28/2010 12:49:45 AM, Peter Rejto wrote:
>
>May be a :Load a new {Snippet} menu
>file:
>or may be a :Load a new {Snippet} menu
>..: , would emphasize this similarity
>more ? What do you think ?

Actually they are not that similar.
When you load User or Tools menu, it stays in memory until you close Vedit (or even longer if you have a project open).
Snippets file, however, only stays in memory during the macro execution. (It is not in the memory even while the snippets list is open). So, you are not loading the file, you are just using it once.

If you want to choose among multiple snippets files, using File Open dialog may not be the most handy method. Instead, you could list the files in your "master" .snp file the same way as html.snp is listed in example.snp.

But my original idea was to have just one snippets file in use in each project. There is no limit in how many snippets you can have in each file.

>
>The only exception was FindFile.vdm. I
>could not find it. In any case, the rest
>of your macros run like a charm.

FindFile.vdm is a kind of front-end to Wildfilew.vdm, for finding files on disk. It is quite handy, actually. But I have not published it yet since I have been waiting for a version of Vedit with wildfilew.vdm to be released.

--
Pauli

 


Topic: snippets.vdm - Code Snippets (10 of 11), Read 15 times
Conf: VEDIT Macro Library
From: Peter Rejto
Date: Sunday, April 03, 2011 11:56 PM

On 2/28/2010 12:49:45 AM, Peter Rejto wrote:
>On 2/23/2010 11:50:40 AM, Pauli Lindgren
>wrote:
>
>
>>However, this macro is mainly
>>for evaluation of the snippets
>>functionality.
>>In order to be really useful,
>>the snippets should be
>>displayed in the sidebar, and
>>there should be option to
>>fold/unfold groups, and
>>perhaps functions to
>>interactively add snippets,
>>rename, change the order etc.
>>I think it should not be too
>>difficult to add this
>>functionality to VEDIT.
>
>
>Pauli,
>
>I share your feelings about this issue.
>In fact, I do hope that Ted will have a
>chance to supply this desired
>fold/unfold operation.
>

Pauli,

I am re reading your message. Now that the smoke has cleared from Vedit 6.20, I think this would be a good time to ask Ted to supply your "fold/unfold operation".

Incidentally, on our moodle website I am using quite a bit
this "fold/unfold operation". Well, I do not have to go to moodle for this. I have used this "fold/unfold operation" on the left pane of this forum quite a bit. That is to say on webboard.vedit.com .



-peter

 


Topic: snippets.vdm - Code Snippets (11 of 11), Read 13 times
Conf: VEDIT Macro Library
From: Pauli Lindgren
Date: Thursday, April 21, 2011 03:16 AM

On 4/3/2011 11:56:12 PM, peter rejto wrote:
>
>I am re reading your message. Now that
>the smoke has cleared from Vedit 6.20, I
>think this would be a good time to ask
>Ted to supply your "fold/unfold
>operation".
>
>Incidentally, on our moodle website I am
>using quite a bit
>this "fold/unfold operation". Well, I do
>not have to go to moodle for this. I
>have used this "fold/unfold operation"
>on the left pane of this forum quite a
>bit. That is to say on
>webboard.vedit.com .

There is already "fold/unfold operation" in Vedit File Selector panel: at Proj tab (and of course Xplor tab, but that is a Windows component, if I am not mistaken).

However, the main point is not the fold/unfold operation, but the suggestion that snippets would be implemented in Vedit.

The snippets should be in File Selector panel so that they would be always visible. Vedit could then have build-in functionality for adding new snippets to the list, organizing the list etc. The snippet list would be automatically loaded with a project, so that for example in html project you would have html-related snippets listed and in a C project you would have C related snippets.

Perhaps the most flexible way would be to allow macro language to add new tabs to File Selector panel. In addition, it would be nice to have other panels, too (at right and bottom edges of screen).

--
Pauli

 


Topic: snippets.vdm - Code Snippets (7 of 11), Read 23 times
Conf: VEDIT Macro Library
From: Pauli Lindgren
Date: Monday, May 10, 2010 11:40 AM

Hi,

I have made a new version of the snippets.vdm macro.
There was a kind of bug. After calling other macros from the snippets file, the text register was not always emptied.

This was caused by the strange behavior I have noticed earlier with user and tools menus, too.
If you call a macro like this:
  #116=Reg_Free Call_File(#116,"some.vdm") Reg_Empty(#116)
the contents of the register #116 may have changed even if the macro did not use that register.

I changed the double-click event macro so that it does not rely on a numeric register.

Another change is that the default name for snippets file is now default.snp (instead of example.snp).
The files default.snp and html.snp have been updated, too, with some new snippets.

P.S.
If you have download the previous version of search116.vdm (v2.5) from my web page, please download the updated version (v2.6).
There was a hazard character added in the code of v2.5 that caused an error.

--
Pauli

 


Topic: snippets.vdm - Code Snippets (8 of 11), Read 23 times
Conf: VEDIT Macro Library
From: Peter Rejto
Date: Sunday, January 09, 2011 05:18 PM

On 5/10/2010 11:40:35 AM, Pauli Lindgren wrote:
>Hi,
>
>I have made a new version of
>the snippets.vdm macro.
>There was a kind of bug. After
>calling other macros from the
>snippets file, the text
>register was not always
>emptied.
>
>This was caused by the strange
>behavior I have noticed
>earlier with user and tools
>menus, too.
>If you call a macro like this:
>#116=Reg_Free
>Call_File(#116,"some.vdm")
>Reg_Empty(#116)the contents of
>the register #116 may have
>changed even if the macro did
>not use that register.
>
>I changed the double-click
>event macro so that it does
>not rely on a numeric
>register.
>
>Another change is that the
>default name for snippets file
>is now default.snp (instead of
>example.snp).
>The files default.snp and
>html.snp have been updated,
>too, with some new snippets.
>
>P.S.
>If you have download the
>previous version of
>search116.vdm (v2.5) from my
>web page, please download the
>updated version (v2.6).
>There was a hazard character
>added in the code of v2.5 that
>caused an error.

Pauli,


I would like to add a footnote to your snippet.vdm macro.

Specifically, I ended up with several .snp files.
When I was double clicking on any of them I got an error message.


Then I realized that this error message was due to the fact that Windows associated the .snp files with the program snapshot.

So, I went into {Windows Explorer, Tools, Folder Options, File Types }

and changed the File Type of the .snp Extension to Vedit.

Now, double clicking on an .snp file, windows opens up the file in Vedit. So, in this respect, Windows treats .snp the same way as it treats .vdm files.


Well, I started out with a footnote. Now I have a real question:

Could you automate this association procedure ?
In other words, if I have a snippet.vmd file in my
USER_MACRO directory, then I would like to associate the .snp files with Vedit.


Thanks as always.

-peter

 


Topic: snippets.vdm - Code Snippets (9 of 11), Read 17 times
Conf: VEDIT Macro Library
From: Peter Rejto
Date: Tuesday, January 11, 2011 02:24 PM

On 1/9/2011 5:18:57 PM, peter rejto wrote:
>On 5/10/2010 11:40:35 AM, Pauli Lindgren
>wrote:
>>Hi,
>>
>>I have made a new version of
>>the snippets.vdm macro.
>>There was a kind of bug. After
>>calling other macros from the
>>snippets file, the text
>>register was not always
>>emptied.
>>
>>This was caused by the strange
>>behavior I have noticed
>>earlier with user and tools
>>menus, too.
>>If you call a macro like this:
>>#116=Reg_Free
>>Call_File(#116,"some.vdm")
>>Reg_Empty(#116)the contents of
>>the register #116 may have
>>changed even if the macro did
>>not use that register.
>>
>>I changed the double-click
>>event macro so that it does
>>not rely on a numeric
>>register.
>>
>>Another change is that the
>>default name for snippets file
>>is now default.snp (instead of
>>example.snp).
>>The files default.snp and
>>html.snp have been updated,
>>too, with some new snippets.
>>
>>P.S.
>>If you have download the
>>previous version of
>>search116.vdm (v2.5) from my
>>web page, please download the
>>updated version (v2.6).
>>There was a hazard character
>>added in the code of v2.5 that
>>caused an error.
>
>Pauli,
>
>
>I would like to add a footnote to your
>snippet.vdm macro.
>
>Specifically, I ended up with several
>.snp files.
>When I was double clicking on any of
>them I got an error message.
>
>
>Then I realized that this error message
>was due to the fact that Windows
>associated the .snp files with the
>program snapshot.
>
>So, I went into {Windows Explorer,
>Tools, Folder Options, File Types }
>
>and changed the File Type of the .snp
>Extension to Vedit.
>
>Now, double clicking on an .snp file,
>windows opens up the file in Vedit. So,
>in this respect, Windows treats .snp the
>same way as it treats .vdm files.
>
>
>Well, I started out with a footnote. Now
>I have a real question:
>
>Could you automate this association
>procedure ?
>In other words, if I have a snippet.vmd
>file in my
>USER_MACRO directory, then I would like
>to associate the .snp files with Vedit.
>
>
>Thanks as always.
>
>-peter


Pauli,


I know that you are busy and I have, essentially, the answer to my question.

So, there is no need for you to answer it.
(In short I noticed that I can use the Vedit registry.vdm macro.)


Thanks as always,

-peter,