http://www.emacsblog.org/

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head profile="http://gmpg.org/xfn/11">
<meta name="microid" content="6e0900aea6d5e70116833469fde58a8c6bc81873" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>M-x all-things-emacs</title>

<meta name="generator" content="WordPress 2.1.3" /> <!-- leave this for stats -->

<link rel="stylesheet" href="http://www.emacsblog.org/wp-content/themes/Cutline-EmacsBlog/style.css" type="text/css" media="screen" />
<link rel="alternate" type="application/rss+xml" title="M-x all-things-emacs RSS Feed" href="http://www.emacsblog.org/feed/" />
<link rel="pingback" href="http://www.emacsblog.org/xmlrpc.php" />

	<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://www.emacsblog.org/xmlrpc.php?rsd" />
</head>
<body>

<div id="container">

	<div id="masthead"><h1><a href="http://www.emacsblog.org">M-x all-things-emacs</a></h1></div>

	<ul id="nav">
		<li><a class="current" href="http://www.emacsblog.org">front page</a></li>
		<li><a href="http://www.emacsblog.org/archives/">archives</a></li>
		<li><a href="http://www.emacsblog.org/about/">about</a></li>
		<li><a href="http://www.emacsblog.org/sitemap/">sitemap</a></li>
		<li class="rss"><a href="http://www.emacsblog.org/feed/">RSS</a></li>
	</ul>
	
        <div id="header_img">
        </div>
	<div id="content_box">
	
		<div id="content" class="posts">

					
								
			<h2><a href="http://www.emacsblog.org/2007/04/17/quick-tip-light-symbol-mode/" rel="bookmark" title="Permanent Link to Quick Tip: light-symbol-mode">Quick Tip: light-symbol-mode</a></h2>
			<h4>April 17th, 2007 by Rob Christie &middot; <a href="http://www.emacsblog.org/2007/04/17/quick-tip-light-symbol-mode/#respond" title="Comment on Quick Tip: light-symbol-mode">No Comments</a></h4>
			<div class="entry">
					<p><img src="/wp-content/uploads/2007/04/light-symbol.png" class="right off" align="right" title="light-symbol mode in action" alt="light-symbol mode in action" width="287" height="100" /> I ran across this package on  <a href="http://groups.google.com/group/gnu.emacs.sources/browse_thread/thread/2d5e8e101df6e502?hl=en">gnu.emacs.sources</a> recently. If you enable <code>light-symbol-mode</code> 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.</p>

			</div>	
			<p class="tagged"><span class="add_comment"><a href="http://www.emacsblog.org/2007/04/17/quick-tip-light-symbol-mode/#respond" title="Comment on Quick Tip: light-symbol-mode">&rarr; No Comments</a></span><strong>Tags:</strong> <a href="http://www.emacsblog.org/tags/misc/" title="View all posts in misc" rel="category tag">misc</a> &middot;  <a href="http://www.emacsblog.org/tags/quick/" title="View all posts in quick" rel="category tag">quick</a></p>
		
								
			<h2><a href="http://www.emacsblog.org/2007/04/09/highlight-the-current-line/" rel="bookmark" title="Permanent Link to Highlight the Current Line">Highlight the Current Line</a></h2>
			<h4>April 9th, 2007 by Ryan McGeary &middot; <a href="http://www.emacsblog.org/2007/04/09/highlight-the-current-line/#comments" title="Comment on Highlight the Current Line">10 Comments</a></h4>
			<div class="entry">
					<p>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&#8217;m working.</p>

	<p><img src="http://www.emacsblog.org/wp-content/uploads/2007/04/hl-line-1.png" class="center on" title="Highlight Current Line, 1" alt="Highlight Current Line, 1" /></p>

	<p>Before a few days ago, I had not realized there were so many packages to accomplish this, but let&#8217;s review a few.   <a href="http://www.emacsblog.org/2007/04/09/highlight-the-current-line/#more-64" class="more-link">Keep reading &rarr;</a></p>			</div>	
			<p class="tagged"><span class="add_comment"><a href="http://www.emacsblog.org/2007/04/09/highlight-the-current-line/#comments" title="Comment on Highlight the Current Line">&rarr; 10 Comments</a></span><strong>Tags:</strong> <a href="http://www.emacsblog.org/tags/misc/" title="View all posts in misc" rel="category tag">misc</a> &middot;  <a href="http://www.emacsblog.org/tags/reviews/" title="View all posts in reviews" rel="category tag">reviews</a></p>
		
								
			<h2><a href="http://www.emacsblog.org/2007/04/05/keyboard-macros-in-the-wild-the-mundane-sql-fix/" rel="bookmark" title="Permanent Link to Keyboard Macros in the Wild: The Mundane SQL Fix">Keyboard Macros in the Wild: The Mundane SQL Fix</a></h2>
			<h4>April 5th, 2007 by Rob Christie &middot; <a href="http://www.emacsblog.org/2007/04/05/keyboard-macros-in-the-wild-the-mundane-sql-fix/#comments" title="Comment on Keyboard Macros in the Wild: The Mundane SQL Fix">12 Comments</a></h4>
			<div class="entry">
					<p>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&#8217;t register with the true magnitude that it should. This <a href="http://www.emacsblog.org/tags/kb-macros/">series</a> shows examples of macros &#8220;in the wild&#8221;. I hope it helps reinforce the value of the keyboard macro. <a href="http://www.emacsblog.org/2007/04/05/keyboard-macros-in-the-wild-the-mundane-sql-fix/#more-66" class="more-link">Keep reading &rarr;</a></p>			</div>	
			<p class="tagged"><span class="add_comment"><a href="http://www.emacsblog.org/2007/04/05/keyboard-macros-in-the-wild-the-mundane-sql-fix/#comments" title="Comment on Keyboard Macros in the Wild: The Mundane SQL Fix">&rarr; 12 Comments</a></span><strong>Tags:</strong> <a href="http://www.emacsblog.org/tags/tips/" title="View all posts in tips" rel="category tag">tips</a> &middot;  <a href="http://www.emacsblog.org/tags/kb-macros/" title="View all posts in kb-macros" rel="category tag">kb-macros</a></p>
		
								
			<h2><a href="http://www.emacsblog.org/2007/04/02/ibm-emacs-tutorial-part-i/" rel="bookmark" title="Permanent Link to IBM Emacs Tutorial, Part I">IBM Emacs Tutorial, Part I</a></h2>
			<h4>April 2nd, 2007 by Ryan McGeary &middot; <a href="http://www.emacsblog.org/2007/04/02/ibm-emacs-tutorial-part-i/#comments" title="Comment on IBM Emacs Tutorial, Part I">1 Comment</a></h4>
			<div class="entry">
					<p>Michael Stutz recently wrote <a href="http://www-128.ibm.com/developerworks/edu/au-dw-au-emacs1-i.html">Part I</a> of a new new series at <span class="caps">IBM</span> called <em>Emacs editing environment</em>.  The first is <a href="http://www-128.ibm.com/developerworks/edu/au-dw-au-emacs1-i.html">Learn the basics of Emacs</a>.</p>

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

	<p><em>Note: <span class="caps">IBM</span> requires free registration to read the tutorial.</em></p>			</div>	
			<p class="tagged"><span class="add_comment"><a href="http://www.emacsblog.org/2007/04/02/ibm-emacs-tutorial-part-i/#comments" title="Comment on IBM Emacs Tutorial, Part I">&rarr; 1 Comment</a></span><strong>Tags:</strong> <a href="http://www.emacsblog.org/tags/news/" title="View all posts in news" rel="category tag">news</a> &middot;  <a href="http://www.emacsblog.org/tags/newbie/" title="View all posts in newbie" rel="category tag">newbie</a></p>
		
								
			<h2><a href="http://www.emacsblog.org/2007/03/29/quick-tip-line-numbering/" rel="bookmark" title="Permanent Link to Quick Tip: Line Numbering">Quick Tip: Line Numbering</a></h2>
			<h4>March 29th, 2007 by Rob Christie &middot; <a href="http://www.emacsblog.org/2007/03/29/quick-tip-line-numbering/#comments" title="Comment on Quick Tip: Line Numbering">2 Comments</a></h4>
			<div class="entry">
					<p><img src="/wp-content/uploads/2007/03/linum.png" class="right off" align="right" title="linum" alt="linum" width="281" height="147" /> I frequent the <a href="http://groups.google.com/group/gnu.emacs.sources/topics?lnk=gschg">gnu.emacs.sources</a> news group as one route to finding out about new packages. <a href="http://groups.google.com/group/gnu.emacs.sources/browse_thread/thread/31a679d4c9b49f06?hl=en">linenum.el</a> 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 <a href="http://www.emacswiki.org/cgi-bin/wiki/setnu.el">setnu.el</a> 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 <code>M-x line-number-mode</code> command. You can set it by default with the following line in your .emacs file.</p>


