Toolbar, Interface, and Shortcuts of the Editor in the MPLAB® X IDE
This section discusses the MPLAB® X Integrated Development Environment (IDE) user interface and various shortcuts (keyboard, toolbar, etc.).
Editor Toolbar
The MPLAB X IDE toolbar provides a range of capabilities to facilitate the development, testing, and debugging of embedded applications. It can be customized by right clicking on the toolbar. There are many predefined arrangements that can be customized to your preference. The following section describes an example of various functions available for the toolbar. Please refer to your version of MPLAB X IDE for available options.
Edit History
Last Edit Jumps to the location of your last edit and moves the cursor to that line. Hitting this button repeatedly will cycle through all edits in the current session. | |
Back Jumps to the location of the previous edit in your edit history and moves the cursor to that line. | |
Forward Jumps to the location of the next edit in your edit history and moves the the cursor to that line. |
Search
Find Selection Searches for other occurrences of whatever text is currently selected in the editor. | |
Find Previous Occurrence After clicking on the Find Selection button, this will find the previous occurrence (upward) of the selected text in the editor. | |
Find Next Occurrence After clicking on the Find Selection button, this will find the next occurrence (downward) of the selected text in the editor. | |
Toggle Highlight Search After clicking on the Find Selection button, this turns on or off the highlighting of other occurrences of the selected text in the editor. |
Bookmarks
Previous Bookmark Jumps to the previous bookmark (up) in the current file and moves the cursor to that line. | |
Next Bookmark Jumps to the next bookmark (down) in the current file and moves the cursor to that line. | |
Toggle Bookmark Creates or removes a bookmark on the line of the cursor's current position. |
Indent
Shift Line Left Reduces the indentation | |
Shift Line Right Increases the indentation |
Macros
When you have repetitive tasks that you perform frequently, macros can save you quite a bit of time.
Start Macro Recording | |
Stop Macro Recording |
Comments
Comment Comments out one or more lines of code around the cursor's current position or multiple highlighted lines. | |
Uncomment Uncomments an entire block comment surrounding the cursor's current position. |
Glyph Margin
The glyph margin is the vertical bar on the left side of the MPLAB X IDE editor window that typically displays line numbers. In addition, various glyphs (icons) will occasionally replace the line number to provide status information.
Glyph | Description |
---|---|
Current Program Counter (PC) location | |
Error | |
Warning | |
Bookmark | |
Suggestion/Hint | |
Line Breakpoint | |
Disabled Line Breakpoint |
Hovering the mouse pointer over a glyph will cause a tool tip to pop-up explaining the details behind the glyph's appearance.
Configure the Tab Key
MPLAB X IDE permits custom configurations for the tab key. These can be assigned default values appropriate for a specific programming language or can be fully customized to your preference.
In this example, the tab key will be configured for the C language and show options for additional settings.
Select the Editor icon along the top of the window.
Select the Formatting tab. This is where the global Tab options are located. However, if you are programming in C, the C language-specific settings by default will override any selection made here. Continue to the next step if you are programming in C.
Immediately under the Formatting tab, select C in the Language combo box. Tab settings for C language files are found under the Indents category in the properties grid on the lower left of the window.
Code Folding
What is code folding?
Code folding is a feature of the MPLAB X IDE editor that makes it possible to collapse (hide) and expand parts of a file, making it easier to focus just on the parts of interest. In general, any code block surrounded by braces { and } will be collapsible. This includes function bodies, compound statements, and groups of compiler directives. Code folds may be nested, providing a high degree of control over which parts of a file are visible at any one time. Code folding is configurable to include or exclude numerous code structures and also provides a means of creating custom code folds to hide and reveal any part of a file you desire.
How to Use Code Folding
On the far left of the editor window, immediately to the right of the glyph margin, you will see some small boxes with either a + or a - inside them. When a block is expanded, you will see a - that may be clicked to collapse the code. Likewise, when the code is collapsed, clicking on the + will expand it.
Function Unfolded
Function Folded
How to Configure Code Folding Options
General code folding is enabled by default, but many of its features are not. To change code folding options (or disable it altogether if you are so inclined) do the following:
Go to the menu Tools ► Options.
In the window that opens, select the Editor icon from the top.
Check or uncheck each item under the Code Folding section as desired.
Code Assistance
Code Assistance is a feature that analyzes the first few characters you have typed and provides a list of possible endings. For example, if you are using a library with a series of functions that start with lcd, after typing in those letters, you will see a list of functions such as lcdInit() and lcdWrite() displayed for you to select from.
To activate the Code Assistance window:
When activated, you will be presented with a list of all identifiers (macros, variables, functions, etc.) that start with those letters. Double-clicking on any item in the list will add it to your code by completing the text you started to type in.
Selecting an item in the list (single click) displays a documentation window that by default will have nothing in it. You need to provide the content for this window using specially formatted comments in your code.
Once you have inserted a new function, a tool tip will appear to prompt you for any required parameters. If there are multiple parameters, the next one to be entered will be highlighted with bold text.
Code Documentation
The Code Assistance window can display documentation for the selected identifier.
To create documentation for a function, you need to add a Javadoc comment block immediately above the function prototype (or definition if available) that starts with /** on the first line. The editor can assist you by auto-populating a basic Javadoc comment block.
To add a documentation comment with the editor's assistance:
Press Enter
The editor will automatically add a skeleton for the documentation similar to the one shown (if documenting a function).
*
* @param num
* @param radix
*/
void lcdPutInt(long num, char radix);
On the first line with a *, you can type in a description of the function. The @param lines were added automatically based on the parameter list of the following function prototype. You can add comments after each parameter on the same line and they will also appear in the documentation window.
The documentation shown in the image above was generated by the following comments immediately above the lcdPutCur function declaration.
* Positions the cursor on a character LCD module at the specified row and column, both of which are zero-based.
* @param row Row number of the display, where the top row is 0.
* @param column Column number of the display, where the leftmost column is 0.
*/
void lcdPutCur(char row, char col);
Javadoc formatted comments can be considerably more complex. Comments may be formatted as HTML which can then be used to generate documentation in the form of web pages. For more details on the syntax and capabilities of this feature, please see the Oracle website's page on the topic.
Code Assistance Options
Enable or Disable Automatic Display of Code Assistance
Click on the Editor icon at the top of the window, then select the Code Completion tab. Check or uncheck the options to suit your needs.
Find Matching Brace
Put the cursor next to one brace, then hit Ctrl + [ (Ctrl and left square bracket) and the editor will move the cursor to the matching brace and if necessary, scroll the editor to make it visible.
Keyboard:
Ctrl + [
Select Between Braces
Put the cursor next to one brace, then hit Ctrl + Shift + [ (Ctrl and Shift and left square bracket) and the editor will select (highlight) all code between matching braces.