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)
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"
- ServersCheck's Thermal Imaging Camera Sensor
- The Italian Army Switches to LibreOffice
- Linux Mint 18
- Chris Birchall's Re-Engineering Legacy Software (Manning Publications)
- Petros Koutoupis' RapidDisk
- Oracle vs. Google: Round 2
- The FBI and the Mozilla Foundation Lock Horns over Known Security Hole
- Privacy and the New Math
Until recently, IBM’s Power Platform was looked upon as being the system that hosted IBM’s flavor of UNIX and proprietary operating system called IBM i. These servers often are found in medium-size businesses running ERP, CRM and financials for on-premise customers. By enabling the Power platform to run the Linux OS, IBM now has positioned Power to be the platform of choice for those already running Linux that are facing scalability issues, especially customers looking at analytics, big data or cloud computing.
￼Running Linux on IBM’s Power hardware offers some obvious benefits, including improved processing speed and memory bandwidth, inherent security, and simpler deployment and management. But if you look beyond the impressive architecture, you’ll also find an open ecosystem that has given rise to a strong, innovative community, as well as an inventory of system and network management applications that really help leverage the benefits offered by running Linux on Power.Get the Guide