M-x all-things-emacs http://www.emacsblog.org EmacsBlog.org Wed, 07 May 2008 16:46:04 +0000 http://wordpress.org/?v=2.5 en Quick Tip: Easier Window Switching in Emacs http://www.emacsblog.org/2008/05/01/quick-tip-easier-window-switching-in-emacs/ http://www.emacsblog.org/2008/05/01/quick-tip-easier-window-switching-in-emacs/#comments Thu, 01 May 2008 15:22:44 +0000 Rob Christie http://www.emacsblog.org/?p=119 I ran across this thread on easier window switching within emacs using the windmove-xxx commands on gnu.emacs.help a few days ago. It’s always nice to find out about commands I didn’t know about… kinda like C-x M-c M-butterfly. I have always used C-x o and C-x b to move between windows and buffers, but my work monitor is large enough to allow me to split my frame into four windows. Using C-x o to move around has been somewhat of an annoyance. The windmove commands allow you to move up, down, left, and right between windows using a prefix key and the arrows on your keyboard. I have added the following to my .emacs:

(windmove-default-keybindings 'meta)

If you invoke the command without an argument then shift is used as the prefix. I also had to place this below the turning on of pc-selection-mode because it also sets the M-up, M-down, M-left, and M-right keys.

]]>
http://www.emacsblog.org/2008/05/01/quick-tip-easier-window-switching-in-emacs/feed/
Package Faves: js2-mode http://www.emacsblog.org/2008/04/04/package-faves-js2-mode/ http://www.emacsblog.org/2008/04/04/package-faves-js2-mode/#comments Fri, 04 Apr 2008 22:23:15 +0000 Ryan McGeary http://www.emacsblog.org/2008/04/04/package-faves-js2-mode/ I just played with Stevey’s new js2-mode. So many previous javascript modes for emacs just didn’t cut it, but now finally, I’m proud to see a javascript mode that works. Steve did a great job with this package. Kudos.

Installation

Grab the latest js2, put it in your load-path, and configure. Full instructions. Here’s my config:

(autoload 'js2-mode "js2" nil t)
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
 
(setq js2-basic-offset 2)
(setq js2-use-font-lock-faces t)

(Steve, I’m one of those who like my font-lock settings, so thanks for keeping the font-lock-faces option around for us crazies.)

Features

  • Indenting that works! Finally.
  • Syntax highlighting that works. ‘Bout time.
  • Inline warnings and syntax errors. Useful.
  • Decent code folding. I like.
  • Other tidbits. You’ll have to read Steve’s long-winded post for more.
]]>
http://www.emacsblog.org/2008/04/04/package-faves-js2-mode/feed/
Yet Another Snippet Package http://www.emacsblog.org/2008/03/13/yet-another-snippet-package/ http://www.emacsblog.org/2008/03/13/yet-another-snippet-package/#comments Thu, 13 Mar 2008 15:47:09 +0000 Rob Christie http://www.emacsblog.org/2008/03/13/yet-another-snippet-package/ There are a number of snippet packages that are available for emacs: snippet.el, smart-snippet, and the older skeleton and tempo packages that are a part of emacs. The snippet package was in the words of the developer:

A quick stab at providing a simple template facility like the one present in TextMate (an OSX editor).

The creator of smart-snippet, an extension to snippet.el, has now created the aptly titled yasnippet – Yet Another Snippet extension for emacs. It looks promising based on the screencast… I have not had a chance to play with it yet locally. The mirrored fields support looks cool though.

]]>
http://www.emacsblog.org/2008/03/13/yet-another-snippet-package/feed/
Fixing Pastie for Emacs http://www.emacsblog.org/2008/01/07/fixing-pastie-for-emacs/ http://www.emacsblog.org/2008/01/07/fixing-pastie-for-emacs/#comments Mon, 07 Jan 2008 03:56:01 +0000 Rob Christie http://www.emacsblog.org/2008/01/07/fixing-pastie-for-emacs/ Pastie Icon Recently, I have been doing more remote pair programming at my day job, and I was copying some code snippets into pastie. Pastie is a site that allows you to share code snippets with nice syntax highlighting. One thing led to another, and next I was searching for emacs integration with pastie. I found it here, but unfortunately the lisp package no longer seemed to work. It turned out that the package just needed to support a minor change to the pastie API. I have fixed it, and added support for sniffing more of the emacs modes associated with Ruby on Rails and java. Here is the updated version of pastie.el. (Note: After publishing I added it to the emacs wiki based on a user’s suggestion: pastie.el). The package has the following functions:

