Difference between revisions of "Gedit-Text-Editor/C3/Snippets-in-gedit/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with "'''Title of script''':''' Snippets in gedit Text editor''' '''Author: Nirmala Venkat''' '''Keywords: Snippets, plugins, Add new snippets, Delete snippets, Highlight matching...")
 
 
Line 44: Line 44:
  
 
What are Snippets?
 
What are Snippets?
| style="border:1pt solid #000001;padding:0.097cm;"| * '''Snippets''' are lines of text or '''source code''' that are used frequently while writing a program.
+
| style="border:1pt solid #000001;padding:0.097cm;"|  
 +
* '''Snippets''' are lines of text or '''source code''' that are used frequently while writing a program.
  
 
* It allows the user to avoid repetitive typing.
 
* It allows the user to avoid repetitive typing.
Line 137: Line 138:
  
 
Recall that one of the features of''' Intelligent Text Completion''' is''' “Auto close brackets and quotes”.'''
 
Recall that one of the features of''' Intelligent Text Completion''' is''' “Auto close brackets and quotes”.'''
 +
 +
|-
 +
| style="border:1pt solid #000001;padding:0.097cm;"|
 +
| style="border:1pt solid #000001;padding:0.097cm;"| Now type as shown here.
  
 
|-
 
|-
Line 193: Line 198:
 
| style="border:1pt solid #000001;padding:0.097cm;"|  
 
| style="border:1pt solid #000001;padding:0.097cm;"|  
 
| style="border:1pt solid #000001;padding:0.097cm;"| Let us see how to use this''' snippet''' in our program.
 
| style="border:1pt solid #000001;padding:0.097cm;"| Let us see how to use this''' snippet''' in our program.
 
Switch to''' gedit Text editor.'''
 
  
 
|-
 
|-
Line 243: Line 246:
 
| style="border:1pt solid #000001;padding:0.097cm;"| Click on the + icon in the bottom left of the window.
 
| style="border:1pt solid #000001;padding:0.097cm;"| Click on the + icon in the bottom left of the window.
 
| style="border:1pt solid #000001;padding:0.097cm;"| At the bottom left of the window, click the''' plus''' icon to create a new '''snippet'''.
 
| style="border:1pt solid #000001;padding:0.097cm;"| At the bottom left of the window, click the''' plus''' icon to create a new '''snippet'''.
 
|-
 
| style="border:1pt solid #000001;padding:0.097cm;"| Point to the New snippet box.
 
| style="border:1pt solid #000001;padding:0.097cm;"| A box with the text''' New Snippet''' appears in the''' Manage snippets''' panel.
 
  
 
|-
 
|-

Latest revision as of 06:41, 22 October 2016

Title of script: Snippets in gedit Text editor

Author: Nirmala Venkat

Keywords: Snippets, plugins, Add new snippets, Delete snippets, Highlight matching brackets, Document Statistics, video tutorials

Visual Cue Narration
Slide 1: Welcome to the Spoken Tutorial on Snippets in gedit Text editor.
Slide 2:

Learning objectives

In this tutorial, we will learn how to:
  • Use default Snippets
  • Add new snippets
  • Delete snippets
  • Highlight matching brackets and
  • Document Statistics
Slide 3:

System Requirements

To record this tutorial, I am using:
  • Ubuntu Linux 14.04 operating system
  • gedit Text editor 3.10
Slide 4:

Pre-requisites

To follow this tutorial, you should have working knowledge of any operating system.
Slide 5:

What are Snippets?

  • Snippets are lines of text or source code that are used frequently while writing a program.
  • It allows the user to avoid repetitive typing.
  • Snippets is one of the default plugins in gedit Text editor.
Let's see how we can create and use Snippets.
Open the gedit Text editor. Let's open the gedit Text editor.
From the Main menu, click Edit and Preferences. First we need to enable the Snippet plugin.

From the Main menu, click Edit and Preferences.

Check the Snippets check box in plugin tab.

Click Close.

In the Plugin tab, scroll down and check the Snippets box.

Click Close.

Let us write a 'C' program to check whether a given number is positive or negative.
Click File>> save. Enter the filename as NumCheck.c Let us save the file as NumCheck.c
#include <studio.h>

void main()

{

int num;

    scanf("%d", &num);

}

Pause this tutorial and type this code in your gedit Text editor.
Place the cursor in the next line When you have finished typing, place your cursor on the next line.
Type the word 'If' and press the Tab key. Now type the word If and press the Tab key.
Point to the 'If' structure statement. Can you see the structure of the If statement automatically inserted here?
Point to the word 'condition'

if(num ==0)

{

         printf("Number is zero.");

}

Point to the insertion of end braces

Type printf open brackets double quotes

Point to end double quotes

Notice that the cursor is on the word condition, by default.


Type num==0.

The word condition is overwritten.

We can see the open curly braces andend braces are inserted automatically.

This is because we have added the plugin called Intelligent text completion in the previous tutorial.

Type printf open brackets double quotes.

Notice the end double quotes are also inserted automatically.

Recall that one of the features of Intelligent Text Completion is “Auto close brackets and quotes”.

Now type as shown here.
Click on Tools>> Manage Snippets Now, from the Main menu, select Tools and Manage Snippets.
Point to Manage Snippets box. The Manage Snippets dialog box appears.
On the left side panel, scroll down and select 'C' On the left side panel, scroll down and select 'C'.
Click on the triangle sign next to it. Click on the triangle sign next to it.
Point to the Snippets that are listed down The list of all the Snippets for 'C' are listed here.
Click on the If snippet. Click on the If snippet.
Point to the syntax of the 'If' statement in the top right panel. In the top right panel, you can see the complete syntax for the 'If' statement in 'C' language.
Point to the 'If' in the Tab Trigger field. Look at the Tab Trigger field at the right bottom.

It is displayed as 'If', by default.

So, by typing 'If' and pressing the Tab key, the complete 'If' statement gets inserted.
Let us see one more snippet called 'else if'.
Click on the 'else if' snippet under 'C'. On the left hand side, click on the 'else if' snippet under 'C'.

You can see the syntax for this on the top right panel.

Point to the 'elif' in the tab trigger field Note the Tab trigger as 'elif'. Click Close.
Let us see how to use this snippet in our program.
Type 'elif' and press tab. Type 'elif' and press tab.

You can see that the syntax for 'else if' is inserted here.

Copy and paste the program

else if(num > 0)

{

printf("Number is positive.");

}

else

{

printf("Number is negative.");

}

    return 0;

Type the program code as shown here.
So, with the help of Snippets, we can avoid repetitive typing in our source code.
Next, we will see how to create our own Snippet.
Click Tools>> Manage Snippets Now, from the Main menu, click Tools and Manage snippets.
Select 'C' In the Manage Snippets dialog box that appears, select C.
Click on the + icon in the bottom left of the window. At the bottom left of the window, click the plus icon to create a new snippet.
Type HelloWorld and press Enter. Type “HelloWorld” and press Enter.
Click on the Edit panel Then click on the Edit panel.
#include<stdio.h>


int main()

{

printf (“Hello World \n”);

return 0;

}

Type the following code. This is a simple basic program in 'C'.
In the Tab trigger field type hello.


Click Close.

In the Tab trigger field, typehello”. This is the shortcut keyword used in the editor.

Click Close.

Click on the Plus icon in the toolbar to create a new document. Open a new document in the gedit Text editor.
Save the file as helloworld.c Save the file as helloworld.c


If you don't save the file with '.c' extension, the snippets will not work.


It will consider the file as a text file, not a 'c' program file.

Type hello and press the Tab key. Typehello and press the Tab key.
Point to the inserted text. The text that we typed in the ‘HelloWorld’ snippet is inserted here.

This is how we create and use a custom snippet.

Next, let us see how to delete a snippet.
Click Tools>> Manage Snippets From the Main menu, click Tools and Manage Snippets.
Click C


Click on HelloWorld Snippet

In the snippet list, click C.


Click on the snippet ‘HelloWorld’ which we have created.

Click the minus icon. At the bottom left of the window, click the minus icon to delete a snippet.

The snippet is deleted.

Select the snippet While loop Now, locate the snippet ‘While loop’ from the list and select it for deletion.
Point to the disabled delete icon

Click close

We can see here that the delete icon is disabled.

This means we can only delete the snippets which we have created, and not the default ones.

Click Close.

Switch back to CheckNum.c Let us switch back to NumCheck.c tab.
Point to the brackets in the program In this 'C' program, you can see brackets of different types.

Sometimes, we may lose track of the closing bracket that matches the opening bracket.

Let us see how to highlight the matching brackets.
Click Edit>>Preferences From the Main menu, click Edit and Preferences.
In the View tab, check the Highlight matching brackets box.

Click Close

In the View tab, check the Highlight matching brackets box.

Click Close.

Place the cursor on the open curly braces after main()

Point to the corresponding close curly braces

Now, place the cursor on the open curly braces at the start of the program.


Notice that the last closed curly braces is highlighted immediately.

Place the cursor on the second open curly braces

Point to the second last close curly braces.

Place your cursor on the second open curly braces.

Notice that the second last closed curly braces is highlighted in gray color.

This is good way to keep track of the brackets in a program.

It helps ensure that all open brackets have the corresponding closing brackets.

Next we will learn about the Document Statistics feature.
Slide 6:

Document Statistics

Document Statistics plugin shows the various statistics related to the current document.

It shows information such as:

  • Number of words
  • Number of lines
  • Number of characters
  • Number of non-space characters
  • Size of the file in bytes
Click Edit >> Preferences From the Main menu, click Edit and Preferences.
Click on the Plugins tab. Click on the Plugins tab.
Scroll down to see Document Statistics Scroll down to see Document Statistics option.
Check the Document Statistics box.

Click Close.

If the Document Statistics plugin is not enabled then check it.

Click Close.

Click Tools>> Document Statistics From the Main menu, select Tools and Document Statistics.
Point to the various statistics details The Document Statistics dialog box opens.

It displays the statistics including lines, words, characters and bytes in the document NumCheck.c

Change the printf statement as

printf(“ The given number is Zero”);

In the file NumCheck.c, change the words as shown.
Click on Update button. Now, from the Document Statistics dialog box, click on Update.
Point to the changes that are reflected in the box.

Click Close.

Notice, that the information has been updated to reflect the changes we made.

Click Close.

This feature is very useful when a document is required to stay within certain number of words.
This brings us to the end of this tutorial.

Let us summarise.

Slide 7:

Summary

In this tutorial, we learnt how to:
  • Use default snippets
  • Add new snippets
  • Delete snippets
  • Highlight matching brackets
  • Document Statistics
Slide 8:

Assignment

Here is an assignment for you.
  • Create a new custom snippet named company header
  • Enter the complete company address in the edit panel
  • In the Tab trigger field, enter the shortcut key as company
  • Open a new document and use the snippet.
Slide 9:

About Spoken Tutorial project

The video at the following link summarises the Spoken Tutorial project.

Please download and watch it.

Slide 10:

Spoken Tutorial workshops

The Spoken Tutorial Project Team:
  • conducts workshops using spoken tutorials and
  • gives certificates on passing online tests.

For more details, please write to us.

Slide 11:

Forum for specific questions

* Please post your timed queries in this forum.
Slide 12: Spoken Tutorial project is funded by NMEICT, MHRD, Government of India.

More information on this mission is available at

this link.

This is Nirmala Venkat from IIT Bombay, signing off. Thanks for watching.

Contributors and Content Editors

Nancyvarkey, Nirmala Venkat