This page is no longer maintained — Please continue to the home page at www.scala-lang.org

2.9.0.1 Scala REPL gets messed up when run within "M-x term" [emacs 23.2.93.1]

6 replies
OP
Joined: 2011-02-08,
User offline. Last seen 1 year 17 weeks ago.

Please let me know if there is any other info needed.. i have described the problem in reproduction steps below.
Using REPL history messes up displayed content within REPL.
0a. Launch emacs and then start 'term' with the "EMACS" env-var unset:
Emacs -Q
 (M-x term RET RET)
$ unset EMACS

0b. launch scala from within this terminal buffer
$ scala <RET>


1. starting state/creating history - adding 2 entries to command-history: <"abc"> and <10>
scala> "abc"
res6: java.lang.String = abc

scala> 10
res7: Int = 10



2. hit 'up' or CTRL-P once - most recent entry is pulled from history. No problem!
scala> 10

3a. hit 'up' once more - next-recent is appended to currently displayed contents.. Problem!
scala> 10"abc"


3b. hit ENTER
scala> 10"abc"
res8: java.lang.String = abc



The issue in 3b repeats for every 'up' or subsequent 'down'.. appending more and more entries.(scala/repl though treats the input correctly internally.. see 3b - here it correctly accepts "abc", not the concatenation of 10 and "abc" that is displayed)


Tab-completion does work fine.

 I have tried running the scala interpreter from within a 'term' session of an "emacs -Q" instance with the same results.  Also, this works fine within Terminal.app: its just that I have emacs/term configured to avoid a lot of keyboard-relate fatigue (so I would be glad for any help in getting 2.9 to work like this)
huynhjl 2
Joined: 2011-03-26,
User offline. Last seen 42 years 45 weeks ago.
Re: 2.9.0.1 Scala REPL gets messed up when run within "M-x term"

Does the problem exist with 2.8.0 or 2.8.1?

--Jean-Laurent

On Jun 14, 4:52 am, OP wrote:
> Please let me know if there is any other info needed.. i have described the
> problem in reproduction steps below.
>
> Using REPL history messes up displayed content within REPL.
>
> 0a. Launch emacs and then start 'term' with the "EMACS" env-var unset:
>
> > Emacs -Q
>
>  (M-x term RET RET)
>
> $ unset EMACS
>
> 0b. launch scala from within this terminal buffer
>
> > $ scala
>
> 1. starting state/creating history - adding 2 entries to command-history:
> <"abc"> and <10>
>
> > scala> "abc"
>
> res6: java.lang.String = abc
>
> > scala> 10
>
> res7: Int = 10
>
> 2. hit 'up' or CTRL-P once - most recent entry is pulled from history. *No
> problem!*
>
> scala> 10
>
> 3a. hit 'up' once more - next-recent is *appended* to currently displayed
> contents.. *Problem!*
>
> > scala> 10"abc"
>
> 3b. hit ENTER
>
> > scala> 10"abc"
>
> res8: java.lang.String = abc
>
> The issue in 3b repeats for every 'up' or subsequent 'down'.. appending more
> and more entries.
> (scala/repl though treats the input correctly internally.. see 3b - here it
> correctly accepts "abc", not the concatenation of 10 and "abc" that is
> displayed)
>
> Tab-completion *does *work fine.
>
>  I have tried running the scala interpreter from within a 'term' session of
> an "emacs -Q" instance with the same results.
>  Also, this works fine within Terminal.app: its just that I have emacs/term
> configured to avoid a lot of keyboard-relate fatigue (so I would be glad for
> any help in getting 2.9 to work like this)

Lex
Joined: 2010-02-28,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: 2.9.0.1 Scala REPL gets messed up when run within "M-x

I have noticed this problem a while ago with Bash.

OP
Joined: 2011-02-08,
User offline. Last seen 1 year 17 weeks ago.
Re: Re: 2.9.0.1 Scala REPL gets messed up when run within "M-x
Hello Jean, all
 The problem does not exist for 2.8.1.final: I can access and use history without these issues with the old version, and see the problem only with 2.9.0.1 final.
I just confirmed the above by switching scala-versions like so (for 2.9 below, and then equivalent 'ln' command to change to a 2.8 installation). So all else is identical for 2.9 and 2.8 testss
\ln -shvf /Applications/typesafe-stack scala_home


Regards OP


On Tue, Jun 14, 2011 at 8:00 PM, huynhjl <huynhjl [at] gmail [dot] com> wrote:
Does the problem exist with 2.8.0 or 2.8.1?

--Jean-Laurent

On Jun 14, 4:52 am, OP <ovr [dot] pro [dot] [dot] [dot] [at] gmail [dot] com> wrote:
> Please let me know if there is any other info needed.. i have described the
> problem in reproduction steps below.
>
> Using REPL history messes up displayed content within REPL.
>
> 0a. Launch emacs and then start 'term' with the "EMACS" env-var unset:
>
> > Emacs -Q
>
>  (M-x term RET RET)
>
> $ unset EMACS
>
> 0b. launch scala from within this terminal buffer
>
> > $ scala <RET>
>
> 1. starting state/creating history - adding 2 entries to command-history:
> <"abc"> and <10>
>
> > scala> "abc"
>
> res6: java.lang.String = abc
>
> > scala> 10
>
> res7: Int = 10
>
> 2. hit 'up' or CTRL-P once - most recent entry is pulled from history. *No
> problem!*
>
> scala> 10
>
> 3a. hit 'up' once more - next-recent is *appended* to currently displayed
> contents.. *Problem!*
>
> > scala> 10"abc"
>
> 3b. hit ENTER
>
> > scala> 10"abc"
>
> res8: java.lang.String = abc
>
> The issue in 3b repeats for every 'up' or subsequent 'down'.. appending more
> and more entries.
> (scala/repl though treats the input correctly internally.. see 3b - here it
> correctly accepts "abc", not the concatenation of 10 and "abc" that is
> displayed)
>
> Tab-completion *does *work fine.
>
>  I have tried running the scala interpreter from within a 'term' session of
> an "emacs -Q" instance with the same results.
>  Also, this works fine within Terminal.app: its just that I have emacs/term
> configured to avoid a lot of keyboard-relate fatigue (so I would be glad for
> any help in getting 2.9 to work like this)

OP
Joined: 2011-02-08,
User offline. Last seen 1 year 17 weeks ago.
Re: Re: 2.9.0.1 Scala REPL gets messed up when run within "M-x
Hi Lex that was an interesting clue: I tried csh, ksh too. Sadly the problem showed up on each of them.
I tested by invoking csh and ksh from within the bash session.Then I also tried launching an independent ksh session:
M-x term RET /bin/ksh RET
(I again did 'unset EMACS' before launching scala)
2.8 worked fine in each case, 2.9 did not.
Regards OP

[ while it looks like a scala issue to me at this point - rather than an emacs one - I'm retaining emacs-help group in "cc:".. any emacs-term users launching scala-2.9 from within term? ]

On Tue, Jun 14, 2011 at 9:05 PM, Lex <lexn82 [at] gmail [dot] com> wrote:
I have noticed this problem a while ago with Bash.

huynhjl 2
Joined: 2011-03-26,
User offline. Last seen 42 years 45 weeks ago.
Re: 2.9.0.1 Scala REPL gets messed up when run within "M-x term"

You mean with Emacs and bash? Or just bash and scala?

On Jun 14, 8:35 am, Lex wrote:
> I have noticed this problem a while ago with Bash.

huynhjl 2
Joined: 2011-03-26,
User offline. Last seen 42 years 45 weeks ago.
Re: 2.9.0.1 Scala REPL gets messed up when run within "M-x term"

After a bit of investigation, I found out that this is due to how the
new jline implements cursor motion and line erase.

The jline code in 2.9.0 use the ansi sequence 1G to go to the
beginning of the line and K to erase to the end of the line.

Those sequences aren't supported by emacs (although the doc says term
mode understands ansi sequences, it appears it's not the case).

You can test it for yourself in bash. The following sequence will
print 3 'a' chars, go back to the beginning of the line, erase to the
end, then print 2 'b' chars:
echo -e "aaa\033[1G\033[Kbb"

The result in bash outside of emacs is "bb"
The results in the term mode of emacs is "aaabb".
See http://en.wikipedia.org/wiki/ANSI_escape_code for details.

I wish I had known about it back when I spent hours finding a solution
to the wrapping behavior. The challenge is that a new implementation
for moving the cursor around and erasing chars has to be tested on a
bunch of terminals under a number of conditions.

May be you can see if there is an emacs term mode that supports the
cursor motions and erase line escape sequences?

--Jean-Laurent

On Jun 14, 11:05 pm, OP wrote:
> Hello Jean, all
>
>  The problem does not exist for *2.8.1.final*:
>  I can access and use history without these issues with the old version, and
> see the problem only with *2.9.0.1 final*.
>
> I just confirmed the above by switching scala-versions like so (for 2.9
> below, and then equivalent 'ln' command to change to a 2.8 installation). So
> all else is identical for 2.9 and 2.8 testss
>
> > \ln -shvf /Applications/typesafe-stack scala_home
>
> Regards
>  OP
>
>
>
>
>
>
>
> On Tue, Jun 14, 2011 at 8:00 PM, huynhjl wrote:
> > Does the problem exist with 2.8.0 or 2.8.1?
>
> > --Jean-Laurent
>
> > On Jun 14, 4:52 am, OP wrote:
> > > Please let me know if there is any other info needed.. i have described
> > the
> > > problem in reproduction steps below.
>
> > > Using REPL history messes up displayed content within REPL.
>
> > > 0a. Launch emacs and then start 'term' with the "EMACS" env-var unset:
>
> > > > Emacs -Q
>
> > >  (M-x term RET RET)
>
> > > $ unset EMACS
>
> > > 0b. launch scala from within this terminal buffer
>
> > > > $ scala
>
> > > 1. starting state/creating history - adding 2 entries to command-history:
> > > <"abc"> and <10>
>
> > > > scala> "abc"
>
> > > res6: java.lang.String = abc
>
> > > > scala> 10
>
> > > res7: Int = 10
>
> > > 2. hit 'up' or CTRL-P once - most recent entry is pulled from history.
> > *No
> > > problem!*
>
> > > scala> 10
>
> > > 3a. hit 'up' once more - next-recent is *appended* to currently displayed
> > > contents.. *Problem!*
>
> > > > scala> 10"abc"
>
> > > 3b. hit ENTER
>
> > > > scala> 10"abc"
>
> > > res8: java.lang.String = abc
>
> > > The issue in 3b repeats for every 'up' or subsequent 'down'.. appending
> > more
> > > and more entries.
> > > (scala/repl though treats the input correctly internally.. see 3b - here
> > it
> > > correctly accepts "abc", not the concatenation of 10 and "abc" that is
> > > displayed)
>
> > > Tab-completion *does *work fine.
>
> > >  I have tried running the scala interpreter from within a 'term' session
> > of
> > > an "emacs -Q" instance with the same results.
> > >  Also, this works fine within Terminal.app: its just that I have
> > emacs/term
> > > configured to avoid a lot of keyboard-relate fatigue (so I would be glad
> > for
> > > any help in getting 2.9 to work like this)

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland