From 16bcd94ceb096aa7b8f50e1bbd97ff83d5e850fd Mon Sep 17 00:00:00 2001 From: Daniel Alejandro Tapia Date: Thu, 5 Dec 2024 01:02:48 -0500 Subject: [PATCH 1/6] add two editor variables to line-numbers, line-number-format and current-line-value with these editor variables, the user can customize line-format and current-line value. for example : ``` (setf (variable-value 'line-number-format :global) "~2D ") (setf (variable-value 'relative-line-numbers-current-line-value :global) 0) ``` this will make the line numbers narrow and make the current line show up as '0' in the line-number column --- src/ext/line-numbers.lisp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/ext/line-numbers.lisp b/src/ext/line-numbers.lisp index ed011fc9b..9bf5e277f 100644 --- a/src/ext/line-numbers.lisp +++ b/src/ext/line-numbers.lisp @@ -1,6 +1,8 @@ (defpackage :lem/line-numbers (:use :cl :lem) (:export :*relative-line* + :line-number-format + :relative-line-numbers-current-line-value :line-numbers-attribute :active-line-number-attribute :line-numbers @@ -15,7 +17,15 @@ (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.") + +(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-attribute line-numbers-attribute (t :foreground :base07 :background :base01)) @@ -46,16 +56,16 @@ 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))) (if (= cursor-line line) - line + (eval (variable-value'relative-line-numbers-current-line-value :default buffer)) (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)) From 4aa462a0244bea111b76cde757bfdfc19f1c25c3 Mon Sep 17 00:00:00 2001 From: Daniel Alejandro Tapia Date: Thu, 5 Dec 2024 14:06:25 -0500 Subject: [PATCH 2/6] 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))) From 02a3963bb44eb398256859c3cb784fdb94165ece Mon Sep 17 00:00:00 2001 From: Daniel Alejandro Tapia Date: Thu, 5 Dec 2024 14:16:58 -0500 Subject: [PATCH 3/6] 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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ext/line-numbers.lisp b/src/ext/line-numbers.lisp index 7f5777942..b5191e707 100644 --- a/src/ext/line-numbers.lisp +++ b/src/ext/line-numbers.lisp @@ -24,7 +24,8 @@ two-character line-number column.") (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 \" ->\")).") + "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)) From 048595598ba08f70ab68488b813aef1b75cfb271 Mon Sep 17 00:00:00 2001 From: Daniel Alejandro Tapia Date: Thu, 5 Dec 2024 20:12:49 -0500 Subject: [PATCH 4/6] add two editor variables to line-numbers add two editor variables to line-numbers, `line-format` and `custom-current-line`. they allow the user to set the line format and choose a custom current line if they want. for example : `(setf (variable-value 'line-number-format :global) "~2D ")` for a narrow line-number column. and `(setf (variable-value 'custom-current-line :global) "->")` for a current-line indicator of `->` --- src/ext/line-numbers.lisp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/ext/line-numbers.lisp b/src/ext/line-numbers.lisp index b5191e707..40998fdb1 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 - :current-line-display-function + :custom-current-line :line-numbers-attribute :active-line-number-attribute :line-numbers @@ -22,10 +22,10 @@ "Set to desired format, for example, \"~2D \" for a two-character line-number column.") -(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-editor-variable custom-current-line nil + "Set to desired current-line value when relative line +numbers are active, for example, \"->\". NIL will make the +the absolute value of the current line display.") (define-attribute line-numbers-attribute (t :foreground :base07 :background :base01)) @@ -57,10 +57,11 @@ 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)) - (current-line-display (funcall (variable-value 'current-line-display-function :default buffer)))) + (line (line-number-at-point point))) (if (= cursor-line line) - current-line-display + (if (variable-value 'custom-current-line) + (variable-value 'custom-current-line :default buffer) + line) (abs (- cursor-line line)))) (line-number-at-point point))) From 4d5417e0017118ceb4b9bd39a9834d7534eba908 Mon Sep 17 00:00:00 2001 From: Daniel Alejandro Tapia Date: Thu, 5 Dec 2024 20:24:49 -0500 Subject: [PATCH 5/6] add two editor variables to line-numbers add two editor variables to line-numbers, `line-format` and `custom-current-line`. they allow the user to set the line format and choose a custom current line if they want. for example : `(setf (variable-value 'line-number-format :global) "~2D ")` for a narrow line-number column. and `(setf (variable-value 'custom-current-line :global) "->")` for a current-line indicator of `->` --- src/ext/line-numbers.lisp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ext/line-numbers.lisp b/src/ext/line-numbers.lisp index 40998fdb1..60c9da3e8 100644 --- a/src/ext/line-numbers.lisp +++ b/src/ext/line-numbers.lisp @@ -20,11 +20,11 @@ (define-editor-variable line-number-format "~6D " "Set to desired format, for example, \"~2D \" for a -two-character line-number column.") +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 +numbers are active, for example, \"->\". NIL will make the absolute value of the current line display.") (define-attribute line-numbers-attribute From 4cf730abd7d5ca7b96de984393845320e1ddacda Mon Sep 17 00:00:00 2001 From: Daniel Alejandro Tapia Date: Thu, 5 Dec 2024 21:16:53 -0500 Subject: [PATCH 6/6] add two editor variables to line-numbers, line-number-formatand current-line-value add two editor variables to line-numbers, `line-format` and `custom-current-line`. they allow the user to set the line format and choose a custom current line if they want. for example : `(setf (variable-value 'line-number-format :global) "~2D ")` for a narrow line-number column. and `(setf (variable-value 'custom-current-line :global) "->")` for a current-line indicator of `->` --- src/ext/line-numbers.lisp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ext/line-numbers.lisp b/src/ext/line-numbers.lisp index 60c9da3e8..f0c25f905 100644 --- a/src/ext/line-numbers.lisp +++ b/src/ext/line-numbers.lisp @@ -57,10 +57,11 @@ 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)) + (custom-line (variable-value 'custom-current-line :default buffer))) (if (= cursor-line line) - (if (variable-value 'custom-current-line) - (variable-value 'custom-current-line :default buffer) + (if custom-line + custom-line line) (abs (- cursor-line line)))) (line-number-at-point point)))