Permalink
Browse files

auto-complete 1.4, R completion (with docs), less intrusive config

  • Loading branch information...
1 parent f6d3095 commit fb1373ceaf79bf3ce6e0e204fd4628dad72270fe @timcharper timcharper committed Mar 24, 2011
Showing with 277 additions and 9,921 deletions.
  1. +3 −0 .gitmodules
  2. +54 −1 initializers.available/auto-complete.el
  3. +219 −0 vendor/ac-R.el
  4. +1 −0 vendor/auto-complete
  5. +0 −451 vendor/auto-complete/COPYING.FDL.txt
  6. +0 −674 vendor/auto-complete/COPYING.GPLv3.txt
  7. +0 −24 vendor/auto-complete/Makefile
  8. +0 −13 vendor/auto-complete/README.txt
  9. +0 −10 vendor/auto-complete/TODO.txt
  10. +0 −483 vendor/auto-complete/auto-complete-config.el
  11. +0 −1,897 vendor/auto-complete/auto-complete.el
  12. +0 −74 vendor/auto-complete/dict/c++-mode
  13. +0 −37 vendor/auto-complete/dict/c-mode
  14. +0 −475 vendor/auto-complete/dict/clojure-mode
  15. +0 −747 vendor/auto-complete/dict/css-mode
  16. +0 −50 vendor/auto-complete/dict/java-mode
  17. +0 −148 vendor/auto-complete/dict/javascript-mode
  18. +0 −62 vendor/auto-complete/dict/php-mode
  19. +0 −104 vendor/auto-complete/dict/python-mode
  20. +0 −181 vendor/auto-complete/dict/ruby-mode
  21. +0 −216 vendor/auto-complete/dict/scheme-mode
  22. +0 −172 vendor/auto-complete/dict/tcl-mode
  23. BIN vendor/auto-complete/doc/ac-fuzzy.png
  24. BIN vendor/auto-complete/doc/ac-isearch.png
  25. BIN vendor/auto-complete/doc/ac.png
  26. +0 −107 vendor/auto-complete/doc/changes.ja.txt
  27. +0 −107 vendor/auto-complete/doc/changes.txt
  28. +0 −11 vendor/auto-complete/doc/demo.txt
  29. +0 −79 vendor/auto-complete/doc/index.ja.txt
  30. +0 −79 vendor/auto-complete/doc/index.txt
  31. +0 −1,067 vendor/auto-complete/doc/manual.ja.txt
  32. +0 −1,062 vendor/auto-complete/doc/manual.txt
  33. +0 −27 vendor/auto-complete/doc/style.css
  34. +0 −45 vendor/auto-complete/etc/install.el
  35. +0 −202 vendor/auto-complete/etc/test.txt
  36. +0 −255 vendor/auto-complete/fuzzy.el
  37. +0 −1,061 vendor/auto-complete/popup.el
