From 4415bb3d5535986eeafda901a6a41154ce2f95b1 Mon Sep 17 00:00:00 2001 From: John Lorentzson Date: Thu, 31 Jul 2025 12:03:48 +0200 Subject: [PATCH] Add indent and unindent commands --- editor/editor.lisp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/editor/editor.lisp b/editor/editor.lisp index a03f75a..30fc036 100644 --- a/editor/editor.lisp +++ b/editor/editor.lisp @@ -812,6 +812,35 @@ Additionally ensures correct line numbers on the way, as a bonus." (read-char *eio*) (com-help)) +(defparameter *indent-width* 4) + +(defun com-indent-line () + ;; TODO: Proper logical indentation + (with-editor-accessors *editor* (:current-line line + :current-column column) + (cond ((< (+ (line-length line) *indent-width*) +screen-width+) + (loop :repeat *indent-width* + :do (insert-character-into-line line 0 #\Space + :try-redisplay-p nil)) + (incf column *indent-width*) + (redisplay-line line)) + (t + (feep))))) + +(defun com-unindent-line () + ;; TODO: Remove when auto-indenting works + (with-editor-accessors *editor* (:current-line line + :current-column column) + (cond ((and (>= (line-length line) *indent-width*) + (>= (- (line-length line) *indent-width*) 0) + (string= (make-string *indent-width* :initial-element #\Space) + (subseq (line-content line) 0 *indent-width*))) + (loop :repeat *indent-width* + :do (delete-character-in-line line 0)) + (redisplay-line line) + (decf column 4)) + (t + (feep))))) (defun compile-fail-prompt (text line col) @@ -930,6 +959,8 @@ Additionally ensures correct line numbers on the way, as a bonus." (#\Del com-backward-delete) (:help com-help) ((:m . #\o) com-f1-help) + ((:c . #\i) com-indent-line) + ((:c . #\u) com-unindent-line) ((:c . #\d) com-forward-delete) ((:c . #\k) com-kill-line) ((:c . #\j) com-newline)