Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add two editor variables to line-numbers, line-number-format and current-line-value #1684

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 "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good.

"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
Loading