Feeds:
Posts
Comments

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)

Uniquify

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")
                       ";c:\\packages\\cygwin\\usr\\local\\bin"
                       ";c:\\packages\\cygwin\\bin"))

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".

(sql-mode)
(sybase-mode)
select count(*)
  from person
go

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 ()
  (interactive)
  (let ((sql-sybase-program "/usr/bin/isql")
        (sql-server "DB_SERVER")
        (sql-database "DB_DATABASE")
        (sql-user "USER")
        (sql-password "PASSWORD")
        (sql-sybase-options '()))
    (delete-other-windows)
    (sql-sybase)
    (other-window -1)
    (switch-to-buffer "*sql*" t)
    (sql-mode)))

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 »

I’ve written the third post in the comint series. Database Mode is a more traditional use of comint mode to interact with an external interpreter. Part 1 described basic use of comint with a cut-down shell mode and Part 2 was about a stock price subscriber.

There is a great tip from emacs-fu on using a custom menu to store all the tips you’ve been reading on blogs like my own.

Ben Atkin mentions a couple of things of things that I really like about emacs. First of all, he talks about the ability to see different parts of the same buffer in two frames. I use this all the time when all my constants (or whatever) are at the top of the file. Admittedly, a trick I’ve linked to before with C-x C-x to return to where you were also works nicely in this case.

And the other thing was the scratch buffer. The great thing about emacs is you can easily create another buffer with C-x b and store whatever you like in there.

There is a nice example of Kit OConnell asking the internet for help with an emacs issue. In the end it looks like it was solved in the real world by someone spotting some "smart quotes" in the .emacs. Perhaps emacs should warn about that at start-up.

There have been a few posts on whitespace recently. Matt Harrison mentions a whitespace mode that can be useful for the pythonistas that have the most trouble with inconsistent whitespace. Rémi Vanicat isn’t the first person to talk about removing trailing whitespace (I linked to an even better solution in an earlier link roundup). It is nice that emacs has such a nice way of dealing with it.

Read Full Post »

As most emacsers probably know, emacs 23 allows you to use anti-aliased fonts, in effect making emacs beautiful and even more of a pleasure and a joy to use. Dagobart recently wrote a post, explaining how to set this up on Linux.

I’ve seen a few posts like this before, ever since version 23 was in alpha so I thought it would be a good opportunity to do a quick roundup.

Way back at the start of 2007, Alexandre Vassalotti packaged up an early version of emacs23. Later on he updated it.

Oscar Bonilla wrote posts on how to prettify emacs for OS X and later on for Windows. The rather excellent EmacsW32 package is now based on a build of Emacs 23.

Dagobart’s post references these Linux setup instructions at sevenever.

And I should note that if you are a fan of muse + htmlize then you need the patched version of htmlize as vanilla 1.34 does not work with emacs 23.

Read Full Post »

I briefly mentioned dabbrev expand in one of my interesting links posts when I noted a post that was covering auto-complete.el. Dabbrev expand is a great little feature of emacs. With one keychord, you can expand text using any match from any buffer that you have opened. Until now, I haven’t particularly wanted more.

However, now it is time to move to auto-complete. It’s nice to get feedback about potential completions. In the linked post, it states that auto-complete is just a framework and it needs quite a bit of tweaking to get the behaviour I want.

The primary thing I want to fix is that by default it only uses completions from the current buffer. I like completion to use all open buffers as dabbrev does by default. I thought that it would be easy to add this by setting ac-sources to ac-source-words-in-all-buffer.

(setq-default ac-sources '(ac-source-words-in-all-buffer))

Unfortunately, that isn’t come close to what I want. There is also an extension called ac-dabbrev.el but that doesn’t work for me either. Fortunately, it is fairly easy to fix myself.

We can use functions from dabbrev to get all of the possible dabbrev expansions.

(require 'cl)
(require 'dabbrev)
(require 'auto-complete)

(defun ac-source-dabbrev (abbrev)
  (interactive)
  (dabbrev--reset-global-variables)
  (let ((dabbrev-check-all-buffers t))
    (sort (dabbrev--find-all-expansions abbrev t) #'string<)))

auto-complete allows you to list multiple sources for completions in ac-sources. Here we just want one but I could see that it might be nice to add language keywords or something like that.

(defvar ac-source-dabbrev-words
  '((candidates
     . (lambda () (all-completions ac-target
                                   (ac-source-dabbrev ac-target)))))
  "Get all the completions using dabbrev")

(setq-default ac-sources '(ac-source-dabbrev-words))

I prefer to manually start completion rather than have it trigger automatically.

(setq ac-auto-start nil)
(global-set-key (kbd "M-/") 'ac-start)

There is a keymap you can add your own keys to. By default, C-g doesn’t cancel the completion window which feels really strange to me. In emacs C-g is pervasive for cancelling options. Fortunately, it is pretty easy to fix that.

(define-key ac-complete-mode-map (kbd "M-x") 'execute-extended-command)
(define-key ac-complete-mode-map (kbd "C-n") 'ac-next)
(define-key ac-complete-mode-map (kbd "C-p") 'ac-previous)
(define-key ac-complete-mode-map (kbd "C-g") 'ac-stop)

I like both RETURN and TAB for completion.

(define-key ac-complete-mode-map "\t" 'ac-complete)
(define-key ac-complete-mode-map "\r" 'ac-complete)

I want completions to update as you type. Did you know that by adding a vector to a keymap, you can capture all ascii keypresses?

(defun ac-self-insert ()
  (interactive)
  (self-insert-command 1)
  (ac-start))

;; (define-key ac-complete-mode-map [t] 'ac-self-insert)

However, [t] also absorbs other ASCII keypresses you’ve defined such as TAB and RETURN. Therefore, we have to define them all individually.

(defun ac-fix-keymap ()
  (let ((i 32))
    (while (<= i ?z)
      (define-key ac-complete-mode-map
        (make-string 1 i) 'ac-self-insert)
      (incf i))))

(ac-fix-keymap)

I also want DELETE to trigger a new completion update.

(define-key ac-complete-mode-map (kbd "DEL")
  (lambda ()
    (interactive)
    (backward-delete-char-untabify 1)
    (ac-start)))

(provide 'auto-complete-config)

Read Full Post »

Older Posts »

Follow

Get every new post delivered to your Inbox.