Archive for April, 2009

It seems that Ian Eure does not understand us1.

I like to think I’m well acquainted with human laziness…

Maybe apply Occam’s Razor and attribute it to something other than laziness? Even better, trying to look at it from my point of view instead of your own.

Let’s say I’ve sent you a hello world program but it doesn’t work. What do you do? Do you a) write to me and ask me for support, or b) write your own? But this is a bit different you might say.

  1. It is more complicated than hello world, and
  2. I should have some faith in an emacs core module.

Okay then, once I’ve noticed the error, what is my next step? Do I?

  1. Try a bunch of things, figuring that maybe I’ve forgotten to setq a variable or (initialize) something.
  2. Or perhaps I try and debug the module (because we all know that debugging is the favourite programmer activity)?
  3. Do I write to the module maintainer asking what the problem is, or do I
  4. Implement my own solution?

Does he seriously not see how appealing the final option is? If he doesn’t he doesn’t understand programmer mentality very well. At a stroke I get full control over how everything works. I don’t have to wait for someone to respond to me. I don’t have to find out who to contact. I don’t need to fire up my rusty debugger. I get to work on greenfield code. Perhaps best of all, it makes a great case study into how to use comint to interact with a REPL.

And what was the downside in this case? I confused someone I don’t know2.

…but this is a species I just don’t understand.

Hmmm… nice.

So. We can agree that:

  • The UX of sql-mode is bad.
  • Nobody has clearly explained how to use it.

Given this situation, I think it’s insane to say that the correct solution is to document how to work around the bad UX.

Actually, I don’t think I even agree with the first point. And to call documenting how to make things work insane? Well, we’ve all indulged in rhetoric on the internet. No harm no foul.

But you know what? Even now it has been ‘fixed’, I’m still not going to use it. Because I’m guessing he didn’t fix the main thing that I didn’t like and also it takes effort and mine works perfectly well for me.

Thank you to commonman for your comments on Ian’s blog, although I must admit, I’m strangely warming to his point of view after this post.

1. I tried to resist the urge to respond but could not. There goes the moral high ground. I really hope that normal service will be resumed shortly.

2. Just kidding Ian. I know you’re not confused.


Read Full Post »

Emacs Hacks

Emacs-fu requested little emacs tricks and I have a few in my config.

Fixing Cut and Paste

I don’t need this on Windows but when working through an X-server it makes cut and paste work.

(setq x-select-enable-clipboard t)

Ido Mode

I have mentioned ido-mode before in my directory aliases post that everybody has probably seen by now.

(ido-mode t)
(setq ido-enable-flex-matching t)

