Skip to content

Commit

Permalink
Fix incorrect attribute applied when using relative line numbers.
Browse files Browse the repository at this point in the history
Previously, if someone have enabled relative line numbers, and have
the attribute of active line number (the line number of the line where
the point is) different than that of normal line number, they will see
something like this:

```
 1 ...
*2*... | <- this is where the point is, *2* means 2 is highlighted.
 1 ...
*2*... this is not where the point is, but the line number is still highlighted.
 3 ...
```
  • Loading branch information
funk443 committed Jan 7, 2025
1 parent 262d829 commit 7b02b2f
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/ext/line-numbers.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ With a positive universal argument, use relative line numbers. Also obey the glo
(line (line-number-at-point point))
(custom-line (variable-value 'custom-current-line :default buffer)))
(if (= cursor-line line)
(or custom-line line)
(abs (- cursor-line line))))
(line-number-at-point point)))
(values (or custom-line line) t)
(values (abs (- cursor-line line)) nil)))
(let ((line (line-number-at-point point)))
(values line (= (line-number-at-point (buffer-point buffer)) line)))))

(defun get-buffer-num-format (buffer)
(let* ((last-line (lem/buffer/internal::point-linum (buffer-end-point buffer)))
Expand All @@ -72,16 +73,15 @@ With a positive universal argument, use relative line numbers. Also obey the glo

(defmethod lem-core:compute-left-display-area-content ((mode line-numbers-mode) buffer point)
(when (buffer-filename (point-buffer point))
(let* ((computed-line (compute-line buffer point))
(num-format (or (variable-value 'line-number-format :default buffer)
(get-buffer-num-format buffer)))
(string (format nil num-format computed-line))
(attribute (if (eq computed-line
(compute-line buffer (buffer-point buffer)))
`((0 ,(length string) active-line-number-attribute))
`((0 ,(length string) line-numbers-attribute)))))
(lem/buffer/line:make-content :string string
:attributes attribute))))
(multiple-value-bind (computed-line active-line-p) (compute-line buffer point)
(let* ((num-format (or (variable-value 'line-number-format :default buffer)
(get-buffer-num-format buffer)))
(string (format nil num-format computed-line))
(attribute (if active-line-p
`((0 ,(length string) active-line-number-attribute))
`((0 ,(length string) line-numbers-attribute)))))
(lem/buffer/line:make-content :string string
:attributes attribute)))))

(defmethod lem-core:compute-wrap-left-area-content (left-side-width left-side-characters)
(if (< 0 left-side-width)
Expand Down

0 comments on commit 7b02b2f

Please sign in to comment.