pastie-buffer – Posts the current buffer as a new paste at pastie.caboo.se.
pastie-region – Posts the selected region as a new paste at pastie.caboo.se.
pastie-get – Fetches the contents of a paste from pastie.caboo.se into a new buffer.

]]>
http://www.emacsblog.org/2008/01/07/fixing-pastie-for-emacs/feed/
Where In The World Are Emacs Users? http://www.emacsblog.org/2007/10/26/where-in-the-world-are-emacs-users/ http://www.emacsblog.org/2007/10/26/where-in-the-world-are-emacs-users/#comments Fri, 26 Oct 2007 13:53:36 +0000 Rob Christie http://www.emacsblog.org/2007/10/26/where-in-the-world-are-emacs-users/ Every few months you see a thread on the emacs news groups polling to see the age or occupation of the users. Recently someone sent out a link on gnu.emacs.help to a site called BuddyMapping with a map for Emacs Users. I have always loved maps, and I am a sucker for these map mash-ups, especially when there is no registration required in order to add yourself.

The thread also points out that the Emacs Wiki contains a list of Emacs User Locations (in text form of course). There is also a link to an Emacs Flickr tag.

]]>
http://www.emacsblog.org/2007/10/26/where-in-the-world-are-emacs-users/feed/
Declaring .emacs Bankruptcy http://www.emacsblog.org/2007/10/07/declaring-emacs-bankruptcy/ http://www.emacsblog.org/2007/10/07/declaring-emacs-bankruptcy/#comments Sun, 07 Oct 2007 14:24:05 +0000 Ryan McGeary http://www.emacsblog.org/2007/10/07/declaring-emacs-bankruptcy/ I give up. During the past 6 years of my emacs career, my .emacs initialization file grew to embarrassing levels. As of this morning, it is well over 1000 lines and is a looming burden of disorganization. Startup time is poor, customizations exist for modes that I don’t use anymore (ahem, csharp-mode), and it has been this way for too long.

Today, I am declaring .emacs bankruptcy.

Akin to email bankruptcy, I’m blowing everything away and starting over. Only as I realize a need for something is it going back in. I’m also starting with a better organization scheme. My intent is to have a .emacs file with nothing but load-path additions and requires.

Examples

Here is an early view of my .emacs as I start this process:

;;;; Ryan McGeary's emacs initialization (2001-2007)
 
;; Enable a backtrace when problems occur
;; (setq debug-on-error t)
 
