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.
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
- SUSE LLC's SUSE Manager
- Murat Yener and Onur Dundar's Expert Android Studio (Wrox)
- 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