From 4aa462a0244bea111b76cde757bfdfc19f1c25c3 Mon Sep 17 00:00:00 2001 From: Daniel Alejandro Tapia Date: Thu, 5 Dec 2024 14:06:25 -0500 Subject: [PATCH] add two editor variables to line-numbers this patch adds two editor variables to line-numbers, `line-format` and `current-line-display-function`. this allows the user to change the width/format of the line numbers and to set the current-line display in relative numbers. for example : ``` (setf (variable-value 'line-number-format :global) "~2D ") (setf (variable-value 'current-line-display-function :global) (lambda () 0)) ``` now the line-numbers will be narrower and the current-line will always be 0. --- src/ext/line-numbers.lisp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ext/line-numbers.lisp b/src/ext/line-numbers.lisp index 9bf5e277f..7f5777942 100644 --- a/src/ext/line-numbers.lisp +++ b/src/ext/line-numbers.lisp @@ -2,7 +2,7 @@ (:use :cl :lem) (:export :*relative-line* :line-number-format - :relative-line-numbers-current-line-value + :current-line-display-function :line-numbers-attribute :active-line-number-attribute :line-numbers @@ -22,16 +22,15 @@ "Set to desired format, for example, \"~2D \" for a two-character line-number column.") -(define-editor-variable relative-line-numbers-current-line-value - '(line-number-at-point (current-point)) - "Set to desired current-line value when relative line numbers -are active, for example, 0 or \"->\".") +(define-editor-variable current-line-display-function + (lambda () (line-number-at-point (current-point))) + "Set to desired current-line display when relative line numbers are active, for example, (lambda () 0) or (lambda () (string \" ->\")).") (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) @@ -57,9 +56,10 @@ 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))) + (line (line-number-at-point point)) + (current-line-display (funcall (variable-value 'current-line-display-function :default buffer)))) (if (= cursor-line line) - (eval (variable-value'relative-line-numbers-current-line-value :default buffer)) + current-line-display (abs (- cursor-line line)))) (line-number-at-point point)))