From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tom Roche Newsgroups: gmane.emacs.help Subject: python development environment: auto-complete fails Date: Sun, 14 Mar 2010 15:17:41 -0400 Message-ID: <871vfmzp9m.fsf@pobox.com> Reply-To: help-gnu-emacs@gnu.org, Tom Roche NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1268594312 30046 80.91.229.12 (14 Mar 2010 19:18:32 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 14 Mar 2010 19:18:32 +0000 (UTC) Cc: Ryan McGuire To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Mar 14 20:18:25 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1NqtKO-0000jw-DT for geh-help-gnu-emacs@m.gmane.org; Sun, 14 Mar 2010 20:18:20 +0100 Original-Received: from localhost ([127.0.0.1]:60147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NqtKN-0005LZ-KZ for geh-help-gnu-emacs@m.gmane.org; Sun, 14 Mar 2010 15:18:19 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NqtJy-0005L2-Fd for help-gnu-emacs@gnu.org; Sun, 14 Mar 2010 15:17:54 -0400 Original-Received: from [140.186.70.92] (port=49239 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NqtJw-0005Jx-D3 for help-gnu-emacs@gnu.org; Sun, 14 Mar 2010 15:17:54 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NqtJs-0006zl-HI for help-gnu-emacs@gnu.org; Sun, 14 Mar 2010 15:17:52 -0400 Original-Received: from b-pb-sasl-quonix.pobox.com ([208.72.237.35]:51645 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NqtJs-0006zc-EJ for help-gnu-emacs@gnu.org; Sun, 14 Mar 2010 15:17:48 -0400 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by b-sasl-quonix.pobox.com (Postfix) with ESMTP id E253495E39; Sun, 14 Mar 2010 15:17:46 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:cc:reply-to:date:message-id:mime-version:content-type; s=sasl; bh=6MJqKzrhuSVuPefQoA6KMeI3l0Q=; b=a1ZRkSaJR1hUSo3a0hVh iScWXEeVTDTTiSzMocAzxllVEzAxhqVlu1CPYQLZNjmJ/H0pNog0vzMuSR9xlmnx WGlhw0O7ktN/WHdpPgEhQzYm9zjGvG6BDfnvmxTWZl934vlgs6TOmrITqXarnUrb VQ+O3+sLSELXDdIi5zifKgs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :cc:reply-to:date:message-id:mime-version:content-type; q=dns; s=sasl; b=e3KTo0bPpmopCUV0bgr0eiBTA9uiYm0tKHjFKvaRj3Yto7+qm1iHC 25PqhiNfWABnYR2mwG7cYgOxr2JFxfPUDfSluRq8UsOqTZVc/B+xEC+vilAag8NV XpaEWfoexVAxdP9euQnJ7Y6CV3vlXNhBmZ7C0uTB0mmmEd1Kb8qlOQ= Original-Received: from b-pb-sasl-quonix. (unknown [127.0.0.1]) by b-sasl-quonix.pobox.com (Postfix) with ESMTP id C181295E37; Sun, 14 Mar 2010 15:17:44 -0400 (EDT) Original-Received: from tlrPanP5.pobox.com (unknown [69.134.240.67]) by b-sasl-quonix.pobox.com (Postfix) with ESMTPA id F095B95E36; Sun, 14 Mar 2010 15:17:41 -0400 (EDT) X-Pobox-Relay-ID: 44A7FEF2-2F9E-11DF-A3B8-68E3016DD5F0-07218935!b-pb-sasl-quonix.pobox.com X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:72429 Archived-At: 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? 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))))))