Temporarily disable tab completion in Scala Repl - scala

I occasionally work with code that has hard tabs instead of spaces. Is there any repl command to instruct the interpreter to process the tabs as normal whitespace at least temporarily - along the lines of :paste ?

Indeed :paste sounds like a good option but if you really want to override keybindings you can provide your own settings file like this:
scala -Djline.keybindings=myfile
The format of the file that I looked up from default scala jar is like this:
from file scala/tools/jline/keybindings.properties in jline.jar:
# Keybinding mapping for JLine. The format is:
# [key code]=[logical operation]
# CTRL-A: move to the beginning of the line
1=MOVE_TO_BEG
# CTRL-B: move to the previous character
2=PREV_CHAR
# CTRL-D: close out the input stream
4=EXIT
# CTRL-E: move the cursor to the end of the line
5=MOVE_TO_END
# CTRL-F: move to the next character
6=NEXT_CHAR
# CTRL-G: abort
7=ABORT
# BACKSPACE, CTRL-H: delete the previous character
# 8 is the ASCII code for backspace and therefor
# deleting the previous character
8=DELETE_PREV_CHAR
# TAB, CTRL-I: signal that console completion should be attempted
9=COMPLETE
Replace the command matching option 9 with empty string.
http://www.scala-sbt.org/release/docs/Howto/interactive.html#change-keybindings

Related

How do you do multiple line entry in the command line REPL of SuperCollider?

