I wrote 100 narray exercises which is a Ruby version of 100 numpy exercises in Markdown, but I wrote it in it. You'll need to copy and paste a piece of code. It was quite annoying to repeat this copy and paste execution, so I investigated how to make it possible to execute the selection range of the file opened in Emacs with a single M-x command.
CentOS Linux release 7.2.1511 (Core)
GNU Emacs 24.3.1 (x86_64-redhat-linux-gnu, GTK+ Version 3.8.8)
The purpose is to select and execute the code part in this Markdown.
## Sample MD
Python:
```python
import numpy as np
Z = np.arange(10)
print(Z)
```
Ruby:
```ruby
require "numo/narray"
z = Numo::DFloat.new(10).seq
```
There are two ways to run Python in an Emacs buffer: python.el and python-mode.el.
It is included in Emacs as standard, so no installation is required.
(require 'python)
This setting is unnecessary because it will be loaded automatically when you open .py, but it is necessary because it will not be loaded when you execute Markdown code pieces.
Open the Markdown file in Emacs, select the Python code, and run the following command.
M-x python-shell-send-region
Then, python in interactive mode starts, and the execution result is recorded in the buffer * Python [filename] *
, but it does not appear in the foreground, so you need to swithc-to-buffer.
(2) python-mode.el
This also supports IPython.
Get the source from the python-mode.el site and install it.
(require 'python-mode)
This is also needed if you want to run a piece of Markdown code.
M-x py-execute-region
The interactive mode python starts, and the buffer * Python *
appears on the split screen and the execution result is displayed.
If you want to pass it to IPython instead of interactive mode python, use the following command.
M-x py-execute-region-ipython
Inf-ruby.el (Inferior Ruby Mode) is used to execute Ruby in the Emacs buffer, but there are also two types.
What is included in the Ruby source code. The update has stopped for a long time.
Place misc / inf-ruby.el in the Ruby source tree in an appropriate path.
(autoload 'run-ruby "inf-ruby" "Run an inferior Ruby process")
(require 'inf-ruby)
M-x run-ruby
M-x ruby-send-region
Developed at https://github.com/nonsequitur/inf-ruby. This has been modified from the Ruby attachment version above, and also supports Pry. The version I tried was 2.4.0.
Get inf-ruby.el from the above URL. When using irb, many useless prompts are displayed as it is and it is difficult to see, so modify it by adding --inf-ruby-mode to the option and then place it in an appropriate path.
diff --git a/inf-ruby.el b/inf-ruby.el
index deb5769..39f586d 100755
--- a/inf-ruby.el
+++ b/inf-ruby.el
@@ -83,7 +83,7 @@ Also see the description of `ielm-prompt-read-only'."
:group 'inf-ruby)
(defcustom inf-ruby-implementations
- '(("ruby" . "irb --prompt default --noreadline -r irb/completion")
+ '(("ruby" . "irb --prompt default --inf-ruby-mode -r irb/completion")
("jruby" . "jruby -S irb --prompt default --noreadline -r irb/completion")
("rubinius" . "rbx -r irb/completion")
("yarv" . "irb1.9 -r irb/completion")
(autoload 'inf-ruby "inf-ruby" "Run an inferior Ruby process" t)
M-x inf-ruby
M-x ruby-send-region
If you want to use Pry instead of irb, add the following line to ~ / .emacs.el.
(setq inf-ruby-default-implementation "pry")
reference: http://d.hatena.ne.jp/rubikitch/20140627/pry
Recommended Posts