1(import (scheme base)2 (srfi 1)3 (srfi 14)4 (chicken process)56 (edward cli)7 (edward parse)8 (edward util)9 (edward ed cmd)10 (edward ed addr)11 (edward ed posix)12 (edward ed editor))1314(include "util.scm")1516;;;;17;; The pipe command.18;;;;1920(define (exec-pipe editor range cmd)21 (let* ((proc (process cmd))22 (output (process-output-port proc))23 (lines (editor-get-lines editor range)))24 (write-string (lines->string lines) output)25 (close-output-port output)26 (let* ((input (process-input-port proc))27 (recv (port->lines input)))28 (close-input-port input)29 (exec-delete editor range)30 (exec-insert editor (car range) (car recv)))))3132(define-file-cmd (pipe exec-pipe (make-range))33 (parse-cmd-char #\|)34 (parse-token (char-set-complement (char-set #\newline))))3536;;;;37;; The ctags command.38;;;;3940(define (exec-tag editor name)41 (let* ((cmd (string-append "!" "readtags -n - " name))42 (out (car (read-from cmd))))43 (if (null? out)44 (editor-error editor (string-append "tag not found: " name))45 (let* ((tags (parse-tags out))46 (tag (select-tag tags)))47 (unless (equal? (tag-file tag) (text-editor-filename editor))48 (%exec-edit editor (tag-file tag)))49 (let* ((addrlst (parse parse-addrs (tag-regex tag)))50 (lpair (addrlst->lpair editor addrlst)))51 (exec-print editor lpair))))))5253(define-file-cmd (tag exec-tag)54 (parse-cmd-char #\T)55 (parse-token char-set:graphic))5657;;;;58;; The FZF command.59;;;;6061(define (exec-fzf editor)62 (let* ((cmd (string-append "!" "fzf"))63 (out (read-from cmd)))64 (unless (null? (car out))65 (%exec-edit editor (caar out)))))6667(define-file-cmd (fzf exec-fzf)68 (parse-cmd-char #\F))6970;;;;71;; The scroll command.72;;;;7374(define (exec-scroll editor start %amount)75 (let* ((amount (if %amount76 %amount77 (max 0 (- (terminal-rows) 2)))) ;; -2 for cur/nxt prompt78 (end (addr->line editor (make-addr79 (cons 'nth-line80 (min81 (editor-lines editor)82 (+ start amount)))))))83 (exec-print editor (cons start end))))8485(define-file-cmd (scroll exec-scroll (make-addr '(current-line) '(+1)))86 (parse-cmd-char #\z)87 (parse-optional parse-digits))8889;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;9091(cond-expand92 ((or chicken-script compiling)93 (edward-main))94 (else #t))