diff --git a/elisp/ghc-rewrite.el b/elisp/ghc-rewrite.el index 01c87b2..0b91963 100644 --- a/elisp/ghc-rewrite.el +++ b/elisp/ghc-rewrite.el @@ -10,6 +10,8 @@ (require 'ghc-func) (require 'ghc-process) +(require 'button) +(require 'dropdown-list) (defvar ghc-auto-info nil) (defvar ghc-auto-buffer nil) @@ -112,32 +114,38 @@ (delete-region begin-pos end-pos) (insert msg))) -(defun auto-button (button) - (let ((text (buffer-substring (button-start button) (button-end button)))) - (with-current-buffer ghc-auto-buffer - (ghc-perform-rewriting-auto ghc-auto-info text)))) +;; (defun auto-button (button) +;; (let ((text (buffer-substring (button-start button) (button-end button)))) +;; (with-current-buffer ghc-auto-buffer +;; (ghc-perform-rewriting-auto ghc-auto-info text)))) -(define-button-type 'auto-button - 'follow-link t - 'help-echo "mouse-2, RET: Insert this completion" - 'action #'auto-button) +;; (define-button-type 'auto-button +;; 'follow-link t +;; 'help-echo "mouse-2, RET: Insert this completion" +;; '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) - (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)))))) + (let* ((completions (ghc-sinfo-get-info info)) + (selected (dropdown-list completions))) + (when selected + (ghc-perform-rewriting-auto info (nth selected completions))))) (defun ghc-auto () "Try to automatically fill the contents of a hole"