diff --git a/README.md b/README.md index 7375fe4..4de25ec 100644 --- a/README.md +++ b/README.md @@ -40,5 +40,7 @@ implementation status of planned features: - [x] s - ce-command-reg-replace - [ ] t - ce-command-copy - [x] w - ce-command-write +- [x] x - ce-command-chop +- [x] X - ce-command-chop-beg - [x] 0 - ce-command-number diff --git a/ce.cl b/ce.cl index 606da45..e0dfc23 100644 --- a/ce.cl +++ b/ce.cl @@ -30,6 +30,8 @@ (#\s . ce-command-reg-replace) (#\t . ce-command-copy) (#\w . ce-command-write) + (#\x . ce-command-chop) + (#\X . ce-command-chop-beg) (#\0 . ce-command-number) (#\1 . ce-command-number) (#\2 . ce-command-number) @@ -431,6 +433,26 @@ specific command. the recognized commands are as follows: :if-does-not-exist :create) (format out "~{~a~%~}" buffer)))) +(defmacro ce-build-chop (fin) + "helper for chop and chop-beg" + `(progn + (ce-reset-input) + (let ((inp (parse-integer (string-or (read-line) "1")))) + (ce-apply-region (lambda (x) + (let ((llen (length x))) + (if (< llen inp) + x ,fin))))))) + +(defun ce-command-chop (&optional c) + "chop off argument characters from end of each line in region" + (declare (ignore c)) + (ce-build-chop (subseq x 0 (- llen inp)))) + +(defun ce-command-chop-beg (&optional c) + "chop off argument characters from start of each line in region" + (declare (ignore c)) + (ce-build-chop (subseq x inp))) + (defun ce-command-number (c) "input a number" (if (or (= 0 newpoint) (= 2 newpoint))