Clojure development: migrate to cider on Mac OS X

The slime replacement for Clojure development under emacs, nrepl.el, has itself been replaced (well, renamed) to cider, Cider, like nrepl.el, integrates with nREPL under leiningen. I took the opportunity to upgrade to it, since had a spare day on my hands. As recommended, I used package.el to install from the Marmalade repo, by adding this to .emacs

  (require 'package)
  (add-to-list (quote package-archives)
    '("marmalade" . "http://marmalade-repo.org/packages/"))
  (package-initialize)

Installed via M-x package-refresh-contents, then M-x package-install RET cider RET.

The problem was that cider-jack-in would not work, just hung. Launching a repl manually via lein and then using cider to connect to the host/port combo was fine.

In the ps list of processes, I noticed this:

  -bin/tcsh -c echo "lein repl :headless" | eval $SHELL -l

Hmm, this must be the command that launches a repl, but clearly not working; the contents of the *nrep-server* emacs buffer just contained the output of my .login script, and nothing else.

You will have noted that the shell invoked by emacs is /bin/tcsh. This is my default shell under Max OS X, because that's the default on FreeBSD (OS X has many elements from FreeBSD). At some point, I had also made it my default shell for emacs (by setting the shell-file-name variable). And this was the cause of the problem. tcsh -c behaves differently to other shells; here's a simple example, first with sh and then with tcsh:

  mark@topaz:~]% sh -c 'echo ls | eval /bin/tcsh -l'
  stty: stdin isnt a terminal
  apache/         dtd/            mbox            saves/          www@
  bin/            etc/            pat/            steel/          www-src/
  dev/            freebsd-config/ patches/        tmp/
  doc/            mail/           public_html/    web/
  [mark@topaz:~]% tcsh -c 'echo ls | eval /bin/tcsh -l'
  [mark@topaz:~]%

With tcsh, the ls command never gets echoed down the pipe to the eval'd shell. I conjecture this is due to tcsh placing additional args to -c after the first in the argv variable, whereas sh places them in $0, $1 etc. echo then looks at the parameter variables, not the argv variable.

sh documentation:

  -c string If  the  -c  option  is  present, then commands are read from
            string.  If there are arguments after the  string,  they  are
            assigned to the positional parameters, starting with $0.

tcsh documentation:

  -c  Commands  are  read  from  the  following  argument  (which must be
      present, and must be a single  argument),  stored  in  the  command
      shell  variable  for  reference, and executed.  Any remaining argu‐
      ments are placed in the argv shell variable.

To work around, I set the default shell in Mac OS X Terminal (User Accounts, unlock, then control/right-click on the account to access advanced settings) and emacs to /bin/bash.