ctrlshiftbryan

ctrlshiftbryan

IEx in Spacemacs terminal

I’ve been trying to get iex to work a spacemacs terminal but it doesn’t seem to be sending the up or down arrows to cycle through history.

I found this possible solution but don’t understand enough about spacemacs/emacs to get it working.

https://groups.google.com/forum/#!topic/elixir-lang-talk/2q_j-zcB2uc

I tried adding this to my user-config but it didn’t do anything.

(defun term-send-up () (interactive) (term-send-raw-string “\e[A”))
(defun term-send-down () (interactive) (term-send-raw-string “\e[B”))
(defun term-send-right () (interactive) (term-send-raw-string “\e[C”))
(defun term-send-left () (interactive) (term-send-raw-string “\e[D”))

Has anyone else been able to get iex working in a spacemacs terminal?

I know alchemist iex is an option but I really prefer iex from a terminal? (alchemist iex seems to keep its own history of commands or something instead of actually sending the up arrow command to iex)

Most Liked

modraedlau

modraedlau

You can do this in ‘user-config’ as following:

(defun mo/term-send-up () (interactive) (term-send-raw-string "\e[A"))
  (defun mo/term-send-down () (interactive) (term-send-raw-string "\e[B"))
  (defun mo/term-send-right () (interactive) (term-send-raw-string "\e[C"))
  (defun mo/term-send-left () (interactive) (term-send-raw-string "\e[D"))

  (defun mo/setup-term-send-arrow-keys ()
    (evil-local-set-key 'insert (kbd "<up>") 'mo/term-send-up)
    (evil-local-set-key 'insert (kbd "<down>") 'mo/term-send-down)
    (evil-local-set-key 'insert (kbd "<right>") 'mo/term-send-right)
    (evil-local-set-key 'insert (kbd "<left>") 'mo/term-send-left)
    )

  (add-hook 'term-mode-hook 'mo/setup-term-send-arrow-keys)
alanm

alanm

Copy and paste this:

(defun term-send-up () (interactive) (term-send-raw-string “\e[A”))
(defun term-send-down () (interactive) (term-send-raw-string “\e[B”))
(defun term-send-right () (interactive) (term-send-raw-string “\e[C”))
(defun term-send-left () (interactive) (term-send-raw-string “\e[D”))

In your spacemacs.local between (defun dotspacemacs/user-init () and (defun dotspacemacs/user-config () as shown in the following:

   ...
   (defun dotspacemacs/user-init ()
   ...
   )
  
  (defun term-send-up    () (interactive) (term-send-raw-string "\e[A"))
  (defun term-send-down  () (interactive) (term-send-raw-string "\e[B"))
  (defun term-send-right () (interactive) (term-send-raw-string "\e[C"))
  (defun term-send-left  () (interactive) (term-send-raw-string "\e[D"))

  (defun dotspacemacs/user-config ()
  ...

restart spacemacs.

Now you have to use a terminal ‘shell’ instead of the default’ansi-term’ terminal, use spc-a-s-i to open a shell terminal, inside there you can cycle through commands history in the prompt using arrow keys, in erl and in iex.

hope it helps.

Where Next?

Popular in Questions Top

belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement