Search code examples
emacsclojureread-eval-print-loopline-endings

How to get suppress ^M characters in my ClojureBox (EmacsW32) REPL connected to lein swank


I am connecting to a swank server from my ClojureBox install. I.e. lein swank from my project directory and then M-x slime-connect from EmacsW32.

However, when I do this I see the DOS line-endings everywhere in the REPL (^M). I.e.

user> (doc map)
-------------------------^M
clojure.core/map^M
([f coll] [f c1 c2] [f c1 c2 c3] [f c1 c2 c3 & colls])^M
  Returns a lazy sequence consisting of the result of applying f to the
  set of first items of each coll, followed by applying f to the set
  of second items in each coll, until any one of the colls is
  exhausted.  Any remaining items in other colls are ignored. Function
  f should accept number-of-colls arguments.^M
nil 

user> (println "foo")
foo^M

I'm aware that this has to do with platform encoding, but I'm having trouble figuring out how to suppress them. I poked around in the EmacsW32 menus and tried the java command line system property (in lein.bat) -Dfile.encoding=ISO-8859-1 to no avail.

I've also found other questions about doing global find/replace of ^M within buffers - but I want to filter REPL output.

I also noticed the following in the *inferior-lisp* buffer:

(do (.. java.net.InetAddress getLocalHost getHostAddress) nil)(swank.swank/start-server "c:/Users/noahz/AppData/Local/Temp/slime.4912" :encoding "iso-latin-1-unix")


Solution

  • I have this in my .emacs:

    (defun hide-eol ()
      "Do not show ^M in files containing mixed UNIX and DOS line endings."
      (interactive)
      (setq buffer-display-table (make-display-table))
      (aset buffer-display-table ?\^M []))
    

    I just call it with M-x hide-eol when required. You could bind a key, or put it in a hook of some sort if you prefer.

    Credit is due to persons unknown - I copied this function from somewhere, but I don't remember where.