Archive for the ‘lisp’ Category

Choosing your clojure startup script from Emacs/SLIME

Thursday, December 3rd, 2009

The standard instructions for swank-clojure (the clojure backend to SLIME) imply you always use the same binary and/or classpath for starting your clojure code. The problem with that is that for different projects you generally want to specify at least additional classpaths and possibly even a completely different clojure version.

At the same time, most projects already contain some kind of startup/REPL script, so why not use that? swank-clojure only really needs some code that starts a repl and has the swank-clojure code in its classpath.

Below is my emacs code to do just that. Just put it somewhere in your emacs init scripts, type M-x clojure and select your startup script and away you go. The following is all my clojure-specific code, but the really "interesting" bit is the (defun clojure ...) bit.

;; this is needed because swank-clojure complains if you don't have any
;; value for this variable. When you use the clojure command it'll override
;; this value
(setq swank-clojure-binary "clj")

(require 'clojure-mode)
(require 'swank-clojure-autoload)
(require 'swank-clojure)
(require 'slime)

(add-hook 'clojure-mode-hook 'slime-mode)

(add-hook 'clojure-mode-hook 'start-paredit)

(slime-setup
 '(slime-fancy ;; turns on fancy inspector, autodoc and other useful stuff
   slime-highlight-edits)) 

(defun clojure (binary)
  (interactive "fbinary: ")
  (setq swank-clojure-binary (or binary "clj"))
  (setq slime-lisp-implementations
        `((clojure (,swank-clojure-binary) :init swank-clojure-init)))
  (slime))

My complete emacs init stuff is at http://github.com/joodie/emacs-d

Oh, before I forget: the code above does assume that you're only using SLIME with clojure and not also with other lisps. If you do need that functionality, you can probably figure out how to make it work.

Adding a modeline to emacs-rails

Saturday, December 6th, 2008

I just updated emacs-rails so that feedback on the currently running test is put in the global modeline. This means you get that feedback in all buffers, so you can work on something else while your tests are running, and the minibuffer stays free for useful things.

It's started automatically when emacs-rails is loaded, but that's customizable of course, and you can switch it on and off using rails-ui:enable-mode-line / rails-ui:disable-mode-line.

the new modeline feature

Get it at http://github.com/remvee/emacs-rails/tree/master

Here are the commit details

Update: actually, the head has some nicely cleaned up code now. So just get that at http://github.com/remvee/emacs-rails/tree/master

better console/keyboard menus for emacs

Sunday, September 14th, 2008

One of the projects I'm working on is in Ruby on Rails, and I'm using emacs-rails (with some small tweaks) as the development environment.

Emacs rails works fine, except for one thing: the navigation menus (x-popup-menus) are awkward when you want to use the keyboard. So I thought I'd switch on the rails-always-use-text-menus option. Which didn't actually work, but I fixed that bit.

Rails-always-use-text-menus uses tmm-prompt, which is the standard function on emacs to mimic drop-down menus on the console. and it's almost as horrible as x-popup-menu: if the items in the menu aren't static you can't predict the which key activates which item, and it takes up a lot of screen space:

Which key can I press to go to the UserPreference model?

Before

I really like iswitch buffers for buffer navigation, and it seemed to me that it should be possible to navigate the menus using the same technique, even for nested menus.

So here is iswitch-menu, a direct replacement for tmm-prompt and/or x-popup-menu. It's not quite finished yet - I'm working out the last issues with some of the more "interesting" constructs used by the menubar keymap - but it's more than adequate for use with emacs-rails, at least.

Now, I can just type some substring of the name of the model, and go there

after, step 1

First character typed, we can see which models still match

after2.png

Second character typed, only one model still matches.

after3.png

Pressing TAB completes the typed text, and goes to the selected model if there's only one. Pressing ENTER opens the first matched model. See also the iswitchb documentation for available tweaks and key bindings.

Get iswitch-menu at github

using emacs’ (compile) command to track errors

Thursday, August 21st, 2008

For a mod_perl project I'm working on I wanted a way to track the apache error log and jump to the source of the errors from emacs.

Fortunately, emacs' (compile) command makes this very easy:

;; restarts apache and track the error log
(defun apache-restart-and-tail ()
      (interactive)
      (compile "sudo /etc/init.d/httpd restart && sudo tail -f /var/log/httpd/error_log"))

;; key binding
(global-set-key (kbd "<C-kp-enter>") 'apache-restart-and-compile)

Emacs CVS HEAD (finally) has anti-aliased fonts

Thursday, February 7th, 2008

The emacs-unicode-2 branch has been merged into the main branch. This means really good looking fonts for everyone on X11.

Get it now:


cvs -z3 -d:pserver:anonymous@cvs.savannah.gnu.org:/sources/emacs co

cd emacs

./configure --with-xpm --with-tiff --with-jpeg --with-png --with-freetype --with-xft --with-rsvg --with-gtk --enable-font-backend

make bootstrap

make

sudo make install

There's no gui interface to select these fonts. I just put the following entry in my .Xresources:

Emacs*font: Monospace-10

Replace "Monospace-10" with whatever font you like.

Arc is released

Wednesday, January 30th, 2008

As one or two of my readers may know, Arc is a project by Paul Graham to produce a new Lisp/Scheme dialect for the future. Up till now details about it have been very sparse, but today the first version was released.

From the notes:

Arc embodies just about every form of political incorrectness possible in a programming language. It doesn't have strong typing, or even type declarations; it uses overlays on hash tables instead of conventional objects; its macros are unhygienic; it doesn't distinguish between falsity and the empty list, or between form and content in web pages; it doesn't have modules or any predefined form of encapsulation except closures; it doesn't support any character sets except ascii. Such things may have their uses, but there's also a place for a language that skips them, just as there is a place in architecture for markers as well as laser printers.

Sounds like a combo of JavaScript and Common Lisp to me, though I'm slightly disappointed about the (current) use of ASCII as the only charset.

When I've played with it a bit I may post more.

Get it here!

Update: here's a tutorial

Joost.

European Common Lisp Meeting, Amsterdam, April 19/20, 2008

Tuesday, December 25th, 2007

From comp.lang.lisp:

Arthur Lemmens and Edi Weitz are proud to announce the European Common Lisp Meeting 2008. The meeting will consist of a Sunday full of talks on April 20, 2008, with optional dinners on Saturday and Sunday evening.

http://weitz.de/eclm2008/

Slime video

Thursday, November 22nd, 2007

Using SLIME, door Marco Baringer is een interessante introductie van SLIME (dé Emacs Lisp mode). Ruby/perl etc mensen opgelet! Zo doe je een "IDE" in een dynamische taal - geen statische bron-code analyse, maar directe interactie met je runtime.

Download 149Mb video in goeie kwaliteit: torrent - HTTP download.

Of bekijk de preview op google video (onleesbaar!).

Deze en meer videos op cliki.net.

Javascript regex en string literal highlighting in Emacs

Wednesday, October 31st, 2007

De beste javascript mode voor Emacs is deze van Karl Landström. Hij heeft alleen moeite met het correct detecteren van strings en regexes:

Voor

Niet leuk als je de source van jQuery opent. (Waarschuwing, dit crasht emacs!)

Ook niet leuk is dat Emacs' ingebouwde syntax-table niet overweg kan
met de complete overloading van / in Javascript (als deel-operator, regex quote, en 2 soorten commentaar marker). Boeh voor Emacs!

De oplossing is dan om alle auto-quoting uit te zetten en het zelf te doen. Kan je net zulke ingewikkelde syntax mee highlighten als je wilt. Hoera voor Emacs!

Relevante passages:

;; --- Syntax Table And Parsing ---

(defvar javascript-mode-syntax-table
  (let ((table (make-syntax-table)))
    (c-populate-syntax-table table)

    ;; switch off build-in quoted string detection
    ;; since that just makes it really hard to detect
    ;; regular expressions and comments
    ;;
    ;; this also has the benefit that multiline strings
    ;; are now not recognized as strings (since javascript does
    ;; not allow them)
    (modify-syntax-entry ?' "." table)
    (modify-syntax-entry ?\" "." table)

    ;; The syntax class of underscore should really be `symbol' ("_")
    ;; but that makes matching of tokens much more complex as e.g.
    ;; "\\" matches part of e.g. "_xyz" and "xyz_abc". Defines
    ;; it as word constituent for now.
    (modify-syntax-entry ?_ "w" table)

    table)
  "Syntax table used in JavaScript mode.")
 
(defconst js-quoted-string-re "\\(\".*?[^\\]\"\\|'.*?[^\\]'\\)")
 
(defconst js-quoted-string-or-regex-re "\\(/.*?[^\\]/\\w*\\|\".*?[^\\]\"\\|'.*?[^\\]'\\)")
 
(defconst js-font-lock-keywords-1
  (list
   "\\<import\\>"
   (list js-function-heading-1-re 1 font-lock-function-name-face)
   (list js-function-heading-2-re 1 font-lock-function-name-face)
 
   ;; detect literal strings following a + operator
   (list (concat "+[ \t]*" js-quoted-string-re)  1 font-lock-string-face)
 
   ;; detect literal strings used in "literal object" keys
   (list (concat "[,{][ \t]*" js-quoted-string-re "[ \t]*:" ) 1 font-lock-string-face)
 
   ;; detects strings and regexes when assigned, passed, returned
   ;; used as an object key string (i.e. bla["some string"]), when used
   ;; as a literal object value (i.e. key: "string"), used as an array
   ;; element, or when they appear as the first expression on a line
   ;; and a few other hairy cases
   (list (concat "[=(:,;[][ \t]*" js-quoted-string-or-regex-re)  1 font-lock-string-face)
   (list (concat "^[ \t]*"      js-quoted-string-or-regex-re) 1 font-lock-string-face)
   (list (concat "return[ \t]*" js-quoted-string-or-regex-re) 1 font-lock-string-face)
 
   ;; detect "autoquoted" object properties... clases with "switch { ...  default: }"
   ;; may not be worth the trouble
   (list "\\(^[ \t]*\\|[,{][ \t]*\\)\\(\\w+\\):" 2 font-lock-string-face))
 
  "Level one font lock.")
 

En dan:
Na

Patch is onderweg naar Karl. In de tussentijd kun je hier mijn versie downloaden.

lispcast.com - Lisp videos

Wednesday, October 31st, 2007

LispCast is a series of screencasts of Common Lisp development.

Lispcast laat in een serie van videos zien hoe je in Common Lisp een web applicatie schrijft, test, refactored en verder... Interessant materiaal.

De komende sessie gaat over database persistence - ik ben benieuwd!

Ps: als je cl-who niet kent, dan is de 1e aflevering alleen al interessant om te zien hoe veel schoner html/xml er uit ziet als je ze met s-expressions schrijft.