Add indent and unindent commands

This commit is contained in:
John Lorentzson 2025-07-31 12:03:48 +02:00
parent 13715859ef
commit 4415bb3d55

View file

@ -812,6 +812,35 @@ Additionally ensures correct line numbers on the way, as a bonus."
(read-char *eio*) (read-char *eio*)
(com-help)) (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) (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) (#\Del com-backward-delete)
(:help com-help) (:help com-help)
((:m . #\o) com-f1-help) ((:m . #\o) com-f1-help)
((:c . #\i) com-indent-line)
((:c . #\u) com-unindent-line)
((:c . #\d) com-forward-delete) ((:c . #\d) com-forward-delete)
((:c . #\k) com-kill-line) ((:c . #\k) com-kill-line)
((:c . #\j) com-newline) ((:c . #\j) com-newline)