;; Load paths
(add-to-list 'load-path (expand-file-name "~/.emacs.d"))
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp"))
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp-personal"))
 
;; Personal customizations
(require 'rmm-generic)
(require 'rmm-iswitchb)
(require 'rmm-carbon-emacs)
(require 'rmm-colors)
;; Many more to come

And here is an example of a personal customization (rmm-generic):

;;; Generic emacs settings I cannot live without
 
;; "y or n" instead of "yes or no"
(fset 'yes-or-no-p 'y-or-n-p)
 
;; Highlight regions and add special behaviors to regions.
;; "C-h d transient" for more info
(setq transient-mark-mode t)
 
;; Display line and column numbers
(setq line-number-mode    t)
(setq column-number-mode  t)
 
;; Emacs gurus don't need no stinking scroll bars
(toggle-scroll-bar -1)
 
;; Line-wrapping
(set-default 'fill-column 80)
 
;; Prevent the annoying beep on errors
(setq visible-bell t)
 
(provide 'rmm-generic)

This particular component is very likely to grow, but with the added organization elsewhere, I am more likely to refactor early and often.

Key points

  • Third party packages go in ~/.emacs.d/lisp.
  • My own packages go in ~/.emacs.d/lisp-personal.
  • Personal customizations are broken into manageable components, and each is prefixed with my initials (rmm) to avoid naming conflicts. These are placed in my ~/.emacs.d directory.
  • Customization components can be compiled for speed, or commented out when not needed.
  • My stress levels are reduced knowing everything has it’s own cubbyhole.

I anticipate this being a good bit of work, but I think it’s going to be well worth it. If nothing else, it makes me happier.

Your feedback, please

Who else wants to declare bankruptcy with me? What other techniques, tools, or conventions am I missing?

]]>
http://www.emacsblog.org/2007/10/07/declaring-emacs-bankruptcy/feed/
Quick Tip: Spaces instead of Tabs http://www.emacsblog.org/2007/09/30/quick-tip-spaces-instead-of-tabs/ http://www.emacsblog.org/2007/09/30/quick-tip-spaces-instead-of-tabs/#comments Sun, 30 Sep 2007 14:04:33 +0000 Ryan McGeary http://www.emacsblog.org/2007/09/30/quick-tip-spaces-instead-of-tabs/ Tab characters used as indentation of source code is a pet peeve of mine. Add this to your emacs initialization to make sure all indentation uses spaces instead.

;; I hate tabs!
(setq-default indent-tabs-mode nil)

Now, if you also use tab completion everywhere, someday, you’ll want to actually insert a real <tab> character (ASCII 9), but won’t be able too. Quoted-insert to the rescue. Type C-q C-i to insert a horizontal tab character.

Note: Even though, I’ve aired my religious preference on this topic, my intention is not to start a war but to teach those who like spaces how to configure emacs (Yes, I’ve read the heated material on the subject).

]]>
http://www.emacsblog.org/2007/09/30/quick-tip-spaces-instead-of-tabs/feed/
Newbie Tip: Visual Emacs Keybinding Cheatsheet http://www.emacsblog.org/2007/08/27/newbie-tip-visual-emacs-keybinding-cheatsheet/ http://www.emacsblog.org/2007/08/27/newbie-tip-visual-emacs-keybinding-cheatsheet/#comments Mon, 27 Aug 2007 17:41:50 +0000 Ryan McGeary http://www.emacsblog.org/2007/08/27/newbie-tip-visual-emacs-keybinding-cheatsheet/ For a newcomer to emacs, learning the default set of keybindings can be daunting. There’s no substitute for C-h b (describe-bindings) and C-h k (describe-key), but sometimes it’s just easier to learn visually.

Visual Keyboard Keybinding Cheatsheet

]]>
http://www.emacsblog.org/2007/08/27/newbie-tip-visual-emacs-keybinding-cheatsheet/feed/
Quick Tip: show-paren-mode http://www.emacsblog.org/2007/08/07/quick-tip-show-paren-mode/ http://www.emacsblog.org/2007/08/07/quick-tip-show-paren-mode/#comments Tue, 07 Aug 2007 06:03:25 +0000 Rob Christie http://www.emacsblog.org/2007/08/07/quick-tip-show-paren-mode/ When show-paren-mode is enabled a matching parenthesis is highlighted based on the location of point (i.e., when your cursor is on a parenthesis). show-paren-mode Example
You can tweak the behaviour of this minor mode by adjusting show-paren-style and the show-paren-delay. There are three styles to choose from:
  • parenthesis – shows the matching paren
  • expression – shows the entire expression enclosed by the paren, and
  • mixed – shows the matching paren if it is visible, and the expression otherwise.

To obtain this behaviour, add the following to your .emacs file:

(show-paren-mode t)
]]>
http://www.emacsblog.org/2007/08/07/quick-tip-show-paren-mode/feed/
Package Faves: rcodetools http://www.emacsblog.org/2007/07/21/package-faves-rcodetools/ http://www.emacsblog.org/2007/07/21/package-faves-rcodetools/#comments Sat, 21 Jul 2007 02:24:21 +0000 Ryan McGeary http://www.emacsblog.org/2007/07/21/package-faves-rcodetools/ rcodetools-xmpfilter Rob recently pointed me to rcodetools and its included emacs integration. Specifically, I’ve only had the chance to play with xmpfilter, but so far, I’m very impressed. Let’s use it to annotate lines in a ruby buffer with intermediate results.

Installation

First, let’s install rcodetools. I am going to assume that you already have ruby and rubygems installed.

$ gem install rcodetools

(Prefix your install with sudo if necessary on your system.)

Rcodetools is now installed under [GEM_INSTALL_DIR]/gems/rcodetools-0.7.0.0 and there is good emacs setup documentation in README.emacs, but for what I’m about to demonstrate here, you only need to install rcodetools.el. Copy rcodetools.el to somewhere in your emacs load-path and require it.

(require 'rcodetools)

Capturing STDOUT

Suppose you have a ruby script in a buffer that looks like this:

3.times { puts "Hello World!" }

Run M-x xmp and now your buffer will look like this:

3.times { puts "Hello World!" }
# >> Hello World!
# >> Hello World!
# >> Hello World!

Code Annotation

You can sprinkle annotated results in your source code by adding # => markers at the end of lines to show their values. This comment marker can be added to the end of a line automatically by running comment-dwim twice (M-; M-;).

If you had a script that looked like this:

def fib(n)
  n < 2 ? n : fib(n - 1) + fib(n - 2)
end
 
fib(2)           # =>
fib(11)          # =>

After running M-x xmp, the last two lines of your buffer will look like this:

...
fib(2)           # => 1
fib(11)          # => 89

Summary

I find this package pretty cool and I wish I knew about it sooner. This is going to change the way I write and test my one-off ruby scripts.

Xmpfilter can also be used to generate Test::Unit assertions and RSpec expectations automatically, but I leave that as an exercise for the reader. Find more information on xmpfilter.

(Rcodetools also ships with Vim support, and TextMate users get bundled xmpfilter integration for free.)

]]>
http://www.emacsblog.org/2007/07/21/package-faves-rcodetools/feed/
Package Faves: emacs-rails http://www.emacsblog.org/2007/06/10/package-faves-emacs-rails/ http://www.emacsblog.org/2007/06/10/package-faves-emacs-rails/#comments Sun, 10 Jun 2007 05:41:54 +0000 Rob Christie http://www.emacsblog.org/2007/06/10/package-faves-emacs-rails/ The emacs-rails package turns emacs into a Ruby on Rails IDE. To put it simply, I love the package. It gets me excited to see this much active development for an emacs mode. The emacs wiki has a laundry list of the functionality that the mode provides. I don’t think a single blog post can do the functionality justice, so I just want to hightlight a few of the features below (and expand on other features in later posts).

