Emacs: Friend or Foe?
Now that you've had a crash course in Emacs LISP programming, let's move on to something more practical. Once you start customizing Emacs, you'll notice that your .emacs file gets to be quite large, and may take a while to load. You may be aware that Emacs allows you to byte-compile LISP source files for faster loading, so let's utilize that feature on our .emacs configuration file.
The first step is to create a directory for your personal Emacs LISP files to reside. At first this directory will contain only one file; namely, your initial configuration file; but later in life you may wish to write separate Elisp files. I use the directory emacs in my home directory for this purpose.
Next, copy your .emacs file to this directory, and rename it to something like startup.el.
Now, we replace the contents of .emacs with a short bit of code that byte-compiles emacs/startup.el and loads it. However, we only want to byte-compile startup.el if it is newer than its compiled counterpart, startup.elc. Here's the trick:
(defun byte-compile-if-newer-and-load (file)
"Byte compile file.el if newer than file.elc"
(if (file-newer-than-file-p (concat file ".el")
(concat file ".elc"))
(byte-compile-file (concat file ".el")))
(load file))
(byte-compile-if-newer-and-load "~/emacs/startup")
This is blatantly obvious, I'm sure, but by way of explanation: this bit of code defines a new function, byte-compile-if-newer-and-load (keeping in line with the Emacs' affinity for verbose function names), and executes it on ~/emacs/startup.el. We have now moved all of the Emacs configuration code to startup.el which is byte-compiled when necessary.
Emacs and the X Window System are two good things that are great together. In fact, my primary motivation for starting to use Emacs for the four thousandth time was to have an editor that incorporated many of the nice features of X, such as mouse-based region cut-and-paste, and so forth. Emacs 19 has support for many useful X-based features, some of which I'll introduce here.
The first thing that you might want to do when using Emacs under X is customize the colors. I'm no fan of black and white; and in fact, I prefer lighter fonts on a dark background. While you can customize Emacs' X-specific attributes using the X resource database (e.g., by editing ~/.Xdefaults), this isn't quite flexible enough. Instead, we can use Emacs internal functions such as set-foreground-color.
For example, in your startup.el file, you might include:
(set-foreground-color "white") (set-background-color "dimgray") (set-cursor-color "red")
which will set these colors appropriately.
Emacs also provides support for faces, used most commonly within font-lock-mode. In this mode, text in the current buffer is “fontified” so that, for example, C source comments appear in one font face, and C function names in another. Several of Emacs' major modes have support for font lock, including C mode, Info, Emacs-Lisp mode, and so on. Each mode has different rules for determining how text is fontified.
For simplicity, I employ faces of the same font, but which use different colors. For example, I set the “bold” face to light blue, and “bold-italic” to a sick shade of green. Each major mode has a different use for each face; for instance, within Info, the bold face is used to highlight node names, and within C mode, the bold-italic face is used for function names.
The Emacs functions set-face-foreground and set-face-background are used to set the colors corresponding to each face. For a list of available faces and their current display parameters, use the command M-x list-faces-display.
For example, I use the following commands in startup.el to configure faces:
(set-face-foreground 'bold "lightblue") (set-face-foreground 'bold-italic "olivedrab2") (set-face-foreground 'italic "lightsteelblue") (set-face-foreground 'modeline "white") (set-face-background 'modeline "black") (set-face-background 'highlight "blue") (set-face-underline-p 'bold nil) (set-face-underline-p 'underline nil)
The modeline face (which is referred to in the Emacs documentation as mode-line, for some reason) is used for the mode line and menu bar. Also, the function set-face-underline-p can be used to specify whether a particular face should be underlined. In this case I turn off underlining for the faces bold and underline. (A non-underlined underline face? Hey, this is Emacs. Anything is possible.)
In order to use all of these wonderful faces, you'll need to turn on font-lock-mode. You may also wish to enable transient-mark-mode, which causes the current region (text between point and mark) to be highlighted using the region face. The following commands will enable this.
(transient-mark-mode 1) (font-lock-mode 1)
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- RSS Feeds
- Dynamic DNS—an Object Lesson in Problem Solving
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Designing Electronics with Linux
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- A Topic for Discussion - Open Source Feature-Richness?
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Validate an E-Mail Address with PHP, the Right Way
- What's the tweeting protocol?
- Kernel Problem
5 hours 16 min ago - BASH script to log IPs on public web server
9 hours 43 min ago - DynDNS
13 hours 19 min ago - Reply to comment | Linux Journal
13 hours 51 min ago - All the articles you talked
16 hours 15 min ago - All the articles you talked
16 hours 18 min ago - All the articles you talked
16 hours 19 min ago - myip
20 hours 44 min ago - Keeping track of IP address
22 hours 35 min ago - Roll your own dynamic dns
1 day 3 hours ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




Comments
Thanks - nice article for an
Thanks - nice article for an new emacs convert (from vi...)
A couple of typos in the code for multiple key sequences:
; Various keys for nuking text (global-unset-key "\C-d")(global-set-key "\C-d g" 'my-nuke-to-end)
(global-set-key "\C-d\C-d" 'my-nuke-line)
which I believe should be:
; Various keys for nuking text(global-unset-key "\C-d")
(global-set-key "\C-dg" 'my-nuke-to-end)
(global-set-key "\C-d\C-d" 'my-nuke-line)
At least that worked for me.
Compare with this..
Ever tried viper mode?