aemoncannon/ensime — Issue #211: Wrong :beg and :end for source files with CRLF line endings
Author: tstgruby
Created: 2011-12-06 14:25:55+00:00
State: open

IProblem apparently reports the begin and and ending of a problem in regard to the byte (character) offset in *binary* mode.

But Emacs basically strips the CR characters from the file when displaying it in a buffer, so the start and end pointers are ``line-1`` characters off and the wrong region gets highlighted.

Looking into it, I see that you've already tried to fix the position in ensime-make-overlay-at by recalculating beg and end using (the erroneous) positions... Alas, this doesn't work.

Why not pass the ``line`` information from ensime-make-note-overlays to ensime-make-overlay-at and only make an overlay spanning the whole line if beg and end are not valid positions (non-integers)?

````lisp
(defun ensime-make-overlay-at (file line b e msg face)
"Create an overlay highlighting the given line in
any buffer visiting the given file."
(let ((beg b)
(end e))
(assert (or (integerp line)
(and (integerp beg) (integerp end))))
(when-let (buf (find-buffer-visiting file))
(with-current-buffer buf
(if (and (integerp beg) (integerp end))
;; If DOS eol's, fix the positioning
;; Note: this is impossible without the line argument.
(when (and (integerp line)
(eq 1 (coding-system-eol-type
(buffer-local-value
'buffer-file-coding-system buf))))
(setq beg (- beg (1- line)))
(setq end (- end (1- line))))

;; If line provided, use line to define region
(save-excursion
(goto-line line)
(setq beg (point-at-bol))
(setq end (point-at-eol)))))

(ensime-make-overlay beg end msg face nil buf))
))

(defun ensime-make-note-overlays (notes)
(dolist (note notes)
(destructuring-bind
(&key severity msg beg end line col file &allow-other-keys) note

;; No empty note overlays!
(when (eq beg end)
(setq beg (- beg 1)))

(let ((lang
(cond
((ensime-java-file-p file) 'java)
((ensime-scala-file-p file) 'scala)
(t 'scala)))
(face
(cond
((equal severity 'error)
'ensime-errline-highlight)
(t
'ensime-warnline-highlight))))

(when-let (ov (ensime-make-overlay-at
file line
(+ beg ensime-ch-fix)
(+ end ensime-ch-fix)
msg face))
(overlay-put ov 'lang lang)
(push ov ensime-note-overlays))

))))
````