diff --git a/haskell-customize.el b/haskell-customize.el index 31a381daa..917848040 100644 --- a/haskell-customize.el +++ b/haskell-customize.el @@ -333,6 +333,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 diff --git a/haskell-yas.el b/haskell-yas.el index 29635cae8..1efc24369 100644 --- a/haskell-yas.el +++ b/haskell-yas.el @@ -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 diff --git a/haskell.el b/haskell.el index c2df62781..1e0240be2 100644 --- a/haskell.el +++ b/haskell.el @@ -58,7 +58,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 @@ -72,11 +72,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 "\\_" 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 "\\_" 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 () diff --git a/snippets/haskell-mode/lang-pragma b/snippets/haskell-mode/lang-pragma index 45c8ec678..241d43a90 100644 --- a/snippets/haskell-mode/lang-pragma +++ b/snippets/haskell-mode/lang-pragma @@ -4,4 +4,4 @@ # condition: (= (length "lang") (current-column)) # contributor: Luke Hoersten , John Wiegley # -- -{-# LANGUAGE `(progn (require 'haskell-yas) (haskell-yas-complete "Extension: " haskell-yas-ghc-language-pragmas))` #-} \ No newline at end of file +{-# LANGUAGE `(progn (require 'haskell-yas) (haskell-yas-complete "Extension: " haskell-ghc-supported-languages))` #-} \ No newline at end of file