You've probably used hypertext links to browse the Web, skipping easily between pages with simple keystrokes or mouse clicks. With etags you can browse your source programs and documentation just as easily. In this article I'll describe tag files and the etags and ctags commands that generate them. I'll also look at how less, Emacs and vi use tag files to make your editing easier and more productive.
By default, etags takes a collection of source files and generates an index of the definitions of all the global symbols of interest. For C and C++ programs, this index includes global and member functions, classes, structures, enums, typedefs and #defines. For (La)TeX documents, it indexes chapters, sections, subsections, figures, equations etc. etags also includes built-in support for assembler, Fortran, lex, Lisp, Pascal, Sheme and yac. etags --help will give a complete list of languages supported by your version.
Try running etags *.c *.h in one of your source directories. After it finishes processing, you'll find that it has produced a file called TAGS. This is a simple text file, with a block of entries for each file parsed. Each block contains a line for each definition in the file, with the text of the definition and the line number and absolute character position on which it was found.
How do you use this? Well, the simplest way is from within Emacs. You start editing as normal in the source directory. When you come across a call to one of your functions, and want to see how it was defined, position the cursor on the call, and enter the Emacs command M-. (press the esc key followed by a period, or hold alt and period down at the same time). Emacs will display the name of the function in the mini-buffer. If you press return to confirm, Emacs will automatically open the file containing the definition and position the cursor at its start. Suppose while looking through that function, you are puzzled by a declaration which uses a typedef name. Move the cursor to it, press M-H. again, and up pops the typedef. If you can't find the a #define you created, use M-., then type the macro name in the minibuffer. Emacs looks it up in the tags table and takes you straight to it.
Sometimes you'll have more than one tag containing the same text, and M-. will take you to the wrong place. Simply keep pressing C-u M-., and Emacs will move through all possible tag matches. If you're finger-tied like me, you may find M-0 M-. a simpler way to enter a prefix for the find-tag command. Entering a negative prefix (C-u -M.) takes you back to a previous definition.
That's not all you can do with the TAGS file. Imagine that when you were typing in some source you decided to give your functions long, descriptive names. It seemed like a good idea at the time but now the glow is wearing off as you're typing a call to that function for the nth time. Again, tags can help. Type the first few characters of the name, then press M-tab. Either the full function name will appear, or a window will pop up displaying a list of possible completions. (This might not work for XEmacs users, and you may have to re-bind M-tab to tag-complete-symbol.)
You can also use tag completion in the minibuffer whenever a command prompts for a tag—type in the first few characters, press tab, and Emacs will do the rest.
If you're an XEmacs user, the M-?i command displays a single line summary of a function or typedef in the modeline—really useful if you've forgotten the calling sequence!
Tags are also a great way to perform search and replace operations across all your source files. The tags-search command prompts you for a regular expression, then displays the first match in any of the files in your TAGS table. You can move on to successive matches using M-, (that's meta-comma). The tags-query-replace performs a egex-replace across all the files in the TAGS table. You can stop it at any point (with escape or C-g) and later resume it with M-,.
Finally, the tags-apropos lists in a separate window all tags matching the regular expression that you enter—a great way to scan for stuff in a hurry.
In the same way that etags works with Emacs, the ctags program generates tag files that can be used with vi, view and less. The basic operation of the command is the same, but it generates a file called tags (in lower case). Once it's finished, you can go straight from the command line to a particular function in either vi or less using vi -tname or less -tname. You don't even have to give a file name!
If you're editing with vi, you can move to a tag using the :tag command.
Practical Task Scheduling Deployment
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.View Now!
|The Firebird Project's Firebird Relational Database||Jul 29, 2016|
|Stunnel Security for Oracle||Jul 28, 2016|
|SUSE LLC's SUSE Manager||Jul 21, 2016|
|My +1 Sword of Productivity||Jul 20, 2016|
|Non-Linux FOSS: Caffeine!||Jul 19, 2016|
|Murat Yener and Onur Dundar's Expert Android Studio (Wrox)||Jul 18, 2016|
- Stunnel Security for Oracle
- The Firebird Project's Firebird Relational Database
- Murat Yener and Onur Dundar's Expert Android Studio (Wrox)
- SUSE LLC's SUSE Manager
- Managing Linux Using Puppet
- My +1 Sword of Productivity
- Non-Linux FOSS: Caffeine!
- Doing for User Space What We Did for Kernel Space
- SuperTuxKart 0.9.2 Released
- Google's SwiftShader Released
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