I have been coding for a while using R and RStudio but recently I started to dig into python. It is fair to say that I am new to python, but moreover, new to editing the emacs .init file (.emacs
) in detail. I am trying to set and understand the interplay between python
and emacs
, mainly IPython, since I suspect that I am going to be heavily using IPython in the near future.
At the beginning, my intention was only to be able to use .emacs
to edit some code and then, if necessary, copy and paste into IPython. At that stage, the part of my .emacs
file dedicated to python
was:
;; Enable python
(add-to-list 'load-path "/sw/lib/python-mode-1.0")
(setq auto-mode-alist
(cons '("\\.py$" . python-mode) auto-mode-alist))
(setq interpreter-mode-alist
(cons '("python" . python-mode)
interpreter-mode-alist))
(autoload 'python-mode "python-mode" "Python editing mode." t)
I loaded /sw/lib/python-mode-1.0
, which comes from installing fink
a while ago, because is the only directory in which I found a python-mode.el file. At that time seemed the only sequence of commands that worked (I have the intuition that half of it is not needed(?)).
The I learned that you could send commands from .emacs
to Python/IPython. I typed: M-x python-mode
, and then M-x py-shell
to work with "normal-python" and it worked. Here I would have to ask the 1st question.
1- Every time I run a command I obtain the message:
`## working on region in file /var/folders/bd/f2194wl90rg38c8jqc12m47m0000gn/T/python-13120iJs.py..`
How do I avoid obtaining this message (every time!). This question is less important than the second one below.
Then, based on this post: How to open IPython interpreter in emacs? I typed this into my .emacs
file:
(when (executable-find "ipython")
(setq
python-shell-interpreter "ipython"
python-shell-interpreter-args ""
python-shell-prompt-regexp "In \\[[0-9]+\\]: "
python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: "
python-shell-completion-setup-code
"from IPython.core.completerlib import module_completion"
python-shell-completion-module-string-code
"';'.join(module_completion('''%s'''))\n"
python-shell-completion-string-code
"';'.join(get_ipython().Completer.all_completions('''%s'''))\n"))
This, effectively, allows me to use IPython by typing: M-x run-python
. However, when I try C-c C-c
I obtain the error message : C-c C-c is undefined
. (same for C-c |
, also undefined)
At this stage, I have these two "chunks" of python-set-up lines in my .emacs
file and nothing seems to work properly. I have looked in the web and found this: http://ipython.org/ipython-doc/1/config/editors.html , so I also tried to type: (require 'ipython)
and it did not work either. It says that file ipython is not found
. Therefore, the 2nd and most important question in this post is:
2- Can someone help me to do a clean set up of IPython in Emacs? (I do not mind if I have to remove all the set up lines so far. I simply want to be able to work efficiently using Emacs+IPython)
I am using a Mac 10.9.5. Emacs version is 24.4. Python 2.7.8. And in case is of any use, I installed python using anaconda:
>which python
/anaconda/bin/python
>which ipython
/anaconda/bin/ipython
and emacs with macports, and is "aliased":
>which emacs
emacs: aliased to open -a /Applications/MacPorts/Emacs.app/Contents/MacOS/Emacs