Tutorial: Emacs for Programmers
Many programs are accompanied by a ChangeLog, which describes updates and modifications to the source on a day-to-day basis. Emacs allows you to semi-automatically update the ChangeLog, using the command M-x add-change-log-entry (or, C-x 4 a, which will do the same in another window).
For example, let's say that we're editing the source file grover.c, and we add a bit of code to grover(). To document this change, we use C-x 4 a, which will open a window containing:
Sun Jul 24 14:39:50 1994 Matt Welsh (email@example.com ) * grover.c (grover):
This command determines that we are within the function grover(), in the file grover.c, and indicates this at the beginning of the entry. We can now enter a new log entry and save the file in the usual way. Each source file that you add entries for will be given its own item.
You can compile programs, and even run a debugger, entirely within Emacs. The most basic compilation command is M-x compile, which will run make (or another command of your choice) in the directory of the current buffer.
The default compilation command is make -k.
(The -k switch will prevent make from halting on an error which has no bearing on other targets in the makefile.) When using M-x compile, you will be prompted for the compilation command to use, and also whether you wish to save any buffers that have changed. If you wish to change the default command, set the variable compile-command to another value. For example,
(setq compile-command "make")
will cause M-x compile to run make without the -k argument.
You can also set a value for compile-command for a particular source file. This is done by including “local variable definitions” within the source file itself. For example, we could include the following comments within a C source file:
/* Local Variables: */ /* mode: C */ /* compile-command: "make" */ /* End: */
These comments set the values of the mode and compile-command variables for the buffer containing this code. When the file is opened by Emacs, it recognizes the line containing Local Variables: and uses subsequent lines, until the line containing End:, to assign values to variables for this buffer alone. You can use this feature to set values for any Emacs variables specific to this buffer.
Now, when we use M-x compile, Emacs runs the given compilation command (here, make) in another window, with which we can monitor the progress of the compilation. To kill the compilation process, type C-c C-k in the compilation buffer.
Once the compilation completes, we can use the error messages printed (if any) to automatically visit the source which caused the errors. For example, let's say that we use M-x compile and the following errors result:
cd /amd/noon/c/mdw/test/lj/ make gcc -O -O2 -I/usr/include -I. -c main.c -o main.o In file included from main.c:12: libpx.h:30: image.h: No such file or directory libpx.h:31: misc.h: No such file or directory make: *** [main.o] Error 1 Compilation exited abnormally with code 1 at Sun Jul 24 16:32:17
Instead of manually locating libpx.h and jumping to the line in question, you can move point to the error message in the compilation buffer, press C-c C-c, and the source corresponding to the error is automatically visited. You can then correct the bug, move to the next error, and repeat. Under X, pressing mouse-2 on an error message in the compilation buffer will jump to the corresponding source line.
If you have a large number of error messages, pressing M-n in the compilation buffer will move to the next error message (in addition to viewing the corresponding source). To cause M-n to have this behavior within the C source buffer as well, you can use the following command in your Emacs startup file: (define-key c-mode-map "\M-n" 'next-error)
To simplify the compilation process, I use the following code within my Emacs configuration file:
(defun my-save-and-compile () (interactive "") (save-buffer 0) (compile "make -k")) (define-key c-mode-map "\C-c\C-c' 'my-save-and-compile)
This defines a new function, my-save-and-compile, which will automatically save the current buffer and run make -k. This saves me the hassle of answering the various prompts given by M-x compile alone. Now, using C-c C-c within a C Mode buffer will save the source and compile it.
Once you get used to the above mechanism, fixing bugs and recompiling code becomes quite painless—you can concentrate on debugging and let Emacs locate the errors, run make, and so forth.
Practical Task Scheduling Deployment
July 20, 2016 12:00 pm CDT
One of the best things about the UNIX environment (aside from being stable and efficient) is the vast array of software tools available to help you do your job. Traditionally, a UNIX tool does only one thing, but does that one thing very well. For example, grep is very easy to use and can search vast amounts of data quickly. The find tool can find a particular file or files based on all kinds of criteria. It's pretty easy to string these tools together to build even more powerful tools, such as a tool that finds all of the .log files in the /home directory and searches each one for a particular entry. This erector-set mentality allows UNIX system administrators to seem to always have the right tool for the job.
Cron traditionally has been considered another such a tool for job scheduling, but is it enough? This webinar considers that very question. The first part builds on a previous Geek Guide, Beyond Cron, and briefly describes how to know when it might be time to consider upgrading your job scheduling infrastructure. The second part presents an actual planning and implementation framework.
Join Linux Journal's Mike Diehl and Pat Cameron of Help Systems.
Free to Linux Journal readers.Register Now!
- Google's SwiftShader Released
- SUSE LLC's SUSE Manager
- My +1 Sword of Productivity
- Managing Linux Using Puppet
- Interview with Patrick Volkerding
- Murat Yener and Onur Dundar's Expert Android Studio (Wrox)
- Non-Linux FOSS: Caffeine!
- SuperTuxKart 0.9.2 Released
- Tech Tip: Really Simple HTTP Server with Python
- Parsing an RSS News Feed with a Bash Script
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide