<?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>Lojic Technologies Blog &#187; emacs</title>
	<atom:link href="http://lojic.com/blog/tag/emacs/feed/" rel="self" type="application/rss+xml" />
	<link>http://lojic.com/blog</link>
	<description></description>
	<lastBuildDate>Fri, 25 Nov 2011 20:12:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Switching from CarbonEmacs to Emacs.app</title>
		<link>http://lojic.com/blog/2010/03/17/switching-from-carbonemacs-to-emacs-app/</link>
		<comments>http://lojic.com/blog/2010/03/17/switching-from-carbonemacs-to-emacs-app/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 05:42:42 +0000</pubDate>
		<dc:creator>Brian Adkins</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://lojic.com/blog/?p=796</guid>
		<description><![CDATA[Thanks to a tip from David Joyner, I discovered that the current version of Emacs will easily build an Emacs.app application for Mac OSX i.e. I no longer need to install the CarbonEmacs application. I&#8217;m thankful to Seiji Zenitani for creating CarbonEmacs, but I&#8217;m glad to be able to build the app directly from the [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks to a tip from David Joyner, I discovered that the current version of Emacs will easily build an Emacs.app application for Mac OSX i.e. I no longer need to install the CarbonEmacs application. I&#8217;m thankful to Seiji Zenitani for creating CarbonEmacs, but I&#8217;m glad to be able to build the app directly from the latest Emacs source code.</p>
<p>Here&#8217;s what I did:</p>
<h1>Get the source code and build it</h1>
<pre>
git clone git://git.savannah.gnu.org/emacs.git
cd emacs
./configure --with-ns
make install
</pre>
<h1>Copy Emacs.app to Applications</h1>
<p>Drag nextstep/Emacs.app to Applications</p>
<h2>Modify Emacs config files</h2>
<p>I had several configuration items I needed to adjust.</p>
<h3>carbon-emacs-package-add-to-path no longer exists</h2>
<p>I used the above command to set the path to allow running programs via shell-command as follows:</p>
<pre>
(carbon-emacs-package-add-to-path "/Users/badkins/sync/bin")
(defun my-fun ()
  (interactive)
  (shell-command "my_ruby_script.rb"))
</pre>
<p>I found a comment by Alex Payne on Ola Bini&#8217;s blog that provided an equivalent for Emacs.app:</p>
<pre>
(setq path "/Users/badkins/sync/bin")
(setenv "PATH" path)
</pre>
<h3>Use command for meta instead of alt/option</h3>
<p>The newly built Emacs.app used the alt/option key for meta instead of the command key that I was used to with CarbonEmacs. The following (found on Hacker News) took care of that:</p>
<pre>
(setq ns-command-modifier 'meta)
</pre>
<p>Prior to the above, I had tried the following. It worked, but was more verbose:</p>
<pre>
(setq mac-option-key-is-meta nil)
(setq mac-command-key-is-meta t)
(setq mac-command-modifier 'meta)
(setq mac-option-modifier nil)
</pre>
<h3>Allow use of command-h to minimize Emacs</h3>
<p>After the above fix for the command key, I could no longer minimize Emacs via command-h because Emacs mapped M-h to a command. The following key binding allowed using M-h to minimize again:</p>
<pre>
(global-set-key (kbd "M-h") 'ns-do-hide-emacs)
</pre>
<h3>Customize exec-path variable</h3>
<p>I was having difficulty using the built-in vc git support. It turns out that Emacs wasn&#8217;t able to find the git command because it wasn&#8217;t in the exec-path. I customized the exec-path variable to include /opt/local/bin where git resides as follows (it&#8217;s within the custom-set-variables invocation):</p>
<pre>
 '(exec-path (quote ("/usr/bin" "/bin" "/usr/sbin" "/sbin" "/Applications/Emacs.app/Contents/MacOS/bin" "/opt/local/bin")))
</pre>
<h2>Emacs is Awesome</h2>
<p>That was all it took to get the latest Emacs up and running equivalently to CarbonEmacs for me. I&#8217;m more pleased with Emacs today than when I started using it in earnest in 2008. I&#8217;m continually learning new things to be more productive. There are just so many things that it does very well, and it&#8217;s so extensible and introspective.</p>
]]></content:encoded>
			<wfw:commentRss>http://lojic.com/blog/2010/03/17/switching-from-carbonemacs-to-emacs-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Send Growl Notifications From Carbon Emacs On OSX</title>
		<link>http://lojic.com/blog/2009/08/06/send-growl-notifications-from-carbon-emacs-on-osx/</link>
		<comments>http://lojic.com/blog/2009/08/06/send-growl-notifications-from-carbon-emacs-on-osx/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 11:42:52 +0000</pubDate>
		<dc:creator>Brian Adkins</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[emacs]]></category>

		<guid isPermaLink="false">http://lojic.com/blog/?p=666</guid>
		<description><![CDATA[I found a handy article for sending growl notifications from Emacs and made some modifications for my particular setup.
Step One: Register Emacs with Growl
We need to register Carbon Emacs with Growl. This is a one time setup task. The following AppleScript script can be run in Script Editor.

tell application "GrowlHelperApp"
	-- Declare a list of notification [...]]]></description>
			<content:encoded><![CDATA[<p>I found <a href="http://alexott.blogspot.com/2008/11/working-with-growl-from-emacs.html">a handy article</a> for sending <a href="http://growl.info/">growl notifications</a> from <a href="http://homepage.mac.com/zenitani/emacs-e.html">Emacs</a> and made some modifications for my particular setup.</p>
<p><strong>Step One: Register Emacs with Growl</strong><br />
We need to register Carbon Emacs with Growl. This is a one time setup task. The following AppleScript script can be run in Script Editor.</p>
<pre class="code">
tell application "GrowlHelperApp"
	-- Declare a list of notification types
	set the allNotificationsList to {"Emacs Notification"}

	-- Declare list of active notifications.  If some of them
	-- isn't activated, user can do this later via preferences
	set the enabledNotificationsList to {"Emacs Notification"}

	-- Register our application in Growl.
	register as application "Emacs.app" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "Emacs.app"
end tell
</pre>
<p><strong>Step Two: Create Growl Notification Script</strong><br />
This is a template of the AppleScript that will be used in the Emacs Lisp function. It can be tested by executing it in the Script Editor.</p>
<pre class="code">
tell application "GrowlHelperApp"
	notify with name "Emacs Notification" title "Emacs alert" description "Message!!!" application name "Emacs.app"
end tell
</pre>
<p><strong>Step Three: Emacs Lisp Function</strong><br />
Create an Emacs Lisp function that can be invoked with a title and message.</p>
<pre class="code">
(defun bja-growl-notification (title message &#038;optional sticky)
  "Send a Growl notification"
  (do-applescript
   (format "tell application \"GrowlHelperApp\"
              notify with name \"Emacs Notification\" title \"%s\" description \"%s\" application name \"Emacs.app\" sticky %s
           end tell"
           title
           (replace-regexp-in-string "\"" "''" message)
           (if sticky "yes" "no"))))
</pre>
<p>This can be tested with the following function which sends two growl notifications. The &#8220;sticky&#8221; one requires an explicit dismissal.</p>
<pre class="code">
(defun bja-growl-test ()
  (interactive)
  (bja-growl-notification "Emacs Notification" "This is my message")
  (bja-growl-notification "Emacs Notification" "This is my sticky message" t))
</pre>
<p><strong>UPDATE:</strong> I noticed bja-growl-notification was failing if the message had embedded double quotes, so I added a call to replace-regexp-in-string to replace them with two apostrophes.</p>
<p><strong>UPDATE 2:</strong> My main motivation for setting this up was to be able to generate growl notifications from ERC (Emacs IRC client). However, I quickly realized that having a generic reminder that I can easily fire up from within Emacs is very handy. Here&#8217;s the code:</p>
<pre class="code">
(defun bja-growl-timer (minutes message)
  "Issue a Growl notification after specified minutes"
  (interactive (list (read-from-minibuffer "Minutes: " "10")
                     (read-from-minibuffer "Message: " "Reminder") ))
  (run-at-time (* (string-to-number minutes) 60)
               nil
               (lambda (minutes, message)
                 (bja-growl-notification "Emacs Reminder" message t))
               minutes
               message))
</pre>
]]></content:encoded>
			<wfw:commentRss>http://lojic.com/blog/2009/08/06/send-growl-notifications-from-carbon-emacs-on-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Retrieve Sunrise, Sunset &amp; Twilight Info in Ruby</title>
		<link>http://lojic.com/blog/2009/03/11/retrieve-sunrise-sunset-twilight-in-ruby/</link>
		<comments>http://lojic.com/blog/2009/03/11/retrieve-sunrise-sunset-twilight-in-ruby/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 05:41:54 +0000</pubDate>
		<dc:creator>Brian Adkins</dc:creator>
				<category><![CDATA[internet]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[science]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[astronomy]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[usno]]></category>

		<guid isPermaLink="false">http://lojic.com/blog/?p=418</guid>
		<description><![CDATA[Sunrise, Sunset &#38; Twilight
I was curious about the exact time of sunrise &#38; sunset at my location, so I found this US Naval Observatory site. In the process, I learned a more precise definition of  twilight. I wanted to be able to automate the process of retrieving the information, so my first attempt was [...]]]></description>
			<content:encoded><![CDATA[<h2>Sunrise, Sunset &amp; Twilight</h2>
<p><a href="http://lojic.com/blog/wp-content/uploads/2009/03/seascape_after_sunset_900x600.jpg"><img class="alignleft size-medium wp-image-441" title="Twilight" src="http://lojic.com/blog/wp-content/uploads/2009/03/seascape_after_sunset_900x600-300x200.jpg" alt="Twilight" width="300" height="200" /></a>I was curious about the exact time of sunrise &amp; sunset at my location, so I found this <a href="http://aa.usno.navy.mil/data/docs/RS_OneDay.php">US Naval Observatory</a> site. In the process, I learned a more precise definition of  <a href="http://aa.usno.navy.mil/faq/docs/RST_defs.php#top"><em>twilight</em></a>. I wanted to be able to automate the process of retrieving the information, so my first attempt was to simply put the query parameters used in the form in the URL as an HTTP GET request, but the server wouldn&#8217;t accept that, so I needed to issue an HTTP POST request.<br />
<br style="clear: left;" /></p>
<h2>Ruby Code</h2>
<p>Ruby is a great language for this sort of task, so I put together the following simple program:</p>
<pre>require 'net/http'

YOUR_ID    = ''    # A unique ID per comment above
YOUR_CITY  = ''    # The name of your city
YOUR_STATE = ''    # Two letter state abbreviation

now   = Time.now
month = now.month
day   = now.day + 1 # Tomorrow
year  = now.year

Net::HTTP.start('aa.usno.navy.mil') do |query|
  response = query.post('/cgi-bin/aa_pap.pl',
    "FFX=1&amp;amp;amp;amp;ID=#{YOUR_ID}&amp;amp;amp;amp;xxy=#{year}&amp;amp;amp;amp;xxm=#{month}&amp;amp;amp;amp;xxd=#{day}&amp;amp;amp;amp;st=#{YOUR_STATE}&amp;amp;amp;amp;place=#{YOUR_CITY}&amp;amp;amp;amp;ZZZ=END")
  if response.body =~ /Begin civil twilight[^0-9]*(\d+:\d{2} [ap].m.).*Sunrise[^0-9]*(\d+:\d{2} [ap].m.).*Sunset[^0-9]*(\d+:\d{2} [ap].m.).*End civil twilight[^0-9]*(\d+:\d{2} [ap].m.)/m
    puts "#{month}/#{day}/#{year}"
    puts "Begin Twilight: #{$1}"
    puts "Sunrise       : #{$2}"
    puts "Sunset        : #{$3}"
    puts "End Twilight  : #{$4}"
  end
end</pre>
<p>You just need to edit the three constants that begin with YOUR_. The id used on the Navy web form is &#8216;AA&#8217;, but they have a comment in the HTML that requests you use a unique id of your own up to 8 characters to help them with tracking. You can find a more complete version of <a href="http://github.com/lojic/sample_code/blob/7b41e88adefd84154a54c97de86924f8517dca2c/ruby/sunrise_http_post.rb">the code</a> in my <a href="http://github.com/lojic">github profile</a>.</p>
<h2>Emacs Goodness</h2>
<p>After writing the above Ruby script, I made it executable, &#8216;chmod +x sunrise.rb&#8217;, and placed it in my path so I could write a simple Emacs function to invoke it.</p>
<pre>(defun bja-sunrise ()
  "Display sunrise, sunset &amp;amp; twilight information."
  (interactive)
  (shell-command "sunrise.rb"))</pre>
<p>Imagine my surprise when I invoked the Emacs apropos help &#8216;C-h a&#8217; to see my newly defined function and discovered that Emacs, naturally, already has several commands to display sunrise/sunset information!</p>
<dl>
<dt>calendar-mouse-sunrise/sunset</dt>
<dd>Show sunrise/sunset times for mouse-selected date.</dd>
<dt>calendar-sunrise-sunset</dt>
<dd>Local time of sunrise and sunset for date under cursor.</dd>
<dt>sunrise-sunset</dt>
<dd>Local time of sunrise and sunset for today.  Accurate to a few seconds.</dd>
</dl>
<p>It doesn&#8217;t, however, display <strong>twilight</strong> information, so my simple function still has a purpose in life. Emacs is awesome :)</p>
]]></content:encoded>
			<wfw:commentRss>http://lojic.com/blog/2009/03/11/retrieve-sunrise-sunset-twilight-in-ruby/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Nice Fonts for GNU Emacs on Ubuntu Linux</title>
		<link>http://lojic.com/blog/2008/02/07/nice-fonts-for-gnu-emacs-on-ubuntu-linux/</link>
		<comments>http://lojic.com/blog/2008/02/07/nice-fonts-for-gnu-emacs-on-ubuntu-linux/#comments</comments>
		<pubDate>Thu, 07 Feb 2008 16:13:18 +0000</pubDate>
		<dc:creator>Brian Adkins</dc:creator>
				<category><![CDATA[software]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://lojic.com/blog/2008/02/07/nice-fonts-for-gnu-emacs-on-ubuntu-linux/</guid>
		<description><![CDATA[UPDATE 12/24/08: This article is now out of date. I just installed Ubuntu 8.10, and getting Emacs with nice fonts is now much easier:

Install the emacs-snapshot-gtk package
Edit ~/.Xresources to have
Emacs.font: Bitstream Vera Sans Mono-10
xrdb -merge ~/.Xresources


Before discussing how to get nice fonts for emacs, it might be reasonable to ask, &#8220;why emacs?&#8221; I haven&#8217;t fully [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE 12/24/08:</strong> This article is now out of date. I just installed Ubuntu 8.10, and getting Emacs with nice fonts is now much easier:</p>
<ol>
<li>Install the emacs-snapshot-gtk package</li>
<li>Edit ~/.Xresources to have<br />
Emacs.font: Bitstream Vera Sans Mono-10</li>
<li>xrdb -merge ~/.Xresources</li>
</ol>
<hr />
<p>Before discussing how to get nice fonts for emacs, it might be reasonable to ask, &#8220;why emacs?&#8221; I haven&#8217;t fully answered that question myself, but had I not been able to get nice, readable fonts on emacs, I probably wouldn&#8217;t continue researching it. For the info on getting nice fonts to work, scroll down to &#8220;Nice Fonts&#8221; below.</p>
<p>After many years of using large IDEs to develop software, I switched to <a href="http://www.vim.org/">vim</a> about a year and a half ago when I began developing with Ruby on Rails. Although the learning curve for vim was a bit steep, I quickly got to the point of being more productive with vim than I was with my previous IDE, and I&#8217;m continually learning features of vim that save me time and effort.</p>
<p>Ok, if vim is so great, why am I considering emacs? In a word, Lisp. Emacs, has great Lisp support. For the little bit of Lisp dabbling I&#8217;ve been doing, vim has been fine, but from what I&#8217;ve seen demonstrated with emacs and slime, I think it&#8217;s worth researching. Another important factor is that emacs is scripted with elisp, a dialect of Lisp. I&#8217;ve never taken the time to read up on vim scripting, but scripting emacs with elisp seems easy. Type in some elisp code into the scratch buffer, evaluate it, and it&#8217;s integrated immediately into emacs. I haven&#8217;t written any vim scripts in a year and a half, but within a few hours of researching emacs, I had implemented several elisp scripts (from source obtained online).</p>
<p>Here&#8217;s one to simulate the % command in vim which moves the cursor to the matching paren:</p>
<pre>
(defun match-paren (arg)
  "Go to the matching paren if on a paren; otherwise insert %."
  (interactive "p")
  (cond ((looking-at "\s(") (forward-list 1) (backward-char 1))
	((looking-at "\s)") (forward-char 1) (backward-list 1))
        (t (self-insert-command (or arg 1)))))

(global-set-key "%" 'match-paren)
</pre>
<p>Here&#8217;s one to simulate the vim o and O commands which open a new line either below or above the cursor and position the cursor properly indented, so you can start typing immediately. I use this quite often in vim:</p>
<pre>
(defun bja-open-line-below ()
  (interactive)
  (end-of-line)
  (open-line 1)
  (next-line 1)
  (indent-according-to-mode))

(global-set-key [?C-o] 'bja-open-line-below)

(defun bja-open-line-above ()
  (interactive)
  (beginning-of-line)
  (open-line 1)
  (indent-according-to-mode))

(global-set-key [?M-o] 'bja-open-line-above)
</pre>
<p>After my brief exposure to emacs, I think vim is more concise. In other words, it appears that vim can accomplish a given task with fewer keystrokes than emacs. I&#8217;m curious to see how hard it is to extend emacs to have some of the niceties I&#8217;m used to with vim. Maybe I can have the best of both worlds &#8211; the conciseness of vim and the extensibility and Lisp support of emacs. Lennart Borgman passed on a link to <a href="http://www.emacswiki.org/cgi-bin/wiki/vimpulse.el">vimpulse.el</a>, so I&#8217;ll take a look at it soon.</p>
<p>I swapped my caps-lock with my left control key a long time ago, so the emacs chording isn&#8217;t quite as much of a problem, but I still wonder if vim might be easier on the hands/wrists since it requires very little chording.</p>
<p>I know some famous lispers use vi(m) for Lisp development, so I don&#8217;t think emacs is a must-have. Also, if I end up using a commercial Lisp such as Lispworks or Allegro, I may consider returning to an IDE for lisp development. So, at this stage, I&#8217;m still very much a vim user who is researching emacs.</p>
<p><strong>UPDATE:</strong>Well, sometime between the original post and now I became a die-hard GNU Emacs user, so I figured I&#8217;d update the post :)</p>
<p><strong>Nice Fonts</strong></p>
<p>But enough of that, how do you get nice fonts on emacs? I had heard that the new version of emacs (22) provided anti-aliased fonts, but apparently I was mistaken. I spent hours Googling and rebuilding emacs to no avail &#8211; quite a frustrating experience. Then I posted a question on the gnu.emacs.help usenet group and received a helpful reply in a few minutes which did the trick. <a href="http://groups.google.com/group/gnu.emacs.help/browse_frm/thread/56467e1d7e39d279/61f2560701405cc8?hl=en#61f2560701405cc8">Here&#8217;s the thread.</a></p>
<p>Here&#8217;s what I did:</p>
<pre>
cvs -z3 -d:pserver:anonymous@cvs.savannah.gnu.org:/sources/emacs co emacs
cd emacs
./configure --enable-font-backend --with-gif=no
make bootstrap
make
sudo make install
</pre>
<p>After that, I was able to use the &#8216;Bitstream Vera Sans Mono-10&#8242; font, and it looks great!</p>
<pre>
emacs -r -fn "Bitstream Vera Sans Mono-10"
</pre>
<p>The -r flag is for reverse video. I much prefer a black background. After making emacs from the cvs sources, it reports its version as 23.0.60.2.</p>
<p>After editing my ~/.Xresources file to have the following line:</p>
<pre>
Emacs.font: Bitstream Vera Sans Mono-10
</pre>
<p>And running the command:</p>
<pre>
xrdb -merge ~/.Xresources
</pre>
<p>Emacs automatically uses that font at startup.</p>
<p>During my hours of Googling, I had seen the page with the correct information <a href="http://www.emacswiki.org/cgi-bin/wiki/XftGnuEmacs">here</a>. But in my haste, I read the statement, &#8220;<em>Note: Since the emacs-unicode-2 branch which had the xft support is merged into trunk, the current page is obsolete.</em>&#8220;, and somehow got the impression that the <strong>entire</strong> page was obsolete, but apparently that is not the case.<strong>*</strong></p>
<p>Fortunately, the helpful folks on gnu.emacs.help set me straight &#8211; thanks guys!</p>
<p><strong>*UPDATE:</strong> I edited the wiki page referenced above, so the &#8220;obsolete&#8221; notice is further down the page.</p>
]]></content:encoded>
			<wfw:commentRss>http://lojic.com/blog/2008/02/07/nice-fonts-for-gnu-emacs-on-ubuntu-linux/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

