From 1b013d0223bbd13d7ae50d109f755126ab355802 Mon Sep 17 00:00:00 2001 From: Kirill Ignatiev Date: Wed, 21 Jan 2015 20:51:10 -0500 Subject: [PATCH 1/5] OPTIONS and LANGUAGE completion using ghci --- haskell.el | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/haskell.el b/haskell.el index c2df62781..770163dd9 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,6 +72,33 @@ (end (match-end 1))) (list start end (haskell-process-get-repl-completions process text)))) + ;; 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 ?-))))) + (let ((text (concat ":set " (match-string-no-properties 0))) + (start (match-beginning 0)) + (end (match-end 0))) + (list start end + (haskell-process-get-repl-completions process text)))) + ;; 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))) + (let* ((start (car symbol-bounds)) + (end (cdr symbol-bounds)) + (text (buffer-substring-no-properties start end)) + (cmd (concat ":set -X" text)) + (completions (haskell-process-get-repl-completions process cmd)) + (names (cdr completions)) ; first string is common prefix + (lang-options (mapcar (lambda (c) (substring c 2)) names))) + (list start end lang-options))) ((setq symbol (symbol-at-point)) (cl-destructuring-bind (start . end) (bounds-of-thing-at-point 'symbol) (let ((completions (haskell-process-get-repl-completions From cdbd868ad9101da8045a89cc797d4d3c80145815 Mon Sep 17 00:00:00 2001 From: Kirill Ignatiev Date: Wed, 21 Jan 2015 20:58:02 -0500 Subject: [PATCH 2/5] Avoid symbol-at-point and don't look it up twice symbol-at-point => thing-at-point 'symbol Also thing-at-point, then bounds-of-thing-at-point looks it up twice, which is unnecessary. --- haskell.el | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/haskell.el b/haskell.el index 770163dd9..79a4171b1 100644 --- a/haskell.el +++ b/haskell.el @@ -99,11 +99,11 @@ (names (cdr completions)) ; first string is common prefix (lang-options (mapcar (lambda (c) (substring c 2)) names))) (list start end lang-options))) - ((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)))))))) + ((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 () From a5ed6773026f92a145c145c16d42585dedced838 Mon Sep 17 00:00:00 2001 From: Kirill Ignatiev Date: Thu, 22 Jan 2015 16:01:14 -0500 Subject: [PATCH 3/5] Use cached ghc options and pragmas instead of ghci --- haskell-yas.el | 6 ++++++ haskell.el | 17 ++++------------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/haskell-yas.el b/haskell-yas.el index 29635cae8..c654fb8da 100644 --- a/haskell-yas.el +++ b/haskell-yas.el @@ -42,6 +42,12 @@ :group 'haskell-yas :type '(repeat string)) +(defcustom haskell-yas-ghc-options + (split-string (shell-command-to-string "ghc --show-options")) + "List of options 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 79a4171b1..fd796db52 100644 --- a/haskell.el +++ b/haskell.el @@ -27,6 +27,7 @@ (require 'haskell-commands) (require 'haskell-sandbox) (require 'haskell-modules) +(require 'haskell-yas) ; import precomputed ghc options/pragmas ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Basic configuration hooks @@ -79,11 +80,7 @@ (and (search-backward "{-#" nil t) (search-forward-regexp "\\_" p t)))) (looking-back (rx symbol-start "-" (* (char alnum ?-))))) - (let ((text (concat ":set " (match-string-no-properties 0))) - (start (match-beginning 0)) - (end (match-end 0))) - (list start end - (haskell-process-get-repl-completions process text)))) + (list (match-beginning 0) (match-end 0) haskell-yas-ghc-options)) ;; Complete LANGUAGE :complete repl ":set -X..." ((and (nth 4 (syntax-ppss)) (save-excursion @@ -91,14 +88,8 @@ (and (search-backward "{-#" nil t) (search-forward-regexp "\\_" p t)))) (setq symbol-bounds (bounds-of-thing-at-point 'symbol))) - (let* ((start (car symbol-bounds)) - (end (cdr symbol-bounds)) - (text (buffer-substring-no-properties start end)) - (cmd (concat ":set -X" text)) - (completions (haskell-process-get-repl-completions process cmd)) - (names (cdr completions)) ; first string is common prefix - (lang-options (mapcar (lambda (c) (substring c 2)) names))) - (list start end lang-options))) + (list (car symbol-bounds) (cdr symbol-bounds) + haskell-yas-ghc-language-pragmas)) ((setq symbol-bounds (bounds-of-thing-at-point 'symbol)) (cl-destructuring-bind (start . end) symbol-bounds (list start end From d9e533a8a9762623ea5fe3ea3083c797fb92da76 Mon Sep 17 00:00:00 2001 From: Kirill Ignatiev Date: Thu, 22 Jan 2015 16:03:36 -0500 Subject: [PATCH 4/5] Allow OPTIONS_GHC in option pragma completion --- haskell.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/haskell.el b/haskell.el index fd796db52..ea764aed6 100644 --- a/haskell.el +++ b/haskell.el @@ -78,7 +78,7 @@ (save-excursion (let ((p (point))) (and (search-backward "{-#" nil t) - (search-forward-regexp "\\_" p t)))) + (search-forward-regexp "\\_" p t)))) (looking-back (rx symbol-start "-" (* (char alnum ?-))))) (list (match-beginning 0) (match-end 0) haskell-yas-ghc-options)) ;; Complete LANGUAGE :complete repl ":set -X..." From f0f98002202381468a56731bef08aaa842aa9a52 Mon Sep 17 00:00:00 2001 From: Kirill Ignatiev Date: Thu, 22 Jan 2015 16:19:39 -0500 Subject: [PATCH 5/5] Precompute ghc supported options and languages Also, move option/language-pragma lists out of haskell-yas, because it's nothing to do with yasnippet, and they are needed for completion. --- haskell-customize.el | 12 ++++++++++++ haskell-yas.el | 12 ------------ haskell.el | 5 ++--- snippets/haskell-mode/lang-pragma | 2 +- 4 files changed, 15 insertions(+), 16 deletions(-) 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 c654fb8da..1efc24369 100644 --- a/haskell-yas.el +++ b/haskell-yas.el @@ -36,18 +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-ghc-options - (split-string (shell-command-to-string "ghc --show-options")) - "List of options 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 ea764aed6..1e0240be2 100644 --- a/haskell.el +++ b/haskell.el @@ -27,7 +27,6 @@ (require 'haskell-commands) (require 'haskell-sandbox) (require 'haskell-modules) -(require 'haskell-yas) ; import precomputed ghc options/pragmas ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Basic configuration hooks @@ -80,7 +79,7 @@ (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-yas-ghc-options)) + (list (match-beginning 0) (match-end 0) haskell-ghc-supported-options)) ;; Complete LANGUAGE :complete repl ":set -X..." ((and (nth 4 (syntax-ppss)) (save-excursion @@ -89,7 +88,7 @@ (search-forward-regexp "\\_" p t)))) (setq symbol-bounds (bounds-of-thing-at-point 'symbol))) (list (car symbol-bounds) (cdr symbol-bounds) - haskell-yas-ghc-language-pragmas)) + haskell-ghc-supported-languages)) ((setq symbol-bounds (bounds-of-thing-at-point 'symbol)) (cl-destructuring-bind (start . end) symbol-bounds (list start end 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