(setq ido-create-new-buffer 'always)


I use uniquify to distinguish between two identically named files as the default, appending a <n> extension, is rubbish. This tip is from Trey Jackson.

(require 'uniquify)
(setq uniquify-buffer-name-style 'reverse)
(setq uniquify-separator "|")
(setq uniquify-after-kill-buffer-p t)
(setq uniquify-ignore-buffers-re "^\\*")

Tidy Backups

I’m not keen on the way that emacs leaves its backups all over the place. You can fix that by configuring backup-directory-alist.

(setq backup-directory-alist
      (cons '("." . "~/.emacs-backups") backup-directory-alist))

I guess I must have written that a while ago as these days I would use push in preference to setq/cons.

(push '("." . "~/.emacs-backups") backup-directory-alist)

Read Full Post »

The MuuWiki has a comprehensive review of Predictive which is a module that performs a similar function to predictive text in mobile phones. I’ve been looking for something that will help write posts quicker for a while. Could this help? I suspect the answer is no – thought is the limiting factor, but I’m going to try it out for a while. You can download it here.

Note that when I compiled the .el files as recommended, it took several minutes to compile dict-english.el but it did finish eventually.

Another useful tool to help with the writing is flyspell. It works ‘out of the box’ on Linux. To get it working on Windows, you need some help from Cygwin.

If you scrolling through a buffer by holding down C-n then the buffer frequently jumps as it re-centers. I find this very difficult to follow. This post explains how to fix it. As mentioned in the comments it is more difficult than it sounds.

Making emacs prettier is a common theme (if you’ll pardon the pun). I’ve pointed out a few related posts myself. This one actually convinced me to try out the color-theme package. I tried the emacs wombat color-theme as recommended which I quite liked but so far my favourite is color-theme-calm-forest.

Read Full Post »

From time to time I’m forced to use that other operating system and I miss the tools that I enjoy under Linux. For example, flyspell doesn’t work because there is no ispell. Fortunately it is possible to fix this by installing cygwin and ispell/cygwin.

Brian Wood wrote instructions how to set everything up back in 2006. A quick summary:

Download cygwin/ispell binaries from ftp://ftp.franken.de/pub/win32/develop/gnuwin32/cygwin/porters/Humblet_Pierre_A/V1.1/ispell-3.2.06-cygwin-1.3-bin.tar.gz which should be extracted from the cygwin root directory – it installs files into /usr/local/…

Add the cygwin paths to your environment. I prefer to do this at emacs start-up (my cygwin is installed in the non-standard c:/packages/cygwin)

(setenv "PATH" (concat (getenv "PATH")

Update: I’ve moved over to aspell which I found in the text section of the cygwin installer as per the comment from emacs user. Thanks.

Read Full Post »

My Emacs Goals

Interesting – there is another guy talking about how people should focus their efforts on fixing and improving core libraries rather than writing their own code.

Documenting Emacs also improves your Emacs Lisp skills because you’ll likely be reading other hacker’s Emacs Lisp code. Most important of all you’ll be working on existing code for Emacs rather than making more when it is not entirely necessary to reinvent the wheel.

I guess my last two posts, which have been more self-indulgent rambling than code demonstration, have muddied the purpose of this blog. Let me try and explain where I’m coming from. Then in future posts I can get back to the important thing which is talking about code.

What do I want [from this blog]?

I don’t want to become a super emacs coder primarily because the effort required is too great. There is no documentation other than the code that gets me from where I am to there. And to be honest I don’t care about hacking on emacs core.

My [unrealistic?] goal is to get more people to write emacs lisp. Not necessarily good emacs lisp but any emacs lisp. Why? Because that leads to more discussion, more libraries, better documentation and more people writing emacs lisp. It is a virtuous circle.

And if you don’t get anyone in on the first rung of the ladder, for sure you won’t be getting new guys hacking on the core libraries either.

What have I done about that?

I’ve written about a couple of libraries and APIs that are available and techniques to solve simple emacs problems that are accessible to any programmer, not just one who is steeped in the emacs way.

And I think I’ve done a pretty good job.

If I want to know how to use overlays, and even what they are where are the best places to look (the answer – my lens which covers a practical use of emacs overlays). If my blog didn’t exist, the only option people have to learn about this stuff is to read some fairly dry documentation or the code itself.

What about comint, my favourite library? Again, either my db mode lens or my comint post. An example that is not mine: emacs fu is the best place to learn about custom menus and numerous other little emacs features.

Unfortunately a blog isn’t an ideal place for documentation. But I do keep the list of archives up to date. And one day I’ll make a half decent index page.

Other places to go for a good introduction to emacs are Xah Lee’s Emacs stuff and of course the Emacs Wiki.

Do you want to know why there are so few elisp programmers? Its because emacs is "self-documenting". That basically means "we can’t be bothered to write documentation".

Take a look at perl, php, python. The documentation is good, extensive and centralised and there are numerous examples and discussions of how to do things. And perhaps not coincidentally, all of those languages are orders of magnitude more popular than elisp. That should be the model to aim at.

And a good start might be to translate parts of PLEAC to elisp. I’ll take a look at that.

Read Full Post »

So Ian Eure mistrusts my code because he thinks I don’t read documentation1. Nice. In fact, I did read that page before I implemented db mode. "Fantastic" I thought, "just what I need".

select count(*)
  from person

And what is the response from emacs?

No SQL process started.

Well gee, so much for the documentation2. At this point I figure that feature doesn’t work correctly and implement my own code, the core of which takes around 10 minutes.

Please understand that I’m not blaming the sql-mode author. It is probably obvious to him (and others) that you need to start the database before you start sql-mode. And I couldn’t help him improve his documentation beforehand either as I didn’t know what the problem was.

1. What is true is that I actually don’t read it particularly well.

2. Yes, I’m aware now that it only works in the opposite order.

Read Full Post »

or is the documentation to blame?

From time to time I have a little niggle with emacs or need a new feature. As I know a bit of elisp it is all too tempting to jump in and code up a solution rather than investigate whether someone else has already solved it.

A case in point would be my database mode. Ian Eure pointed out that there is a way to get sql-mode (a core module) to do something similar to what I wanted.

(defun enter-db ()
  (let ((sql-sybase-program "/usr/bin/isql")
        (sql-server "DB_SERVER")
        (sql-database "DB_DATABASE")
        (sql-user "USER")
        (sql-password "PASSWORD")
        (sql-sybase-options '()))
    (other-window -1)
    (switch-to-buffer "*sql*" t)

And there are modules that provide similar functionality to my directory aliases although I am extremely pleased I wrote it. I use it many times every day and I love it.

In fact, often when I publish a piece of elisp I have written, people point out that it has already been done. Another example would be when Peter Jones pointed out a much easier way of implementing emacs muse aliases.

So what is the answer? Hang out on #emacs? Improve my google-fu so I can find pre-existing solutions? Or some kind of central documentation / module repository. Yes, the wiki is great but it isn’t comprehensive. It didn’t mention the alternative to database mode until I added it.

Central Documentation / Module Repository

I often think that emacs would make a nice alternative to Visual Basic for creating quick interactive applications if only there was a decent API reference.

I’m not saying CPAN (if you listen carefully, you can hear me very clearly not saying CPAN) but some sort of centralised repository would be nice. However, I suspect the emacs lisp writing part of the community is [far] to small to generate or support the required infrastructure. Yes, I know about ELPA, but when I checked it didn’t have more than half my third-party packages (including org-mode, htmlize and tuareg)

My Solution

No, I think that the best solution is to keep publishing my code and wait for my readers to tell me about the right way to do things. What do you think?

Read Full Post »

Older Posts »