Skip to content

Commit

Permalink
Merge pull request #1732 from Encryptoid/line-number-mode-fixes
Browse files Browse the repository at this point in the history
Fix: [line-number-mode] - Wrapped line attributes & Uniform number width
  • Loading branch information
cxxxr authored Jan 4, 2025
2 parents 798d1fd + 9d0f174 commit c3ad998
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/display/base.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
(defgeneric compute-left-display-area-content (mode buffer point)
(:method (mode buffer point) nil))

(defgeneric compute-wrap-left-area-content (left-side-width left-side-characters)
(:method (left-side-width left-side-characters)
nil))

(defvar *in-redraw-display* nil
"T if the screen is currently being redrawn by `redraw-display`.
Used to prevent recursive `redraw-display` calls.")
Expand Down
11 changes: 3 additions & 8 deletions src/display/physical-line.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,14 @@
(objects-per-physical-line
(separate-objects-by-width (create-drawing-objects logical-line)
(- (window-view-width window) left-side-width)
(window-buffer window)))
(empty-left-side-object (if (< 0 left-side-width)
(list (make-object-with-type
(make-string left-side-characters :initial-element #\space)
nil
(char-type #\space)))
nil)))
(window-buffer window))))
(loop :for objects :in objects-per-physical-line
:for all-objects := (append left-side-objects objects)
:for height := (max-height-of-objects all-objects)
:do (render-line-with-caching window 0 y all-objects height)
(incf y height)
(setq left-side-objects (copy-list empty-left-side-object))
(setq left-side-objects (copy-list (compute-wrap-left-area-content
left-side-width left-side-characters)))
:sum height)))

(defun find-cursor-object (objects)
Expand Down
22 changes: 19 additions & 3 deletions src/ext/line-numbers.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

(defvar *initialized* nil)

(define-editor-variable line-number-format "~6D "
(define-editor-variable line-number-format nil
"Set to desired format, for example, \"~2D \" for a
two-character line-number column and a margin of one space.")
two-character line-number column and a margin of one space.
The default NIL will use a number format matching the current buffer length.")

(define-editor-variable custom-current-line nil
"Set to desired current-line value when relative line
Expand Down Expand Up @@ -64,13 +65,28 @@ With a positive universal argument, use relative line numbers. Also obey the glo
(abs (- cursor-line line))))
(line-number-at-point point)))

(defun get-buffer-num-format (buffer)
(let* ((last-line (lem/buffer/internal::point-linum (buffer-end-point buffer)))
(digit-count (1+ (floor (log (abs last-line) 10)))))
(format nil " ~~~aD " digit-count)))

(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))
(string (format nil (variable-value 'line-number-format :default buffer) computed-line))
(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))))

(defmethod lem-core:compute-wrap-left-area-content (left-side-width left-side-characters)
(if (< 0 left-side-width)
(list (lem-core::make-object-with-type
(make-string left-side-characters :initial-element #\space)
'line-numbers-attribute
(lem-core::char-type #\space)))
nil))
3 changes: 2 additions & 1 deletion src/internal-packages.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,8 @@
:wrap-line-attribute
:inactive-window-background-color
:redraw-buffer
:compute-left-display-area-content)
:compute-left-display-area-content
:compute-wrap-left-area-content)
;; interface.lisp
(:export
:with-implementation
Expand Down

0 comments on commit c3ad998

Please sign in to comment.