Skip to content

Commit

Permalink
Merge pull request #444 from ikirill/pr-option-completions
Browse files Browse the repository at this point in the history
OPTIONS and LANGUAGE completion using ghci
  • Loading branch information
lukehoersten committed Apr 22, 2015
2 parents b2aa551 + f0f9800 commit 64cb818
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
12 changes: 12 additions & 0 deletions haskell-customize.el
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,18 @@ when Data.Map is the candidate.
:group 'shm
:type '(repeat 'string))

(defcustom haskell-ghc-supported-languages
(split-string (shell-command-to-string "ghc --supported-extensions"))
"List of language pragmas supported by the installed version of GHC."
:group 'haskell
:type '(repeat string))

(defcustom haskell-ghc-supported-options
(split-string (shell-command-to-string "ghc --show-options"))
"List of options supported by the installed version of GHC."
:group 'haskell
:type '(repeat string))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Accessor functions

Expand Down
6 changes: 0 additions & 6 deletions haskell-yas.el
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@
:group 'haskell
:prefix "haskell-yas-")

(defcustom haskell-yas-ghc-language-pragmas
(split-string (shell-command-to-string "ghc --supported-extensions"))
"List of language pragmas supported by the installed version of GHC."
:group 'haskell-yas
:type '(repeat string))

(defcustom haskell-yas-completing-function 'ido-completing-read
"Function to use for completing among alternatives."
:group 'haskell-yas
Expand Down
29 changes: 23 additions & 6 deletions haskell.el
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
(defun haskell-process-completions-at-point ()
"A completion-at-point function using the current haskell process."
(when (haskell-session-maybe)
(let ((process (haskell-process)) symbol)
(let ((process (haskell-process)) symbol symbol-bounds)
(cond
;; ghci can complete module names, but it needs the "import "
;; string at the beginning
Expand All @@ -74,11 +74,28 @@
(end (match-end 1)))
(list start end
(haskell-process-get-repl-completions process text))))
((setq symbol (symbol-at-point))
(cl-destructuring-bind (start . end) (bounds-of-thing-at-point 'symbol)
(let ((completions (haskell-process-get-repl-completions
process (symbol-name symbol))))
(list start end completions))))))))
;; Complete OPTIONS using :complete repl ":set ..."
((and (nth 4 (syntax-ppss))
(save-excursion
(let ((p (point)))
(and (search-backward "{-#" nil t)
(search-forward-regexp "\\_<OPTIONS\\(?:_GHC\\)?\\_>" p t))))
(looking-back (rx symbol-start "-" (* (char alnum ?-)))))
(list (match-beginning 0) (match-end 0) haskell-ghc-supported-options))
;; Complete LANGUAGE :complete repl ":set -X..."
((and (nth 4 (syntax-ppss))
(save-excursion
(let ((p (point)))
(and (search-backward "{-#" nil t)
(search-forward-regexp "\\_<LANGUAGE\\_>" p t))))
(setq symbol-bounds (bounds-of-thing-at-point 'symbol)))
(list (car symbol-bounds) (cdr symbol-bounds)
haskell-ghc-supported-languages))
((setq symbol-bounds (bounds-of-thing-at-point 'symbol))
(cl-destructuring-bind (start . end) symbol-bounds
(list start end
(haskell-process-get-repl-completions
process (buffer-substring-no-properties start end)))))))))

;;;###autoload
(defun haskell-interactive-mode-return ()
Expand Down
2 changes: 1 addition & 1 deletion snippets/haskell-mode/lang-pragma
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# condition: (= (length "lang") (current-column))
# contributor: Luke Hoersten <[email protected]>, John Wiegley
# --
{-# LANGUAGE `(progn (require 'haskell-yas) (haskell-yas-complete "Extension: " haskell-yas-ghc-language-pragmas))` #-}
{-# LANGUAGE `(progn (require 'haskell-yas) (haskell-yas-complete "Extension: " haskell-ghc-supported-languages))` #-}

0 comments on commit 64cb818

Please sign in to comment.