Context Sensitive Switching Between Rails Buffers

The rails framework espouses convention over configuration, therefore you can typically make assumptions that a method named edit in your controller is going to display a view that can be found under app/views/<controller name>/edit.rhtml. Additionally, due to the frameworks conventions there are a number of other files that are generally associated with a specific controller or model. M-Shift-up will take you directly to the primary file that is associated with the code location at point. M-Shift-down provides a list of other potential file options from which you can choose. For example, the screenshot below shows the results of pressing M-Shift-down when point is in the show method of the CompanyController.

Context Sensitive Switching Between Rails Buffers Example

Snippet Functionality

This functionality is actually derived from the
snippet.el package that provides another take on templating in emacs that closely mimics the templating functionality that is provided in TextMate. Snippet Example In the case of emacs-rails mode, these templates are tied to abbreviations. So if I type tcl and then tab while in a migration file, then a new line will be added to the table creation and my point will be placed in the area of the title of the column. When I am done updating the column name I can tab and I will be able to enter the type of column. I tab once again an I am out of the snippet editing mode. I think the rails-mode snippet integration is nicely done.

Invocation of Rake with Task Name Completion

C-c C-c r will prompt you in the minibuffer for the rake task that you want to run. Output of the rake task is then shown in a separate *ROutput* buffer. C-c / will toggle the showing or hiding of the output buffer. Rake tasks specific to testing are actually invoked via a separate command, C-c C-c t.

Invocation of Rake and Task Name Completion

For users that like to use the mouse and menus, all of the commands listed above can be accessed from the menu. I would also recommend taking a look at the two screencasts (here and here) that show emacs-rails mode in use, although there have been a number of changes to the package since the screencasts were made.

]]>
http://www.emacsblog.org/2007/06/10/package-faves-emacs-rails/feed/
Quick Tip: delete-blank-lines http://www.emacsblog.org/2007/06/07/quick-tip-delete-blank-lines/ http://www.emacsblog.org/2007/06/07/quick-tip-delete-blank-lines/#comments Thu, 07 Jun 2007 10:00:43 +0000 Ryan McGeary http://www.emacsblog.org/2007/06/07/quick-tip-delete-blank-lines/ The delete-blank-lines function is a simple yet handy tool to have in your bag of tricks. It is bound to C-x C-o. There isn’t a whole lot of magic surrounding it’s usage, so I’ll just quote the built-in help directly:

On blank line, delete all surrounding blank lines, leaving just one.
On isolated blank line, delete that one.
On nonblank line, delete any immediately following blank lines.

Before:
delete-blank-lines before
After:
delete-blank-lines after
 
]]>
http://www.emacsblog.org/2007/06/07/quick-tip-delete-blank-lines/feed/
GNU Emacs 22 Released http://www.emacsblog.org/2007/06/03/gnu-emacs-22-released/ http://www.emacsblog.org/2007/06/03/gnu-emacs-22-released/#comments Sun, 03 Jun 2007 06:25:09 +0000 Rob Christie http://www.emacsblog.org/2007/06/03/gnu-emacs-22-released/ Emacs 22 was officially released yesterday.

Emacs version 22 includes GTK+ toolkit support, enhanced mouse support, a new keyboard macro system, improved Unicode support, and drag-and-drop operation on X, plus many new modes and packages including a graphical user interface to GDB, Python mode, the mathematical tool Calc, the remote file editing system Tramp, and more.

You can get it here.

]]>
http://www.emacsblog.org/2007/06/03/gnu-emacs-22-released/feed/
Quick Tip: Managing ChangeLogs http://www.emacsblog.org/2007/05/29/quick-tip-managing-changelogs/ http://www.emacsblog.org/2007/05/29/quick-tip-managing-changelogs/#comments Tue, 29 May 2007 02:03:58 +0000 Ryan McGeary http://www.emacsblog.org/2007/05/29/quick-tip-managing-changelogs/ Ever wonder how people keep such organized ChangeLog files in the root of their source trees? I’m sure some are just anal enough to manually manage them. I know I’ve done so on smaller projects, but I find it too much of a hassle for anything larger.

So, what do people use on larger projects? Believe it or not, there are actually GNU conventions for styling these files, and emacs includes an add-log package to help adhere to these conventions.

The command add-change-log-entry-other-window (C-x 4 a) automatically adds a new entry to the closest change log file found up the parent directory hierarchy. If none exists, a new change log file is created in your current directory, and the formatting is organized for you:

