Skip to content

Commit

Permalink
added: auto-complete-mode setting for haskell
Browse files Browse the repository at this point in the history
  • Loading branch information
ncaq committed Mar 25, 2015
1 parent 891cbe4 commit d6e257b
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
;;; ac-haskell-process-autoloads.el --- automatically extracted autoloads
;;
;;; Code:
(add-to-list 'load-path (or (file-name-directory #$) (car load-path)))

;;;### (autoloads nil "ac-haskell-process" "ac-haskell-process.el"
;;;;;; (21778 63301 779828 263000))
;;; Generated autoloads from ac-haskell-process.el

(defconst ac-source-haskell-process '((available . ac-haskell-process-available-p) (candidates . ac-haskell-process-candidates) (document . ac-haskell-process-doc) (symbol . "h")) "\
Haskell auto-complete source which uses the current haskell process.")

(autoload 'ac-haskell-process-setup "ac-haskell-process" "\
Add the haskell process completion source to the front of `ac-sources'.
This affects only the current buffer.
\(fn)" t nil)

(autoload 'ac-haskell-process-popup-doc "ac-haskell-process" "\
Show documentation for the symbol at point in a popup.
\(fn)" t nil)

;;;***

;; Local Variables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; End:
;;; ac-haskell-process-autoloads.el ends here
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(define-package "ac-haskell-process" "20150204.1104" "Haskell auto-complete source which uses the current haskell process" '((auto-complete "1.4") (haskell-mode "13")) :keywords '("languages"))
Binary file not shown.
118 changes: 118 additions & 0 deletions elpa/ac-haskell-process-20150204.1104/ac-haskell-process.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
;;; ac-haskell-process.el --- Haskell auto-complete source which uses the current haskell process

;; Copyright (C) 2014 Steve Purcell

;; Author: Steve Purcell <steve@sanityinc.com>
;; Keywords: languages
;; Package-Version: 20150204.1104
;; Version: DEV
;; Package-Requires: ((auto-complete "1.4") (haskell-mode "13"))

;; 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 of the License, 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. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Provides an auto-complete source for Haskell which obtains its
;; completions from the current inferior haskell process (see the
;; `haskell-process' library included in `haskell-mode').

;;; Installation:

;; Available as a package in MELPA at http://melpa.org/
;; M-x package-install ac-haskell-process

;;; Usage:

;; (require 'ac-haskell-process) ; if not installed via package.el
;; (add-hook 'interactive-haskell-mode-hook 'ac-haskell-process-setup)
;; (add-hook 'haskell-interactive-mode-hook 'ac-haskell-process-setup)
;; (eval-after-load "auto-complete"
;; '(add-to-list 'ac-modes 'haskell-interactive-mode))

;; If you want to trigger auto-complete using TAB in REPL buffers, you may
;; want to use auto-complete in your `completion-at-point-functions':

;; (defun set-auto-complete-as-completion-at-point-function ()
;; (add-to-list 'completion-at-point-functions 'auto-complete))
;; (add-hook 'auto-complete-mode-hook 'set-auto-complete-as-completion-at-point-function)
;; (add-to-list 'ac-modes 'haskell-interactive-mode)
;; (add-hook 'haskell-interactive-mode-hook 'set-auto-complete-as-completion-at-point-function)
;; (add-hook 'haskell-mode-hook 'set-auto-complete-as-completion-at-point-function)
;;
;; You can use `ac-haskell-process-popup-doc' to pop up documentation
;; for the symbol at point:
;;
;; (eval-after-load 'haskell-mode
;; '(define-key haskell-mode-map (kbd "C-c C-d") 'ac-haskell-process-popup-doc))
;;
;; This will only work if Emacs can execute the "hoogle" command.

;;; Code:

(require 'auto-complete)
(require 'haskell)
(require 'haskell-process)


(defun ac-haskell-process-available-p ()
"Return non-nil if completions are available from this source."
(haskell-session-maybe))

(defun ac-haskell-process-candidates ()
"Return a list of completion candidates for the current `ac-prefix'."
(haskell-process-get-repl-completions (haskell-process) ac-prefix))

(defun ac-haskell-process-doc (sym)
"Return the docstring for SYM."
(when (executable-find "hoogle")
(shell-command-to-string
(concat "hoogle --info " (shell-quote-argument sym)))))

;;;###autoload
(defconst ac-source-haskell-process
'((available . ac-haskell-process-available-p)
(candidates . ac-haskell-process-candidates)
(document . ac-haskell-process-doc)
(symbol . "h"))
"Haskell auto-complete source which uses the current haskell process.")

;;;###autoload
(defun ac-haskell-process-setup ()
"Add the haskell process completion source to the front of `ac-sources'.
This affects only the current buffer."
(interactive)
(add-to-list 'ac-sources 'ac-source-haskell-process))

(defun ac-haskell-process-symbol-start-pos ()
"Find the starting position of the symbol at point, unless inside a string."
(let ((sap (symbol-at-point)))
(when (and sap (not (in-string-p)))
(car (bounds-of-thing-at-point 'symbol)))))

;;;###autoload
(defun ac-haskell-process-popup-doc ()
"Show documentation for the symbol at point in a popup."
(interactive)
(let ((doc (ac-haskell-process-doc (symbol-name (symbol-at-point)))))
(when doc
(popup-tip doc
:point (ac-haskell-process-symbol-start-pos)
:around t
:scroll-bar t
:margin t))))



(provide 'ac-haskell-process)
;;; ac-haskell-process.el ends here
Binary file not shown.
5 changes: 5 additions & 0 deletions profile/30_haskell.el
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
'(haskell-stylish-on-save t)
)

(add-to-list 'ac-modes 'haskell-interactive-mode)
(add-hook 'interactive-haskell-mode-hook 'ac-haskell-process-setup)
(add-hook 'haskell-interactive-mode-hook 'ac-haskell-process-setup)

(defun haskell-mode-stylish-buffer-and-save-buffer()
(interactive)
(save-buffer)
Expand All @@ -27,6 +31,7 @@
(add-hook 'haskell-mode-hook 'ghc-init)

(with-eval-after-load 'ghc
(add-to-list 'ac-sources 'ac-source-ghc-mod)
(add-hook 'after-save-hook 'ghc-import-module nil t)

(defun ghc-show-info-minibuffer ()
Expand Down
Binary file modified profile/30_haskell.elc
Binary file not shown.

0 comments on commit d6e257b

Please sign in to comment.