Emacs Macros and the Power-Macros Package
Power Macros is an Emacs package, which I developed out of frustration at not being able to define a macro, bind it to a key, and have it bound for future Emacs sessions (or rather, not being able to do so easily).
To use this Emacs package, download the file from its home page at http://www.imada.sdu.dk/~blackie/emacs/. Copy the Lisp file to a location in your load path, and insert the following into your .emacs file:
(require 'power-macros) (power-macros-mode) (pm-load)
If you do not know what a load path is, or do not have one, create a directory called Emacs in your home directory, copy the file to this directory, and insert the following line into your .emacs file before the lines above:
(setq load-path (cons "~/Emacs" load-path))When that is done, you may simply press CTRL-c n when you have defined a macro, and Emacs will ask you the following questions in the mini-buffer.
Which key to bind the macro to? First, Emacs must know to which key the macro should be bound. When you are finished answering these questions, the macro will be available simply by pressing this key. By binding to different keys, you can have several macros defined at the same time.
How should the macro be accessible? With power-macros, you may make the macro accessible in one of two ways:
Global: it is accessible in every buffer.
A major-mode-specific macro: the macro is accessible only in buffers with a given major mode.
As an example of a mode-specific macro, think about the for-loop macro from the example above. This macro is useful only when writing C++ programs. Furthermore, you may need a similar macro using Java syntax for programming Java. With power-macros, you may bind both the macro for C++-mode and the macro for Java-mode to the same key (say CTRL-m-f); then the correct one will be used for the given mode.
Which file should it be saved to? By default, Emacs saves the macros defined with power-macro to the file named ~/.power-macros. If that is okay for the macro you are defining, simply press ENTER at this question. If you do not want to save the given macro to a file for future Emacs sessions, remove the suggested text (i.e., answer the question with an empty string). Also, you can name another file. The section below has a description of when doing this can be of special interest.
What is its description? Finally, you have to write a description for the macro just defined. This will make it much easier for you to identify it later, when you have forgotten which key it is bound to, or when you are searching for a key to bind a new macro.
As part of binding the macro to a key, Emacs will also check if the given binding will override an existing binding. If this is the case, it will warn you and ask for confirmation to continue the definition.
Some time ago, I was going to give a speech on Emacs. I have previously made that a number of times, so I hadn't done any special preparation for this specific speech. While I was traveling to the event by train, I decided to go through my presentation. I was terrified to see that the presentation program suddenly didn't work on my machine. What should I do? The answer was obvious: why not make the presentation using Emacs? Fortunately, the input to the other presentation program was ASCII, and the only construct I used in the presentation was enumerated lists, so it was very easy to rewrite the presentation so it looked good in an Emacs buffer (with a slightly enlarged font).
Now there was only one problem: how could I easily go forward/backward one presentation page? The answer was to create two macros: one going forward one page, and another going backward one page.
Going forward one page was done in the following way:
Search for a line starting with a number of equal signs, namely the second line of each presentation page (just below the title of the page).
Press CTRL-1 CTRL-l (that is, control-(number)one control-(letter)l). This would locate this line as the second line of the screen, and consequently, the title of the page would be the first one.
Go to the beginning of the next line. This was necessary so that the subsequent search would not find the current page.
The two macros just defined are useful only for the given file, and later for all files which contain a presentation made for viewing with Emacs. Therefore, it would be a bit annoying to have these macros defined and bound to keys all the time, especially given that there might be several months before my next Emacs presentation.
The two macros were therefore saved to a separate file, and whenever needed, I can simply load them. Loading a power-macro is done by using the function pm-load. Thus, I could load the macros by pressing META-x, typing pm-load, pressing ENTER, and typing the name of the file to load. Loading the macros for the presentation could be done even more automatically by inserting the following lines as the last lines of the file:
Local Variables: eval: (pm-load "presentation.macro") End:
Here, it is assumed that the name of the file containing the macros is called presentation.macro. Now, Emacs automatically loads the presentation macros whenever the file is opened.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Client-Side Performance
- Peppermint 7 Released
- Sony Settles in Linux Battle
- Libarchive Security Flaw Discovered
- Maru OS Brings Debian to Your Phone
- The Giant Zero, Part 0.x
- Git 2.9 Released
- Snappy Moves to New Platforms
- Profiles and RC Files
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