ChangeLog Example

The command vc-update-change-log (C-x v a) finds the change log file and add entries from the recent version control logs. Apparently, this only works with RCS or CVS. For subversion, you can try vc-comment-to-change-log (Emacs 21) or log-edit-comment-to-change-log (Emacs 22), but this might require some customization to suit you.

To change the email address listed in your change log entries, edit the user-mail-address variable. To change the default change log file name, edit the change-log-default-name variable.

(setq user-mail-address "ryan@example.com")  ;; default: user@host
(setq change-log-default-name "CHANGELOG")   ;; default: ChangeLog

Some might say that keeping a ChangeLog file is defeated by public subversion repositories. I tend to agree for most circumstances, but there are some cases where a local, easily readable ChangeLog file is a good idea. Besides, it’s the cool thing to do.

The emacs manual has more information on change logs.

]]>
http://www.emacsblog.org/2007/05/29/quick-tip-managing-changelogs/feed/
Quick Tip: compilation-skip-threshold http://www.emacsblog.org/2007/05/22/quick-tip-compilation-skip-threshold/ http://www.emacsblog.org/2007/05/22/quick-tip-compilation-skip-threshold/#comments Tue, 22 May 2007 13:28:58 +0000 Rob Christie http://www.emacsblog.org/2007/05/22/quick-tip-compilation-skip-threshold/ compilation-mode has a nice feature so that you can skip over your info and warning level messages and jump right to those nasty errors. Set the variable compilation-skip-threshold to 2 so that M-n and M-p will jump to the next or previous error respectively. The other possible settings for this variable are:

2 — skip anything less than error
1 — skip anything less than warning, or
0 — don’t skip any messages.

Note that all messages not positively identified as warning or info are considered errors.

]]>
http://www.emacsblog.org/2007/05/22/quick-tip-compilation-skip-threshold/feed/
Package Faves: psvn http://www.emacsblog.org/2007/05/17/package-faves-psvn/ http://www.emacsblog.org/2007/05/17/package-faves-psvn/#comments Thu, 17 May 2007 14:11:28 +0000 Rob Christie http://www.emacsblog.org/2007/05/17/package-faves-psvn/ If you interact with a Subversion version controlled repository and you use emacs, then you are probably already using this package. However, I use this package every day, and if someone was just starting to use emacs, this would be on my short list of packages that must be installed.

psvn mode is similar to pcl-cvs for the Concurrent Version System (CVS). It is a frontend to the subversion client (svn). M-x svn-status will prompt you for the location of your working directory (or subdirectory). Once it is entered a new buffer, *svn-status* , will open up with a status of all files within that directory and any subdirectories. It essentially runs svn status -v. This view of your working copy of the repository shows the status of the files. You have the option of hiding unchanged files with the command _. You can mark multiple files to be committed, and then commit them with the command c which will in turn bring up an edit window where you can write the comment associated with your commit. Additionally, there are commands for diffing files, editing properties, and just about every other interaction you have with subversion. Be sure to check the following options:

  • svn-status-verbose – Setting this to nil will make M-x svn-status run without the -v option at the command line.
  • svn-status-hide-unmodified – Setting this automatically performs the toggle that you can do with _ when in the *svn-status* buffer, so that you only see files with a status that has changed in your working directory.

The package and its commands become an extension of the way you work with your files within emacs. It’s one of my favorites because it doesn’t get in the way of your normal process.

]]>
http://www.emacsblog.org/2007/05/17/package-faves-psvn/feed/
Emacs Key Bindings in Windows http://www.emacsblog.org/2007/05/10/emacs-key-bindings-in-windows/ http://www.emacsblog.org/2007/05/10/emacs-key-bindings-in-windows/#comments Thu, 10 May 2007 17:25:33 +0000 Ryan McGeary http://www.emacsblog.org/2007/05/10/emacs-key-bindings-in-windows/ XKeymacs Screenshot This might be old news to some, but it was new to me.

XKeymacs is a keyboard utility to realize emacs-like usability on all windows applications. With XKeymacs you can use emacs keybindings with any windows application. You can create a keyboard macro and assign any shortcut key too. You also get bash-like command completion in your DOS shell.

This may very well void the need for Emacs Keybindings in MS Word.

I only played with it briefly as I’m no longer Windows-bound, but my initial impressions were good. Here is a more comprehensive review of XKeymacs.

