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

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

Re: python development environment: auto-complete fails


From: Andreas Röhler
Subject: Re: python development environment: auto-complete fails
Date: Mon, 15 Mar 2010 07:49:35 +0100
User-agent: Thunderbird 2.0.0.19 (X11/20081227)

Tom Roche wrote:
> summary: I'm trying to steal the config for a python development
> environment for emacs (PDEE). I believe I've mostly got one, except
> when I open *.py I get
> 
> *Messages*
>> File mode specification error: (void-function auto-complete-mode)
> 
> and auto-complete fails. How to fix or do better?
> 
> details:
> 
> I'm currently running 
> 
> GNU Emacs 23.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 2.18.0)
> of 2009-09-27 on crested, modified by Debian
> 
> on 64-bit Ubuntu 9.10. I'm starting to code python (specifically 2.6.4)
> more seriously, so I'm trying to setup a PDEE. I'd really like a python
> equivalent of JDEE, but I'd settle for, e.g., the ability to run tests
> in one buffer and navigate to errors in source. Some of Ryan McGuire's
> blog posts
> 
> http://www.enigmacurry.com/2008/05/09/emacs-as-a-powerful-python-ide/
> http://www.enigmacurry.com/2009/01/19/my-emacs-config-on-github/
> 
> are often recommended as a way to setup a PDEE, and would be great
> for beginners, but
> 
> * They includes lotsa utilities. I prefer installing ubuntu packages.
> 
> * I've already got a substantial init.el and associated elisp.
> 
> so I'm trying to transplant the happy bits (as he recommends in the
> first post) from his emacs config on github (which is another great idea
> I've gotta steal) into my emacs config. I believe I've *mostly* gotten
> that, thusly:
> 
> 0 Ensure current ubuntu packages are up-to-date:
> 
> $ sudo aptitude update
> 
> 1 Install additional ubuntu packages: I (apparently) needed
> 
> automake
> cedet-common
> cedet-contrib
> emacs-jabber
> git-core
> libgconf2-dev
> pymacs
> python-rope
> python-ropemacs
> texinfo
> 
> 2 Install auto-complete: not found in ubuntu package search, so I
> 
> * downloaded from 
> 
> http://cx4a.org/pub/auto-complete/auto-complete-1.2.tar.bz2
> 
>   (apparently the latest version)
> 
> * installed per its User Manual
> 
> http://cx4a.org/software/auto-complete/manual.html#Installation_Script
> 
> * hooked into my init.el (more below)
> 
> 3 "install" python.el by copying from McGuire's setup (downloaded to
>   /tmp with `git`)
> 
> $ cp -r /tmp/.emacs.d/vendor/dave-loves-python-mode 
> /home/tlroche/.emacs.d/site-lisp/
> 
> 4 "install" McGuire's ryan-python.el, i.e.
> 
> * copy/modify:
> 
> $ cp /tmp/.emacs.d/ryan-python.el /home/tlroche/.emacs.d/tlrPython.el
> 
>   and edit tlrPython.el (more below), adding attribution and tweaking
>   `add-to-list 'load-path`
> 
> * byte-compiled tlrPython.el
> 
> * hooked it into my init.el
> 
> 5 restart emacs: no errors while loading my desktop.
> 
> 6 C-x C-f a python file: the minibuffer modeline says
> 
>> (Python Fill)
> 
>   and recognizes the file under svn (and the psvn color button is
>   working), but I also get
> 
> *Messages*
>> File mode specification error: (void-function auto-complete-mode)
> 
>   and attempting an autocomplete with TAB gets
> 
> *Messages*
>> Symbol's function definition is void: yas/expand [2 times]
> 
> So I'm wondering, how to fix? 

Check your load-path variable in any case.
You write you've set the path via "add-to-list", so it should be there.
However, the error shown raises doubts.

If this not helps, maybe set the files containing missing functions via "load" 
in your init-file.

HTH

Andreas

