How to configure emacs to work with ipython - emacs

I'm using ubuntu 14.04, emacs 24.3.1, python 2.7.6, ipython 1.2.1, python-mode 6.1.3. Ipython has been working well within emacs for at least a year, however, I have the following problem since two weeks ago.
use C-c! to start default interpreter, ipython shows as I hoped, but instead of split frame and show in another window, it appears in the original code window. (this is a minor problem)
use C-c| to execute a region, python interpreter starts, and the code sends to the python interpreter instead of ipython interpreter
I searched on SO, but this problem seems too recent to have an answer. I googled, found this page https://answers.launchpad.net/python-mode/+question/250905, tried methods therein, still didn't work... Could anyone help me fix the problem? Many thanks!
My .emacs python part looks like
(require 'python-mode)
(setq-default py-shell-name "ipython")
(setq-default py-which-bufname "IPython")
; switch to the interpreter after executing code
(setq py-shell-switch-buffers-on-execute-p t)
(setq py-switch-buffers-on-execute-p t)
; don't split windows
(setq py-split-windows-on-execute-p nil)

In order to split the window
(setq py-split-windows-on-execute-p t)
is needed, resp. reset to default - last line in example. Maybe check settings via M-x customize ... also, which may conflict with setq from init.
When selecting shell for execution: a shebang in buffer might override default py-shell-name.
When shebang should be ignored, use
(setq py-force-py-shell-name-p t)
See menu
Python/Customize/Switches/Interpreter
for an easy way to change this value during current session.

Related

Customizing emacs in .emacs file

I want emacs to start with specific settings by default. I found that I need to edit the .emacs file in my home directory and use LISP language. However I do get some errors. I need to have:
Windows split by vertical line (I work in C++ with headers and source files)
Column number mode
Cua-mode enabled (to work with normal copy, cut & paste shortcuts)
That's what I have in my .emacs file:
(column-number-mode)
(load "cua-mode")
(CUA-mode t)
(split-window-right)
I'ver tried coding two middle settings in one - (cua-mode). It didn't work out well.
The column-number-mode works, cua does not load and my window is split horizontally (top and bottom window). Where is my error? Thanks for feedback.
From the comments to the question:
if you're using Emacs 24.1 or later,
(column-number-mode)
(load "cua-mode")
(cua-mode t)
(split-window-right)
but if you're using an earlier version,
(column-number-mode)
(load "cua-mode")
(cua-mode t)
(split-window-horizontally)
By the way, the split-window-horizontally also works in later versions of Emacs (I'm using Emacs 25.2.1).

ac-auto-start (auto-complete mode) would not get set no matter what

I'm facing a very bizarre behaviour. No matter how I set ac-auto-start, be it through customization, by evaluating (setq ac-auto-start 2), (setq-default ac-auto-start 2) or (setq-local ac-auto-start 2) immediately after I do it, the variable is set to nil.
I've looked through the source of auto-complete mode and the ac-slime in my case, but none of these does nothing to this variable. I am at a loss as to how to deal with this.
The effective consequences of this malfunction is that completion combobox doesn't appear on its own, unless I force it to by doing M-x auto-complete. This behaviour is consistent in all modes where auto-complete minor mode is enabled.
EDIT
This seems to be an issue with latest Emacs. Now it fails to modify variables values, no matter what variable it is. So, say, after running it with -Q I've now discovered that I can't evaluate the code that uses (setq ...) forms as it has no effect. :/ So, please, hold on, I'll try to investigate this...
This was due to the typo, but the original problem is still there.
Emacs version is 24.3.50.1 pulled from trunk about a week ago.
auto-complete is version 1.4 installed from MELPA.
I'm setting the variable by moving the point to the REPL buffer, then M-:. I check its value in the same way.
EDIT2
OK, I finally found the reason: I had enzyme package installed, and it had an earlier version of auto-complete inside of it, for some reason parts of the auto-complete code were loaded from there and other parts from the one installed from MELPA. After disabling enzyme it all works well now.
EDIT3
This still happens after I run (auto-complete-mode 1) in the REPL buffer. The variable will become impossible to set. I've searched through various autocomplete timers that may be setting something, but no luck so far.
There is indeed something strange going on with the setting of auto-complete-mode.
(I'm using the ELPA version in a GNU Emacs 24.3.1)
This is set up by customize-group RET auto-complete :
'(ac-auto-show-menu t)
'(ac-auto-start t)
At this point if you M-x auto-complete-mode you get a [no match] right in the minibuffer. Only after you try to M-x auto-complete, yelding a "auto-complete-mode is not enabled" weird error, will you be able to M-x auto-complete-mode (but without command completion... Hm) and then be in the mode.
If you put this in your init file (.emacs)
(require 'auto-complete)
(auto-complete-mode t)
It will be effective only if you re-eval it after startup (?!?).
The same with something like
(if (auto-complete)
(auto-complete-mode t))
The only way that I found to get auto-complete-mode to load at startup is to :
(eval-and-compile
(require 'auto-complete nil 'noerror))
(The above customize options are now effective)

Settings only for GUI/Terminal emacs

I'm trying to set a theme - one only for terminal, and one only for gui.
I've read this thread: Run certain Emacs init commands only in GUI mode
Which led me here: https://superuser.com/questions/165335/how-can-i-show-the-emacs-menu-in-gui-emacs-frames-but-not-in-tty-frames-when-usi
And tried to create a function to suit my need.
(defun set-frame-theme (frame)
(let ((want-theme (memq (framep frame) '(x w32 ns))))
(set-frame-parameter frame '(load-theme '(if want-theme monokai solarized-dark) t))))
(add-hook 'after-make-frame-functions 'set-frame-theme)
It doesn't work.
I'm trying him to load monokai only if gui, otherwise load solarized-dark.
It does work for the GUI interface, but causes the terminal to seemingly crash.
Suggestions?
The emacs lisp function,
(display-graphic-p)
Will return true if emacs is running in a GUI.
In your .emacs, add the following to switch between your GUI and terminal themes
(if (display-graphic-p)
(load-GUI-theme)
(load-Terminal-theme))
For easier configuration, I have a simple function called is-in-terminal
(defun is-in-terminal()
(not (display-graphic-p)))
you could use this to write an easier to read function
(if (is-in-terminal)
(load-Terminal-theme)
(load-GUI-theme))
For a more complete approach to Terminal Only configuration I have a macro that works just like progn but only evaluates the body when Emacs is running without a GUI
(defmacro when-term (&rest body)
"Works just like `progn' but will only evaluate expressions in VAR when Emacs is running in a terminal else just nil."
`(when (is-in-terminal) ,#body))
Example Usage:
(when-term
(load-my-term-theme)
(set-some-keybindings)
(foo-bar))
This entire block will be totally ignored if running in a GUI, but will run if in Terminal.
All this code was taken from a file in my config, if interested you can check it out here:
https://github.com/jordonbiondo/Emacs/blob/master/Jorbi/jorbi-util.el
i could solve the issue with:
(if (display-graphic-p) (load-theme 'solarized-dark t))
the final t is to override the confirmation prompt in theme selection.
More here.
I too had the problem of emacs crashing when running in terminal mode while selecting a color-theme.
I would say this is not an issue with the color-theme but with emacs itself.
Updating to the newest version from HEAD did work for me as of time of this writing.
As mentioned at https://www.emacswiki.org/emacs/CustomizingFaces
"If you want different color schemes for different displays, you can customize this as well. In the customize buffer, click the [State] button and choose “Show all display specs”. Now you can use different specs for different displays."
Seems like an issue with the theme itself - nothing more and nothing less. uh well.

Emacs Init File Line Numbering

I am trying to display line numbers in emacs on the left hand side. I know it is the linum-mode. When I do M-x linum-mode, my emacs can't find linum-mode. It only finds line-numbers-mode which displays it on the mode bar at the bottom. Why does it not have linum-mode?
Also, when I put (menu-bar-mode t) or even (menu-bar-mode 1), the menu bar does not start at start-up.
When I put (global-linum-mode t) I get the following init error (using --debug-init):
Debugger entered--Lisp error: (void-function global-linum-mode)
(global-linum-mode t)
eval-buffer(#<buffer *load*> nil "/Users/nayef/.emacs.d/init.el" nil t) ; Reading at buffer position 68
load-with-code-conversion("/Users/nayef/.emacs.d/init.el" "/Users/nayef/.emacs.d/init.el" t t)
load("/Users/nayef/.emacs.d/init" t t)
This is extremely extremely frustrating. It works on one computer over SSH but when I do it on my laptop it does not work. I am starting to understand that even though Emacs is more powerful than VIM, VIM is at least 10 times easier to use, less keystrokes and requires WAY less modifications.
Which version of Emacs do you have? linum-mode is included with Emacs 23 and Emacs 24. If you can, you should probably upgrade to those version. If you can't upgrade and you have Emacs 22, you'll need to do the following steps:
Download linum.el on your system (let's say it's in /home/nayefc/).
Add the line (add-to-list 'load-path "/home/nayefc/") to your .emacs
Add the line (require 'linum) to your .emacs
Restart Emacs, and you should be able to call M-x linum-mode. Good luck.
Vincent.
You're having problems because linum-mode is not a standard part of any Emacs distribution; it has to be installed. You can get it here.

How can I set up two, parallel buffers in emacs to edit Python files in one and execute in an IPython shell in the other?

I'm trying to setup ipython.el in emacs23. I've successfully installed it (after putting python-mode.el in my load-path to supplant python.el which comes pre-installed with emacs). And I can even get it to run via M-x py-shell, etc.
The interface seems to be pretty poorly setup, and I was wondering if I was doing it wrong, or if I need to customize it to make it work the way I'd like.
In short, the workflow I'd like to have:
in one or more buffers, edit Python code
When I hit C-c C-c in that buffer, either execute the Python code in that buffer in the open IPython shell buffer (if there is one) or open up another buffer to do that.
But what happens right now is:
With the IPython shell in one buffer and the Python file in the other, if I hit C-c C-c in the Python file buffer, the file buffer switches to the IPython buffer (meaning I now have two, duplicated iPython buffers) and the file is executed.
This is annoying.
I'm pretty new to elisp, but my understanding of defadvice is that I could advise around python-execute-buffer to take note of the existing file buffer, run python-execute-buffer, and then switch back to the original file buffer as a workaround.
This seems pretty silly. Any suggestions for better ways to accomplish this would be appreciated!
If it matters: I'm on OS X 10.6.8 with IPython 0.10.1 running Emacs 24.0.50.
Thanks in advance!
Turns out that simply installing python-mode.el and anything-ipython.el and putting
(require 'python-mode)
(require 'ipython)
(require 'anything-ipython)
(add-hook 'python-mode-hook #'(lambda ()
(define-key py-mode-map (kbd "C-<tab>") 'anything-ipython-complete)))
(add-hook 'ipython-shell-hook #'(lambda ()
(define-key py-mode-map (kbd "C-<tab>")
'anything-ipython-complete)))
in my .emacs made everything work just how I wanted if py-shell is executed before py-execute-buffer (so that C-c C-c) executes the code in the shell instead of just opening up the *Python Output* buffer.