Once you install it, the bindings are global – they work in Windows Explorer, Microsoft Word, Excel, in text-boxes and combo-boxes – everywhere. As for applications that provide their own readline bindings (such as Gnu Emacs on Windows), you must setup key-binding exceptions…

]]>
http://www.emacsblog.org/2007/05/10/emacs-key-bindings-in-windows/feed/
A Little Bit of History http://www.emacsblog.org/2007/05/04/a-little-bit-of-history/ http://www.emacsblog.org/2007/05/04/a-little-bit-of-history/#comments Fri, 04 May 2007 20:43:44 +0000 Rob Christie http://www.emacsblog.org/2007/05/04/a-little-bit-of-history/ I just ran across this article. The Church of Emacs is a good read… no it’s not from alt.religion.emacs. The article is more of a history of emacs with some great references as well.

]]>
http://www.emacsblog.org/2007/05/04/a-little-bit-of-history/feed/
Quick Tip: dos2unix, et al http://www.emacsblog.org/2007/04/30/quick-tip-dos2unix-et-al/ http://www.emacsblog.org/2007/04/30/quick-tip-dos2unix-et-al/#comments Mon, 30 Apr 2007 01:25:27 +0000 Ryan McGeary http://www.emacsblog.org/2007/04/30/quick-tip-dos2unix-et-al/ I despise the fact that we live in a world with different end-of-line file formats. Windows/DOS uses CRLF, Unix uses LF, and Mac’s used to use CR1. Thankfully, Mac’s started to adopt the Unix format when OS X was released — if only Windows could do the same.

What I despise even more is that some editors seem to be incapable of determining the difference between a DOS and Unix file. There’s nothing worse than finding a once, perfect Unix file corrupted by a small section of lines with CRLFs while the rest of the file keeps only LFs. Most of the time, the blame can be placed on one’s editor configuration, but I also blame some editor defaults for not at least maintaining the format that the file was opened in. To be fair, most power-editors like emacs, vim, TextMate, etc behave “correctly” by default and keep the format that the file was opened in, but many others (unnamed) do not.

There’s not a whole lot we can do to avoid these problems without hounding our peers, but there are ways to fix these problems after they’re found.

Let’s fix the nastier problem first. When you find a file corrupted with half LFs and half CRLFs, strip out the ^M (CR) characters with a quick search and replace. Run M-% (query-replace) and substitute C-q C-m with nothing. C-q runs quoted-insert and is useful for inserting control characters (e.g. ^M, entered as C-m). Afterwards hit the exclamation point (!) to tell query-replace to replace all matches with no questions.

Other times, you will run into DOS formatted files and will just want to convert them to Unix format for consistency sake. To do this, open the buffer and run C-x <RET> f then enter unix or undecided-unix when prompted for the new coding system. This runs set-buffer-file-coding-system and the result is very similar to running dos2unix myfile.txt at the command line.

1 CR is Carriage Return. LF is Line Feed (aka Newline).

]]>
http://www.emacsblog.org/2007/04/30/quick-tip-dos2unix-et-al/feed/
Package Faves: iswitchb http://www.emacsblog.org/2007/04/24/package-faves-iswitchb/ http://www.emacsblog.org/2007/04/24/package-faves-iswitchb/#comments Tue, 24 Apr 2007 14:03:14 +0000 Rob Christie http://www.emacsblog.org/2007/04/24/package-faves-iswitchb/ This is the start of a series on our favorite emacs packages. Some of these packages are part of emacs core, some aren’t (but we could argue should be). I use iswitchb-mode at least a hundred times a day. iswitchb is one of the features of emacs that I rave about whenever I try to explain why I am still using a 30-year old editor. From the package commentary:

As you type in a substring, the list of buffers currently matching the substring is displayed as you type. The list is ordered so that the most recent buffers visited come at the start of the list. The buffer at the start of the list will be the one visited when you press return. By typing more of the substring, the list is narrowed down so that gradually the buffer you want will be at the top of the list. Alternatively, you can use C-s and C-r to rotate buffer names in the list until the one you want is at the top of the list. Completion is also available so that you can see what is common to all of the matching buffers as you type.

The key stroke C-x b brings up the iswitchb mini-buffer, and with a few key strokes the file you want is open. My normal mode of operation is to load the project I am working on into the emacs file name cache, and then use iswitchb to switch between the files. In order to use iswitchb in this manner you will need iswitchb-fc, and a means for populating the file name cache.

iswitchb in action, 1

Some of the nice features of iswitchb include filtering out buffers that you don’t want to see, and limiting how many files are shown in the minibuffer by customizing the iswitchb-max-to-show variable. Additionally, you can kill a buffer from within iswitchb by typing C-k. The following is a snippet from my .emacs:

