Invoking Make from Inside Kate

Running Make is about as easy as anything you'll ever do in programming: you type make on the command line and press Enter. Make will handle the rest. There is only one command-line option of interest to beginners, and that is -k. The -k option instructs Make to stop building any file in which an error occurs and leave the previous copy of the target file undisturbed. (It continues building any other files that need building.) Absent the -k option, Make may overwrite your existing object code and executable files with incomplete copies, which isn't the end of the world but is sometimes a nuisance, and confusing. If this doesn't make total sense to you right now, don't worry—it's a good idea to use -k until you're really sure you don't need it. That said, for simple projects in which there is one project per directory, and a makefile named ''makefile,'' invoking Make is no more than this:

make -k

Anytime you make any change to one of your source code files, no matter how minor, you will have to run Make to test the consequences of that change. As a beginner you will probably be learning by the ''tweak and try'' method, which means that you might change only one instruction on one line of your source code file, and then ''see what that does.''

If you do tend to learn this way (and there's nothing wrong with it!), then you're going to be running Make a lot. The famous EMACS text editor includes a key binding that enables you to run Make with a single keystroke. We can do the same thing with Kate, so that as soon as you save changes to a file, you can press a single key to turn Make loose on your project.

To give yourself a Make key, you have to add a key binding, not to Kate but to the Konsole terminal emulator program. Konsole is ''embedded'' in Kate, and when you open the terminal window under the source code window, what you're opening is in fact a copy of Konsole. Defining the key binding for Konsole adds it to all copies of Konsole, including the one embedded in Kate.

The option is buried deep in Konsole's menu tree, so read carefully:

1. Launch Konsole from the desktop, not from within Kate.

2. Select Settings ^ Manage profiles from Konsole's main menu.

3. Create a new profile is you haven't already. Earlier in this chapter I described how to create a new profile for Konsole to provide the IBM-850 character encoding (for the sake of the old box-border character set); if you created a new profile back then, select it and open it.

4. When the Edit Profile dialog appears, click the Input tag.

5. When the Key Bindings dialog appears, make sure that xFree 4 is selected. This is the default using Konsole under Ubuntu 8.10. Click Edit.

6. When the Edit Key Binding List dialog appears, scroll down the list of bindings until you see ScrollLock in the Key Combination column. We're going to hijack the ScrollLock key, which I consider the most expendable key in the standard PC keyboard. If you use ScrollLock for something, you may have to choose a different key.

7. Double-click in the Output column to the right of ScrollLock. This enables you to enter a string that will be emitted to standard output by Konsole anytime the ScrollLock key is pressed when Konsole has the focus. Type the following string: make -k/r (see Figure 6-11).

8. Click OK in the Edit Key Bindings List dialog, and click OK in the Key Bindings dialog. Then click Close in the Manage Profiles dialog. You're done!

Test the new key binding by bringing up Konsole and pressing the ScrollLock key. Konsole should type make -k on the command line, followed by Enter. (That's what the /r means in the key binding string.) Make will be invoked and, depending on whether Konsole was open to a project directory with a make file in it, build your project.

Now you can launch Kate, open its terminal window, and do the same thing. Press ScrollLock, and Make will be invoked in the terminal window. Each press of the ScrollLock key will invoke Make again.

Figure 6-11: Adding a key binding to Konsole

Was this article helpful?

0 0

Post a comment