Showing posts with label emacs. Show all posts
Showing posts with label emacs. Show all posts

Friday, December 14, 2007

aspell for emacs and Mac OS X

Here's how to add a spelling checker to Emacs on Mac OS X. This will work for both terminal based or GUI based versions.

First, for goodness sake, install MacPorts. After it is installed from terminal do:

$ sudo port -v selfupdate
$ sudo port install aspell-dict-en

You can install other languages too. Take a look at "port search aspell" for the list.

Then just add the following line to your .emacs

(setq ispell-program-name "/opt/local/bin/aspell")

Load you your text (or html or xm) file and do M-x ispell

Oh yeah! You can read more on the Emacs commands here

Sunday, September 2, 2007

ruby-mode for emacs

I'm not really a ruby guy, but recently I had to do some ruby hacking, which means I needed ruby-mode for emacs. Between the InterWeb, RubyGarden, and EmacsWiki, I couldn't find a clear, correct description of how to get ruby-mode. Here's my take.

Step 1: Why not upgrade emacs?

Did you know emacs finally released a new version?!

If you are using MacPorts, do this for a terminal (non-gui version). Do port variants emacs for other options.

sudo port install -v emacs

Step 2: Download the code

We are going to install our lisp code in ~/.emacs.d/site-lisp which I think is more-or-less standard, but you could use any directory.

export SITE_LISP=~/.emacs.d/site-lisp
mkdir -p $SITE_LISP
svn export http://svn.ruby-lang.org/repos/ruby/trunk/misc ${SITE_LISP}/ruby
emacs -batch -f batch-byte-compile ${SITE_LISP}/ruby

Don't forget that last step! That compiles the lisp code, and will make emacs run faster (handy if you re-indent a large file).

Step 3: Configure your .emacs

Add this to your .emacs. This is a complete rip from RubyGardens's Installing Emacs Extensions, with the exception of the first line.

;; ruby                                                                         
;; based on http://www.rubygarden.org/Ruby/page/show/InstallingEmacsExtensions  
;;                                                                              

(add-to-list 'load-path "~/.emacs.d/site-lisp/ruby")

 (autoload 'ruby-mode "ruby-mode"
     "Mode for editing ruby source files")
 (add-to-list 'auto-mode-alist '("\\.rb$" . ruby-mode))
 (add-to-list 'interpreter-mode-alist '("ruby" . ruby-mode))
 (autoload 'run-ruby "inf-ruby"
     "Run an inferior Ruby process")
 (autoload 'inf-ruby-keys "inf-ruby"
     "Set local key defs for inf-ruby in ruby-mode")
 (add-hook 'ruby-mode-hook
     '(lambda ()
         (inf-ruby-keys)))
 ;; If you have Emacs 19.2x or older, use rubydb2x                              
 (autoload 'rubydb "rubydb3x" "Ruby debugger" t)
 ;; uncomment the next line if you want syntax highlighting                     
 (add-hook 'ruby-mode-hook 'turn-on-font-lock)

Step 4: Get back to work

EOF

Emacs 22.1

Did you know emacs finally popped out a new release? The last release was in Feb 6, 2005! Yes 2.5 years ago. You probably have been using a snapshotted version, but now it's time to upgrade to the real version. The list of changes is kinda long: 230K of raw text. I mostly use emacs in the terminal (not GUI), on Mac OSX, and mostly for programming. Here's my greatest hits.

Mac OS X Support

Finally official and supported. This is more a big deal if you use a GUI. For terminal users, the following key remapping command may be useful

** The variable `mac-command-key-is-meta' is obsolete.  Use
`mac-command-modifier' and `mac-option-modifier' instead.

Tidbits

ruler-mode is neato.

display-battery-mode -- more toys!

;; turn off the splash screen on startup
(setq inhibit-splash-screen t)

New major modes

python-mode was finally added. ruby-mode, javascript/emacs-script-mode still absent. Boo!

dns master files, and cfengine config file however get their own mode.

conf-file major mode

conf-mode is a new major mode for editing conf file. Apparently it can recongize .cf, .config.properties, .desktop, .ini, and "many others".

If emacs doesn't recognize your conf file, I suppose you need to add something like this to your .emacs

(add-to-list 'auto-mode-alist '("\\.XXX$" . conf-mode))

cc-mode improvements

all sorts of parsing improvements to C++

Doc-comment highlighting. For you javadocs can now be color coded. Oddly, no support Doxygen! They they the system is plug-inable. So maybe this can be fixed. More here

Doxygen does support javadoc style comments in C++ code, so if you do that, then add this to your .emacs

(add-hook 'c++-mode-hook
    (function (lambda ()
        (add-to-list 'c-doc-comment-style '(c++-mode . javadoc))))

Other programming stuff improved

More improvements to M-x compile to support more messages

Lots of improvements and additions in etags for: C, C++, HTML, PHP, Lua, perl, prolog

flymake

Quote:
** The new package flymake.el does on-the-fly syntax checking of program
source files.  See the Flymake's Info manual for more details.

The idea is thatin the background, your source file will be get compiled and proactively tell you where you made mistakes. I haven't tried it yet, but it sounds interesting.

Wow, there is a movie demo-ing this feature. A movie on emacs. Amazing. It's oddly effective. Oh yeah, flymake is cool too. I may yet need to upgrade to GUI version of emacs.

File Operations

*** The new hook 'before-save-hook' is invoked by `basic-save-buffer'
before saving buffers.  This allows packages to perform various final
tasks.  For example, it can be used by the copyright package to make
sure saved files have the current year in any copyright headers.

I don't remember where I saw this, but I'm told this is also Emacs 22

;;
;; Trick for emacs 22
;; if the script has a first line of "#!" then do chmod a+x
;;
(add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)