<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Design, Development, and Consulting &#187; Tutorials</title>
	<atom:link href="http://netlumination.com/blog/category/tutorials/feed" rel="self" type="application/rss+xml" />
	<link>http://netlumination.com</link>
	<description>A web design, development, and consulting firm based in Portland, Oregon helping small businesseses and individuals.</description>
	<lastBuildDate>Wed, 01 Sep 2010 23:27:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Visibility Toggling with jQuery</title>
		<link>http://netlumination.com/blog/visibility-toggling-with-jquery</link>
		<comments>http://netlumination.com/blog/visibility-toggling-with-jquery#comments</comments>
		<pubDate>Mon, 16 Aug 2010 22:10:18 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[toggling]]></category>
		<category><![CDATA[visibility]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=1361</guid>
		<description><![CDATA[User interface design often makes use of showing and hiding blocks of content. It focuses one&#8217;s attention to the right thing, and it&#8217;s fun to do with jQuery. I&#8217;ll show you how to toggle the visibility on a group of selected elements. I&#8217;ll build up from a simple case to the more complicated ultimate goal. [...]]]></description>
			<content:encoded><![CDATA[<p>User interface design often makes use of showing and hiding blocks of content. It focuses one&#8217;s attention to the right thing, and it&#8217;s fun to do with <a href="http://jquery.com/">jQuery</a>.</p>
<p>I&#8217;ll show you how to toggle the visibility on a group of selected elements. I&#8217;ll build up from a simple case to the more complicated ultimate goal.</p>
<p><span id="more-1361"></span></p>
<p>First, whenever you&#8217;re working with jQuery and Javascript, you should probably get your references ready. For online references there&#8217;s the<a href="http://docs.jquery.com/Main_Page"> jQuery documentation</a> (which is easier to search with Google than with the site search, I find) and the <a href="https://developer.mozilla.org/en/javascript">Mozilla Development Center Javascript reference</a> among others. A very nice site to test, store, and share your jQuery snippets is <a href="http://jsfiddle.net/">jsFiddle</a>.</p>
<p>Ok, let&#8217;s get started. First let&#8217;s toggle the visibility of an element with jQuery using <a href="http://api.jquery.com/toggle/">.toggle()</a>. Since we&#8217;re talking about user interfaces, we&#8217;ll probably trigger the toggle with an action, let&#8217;s say a <a href="http://api.jquery.com/click/">.click()</a>:</p>
<ol>
<li>
<pre>$(document).ready(function(){</pre>
</li>
<li>
<pre>      // Toggle the visibility of all divs when one is clicked.</pre>
</li>
<li>
<pre>    $("input").click(function() {</pre>
</li>
<li>
<pre>        $("div").toggle();</pre>
</li>
<li>
<pre>    });</pre>
</li>
<li>
<pre>});​​</pre>
</li>
</ol>
<p><a href="http://jsfiddle.net/QXZ7p/">jsFiddle example</a></p>
<p>The code above will toggle the visibility of all the divs on a page if an input button is pressed.  The way this works is that after the document is ready, an event handler is bound to all the &lt;input&gt; elements. The handler waits for the user to click it. If clicked jQuery selects all the divs on the page and reverses their visibility. If they were invisible they become visible and vica versa.</p>
<p>Well, this was just to give you a tast of .toggle(), since the above example is pretty crude. Usually you want more control over which divs appear and disappear. In fact, an often trick part of visibility toggling in jQuery is to make sure each toggling button is linked uniquely to one block of content. You also want to ensure that when a block of content appears, all the other similar blocks of content disappears.</p>
<p>I&#8217;ll show you two methods of making sure that each time only one block of content appears, while all the other blocks of content disappears. The first method will only work if all the content blocks are siblings in the DOM. This will often be the case, since we&#8217;ll usually be dealing with semantically related chunks of content. The second way will be a little trickier but more flexible.</p>
<p>But before we start discussing siblings, let&#8217;s make sure we can toggle one specific div with one particular button. There&#8217;s many ways of doing this. I&#8217;ll show you how to use individual but related ids for the buttons and the content divs. Each button will have a name like, &#8220;block-x&#8221; where &#8220;x&#8221; is a number, and it&#8217;ll have a corresponding content block with the id &#8220;block-x-content&#8221;. Now if we have 3 content blocks, we could write one functions to control each block, for a total of 3 functions, but it&#8217;s more convenient and maintainable to generalize. We&#8217;re going to use input buttons with class &#8220;.toggler&#8221; to toggle the divs. You, of course, don&#8217;t have to use buttons, you can use other divs, or images, or whatever your little heart desires. So, so far we have:</p>
<ol>
<li>
<pre>$(document).ready(function(){</pre>
</li>
<li>
<pre>      // Toggle the visibility of all divs when one is clicked.</pre>
</li>
<li>
<pre>    $("input.toggler").click(function() {</pre>
</li>
<li>
<pre>        $( "#" + $(this).attr("id") + "-content" ).toggle();</pre>
</li>
<li>
<pre>    });</pre>
</li>
<li>
<pre>});​</pre>
</li>
</ol>
<p><a href="http://jsfiddle.net/N4PDK/">jsFiddle example</a></p>
<p>The most complex part is the line with the toggle. The previous line simply binds an click event handler to all input elements with a &#8220;toggler&#8221; class. The function that is triggered in case of a click is an anonymous function that toggles one div. To see witch div gets toggled we&#8217;ll look more closely at &#8220;$(&#8220;#&#8221; + $(this).attr(&#8220;id&#8221;) + &#8220;-content&#8221; )&#8221; . The part inside the parentheses is simply a jQuery selector string. The string starts with a literal &#8220;#&#8221;, so we know that an element with a certain ID is getting toggled. The &#8220;#&#8221; is followed by the &#8220;ID&#8221; attribute of the element that was clicked. So far we have something like $(&#8220;#block-x&#8221;). This by itself would make the buttons disappear. But we know that each button has a corresponding content block. This block is selected by concatenating &#8220;-content&#8221; to the previous to give us a toggling of $(&#8220;#block-x-content&#8221;). Where is the number in the ID attribute of the INPUT button we clicked. Notice how the visibility of each DIV is kept track of separately. .toggle() is doing all the hard work for us.</p>
<p>Well, we&#8217;re approaching what we want. The previous example is okay, in that it let&#8217;s us toggle things, but it doesn&#8217;t really feel like we&#8217;re concentrating the attention of the user to one pertinent block of information. To achieve that end, we must make all the other divs invisible when we make one div visible.</p>
<p>We only have to change one line to achieve this. We&#8217;ll go from:</p>
<pre>$( "#" + $(this).attr("id") + "-content" ).toggle();</pre>
<p>to:</p>
<pre>$( "#" + $(this).attr("id") + "-content" ).toggle().siblings().hide();</pre>
<p>Notice how I chained the methods .siblings() and .hide() onto the previous line. This means that after toggling our content block, we&#8217;ll select the DOM siblings of that block and make them invisible. This means you have to make sure you&#8217;ve thought through your HTML. The easy way to do this is to nest all the content divs into a parent div, or if it makes sense, maybe to have content LIs in a parent UL or OL.</p>
<p>One finally change is that you may not want the content to disappear if a button is pressed twice, so we&#8217;ll switch out .toggle() with .show() to give:</p>
<ol>
<li>
<pre>$(document).ready(function(){</pre>
</li>
<li>
<pre>      // Toggle the visibility of all divs when one is clicked.</pre>
</li>
<li>
<pre>    $("input.toggler").click(function() {</pre>
</li>
<li>
<pre>        $( "#" + $(this).attr("id") + "-content" ).show().siblings().hide();</pre>
</li>
<li>
<pre>    });</pre>
</li>
<li>
<pre>});​</pre>
</li>
</ol>
<p><a href="http://jsfiddle.net/NeVDs/">jsFiddle example</a></p>
<p>But what if our content DIVs aren&#8217;t siblings? They usually should be, just because of the way information is structured on an HTML page, but we really don&#8217;t want to count on that. We want the flexibility to toggle any set of elements we want.</p>
<p>To toggle any set of elements we want, all we have to do is create jQuery set of the elements and use .not() in combination with that. I&#8217;ll show you how.</p>
<p>First, let&#8217;s say that we have 3 content divs. Let&#8217;s select all of them with jQuery:</p>
<pre>
var theDivs = $("#block-1-content, #block-2-content, #block-3-content);
</pre>
<p>So, now theDivs is a jQuery selection of out content DIVs, let&#8217;s use that in combination with our click handler and .not() to toggle the appropriate content divs. Except, now I&#8217;m going to use an unordered list, so our content will be in LIs. If we&#8217;re dealing with unordered lists, we could easy have a situation where all the individual content LIs are not siblings of each other.</p>
<p>To show the corresponding content LI of a button, we&#8217;ll still use:</p>
<pre>
$( "#" + $(this).attr("id") + "-content" ).show();
</pre>
<p>But now we can&#8217;t simply make the siblings disappear. Instead we&#8217;ll make everything from our jQuery slection &#8220;theDivs&#8221; that isn&#8217;t the corresponding content LI vanish. Like this:</p>
<pre>
theDivs.not( $( "#" + $(this).attr("id") + "-content" ) ).hide();
</pre>
<p>And that&#8217;s it! You can of course replace the .show() and .hide() methods with fancier animations like .slideDown() and .slideUp(), but overall we have a relatively simple to implement, generalizable way of toggling the visibility of a group of content divs. The full code will look something like this:</p>
<ol>
<li>
<pre>$(document).ready(function(){</pre>
</li>
<li>
<pre>      // Create a selection of the content divs of interest</pre>
</li>
<li>
<pre>    var theDivs = $("#block-1-content, #block-2-content, #block-3-content");</pre>
</li>
<li>
<pre>      // Toggle the visibility of all divs when one is clicked.</pre>
</li>
<li>
<pre>    $("input.toggler").click(function() {        </pre>
</li>
<li>
<pre>        $( "#" + $(this).attr("id") + "-content" ).show();</pre>
</li>
<li>
<pre>        theDivs.not( $( "#" + $(this).attr("id") + "-content" ) ).hide();</pre>
</li>
<li>
<pre>    });</pre>
</li>
<li>
<pre>});​</pre>
</li>
</ol>
<p><a href="http://jsfiddle.net/NNLzj/">jsFiddle example</a></p>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/visibility-toggling-with-jquery/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A few code snippets.</title>
		<link>http://netlumination.com/blog/a-few-code-snippets</link>
		<comments>http://netlumination.com/blog/a-few-code-snippets#comments</comments>
		<pubDate>Sun, 25 Jul 2010 02:40:09 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[samples]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=1325</guid>
		<description><![CDATA[I often write very short, very simply little code snippets just to test specific things in HTML, CSS, PHP, or Javascript (and jQuery).  These are short little blurbs, that are useful for looking at how certain specific things work. They are mostly notes to self. Here are links to a few of them: Short Code [...]]]></description>
			<content:encoded><![CDATA[<p>I often write very short, very simply little code snippets just to test specific things in HTML, CSS, PHP, or Javascript (and jQuery).  These are short little blurbs, that are useful for looking at how certain specific things work. They are mostly notes to self.</p>
<p>Here are links to a few of them:</p>
<table>
<tbody>
<tr>
<td colspan="2"><strong>Short Code Snippets:</strong></td>
</tr>
<tr>
<td>CSS</td>
<td><a href="http://peter-ajtai.com/examples/html/images.php">Change image on hover.</a></td>
</tr>
<tr>
<td>CSS</td>
<td><a href="http://peter-ajtai.com/examples/html/menu-good.html">Creating large clickable areas.</a></td>
</tr>
<tr>
<td>CSS</td>
<td><a href="http://peter-ajtai.com/examples/html/sample.html">Images sprites example</a> &#8211; <a href="http://peter-ajtai.com/examples/html/styles.css">External CSS is here</a> &#8211; <a href="http://peter-ajtai.com/examples/html/images/sprite.png">Sprite is here</a></td>
</tr>
<tr>
<td>DOM</td>
<td><a href="http://peter-ajtai.com/examples/html/dom.php">Checking how many elements in an ID.</a></td>
</tr>
<tr>
<td>Javascript</td>
<td><a href="http://peter-ajtai.com/examples/js/animation.php">Basketball animation</a></td>
</tr>
<tr>
<td>jQuery</td>
<td><a href="http://peter-ajtai.com/examples/js/custom-iteration.php">Return ID of clicked LI</a></td>
</tr>
<tr>
<td>jQuery</td>
<td><a href="http://peter-ajtai.com/examples/js/jq-exs.php">Sliding, fading, and disappearing</a></td>
</tr>
<tr>
<td>jQuery</td>
<td><a href="http://peter-ajtai.com/examples/js/not.php">Not this array element</a></td>
</tr>
<tr>
<td>jQuery</td>
<td><a href="http://peter-ajtai.com/examples/js/toggle.php">Using toggle()</a></td>
</tr>
<tr>
<td>PHP Algorithm</td>
<td><a href="http://peter-ajtai.com/examples/php/lll.php">A linear linked list</a></td>
</tr>
<tr>
<td>PHP Recursion</td>
<td><a href="http://peter-ajtai.com/examples/numbers.php">Turning digits into words</a></td>
</tr>
<tr>
<td>PHP JSON CSS</td>
<td><a href="http://peter-ajtai.com/examples/php/del.php">Retrieving and displaying information from Delicious</a></td>
</tr>
<tr>
<td colspan="2"><strong>Simple Apps:</strong></td>
</tr>
<tr>
<td>jQuery PHP</td>
<td><a href="http://peter-ajtai.com/examples/php/so.php">Guessing game using Stackapps and Stackoverflow data</a></td>
</tr>
<tr>
<td>jQuery PHP</td>
<td><a href="http://peter-ajtai.com/examples/js/highlight.php">Dynamic Syntax Highlighting</a></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/a-few-code-snippets/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery for a little night time reading</title>
		<link>http://netlumination.com/blog/jquery-for-a-little-night-time-reading</link>
		<comments>http://netlumination.com/blog/jquery-for-a-little-night-time-reading#comments</comments>
		<pubDate>Tue, 15 Jun 2010 01:16:26 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=1242</guid>
		<description><![CDATA[If you use Javascript, JQuery is a great framework to speed up your coding. It&#8217;s essentially a collection of really convenient shortcuts. It does more, since JQuery also handles a lot of browser compatibility issues. So, you don&#8217;t have to go through your JQuery code to update it for new browsers, all you have to [...]]]></description>
			<content:encoded><![CDATA[<p>If you use Javascript, <a href="http://jquery.com/">JQuery</a> is a great framework to speed up your coding. It&#8217;s essentially a collection of really convenient shortcuts. It does more, since JQuery also handles a lot of browser compatibility issues. So, you don&#8217;t have to go through your JQuery code to update it for new browsers, all you have to do is download the new version of JQuery, and your old commands will learn new tricks.</p>
<p>Ah, speaking of downloading JQuery, you just might want to understand how JQuery works if you use it. The first time I tried to do this, I simply clicked on my JQuery src file link:</p>
<ol>
<li>
<pre>&lt;script type="text/javascript" src="http://peter-ajtai.com/jquery/jquery-1.4.2.min.js"&gt;&lt;/script&gt;</pre>
</li>
</ol>
<p>&#8230; and this is what I saw:</p>
<p><img class="alignnone size-full wp-image-1243" title="Happy reading" src="http://netlumination.com/wp-content/uploads/2010/06/wall-o-text.jpg" alt="Wall o text JQuery" width="419" height="323" /></p>
<p>Fun reading, huh? <span id="more-1242"></span>Well, when your browser loads Javascript, it has to load each charachter, so the less whitespace there is, and the shorter the variable names are, the faster it will load.</p>
<p>This means you should be using this, the minified, version of JQuery on your site, but if you want some <del>pleasant and relaxing</del> reading&#8230; you should look at the uncompressed version. <a href="http://docs.jquery.com/Downloading_jQuery">JQuery shows you both versions very clearly on their download page</a>, but for some reason, it took me a while to realize that there is an uncompressed version. The <a href="http://code.jquery.com/jquery-latest.js">uncompressed version of the latest version is here</a>. The uncompressed version is actually very readable:</p>
<p><img class="alignnone size-full wp-image-1244" title="That's better" src="http://netlumination.com/wp-content/uploads/2010/06/readable.jpg" alt="Readable JQuery" width="423" height="352" /></p>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/jquery-for-a-little-night-time-reading/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Three Steps for Using JQuery in Your WordPress Theme</title>
		<link>http://netlumination.com/blog/three-steps-for-using-jquery-in-your-wordpress-theme</link>
		<comments>http://netlumination.com/blog/three-steps-for-using-jquery-in-your-wordpress-theme#comments</comments>
		<pubDate>Mon, 31 May 2010 05:58:39 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[theme]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=1202</guid>
		<description><![CDATA[This is a quick post on using Javascript and the JQuery framework in particular within your WordPress theme. It&#8217;s quick and pretty painless. This is just for regular themes, not admin themes, plugins, or posts. Step 1: Load JQuery and your custom JS onto your page with wp_enqueue_script(). It&#8217;s better to use wp_enqueue_script than hard [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick post on using Javascript and the JQuery framework in particular within your WordPress theme. It&#8217;s quick and pretty painless. This is just for regular themes, not admin themes, plugins, or posts.</p>
<p><strong>Step 1:</strong></p>
<p><strong><span id="more-1202"></span></strong></p>
<p>Load JQuery and your custom JS onto your page with wp_enqueue_script(). It&#8217;s better to use wp_enqueue_script than hard coding it into your page. This is because WordPress comes with JQuery, so you won&#8217;t have to worry about updating JQuery as new versions come out. WordPress will do the work for you.  Make sure wp_enqueue script is before wp_head(), or it won&#8217;t work.</p>
<p>Here&#8217;s a snippet from my template file (let&#8217;s say index.php). I&#8217;ve created my custom JQuery functions in my themes &#8220;scripts&#8221; directory with the file name &#8220;custom-js.js&#8221;. You also have to make up a handle or name for your collection of custom JQuery functions. I called mine custom:</p>
<ol>
<li>
<pre>&lt;?php</pre>
</li>
<li>
<pre>    wp_enqueue_script('jquery');</pre>
</li>
<li>
<pre>    wp_enqueue_script('custom', get_bloginfo('stylesheet_directory') . '/scripts/custom-js.js');</pre>
</li>
<li>
<pre>    wp_head(); // WP API Hook</pre>
</li>
<li>
<pre>?&gt;</pre>
</li>
</ol>
<p>get_bloginfo is your friend. If you hard code your themes directory into your code anywhere, you won&#8217;t be able to share it with others, and you&#8217;ll break everything if you ever move hosts or just directories.</p>
<p>Here&#8217;s another example. Let&#8217;s say you want to use <a href="http://code.google.com/apis/maps/documentation/javascript/examples/index.html">Google Maps</a> on your page. Here is the line of WP code that makes that possible:</p>
<ol>
<li>
<pre>&lt;?php</pre>
</li>
<li>
<pre>    wp_enqueue_script('googleMaps', 'http://maps.google.com/maps/api/js?sensor=false');  </pre>
</li>
<li>
<pre>?&gt;</pre>
</li>
</ol>
<p>Finally, if you just want plain JS with no JQuery, you can simply leave out the line that calls JQuery but leave in the line that enqueues your custom functions. WordPress comes with a lot of other JS goodies besides JQuery. Scroll down to<a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_script"> the bottom of this page</a> to look at all the other stuff included with WordPress.</p>
<p><strong>Step 2:</strong><br />
Write your JQuery. The only thing you have to look out for is that wp_enqueue_script() calls JQuery in no conflict mode. This means that $ will not work as a shortcut for JQuery functions. There are two simple solutions.</p>
<ol>
<li>Define another shortcut for JQuery functions.</li>
<li>Use a wrapper around your JQuery code.</li>
</ol>
<p>Here is how to define a new shortcut for JQuery functions, $j in this case. The script shown is a very effective test to see if you&#8217;ve got JQuery working in your theme. It&#8217;s a little blunt, but it&#8217;s effects are hard to miss.</p>
<ol>
<li>
<pre>var $j = jQuery.noConflict();</pre>
</li>
<li>
<pre>$j(document).ready(function(){</pre>
</li>
<li>
<pre> $j("body").html("Your page is belong to us... just kidding, but you can use JQuery now.");</pre>
</li>
<li>
<pre>});</pre>
</li>
</ol>
<p>Here is how to use a wrapper in order to use the default JQuery shortcut:</p>
<ol>
<li>
<pre>jQuery(document).ready(function($) {</pre>
</li>
<li>
<pre>    $("body").html("Your page is belong to us... just kidding, but you can use JQuery now.");</pre>
</li>
<li>
<pre>});</pre>
</li>
</ol>
<p>Make sure you pay attention to all the curly brackets and parentheses. If the long and multiple parenthetical expressions annoy you, go check out <a href="http://www.cs.cmu.edu/afs/cs/project/theo-11/www/decision-trees.lisp">Lisp</a>.</p>
<p>Anyway, the second method is nice, since it let&#8217;s you use previously written code easily.</p>
<p><strong>Step 3:</strong></p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/three-steps-for-using-jquery-in-your-wordpress-theme/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Big Button CSS Menu Links</title>
		<link>http://netlumination.com/blog/big-button-css-menu-links</link>
		<comments>http://netlumination.com/blog/big-button-css-menu-links#comments</comments>
		<pubDate>Sun, 30 May 2010 01:08:54 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[highlight]]></category>
		<category><![CDATA[hover]]></category>
		<category><![CDATA[menu]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=1147</guid>
		<description><![CDATA[This post will show you how to make this: Home Gnome Rome Notice that the entire highlighted area is clickable, not just the lettering. I&#8217;ll describe a simple way to make pure CSS menu links that highlight nicely when hovered over. Now, you can obviously get a lot fancier with Javascript, but a good website [...]]]></description>
			<content:encoded><![CDATA[<p>This post will show you how to make this:</p>
<div id="da-body4">
<ul id="da-menu4">
<li><a href="http://peter-ajtai.com/examples/html/menu-good.html">Home</a></li>
<li><a href="http://peter-ajtai.com/examples/html/menu-good.html">Gnome</a></li>
<li><a href="http://peter-ajtai.com/examples/html/menu-good.html">Rome</a></li>
</ul>
</div>
<p>Notice that the entire highlighted area is clickable, not just the lettering.<span id="more-1147"></span></p>
<p>I&#8217;ll describe a simple way to make pure CSS menu links that highlight nicely when hovered over. Now, you can obviously get a lot fancier with Javascript, but a good website design degrades nicely. This means that you should stack as much functionality into the (X)HTML and CSS as you can, and then add extras on with Javascript. This will enable you to read the page nicely through the widest range of media. This is important these days when you don&#8217;t know whether your visitors are using a cell phone, iPAD, curl on a UNIX shell, text reader for the vision impaired, or whatever. There are obviously some things Javascript is great for, but there&#8217;s no need to kill a fly with an elephant gun. Don&#8217;t use it when you don&#8217;t have to.</p>
<p>The <a href="http://www.w3.org/">W3C</a> page has a nice example of elegant page degradation when Javascript is turned off. The menu links on the left hand side of the page, for example the ones under standards, flash dark gray before settling to light gray when hovered over. The flash is Javascript. When you <a href="http://noscript.net/">turn Javascript off</a>, notice that the flash is gone, but the links are still highlighted in the same way. You can click anywhere in the Menu box to follow the link, not just over the lettering, and the entire menu box is highlighted in light gray.</p>
<p>Ok let&#8217;s build a similar but simpler vertical menu. Horizontal menus are easier to highlight, since the horizontal width of each box can vary without having the menu look unnatural.</p>
<p>Our menu will have three items: Home, Gnome, and Rome. It often makes sense to put your menu items in an unordered list, so we&#8217;ll do that, and we&#8217;ll set a fixed with for the items. We&#8217;ll use a 440 px body width and 220px menu width, just so you can easily see the results as displayed in this blog.</p>
<p>Ok, let&#8217;s set up the menu with simple highlighting using &#8220;a:hover&#8221;.</p>
<div id="da-body">
<ul id="da-menu">
<li><a href="http://peter-ajtai.com/examples/html/menu-bad.html"> Home</a></li>
<li><a href="http://peter-ajtai.com/examples/html/menu-bad.html"> Gnome</a></li>
<li><a href="http://peter-ajtai.com/examples/html/menu-bad.html"> Rome</a></li>
</ul>
</div>
<p>You can take a look at the menu above <a href="http://peter-ajtai.com/examples/html/menu1.html">on its own page</a>. Here is what that code looks like (remember to use style sheets; I used a style definition in head, so that all the code could be read easily in one go, but unless you like to individually and tediously change CSS rules one at a time for hundreds or thousands of pages, you&#8217;d better use external style sheets):</p>
<p><a href="http://peter-ajtai.com/examples/html/menu-bad.html">Bad Hover Menu</a></p>
<ol>
<li>
<pre>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;</pre>
</li>
<li>
<pre>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;</pre>
</li>
<li>
<pre>    &lt;head&gt;</pre>
</li>
<li>
<pre>	&lt;style type="text/css"&gt;</pre>
</li>
<li>
<pre>	    #da-body {</pre>
</li>
<li>
<pre>	        background-color:#A6734A;</pre>
</li>
<li>
<pre>	        width:440px;</pre>
</li>
<li>
<pre>	    }</pre>
</li>
<li>
<pre>	    #da-menu {</pre>
</li>
<li>
<pre>		list-style-type:none;</pre>
</li>
<li>
<pre>		width:220px;</pre>
</li>
<li>
<pre>	    }</pre>
</li>
<li>
<pre>	    div#da-body ul#da-menu li a {</pre>
</li>
<li>
<pre>		font-size:180%;</pre>
</li>
<li>
<pre>		line-height:220%;</pre>
</li>
<li>
<pre>		color:#FAEAF3;</pre>
</li>
<li>
<pre>	        text-decoration:none;</pre>
</li>
<li>
<pre>	    }</pre>
</li>
<li>
<pre>	    div#da-body ul#da-menu li a:hover {</pre>
</li>
<li>
<pre>		background-color:#BFB6AF;</pre>
</li>
<li>
<pre>	    }</pre>
</li>
<li>
<pre>	&lt;/style&gt;</pre>
</li>
<li>
<pre>    &lt;/head&gt;</pre>
</li>
<li>
<pre>    &lt;body&gt;</pre>
</li>
<li>
<pre>	&lt;div id="da-body"&gt;</pre>
</li>
<li>
<pre>	    &lt;ul id="da-menu"&gt;</pre>
</li>
<li>
<pre>		&lt;li&gt;&lt;a href="#"&gt;Home&lt;/a&gt;&lt;/li&gt;</pre>
</li>
<li>
<pre>		&lt;li&gt;&lt;a href="#"&gt;Gnome&lt;/a&gt;&lt;/li&gt;</pre>
</li>
<li>
<pre>		&lt;li&gt;&lt;a href="#"&gt;Rome&lt;/a&gt;&lt;/li&gt;</pre>
</li>
<li>
<pre>	    &lt;/ul&gt;</pre>
</li>
<li>
<pre>	&lt;/div&gt;</pre>
</li>
<li>
<pre>    &lt;/body&gt;</pre>
</li>
<li>
<pre>&lt;/html&gt;</pre>
</li>
</ol>
<p>If you hover over a link, the background changes in color. Yeah, but it&#8217;s not very elegant, since the area that&#8217;s highlighted has a different shape for each link. Additionally, you have to be pretty precise with you mouse. The list takes up half the colored area, but you have to hover directly over letters in order to follow a link. Let&#8217;s deal with the first problem first.</p>
<p>It turns out that :hover is a valid pseudo class for a list item not just a. So if we change the a:hover code to li:hove like this:</p>
<ol>
<li>
<pre>div#da-body2 ul#da-menu2 li:hover {</pre>
</li>
<li>
<pre>    background-color:#BFB6AF;</pre>
</li>
<li>
<pre>}</pre>
</li>
</ol>
<p>We&#8217;ll see this:</p>
<div id="da-body2">
<ul id="da-menu2">
<li><a href="http://peter-ajtai.com/examples/html/menu-blah.html"> Home</a></li>
<li><a href="http://peter-ajtai.com/examples/html/menu-blah.html"> Gnome</a></li>
<li><a href="http://peter-ajtai.com/examples/html/menu-blah.html"> Rome</a></li>
</ul>
</div>
<p>Now we&#8217;re getting close. The problem is that you cannot click the entire highlighted area to follow the link. This is because we&#8217;re highlighting the li element and not the a element. Ok, well how about:</p>
<ol>
<li>
<pre>/* THIS WILL NOT WORK!!! */</pre>
</li>
<li>
<pre>div#da-body2 ul#da-menu2 a {</pre>
</li>
<li>
<pre>    width:100%</pre>
</li>
<li>
<pre>}</pre>
</li>
<li>
<pre>div#da-body2 ul#da-menu2 a:hover {</pre>
</li>
<li>
<pre>    background-color:#BFB6AF;</pre>
</li>
<li>
<pre>}</pre>
</li>
<li>
<pre>/* ^^ INCORRECT */</pre>
</li>
</ol>
<p>Nope, that&#8217;ll basically just look like the first example. The problem is that the &#8220;a&#8221; element cannot have a width attribute. It&#8217;s not a block level element. You can&#8217;t set it&#8217;s width normally.</p>
<p>Don&#8217;t you wish we could simply display the anchor element like a block item, in this case like a list item, and then we could set its width. Well, CSS knows about inheritance, and there is a display attribute. We just have to force the &#8220;a&#8221; or anchor tag to act different than usual using, &#8220;display:inherit;&#8221;. This means that the &#8220;a&#8221; tag will inherit whatever display mode its parent element has. In this case it will will inherit the &#8220;block&#8221; display from the li element. So, our solution is:</p>
<ol>
<li>
<pre>div#da-body ul#da-menu a {</pre>
</li>
<li>
<pre>    display:inherit;</pre>
</li>
<li>
<pre>    width:100%</pre>
</li>
<li>
<pre>}</pre>
</li>
<li>
<pre>div#da-body ul#da-menu a:hover {</pre>
</li>
<li>
<pre>    background-color:#BFB6AF;</pre>
</li>
<li>
<pre>}</pre>
</li>
</ol>
<p>This will produce:</p>
<div id="da-body3">
<ul id="da-menu3">
<li><a href="http://peter-ajtai.com/examples/html/menu-good.html">Home</a></li>
<li><a href="http://peter-ajtai.com/examples/html/menu-good.html">Gnome</a></li>
<li><a href="http://peter-ajtai.com/examples/html/menu-good.html">Rome</a></li>
</ul>
</div>
<p>Incidentally, &#8220;display:block&#8221; will work too. To wrap up, here is the full code:</p>
<p><a href="http://peter-ajtai.com/examples/html/menu-good.html">Good Hover Menu</a>:</p>
<ol>
<li>
<pre>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;</pre>
</li>
<li>
<pre>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;</pre>
</li>
<li>
<pre>    &lt;head&gt;</pre>
</li>
<li>
<pre>        &lt;style type="text/css"&gt;</pre>
</li>
<li>
<pre>            #page {</pre>
</li>
<li>
<pre>                background-color:#A6734A;</pre>
</li>
<li>
<pre>                width:440px;</pre>
</li>
<li>
<pre>            }</pre>
</li>
<li>
<pre>            #menu {</pre>
</li>
<li>
<pre>                list-style-type:none;</pre>
</li>
<li>
<pre>                width:220px;</pre>
</li>
<li>
<pre>                padding:0;</pre>
</li>
<li>
<pre>                margin:0;</pre>
</li>
<li>
<pre>            }</pre>
</li>
<li>
<pre>            div#page ul#menu li {</pre>
</li>
<li>
<pre>                padding:0;</pre>
</li>
<li>
<pre>                margin:0;</pre>
</li>
<li>
<pre>            }</pre>
</li>
<li>
<pre>            div#page ul#menu li a {</pre>
</li>
<li>
<pre>                display:inherit;</pre>
</li>
<li>
<pre>                width:100%;</pre>
</li>
<li>
<pre>                font-size:180%;</pre>
</li>
<li>
<pre>                line-height:220%;</pre>
</li>
<li>
<pre>                color:#FAEAF3;</pre>
</li>
<li>
<pre>                text-decoration:none;</pre>
</li>
<li>
<pre>                text-indent:0.5em;</pre>
</li>
<li>
<pre>            }</pre>
</li>
<li>
<pre>            div#page ul#menu li a:hover {</pre>
</li>
<li>
<pre>                background-color:#BFB6AF;</pre>
</li>
<li>
<pre>            }</pre>
</li>
<li>
<pre>        &lt;/style&gt;</pre>
</li>
<li>
<pre>    &lt;/head&gt;</pre>
</li>
<li>
<pre>    &lt;body&gt;</pre>
</li>
<li>
<pre>        &lt;div id="page"&gt;</pre>
</li>
<li>
<pre>            &lt;ul id="menu"&gt;</pre>
</li>
<li>
<pre>                &lt;li&gt;&lt;a href="#"&gt;Home&lt;/a&gt;&lt;/li&gt;</pre>
</li>
<li>
<pre>                &lt;li&gt;&lt;a href="#"&gt;Gnome&lt;/a&gt;&lt;/li&gt;</pre>
</li>
<li>
<pre>                &lt;li&gt;&lt;a href="#"&gt;Rome&lt;/a&gt;&lt;/li&gt;</pre>
</li>
<li>
<pre>            &lt;/ul&gt;</pre>
</li>
<li>
<pre>        &lt;/div&gt;</pre>
</li>
<li>
<pre>    &lt;/body&gt;</pre>
</li>
<li>
<pre>&lt;/html&gt;</pre>
</li>
</ol>
<p>Incidentally, you can see that I&#8217;ve got a few margin:0s and padding:0s thrown in to make things look neater. Instead of dealing with zeroing the margins, paddings, etc. for each item one by one, you can simply use a <a href="http://meyerweb.com/eric/tools/css/reset/">CSS reset</a>. You can put this at the top of your style sheet, or add it in as a separate style sheet. I didn&#8217;t use a CSS reset for this example, since I wanted to keep the code as self contained as possible.</p>
<p>Ok, that&#8217;s all the hovering over CSS menus for today.</p>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/big-button-css-menu-links/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating your first WordPress theme &#8211; Part 1</title>
		<link>http://netlumination.com/blog/creating-your-first-wordpress-theme-part-1</link>
		<comments>http://netlumination.com/blog/creating-your-first-wordpress-theme-part-1#comments</comments>
		<pubDate>Wed, 26 May 2010 19:26:46 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[convenience]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=1041</guid>
		<description><![CDATA[Content Management Systems and WordPress is so powerful because it allows site owners to update their sites efficiently and to customize their sites and their CMS experience. WordPress themes control both the look of a site and the options a site owner has in terms of customizing this look. That sounds pretty good and rather [...]]]></description>
			<content:encoded><![CDATA[<p>Content Management Systems and <a href="http://wordpress.org/">WordPress</a> is so powerful because it allows site owners to update their sites efficiently and to customize their sites and their CMS experience. <a href="http://codex.wordpress.org/Theme_Development">WordPress themes</a> control both the look of a site and the options a site owner has in terms of customizing this look.</p>
<p>That sounds pretty good and rather vague. It&#8217;s hard to describe what you can do with WordPress themes, since they can do a lot. It&#8217;s like trying to describe all the things you can do with a nail. It all depends on how you use it.</p>
<p>In light of this, it seems like the best thing to do would be to go through an example of building a WordPress theme. I&#8217;ll go through a theme as I develop it, and I&#8217;ll try to build it starting at the simplest level and working to progressively more complicated iterations.</p>
<p>Before we begin, there&#8217;s a few things that I&#8217;m going to assume:</p>
<ol>
<li>You&#8217;ve got WordPress installed on your site. <a href="http://codex.wordpress.org/Installing_WordPress">It&#8217;s usually pretty easy to install WordPress</a>.</li>
<li>You can access the files in your WordPress install.</li>
<li>You can access your WordPress admin panel.</li>
</ol>
<p><span id="more-1041"></span></p>
<p>You can usually access your files through FTP, SSH, or even your web host&#8217;s control panel. On Windows I usually use <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/">PuTTY</a> for SSH. I&#8217;ve heard good things about <a href="http://filezilla-project.org/">FileZilla</a> for FTP, but I&#8217;ve personally never tried it. You can edit your files with anything from Notepad (ugh) to <a href="http://notepad-plus.sourceforge.net/uk/site.htm">Notepad++</a> (yay!) to <a href="http://www.adobe.com/products/dreamweaver/">Dreamweaver</a> (for all the flack Dreamweaver gets, it sure can speed up a lot of things), <a href="http://www.gnu.org/software/emacs/tour/">Emacs</a> (hang on, let me grow a beard and put on my glasses)&#8230;</p>
<p>Actually, in spite of the beard and glasses joke, if your host offers a Unix or Linux shell, then working on your pages with Emacs can be a great pleasure. I mean you have access to not just your files, but also to your files through one of the most powerful &#8220;word processors&#8221; in the world. No more worrying about whether your files are on your desktop, laptop, smartphone, or smartbrain. Anyway, Emacs is fun and free (free as in hair, and yanking it out in frustration while you pound your head against the keyboard trying to understand what a <a href="http://www.gnu.org/software/emacs/emacs-lisp-intro/elisp/Lambda-Expressions.html#Lambda-Expressions">Lambda expression</a> is). No, but seriously, using Emacs through SSH courtesy of your web host is fantastic stuff, and lets them work a little for the money you give them. I will shamelessly mention that I use <a href="http://www.dreamhost.com/r.cgi?132190">Dreamhost</a>, and so can you by clicking on that link that will earn me money when you sign up.</p>
<p><script type="text/javascript">// <![CDATA[
 google_ad_client = "pub-4166122661117213"; /* 336x280, created 4/27/09 */ google_ad_slot = "9673694336"; google_ad_width = 336; google_ad_height = 280;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></p>
<p>Ok, you&#8217;ve got WordPress installed, and you can access the files on your server. Let&#8217;s start building a theme.</p>
<p>The way WordPress works is that it runs a bunch of PHP create the HTML for your web pages. These PHP pages will often look into an associated MySQL database for info. The PHP will also look (ok, I&#8217;m definitely anthropomorphizing) in specific directories for certain things.</p>
<p>One of these special directories contain all the themes that you have installed. Each theme is in its own folder, and you can pick the theme to use through the WordPress admin panel.</p>
<p>You can find the theme choices on the left side of the adminn panel under &#8220;Appearance&#8221;:</p>
<p><img class="alignnone size-full wp-image-1046" title="Wordpress themes" src="http://netlumination.com/wp-content/uploads/2010/05/wp-011.jpg" alt="Themes through the admin panel" width="244" height="436" /></p>
<p>The directory that the themes you can pick from are in is:</p>
<blockquote><p>/wp-content/themes/</p></blockquote>
<p>Each directory in themes is a theme you can use. Understanding how WordPress knows that the contents of these directories are themes will help us create our first theme.</p>
<p>WordPress looks at the main stylesheet in each directory, and from this style sheet it reads the information about the theme. You have to know that convention that for WordPress the main style sheet is a file called, &#8220;style.css&#8221;. So the simplest theme is just a style sheet in a directory. Let&#8217;s see how to make one of these themes&#8230;</p>
<p>Let&#8217;s look at this in practice. Here&#8217;s is what the themes page looks like when /wp-content/themes only has the Classic theme in it. In other words /wp-content/themes only has a directory named &#8220;classic&#8221; in it, and the index.php file:</p>
<p><img class="alignnone size-full wp-image-1056" title="Classic theme" src="http://netlumination.com/wp-content/uploads/2010/05/wp-021.jpg" alt="Classic theme" width="440" height="239" /></p>
<p>As you can see, I&#8217;m currently redoing <a href="http://www.evergreenicesports.org/">Evergreen Ice Sports</a> web page. Soon it&#8217;ll look nicer and be easier to maintain for the site owners. Anyway, as you can see currently Classic is the only available theme.</p>
<p>If we create a directory with only a style sheet called &#8220;style.css&#8221; in it, we can use that style sheet to:</p>
<ol>
<li>Tell WordPress that the directory the style sheet is in contains a WordPress theme.</li>
<li>Tell WordPress that theme is just like another theme with a few modifications (in other words the theme is a <a href="http://codex.wordpress.org/Child_Themes">child theme</a>).</li>
</ol>
<p>Ok, let&#8217;s step through this and then discuss it. First create a directory called, &#8220;mytheme&#8221; in wp-content/themes . Now reload the Manage Themes page in the admin panel to see what happened:</p>
<p><img class="alignnone size-full wp-image-1057" title="Mytheme" src="http://netlumination.com/wp-content/uploads/2010/05/wp-031.jpg" alt="Broken theme" width="440" height="291" /></p>
<p>This shows you that I was telling the truth about WP looking in the wp-content/themes directory for the available themes. It looked in your empty directory called mythemes, and since it the information about each theme is supposed to be in the main style sheet, and there is no style sheet in mythemes, we have a broken theme.</p>
<p>Let&#8217;s add a stylesheet over at wp-content/themes/mytheme/style.css. This style sheet will contain all the necessary information to create a WordPress theme. Here are all of the contents:</p>
<ol>
<li>
<pre>/*</pre>
</li>
<li>
<pre>Theme Name:     My Theme</pre>
</li>
<li>
<pre>Theme URI:      http: //netlumination.com/</pre>
</li>
<li>
<pre>Description:    Child theme spawned by the Classic theme</pre>
</li>
<li>
<pre>Author:         Peter Ajtai</pre>
</li>
<li>
<pre>Author URI:     http: //peter-ajtai.com/</pre>
</li>
<li>
<pre>Template:       classic</pre>
</li>
<li>
<pre>Version:        1.0</pre>
</li>
<li>
<pre>*/</pre>
</li>
</ol>
<p>Yup, that&#8217;s all it takes, and yeah replace my info with your info, but make sure that line 7 stays untouched. The file contains only CSS comments. WordPress, reads these comments, and when it sees line 7, that says &#8220;Template: default&#8221;, it understands that mytheme is a child theme of the theme that is in the directory called, &#8220;classic&#8221;. Let&#8217;s reload the Themes admin panel and activate this new theme.</p>
<p><img class="alignnone size-full wp-image-1058" title="Our style" src="http://netlumination.com/wp-content/uploads/2010/05/wp-041.jpg" alt="Our style" width="440" height="521" /></p>
<p>You can see how WordPress used the information in the CSS file to fill in the information about our new theme. You&#8217;ll notice that there is no screen shot for My Theme. We&#8217;ll do this soon. Anyway, click on &#8220;activate&#8221; to&#8230;. uh&#8230;.. activate the theme. Since MyTheme is a child of Classic, this means that MyTheme inherits all the characteristics of Classic. We can add to or modify these characteristics, but we haven&#8217;t done that yet, so right now our theme should look identical to Classic. Visit your site&#8217;s homepage to check on this&#8230;&#8230;</p>
<p>Whoops!</p>
<p>Our page looks like it has no styles! I guess I lied. MyTheme inherits everything from Classic <strong><em>except</em></strong> the style sheet. That&#8217;s a little odd right? Especially if you&#8217;re used to dealing with inheritance in things like children and object oriented programming, but no matter, it&#8217;s easier to fix than your&#8230;. well, than, many things. So, let&#8217;s grab the style sheet from the classic theme using the line:</p>
<ol>
<li>
<pre>@import url("../classic/style.css");</pre>
</li>
</ol>
<p>So now our entire wp-content/themes/mytheme/style.css file looks like:</p>
<ol>
<li>
<pre>/*</pre>
</li>
<li>
<pre>Theme Name:     My Theme</pre>
</li>
<li>
<pre>Theme URI:      http: //netlumination.com/</pre>
</li>
<li>
<pre>Description:    Child theme spawned by the Classic theme</pre>
</li>
<li>
<pre>Author:         Peter Ajtai</pre>
</li>
<li>
<pre>Author URI:     http: //peter-ajtai.com/</pre>
</li>
<li>
<pre>Template:       classic</pre>
</li>
<li>
<pre>Version:        1.0</pre>
</li>
<li>
<pre>*/</pre>
</li>
<li>
<pre>@import url("../classic/style.css");</pre>
</li>
</ol>
<p>Ok, now go and check on how your home page looks&#8230;. Just like classic, huh? Well, that&#8217;s not very interesting, let&#8217;s make things a very tiny bit more interesting by adding one more line to prove that we have a theme that uses default but has some of it&#8217;s own rules:</p>
<ol>
<li>
<pre>/*</pre>
</li>
<li>
<pre>Theme Name:     My Theme</pre>
</li>
<li>
<pre>Theme URI:      http: //netlumination.com/</pre>
</li>
<li>
<pre>Description:    Child theme spawned by the Classic theme</pre>
</li>
<li>
<pre>Author:         Peter Ajtai</pre>
</li>
<li>
<pre>Author URI:     http: //peter-ajtai.com/</pre>
</li>
<li>
<pre>Template:       classic</pre>
</li>
<li>
<pre>Version:        1.0</pre>
</li>
<li>
<pre>*/</pre>
</li>
<li>
<pre>@import url("../classic/style.css");</pre>
</li>
<li>
<pre>body {</pre>
</li>
<li>
<pre>	background-color:blue;</pre>
</li>
<li>
<pre>}</pre>
</li>
</ol>
<p>Ok, that was 3 lines, but I could have made it one line. Does it work? Yup. Does it work with all themes&#8230;&#8230; uh, no. For example, if you try the same thing with the Default theme, you&#8217;ll notice that some of the background images that are used in the Default theme will not be used in your child theme. This is because the CSS for these background images are created by PHP that looks for them in the wrong directory. It&#8217;s easy to fix, but it illustrates why I&#8217;m using so many words to explain this one simple thing of how to make a child theme. If you know how all of this works, you can probably track down these problems. If you don&#8217;t know how it works, you&#8217;re lost. But these details aren&#8217;t important right now, since we want to create our own theme, not look for weird little leaks in the inheritance abstraction for WordPress themes.</p>
<p>You&#8217;ve just created your own WP theme! Don&#8217;t worry it gets better. We&#8217;ll do stuff that&#8217;s more useful. We&#8217;ll push pixels around around like they&#8217;re not our boss. We&#8217;ll meld code to our mind&#8217;s desire, but you&#8217;ll have to wait for the next part of this series for that&#8230; until then we&#8217;ll&#8230;.. well, we&#8217;ll see you later.</p>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/creating-your-first-wordpress-theme-part-1/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Piping grep into the Odyssey</title>
		<link>http://netlumination.com/blog/piping-grep-into-the-odyssey</link>
		<comments>http://netlumination.com/blog/piping-grep-into-the-odyssey#comments</comments>
		<pubDate>Mon, 10 May 2010 01:00:00 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[pipe]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=919</guid>
		<description><![CDATA[Grep and piping ( &#124; ) are two powerful tools in Linux. Grep allows you to search lines of text for certain patterns using regular expressions. Piping allows you to take the output of one command and make it the input of another. So, lets say you want to look through the Odyssey and find [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.gnu.org/software/grep/manual/grep.html">Grep</a> and piping ( | ) are two powerful tools in Linux. Grep allows you to search lines of text for certain patterns using regular expressions. Piping allows you to take the output of one command and make it the input of another.</p>
<p>So, lets say you want to look through the Odyssey and find all mentions of Sirens. That would be:</p>
<ol>
<li>
<pre>grep -in siren odyssey.txt</pre>
</li>
</ol>
<p>But let&#8217;s say you don&#8217;t have the Odyssey on your hard drive, you could just get it from MIT and pipe it over to grep</p>
<ol>
<li>
<pre>curl http://classics.mit.edu/Homer/odyssey.mb.txt | grep -in siren</pre>
</li>
</ol>
<p>In both cases, I used case insensitive search, grep -i, and I list what line number the instances are found on with -n.</p>
<p>So far this has all been pretty straight forward, but I know that the Odyssey is divided into books, and I want to know which books contain the lines about sirens. This is where piping becomes very handy.</p>
<ol>
<li>
<pre>curl http://classics.mit.edu/Homer/odyssey.mb.txt | grep -in "siren\|^book" | grep -iB1 "siren"</pre>
</li>
</ol>
<p><span id="more-919"></span></p>
<p>Let&#8217;s look at this line from left to right in order to understand it. &#8220;curl &#8230;&#8221; simply goes and gets whatever characters are at the referenced url. We pipe these lines of text into: grep -in &#8220;siren\|^book&#8221;.  This is another case insensitive search, but it is looking for each line that matches any one of two possible patterns. In regular expressions the pipe, |, means OR. When using Linux, you have to escape the pipe, and write \| to mean OR in a regular expression. So we are looking for  an appearance of the word siren OR a line that begins with the word &#8220;book.&#8221; (^ is the beginning of a line). It is important that we only use -n in the first instance of grep, since this first instance will return the line number in the original text file. If you use -n in the second grep, you won&#8217;t get the line numbers of the original file, you&#8217;ll get the line numbers from the first grep output, which is probably meaningless to you.</p>
<p><script type="text/javascript">// <![CDATA[
      google_ad_client = "pub-4166122661117213"; /* 336x280, created 4/27/09 */ google_ad_slot = "9673694336"; google_ad_width = 336; google_ad_height = 280;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></p>
<p>At this point we have all the lines which reference sirens and we have all the lines that say, &#8220;BOOK &#8230;&#8221; from BOOK I to BOOK XXIV, whether these books contain siren references or not. To clean all of this up, we take these lines, the book lines and the siren lines, and pipe them over to:  grep -iB1 &#8220;sirens&#8221;</p>
<p>This will take our list and display the lines one previous to a siren reference and the siren reference line. This will show us the siren references and which of the 24 books in the Odyssey reference sirens. So, if you want to read about sirens, look for Books XII and XXIII in the Odyssey.</p>
<p>Here is the output (edited a little for shorter lines), without the curl status output&#8230; notice that none of the lines are repeated, and that the blocks of text are separated by 2 dashes&#8230; grep at work:</p>
<ol>
<li>
<pre>4936:BOOK XII</pre>
</li>
<li>
<pre>4972:you will come to the Sirens</pre>
</li>
<li>
<pre>4974:of the Sirens, his wife and</pre>
</li>
<li>
<pre>4978:these Sirens by, and stop</pre>
</li>
<li>
<pre>4986:past these Sirens, I cannot</pre>
</li>
<li>
<pre>5074:the Sirens, who sit and sing</pre>
</li>
<li>
<pre>5083:two Sirens, for the wind had</pre>
</li>
<li>
<pre>5094:good rate, the Sirens saw</pre>
</li>
<li>
<pre>5109:Sirens' voices. Then my men</pre>
</li>
<li>
<pre>--</pre>
</li>
<li>
<pre>9638:BOOK XXIII</pre>
</li>
<li>
<pre>9921:wondrous singing of the Sirens</pre>
</li>
</ol>
<p>And of course, this is just the tip of the iceberg, or should I say, just the beginning of the Siren&#8217;s song?</p>
<p>To learn more about grep type, &#8220;man grep&#8221; in Linux or, &#8220;M-x woman ENTER grep&#8221; in Emacs.</p>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/piping-grep-into-the-odyssey/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bite Sized Emacs</title>
		<link>http://netlumination.com/blog/bite-sized-emacs</link>
		<comments>http://netlumination.com/blog/bite-sized-emacs#comments</comments>
		<pubDate>Wed, 14 Apr 2010 23:17:10 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Emacs]]></category>
		<category><![CDATA[reference]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=854</guid>
		<description><![CDATA[Emacs is a big complicated beast. You can spend lots of time looking through the documentation, but sometimes it&#8217;s nice to enjoy a quick bite of Emacs goodness. Table of Contents: 1: Custom Keystrokes 2: Indenting only as far as you feel comfortable 3: Indentation on steroids 4: Colorful shells 5: Colorful men 6: No [...]]]></description>
			<content:encoded><![CDATA[<p>Emacs is a big complicated beast. You can spend lots of time  looking through the documentation, but sometimes it&#8217;s nice to enjoy a quick bite of Emacs goodness.</p>
<p><strong>Table of Contents:</strong><br />
<strong><a href="#keystrokes">1: Custom Keystrokes</a></strong><br />
<strong><a href="#indentation1">2: Indenting only as far as you feel comfortable</a></strong><br />
<strong><a href="#indentation2">3: Indentation on steroids</a></strong><br />
<strong><a href="#color">4: Colorful shells</a></strong><br />
<strong><a href="#woman">5: Colorful men</a></strong><br />
<strong><a href="#beep">6: No more beeping, only flashing</a></strong><br />
<strong><a href="#menu">7: Turn off annoying menu bar</a></strong><br />
<strong><a href="#font">8: Customizing font appearance</a></strong><br />
<strong><a href="#wraps1">9: Line wrapping on horizontally split windows</a></strong><br />
<strong><a href="#wraps2">10: Normal looking line wraps</a></strong><br />
<strong><a href="#backup">11: Auto backup a little smarter</a></strong><br />
<strong><a href="#complete">12:  Autocomplete</a></strong><br />
<strong><a href="#jump">13: Jumping the line</a></strong><br />
<strong><a href="#move">14:  Moving from one window to the other easilly</a></strong><br />
<strong><a href="#delete">15: Delete the entire word</a></strong><br />
<strong><a href="#num">16: Enabling the Num Pad</a></strong><br />
<strong><a href="#macros">17: Making and storing macros</a></strong><br />
<strong><a href="#count">18: Word Count</a></strong></p>
<p><strong><a name="keystrokes"></a>Morsel 1 &#8211; Custom keystrokes</strong></p>
<p><a href="http://netlumination.com/blog/three-steps-to-making-a-custom-keystroke-shortcut-in-emacs">Make your own custom keystrokes.</a></p>
<p><strong><a name="indentation1"></a>Morsel 2 &#8211; Indenting only as far as you feel comfortable</strong></p>
<p>Change the indentation rules in cc-mode to as many spaces as you want (I use 4, which looks like normal tabs on other editors, some people use 8, or 2, or whatever).<br />
Edit your .emacs.d/init.el (<a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Init-File.html">depending it could be ~/.emacs, ~/.emacs.el, or ~/.emacs.d/init.el</a>) like this (substitute the number you want where I write 4):</p>
<ol>
<li>
<pre>;; define indents as 4 spaces in cc-mode</pre>
</li>
<li>
<pre>(setq c-basic-offset 4</pre>
</li>
<li>
<pre>      tab-width 4</pre>
</li>
<li>
<pre>      indent-tabs-mode t)</pre>
</li>
</ol>
<p><span id="more-854"></span></p>
<p>The first line (setting c-basic-offset) does most of the work usually. The other two lines deal with how big tabs show.</p>
<p>You can change the c indentation style using <span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">(setq c-default-style &#8220;[style name here]&#8220;)</span>. These styles include bsd,stroustrup, etc. Look at the <a href="http://www.emacswiki.org/emacs/IndentingC">Emacs wiki about indentation in C style</a>.</p>
<p><strong><a name="indentation2"></a>Morsel 3 &#8211; Indentation on steroids</strong></p>
<p>Indent an entire block of code according to applicable rules by selecting the code and then typing &#8220;C-M-\&#8221;.<br />
For example, let&#8217;s say you just changed c-basic-offset to 4 from 8. Or you changed the c-default-style. If you now start typing a new program, then the new rules will be in effect. But, when you open a program you&#8217;ve been working on, the parts already written will look unchanged. Here&#8217;s the step by step as to what you type (remember C = Control key and M = Meta key&#8230; usually the Alt key):</p>
<ol>
<li>
<pre>C-x [</pre>
</li>
<li>
<pre>C-SPACE</pre>
</li>
<li>
<pre>C-x ]</pre>
</li>
<li>
<pre>M-w</pre>
</li>
<li>
<pre>C-M-\</pre>
</li>
</ol>
<p>And now your entire code is indented according to the new rules! Translation of steps 1: C-x [ is beginning of file. 2: C-SPACE is set mark for region. 3: C-x ] is end of file. 4: M-w is copy or mark regin. 5: C-M-\ is indent entire marked region according to applicable rules.</p>
<p><strong><a name="color"></a>Morsel 4 &#8211; Colorful shells</strong></p>
<p>Show the colors properly in shell mode.</p>
<ol>
<li>
<pre>;; Deal with colors in shell mode correctly</pre>
</li>
<li>
<pre>(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)</pre>
</li>
</ol>
<p>You know you need this if you got to shell mode in Emacs (M-x shell) and you see something like &#8220;^[[1;37m091".</p>
<p><strong><a name="woman"></a>Morsel 5 - Colorful men</strong></p>
<p>To read the Unix / Linux man pages in Emacs just type:</p>
<ol>
<li>
<pre>M-x man</pre>
</li>
</ol>
<p>Then the name of the command of interest. If you want to look at the manual pages in color, type (I mentioned this in my <a href="http://netlumination.com/blog/a-completely-random-guide-to-emacs">Completely Random Guide to Emacs</a>)</p>
<ol>
<li>
<pre>M-x woman</pre>
</li>
</ol>
<p>If you want the F1 key to bring up the woman pages, that is, manual pages in color, then add this to your .emacs.d/init.el</p>
<ol>
<li>
<pre>(global-set-key [f1] ‘woman)</pre>
</li>
</ol>
<p><strong><a name="beep"></a>Morsel 6 - No more beeping, only flashing</strong></p>
<p>Turn off the audible Emacs warning, but have your screen flash when it would have sounded:</p>
<ol>
<li>
<pre>;; Turn off bell, but make it visible</pre>
</li>
<li>
<pre>(setq visible-bell t)</pre>
</li>
</ol>
<p><strong><a name="menu"></a>Morsel 7 - Turn off annoying menu bar</strong></p>
<p>Turn off the menu bar at the top of the screen:</p>
<pre>;; Turn off menu bar at top of screen
(menu-bar-mode -1)</pre>
<p>You can also do the same thing with the tool bar if you have that:</p>
<pre>(tool-bar-mode -1)</pre>
<p>You can toggle these back on or off by typing</p>
<pre>M-x menu-bar-mode or M-x tool-bar-mode</pre>
<p><strong><a name="font"></a>Morsel 8 - Customizing font appearance</strong></p>
<p>Change font appearance (this will often be useful using a major mode for a programming language or text type):</p>
<pre>M-x customize-face</pre>
<p>If you hit enter and enter again to pick the default, you'll be able to change the default appearance of the face that is used to show the word type you we're on (comment, string, keyword, etc.). Your changes will automatically be saved to .emacs.d/init.el, so you'll be able to see how the changes were done.</p>
<p><strong><a name="wraps1"></a>Morsel 9 - Line wrapping on horizontally split windows</strong></p>
<p>Usually line wrapping is on by default. You can see it is when a line comes to the edge of the screen, the '\' is shown and the line continues one below. If the line is truncated on the other hand, you won't be able to see the rest of the line, you'll only be able to see a '$'. You can use <a href="http://www.emacswiki.org/emacs/TruncateLines">truncate lines</a> to toggle back and forth between the wrap and truncate states by typing (this will be local to that buffer):</p>
<pre>M-x toggle-truncate-lines</pre>
<p>The tricky thing is that horizontally split windows (windows split by a vertical line) will still truncate. One line in your .emacs.d/init.el will let you wrap lines for horizontally split windows:</p>
<pre>(setq truncate-partial-width-windows nil)</pre>
<p><strong><a name="wraps2"></a>Morsel 10 - Normal looking line wraps</strong></p>
<pre>M-x longlines-mode</pre>
<p>or if you have it (Emacs 23+)</p>
<pre>M-x global-visual-line-mode</pre>
<p>Will toggle normal looking line wraps on and off.  If you want to get fancy, you can set up some default in your .emacs.d/init.el</p>
<ol>
<li>
<pre>;; Wrap lines visually</pre>
</li>
<li>
<pre>(add-hook 'text-mode-hook 'longlines-mode)</pre>
</li>
<li>
<pre>(setq longlines-wrap-follows-window-size 1)</pre>
</li>
</ol>
<p><strong><a name="backup"></a>Morsel 11 - Auto backup a little smarter</strong></p>
<p>You'll soon notice Emacs scattering funny looking ~FILE and #FILE# backups across your directories. I like throwing all the auto backups into one directory and putting some sort of version number on them. This code is straight from the <a href="http://www.emacswiki.org/emacs/BackupDirectory">Emacs wiki</a>, it goes into you .emacs.d/init.el:</p>
<ol>
<li>
<pre>(setq</pre>
</li>
<li>
<pre>     backup-by-copying t      ; don't clobber symlinks</pre>
</li>
<li>
<pre>     backup-directory-alist</pre>
</li>
<li>
<pre>     '(("." . "~/.saves"))    ; don't litter my fs tree</pre>
</li>
<li>
<pre>     delete-old-versions t</pre>
</li>
<li>
<pre>     kept-new-versions 6</pre>
</li>
<li>
<pre>     kept-old-versions 2</pre>
</li>
<li>
<pre>     version-control t)       ; use versioned backups</pre>
</li>
</ol>
<p><strong><a name="complete"></a>Morsel 12 - Autocomplete</strong></p>
<p>This is quite useful, but you do have to install it. The installation instructions in the manual are clear. Take a look at <a href="http://www.emacswiki.org/emacs/AutoComplete">autocompletion for Emacs</a>.</p>
<p><strong><a name="jump"></a>Morsel 13 - Jumping the line</strong></p>
<p>C-n and C-p move your pointer up and down one line, but I can do this with my up and down arrow keys, so a redefined C-n and C-p to move up and down 5 lines at a time:</p>
<ol>
<li>
<pre>;; Move up and down five lines at a time</pre>
</li>
<li>
<pre>(global-set-key "\C-n"</pre>
</li>
<li>
<pre>    (lambda () (interactive) (next-line 5)))</pre>
</li>
<li>
<pre>(global-set-key "\C-p"</pre>
</li>
<li>
<pre>    (lambda () (interactive) (next-line -5)))</pre>
</li>
</ol>
<p><strong><a name="move"></a>Morsel 14 - Moving from one window to the other easilly</strong></p>
<p>You split your window using C-x 2 and C-x 3 into as many pieces as you want. The default for moving to the next window is C-x O, but if you have 10 windows, this might take a while.</p>
<p>Here's how to use the arrow keys on your Num Pad to simply move up, down, left, or  right (up up down down left right...... nevermind) among your windows:</p>
<ol>
<li>
<pre>;; move to window to the left</pre>
</li>
<li>
<pre>(global-set-key (kbd "&lt;kp-4&gt;") 'windmove-left)</pre>
</li>
<li>
<pre>;; move to window to the right</pre>
</li>
<li>
<pre>(global-set-key (kbd "&lt;kp-6&gt;") 'windmove-right)</pre>
</li>
<li>
<pre>;; move to window below</pre>
</li>
<li>
<pre>(global-set-key (kbd "&lt;kp-8&gt;") 'windmove-up)</pre>
</li>
<li>
<pre>;; move to window above</pre>
</li>
<li>
<pre>(global-set-key (kbd "&lt;kp-2&gt;") 'windmove-down)</pre>
</li>
</ol>
<p><strong><a name="delete"></a>Morsel 15 - Delete the entire word</strong><br />
This one's from a StackOverflow post that I cannot find right now. The kill-word function will delete a word from where your cursor is forward. What if you want to delete the entire word, including the part before your pointer?</p>
<ol>
<li>
<pre>;; kill entire word</pre>
</li>
<li>
<pre>(defun my-kill-word ()</pre>
</li>
<li>
<pre>  (interactive)</pre>
</li>
<li>
<pre>  (backward-word)</pre>
</li>
<li>
<pre>  (kill-word 1))</pre>
</li>
<li>
<pre>(global-set-key (kbd "M-d") 'my-kill-word)</pre>
</li>
</ol>
<p><strong><a name="num"></a>Morsel 16 - Enabling the Num Pad</strong></p>
<p>Depending how you're using Emacs. The keys for the num pad may not work the way you want. You can enable them to work like this:</p>
<ol>
<li>
<pre>;; Num pad enable</pre>
</li>
<li>
<pre>;; The arithmetic operators already have keybindings,</pre>
</li>
<li>
<pre>;; so you may not want to use those</pre>
</li>
<li>
<pre>(global-set-key (kbd "&lt;kp-1&gt;") "1")</pre>
</li>
<li>
<pre>(global-set-key (kbd "&lt;kp-2&gt;") "2")</pre>
</li>
<li>
<pre>(global-set-key (kbd "&lt;kp-3&gt;") "3")</pre>
</li>
<li>
<pre>(global-set-key (kbd "&lt;kp-4&gt;") "4")</pre>
</li>
<li>
<pre>(global-set-key (kbd "&lt;kp-5&gt;") "5")</pre>
</li>
<li>
<pre>(global-set-key (kbd "&lt;kp-6&gt;") "6")</pre>
</li>
<li>
<pre>(global-set-key (kbd "&lt;kp-7&gt;") "7")</pre>
</li>
<li>
<pre>(global-set-key (kbd "&lt;kp-8&gt;") "8")</pre>
</li>
<li>
<pre>(global-set-key (kbd "&lt;kp-9&gt;") "9")</pre>
</li>
<li>
<pre>(global-set-key (kbd "&lt;kp-0&gt;") "0")</pre>
</li>
<li>
<pre>(global-set-key (kbd "M-O n") ".")</pre>
</li>
<li>
<pre>(global-set-key (kbd "&lt;kp-enter&gt;") 'newline)</pre>
</li>
<li>
<pre>;; Optional arithmetic operators</pre>
</li>
<li>
<pre>;; These will change the regular F key defs too</pre>
</li>
<li>
<pre>;; and you'll overide some macro and other settings</pre>
</li>
<li>
<pre>(global-set-key (kbd "&lt;f2&gt;") "/")</pre>
</li>
<li>
<pre>(global-set-key (kbd "&lt;f3&gt;") "*")</pre>
</li>
<li>
<pre>(global-set-key (kbd "&lt;f4&gt;") "-")</pre>
</li>
<li>
<pre>(global-set-key (kbd "&lt;kp-separator&gt;") "+")</pre>
</li>
</ol>
<p>Of course, you have to make some choices sometimes. If you have the num pad enabled to show numbers and symbols, then you can't use it to move from one buffer to another. This is when a defining your own minor mode might come in handy.</p>
<p><strong><a name="macros"></a>Morsel 17 - Making and storing macros</strong></p>
<p>Define the macro. To start recording the macro:</p>
<ol>
<li>
<pre>C-x (</pre>
</li>
</ol>
<p>Now type the keys, commands, etc you want done. This is just like in Excel.<br />
Stop the macro recording with:</p>
<ol>
<li>
<pre>C-x )</pre>
</li>
</ol>
<p>Now to save this macro we have to save it and insert it into our .emacs or init.el file.<br />
Name the macro:</p>
<ol>
<li>
<pre>M-x name-last-kbd-macro</pre>
</li>
</ol>
<p>Ok, now open up your .emacs or init.el file, and move your pointer (cursor) to where you want the code for your macro definition to go and type:</p>
<ol>
<li>
<pre>M-x insert-kbd-macro</pre>
</li>
</ol>
<p>Now type in your <a href="http://netlumination.com/blog/three-steps-to-making-a-custom-keystroke-shortcut-in-emacs">custom keybinding</a>, something like:</p>
<ol>
<li>
<pre>(global-set-key (kbd "C-c n") 'my-macro)</pre>
</li>
</ol>
<p>Of course, the keybinding (C-c n) and name (my-macro) will be your own.</p>
<p><strong><a name="count"></a>Morsel 18 - Word Count</strong><br />
Emacs doesn't have a built in word count function. You can Lisp through a function, or you can avoid reinventing the wheel by calling the Unix word count function, "wc". Just remember that the "-w" option shows the actual word count. These lines of code in your .emacs or init.el file will define the function, "word-count" to count the words in the current file. I also set "C-c c" as the shortcut for this function:</p>
<ol>
<li>
<pre>;; Word count</pre>
</li>
<li>
<pre>(defun word-count nil "Count words in buffer" (interactive)</pre>
</li>
<li>
<pre>(shell-command-on-region (point-min) (point-max) "wc -w"))</pre>
</li>
<li>
<pre>;; Shortcut for Word count</pre>
</li>
<li>
<pre>(global-set-key (kbd "C-c c") 'word-count)</pre>
</li>
</ol>
<p>Thanks to <a href="http://iquaid.org/2008/02/08/counting-words-in-emacs/">Karsten Wade and the discussion on this page</a>. There are many <a href="http://www.emacswiki.org/emacs/WordCount">word count alternatives in the Emacs Wiki</a>, and there's also a word-count-mode that you can download. I just like the code above for its simplicity if you're on a Unix like system anyway.<br />
Have fun chewing on these eMACS!</p>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/bite-sized-emacs/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Three Steps to Making a Custom Keystroke Shortcut in Emacs</title>
		<link>http://netlumination.com/blog/three-steps-to-making-a-custom-keystroke-shortcut-in-emacs</link>
		<comments>http://netlumination.com/blog/three-steps-to-making-a-custom-keystroke-shortcut-in-emacs#comments</comments>
		<pubDate>Mon, 12 Apr 2010 21:52:33 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Emacs]]></category>
		<category><![CDATA[keystrokes]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=848</guid>
		<description><![CDATA[This one&#8217;s short (ish?) and sweet. It describes how to make your own global key bindings for functions of your choice in Emacs. Type &#8220;C-h b&#8221; in Emacs. This will bring up a list of all the current keybindings. Type &#8220;C-s [KEYBINDING YOU WANT WRITTEN OUT]&#8221; to double check that the shortcut isn&#8217;t taken using [...]]]></description>
			<content:encoded><![CDATA[<p>This one&#8217;s short (ish?) and sweet. It describes how to make your own global key bindings for functions of your choice in Emacs.</p>
<ol>
<li>Type &#8220;C-h b&#8221; in Emacs. This will bring up a list of all the current keybindings.</li>
<li>Type &#8220;C-s [KEYBINDING YOU WANT WRITTEN OUT]&#8221; to double check that the shortcut isn&#8217;t taken using search. For example to check that &#8220;C-c t&#8221; isn&#8217;t taken type &#8220;C-s C-c t&#8221;.</li>
<li>Modify your .emacs.d/init.el file like this
<ol>
<li>
<pre>;; [USEFUL COMMENTS]</pre>
</li>
<li>
<pre>(global-set-key (kbd "[KEYSTROKES WRITTEN OUT]") '[FUNCTION NAME])</pre>
</li>
</ol>
</li>
</ol>
<p>For example to set C-c g to trigger goto-line:</p>
<ol>
<li>
<pre>;; Define C-c g as a shortcut for goto-line.</pre>
</li>
<li>
<pre>(global-set-key (kbd "C-c g") 'goto-line)</pre>
</li>
</ol>
<p>That&#8217;s all there is to it. A little bit more about <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Rebinding.html">setting key binding in the GNU Emacs Manual</a>.</p>
<p>If you want to use a key that you don&#8217;t know the code of simply press, &#8220;C-c h [KEY OF INTEREST]&#8220;. For example &#8220;C-c h [F5]&#8221; shows: &#8221; is undefined&#8221;, so I would use (kbd &#8220;&lt;f5&gt;&#8221;)</p>
<p><span id="more-848"></span></p>
<p>Ok, that&#8217;s it, you don&#8217;t have to read the rest. The rest is just the usual quagmire  associated with most things in Emacs.</p>
<p>A side note is that there are multiple ways of refering to keybindings in emacs. In this example, I make use of the kbd macro. The <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Init-Rebinding.html">kbd macro converts keystrokes written out using M-, C-, etc. into a form that can be passed as an argument to global-set-key.</a> Instead of using kbd, you can also write out your keystroke combinations using a Lisp string. This will only work , &#8220;for ASCII characters and Meta-modified ASCII characters.&#8221;</p>
<ol>
<li>
<pre>;; Alternate definition of C-c g as a shortcut for goto-line using Lisp strings.</pre>
</li>
<li>
<pre>(global-set-key "\C-cg" 'goto-line)</pre>
</li>
</ol>
<p>Finally, you can use a Lisp vector. Vectors are written in square brackets, and characters in vectors are written with a question mark and slash in front of them.</p>
<ol>
<li>
<pre>;; Alternate definition of C-c g as a shortcut for goto-line using Lisp vectors.</pre>
</li>
<li>
<pre>(global-set-key [?\C-c ?\g] 'goto-line)</pre>
</li>
</ol>
<p>I usually try the kbd method first, since it will usually work. You can use array to make use of strange keytrokes. Simply type C-q and the keystroke you&#8217;re interested in to insert the code for it.</p>
<p>For example, if we type C-q C-c we get ^C, and C-q g gives simply g, so the example above can also be written like:</p>
<ol>
<li>
<pre>;; Another alternate definition of C-c g as a shortcut for goto-line using Lisp vectors.</pre>
</li>
<li>
<pre>(global-set-key [?^C ?g] 'goto-line)</pre>
</li>
</ol>
<p>I have to say, that there are some keystrokes whose codes I have trouble getting emacs to understand this way, but using &#8220;C-c h&#8221; and kbd will usually do the trick. There&#8217;s certain keys you won&#8217;t be able to use. For example if you&#8217;re on a Windows system and you hit the Windows key while using Emacs in a terminal, you&#8217;ll get the Start menu on Windows instead of  a keystroke sent to Emacs.</p>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/three-steps-to-making-a-custom-keystroke-shortcut-in-emacs/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Some Standard Emacs Commands / Keystrokes</title>
		<link>http://netlumination.com/blog/some-standard-emacs-commands</link>
		<comments>http://netlumination.com/blog/some-standard-emacs-commands#comments</comments>
		<pubDate>Thu, 08 Apr 2010 17:36:28 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Emacs]]></category>
		<category><![CDATA[commands]]></category>
		<category><![CDATA[keyboard shortcuts]]></category>
		<category><![CDATA[keystrokes]]></category>
		<category><![CDATA[reference]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=676</guid>
		<description><![CDATA[&#8220;C-&#8221; is your CTRL key. &#8220;M-&#8221; is your Meta key, usually ALT or ESC. Hover over a section to expand it, or: * The &#8220;Expand Entire Menu&#8221; button works with Javascript. You do not have Javascript enabled. * Buffers (they&#8217;re like Tabs) Close (kill) buffer ==&#62; C-x k List buffers ==&#62; C-x C-b Switch to [...]]]></description>
			<content:encoded><![CDATA[<p><strong>&#8220;C-&#8221; is your CTRL key. &#8220;M-&#8221; is your Meta key, usually ALT or ESC.</strong></p>
<p><strong>Hover over a section to expand it, or:</strong></p>
<input id="emacsButton" onclick="showAll()" type="button" value="Expand Entire Menu" /> <noscript>* The &#8220;Expand Entire Menu&#8221; button works with Javascript. You do not have Javascript enabled. *</noscript></p>
<ul id="emacs">
<li><a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Buffers.html">Buffers</a> (they&#8217;re like Tabs)
<ul>
<li>Close (kill) buffer ==&gt; C-x k</li>
<li>List buffers ==&gt; C-x C-b</li>
<li>Switch to next buffer ==&gt; C-x RIGHT</li>
<li>Switch to other buffer ==&gt; C-x b</li>
<li>Switch to previous buffer ==&gt; C-x LEFT</li>
</ul>
</li>
<li>Coding
<ul>
<li><strong>You have to be in outline-minor-mode for many of these. To get there type ==&gt; M-x outline-minor-mode</strong></li>
<li><strong>The keystroke shortcuts for these functions have changed quite a bit recently. To check yours, type &#8220;C-h b&#8221; and look for the command.</strong></li>
<li>Collapse all functions  ==&gt;  M-x hide-other</li>
<li>Evaluate the Lisp S-expression before the cursor and print result in mini-buffer ==&gt; C-x C-e</li>
<li>Hide body of one function ==&gt; M-x hide-subtree</li>
<li>Show all functions ==&gt; M-x show-all</li>
<li>Show body of one collapsed function ==&gt; M-x show-subtree</li>
</ul>
</li>
<li><a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Starting-GUD.html#Starting-GUD">Debugging</a>
<ul>
<li><strong>After all of the following commands type ENTER and<br />
the name of the file you want to debug and ENTER.</strong></li>
<li>Run DBX (cli) ==&gt; M-x dbx</li>
<li>Run GDB (graphic like IDE interface) ==&gt; M-x gdb</li>
<li>Run Java debugger ==&gt; M-x jdb</li>
<li>Run Perl interpreter in debug mode ==&gt; M-x perldb</li>
<li>Run Python debugger ==&gt; M-x pdb</li>
<li>Run SDB (cli) ==&gt; M-x sdb</li>
<li>Run XDB (cli) ==&gt; M-x xdb</li>
</ul>
</li>
<li>Editing
<ul>
<li>Copy region (after you marked &#8216;beginning&#8217; w C-SPACE) ==&gt; M-W</li>
<li>Cut (after you marked &#8216;beginning&#8217; w C-SPACE) ==&gt; C-W</li>
<li>Kill (delete) rest of line ==&gt; C-k</li>
<li>Kill (delete) rest of sentence ==&gt; M-k</li>
<li>Kill (delete) rest of word ==&gt; M-d</li>
<li>Paste marked region (yank) ==&gt; C-y</li>
<li>Set mark begin here (for copy, paste, etc.) ==&gt; C-SPACE</li>
<li>Set mark and highlight marked area ==&gt; C-SPACE C-SPACE</li>
<li>Spell check entire file (buffer) ==&gt; M-x spell-buffer</li>
<li>Spell check word ==&gt; M-$</li>
</ul>
</li>
<li><a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Files.html">Files</a>
<ul>
<li>Compare differences between two files ==&gt; M-x ediff</li>
<li>Insert file into buffer ==&gt; C-x i</li>
<li>Open a file ==&gt; C-x C-f</li>
<li>Quit and Save ==&gt; C-x C-c</li>
<li>Refresh buffer after file has been edited elsewhere ==&gt; M-x revert-buffer</li>
<li>Replace this with other file ==&gt; C-x C-v</li>
<li>Save all ==&gt; C-x s</li>
<li>Save file ==&gt; C-x C-s</li>
<li>Show directory explorer (dired) ==&gt; C-x d</li>
<li>Show number of lines in file ==&gt; C-x l (letter &#8220;el&#8221;)</li>
<li>Suspend and exit to shell (type %emacs in shell to resume) ==&gt; C-z</li>
</ul>
</li>
<li>Fonts
<ul>
<li><a href="http://www.delorie.com/gnu/docs/emacs/emacs_482.html">Interactively change fonts</a> ==&gt; M-x customize-face</li>
</ul>
</li>
<li>Formatting
<ul>
<li>Indent line appropriately (according to mode) ==&gt; TAB</li>
<li>Indent marked (see Editing) region ==&gt; C- M- \</li>
<li>Tabbing (to next Tab stop) ==&gt; M-i</li>
</ul>
</li>
<li><a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Help.html">Help</a>
<ul>
<li>Describe function run by keystrokes in a window (more info)<br />
==&gt; C-h k [COMMAND]</li>
<li><strong>RUN TUTORIAL</strong> ==&gt; C-h t</li>
<li>Show all keyboard shortcuts  (key bindings) in effect ==&gt; C-h b</li>
<li>Show commands containing a word you type (apropos) ==&gt; C-h a</li>
<li>Show function run by keystrokes in echo area (quick info)<br />
==&gt; C-h c [COMMAND]</li>
<li>Show manual section for function run by kestrokes<br />
==&gt; C-h K [COMMAND]</li>
</ul>
</li>
<li>Modes (using Emacs for different stuff)
<ul>
<li>Debugging (gdb) mode ==&gt; M- x gdb</li>
<li>Shell mode ==&gt; M- x shell</li>
</ul>
</li>
<li>Movement
<ul>
<li>Beginning of file ==&gt; C-x [</li>
<li>Beginning of line ==&gt; C-a</li>
<li>Beginning of sentence ==&gt; M-a</li>
<li>Center cursor vertically ==&gt; C-l (letter "el")</li>
<li>End of file ==&gt; C-x ]</li>
<li>End of line ==&gt; C-e</li>
<li>End of sentence ==&gt; M-e</li>
<li>Go to line ==&gt; M- x goto-line</li>
<li>Next word ==&gt; M- f or M-RIGHT</li>
<li>Previous word ==&gt; M- b or M-LEFT</li>
<li>Next screen (scroll down) ==&gt; C-v</li>
<li>Previous screen (scroll up) ==&gt; M-v</li>
<li>Scroll down OTHER window ==&gt; C- M- v</li>
</ul>
</li>
<li><a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Search.html">Search / Search and Replace</a>
<ul>
<li>Interactive / Incremental Search (highlight as you type) ==&gt; C-s</li>
<li>Keep going with current search after editing ==&gt; C-s C-s</li>
<li>Next highlighted item ==&gt; C-s</li>
<li>Previous highlighted item ==&gt; C-r</li>
<li>Search and replace (from cursor to end of file). Type ? for help in replacing. ==&gt; M-%</li>
<li><a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Regexp-Search.html">Search using a regular expression</a> ==&gt; M-C-s</li>
<li>Select next search string (while in incremental search mode)<br />
==&gt; M-n</li>
<li>Select previous search string (while in incremental search mode)<br />
==&gt; M-p</li>
</ul>
</li>
<li>Undo
<ul>
<li><strong>Undo is very good in Emacs, you should<a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Undo.html"> look into it in detail</a></strong></li>
<li>Abort command ==&gt; C-g</li>
<li>Undo a change ==&gt; C-x u or C-_</li>
</ul>
</li>
<li><a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Windows.html">Windows</a>
<ul>
<li>Close all other windows ==&gt; C-x 1</li>
<li>Close this window (&#8220;zero&#8221;) ==&gt; C-x 0</li>
<li>Make window narrower ==&gt; C-x {</li>
<li>Make window wider ==&gt; C-x }</li>
<li>Make window taller ==&gt; C-x ^</li>
<li>Make window shorter ==&gt; M-x shrink-window</li>
<li>Move cursor to other window (letter &#8220;oh&#8221;) ==&gt; C-x o</li>
<li>Split this window with a horizontal line ==&gt; C-x 2</li>
<li>Split this window with a vertical line ==&gt; C-x 3</li>
</ul>
</li>
<li>Some of my own keystroke definitions
<ul>
<li><strong>To make these definitions work, you would have to define them yourself. I include them as a seed for ideas.</strong></li>
<li>Go to line # ==&gt; C-c g</li>
<li>Move down five lines ==&gt; C-n</li>
<li>Move up five lines ==&gt; C-p</li>
<li>Outline-minor-mode hide-other ==&gt; C-c c</li>
<li>Outline-minor-mode hide-subtree ==&gt; C-c h</li>
<li>Outline-minor-mode show-all ==&gt; C-c a</li>
<li>Outline-minor-mode show-subtree ==&gt; C-c s</li>
<li>Trigger word auto completion ==&gt; TAB</li>
<li>Twittering mode (for an Emacs Twitter client) ==&gt; C-c t</li>
<li>Woman (in color manual pages) ==&gt; C-c w</li>
</ul>
</li>
</ul>
<p>*This is a work in progress &#8211; Content and presentation are evolving*<br />
<span id="more-676"></span><br />
Above you hopefully found the typical keystroke / command combinations for Emacs. Emacs has a lot of commands. You fire these commands, or functions, with keystrokes. Which keystroke goes with which function is ultimately up to you. This should not be confusing to anyone who works with Photoshop, Illustrator or any of the Adobe Creative Suite. Emacs uses keyboard shortcuts&#8230;.. very extensively.</p>
<p>I&#8217;m using the abbreviations that you&#8217;ll see in most text discussing Emacs. In other words &#8220;M-&#8221; stands for pressing your &#8220;Meta&#8221; key. This is usually the &#8220;Alt&#8221; key. &#8220;C-&#8221; stands for pressing your &#8220;Control&#8221; key. So, &#8220;C-x C-s&#8221; means hit Control + x then Control + c.</p>
<h3>Extended Commands</h3>
<p>By hitting M-x you can type in different commands. As you start typing in a command, you&#8217;ll be able to hit the TAB key to see possible ways to complete your command (hints). For example &#8220;M-x gomoku&#8221; let&#8217;s you play gomoku. M-x fires the execute-extended-command function, which lets you type in the name of a command&#8230;. can the name be, &#8220;execute-extended-command&#8221;?</p>
<h3>Documentation</h3>
<p>You should know that Emacs has a ton of self description and a ton of online reference. In fact <a href="http://www.gnu.org/software/emacs/manual/emacs.html">this is the Emacs manual</a>. I find the <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/index.html">HTML one page per node version</a> the most useful online and the PDF version the best for leisurely fireside thumbing.</p>
<p>Oh, and you can go look at <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Key-Index.html#Key-Index">the key index in the Emacs manual</a>. Additionally the interweb pipes are filled with Emacs Cheat Sheets and Reference Cards. This is a <a href="http://inst.eecs.berkeley.edu/~cs3/sp07/emacsreference.pdf">PDF Reference Sheet by CAL CS</a> that&#8217;s pretty good.</p>
<h3>What does this keystroke do?</h3>
<p>Ok, this is in the keystroke / commands list, but it&#8217;s important enough to repeat: To find out what a keystroke combination does in Emacs, type &#8220;C-h c [THE KEYSTROKES]&#8221; or &#8220;C-h k [THE KEYSTROKES]&#8220;. C-h c is the short info version. It is displayed in the echo area at the bottom of the screen. C-h k is the long info version, and it displays in a window. (C-h K [THE KEYSTROKES] will show the manual area for that command.).</p>
<p>So, if you want to find out what C-z does, you would type &#8220;C-h k C-z&#8221;.</p>
<h3>Defining your own keystrokes</h3>
<p>There may be some keytrokes you wish were defined. For example, &#8220;M-x goto-line&#8221; seems very long, so if you want to define &#8220;C-c g&#8221; to jump you to the line you enter, then you could add the following line to your init.el file, which is usually in your .emacs.d directory:</p>
<pre>(global-set-key "\C-cg" 'goto-line)</pre>
<p>These days (since Emacs 22) these sort of customizations (the Lisp commands that are automatically executed when Emacs is started) are placed in the &#8220;.emacs.d&#8221; directory within the init.el file. They used to be put simply in a &#8220;.emacs&#8221; file. <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Init-File.html">In fact when Emacs starts it tries three locations:  ~/.emacs, ~/.emacs.el, or ~/.emacs.d/init.el.</a>. Here &#8220;~&#8221; is your home directory.</p>
<p><script type="text/javascript">// <![CDATA[
    google_ad_client = "pub-4166122661117213"; /* 336x280, created 4/27/09 */ google_ad_slot = "9673694336"; google_ad_width = 336; google_ad_height = 280;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></p>
<h3>Modes</h3>
<p>The same keystroke can have different effects depending on the <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Major-Modes.html#Major-Modes">mode</a> your in. A mode is simply an environment to handle a particular type of text. You can usually see what mode your in by looking at the bar at the bottom of your window. You can pick one major mode and several <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Minor-Modes.html">minor modes</a>. I&#8217;ve tried to only include keyboard shortcuts for the global mode.</p>
<h3>A note on terminology</h3>
<p>I try to use terminology that&#8217;ll make sense to people who use things like Word. This terminology isn&#8217;t always the most accurate. Things like &#8220;Copy&#8221; and &#8220;Paste&#8221; don&#8217;t work exactly the same in Emacs as they do in Word. But I use these terminology short cuts to make things more accessible. Additionally, while most of the keystrokes should work, your sysadmin may have changed some of them (and you can change them back). But finally, I just wanted to provide a quick and easy guide to the typical keystrokes in Emacs. You owe it to yourself to look deeper into Emacs if you anticipate using it often or want to play gomoku.</p>
<h3>Final note: Fonts</h3>
<p>There are many ways to change fonts. Do yourself a favor and explore &#8220;M-x customize-face&#8221;. It&#8217;s interactive, and you can choose, &#8220;save for future use&#8221;. If you do this, Emacs will save some Lisp commands to your init.el file, and you&#8217;ll get a chance to look at them. Additionally, it&#8217;s not always Emacs fault! For example, if you&#8217;re using PuTTY to SSH in to a session, then PuTTY will control some aspects of your fonts. For example, PuTTY will controls you <strong>FONT SIZE</strong> and <strong>FONT TYPE</strong>! ( Window &gt;&gt; Appearance ). Emacs will still control the colors.</p>
<p>Hopes this collapsible interface helps organize things a little. Let me know if you have any suggestions for keystrokes to add!</p>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/some-standard-emacs-commands/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
