j-mode: edit and run J code with Emacs

Author: Alexander Schmolck
Date: 2007-02-13



2007-02-13 Added the newer j-mode.el version I've been using for well over a year now, but haven't got around to upload so far; I originially wanted to wait till I could test under J 6.01 (I'm still using 5.04) but unfortunately it looks like I would need a system update to install it, something for which I currently lack the time.


This mode provides editing and interactive evaluation support for the J programming language (freely available from <http://www.jsoftware.com>) under emacs. J is an APL descendant and as such offers very powerful and concise array manipulation facilities. J + j-mode can also be just used as a very fancy graphing calculator (Just keep a M-x j-shell around).








If you lack experience configuring emacs you might first want to have a look here (if you use windows) and here (regardless of OS).

I might add that you don't need to restart emacs: you can just mark the code below and then execute it with M-x eval-region; also if you want to put j-mode.el into /SomeWhere/MyEmacsStuff/ you can add that directory to the load-path like so:

(add-to-list 'load-path "/SomeWhere/MyEmacsStuff/")
  1. Copy j-mode.el to a directory in your emacs load-path.

  2. Add the following to your .emacs file or site-init.el:

    (autoload 'j-mode "j-mode.el"  "Major mode for J." t)
    (autoload 'j-shell "j-mode.el" "Run J from emacs." t)
    (setq auto-mode-alist
          (cons '("\\.ij[rstp]" . j-mode) auto-mode-alist))
  3. Set j-path to the right value, e.g. by adding something like the following to .emacs:

    (setq j-path "/home/foo/j504/")
  4. If you don't need plotting or graphics and want to save ressources you can also

    (setq j-command "jconsole")

    (the default is now "jee" which connects to a java process to allow plotting from a j shell buffer).

Other things you might find useful:


Here's a simple example you can use to see if everything is installed correctly. Open up a file test.ijs (anything with extension .ijs will do). Paste in the following code:

load 'viewmat'

If you position the cursor on 'viewmat' and press return it should open the viewmat library. Go back to test.ijs and open a J shell by typing C-! (or M-x j-shell). Press C-c C-c to execute the whole file. You should see the following plot window:


Press C-hm for more info on J mode or have a look at the J menu item.