Just as the title says, How do you do multiple line entry in the command line REPL of SuperCollider? For example, in Haskell, you use :{ and :} to open and close multiple line entry in ghci.
If you're using sclang with the -i flag (meaning e.g. sclang -i something), the keycode to execute previously entered text is esc, followed by a newline. For example:
~a = {
"test".postln;
}^[
~a.();^[
outputs: test
This works file if you're driving sclang from an IDE or another scripting context (this is used for sclang's unit tests). If you're using the repl, it appears that there ISN'T a way to do multiline entries - the repl uses readline which doesn't have multiline support out of the box. This should probably be filed as a bug.

How to insert new lines when editing some script with fish's built-in editor?

When inputing multiline script in fish shell, e.g. I have input these script
$ for file in *.txt
echo $file
end
and my caret is after the word end. Now I want to insert a line before it, make it like:
$ for file in *.txt
echo $file
echo "hello" // I want to insert this line
end
But I found if I move my caret up and after echo $file, and press enter(or cmd/option/ctrl+enter), it just run the entire script without inserting a new line. I have to copy them to another editor and copy back after editing.
Is there any way to do it?
Update:
I just uploaded a screen recording https://asciinema.org/a/i7pOWhpdXUu0RLVOAMjVJTXbn. In the recording, I moved my caret up to after echo and pressed option + enter, but it executed the script instead of inserting a new line
fish binds escape + newline to unconditionally insert a newline. On a Mac, you would typically press option + return. However Mac terminal emulators do not send an escape-newline by default. With iTerm2 you can request that option acts as escape, under Preferences->Profiles->Keys:
Now the binding will be active and option-return will unconditionally insert a newline.
(You could instead add a key mapping for just this case if you prefer.)
You can confirm what the terminal receives from the emulator with fish_key_reader which is installed alongside fish.
In the default bindings, Alt-Enter will always insert a new line:
> bind|fgrep \\n
bind \e\n commandline\ -i\ \\n
bind \e\r commandline\ -i\ \\n
...
Depending on your system configuration, the Enter/Return key may send either a newline character (\n) or a carriage-return character (\r), so that's why there's two entries.

How to find and remove the invisible characters in text file using emacs

I have a .txt file named COPYING which is edited on windows.
It contains Windows-style line breaks :
$ file COPYING
COPYING: ASCII English text, with CRLF line terminators
I tried to convert it to Unix style using dos2unix. Below is the output :
$ dos2unix COPYING
dos2unix: Skipping binary file COPYING
I was surprised to find that the dos2unix program reports it as a binary file. Then using some other editor (not Emacs) I found that the file contains a control character. I am interested in finding all the invisible characters in the file using Emacs.
By googling, I have found the following solution which uses tr :
tr -cd '\11\12\40-\176' < file_name
How can I do the same in an Emacs way? I tried the Hexl mode. The Hexl mode shows text and their corresponding ASCII values in a single buffer which is great. How do I find the characters which have ASCII values other than 11-12, 40-176 (i.e tab, space, and visible characters)? I tried to create a regular expression for that search, but it is quite complicated.
To see invisible characters, you can try whitespace-mode. Spaces and tabs will be displayed with a symbol in a different face. If the coding system is automatically being detected as dos (showing (DOS) on the status bar), carriage returns at the end of a line will be hidden as well. Run revert-buffer-with-coding-system to switch it to Unix or binary (e.g. C-x RET r unix) and they'll always show up as ^M. The binary coding system will display any non-ASCII characters as control characters as well.
Emacs won't hide any character by default. Press Ctrl+Meta+%, or Esc then Ctrl+% if the former is too hard on your fingers, or M-x replace-regexp RET if you prefer. Then, for the regular expression, enter
[^#-^H^K-^_^?]
However, where I wrote ^H, type Ctrl+Q then Ctrl+H, to enter a “control-H” character literally, and similarly for the others. You can press Ctrl+Q then Ctrl+Space for ^#, and usually Ctrl+Q then Backspace for ^?. Replace all occurrences of this regular expression by the empty string.
Since you have the file open in Emacs, you can change its line endings while you're at it. Press C-x RET f (Ctrl+X Return F) and enter us-ascii-unix as the new desired encoding for the file.
Check out M-x set-buffer-file-coding-system. From the documentation:
(set-buffer-file-coding-system CODING-SYSTEM &optional FORCE NOMODIFY)
Set the file coding-system of the current buffer to CODING-SYSTEM.
This means that when you save the buffer, it will be converted
according to CODING-SYSTEM. For a list of possible values of
CODING-SYSTEM, use M-x list-coding-systems.
So, going from DOS to UNIX, M-x set-buffer-file-coding-system unix.

Is there a way to use ctrl-d as forward delete in Scala's REPL?

So in the Scala REPL, I can use the ctrl-{p,n,a,e} to do previous-, next-, beginning of- and end of line. However, I'll soon go crazy if I can't use ctrl-d to forward-delete.
Is it possible to achieve this in some way?
I'm using a Mac.
Update
Add the following lines to the accepted answer to get ctrl-{a,e}. A larger keybindings file kan be found in the jline2 repo jline2 repo at GitHub.
# CTRL-A: move to the beginning of the line
1=MOVE_TO_BEG
# CTRL-E: move the cursor to the end of the line
5=MOVE_TO_END
Update2
I just installed Scala 2.9.0.final and I can confirm that the ctrl-d is now working as it should. It's forward delete unless it's an empty line when it terminates the shell.
Here's a very minimal keybinding property file, including your desired ^D:
# CTRL-B: move to the previous character
2: PREV_CHAR
# CTRL-D: delete the previous character
4: DELETE_NEXT_CHAR
# CTRL-F: move to the next character
6: NEXT_CHAR
# BACKSPACE, CTRL-H: delete the previous character
# 8 is the ASCII code for backspace and therefor
# deleting the previous character
8: DELETE_PREV_CHAR
# TAB, CTRL-I: signal that console completion should be attempted
9: COMPLETE
# CTRL-J, CTRL-M: newline
10: NEWLINE
# ENTER: newline
13: NEWLINE
# CTRL-N: scroll to the next element in the history buffer
14: NEXT_HISTORY
# CTRL-P: scroll to the previous element in the history buffer
16: PREV_HISTORY
# CTRL-V: paste the contents of the clipboard (useful for Windows terminal)
22: PASTE
# DELETE, CTRL-?: delete the previous character
# 127 is the ASCII code for delete
127: DELETE_PREV_CHAR
Put it in a file, and call scala like this:
scala -Djline.keybindings=/path/to/keybindings.properties
Or pass it through JAVA_OPTS. You'll have to look up on the Internet what keybindings exist, and try :keybindings from Scala to see what are the defaults (it won't reflect your actual keybindings, though).
in scala 2.9's REPL you have a new :keybindings command. This reveals:
scala> :keybindings
Reading jline properties for default key bindings.
Accuracy not guaranteed: treat this as a guideline only.
1 CTRL-A: move to the beginning of the line
2 CTRL-B: move to the previous character
4 CTRL-D: close out the input stream
5 CTRL-E: move the cursor to the end of the line
6 CTRL-F: move to the next character
7 CTRL-G: abort
8 BACKSPACE, CTRL-H: delete the previous character 8 is the ASCII code for backspace and therefor deleting the previous character
9 TAB, CTRL-I: signal that console completion should be attempted
10 CTRL-J, CTRL-M: newline
11 CTRL-K: erase the current line
12 CTRL-L: clear screen
13 ENTER: newline
14 CTRL-N: scroll to the next element in the history buffer
15 CTRL-O: move to the previous word
16 CTRL-P: scroll to the previous element in the history buffer
18 CTRL-R: redraw the current line
21 CTRL-U: delete all the characters before the cursor position
22 CTRL-V: paste the contents of the clipboard (useful for Windows terminal)
23 CTRL-W: delete the word directly before the cursor
127 DELETE, CTRL-?: delete the next character 127 is the ASCII code for delete
on the macbook laptops, DELETE can be accessed via Fn + BACKSPACE.

Vim ex knowing number typed before

I'm making a shortcut that places a # at the front of each line, in the next x lines. x is a number I type before entering the shortcut, like typing 11dd deletes the next eleven lines.
The command is .,+10 s/^/#/g. Here the number ten should really be whatever was typed before the shortcut. How do I make the shortcut change according to the number that was typed before it?
Added after question was answered:
So now I have the following in the .vimrc:
nmap c1 :s/^/#/g<esc>``
nmap c0 :s/^#//g<esc>``
Which allows me to type 13ac, to add # at the front of the next 13 lines, and 13dc to delete any # at the front of the next 13 lines.
It's better than =pod and =cut for they cause errors when nested.
c1=comment add,
c0=comment delete.
# is used in Perl.
In ex mode, you can use the following command:
s/^/#/count
where count is the number of lines you want to change. You can't put the number before the command, because that is used to select the starting line (current line if omitted). Thus:
5s/^/#/3
will add a '#' before lines 5, 6 and 7.
Edit
In ex mode you can use the map command to create a shortcut to a colon command, which you can then use with a prefix number:
map CC :s/^/#/g
Now you can use 'xCC' in vi mode to prepend '#' to the next x lines.