<div class="wp_syntax"><div class="code"><pre class="lisp"><span style="color: #66cc66;">&#40;</span>line-number-mode <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span></pre></div></div>


	<p>And in case you forgot (or didn&#8217;t know), <code>M-g M-g</code> (or <code>M-g g</code>) is the key binding for <code>M-x goto-line</code> in Emacs 22.</p>

 			</div>	
			<p class="tagged"><span class="add_comment"><a href="http://www.emacsblog.org/2007/03/29/quick-tip-line-numbering/#comments" title="Comment on Quick Tip: Line Numbering">&rarr; 2 Comments</a></span><strong>Tags:</strong> <a href="http://www.emacsblog.org/tags/tips/" title="View all posts in tips" rel="category tag">tips</a> &middot;  <a href="http://www.emacsblog.org/tags/quick/" title="View all posts in quick" rel="category tag">quick</a></p>
		
								
			<h2><a href="http://www.emacsblog.org/2007/03/26/newbie-tip-isearch-word-yank/" rel="bookmark" title="Permanent Link to Newbie Tip: isearch Word Yank">Newbie Tip: isearch Word Yank</a></h2>
			<h4>March 26th, 2007 by Ryan McGeary &middot; <a href="http://www.emacsblog.org/2007/03/26/newbie-tip-isearch-word-yank/#comments" title="Comment on Newbie Tip: isearch Word Yank">3 Comments</a></h4>
			<div class="entry">
					<p>Our <a href="http://www.emacsblog.org/tags/newbie">newbie tips</a> are our way of expressing emacs features we might otherwise take for granted.  We hope they help beginners climb the learning curve faster.  This particular tip is one that I wish I knew far sooner when I first started using emacs.</p>

	<p>Incremental searching with <code>isearch-forward</code> and <code>isearch-backward</code> (<code>C-s</code> and <code>C-r</code>) is crucial in day-to-day and even minute-by-minute emacs usage.  Maybe you want to find all uses of a particular variable name, or maybe you want to make sure you&#8217;re not repeating the same word in a piece of literature.  Let&#8217;s dive in with an example:</p>

	<p>Suppose we want to search for the word &#8220;lorem&#8221; in the folowing paragraph:</p>

	<p><img src="http://www.emacsblog.org/wp-content/uploads/2007/03/isearch-yank-next-1.png" class="center on" title="Step 1: Incremental Search Yank" alt="Step 1: Incremental Search Yank" /></p>

	<p>We could type <code>C-s l o r e m</code>, but seeing as our point is already at one particular instance of &#8220;lorem,&#8221; we can instead enter <code>C-s C-w</code>.  The result is the same.  When in isearch-mode, <code>C-w</code> yanks the next word in the buffer and appends it to the end of the current search string:</p>

	<p><img src="http://www.emacsblog.org/wp-content/uploads/2007/03/isearch-yank-next-2.png" class="center on" title="Step 2: Incremental Search Yank" alt="Step 2: Incremental Search Yank" /></p>

	<p>Now suppose we want to search for instances of &#8220;lorem ipsum.&#8221;  Just hit <code>C-w</code> again:</p>

	<p><img src="http://www.emacsblog.org/wp-content/uploads/2007/03/isearch-yank-next-3.png" class="center on" title="Step 3: Incremental Search Yank" alt="Step 3: Incremental Search Yank" /></p>

	<p>Awesome, we just saved 9 key presses &#8212; a productivity boost.</p>

	<p><code>C-w</code> is part of the <code>isearch-mode-map</code>.  There are many isearch modifiers.  Here are some that I use most frequently:</p>

	<ul>
		<li><code>C-s</code> &#8211; to search again forward</li>
		<li><code>C-r</code> &#8211; to search again, but backward</li>
		<li><code>C-w</code> &#8211; to yank next word or character in buffer onto the end of the search string, and search for it</li>
		<li><code>M-y</code> &#8211; to yank last killed text onto end of search string and search for it</li>
		<li><code>M-r</code> &#8211; to toggle regular-expression mode</li>
		<li><code>M-e</code> &#8211; to edit the search string in the minibuffer</li>
	</ul>

	<p>For a full listing of available isearch modifier keys, review the help for isearch (<code>C-h f isearch-forward</code>).  It is also possible to add your own functions to the <code>isearch-mode-map</code>.  Last month, we referenced a way to <a href="http://www.emacsblog.org/2007/02/27/quick-tip-add-occur-to-isearch/">add occur to isearch</a>.</p>			</div>	
			<p class="tagged"><span class="add_comment"><a href="http://www.emacsblog.org/2007/03/26/newbie-tip-isearch-word-yank/#comments" title="Comment on Newbie Tip: isearch Word Yank">&rarr; 3 Comments</a></span><strong>Tags:</strong> <a href="http://www.emacsblog.org/tags/tips/" title="View all posts in tips" rel="category tag">tips</a> &middot;  <a href="http://www.emacsblog.org/tags/newbie/" title="View all posts in newbie" rel="category tag">newbie</a> &middot;  <a href="http://www.emacsblog.org/tags/quick/" title="View all posts in quick" rel="category tag">quick</a> &middot;  <a href="http://www.emacsblog.org/tags/isearch/" title="View all posts in isearch" rel="category tag">isearch</a></p>
		
								
			<h2><a href="http://www.emacsblog.org/2007/03/22/bookmark-mania/" rel="bookmark" title="Permanent Link to Bookmark Mania">Bookmark Mania</a></h2>
			<h4>March 22nd, 2007 by Rob Christie &middot; <a href="http://www.emacsblog.org/2007/03/22/bookmark-mania/#comments" title="Comment on Bookmark Mania">6 Comments</a></h4>
			<div class="entry">
					<p>Bookmarks are one of those features that I have used, but have been on my list to learn more about.  This week I decided to bump it off my list and pass along my notes.  There are a number of different packages that can be used for bookmarking. I will discuss three. <a href="http://www.emacsblog.org/2007/03/22/bookmark-mania/#more-57" class="more-link">Keep reading &rarr;</a></p>			</div>	
			<p class="tagged"><span class="add_comment"><a href="http://www.emacsblog.org/2007/03/22/bookmark-mania/#comments" title="Comment on Bookmark Mania">&rarr; 6 Comments</a></span><strong>Tags:</strong> <a href="http://www.emacsblog.org/tags/reviews/" title="View all posts in reviews" rel="category tag">reviews</a></p>
		
								
			<h2><a href="http://www.emacsblog.org/2007/03/17/quick-tip-set-goal-column/" rel="bookmark" title="Permanent Link to Quick Tip: set-goal-column">Quick Tip: set-goal-column</a></h2>
			<h4>March 17th, 2007 by Ryan McGeary &middot; <a href="http://www.emacsblog.org/2007/03/17/quick-tip-set-goal-column/#comments" title="Comment on Quick Tip: set-goal-column">6 Comments</a></h4>
			<div class="entry">
					<p>On the surface, it might not sound like editing columns of text is something that happens a lot, but I find myself doing it fairly often.  A quick way to enter different values on each line down a column is to use <code>set-goal-column</code> (bound to <code>C-x C-n</code>).</p>

	<p>Let&#8217;s say we have a block of text like the following comma-separated list.  We&#8217;d like to enter a different value in the second field of each line.  First we position the point on the first line between the two commas.  This is at column position 6 (emacs starts counting columns at zero).</p>

	<p><img src="http://www.emacsblog.org/wp-content/uploads/2007/03/set-goal-column-1.png" class="center on" title="Step 1: set-goal-column" alt="Step 1: set-goal-column" /></p>

	<p>Now let&#8217;s input our first text field and hit <code>C-n</code> to go to the next line.</p>

	<p><img src="http://www.emacsblog.org/wp-content/uploads/2007/03/set-goal-column-2.png" class="center on" title="Step 2: set-goal-column" alt="Step 2: set-goal-column" /></p>

	<p>It does what you might expect.  Because our first field pushed us out to column position 23, when we went to the next line our point was placed at the end of the second line.  To enter a new field on line 2, we&#8217;ll have to first jump back to column 6 manually.  That&#8217;s no fun.  Let&#8217;s start over and use <code>set-goal-column</code> instead.</p>

	<p><img src="http://www.emacsblog.org/wp-content/uploads/2007/03/set-goal-column-1.png" class="center on" title="Step 1: set-goal-column" alt="Step 1: set-goal-column" /></p>

	<p>Now, before we enter our first field, we&#8217;ll first hit <code>C-x C-n</code>.  Setting a goal column sets the current horizontal position as a goal for <code>C-n</code> and <code>C-p</code>.  Let&#8217;s see what happens when we re-input our first field and hit <code>C-n</code>.</p>

	<p><img src="http://www.emacsblog.org/wp-content/uploads/2007/03/set-goal-column-3.png" class="center on" title="Step 3: set-goal-column" alt="Step 3: set-goal-column" /></p>

	<p>Perfect.  We&#8217;re right were we need to be.  Quickly, we finish our text entry down the column:</p>

	<p><img src="http://www.emacsblog.org/wp-content/uploads/2007/03/set-goal-column-4.png" class="center on" title="Step 4: set-goal-column" alt="Step 4: set-goal-column" /></p>

	<p>To turn off the goal column, pass a non-nil argument to <code>set-goal-column</code> (i.e. <code>C-u C-x C-n</code>).</p>

	<p><strong>Note:</strong>  When you run <code>set-goal-column</code> for the first time, you’ll receive a warning that the function is disabled. You can either follow the built-in instructions and customizations to enable the function, or you can add the following to your emacs initialization.</p>


<div class="wp_syntax"><div class="code"><pre class="lisp"><span style="color: #66cc66;">&#40;</span>put 'set-goal-column 'disabled <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span></pre></div></div>


	<p>This exercise provided a nice way to manage a column of text with different values on each line.  When the task is more repetitive, emacs rectangles come in handy.  We&#8217;ll make rectangles a future topic of discussion.</p>			</div>	
			<p class="tagged"><span class="add_comment"><a href="http://www.emacsblog.org/2007/03/17/quick-tip-set-goal-column/#comments" title="Comment on Quick Tip: set-goal-column">&rarr; 6 Comments</a></span><strong>Tags:</strong> <a href="http://www.emacsblog.org/tags/tips/" title="View all posts in tips" rel="category tag">tips</a> &middot;  <a href="http://www.emacsblog.org/tags/quick/" title="View all posts in quick" rel="category tag">quick</a></p>
		
								
			<h2><a href="http://www.emacsblog.org/2007/03/15/newbie-tip-re-builder/" rel="bookmark" title="Permanent Link to Quick Tip: re-builder">Quick Tip: re-builder</a></h2>
			<h4>March 15th, 2007 by Rob Christie &middot; <a href="http://www.emacsblog.org/2007/03/15/newbie-tip-re-builder/#comments" title="Comment on Quick Tip: re-builder">5 Comments</a></h4>
			<div class="entry">
					<p>Have you ever wanted to test out regular expressions in emacs? Until I found out about <code>re-builder</code> I used to run <code>M-x isearch-forward-regexp</code> (also bound to <code>C-M-s</code>) in a buffer until I figured out the expression I needed. This works but just having <code>M-x re-builder</code> in your bag of tricks helps. In the words of the author, <a href="http://cvs.savannah.gnu.org/viewcvs/*checkout*/emacs/emacs/lisp/emacs-lisp/re-builder.el">Detlev Zundel</a></p>

	<blockquote>
		<p>When I have to come up with regular expressions that are more complex than simple string matchers, especially if they contain sub expressions, I find myself spending quite some time in the `development cycle&#8217;.  `re-builder&#8217; aims to shorten this time span so I can get on with the more interesting bits. With it you can have immediate visual feedback about how well the regexp behaves to your expectations on the intended data.</p>
	</blockquote>

	<p><code>re-builder</code> supports a number of different input forms for the regular expression. The input type can be changed by <code>C-c TAB</code> when you are in this mode. </p>

	<h3>Read Regexp Syntax in re-builder</h3>

	<p><img src="http://www.emacsblog.org/wp-content/uploads/2007/03/re-builder.png" class="on" title="re-builder read syntax example" alt="re-builder read syntax example" /></p>

	<p>Another nice feature is the highlighting of the different subexpression matches. <a href="http://cvs.xemacs.org/viewcvs.cgi/XEmacs/packages/xemacs-packages/re-builder/re-builder.el?rev=1.5&#38;content-type=text/vnd.viewcvs-markup">Xemacs</a> has added perl regular expression support to <code>re-builder</code> as noted on the <a href="http://www.emacswiki.org/cgi-bin/wiki/ReBuilder">emacs wiki</a>. I hope this gets added back into <span class="caps">GNU</span> emacs.  </p>			</div>	
			<p class="tagged"><span class="add_comment"><a href="http://www.emacsblog.org/2007/03/15/newbie-tip-re-builder/#comments" title="Comment on Quick Tip: re-builder">&rarr; 5 Comments</a></span><strong>Tags:</strong> <a href="http://www.emacsblog.org/tags/tips/" title="View all posts in tips" rel="category tag">tips</a> &middot;  <a href="http://www.emacsblog.org/tags/quick/" title="View all posts in quick" rel="category tag">quick</a></p>
		
								
			<h2><a href="http://www.emacsblog.org/2007/03/12/tab-completion-everywhere/" rel="bookmark" title="Permanent Link to Tab Completion Everywhere">Tab Completion Everywhere</a></h2>
			<h4>March 12th, 2007 by Ryan McGeary &middot; <a href="http://www.emacsblog.org/2007/03/12/tab-completion-everywhere/#comments" title="Comment on Tab Completion Everywhere">5 Comments</a></h4>
			<div class="entry">
					<p>I am addicted to tab completion in the minibuffer and in shells like bash &#8212; so much so that I want it everywhere.   By default, emacs comes with <code>dabbrev-expand</code> (bound to <code>M-/</code>).  When invoked after typing the first few letters of a word, <code>dabbrev-expand</code> first searches the current buffer and then other open buffers for possible completions.  Completions are expanded inline on each subsequent call.  This is pretty close to what we want, but it&#8217;s not the <span class="caps">TAB</span> key.  We could rebind <code>dabbrev-expand</code> to <span class="caps">TAB</span>, but then how would we indent a line?  Let&#8217;s apply a little bit of elisp smarts.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="lisp"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> indent-or-expand <span style="color: #66cc66;">&#40;</span>arg<span style="color: #66cc66;">&#41;</span>
  <span style="color: #ff0000;">&quot;Either indent according to mode, or expand the word preceding
point.&quot;</span>
  <span style="color: #66cc66;">&#40;</span>interactive <span style="color: #ff0000;">&quot;*P&quot;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">and</span>
       <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">or</span> <span style="color: #66cc66;">&#40;</span>bobp<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>= ?w <span style="color: #66cc66;">&#40;</span>char-syntax <span style="color: #66cc66;">&#40;</span>char-before<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">or</span> <span style="color: #66cc66;">&#40;</span>eobp<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> <span style="color: #66cc66;">&#40;</span>= ?w <span style="color: #66cc66;">&#40;</span>char-syntax <span style="color: #66cc66;">&#40;</span>char-after<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>dabbrev-expand arg<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>indent-according-to-mode<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>


	<p>If we&#8217;re at the end of a word boundary, this function invokes <code>dabrev-expand</code>; otherwise, <code>indent-according-to-mode</code>.  To avoid errors, the <code>bobp</code> and <code>eobp</code> calls are there to make sure we&#8217;re not looking for characters before or after the buffer&#8217;s boundary.  An interactive prefix argument is optional and is passed directly to dabbrev (<code>C-h f dabbrev-expand</code> for more info).</p>

	<blockquote>
		<p>A positive prefix argument, N, says to take the Nth backward distinct possibility.  A negative argument says search forward. </p>
	</blockquote>

	<p>I find that this makes for some wicked-cool behavior.  For me, it seems intuitive and natural.  But wait, we haven&#8217;t bound this to <span class="caps">TAB</span> yet.  Let&#8217;s do that now.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="lisp"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> my-tab-fix <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>local-set-key <span style="color: #66cc66;">&#91;</span>tab<span style="color: #66cc66;">&#93;</span> 'indent-or-expand<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>add-hook 'c-mode-hook          'my-tab-fix<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>add-hook 'sh-mode-hook         'my-tab-fix<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>add-hook 'emacs-lisp-mode-hook 'my-tab-fix<span style="color: #66cc66;">&#41;</span>
<span style="color: #808080; font-style: italic;">;; more mode hooks, yada yada, etc ...</span></pre></td></tr></table></div>


	<p>To avoid strange behavior in the minibuffer and other special buffers, it is necessary to rebind <span class="caps">TAB</span> only in local modes.  I&#8217;m sure there is a smarter/cleaner way to do this by instead excluding only the problematic buffers or modes, but I&#8217;ll leave that as an exercise for the reader (please post a comment if you have a solution though).</p>

	<p><em>Credits:  While I&#8217;ve had this nugget in my <code>.emacs</code> for a very long time, I cannot take credit for it.  I&#8217;ve seen <a href="http://www.dotemacs.de/dotfiles/KilianAFoth.emacs.html">similar</a> <a href="http://www.emacswiki.org/cgi-bin/wiki/DynamicAbbreviations">solutions</a> in <a href="http://www.richardrodger.com/roller/page/richard/Weblog/emacs_auto_complete">several</a> <a href="http://tsdh.wordpress.com/2006/12/02/using-tab-to-complete-and-indent/">places</a>, and while I tweaked it a bit myself, I originally stole it from someone else.  <a href="http://rubyforge.org/projects/emacs-rails/">Emacs-Rails</a> takes this approach one step further by also including <a href="http://www.kazmier.com/computer/snippet.el">snippet</a> support.</em></p>

	<h3>Hippie Expand Alternative</h3>

	<p>We used <code>dabbrev-expand</code> above, but I am considering changing that to <code>hippie-expand</code> instead.  <a href="http://www.xemacs.org/Documentation/packages/html/edit-utils_23.html">Hippie Expand</a> is more powerful, but might require some customization to suit to your liking.  I&#8217;m not ready for <a href="http://images.google.com/images?q=1962+volkswagen+van">groovy vans</a> or <a href="http://en.wikipedia.org/wiki/Tie-dye">tie-dye</a>, so we&#8217;ll have to talk about the details of Hippie Expand sometime later.</p>			</div>	
			<p class="tagged"><span class="add_comment"><a href="http://www.emacsblog.org/2007/03/12/tab-completion-everywhere/#comments" title="Comment on Tab Completion Everywhere">&rarr; 5 Comments</a></span><strong>Tags:</strong> <a href="http://www.emacsblog.org/tags/tips/" title="View all posts in tips" rel="category tag">tips</a> &middot;  <a href="http://www.emacsblog.org/tags/elisp/" title="View all posts in elisp" rel="category tag">elisp</a></p>
		
						
			
<div class="navigation">
	<div class="previous"><a href="http://www.emacsblog.org/page/2/">&larr; Previous Entries</a></div>
	<div class="next"></div>
</div>
<div class="clear"></div>

			
				</div>

		<div id="sidebar">
	<ul class="sidebar_list">
				<li class="widget">
			<h2>Search It!</h2>
			<form method="get" id="search_form" action="http://www.emacsblog.org/">
	<input type="text" class="search_input" value="To search, type and hit enter" name="s" id="s" onfocus="if (this.value == 'To search, type and hit enter') {this.value = '';}" onblur="if (this.value == '') {this.value = 'To search, type and hit enter';}" />
	<input type="hidden" id="searchsubmit" value="Search" />
</form>
		</li>
		<li class="widget">
			<h2>Recent Entries</h2>
			<ul>
												<li><a href="http://www.emacsblog.org/2007/04/17/quick-tip-light-symbol-mode/">Quick Tip: light-symbol-mode</a><span class="recent_date">4.17</span></li>
								<li><a href="http://www.emacsblog.org/2007/04/09/highlight-the-current-line/">Highlight the Current Line</a><span class="recent_date">4.9</span></li>
								<li><a href="http://www.emacsblog.org/2007/04/05/keyboard-macros-in-the-wild-the-mundane-sql-fix/">Keyboard Macros in the Wild: The Mundane SQL Fix</a><span class="recent_date">4.5</span></li>
								<li><a href="http://www.emacsblog.org/2007/04/02/ibm-emacs-tutorial-part-i/">IBM Emacs Tutorial, Part I</a><span class="recent_date">4.2</span></li>
								<li><a href="http://www.emacsblog.org/2007/03/29/quick-tip-line-numbering/">Quick Tip: Line Numbering</a><span class="recent_date">3.29</span></li>
								<li><a href="http://www.emacsblog.org/2007/03/26/newbie-tip-isearch-word-yank/">Newbie Tip: isearch Word Yank</a><span class="recent_date">3.26</span></li>
								<li><a href="http://www.emacsblog.org/2007/03/22/bookmark-mania/">Bookmark Mania</a><span class="recent_date">3.22</span></li>
								<li><a href="http://www.emacsblog.org/2007/03/17/quick-tip-set-goal-column/">Quick Tip: set-goal-column</a><span class="recent_date">3.17</span></li>
								<li><a href="http://www.emacsblog.org/2007/03/15/newbie-tip-re-builder/">Quick Tip: re-builder</a><span class="recent_date">3.15</span></li>
								<li><a href="http://www.emacsblog.org/2007/03/12/tab-completion-everywhere/">Tab Completion Everywhere</a><span class="recent_date">3.12</span></li>
							</ul>
		</li>
					<li id="linkcat-10" class="linkcat"><h2>reference</h2>
	<ul>
<li><a href="http://www.damtp.cam.ac.uk/user/sje30/emacs/ell.html">Emacs Lisp List</a></li>
<li><a href="http://www.emacswiki.org/cgi-bin/wiki">EmacsWiki</a></li>
<li><a href="http://www.gnu.org/software/emacs/">GNU Emacs</a></li>
<li><a href="http://jdee.sunsite.dk/" title="Java Development Environment For Emacs">JDEE</a></li>
<li><a href="http://emacs.wordpress.com/">minor emacs wizardry</a></li>
<li><a href="http://dima-exe.ru/rails-on-emacs" title="emacs-rails: Ruby on Rails minor mode">Rails On Emacs</a></li>

	</ul>
</li>
			</ul>
</div>	
	</div>

	<div id="footer">
		<p class="center">&copy; 2007 M-x all-things-emacs</p>
		<p class="center">Powered by <a href="http://wordpress.org/">WordPress</a> / Styled by <a href="http://cutline.tubetorial.com/">Cutline</a></p>
		<!-- Google Analytics Tracking by Google Analyticator: http://cavemonkey50.com/code/google_analyticator/ -->
	<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
	<script src="http://www.emacsblog.org/wp-content/plugins/google-analyticator/ga_external-links.js" type="text/javascript"></script>
	<script type="text/javascript">
		urchin = new urchin();
		urchin.trackDownload = "";
		urchin.trackLinks();
		_uacct="UA-1187477-1";  urchinTracker();
	</script>
	</div>
</div>

</body>
</html>
<!-- Dynamic Page Served (once) in 1.224 seconds -->
<!-- Cached page served by WP-Cache in 0.001 seconds -->
