From a5c62acec9574dab270f9c2f78cb4ff49272b6fc Mon Sep 17 00:00:00 2001 From: Noriyuki OHKAWA Date: Fri, 4 Apr 2014 23:52:09 +0900 Subject: [PATCH] display error message to minibuffer when goto next/prev error. --- elisp/ghc-check.el | 22 ++++++++++++++++++++++ elisp/ghc.el | 19 +++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/elisp/ghc-check.el b/elisp/ghc-check.el index 07595d0..ae86d1a 100644 --- a/elisp/ghc-check.el +++ b/elisp/ghc-check.el @@ -144,6 +144,18 @@ (insert (overlay-get (car ovls) 'ghc-file) "\n\n") (mapc (lambda (x) (insert x "\n\n")) errs)))))) +(defun ghc-display-errors-to-minibuf () + (interactive) + (let* ((ovls (ghc-check-overlay-at (point))) + (errs (mapcar (lambda (ovl) (overlay-get ovl 'ghc-msg)) ovls)) + (old-max-mini-window-height max-mini-window-height)) + (setq max-mini-window-height 0.95) + (if (null ovls) + (message "No errors or warnings") + (progn + (message "%s\n" (mapconcat (lambda (x) (replace-regexp-in-string "\0" "\n" x)) errs "\n")))) + (setq old-max-mini-window-height))) + (defun ghc-check-overlay-at (p) (let ((ovls (overlays-at p))) (ghc-filter (lambda (ovl) (overlay-get ovl 'ghc-check)) ovls))) @@ -160,6 +172,11 @@ (pnts (mapcar 'overlay-start ovls2))) (if pnts (goto-char (apply 'max pnts))))) +(defun ghc-goto-and-display-prev-error () + (interactive) + (ghc-goto-prev-error) + (ghc-display-errors-to-minibuf)) + (defun ghc-goto-next-error () (interactive) (let* ((here (point)) @@ -170,6 +187,11 @@ (pnts (mapcar 'overlay-start ovls2))) (if pnts (goto-char (apply 'min pnts))))) +(defun ghc-goto-and-display-next-error () + (interactive) + (ghc-goto-next-error) + (ghc-display-errors-to-minibuf)) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun ghc-check-insert-from-warning () diff --git a/elisp/ghc.el b/elisp/ghc.el index c29bc34..c3c1f6c 100644 --- a/elisp/ghc.el +++ b/elisp/ghc.el @@ -8,6 +8,14 @@ ;; ;; (autoload 'ghc-init "ghc" nil t) ;; (add-hook 'haskell-mode-hook (lambda () (ghc-init))) +;; +;; Or you wish to display error to minibuffer. +;; +;; (autoload 'ghc-init "ghc" nil t) +;; (setq ghc-display-error-to-minibuffer t) +;; (add-hook 'haskell-mode-hook (lambda () (ghc-init))) + +;; ;;; Code: @@ -56,6 +64,8 @@ (defvar ghc-shallower-key "\C-c<") (defvar ghc-deeper-key "\C-c>") +(defvar ghc-display-error-to-minibuffer nil) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Initializer @@ -74,8 +84,13 @@ (define-key haskell-mode-map ghc-info-key 'ghc-show-info) (define-key haskell-mode-map ghc-expand-key 'ghc-expand-th) (define-key haskell-mode-map ghc-import-key 'ghc-import-module) - (define-key haskell-mode-map ghc-previous-key 'ghc-goto-prev-error) - (define-key haskell-mode-map ghc-next-key 'ghc-goto-next-error) + (if ghc-display-error-to-minibuffer + (progn + (define-key haskell-mode-map ghc-previous-key 'ghc-goto-and-display-prev-error) + (define-key haskell-mode-map ghc-next-key 'ghc-goto-and-display-next-error)) + (progn + (define-key haskell-mode-map ghc-previous-key 'ghc-goto-prev-error) + (define-key haskell-mode-map ghc-next-key 'ghc-goto-next-error))) (define-key haskell-mode-map ghc-help-key 'ghc-display-errors) (define-key haskell-mode-map ghc-insert-key 'ghc-insert-template) (define-key haskell-mode-map ghc-sort-key 'ghc-sort-lines)