Skip to content

Instantly share code, notes, and snippets.

@david-christiansen
Created November 4, 2014 02:12
Show Gist options
  • Save david-christiansen/a463bdb0086dab60c72b to your computer and use it in GitHub Desktop.
Save david-christiansen/a463bdb0086dab60c72b to your computer and use it in GitHub Desktop.
ghc-mod error annotations as Helm data source
(defun helm-ghc-errors-in-buffer ()
(with-current-buffer helm-current-buffer
(remove-if-not #'(lambda (o) (overlay-get o 'ghc-check))
(overlays-in (point-min) (point-max)))))
(defun helm-ghc-describe-overlay (o)
(cl-flet ((abbreviate (str)
(if (> (length str) fill-column)
(concat (substring str 0 (- fill-column 3)) "...")
str)))
(with-current-buffer (overlay-buffer o)
(let* ((start (overlay-start o))
(end (overlay-end o))
(msg (overlay-get o 'ghc-msg)))
(concat
(propertize
(format "%s (%s,%s)-(%s,%s):\n"
(buffer-name (overlay-buffer o))
(line-number-at-pos start)
(save-excursion (goto-char start) (current-column))
(line-number-at-pos end)
(save-excursion (goto-char end) (current-column)))
'face 'italic)
(format "%s\n\t%s"
(abbreviate (buffer-substring start end))
(if msg (abbreviate msg) "")))))))
(defun helm-ghc-candidates ()
(with-current-buffer helm-current-buffer
(mapcar (lambda (o) (cons (helm-ghc-describe-overlay o) o))
(helm-ghc-errors-in-buffer))))
(defun helm-ghc-goto-overlay (o)
(with-current-buffer (overlay-buffer o)
(goto-char (overlay-start o))
(ghc-display-errors)))
(defvar helm-ghc-errors-source
'((name . "GHC notes")
(candidates . helm-ghc-candidates)
(action . (("Go to error" . helm-ghc-goto-overlay)))
(multiline)))
(defun helm-ghc-errors ()
(interactive)
(helm :sources helm-ghc-errors-source))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment