Make completion from Djinn use a dropdown list

Fixes #312
This commit is contained in:
Alejandro Serrano 2014-08-12 23:01:37 +02:00
parent eec1419040
commit 7315dff801

View File

@ -10,6 +10,8 @@
(require 'ghc-func) (require 'ghc-func)
(require 'ghc-process) (require 'ghc-process)
(require 'button)
(require 'dropdown-list)
(defvar ghc-auto-info nil) (defvar ghc-auto-info nil)
(defvar ghc-auto-buffer nil) (defvar ghc-auto-buffer nil)
@ -112,32 +114,38 @@
(delete-region begin-pos end-pos) (delete-region begin-pos end-pos)
(insert msg))) (insert msg)))
(defun auto-button (button) ;; (defun auto-button (button)
(let ((text (buffer-substring (button-start button) (button-end button)))) ;; (let ((text (buffer-substring (button-start button) (button-end button))))
(with-current-buffer ghc-auto-buffer ;; (with-current-buffer ghc-auto-buffer
(ghc-perform-rewriting-auto ghc-auto-info text)))) ;; (ghc-perform-rewriting-auto ghc-auto-info text))))
(define-button-type 'auto-button ;; (define-button-type 'auto-button
'follow-link t ;; 'follow-link t
'help-echo "mouse-2, RET: Insert this completion" ;; 'help-echo "mouse-2, RET: Insert this completion"
'action #'auto-button) ;; 'action #'auto-button)
;; (defun ghc-show-auto-messages (info)
;; (let ((buf (current-buffer)))
;; (setq ghc-auto-info info)
;; (setq ghc-auto-buffer buf)
;; (ghc-display nil
;; (lambda ()
;; (insert "Possible completions:\n")
;; (mapc
;; (lambda (x)
;; (let* ((ins1 (insert "- "))
;; (pos-begin (point))
;; (ins (insert x))
;; (pos-end (point))
;; (ins3 (insert "\n")))
;; (make-button pos-begin pos-end :type 'auto-button)))
;; (ghc-sinfo-get-info info))))))
(defun ghc-show-auto-messages (info) (defun ghc-show-auto-messages (info)
(let ((buf (current-buffer))) (let* ((completions (ghc-sinfo-get-info info))
(setq ghc-auto-info info) (selected (dropdown-list completions)))
(setq ghc-auto-buffer buf) (when selected
(ghc-display nil (ghc-perform-rewriting-auto info (nth selected completions)))))
(lambda ()
(insert "Possible completions:\n")
(mapc
(lambda (x)
(let* ((ins1 (insert "- "))
(pos-begin (point))
(ins (insert x))
(pos-end (point))
(ins3 (insert "\n")))
(make-button pos-begin pos-end :type 'auto-button)))
(ghc-sinfo-get-info info))))))
(defun ghc-auto () (defun ghc-auto ()
"Try to automatically fill the contents of a hole" "Try to automatically fill the contents of a hole"