Support for multiple completions in Emacs

This commit is contained in:
Alejandro Serrano 2014-08-02 10:27:40 +02:00
parent 3aa83e14dd
commit 5623c62200
2 changed files with 31 additions and 11 deletions

View File

@ -256,6 +256,7 @@ nil does not display errors/warnings.
(define-button-type 'find-file-button (define-button-type 'find-file-button
'follow-link t 'follow-link t
'help-echo "mouse-2, RET: Go to definition"
'action #'find-file-button) 'action #'find-file-button)
(defun buttonize-buffer () (defun buttonize-buffer ()

View File

@ -75,7 +75,7 @@
;;; Auto ;;; Auto
;;; ;;;
(defun ghc-perform-rewriting-auto (info) (defun ghc-perform-rewriting-auto (info msg)
"Replace code with new string obtained from ghc-mod from auto mode" "Replace code with new string obtained from ghc-mod from auto mode"
(let* ((current-line (line-number-at-pos)) (let* ((current-line (line-number-at-pos))
(begin-line (ghc-sinfo-get-beg-line info)) (begin-line (ghc-sinfo-get-beg-line info))
@ -87,15 +87,34 @@
(end-line-pos (line-beginning-position end-line-diff)) (end-line-pos (line-beginning-position end-line-diff))
(end-pos (- (+ end-line-pos (ghc-sinfo-get-end-column info)) 1)) ) (end-pos (- (+ end-line-pos (ghc-sinfo-get-end-column info)) 1)) )
(delete-region begin-pos end-pos) (delete-region begin-pos end-pos)
(insert (first (ghc-sinfo-get-info info))) ) (insert msg)))
)
(defun ghc-show-auto-messages (msgs) (defun auto-button (button)
(ghc-display-with-name nil (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)
(defun ghc-show-auto-messages (info)
(let ((buf (current-buffer)))
(setq ghc-auto-info info)
(setq ghc-auto-buffer buf)
(ghc-display nil
(lambda () (lambda ()
(insert "Possible completions:\n") (insert "Possible completions:\n")
(mapc (lambda (x) (insert "- " x "\n")) msgs)) (mapc
"*Djinn completions*")) (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"
@ -104,8 +123,8 @@
(if (null info) (if (null info)
(message "No automatic completions found") (message "No automatic completions found")
(if (= (length (ghc-sinfo-get-info info)) 1) (if (= (length (ghc-sinfo-get-info info)) 1)
(ghc-perform-rewriting-auto info) (ghc-perform-rewriting-auto info (first (ghc-sinfo-get-info info)))
(ghc-show-auto-messages (ghc-sinfo-get-info info)))))) (ghc-show-auto-messages info)))))
(defun ghc-obtain-auto () (defun ghc-obtain-auto ()
(let* ((ln (int-to-string (line-number-at-pos))) (let* ((ln (int-to-string (line-number-at-pos)))