lispy repl-loop substitution with IPython? - ipython

Is there a way to substitute this Lisp interpreter repl() loop with IPython.
http://www.norvig.com/lispy2.html
here is the full source code :
https://github.com/norvig/pytudes/blob/master/lispy.py

Related

Replace text literally without regular expression in Emacs evil-mode

In vim, I could use :%sno/[abt]//g to remove all text of "[abt]" literally (as explained here).
I tried the same command in evil-mode, but it complains it doesn't understand the sno command, so how can I do the same thing in evil-mode?
To my knowledge, evil does not (yet?) support the "magic/no magic" regexp options (actually, it only does a smallish subset of ex functionality, so I don't think % will work either). As #Ehvince's answer suggests, the standard Emacs way to do the replace is with query-replace or query-replace-regexp. If you'd like to stick to evil, just escape the square brackets with a backslash:
:s/\[abt\]//g
NB: backslash escapes in Emacs often bite people coming from other environments or programming languages; have a look at the bottom of this manual node on the backslash for more information.
You would use the emacs command query-replace bound to M-%:
M-% [abt] RET <nothing> RET
and then approve each occurence with y or all with !.
The doc is at C-h f query-replace.
query-replace-regexp is bound to C-M-%.

How to write comma character in a SLIME EMACS window

How can I write a "," (comma) character in the SLIME emacs window? The , key brings up the SLIME command prompt automatically.
Thanks, a Lisp beginner
, only triggers REPL shortcut selection when input at the beginning of a line. In all other cases, you can input a comma by typing ,.
In the case of Common Lisp, since as long as you don't modify the reader, , can only occur within a quasi-quoted expression, this should not be a significant restriction.
If it really is a problem, refer to Deokhwan Kim's answer.
You can insert , by C-q, (Control-q and then comma). C-q is bound to quoted-insert, which can be generally used whenever you want Emacs to read a next input character and insert it instead of invoking a command bound to the input character.

Gvim syntax highlighting

I was trying to make Gvim highlight syntax of a certain type of file(as Perl) using following command
au BufNewFile,BufRead *.bias setf perl
But as the first line of this file doesn't start with a #!/usr/bin/perl. Gvim is not performing syntax highlighting of Perl. Any solution for this ?
Try this in your .vimrc (I think Gvim still uses that)
autocmd BufRead *.bias set filetype=perl
If you just want to do it for a single file then try:
:set filetype=perl
Just put the line you already have in ~/.vim/ftdetect/bias.vim and it should work. I have several custom files I've set up syntax highlighting for in this way and have had no problems.
(Note: if you're on windows, the path would be ~/vimfiles/ftdetect/bias.vim )

How can I script vim to run perltidy on a buffer?

At my current job, we have coding-style standards that are different from the ones I normally follow. Fortunately, we have a canned RC file for perltidy that I can apply to reformat files before I submit them to our review process.
I have code for emacs that I use to run a command over a buffer and replace the buffer with the output, which I have adapted for this. But I sometimes alternate between emacs and vim, and would like to have the same capabilities there. I'm sure that this or something similar is simple and had been done and re-done many times over. But I've not had much luck finding any examples of vim-script that seem to do what I need. Which is, in essence, to be able to hit a key combo (like Ctrl-F6, what I use in emacs) and have the buffer be reformatted in-place by perltidy. While I'm a comfortable vim-user, I'm completely clueless at writing this sort of thing for vim.
After trying #hobbs answer I noticed that when filtering the entire buffer through perltidy the cursor returned to byte 1, and I had to make a mental note of the original line number so I could go back after :Tidy completed.
So building on #hobbs' and #Ignacio's answers, I added the following to my .vimrc:
"define :Tidy command to run perltidy on visual selection || entire buffer"
command -range=% -nargs=* Tidy <line1>,<line2>!perltidy
"run :Tidy on entire buffer and return cursor to (approximate) original position"
fun DoTidy()
let l = line(".")
let c = col(".")
:Tidy
call cursor(l, c)
endfun
"shortcut for normal mode to run on entire buffer then return to current line"
au Filetype perl nmap <F2> :call DoTidy()<CR>
"shortcut for visual mode to run on the current visual selection"
au Filetype perl vmap <F2> :Tidy<CR>
(closing " added to comments for SO syntax highlighting purposes (not required, but valid vim syntax))
DoTidy() will return the cursor to its original position plus or minus at most X bytes, where X is the number of bytes added/removed by perltidy relative to the original cursor position. But this is fairly trivial as long as you keep things tidy :).
[Vim version: 7.2]
EDIT: Updated DoTidy() to incorporate #mikew's comment for readability and for compatibility with Vim 7.0
My tidy command:
command -range=% -nargs=* Tidy <line1>,<line2>!
\perltidy (your default options go here) <args>
If you use a visual selection or provide a range then it will tidy the selected range, otherwise it will use the whole file. You can put a set of default options (if you have any) at the point where I wrote (your default options go here), but any arguments that you provide to :Tidy will be appended to the perltidy commandline, overriding your defaults. (If you use a .perltidyrc you might not have default args -- that's fine -- but then again you might want to have a default like --profile=vim that sets up defaults only for when you're working in vim. Whatever works.)
The command to filter the entire buffer through an external program is:
:%!command
Put the following in ~/.vimrc to bind it to Ctrl-F6 in normal mode:
:nmap <C-F6> :%!command<CR>
For added fun:
:au Filetype perl nmap <C-F6> :%!command<CR>
This will only map the filter if editing a Perl file.
Taking hobbs' answer a step further, you can map that command to a shortcut key:
command -range=% -nargs=* Tidy <line1>,<line2>!perltidy -q
noremap <C-F6> :Tidy<CR>
And another step further: Only map the command when you're in a Perl buffer (since you probably wouldn't want to run perltidy on any other language):
autocmd BufRead,BufNewFile *.pl,*.plx,*.pm command! -range=% -nargs=* Tidy <line1>,<line2>!perltidy -q
autocmd BufRead,BufNewFile *.pl,*.plx,*.pm noremap <C-F6> :Tidy<CR>
Now you can press Ctrl-F6 without an active selection to format the whole file, or with an active selection to format just that section.
Instead of creating a new keyboard shortcut, how about replacing the meaning of the = command which is already in people's finger memory for indenting stuff? Yes, perlcritic does more than just indent but when you use perlcritic anyways, then you probably don't want to go back to the inferior "just indent" = command. So lets overwrite it!
filetype plugin indent on
autocmd FileType perl setlocal equalprg=perltidy
And now we can use = just like before but with the added functionality of perlcritic that goes beyond just indenting lines:
== run perlcritic on the current line
5== run perlcritic on five lines
=i{ Re-indent the 'inner block', i.e. the contents of the block
=a{ Re-indent 'a block', i.e. block and containing braces
=2a{ Re-indent '2 blocks', i.e. this block and containing block
gg=G run perlcritic on the entire buffer
And the best part is, that you don't have to learn any new shortcuts but can continue using the ones you already used with more power. :)
I'm used to select text using line oriented visual Shift+V and then I press : an I have !perltidy -pbp -et4 somewhere in history so I hit once or more up arrow ⇧.

Indenting template arguments in Emacs

I'm having no luck getting Emacs (cc-mode) to indent multiline template arguments. Here's an example line:
typedef ::boost::zip_iterator< ::boost::tuple<
vector<int>::const_iterator, vector<float>::const_iterator > >;
I'd like the second line to be indented, as like in a function. It is indented, until I enter the second-to-last >, at which point the second line up moves to the left to align with the typedef.
When I start typing the second line, the syntactic analysis is ((statement-cont 52)), until the second-to-last >, at which point it becomes ((defun-block-intro 46)). Deleting the character doesn't return to the old syntactic analysis.
I expected to have template-args-cont as the syntactic analysis.
I'm using the emacs 22.2 (ubuntu intrepid) and cc-mode version 5.31.5 that came with it.
You should just need to set template-args-cont to some useful value. To experiment with it, put your cursor on the second line and enter C-cC-o for c-set-offset. Insert a convenient value. With 4, I get:
typedef ::boost::zip_iterator< ::boost::tuple<
vector<int>::const_iterator, vector<float>::const_iterator > >;
If that doesn't work, check your version: I have cc-mode version 5.31.6. To check, do M-x c-version. I get
Using CC Mode version 5.31.6