View
@@ -49,3 +49,6 @@
[submodule "vendor/durendal"]
path = vendor/durendal
url = https://github.com/technomancy/durendal.git
+[submodule "vendor/auto-complete"]
+ path = vendor/auto-complete
+ url = git://github.com/timcharper/auto-complete.git
@@ -1,4 +1,57 @@
(add-to-list 'load-path "~/.emacs.d/vendor/auto-complete")
(require 'auto-complete-config)
-(add-to-list 'ac-dictionary-directories "~/.emacs.d/vendor/auto-complete/dict")
+
+(setq help-xref-following nil) ;; autocomplete causes help to break unless if this is defined.... hmph
+
+(setq ac-use-menu-map t
+ ac-auto-show-menu t
+ ac-delay 999.0
+ ac-expand-on-auto-complete nil
+ ac-quick-help-delay 0.25
+ ac-use-quick-help t)
(ac-config-default)
+
+(add-to-list 'ac-dictionary-directories "~/.emacs.d/vendor/auto-complete/dict")
+
+(require 'ac-R)
+
+(defun auto-complete-or-show-menu ()
+ (interactive)
+ "Try to autocomplete. If only one possibility, show the menu so we can at least see the help for the method if available"
+ (auto-complete)
+ (when (not (ac-menu-live-p))
+ (progn
+ (ac-start :requires t)
+ (ac-update-greedy))))
+
+(defun auto-complete-words ()
+ (interactive)
+ (auto-complete-mode t)
+ (let ((ac-sources (list 'ac-source-words-in-all-buffer)))
+ (auto-complete)))
+
+(global-set-key (kbd "s-;") 'auto-complete-words)
+(global-set-key (kbd "s-:") 'auto-complete-or-show-menu)
+
+(define-key ac-completing-map (kbd "s-;") 'ac-expand)
+(define-key ac-completing-map (kbd "ESC") 'ac-stop)
+(define-key ac-menu-map (kbd "C-n") 'ac-next)
+(define-key ac-menu-map (kbd "C-p") 'ac-previous)
+(define-key ac-menu-map (kbd "C-v") 'ac-quick-help-scroll-down)
+(define-key ac-menu-map (kbd "M-v") 'ac-quick-help-scroll-up)
+
+(dotimes (i 9)
+ (define-key ac-menu-map (number-to-string i) (intern (format "ac-complete-%d" i))))
+
+;; Hack auto-complete to show numbers (for easier selection...)
+
+(defadvice popup-preferred-width (around popup-preferred-width-adjust-for-prefix activate)
+ ad-do-it
+ (setq ad-return-value (+ 4 ad-return-value)))
+
+(defadvice popup-set-line-item (around popup-set-line-item-with-number activate)
+ (let ((item (ad-get-arg 2))
+ (item-index (ad-get-arg 3)))
+ (ad-set-arg 2
+ (concat (format "%2d %s" (+ 1 item-index) item)))
+ ad-do-it))
View
@@ -0,0 +1,219 @@
+;;; ac-R.el --- Autocompletion routines for R
+;;
+;; Filename: ac-R.el
+;; Description: Autocompletion for R.
+;; Author: Matthew L. Fidler
+;; Maintainer: Matthew L. Fidler
+;; Created: Mon Aug 23 15:11:28 2010 (-0500)
+;; Version: 0.2
+;; Last-Updated:
+;; By:
+;; Update #: 46
+;; URL:
+;; Keywords:
+;; Compatibility:
+;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;;; Commentary:
+;;
+;;Put this file into load-path'ed directory, and byte compile it if
+;; desired. And put the following expression into your ~/.emacs.
+;;
+;; (require 'ac-R)
+;;
+;; Most of this was hacked from the Ess sources for completion.
+;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;;; Change log:
+;; 23-Mar-2011 Timothy C. Harper
+;; Hook up R documentation in completion popup.
+;; 22-Oct-2010 Matthew L. Fidler
+;; Added caching mechanism for 3 characters or less
+;; 23-Aug-2010 Matthew L. Fidler
+;; Initial Version
+;;
+;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation; either version 3, or
+;; (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program; see the file COPYING. If not, write to
+;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
+;; Floor, Boston, MA 02110-1301, USA.
+;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;;; Code:
+(defvar ac-R-cache '()
+ "A cache of R autocompletion.")
+
+(make-variable-buffer-local 'ac-R-cache)
+(defun ac-R-add-to-alist (alist-var elt-cons &optional no-replace)
+ "Add to the value of ALIST-VAR an element ELT-CONS if it isn't there yet.
+If an element with the same car as the car of ELT-CONS is already present,
+replace it with ELT-CONS unless NO-REPLACE is non-nil; if a matching
+element is not already present, add ELT-CONS to the front of the alist.
+The test for presence of the car of ELT-CONS is done with `equal'."
+ (let (
+ (case-fold-search 't)
+ (existing-element (assoc (car elt-cons) (symbol-value alist-var))))
+ (if existing-element
+ (or no-replace
+ (rplacd existing-element (cdr elt-cons)))
+ (set alist-var (cons elt-cons (symbol-value alist-var))))))
+
+(defun ac-R ()
+ "Returns a list of completions"
+ (let ( (prefix "") present ret)
+ (when (looking-back "\\<[^ \t\n,=.$]*")
+ (setq prefix (match-string 0)))
+ (setq present (assoc prefix ac-R-cache))
+ (if present
+ (setq ret (assoc prefix present))
+ (if ess-use-R-completion
+ (setq ret (ac-R-complete-object-name))
+ (setq ret (ac-internal-complete-object-name)))
+ (when (>= 3 (length prefix))
+ (ac-R-add-to-alist 'ac-R-cache (list prefix ret))))
+ (symbol-value 'ret)))
+
+(defun ess-get-help-text (sym)
+ (interactive)
+ (require 'ess-help)
+ (with-temp-buffer
+ (ess-command (format inferior-ess-help-command sym) (current-buffer))
+ (ess-help-underline)
+ ;; Stata is clean, so we get a big BARF from this.
+ (if (not (string= ess-language "STA"))
+ (ess-nuke-help-bs))
+ (buffer-substring (point-min) (point-max))))
+
+(setq ac-source-R
+ '((prefix . "\\<[^ \t\n,=.$]*")
+ (requires . 1)
+ (candidates . ac-R)
+ (document . ess-get-help-text)
+ (cache)))
+
+(defun ac-R-complete-object-name ()
+ ;; Modified from ESS
+ "Completion in R via R's completion utilities (formerly 'rcompgen').
+To be used instead of ESS' completion engine for R versions >= 2.5.0
+ (or slightly older versions of R with an attached and working 'rcompgen' package)."
+ (interactive)
+ (ess-make-buffer-current)
+ (let* ((comint-completion-addsuffix nil)
+ (beg-of-line (save-excursion (comint-bol nil) (point)))
+ (end-of-line (point-at-eol))
+ (line-buffer (buffer-substring beg-of-line end-of-line))
+ (NS (if (ess-current-R-at-least '2.7.0)
+ "utils:::"
+ "rcompgen:::"))
+ (token-string ;; setup, including computation of the token
+ (progn
+ (ess-command
+ (format (concat NS ".assignLinebuffer('%s')\n") line-buffer))
+ (ess-command (format (concat NS ".assignEnd(%d)\n")
+ (- (point) beg-of-line)))
+ (car (ess-get-words-from-vector
+ (concat NS ".guessTokenFromLine()\n")))))
+
+ (possible-completions ;; compute and retrieve possible completions
+ (progn
+ (ess-command (concat NS ".completeToken()\n"))
+ (ess-get-words-from-vector
+ (concat NS ".retrieveCompletions()\n")))))
+ (symbol-value 'possible-completions)))
+
+(defun ac-internal-complete-object-name (&optional listcomp)
+ "Perform completion on `ess-language' object preceding point.
+The object is compared against those objects known by
+`ess-get-object-list' and any additional characters up to ambiguity are
+inserted. Completion only works on globally-known objects (including
+elements of attached data frames), and thus is most suitable for
+interactive command-line entry, and not so much for function editing
+since local objects (e.g. argument names) aren't known.
+
+Use \\[ess-resynch] to re-read the names of the attached directories.
+This is done automatically (and transparently) if a directory is
+modified (S only!), so the most up-to-date list of object names is always
+available. However attached dataframes are *not* updated, so this
+command may be necessary if you modify an attached dataframe.
+
+If ARG is non-nil, no completion is attempted, but the available
+completions are listed [__UNIMPLEMENTED__]."
+ (interactive "P");; FIXME : the `listcomp' argument is NOT used
+ (ess-make-buffer-current)
+ (if (memq (char-syntax (preceding-char)) '(?w ?_))
+ (let* ((comint-completion-addsuffix nil)
+ (end (point))
+ (buffer-syntax (syntax-table))
+ (beg (unwind-protect
+ (save-excursion
+ (set-syntax-table ess-mode-syntax-table)
+ (backward-sexp 1)
+ (point))
+ (set-syntax-table buffer-syntax)))
+ (full-prefix (buffer-substring beg end))
+ (pattern full-prefix)
+ ;; See if we're indexing a list with `$'
+ (listname (if (string-match "\\(.+\\)\\$\\(\\(\\sw\\|\\s_\\)*\\)$"
+ full-prefix)
+ (progn
+ (setq pattern
+ (if (not (match-beginning 2)) ""
+ (substring full-prefix
+ (match-beginning 2)
+ (match-end 2))))
+ (substring full-prefix (match-beginning 1)
+ (match-end 1)))))
+ ;; are we trying to get a slot via `@' ?
+ (classname (if (string-match "\\(.+\\)@\\(\\(\\sw\\|\\s_\\)*\\)$"
+ full-prefix)
+ (progn
+ (setq pattern
+ (if (not (match-beginning 2)) ""
+ (substring full-prefix
+ (match-beginning 2)
+ (match-end 2))))
+ (ess-write-to-dribble-buffer
+ (format "(ess-C-O-Name : slots..) : patt=%s"
+ pattern))
+ (substring full-prefix (match-beginning 1)
+ (match-end 1)))))
+ (components (if listname
+ (ess-object-names listname)
+ (if classname
+ (ess-slot-names classname)
+ ;; Default case: It hangs here when
+ ;; options(error=recoves) :
+ (ess-get-object-list ess-current-process-name)))))
+ ;; always return a non-nil value to prevent history expansions
+ (append classname components))))
+
+
+(add-to-list 'ac-modes 'ess-mode)
+
+(add-hook 'ess-mode-hook
+ (lambda ()
+ (add-to-list 'ac-sources 'ac-source-R)
+ (make-local-variable ac-ignore-case)
+ (setq ac-ignore-case nil)))
+(add-hook 'inferior-ess-mode-hook
+ (lambda ()
+ (add-to-list 'ac-sources 'ac-source-R)
+ (make-local-variable ac-ignore-case)
+ (setq ac-ignore-case nil)))
+
+(provide 'ac-R)
Submodule auto-complete added at 88b890
Oops, something went wrong.

0 comments on commit fb1373c

Please sign in to comment.