--
https://code.launchpad.net/~a-roehler/python-mode
https://code.launchpad.net/s-x-emacs-werkstatt/


or is there a better way to do this?
> FWIW I have (comments mostly omitted, for brevity)
> 
> ~/.emacs.d/init.el (fragment of much larger file)
>> (load "tlrAutoComplete")
>> (load "tlrPython")
> 
> ~/.emacs.d/tlrAutoComplete.el (
>> (add-to-list 'load-path "~/.emacs.d/site-lisp/auto-complete-1.2")
>> (require 'auto-complete-config)
>> (add-to-list 'ac-dictionary-directories
>>      "~/.emacs.d/site-lisp/auto-complete-1.2/ac-dict")
>> (ac-config-default)
> 
> ~/.emacs.d/tlrPython.el (to end of post, complete minus most comments)
>> (add-to-list 'load-path "~/.emacs.d/site-lisp/dave-loves-python-mode")
>> (load-library "python")
> 
>> (autoload 'python-mode "python-mode" "Python Mode." t)
>> (add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode))
>> (add-to-list 'interpreter-mode-alist '("python" . python-mode))
>> (setq interpreter-mode-alist
>>       (cons '("python" . python-mode)
>>           interpreter-mode-alist)
>>       python-mode-hook
>>       '(lambda () 
>>           (progn
>>               (set-variable 'py-indent-offset 4)
>>               (set-variable 'py-smart-indentation nil)
>>               (set-variable 'indent-tabs-mode nil) 
>>               (define-key python-mode-map "\C-m" 'newline-and-indent)
>>           )
>>       )
>> )
> 
>> (defun python-auto-fill-comments-only ()
>>     (auto-fill-mode 1)
>>     (set (make-local-variable 'fill-nobreak-predicate)
>>        (lambda ()
>>            (not (python-in-string/comment)))))
>> (add-hook 'python-mode-hook
>>     (lambda ()
>>         (python-auto-fill-comments-only)))
> 
>> (autoload 'pymacs-apply "pymacs")
>> (autoload 'pymacs-call "pymacs")
>> (autoload 'pymacs-eval "pymacs" nil t)
>> (autoload 'pymacs-exec "pymacs" nil t)
>> (autoload 'pymacs-load "pymacs" nil t)
>> (pymacs-load "ropemacs" "rope-")
>> (setq ropemacs-enable-autoimport t)
> 
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> ;;; Auto-completion
>> ;;;  Integrates:
>> ;;;   1 Rope
>> ;;;   2 Yasnippet
>> ;;;   with AutoComplete.el
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> 
>> (defun prefix-list-elements (list prefix)
>>   (let (value)
>>     (nreverse
>>      (dolist (element list value)
>>       (setq value (cons (format "%s%s" prefix element) value))))))
> 
>> (defvar ac-source-rope
>>   '((candidates
>>      . (lambda ()
>>          (prefix-list-elements (rope-completions) ac-target))))
>>   "Source for Rope")
> 
>> (defun ac-python-find ()
>>   "Python `ac-find-function'."
>>   (require 'thingatpt)
>>   (let ((symbol (car-safe (bounds-of-thing-at-point 'symbol))))
>>     (if (null symbol)
>>         (if (string= "." (buffer-substring (- (point) 1) (point)))
>>             (point)
>>           nil)
>>       symbol)))
> 
>> (defun ac-python-candidate ()
>>   "Python `ac-candidates-function'"
>>   (let (candidates)
>>     (dolist (source ac-sources)
>>       (if (symbolp source)
>>           (setq source (symbol-value source)))
>>       (let* ((ac-limit (or (cdr-safe (assq 'limit source)) ac-limit))
>>              (requires (cdr-safe (assq 'requires source)))
>>              cand)
>>         (if (or (null requires)
>>                 (>= (length ac-target) requires))
>>             (setq cand
>>               (delq nil
>>                 (mapcar (lambda (candidate)
>>                   (propertize candidate 'source source))
>>                     (funcall (cdr (assq 'candidates source)))))))
>>         (if (and (> ac-limit 1)
>>                  (> (length cand) ac-limit))
>>             (setcdr (nthcdr (1- ac-limit) cand) nil))
>>         (setq candidates (append candidates cand))))
>>     (delete-dups candidates)))
> 
>> (add-hook 'python-mode-hook
>>     (lambda ()
>>         (auto-complete-mode 1)
>>         (set (make-local-variable 'ac-sources)
>>              (append ac-sources '(ac-source-rope)))
>>         (set (make-local-variable 'ac-find-function) 'ac-python-find)
>>         (set (make-local-variable 'ac-candidate-function)
>>             'ac-python-candidate)
>>         (set (make-local-variable 'ac-auto-start) nil)))
> 
>> ;;Ryan's python specific tab completion
>>   ; Try the following in order:
>>   ; 1 Try a yasnippet expansion without autocomplete
>>   ; 2 If at the beginning of the line, indent
>>   ; 3 If at the end of the line, try to autocomplete
>>   ; 4 If the char after point is not alpha-numerical, try autocomplete
>>   ; 5 Try to do a regular python indent.
>>   ; 6 If at the end of a word, try autocomplete.
>> (define-key python-mode-map "\t" 'yas/expand)
>> (add-hook 'python-mode-hook
>>     (lambda ()
>>         (set (make-local-variable 'yas/trigger-fallback)
>>             'ryan-python-expand-after-yasnippet)))
> 
>> (defun ryan-indent ()
>>     "Runs indent-for-tab-command but returns t if it actually did an indent; 
>> nil otherwise"
>>   (let ((prev-point (point)))
>>     (indent-for-tab-command)
>>     (if (eql (point) prev-point)
>>         nil
>>       t)))
> 
>> (defun ryan-python-expand-after-yasnippet ()
>>   (interactive)
>>   ;;2 Try indent at beginning of the line
>>   (let ((prev-point (point))
>>         (beginning-of-line nil))
>>     (save-excursion
>>       (move-beginning-of-line nil)
>>       (if (eql 0 (string-match "\\W*$" 
>>                      (buffer-substring (point) prev-point)))
>>           (setq beginning-of-line t)))
>>     (if beginning-of-line
>>         (ryan-indent)))
>>   ;;3 Try autocomplete if at the end of a line, or
>>   ;;4 Try autocomplete if the next char is not alpha-numerical
>>   (if (or (string-match "\n" 
>>               (buffer-substring (point) (+ (point) 1)))
>>           (not (string-match "[a-zA-Z0-9]" 
>>                    (buffer-substring (point) (+ (point) 1)))))
>>       (ac-start)
>>     ;;5 Try a regular indent
>>     (if (not (ryan-indent))
>>         ;;6 Try autocomplete at the end of a word
>>         (if (string-match "\\W"
>>                 (buffer-substring (point) (+ (point) 1)))
>>             (ac-start)))))
> 
>> ;; End Tab completion
> 
>> ;;Workaround so that Autocomplete is by default is only invoked 
>> ;;explicitly, but still automatically updates as you type while
>> ;;attempting to complete.
>> (defadvice ac-start (before advice-turn-on-auto-start activate)
>>   (set (make-local-variable 'ac-auto-start) t))
> 
>> (defadvice ac-cleanup (after advice-turn-off-auto-start activate)
>>   (set (make-local-variable 'ac-auto-start) nil))
> 
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> ;;; End Auto Completion
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> 
>> ;;Autofill comments
>> ;;TODO: make this work for docstrings too.
>> ;;      but docstrings just use font-lock-string-face unfortunately
>> (add-hook 'python-mode-hook
>>           (lambda ()
>>             (auto-fill-mode 1)
>>             (set (make-local-variable 'fill-nobreak-predicate)
>>                  (lambda ()
>>                    (not (eq (get-text-property (point) 'face)
>>                             'font-lock-comment-face))))))
> 
> 
> 





reply via email to

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