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)
Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.
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
| 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 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
| Dart: a New Web Programming Experience | May 07, 2013 |
- New Products
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- A Topic for Discussion - Open Source Feature-Richness?
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Home, My Backup Data Center
- What's the tweeting protocol?
- One Hand Slapping
- The Secret Password Is...
- Trying to Tame the Tablet
- RSS Feeds
- Reply to comment | Linux Journal
5 hours 53 min ago - Reply to comment | Linux Journal
8 hours 26 min ago - Reply to comment | Linux Journal
9 hours 43 min ago - great post
10 hours 18 min ago - Google Docs
10 hours 41 min ago - Reply to comment | Linux Journal
15 hours 29 min ago - Reply to comment | Linux Journal
16 hours 16 min ago - Web Hosting IQ
17 hours 50 min ago - Thanks for taking the time to
19 hours 26 min ago - Linux is good
21 hours 24 min ago
Enter to Win an Adafruit Prototyping Pi Plate 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 Prototyping Pi Plate 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
- Next winner announced on 5-21-13!
Free Webinar: Linux Backup and Recovery
Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.
In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.




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?