Aptana code snippets (code snippet)

Source: Internet
Author: User

Original article: http://blog.sina.com.cn/s/blog_53d96fe30100bgxc.html

Code snippets (CodeSegment, which is also translated into a code segment.) What is it? The so-called code snippets is a way for users to save frequently used code or code worth collecting during programming, it can be conveniently called when necessary. This feature is available in Visual Studio. NET 2005. Aptana also supports this feature.

In Windows> views on the main menu, click snippets to open it. Shows the snippets panel.

Aptana has some built-in code segments, such as CSS comments, common HTML tags, DTD, JS functions, and switch statements. It helps us efficiently input the most commonly used code to save time. All you need to do is double-click it to quickly Insert the code into the current code editor.

Since there is such a good stuff, how can we expand it to meet our own needs and customize it?

Add a new code segment

    1. On the project panel, create a project named testproject (with a random name), and then create a folder (folder) under the testproject ), the name is snippets (you must first create this directory before proceeding with the subsequent operations, and the directory name must be snippets ).
    2. In the snippets directory, create a file, which can be CSS, HTML, JS, or XML. Here we create a new test. js file. Double-click to open the file.
    3. In test. JS, we enter a function:
      Function Test (){

      Alert ("this is a test function ");

      }
    4. Place the cursor at the starting position of the first line of the test. js file, expand snippets templates in the snippets panel, and double-click JS snippet template. After double-clicking, the following code is generated in the test. js header:

      /*
      Category: JS
      Name: Test
      Tooltip: Test
      */

    5. Save test. JS, and then look at the js on the snippets panel. A code snippet named test has been generated. How are you doing? Next time you edit a JS file, double-click test to insert the function definition to the cursor position.

Careful people may find that there is a row of buttons above the Aptana editor and several common code snippets have been integrated.

So how can we add our own code snippets here?

In fact, the MIME type is added to the toolbar through the snippet file, which is roughly as follows:

<! --

Category: HTML

Name: wrap

Tooltip: wrap with <strong>




Toolbar: True

Icon: strong.png

Language: text/html

-->

<Strong >$ {selection} </strong>

The icon is a relative path. If you need to publish this code snippet as a plug-in of Aptana Studio, you need to write the complete path, such as com. Aptana. Ide. snippets/icons/strong.png. For example, in Aptana Studio 1.2 Professional, getelementbyid.png is stored in the icons directory of plugins/COM. Aptana. Ide. snippets_1.2.0.018629.jar.

Modify an existing code segment

It's easier to modify a code snippet. Let's go through it.

    1. On the snippets panel, right-click the code snippet you want to edit.
    2. Right-click Edit snippet and open it in the Aptana editor.
    3. Modify and save it.

In the next section, we will introduce how to insert a code snippet into the scripts of the Aptana main menu and call it through the shortcut key.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.