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

Monday, November 7, 2011

Displaying ANSI Escape Sequences in Windows

I installed Busybox on my Samsung Galaxy S II to enjoy the Swiss Army Knife of Embedded Linux. When I want to look at my phone SD card content, I often use adb if the phone is connected with my laptop. So I typed the following command at Windows command prompt:

adb shell ls /sdcard

What I got is somehow scary as shown below (only first line is shown):

←[1;34mAndroid←[0m ←[1;34mTitaniumBackup←[0m

After a while, I realized that what is shown is actually ANSI escape codes. The ls command provided by Busybox is actually showing color codes by default.

So what shall I do? I know option --color=never can suppress ANSI escape sequences but I don't like typing such long keystrokes. On the other hand, getting useful information out of those ANSI codes is very difficult. My first reaction is trying to see whether Windows shell can show those ANSI codes. I remember my old friend DOS can display ANSI codes, so a modern Windows 7 should be able to do so. But I cannot find relevant configuration in Properties dialog of command prompt. After reading Wikipedia page on ANSI escape codes, I found the following sentence Console windows in all versions of Windows do not support ANSI escape sequences at all. Therefore the only solution is to find some console replacements which can show ANSI codes.

I do found some by Googling. But before trying one, I asked myself why I should install one software for just such a trivial task? I suddenly thought: how about Emacs shell? Maybe Emacs folks have already solved this issue? So I fired up Emacs, typed M-x shell, and typed adb shell ls /sdcard in Emacs shell. Bingo! All ANSI color codes are correctly shown, just as in an Linux box when typing ls --color.

Ubiquitous Emacs to the rescue again.

Saturday, December 25, 2010

Switching From Gentoo Linux to Arch Linux

Introduction

Although I have been using Gentoo Linux for several years, I started to consider switching to other Linux distributions. The main drawback of Gentoo is that too much time is spent on compiling. It is really cool to build a cutting-edge system, however the time spent on building it and maintaining it is enormous. Therefore I am searching a minimalist's Linux distribution with binary packages. Arch Linux seems to be quite good. I gave it a try under VirtualBox 4.0. The reference I used was Beginner's Guide.


Install the base system

The overall installation steps are quite similar to Gentoo: you need to configure many things by hand. The difference is that the installation is significantly faster.

If possible, one should select the fastest mirror since downloading time is the most significant component of installing Arch Linux packages. For me, I select the mirror listed here with the best score for my location. After determining the mirror, you can download the ISO image from that mirror, and add it to your /etc/pacman.conf after installation. For example by adding Server = http://mirror.url/archlinux/$repo/os/x86_64 under the repo names, or uncomment preferred mirros in /etc/pacman.d/mirrorlist (which is preferred). As an alternative, one may also try reflector after installing Arch Linux. Yet another option (I'm currently using) is to rely on script rankmirrors (according to here) to select the fastest mirrors. Note that for rankmirrors option, file /etc/pacman.conf needs one line Architecture = x86_64.

To enable the compatibility with 32-bit legacy programs (like Android emulator), multilib should be enabled in pacman.conf as below:

[multilib]
Include = /etc/pacman.d/mirrorlist

Simply download the latest ISO image. I used "core" image since it contains all the base packages for installation. The latest version as writing is archlinux-2011.08.19-core-x86_64.iso. Download and mount it under VirtualBox. Then boot the virtual machine.

For help, open a virtual terminal (by typing Alt+F2) and type less /arch/beginnersguide.txt

The installation steps are as follows:

  1. Login as root.
  2. Type /arch/setup to start the installer.
  3. Select the source as "core-local".
  4. Select Editor according to your taste.
  5. Set the clock by selecting region and timezone according to your location. You should know whether your hardware clock is UTC or local (my settings in VirtualBox is UTC). The recommended setting is UTC.
  6. For "Prepare Hard Drive(s)", firslty I choose "Manually Partition Hard Drives" and then "Manually Configure block devices, file systems and mount points.". I only setup two partitions, /boot partition (200 MB, ext2), and root partition (remaining disk, ext4.)". For menu "Partition Access Method", select "uuid".
  7. After completing partitioning, go back to main menu and select "Select Packages. For bootloaders, choose "grub". Then for package, select "base-devel" meta-package as well, and select following packages in addition: gpm, inetutils, linux-header, mlocate, ncurses, openssh, pacman-mirrorlist, readline, sqlite3, sqlite3-doc, sudo, xinetd.
  8. Select "Install Packages" from main menu. Select "Yes" to keep packages in pacman cache.
  9. Select "Configure the System" from main menu.
    • Modify /etc/rc.conf. Change "foo" to your desired host name.
      # NETWORKING
      
      interface=eth0
      
      I also removed netfs from DAEMONS line.
    • Write your desired host name to /etc/hostname.
    • Modify /etc/fstab by adding options noatime and nodiratime to partition /.
    • Modify /etc/locale.gen by uncommenting the lines starting as "zh_CN" since I'm a Chinese.
    • Modify /etc/pacman.conf by uncommenting the Xfercommand line in /etc/pacman.conf for wget.
    • Modify /etc/pacman.d/mirrorlist by uncomment your preferred mirrors as discussed above.
    • Change root password.
  10. Back to main menu, select "Install Boot loader". Add option "vga=0x360" for customed VESA mode provided by VirtualBox (as discussed below). Install the bootloader to master boot record (sda in my case).
  11. Finally, select "Exit Install" and type reboot to turn on the new system.

Configuration and Graphics User Interface

This section documents further installation and customization I made.

VirtualBox related settings

Install custom VESA mode to support your PC/Laptop's screen resolution according to VirtualBox manual, if necessary.

Install VirtualBox guest additions as shown below (note that we need to install kernel headers first to compile the additions). Reboot is needed to make additions work. Note that if you want to install Xorg, you can run VBoxLinuxAdditions.run after completing pacman -S xorg. Optionally package xorg-xinit can be installed for script startx and package rxvt-unicode for a nice terminal.

# mkdir /mnt/cdrom
# mount -t iso9660 /dev/cdrom /mnt/cdrom
# cd /mnt/cdrom
# ./VBoxLinuxAdditions.run
# reboot

Proxy: for proxy, add export http_proxy=proxy.url to .bashrc of root. If subversion was later installed, oen need to modifiy ~/.subversion/servers for lines containing http-proxy-host and http-proxy-port. When using sudo to update pacman, one need to add the following line after typing visudo: Defaults env_keep += "http_proxy https_proxy".

To share folders between host and Linux guest, one need to first setup the sharing in VirtualBox GUI. Then after installing Guest Additions as discussed above, the sharing can be enabled like below (assuming the shared folder name is bar and you want to mount it in your Linux guest directory /mnt/bar):

# mkdir /mnt/bar
# mount -t vboxsf bar /mnt/bar

Add additional user

# useradd -m -G audio,optical,storage,video,wheel foo
# passwd foo

Change foo to your desired name.

Run visudo to edit file /etc/sudoers. Uncomment the 1st line containing wheel to enable running root commands from wheel group. One may add lines like Defaults env_keep += "http_proxy" to pass environment variables.

Handling of security

Ru nthe following command: cp /etc/pacman.conf.pacnew /etc/pacman.conf. Apply all previously mentioned changes to /etc/pacman.conf to the overwrittine file. Then uncomment following line:

SigLevel = Optional TrustAll

Run pacman-key --init to initialize keyrings.

Cleanup unused packages

Since some packages are not useful to me, I remove them to avoid future waste of time and bandwidth to update them. Note that you may use pacman -Qe to list the explicitly installed packages. Warning: please make sure you do understand what you're doing: removing important system packages may break your system. As shown below, I only remove those packages related to file systems I'm not using.

# pacman -Rsn jfsutils reiserfsprogs xfsprogs

ABS

Run the following command:

# pacman -S abs

Edit /etc/abs.conf, For REPOS line, add ! before testing.

AUR helper

There are lots of AUR helpers, and I chose pacaur after trying various helpers (e.g. pacaur support proxy seamlessly pacman). To install pacaur, one needs to first install yajl and expac using pacman, then install cower and pacaur by running the following command.

$ sudo pacman -S yajl
$ wget http://aur.archlinux.org/packages/co/cower/PKGBUILD ; makepkg -si
$ wget http://aur.archlinux.org/packages/pa/pacaur/PKGBUILD ; makepkg -si

To install packages from AUR, simply run pacaur -S pkg.

SSHD

If one want to run SSHD server, one need to add sshd to DAEMON line of /etc/rc.conf. One may modify /etc/hosts.allow and/or /etc/hosts.deny. Default is that all connections are denied.

Xorg

Install Xorg by simply running pacman -S xorg. Accept the default (although there are many drivers not needed). Afterward, one need to install VirtualBox Guest Addition for video drivers, as discussed above.

Generally, there is no need to modify /etc/X11/xorg.conf since VirtualBox can handle the file for you when installing Guest additions. There is no need to specify screen resolutions since VirtualBox can seamless adjust it according to host resolution. However, if one wants to restrict available resolutions (e.g. to use StumpWM which is not compatible with VirtualBox's seamleass operation), one can add the following line in Section Screen, Subsection Display. Below example sets up two resolutions with 60 Hz refresh rate.

  Modes "1680x1050_60.00" "1440x900_60.00"

One may install package mesa-demos to benchmark OpenGL performance with glxgears.

For better font rendering, one may install freetype2-infinality, fontconfig-infinality, ttf-google-webfonts, and libxft-lcd from AUR.

GNOME

Install GNOME by typing the command pacman -S gnome. Then add dbus to DAEMONS array in /etc/rc.conf.

Add the following line to ~/.xinitrc:

#!/bin/sh

# Make sure it is at the beginnig of the file, especially before "exec gnome-session"
[ -f /etc/xprofile ] && . /etc/profile
[ -f ~/.xprofile ] && . ~/.xprofile
exec gnome-session

For VirtualBox, type the following to use GNOME 3:

# ln -s /usr/lib/xorg/modules/dri/vboxvideo_dri.so /usr/lib/dri
# pacman -S libltdl # Such reinstallation is needed.
$ gnome-shell --replace

To start GNOME, simply type startx.

I installed following packages in addition:

gconf-editor
- Edit GNOME settings
gnome-system-tools
- contains GNOME admin tools
gksu
- allows normal user to use system tools
gamin
- allows changes to files and directories to be detected immediately.
gnome-media-pulse
- enables volume control as tray notification
faenza-icon-theme
- cool icon theme
baobab
- disk usage

To select fonts suitable for LCD display, right click mouse on desktop, then select Change Desktop Background -> Font, select "Subpixel smoothing (LCDs)" for Rendering.

Update (2011-05-03): I installed login manager GDM by typing pacman -S gdm, and perform following changes to /etc/inittab:

  • comment line id:3:initdefault:
  • uncomment line id:5:initdefault:
  • comment line x:5:respawn:/usr/bin/xdm -nodaemon
  • uncomment line x:5:respawn:/usr/sbin/gdm -nodaemon

Audio

In VirtualBox settings for Audio Controller, I select Intel HD Audio. The sound car can be automatically detected by udev. So what needs to be done is to unmute some channels and let alsa store and restore mixer settings.

# pacman -S alsa-utils
# amixer set Master 90% unmute
# amixer set PCM 85% unmute
# aplay /usr/share/sounds/alsa/Front_Center.wav
# alsactl -f /var/lib/alsa/asound.state store

Finally, edit /etc/rc.conf and add "alsa" to DAEMONS array to store on shutdown and restore mixer settings on boot.


Customization and Applications

Note: this part is quite personal. The purpose I wrote it is mainly for documenting the steps so I myself may use it later.

Applications

Following is a list of applications installed by category. Some packages are only available from AUR and are marked by suffix [A].

  • Development tools: gdb, strace, cmake, valgrind, gprof2dot-git[A], bochs, qemu, mmixware [A], ghc, cabal-install, sbcl, racket, fluxus-git[A], squeak-vm[A], squeak-image[A], ruby, python, ipython, ipython2, pylint, pychecker, pyflakes, pep8[A], scipy, python2-pybrain [A], python2-nltk, wxpython, python-httplib2, python-pygame, ropemacs[A], matplotlib, libgnomeui, python2-pandas, django, nginx, gunicorn[A], postgresql, python2-psycopg2, auto-complete[A], jdk7-openjdk, visualvm[A], eclipse, eclipse-findbugs[A], android-sdk[A], android-ndk[A], android-sdk-platform-tools[A], emacs-android-git[A], scala, scala-docs, scala-sources, sbt, r, emacs-ess-svn[A], nasm, clojure, subversion, rapidsvn, ctags, git, perl-term-readkey, tig, tk, perl-libwww, mercurial, darcs[A], xmlstarlet, cconv[A], emacs-markdown-mode-git[A]
  • Documentation: texlive-most, pdftk[A], aspell-en, multimarkdown-git
  • Font: ttf-dejavu, ttf-inconsolata, terminus-font, wqy-bitmapfont, wqy-zenhei, wqy-microhei[A], ttf-arphic-uming, ttf-ms-fonts[A], ttf-vista-fonts[A], ttf-ms-fonts-zh_cn[A]
  • Multimedia: mplayer, mencoder, ffmpeg, codecs, cdparanoia, lame, cuetools, flac, shntool, wavpack, mac, mp3info, vorbis-tools
  • Web: lynx, chromium, flashplugin-prerelease, w3m, curl, amule
  • Utilities: gnupg, unzip, zip, p7zip
  • Graphics: gnuplot, inkscape, processing, graphviz, gimp, blender, imagemagick, darktable
  • Reader: djview4 , evince, kchmviewer, fbreader, calibre, pdf2djvu, catdoc, tesseract, tesseract-data-eng
  • Network: whois, nfs-utils, xinetd
  • Mathematics: maxima
  • Education: timidity++, solfege
  • X: xscreensaver
  • Fun: povray
  • Libraries: gsl, atlas-lapack[A], libmtp
  • Science: pymol, biopython, stellarium, celestia

Chinese Input

I install ibus as below:

# pacman -S ibus ibus-pinyin

Then add the following lines into ~/.xprofile:

export XMODIFIERS=@im=ibus
export GTK_IM_MODULE=ibus
export QT_IM_MODULE=ibus
ibus-daemon -d -x

Update (2011-01-06): switch from SCIM to ibus.

Emacs

For Emacs package management, el-get is interesting to try. The installation method is very unique and there is no need for an ArchLinux package.

Install scala-mode as below:

$ cd ~/.emacs.d/plugins
$ svn co http://lampsvn.epfl.ch/svn-repos/scala/scala-tool-support/trunk/src/emacs/ scala-mode

Get anything.el by wget http://www.emacswiki.org/emacs/download/anything.el.

Install following packages: auctex, slime-cvs, emacs-w3m-cvs, pymacs.

Install clojure related modes.

$ cd ~/.emacs.d/plugins
$ git clone https://github.com/technomancy/clojure-mode.git clojure-mode
$ git clone https://github.com/technomancy/swank-clojure.git
$ mkdir ~/.swank-clojure
$ cd ~/.swank-clojure
## Get three jars in https://github.com/technomancy/swank-clojure/blog/master/swank-clojure.el manually.

Install Hyperspec for Common Lisp

Run the following commands:

# wget ftp://ftp.lispworks.com/pub/software_tools/reference/HyperSpec-7-0.tar.gz
# tar xzvf HyperSpec-7-0.tar.gz
# mkdir /usr/share/doc/hyperspec
# mv HyperSpec !$

Stumpwm

First invoke sbcl, then type the following into REPL. Note that ASDF install is used other than AUR. Note that installation of trivial-gray-streams, flexi-streams, and cl-unicode might not be needed.

(require 'asdf)
(require 'asdf-install)
(asdf-install:install "http://common-lisp.net/project/cl-plus-ssl/download/trivial-gray-streams.tar.gz")
(asdf-install:install "http://weitz.de/files/flexi-streams.tar.gz")
(asdf-install:install "http://weitz.de/files/cl-unicode.tar.gz")
(asdf-install:install 'clx)
(asdf-install:install 'cl-ppcre)

When prompted by "Install where", it is recommended to select "Personal Installation" since it does not require root privilege. Note that some packages do not have GPG signature, so if SBCL drops you into debugger, simply select skip GPG check. If SBCL complaints and exited (due to in --disable-debugger mode), type the following after enter sbcl (sb-ext:enable-debugger) or add it to /etc/sbclrc as system initialize file for SBCL.

After installation of the dependencies, quit SBCL by type (sb-ext:quit) and run the following at CLI:

$ git clone http://git.sv.gnu.org/r/stumpwm.git stumpwm
$ cd stumpwm
$ ./autogen.sh
$ ./configure
$ make

After copy stumpwm to a directory in PATH, one can add "exec stumpwm" at the end of ~/.xinitrc. Then typing startx will bring up Stumpwm. Since I installed both GNOME and StumpWM, I decides to write two scrips to automate the changes to .~/.xinitrc. With these scripts, I can type startg for GNOME or starts for StumpWM.

Contents of script startg:

#!/usr/bin/env bash
sed -e 's/exec.*$/exec gnome-session/' -i ~/.xinitrc
startx

Contents of script starts:

#!/usr/bin/env bash
echo "exec stumpwm" > ~/.xinitrc
startx

Miscellaneous

For root, add one line in ~/.bash_profile to enable .bashrc
. $HOME/.bashrc

To run indexing daily, run crontab -e to add the following line (Update (2010-12-28): this step is not needed since updatedb is already added in /etc/cron.daily during installation of mlocate):

11 11 * * * updatedb

To keep boot messages on tty1 instead of clearing screen, add option for tty1 in /etc/inittab like below:

c1:2345:respawn:/sbin/agetty -i -8 38400 tty1 linux

Conclusion

After using Arch Linux for a long time, I have to say that I'm extremely satisfied. Your system may not be extremely fast as Gentoo boxes, but what you gain is significant: invaluable time.

Friday, May 2, 2008

Switching Browsers in Emacs

Recently, I have met one dilemma in Emacs. Since I'm using Emacs for my blog writing, Firefox is used for previewing. Also as an Common Lisp user, I use emacs-w3m to read HyperSpec. Here comes the problem: I can only set one browser for browse-url-browser-function. How can I suit my requirements simultaneously?

Fortunately, Emacs is highly extensible. I just write one simple interactive function toggle-browser, which can toggle between Firefox and emacs-w3m when pressing M-x toggle-browser. Following is the code:

(defun toggle-browser ()
  "Toggle browser between Firefox and emacs-w3m."
  (interactive)
  (setq browse-url-browser-function 
        (if (eql browse-url-browser-function 'browse-url-firefox)
            'w3m-browse-url
          'browse-url-firefox))
  (message "%s" browse-url-browser-function))

Update: please look at the 1st comment from pedro for a better solution.

Friday, December 28, 2007

Install Proggy Fonts for Emacs in Gentoo

Coding horror discussed various nice programming fonts (see here and here). Intrigued by these posts, I decided to try these fonts on my Gentoo box. Following is a record of what I have done.

Install Fonts in Gentoo

I decided to use Proggy Clean font (website is here). This section is mainly related to this particular font, but I will discuss at the end of this section how to handle other fonts in the same site.

Instead of manually installing the font, I determined to writer one ebuild. Main rationale is to rely on font eclass to automate font installation work. The ebuild could be easily reused and even incorporate into Gentoo portage (hopefully). The other reason is that I want to practice a little bit on portage overlay and to write my first (trivial) ebuild.

Create portage overlay

If you have already setup a overlay, you may skip this part. However it should be noted that all the description in this post assumes that your overlay is located in /usr/local/portage.

Run the following commands.

# mkdir -p /usr/local/portage
# echo 'PORTDIR_OVERLAY="/usr/local/portage"' >> /etc/make.conf    

Create the ebuild

First, create the directories.

mkdir -p /usr/local/portage/media-fonts/ttf-proggy-clean

Next, create a file named ttf-proggy-clean-1.0.ebuild under the directory just created. Fill the contents as below.

inherit font

DESCRIPTION="Proggy Clean TTF font"
HOMEPAGE="http://www.proggyfonts.com/"
SRC_URI="http://www.proggyfonts.com/download/download_bridge.php?get=ProggyClean.ttf.zip"

LICENSE="Proggy"
SLOT="0"
KEYWORDS="alpha amd64 arm ia64 ppc s390 sh sparc x86"
IUSE=""

DEPEND=""

S="${WORKDIR}"
FONT_S=${S}
FONT_SUFFIX="ttf"
DOCS="Licence.txt Readme.txt"

RESTRICT="mirror" 

Some explanations of the ebuild:

  • Version: I believe the font is quite stable, therefore version 1.0 should be OK :-).
  • License: the license in the package is quite permissive, but since I cannot link it to any existing license, I category it simply as Proggy.

Run the following command to sign the ebuild.

# ebuild /usr/local/portage/media-fonts/ttf-proggy-clean/ttf-proggy-clean-1.0.ebuild digest

BTW, I refers a lot to this when writing this first ebuild (of course, the skeleton is from man font.eclass).

Install font

Now comes our familiar emerge.

# emerge media-fonts/ttf-proggy-clean

Now we need to add the font path. Open file /etc/X11/xorg.conf, find the section Section "Files", and add the following line within the section:

  FontPath "/usr/share/fonts/ttf-proggy-clean"

Then press Ctrl-Alt-Backspace to restart X server. After login again, you may issue the following command (if you have not installed xlsfonts, please do so by typing emerge xlsfonts).

# xlsfonts | grep proggy

You should see several lines looking like -altsys-proggycleantt.... If not, there is something wrong to fix (please check previous typings).

Caveat: before I add the FontPath line in section Files, that section is actually empty! Therefore X simply cannot restart. The solution is to add some default paths into that section, e.g. /usr/share/fonts/100dpi, /usr/share/fonts/misc.

How to use other fonts

Following is a guideline for other fonts listed in the same website.

  • Use appropriate directory and file name to represent the font. For example, for Proggy Square X font, one might setup directory /usr/local/portage/media-fonts/proggy-square, and create a ebuild called proggy-square-1.0.ebuild. The directory should be added into /etc/X11/xorg.conf as described above.
  • Modify the ebuild:
    • Specify appropriate DESCRIPTION.
    • Use correct SRC_URI.
    • Specify DOCS correctly. I found that X font package does not contain Readme.txt.
    • Specify FONT_SUFFIX. For X fonts, use gz; use ttf (like above) for TTF fonts.

Configure Emacs

Compared with the installation described above, this part is rather easy. Assume that you want to use the font -altsys-proggycleantt-medium-r-normal--0-0-0-0-m-0-iso8859-1 (you may select one from the output of xlsfonts as described above)d, simply add the following line in your .emacs:

(set-default-font "-altsys-proggycleantt-medium-r-normal--0-0-0-0-m-0-iso8859-1")

Thursday, November 8, 2007

Emacs + Firefox as Blog Development Environment

In my previous post, I advocated to use Emacs as a blog post editor. This post deals with how to setup a nice blog development environment with Emacs + Firefox.

Introduction

As discussed in the post on Immersing Tutorial, a development environment is more productive if it can reduce the time for context switching, i.e. keep edit, building and running in the same environment. With Emacs + nXhtml + w3m, we can achieve this goal. The only but critical problem is that the functionalities of w3m is quite limited compared with popular browsers like Firefox: e.g. it does not support Javascript!

After googling around the web, I got the conclusion that it is impossible to embed a Firefox browser within Emacs, i.e. there seems to be no interface like emacs-w3m, which links Emacs and w3m. I'm not sure whether this is due to the fundamental limitations of Emacs or there is purely no interest on such functionality (the former seems to be more likely since even Emacs guru Bill Clementson have to use both Emacs and Firefox).

I then started an adventure to investigate the alternatives. The first thing come into my mind is to resort to Eclipse. After setting up Eclipse + WTP and changing key scheme to Emacs, I successfully created a static Web project and started writing a new XHTML page. The problem I encountered next is that I cannot preview the web page just created! My intuition told me that the context menu "Run as Server" seems to be the solution, however "HTTP Preview" always complained that port 8080 is occupied by another process and I found nowhere to change the port setting. After long time searching, I finally gave up the Eclipse approach: I'm just such a novice to Eclipse that it may not be justified to learn this giant with the only purpose to write blogs.

I then settled down on the approaches to use Emacs and Firefox jointly. I first tried the Edit HTML Bookmarklet, it is quite handy to change the page you're viewing (with similar functionality as Firebug), but the drawback is that your changes are only saved in memory but not on disk. I then installed ViewSourceWith add-on. It can call an external application like Emacs to view and edit the web page you're viewing. It works pretty well but I soon realized that it is not a developing model I like. The underlying concept for this add-on is that your main environment is Firefox and you occasionally invokes Emacs to tweak the HTML code. However what I need is on the contrary: I'd like to work mainly in Emacs, and use Firefox to preview the blog post when necessary.

Finally I come to the current solution I'm using: setup Emacs browse-url functions for Firefox. By doing so, I can edit post in Emacs, and preview it with nXhtml key binding C-C C-h b f. Following is the detailed setup process.

Installation

We are going to look at how to setup the BDE (please do not confuse the term with Borland Database Engine). The easier part is on Firefox, so we treat it first.

Firefox

Just install the latest Firefox distribution. To make efficient usage of Firefox for blog development, one may need Firebug and Web Developer. If you are a fan of Emacs, you may also try Conkeror, but be warned that you should read the manual carefully since it will dramatically changes your Firefox (and your just installed Firebug or Web Developer may not work well with Conkeror).

Emacs

If you read this long, you should be a regular Emacs user therefore you may not need to install Emacs additionally. But just for my future reference, I'd like to note that Emacs 23 worked fine with nXhtml.

Following is a list of Emacs extensions and programs related to Emacs for blog development.

Aspell

We should strive to remove spelling errors from our blog posts. We may use spell checking functionalities provided by blog services, however this is inefficient considering that we are mainly editing our blogs offline. Therefore on-the-fly spell checking within Emacs is needed. Aspell is a popular spell checker and Emacs has built-in support for it. So just install aspell and the dictionary for your language, and add the following lines to your .emacs:

(setq-default ispell-program-name "aspell")
(autoload 'flyspell-mode "flyspell" "On-the-fly spelling checker." t)
(add-hook 'nxhtml-mode-hook 'flyspell-mode)
Note that you should ensure that aspell is in your searching path.

nXhtml mode

After download and extracting the package, add the following lines to your .emacs:

(load "/path/to/nxhtml/autostart.el")
(eval-after-load 'nxhtml '(define-key nxhtml-mode-map [f2] 'nxml-complete))
(setq nxhtml-skip-welcome t)

Some explanation of above code:

  • 1st line: change it to match the directory where you installed nXhtml.
  • 2nd line: if you are working in Windows, you need this line since normally nxml-complete is bound to M-tab which is used by Windows itself. You may use keys other than f2 of course.
  • 3rd line: this is to remove the welcome message.

Link Emacs with Firefox

Add the following code to your .emacs:

(setq browse-url-browser-function 'browse-url-firefox
      browse-url-new-window-flag  t
      browse-url-firefox-new-window-is-tab t)

Make sure Firefox is in your search path. Note that currently there is one issue here on Windows (I have not tested under Linux). If there is no running Firefox, the preview works just fine; otherwise, preview actually opens two new Firefox tabs (in addition to those already existed). This is annoying but not a big issue. I have tried a few browser-url related changes in .emacs but failed.

Other Emacs Extensions

You may install other Emacs packages e.g. CSS mode and Javascript mode if you like.

Final Words

After installation, we can now edit blog posts in Emacs (with the help of nXhtml), and preview it in Firefox. So far, so good. It would be exciting if we can embed Firefox in Emacs or vice versa.