Skip to content

Commit

Permalink
Merge pull request #1684 from SequentialDesign/add-line-number-format…
Browse files Browse the repository at this point in the history
…-and-current-line-value-editor-vatriables-to-line-numbers

add two editor variables to line-numbers, line-number-format and current-line-value
  • Loading branch information
cxxxr authored Dec 6, 2024
2 parents 349be92 + 4cf730a commit 8b822cd
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/ext/line-numbers.lisp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(defpackage :lem/line-numbers
(:use :cl :lem)
(:export :*relative-line*
:line-number-format
:custom-current-line
:line-numbers-attribute
:active-line-number-attribute
:line-numbers
Expand All @@ -15,13 +17,21 @@
(defvar *previous-relative-line* nil)

(defvar *initialized* nil)
(defvar *line-number-format* nil)

(define-editor-variable line-number-format "~6D "
"Set to desired format, for example, \"~2D \" for a
two-character line-number column and a margin of one space.")

(define-editor-variable custom-current-line nil
"Set to desired current-line value when relative line
numbers are active, for example, \"->\". NIL will make
the absolute value of the current line display.")

(define-attribute line-numbers-attribute
(t :foreground :base07 :background :base01))
(t :foreground :base07 :background :base01))

(define-attribute active-line-number-attribute
(t :foreground :base07 :background :base01))
(t :foreground :base07 :background :base01))

(define-editor-variable line-numbers nil ""
(lambda (value)
Expand All @@ -46,16 +56,19 @@ With a positive universal argument, use relative line numbers. Also obey the glo

(defun compute-line (buffer point)
(if *relative-line*
(let* ((cursor-line (line-number-at-point (buffer-point buffer)))
(line (line-number-at-point point)))
(let ((cursor-line (line-number-at-point (buffer-point buffer)))
(line (line-number-at-point point))
(custom-line (variable-value 'custom-current-line :default buffer)))
(if (= cursor-line line)
line
(if custom-line
custom-line
line)
(abs (- cursor-line line))))
(line-number-at-point point)))

(defmethod lem-core:compute-left-display-area-content ((mode line-numbers-mode) buffer point)
(when (buffer-filename (point-buffer point))
(let* ((string (format nil "~6D " (compute-line buffer point)))
(let* ((string (format nil (variable-value 'line-number-format :default buffer) (compute-line buffer point)))
(attribute (if (eq (compute-line buffer point)
(compute-line buffer (buffer-point buffer)))
`((0 ,(length string) active-line-number-attribute))
Expand Down

0 comments on commit 8b822cd

Please sign in to comment.