Scripts/Templates/Snippets

Scripts/Templates/Snippets

9
NewbieNewbie
9

    Mar 10, 2010#1

    I know this has been brought up in times past, but I am just wondering how others are dealing with the apparent lack of snippet support.

    Personally, I have gone through and converted my snippets from PrimalScript into US's Template List and have the tab visible on the side of my editor. My issue is that I have more than 50 I wish to use.

    Would it be better to parse out the snippets from the Template file and convert them to Scripts? Since there is apparently no limit in the number of scripts you can have. How would I code it so the script placed the text at the cursor only in the current file, rather than all files?

    Also, is this how people are generally working around getting snippet support, even though it is not explicitly supported in name?

    6,675585
    Grand MasterGrand Master
    6,675585

      Mar 10, 2010#2

      I'm really wondering that you need more than 50 templates. Do you really have 50 multi-line templates?

      You know that you can also use a customized tag group and use the tag list view. Tags can be also defined for multiple lines. The only problem with multiple lines tags is that the current indentation level is not taken into account when inserting the multi-line tags. The tag support includes also inserting a tag left and right an existing selection like needed for HTML, XHTML and XML. When I write UE scripts I use always the tag list view and the tag group "UE/UES Script Commands" because that avoids making mistakes when writing the code. When I write macro code I mainly use the auto-completion + auto-correction feature because the commands are short and I can quickly enter them. Only for complex commands like the sorting commands or FindInFiles, ReplInFiles I use the tag group "UE/UES Macro Commands". HTML entities are either automatically inserted using small macros stored in an automatically loaded macro file on startup of UE when pressing the key (like German umlauts) or I use the tag group for HTML characters. The small macros inserting common German ANSI characters work file extension based. User-submitted tag list files are available on the tag and autocomplete files page.

      For single line snippets which must be just inserted it is much better to use an auto-completion file and use the auto-complete feature. It is possible to associate different auto-completion files to different file extensions. One auto-completion file for HTML files, another for CSS files, the third for Java files, etc. Typical usage for auto-completion is inserting certain and often needed styles in HTML files. There are user-submitted auto-completion files available also on the tag and autocomplete files page, but most of them can be only used as template for creating an auto-completion file containing the strings you really often need to insert into your files. That's the reason why I have not yet written pulic auto-completion files for HTML and CSS files. There are some many combinations of tags, attributes and styles possible that I think, an auto-completion file containing all possible combinations would be no real help for quick inserting the most often needed strings.

      Some users have written a single script which inserts on execution snippets based on the existing characters left the cursor position. Those scripts are more or less a customized auto-completion with the advantage of being able to auto-complete multi-line strings with taking current indentation level into account when the script code is smart enough. So instead of creating dozens of small scripts you could also write 1 smart script. A script allows you also total control over cursor position after inserting the text.

      9
      NewbieNewbie
      9

        Mar 10, 2010#3

        I have over 100 snippets I use on a regular basis. Any code that is reusable with only slight changes finds its way into my snippet directory. When it covers more than 4 different languages, that is not so many per language.

        From database connection strings and methods for VB/VBS/ASP/PHP to getting the logged on user on a machine to a nicely formatted Uptime for a windows box. They are things I use all the time, and with snippets, I can just point to the right one and insert it in the code with a click of the mouse, rather than searching through older scripts to copy/paste the code.

        Rarely are these single-line bits of code. either full functions/subs or a set of "set" commands.

        I was really looking to see if anyone else was trying to do like me, and convert the templates to scripts. I only just started to look into the script feature of UE, and have so far only used it to set up my headers for the various scripts I write for work.

        2362
        MasterMaster
        2362

          Mar 10, 2010#4

          I generally don't have so many snippets to use. If I find a piece of code reusable on a regular basis, I convert it to a function that I can call with parameters to customize it more to the current application. I make it part of my function library and include the file that contains the function in my project. Problem solved. I don't have to insert code, I just call the function after including the file. Much easier way to handle it.

          Of course, I suppose that would depend on your language, but my method has worked well for me so far from everything from PHP to Javascript, C++, Delphi, and a few other languages. As I don't use VB or ASP I can't speak for those. I suppose this is why I'm not one who complains a lot about snippets. Those or for people who reuse actual code. Code reuse, to me, should be contained in functions or included files, not inserted a 1000 times into 1000 different programs. If the code ever needed to be updated, this would make it problematic to do so. It's just not good coding practice, and is generally used by people who haven't had extensive formal training.

          Templates and tags, however, can be extremely useful. Templates can help you set up the format of a new file (the way I use them) and the tags can insert often used functions/tags in your code to make coding faster. But to insert entire segments of code? Best to find a better way to access a library of code. That way of using snippets is just not good coding.

          I know the attacks are probably coming at me on this one, but I'll stand by my statement. I for one am glad UE helps to promote the better coding practices.
          “Don’t document the problem, fix it.” – Atli Björgvin Oddsson

          1
          NewbieNewbie
          1

            Nov 17, 2010#5

            Regardless of how many Snippets UE holds, I wish they were more organized than simply an unsorted list of 50 text slots.

            As developers, what snippet library are most of you using? I need to manage my numerous snippets better.

            7
            NewbieNewbie
            7

              Jan 19, 2011#6

              I love UltraEdit. I use from a long time ago.
              But I have seen best snippets than the rather poor template implementation for an editor that it's giving a solution for developers.
              What I'm talking about? You can see textmate or e-texteditor. They are very simple with not so many options like Ultraedit has. But both of them are grate at two very useful things. Snippets and search and replace and things like that.

              This message has no other purpose than try to see that kind of evolution with Ultraedit. But for now, I will gave a try to e-texteditor.

              Thank's

              18
              Basic UserBasic User
              18

                Jun 22, 2011#7

                Mofi wrote:I'm really wondering that you need more than 50 templates. Do you really have 50 multi-line templates?
                I actually agree with deckyon... presently I have 66 and the number is growing. Since my first post on this board, and my "conversion" to using UE for around 95% all TEXT editing. Although I don't have all 66 showing, I do use about 42 I use on a fairly regular basis. A few of them use the INCLUDE ability to pull in others automatically and run them.

                In the other 5%, I use TEXTPAD because a few of it's features isn't in UE. I converted to UE from TEXTPAD because of the ease of creating scripts. TEXTPAD if you record a macro, since it is stored in binary format, you have to re-record it.

                I know this is a user-to-user board, but one feature I wish UE had was the AUTOMATIC conversion of tabs to spaces. For instance if I paste text into textpad with spaces, I can tell TEXTPAD to auto convert tabs to spaces, without having to use a script or selecting it off the menu. However, to get around that, I have a script open on the list, on the right that is called "tabs_to_spaces". I just paste the text, then double click on it. But in TEXTPAD, you paste it, and if you have it configured, it will auto take the tabs and make them spaces (1 tab = 4 spaces in my case).

                5
                NewbieNewbie
                5

                  Jul 08, 2011#8

                  Having always used templates, I hadn't thought about scripts before today (or javascript for that matter). But I was wanting an easy way to insert chunks of SAS code/procs that I use constantly. So for instance, to insert "Proc export" w/ the defaults that I use 90% of the time I tried something (ugly) but functional.

                  Code: Select all

                  //PROC EXPORT alt ^X
                  var nameoffile = UltraEdit.activeDocument.path;
                  var DocName =(nameoffile.substring(nameoffile.lastIndexOf("\\")+1,nameoffile.lastIndexOf("\.")));
                  var proc = "PROC EXPORT DATA=";
                  var linefeed = " \r\n";
                  var line1 = proc+DocName+linefeed;
                  var line2 = "    OUTFILE='"+DocName+".XLS' \r\n"
                  
                  UltraEdit.activeDocument.write(line1);
                  UltraEdit.activeDocument.write(line2);
                  UltraEdit.activeDocument.write("    DBMS=excel REPLACE; \r\n")  
                  UltraEdit.activeDocument.write("    run;") 
                  
                  //PROC EXPORT DATA=export 
                  //    OUTFILE='export.XLS' 
                  //    DBMS=excel REPLACE; 
                  //    run;
                  I've used UltraEdit forever, but relatively little of its more powerful features. But before reinventing the SAS snippet wheel I was wondering if
                  1. someone has done all this already
                  2. Is there any advantage to doing this SAS proc prefabrication w/ scripts over templates?
                  3. Isn't there something like var nameoffile = UltraEdit.activeDocument.Filename; that would return the filename without extension without going through the substringing/indexing of the full path? I'm sure I simply didn't find the default js variablename that would return that automatically.

                  6,675585
                  Grand MasterGrand Master
                  6,675585

                    Jul 09, 2011#9

                    1. I'm not a SAS programmer and therefore can't answer that question.
                    2. Executing scripts can be done from the Scripting menu, from the Script List, or by hotkey or chord. Same possibilities exist for inserting a string by template.

                      The command to insert a template string can be also added to a customized toolbar. But there is yet no command to execute a script from a customized toolbar in UE v17.10.0.1010. As long as you don't want to insert the template strings by clicking on a symbol in a toolbar, this difference does not matter.

                      Inserting template strings can be also done from within macros and scripts. You can't call a script from within a macro. Just including a script in another script is possible. But if you insert template strings always manually and never by macros that difference also does not matter.

                      The next difference is the number of undo records/steps. The insert template command produces always exactly 1 undo record. Your script as is results in 4 undo records. Of course you could concatenate all 4 strings to a single string and use only 1 write command to get only one undo record.

                      There is one last difference in inserting strings by template or by script. A script usually write status information to output window on every execution resulting in clearing content of active output window. This can be turned off by enabling the Scripting configuration setting Show status information in output window. But please uncheck this setting on start of the development of your next script because you won't see any error message from the Javascript interpreter if this configuration setting is enabled and turn it on again when new script is working fine.

                      The insert template command is faster than execution of a script. But depending on performance of your computer (hard disk speed, CPU and RAM speed) you won't see a noticeable delay on script execution in comparison to insert template command, perhaps just on first time of script execution after starting Windows because script file content not already in Windows file cache as on consecutive executions.
                    3. There are no properties (member variables) which contain just parts of the full file name which is the reason why I have written the general file name evaluating functions. Your single line code to get just the file name from full file name is perfect for all named files with an extension. This code can't be used for general usage, but if your code works for your needs, it is better than using my GetFileName function.

                    1

                      21:55 - Jan 04#10

                      In UE Settings >> Editor >> Word wrap / tab settings configure the behavior you want for the file type, which includes spaces in place of tabs, tab stop value, indent spaces.