help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Configuring Anaconda-Mode and Company-Mode with IPython


From: daniel . galtieri
Subject: Configuring Anaconda-Mode and Company-Mode with IPython
Date: Wed, 15 Apr 2015 06:42:36 -0700 (PDT)
User-agent: G2/1.0

I am new to using Emacs, and am currently trying to configure it to be a more 
robust environment for coding in Python.

To do this I'm using Company-Mode with Anaconda-Mode for autocompletion, along 
with the defaul Python.el mode

I would like to use IPython as my repl, but I'm experiencing some odd behavior 
with autocompletion in the IPython buffer (autocompletion works fine in the 
normal python buffer(s)).

Basically what happens is as follows:

If I start typing something, such as "import sys" the appropriate hints for 
import and sys pop up (so that's working fine).

When I go to use sys, though, if I symply type "sy" and then hit tab/enter to 
complete sys and then go to use one of the methods in sys (e.g. sys.path), 
again the appropriate hints are shown (so again, working fine)

However, if instead I type out sys and try to then continue by typing sys.p, no 
hints are shown. I can force company to complete manually with M-x 
company-complete, but obviously this is not the desired behavior.

I think this may have something to do with Anaconda-mode and IPython. Looking 
at my Python buffers, Anaconda-mode is listed as one of the minor modes, but it 
is not listed in my IPython buffer. Disabling Anaconda-mode in my Python 
buffers also produces the behavior described above. If I manually start 
Anaconda-mode in the IPython buffer (Inferior Python), the tooltips now 
activate properly but the contents are incorrect (i.e. the class methods shown 
to be available are not correct). 

Also, I'm using company-quickhelp for docstring tooltips. In none of the above 
scenarios do the docstring tooltips popup. 

I'm assuming there is an issue with how I have IPython / Anacanda-mode (and 
associated company-anaconda backed) / company-mode, but I'm not sure how to 
resolve it. 

Also, I'm not sure if it's related to this or not, but looking at the 
*Messages* buffer, whenever I go to type in the IPython buffer I see the 
following message popping up:

Invalid face reference: nil [nnn times]

where the value for nnn increases every time I type in the IPython buffer


I have my configuration split up into different files:

init.el:

;;; add path to settings files
(add-to-list 'load-path "~/.emacs.d/settings")

;;; setup package management
(require 'package)
(package-initialize)
(add-to-list 'package-archives
             '("melpa" . "http://melpa.org/packages/";) t)

;;; configure general settings
(require 'general-settings)

;;; configure general settings for all coding buffers
(require 'general-code-settings)

;;;
(require 'python-settings)
;;; init.el ends here

python-settings.el:

;;enable anaconda-mode and eldoc-mode in all python buffers
(add-hook 'python-mode-hook 'anaconda-mode)
(add-hook 'python-mode-hook 'eldoc-mode)

;;use IPython
(setq python-shell-interpreter "ipython")

(provide 'python-settings)
;;; python-settings.el ends here

general-code-settings.el:

;;enable company mode globally and add company-anaconda backend
(add-hook 'after-init-hook 'global-company-mode)
;;(add-hook 'prog-mode-hook 'company-mode)
(with-eval-after-load 'company
  (add-to-list 'company-backends 'company-anaconda))

;;makes completion start automatically rather than waiting for 3 chars / 0.5sec
(setq company-minimum-prefix-length 1)
(setq company-idle-delay 0)

;;company quickhelp gives docstring info
(company-quickhelp-mode 1)

;;enable flycheck
(add-hook 'after-init-hook #'global-flycheck-mode)

;;enable fill-column-indicator for 80char line indication
(require 'fill-column-indicator)
(add-hook 'prog-mode-hook 'fci-mode)
(setq fci-rule-column 80)


;;workaround for bug between company mode and fill-column-indicator
(defvar-local company-fci-mode-on-p nil)

(defun company-turn-off-fci (&rest ignore)
  (when (boundp 'fci-mode)
    (setq company-fci-mode-on-p fci-mode)
    (when fci-mode (fci-mode -1))))

(defun company-maybe-turn-on-fci (&rest ignore)
  (when company-fci-mode-on-p (fci-mode 1)))

(add-hook 'company-completion-started-hook 'company-turn-off-fci)
(add-hook 'company-completion-finished-hook 'company-maybe-turn-on-fci)
(add-hook 'company-completion-cancelled-hook 'company-maybe-turn-on-fci)

(provide 'general-code-settings)
;;; general-code-settings.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]