;;============================================================
;; iswitchb
;;============================================================
(require 'iswitchb)  
(iswitchb-mode 1)
;;============================================================
;; iswitchb ignores
;;============================================================
(add-to-list 'iswitchb-buffer-ignore "^ ")
(add-to-list 'iswitchb-buffer-ignore "*Messages*")
(add-to-list 'iswitchb-buffer-ignore "*ECB")
(add-to-list 'iswitchb-buffer-ignore "*Buffer")
(add-to-list 'iswitchb-buffer-ignore "*Completions")
(add-to-list 'iswitchb-buffer-ignore "*ftp ")
(add-to-list 'iswitchb-buffer-ignore "*bsh")
(add-to-list 'iswitchb-buffer-ignore "*jde-log")
(add-to-list 'iswitchb-buffer-ignore "^[tT][aA][gG][sS]$")
;;============================================================
;; iswitchb-fc
;;============================================================
(require 'filecache)
(load "iswitchb-fc")

There are other packages out there that do the same thing and even more. Even though I love iswitchb, I have been meaning to try icicles and/or the ido package since they seem to provide the same functionality on steroids. If you are an advocate of one of these other packages, I hope to hear from you. If you are not using any of these packages on an hourly basis then start today. The package is indispensable.

]]>
http://www.emacsblog.org/2007/04/24/package-faves-iswitchb/feed/
Quick Tip: light-symbol-mode http://www.emacsblog.org/2007/04/17/quick-tip-light-symbol-mode/ http://www.emacsblog.org/2007/04/17/quick-tip-light-symbol-mode/#comments Tue, 17 Apr 2007 12:24:08 +0000 Rob Christie http://www.emacsblog.org/2007/04/17/quick-tip-light-symbol-mode/ light-symbol mode in action I ran across this package on gnu.emacs.sources recently. If you enable light-symbol-mode in a buffer and pause on a symbol, then Emacs will highlight all other occurrences of the symbol in the buffer. When you move point the highlighting goes away.

]]>
http://www.emacsblog.org/2007/04/17/quick-tip-light-symbol-mode/feed/
Highlight the Current Line http://www.emacsblog.org/2007/04/09/highlight-the-current-line/ http://www.emacsblog.org/2007/04/09/highlight-the-current-line/#comments Mon, 09 Apr 2007 00:28:02 +0000 Ryan McGeary http://www.emacsblog.org/2007/04/09/highlight-the-current-line/ There are several ways to customize the display of the cursor. I happen to prefer highlighting the current line as a visual cue to keep my eye focused on where I’m working.

Highlight Current Line, 1

Before a few days ago, I had not realized there were so many packages to accomplish this, but let’s review a few.

highlight-current-line

I’ve used highlight-current-line for years. It’s a very adequate package. To enable, put highlight-current-line.el in your load-path and add the following to your emacs initialization:

(require 'highlight-current-line)
(highlight-current-line-on t)
 
;; To customize the background color
(set-face-background 'highlight-current-line-face "light yellow")

hl-line

To my surprise, I learned that GNU Emacs 21 introduced a built-in hl-line-mode. To enable it globally, add this to your emacs initialization:

(global-hl-line-mode 1)
 
;; To customize the background color
(set-face-background 'hl-line "#330")  ;; Emacs 22 Only
;(set-face-background 'highlight "#330")  ;; Emacs 21 Only

(Note the difference between customizing the color in Emacs 21 and 22.)

highline

Highline was inspired by hl-line, highlight-current-line, and linemenu. It is supposedly the best option for the XEmacs contingent. To enable, put highline.el in your load-path and add the following to your emacs initialization:

(require 'highline)
(highline-mode 1)
 
;; To customize the background color
(set-face-background 'highline-face "#222")

Even More

Other packages such as hl-line+, col-highlight, and crosshairs have extra features such as idle-timers, line flashing, and column highlighting. I found most of these a little over-the-top, but if your personal preferences differ, give them a try.

Background Colors

I use a black emacs background and prefer a deep-dark gray like #111 for highlighting to keep things subtle.

Highlight Current Line, 2

When on a white background, I prefer a light yellow such as lemon chiffon or light goldenrod yellow. What colors do you like?

Highlight Current Line, 3

Conclusion

Up until this article, I used highlight-current-line, but I just switched to using the built-in hl-line. It’s now one less dependency I need to manage, and hl-line happens to work better in conjuction with visible bookmarks.

Bibliography

1 EmacsWiki, HighlightCurrentLine — libraries that highlight the current line of characters.

2 GNU Emacs Manual, Displaying the Cursor

3 EmacsWiki, HighlightCurrentColumn — libraries that highlight the current column of characters.

]]>
http://www.emacsblog.org/2007/04/09/highlight-the-current-line/feed/
Keyboard Macros in the Wild: The Mundane SQL Fix http://www.emacsblog.org/2007/04/05/keyboard-macros-in-the-wild-the-mundane-sql-fix/ http://www.emacsblog.org/2007/04/05/keyboard-macros-in-the-wild-the-mundane-sql-fix/#comments Thu, 05 Apr 2007 20:32:29 +0000 Rob Christie http://www.emacsblog.org/2007/04/05/keyboard-macros-in-the-wild-the-mundane-sql-fix/ When you first start using emacs, there is normally someone who says something like keyboard macros in emacs rock. At that moment in time, they show you some quick little example, it looks neat but it probably doesn’t register with the true magnitude that it should. This series shows examples of macros “in the wild”. I hope it helps reinforce the value of the keyboard macro.

Problem

I have 80 lines of sql code that need to be updated with new unique ids starting at 500 and a new group id of 5. An example of the original sql is below:

INSERT INTO group_perms (id, groupid, permid) VALUES (248, 4, 1); 
INSERT INTO group_perms (id, groupid, permid) VALUES (249, 4, 1); 
INSERT INTO group_perms (id, groupid, permid) VALUES (250, 4, 1); 
INSERT INTO group_perms (id, groupid, permid) VALUES (251, 4, 1);

Macro

My solution was to move point to the start of the unique id 248 in the first row and to set a goal column (C-x C-n) at column 65 (this location). I then created the following macro by calling M-5 M-0 M-0 M-x kmacro-start-macro-or-insert-counter (in my case M-x kmacro-start-macro-or-insert-counter is bound to S-f7). This starts recording the macro and initializes the counter to 500. The macro I recorded is shown below. The macro kills the existing value of the unique id, and then replaces it with the value of the counter. The call to kmacro-start-macro-or-insert-counter also increments the counter. I then move to the next line which because of setting the goal column brings me back to column 65 which is the beginning of the next unique id that I need to replace.

C-SPC			;; set-mark-command
M-f			;; forward-word
C-w			;; kill-region
<S-f7>			;; kmacro-start-macro-or-insert-counter
M-f			;; forward-word
DEL			;; backward-delete-char-untabify
5			;; self-insert-command
C-n			;; next-line

I then run the macro for each line by holding down my f7 key that is bound to M-x kmacro-end-or-call-macro. The total number of key chords for the entire process is around 15. Here is a sample of the resulting output:

INSERT INTO group_perms (id, groupid, permid) VALUES (500, 5, 1); 
INSERT INTO group_perms (id, groupid, permid) VALUES (501, 5, 1); 
INSERT INTO group_perms (id, groupid, permid) VALUES (502, 5, 1); 
INSERT INTO group_perms (id, groupid, permid) VALUES (503, 5, 1);

Since the macro has saved me much more time than if I had done it line by line, I decide to get a cup of coffee. In all seriousness though, the macro way is faster than the alternatives.

Note: I think the kmacro-start-or-insert-counter and kmacro-end-or-call-macro are Emacs 22 specific functions, but you could do the same thing in Emacs 21 with a few more key strokes. Also, by default Emacs 22 binds the fancy start and end macro functions to f3 and f4. I have f3 and f4 bound to other functions, so I use S-f7 and f7.

]]>
http://www.emacsblog.org/2007/04/05/keyboard-macros-in-the-wild-the-mundane-sql-fix/feed/
IBM Emacs Tutorial, Part I http://www.emacsblog.org/2007/04/02/ibm-emacs-tutorial-part-i/ http://www.emacsblog.org/2007/04/02/ibm-emacs-tutorial-part-i/#comments Mon, 02 Apr 2007 14:08:53 +0000 Ryan McGeary http://www.emacsblog.org/2007/04/02/ibm-emacs-tutorial-part-i/ Michael Stutz recently wrote Part I of a new new series at IBM called Emacs editing environment. The first is Learn the basics of Emacs.

This first tutorial is definitely geared toward the emacs newcomer. There is a lot of overlap with the built-in emacs tutorial (C-h t), but different mediums are good for teaching different kinds of people. Also, reinforcement of the basics is good for a budding emacs hacker.

Note: IBM requires free registration to read the tutorial.

]]>
http://www.emacsblog.org/2007/04/02/ibm-emacs-tutorial-part-i/feed/
Quick Tip: Line Numbering http://www.emacsblog.org/2007/03/29/quick-tip-line-numbering/ http://www.emacsblog.org/2007/03/29/quick-tip-line-numbering/#comments Thu, 29 Mar 2007 12:26:13 +0000 Rob Christie http://www.emacsblog.org/2007/03/29/quick-tip-line-numbering/ linum I frequent the gnu.emacs.sources news group as one route to finding out about new packages. linenum.el came across the list recently. The package displays line numbers on the left side of your buffer. The author indicates that it is an alternative to setnu.el with the benefit that it works incrementally and can handle large files. It seems like one of those packages that is nice to have in your bag of tricks. Of course, you may just want the current line number in your modeline by using the M-x line-number-mode command. You can set it by default with the following line in your .emacs file.

(line-number-mode 1)

And in case you forgot (or didn’t know), M-g M-g (or M-g g) is the key binding for M-x goto-line in Emacs 22.

]]>
http://www.emacsblog.org/2007/03/29/quick-tip-line-numbering/feed/