Skip to content

Commit

Permalink
Simplify idris-warning-overlay by
Browse files Browse the repository at this point in the history
 - inline idris-get-line-region and remove cl-multiple-value-bind
 - remove extra goto-char
 - flatten body
  • Loading branch information
keram committed Dec 20, 2022
1 parent a47903d commit 0379683
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions idris-warnings.el
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,12 @@
(setq idris-warnings '())
(delq (current-buffer) idris-warnings-buffers))

(defun idris-get-line-region (line)
(goto-char (point-min))
(cl-values
(line-beginning-position line)
(line-end-position line)))

(defun idris-warning-overlay-p (overlay)
(overlay-get overlay 'idris-warning))

(defun idris-warning-overlay-at-point ()
"Return the overlay for a note starting at point, otherwise nil."
(cl-find (point) (cl-remove-if-not 'idris-warning-overlay-p (overlays-at (point)))
(defun idris-warning-overlay-at-point (point)
"Return the overlay for a note starting at POINT, otherwise nil."
(cl-find point (cl-remove-if-not 'idris-warning-overlay-p (overlays-at point))
:key 'overlay-start))

(defun idris-warning-overlay (warning)
Expand Down Expand Up @@ -103,23 +97,21 @@ is mostly the same as (startline startcolumn)"
(save-restriction
(widen) ;; Show errors at the proper location in narrowed buffers
(goto-char (point-min))
(cl-multiple-value-bind (startp endp) (idris-get-line-region startline)
(goto-char startp)
(let ((start (+ startp startcol))
(end (if (and (= startline endline) (= startcol endcol))
;; this is a hack to have warnings reported which point to empty lines
(if (= startp endp)
(progn (insert " ")
(1+ endp))
endp)
(+ (save-excursion
(goto-char (point-min))
(line-beginning-position endline))
endcol)))
(overlay (idris-warning-overlay-at-point)))
(if overlay
(idris-warning-merge-overlays overlay message)
(idris-warning-create-overlay start end message)))))))))))
(let* ((startp (line-beginning-position startline))
(endp (line-end-position startline))
(start (+ startp startcol))
(end (if (and (= startline endline) (= startcol endcol))
;; this is a hack to have warnings reported which point to empty lines
(if (= startp endp)
(progn (goto-char startp)
(insert " ")
(1+ endp))
endp)
(+ (line-beginning-position endline) endcol)))
(overlay (idris-warning-overlay-at-point startp)))
(if overlay
(idris-warning-merge-overlays overlay message)
(idris-warning-create-overlay start end message))))))))))

(defun idris-warning-merge-overlays (overlay message)
(overlay-put overlay 'help-echo
Expand Down

0 comments on commit 0379683

Please sign in to comment.