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.
|illusive networks' Deceptions Everywhere||Aug 29, 2016|
|Happy Birthday Linux||Aug 25, 2016|
|ContainerCon Vendors Offer Flexible Solutions for Managing All Your New Micro-VMs||Aug 24, 2016|
|Updates from LinuxCon and ContainerCon, Toronto, August 2016||Aug 23, 2016|
|NVMe over Fabrics Support Coming to the Linux 4.8 Kernel||Aug 22, 2016|
|What I Wish I’d Known When I Was an Embedded Linux Newbie||Aug 18, 2016|
- illusive networks' Deceptions Everywhere
- illusive networks' Deceptions Everywhere
- Happy Birthday Linux
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- What I Wish I’d Known When I Was an Embedded Linux Newbie
- New Version of GParted
- All about printf
- Updates from LinuxCon and ContainerCon, Toronto, August 2016
- Tech Tip: Really Simple HTTP Server with Python
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