Using Kate While Programming

At least for the programs I present in this book, Kate is going to be the ''workbench'' where we edit, assemble, link, test, and debug our code. In other words, you run Kate from the Applications menu or from a desktop or panel launcher, and then everything else you do you do from inside Kate.

''Inside'' here has an interesting wrinkle: Kate has its own built-in Linux terminal window, and this terminal window enables us to launch other tools from inside Kate: specifically, the Make utility (more on this in the next section) and whatever debugger you decide to use. Anything you can do from the Linux console you can do in Kate's terminal window, which by default connects to the Linux console.

Figure 6-8: The search and replace bar

Although you can launch Kate itself from inside a terminal window, I don't recommend this. When launched from a terminal, Kate posts status information relating to its own internal machinery to the window pretty much continuously. This is for the sake of the programmers who are working on Kate, but it's of little or no value to Kate's users, and yet another distraction on your screen. It's much better to create a desktop or panel launcher icon and launch Kate from the icon.

Creating and Using Project Directories

As explained earlier in this section, an assembly language project maps neatly onto Kate's idea of a session. A project should reside in its own directory under your assembly language work directory, which in turn should reside under your Ubuntu Home directory. All files associated with the project (except for library files shared among projects) should remain in that project's directory. In this book, I'll refer to your overall assembly language work directory as ''asmwork.''

The example code archive I've created for this book is a ZIP archive, and when you extract the archive to your hard drive in your asmwork directory, it will create a project directory for each of the example programs. To open these ''readymade'' project directories from Kate for the first time, do this:

1. Launch Kate.

2. When the Session Chooser dialog appears, click New Session.

3. Click the Open button on the main toolbar, or select File ^ Open. Use the Open File dialog that appears to navigate to the project directory that you want, starting from your Home directory.

4. When the files in the project directory are displayed, open the source code files and makefile. You can do this in one operation by holding Ctrl down while clicking on all the files you wish to open. All selected files will be highlighted. Then click the dialog's Open button to open them all.

5. Once all the opened files are displayed in the Documents view in the Kate sidebar, save the new session with a descriptive name. This is done by selecting Sessions ^ Save As and typing the name for the new session in the Session Name dialog that appears. Click OK, and you have a new Kate session for that project directory.

When you want to create a brand-new project for which no directory exists yet, do this:

1. Launch Kate.

2. When the Session Chooser dialog appears, click New Session.

3. Click the Filesystem Browser button to display the Filesystem Browser view.

4. Navigate to your assembly language working directory (''asmwork,'' for example) using the Filesystem Browser.

5. Right-click anywhere in the Filesystem Browser view, and from the context menu select New Folder. Type a name for the new directory and click OK.

6. Save the new session under a new name, as described in step 5.

At this point you can begin entering source code text for your new project. Don't forget to save it periodically, by clicking Save All.

Kate's terminal window is not displayed by default. You can display it by clicking the Terminal icon at the bottom edge of Kate's window. Note that the terminal will not display a brand-new project directory that you just created until you save at least one document from Kate into that directory. Kate synchronizes the terminal to the location of the document shown in the editor window, and until there's a document in the editor window that's been saved to a specific location in your directory tree, there's nowhere for the terminal window to ''go.''

Once you have a project directory and have begun saving files into that directory from Kate, your workflow will go something like this:

1. Enter and make changes to your source code files and make-file in Kate's editor window. Save all changes to disk.

2. Build your project by clicking in the terminal window to give it the focus, and then enter the make command at the terminal command line. Assuming you've created a makefile for the project, the Make utility will launch NASM and the linker, and will show any errors that occur during the build. (More on Make later in this chapter.)

3. Test the executable built by Make by ensuring that the terminal window has the focus, and then enter ./myprog, where "myprog" is the name of the executable file that you want to test.

4. If you want to observe your program running in a debugger, make sure the terminal window has the focus, and then enter the name of the debugger, followed by the name of the executable—for example, insight myprog. The debugger will appear with your program loaded and read to observe. When you're done debugging, exit the debugger to return to Kate.

5. Return to the editor by clicking on the editor window to give it the focus, and continue working on your source files.


The issue of where the focus is may trip you up when you're first getting used to working with Kate. In any modern windowing environment like GNOME or KDE, the focus is basically the screen component that receives keystrokes you type. Most of the time, you'll be typing into Kate's editor window, because the editor window has the focus while you're editing. If you don't explicitly move the focus to the terminal, you'll end up typing make or other Linux commands into your source code files—and if you don't notice that you're doing this (and it's very easy to forget in the heat of software creation), you may find the text pointed up by NASM in an error message the next time you try to assemble the project.

It's easy to tell if the terminal window has the focus or not: if the terminal's block cursor is a hollow box, the focus is elsewhere. If the terminal's block cursor is a filled box, the terminal has the focus.

Was this article helpful?

0 0

Post a comment