📜 ⬆️ ⬇️

Unhealthy minimalism: ide

When programming in common lisp, the standard development environment is SLIME . Perhaps the only major flaw in SLIME is emacs, especially for vi fans. Of course, there are crafts for vim, but vim itself is also not the height of minimalism.

Under the cut is the minimum ide for interpretable media without blackjack and whores .


What you need:
Who is familiar with the screen, but not familiar with tmux: differences in the official FAQ (EN), who is not familiar with either the screen or tmux: a mini tmux introduction . For those who do not like English - wikipedia (RU).
')
- What's wrong with the screen?
“By the fact that it is GNU and besides it cannot divide the window vertically.”

Concept


The main problem of working with a clean interpreter is that you must save the code in some way (provided that it does not do it for you). It is solved quite simply:
  1. open terminal with interpreter
  2. open text editor
  3. typing code in the editor
  4. we copy in the terminal
  5. see the result, rejoice / grieve
The code is saved in the editor. So you can live, but sad. It would be necessary to automate. We use tmux, and to help him write a couple of simple scripts.

Implementation


#!/bin/sh #  ide interpreter="sbcl" windowname="ide" ide_running=`tmux list-windows | grep "$windowname"` if [ "$TMUX" ]; then if [ "$ide_running" ]; then tmux select-window -t "$windowname" else tmux rename-window "$windowname" \; split-window -dhp 40 "$interpreter" fi else if [ "$ide_running" ]; then tmux attach-session \; select-window -t "$windowname" elif tmux has-session >/dev/null 2>&1; then tmux attach-session \; new-window -n "$windowname" \; split-window -dhp 40 "$interpreter" else tmux new-session -n "$windowname" \; split-window -dhp 40 "$interpreter" fi fi 


 #!/bin/sh #  idepipe tmpfile=`mktemp /tmp/tmuxbuffer.XXXXXX` tee $tmpfile tmux load-buffer $tmpfile >/dev/null 2>&1 tmux paste-buffer -dt 1 >/dev/null 2>&1 rm -f $tmpfile 

The first script starts / restores the tmux session with the ide window and two panels. In the left console, in the right - the interpreter from the $ interpreter variable. In the console, run your favorite text editor. On BSD vi systems, the default clone is nvi. It fits, and run it.



The second script is a filter. The code for the interpreter is fed to the standard input, the output is written to the interpreter window and to the standard output. Standard output is necessary for vi, without it all your precious code will be permanently erased from the buffer.

Examples


Common lisp


Put the scripts in $ PATH, run ide. In the text editor vi, type arbitrary code. When it looks quality enough, type the command :%!idepipe . For those who are not familiar with vi, it should be clarified: the colon starts the command, % means the entire file, idepipe name of the filter. In human language, it will sound like this: output the entire buffer to the input of the idepipe and overwrite the entire buffer with what we get at the output. It's clear that we don’t want to change the code, so tee used inside the idepipe . If everything worked out as planned, then the interpreter window will contain all the desired code, as well as the result of its execution. To execute all the code, the last line in the file must be empty, otherwise you need to press enter in the interpreter window yourself.



In addition to the % sign, you can use many more address symbols. Thus, only part of the code (which has been changed) can be sent to the interpreter, without the need to re-digest the entire file.
:10,30!idepipe - interpret everything between 10 and 30 lines, inclusive
(!)idepipe (without a colon) - interpret one lisp block
Moreover, there is no need to type these commands every time, it is enough to put them down once.
:map {ctrl-v}{F3} {ctrl-v}{esc}(!)idepipe{ctrl-v}{enter} - we interpret the code block by pressing F3
:map {ctrl-v}{F5} {ctrl-v}{esc}:%!idepipe{ctrl-v}{enter} - we interpret the entire file by pressing F5
In place of curly brackets, you must press the corresponding key
Both commands operate including from edit mode.
- And will work with other interpreters.
- Should work with any REPL environments (Read Eval Print Loop). Check out a couple more.

Python



Python I run for the first time, so the code is not too tricky, but it works.

Shell




In addition, mysql, irb, and others should work.
- It looks good, but I still want cards and girls.
- No problem. Add a mega feature.

Mega feature


First, let's change the idepipe script.
 #!/bin/sh #  idepipe tmpfile=`mktemp /tmp/tmuxbuffer.XXXXXX` tee $tmpfile tmux load-buffer $tmpfile >/dev/null 2>&1 tmux paste-buffer -t 1 >/dev/null 2>&1 tmux paste-buffer -t 2 >/dev/null 2>&1 tmux paste-buffer -dt 3 >/dev/null 2>&1 rm -f $tmpfile 
Wow, two new lines. What kind of minimalism is there? What makes this change? Everything is very simple: instead of one interpreter, we can send the code to three at once. To the unspoken question “why?” The answer is very simple: different implementations of the common lisp language have incompatibilities. Checking the code in three interpreters at once - we kill two three birds with one stone.

disclaimer: idepipe written without any kind of fool protection, so to avoid the strange behavior of tmux, you must manually create two additional panels on the ide window and run interpreters in them. The number of interpreter panels (as can be seen from the script) should be 1, 2 and 3.



So, the moment X. (!)idepipe familiar command (!)idepipe on one of the functions and observe the execution of the code in three different interpreters. This is WAY cool! We will limit ourselves to one feature, minimalism demands.



A portion of unhealthy minimalism


Geoff's favorite text editor tr - ed. Who would have thought that ed was suitable for this article, and in fact was suitable. He and the minimum, and the text in the pipe can transfer. What else is needed for happiness? We execute 12,13w! Idepipe and the result appears in all panels.



Thanks

I got the original idea from the vim plugin .

Source: https://habr.com/ru/post/123163/


All Articles