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-values (((in out _) (process cmd))22 ((lines) (editor-get-lines editor range)))23 (write-string (lines->string lines) out)24 (close-output-port out)25 (let ((recv (port->lines in)))26 (close-input-port in)27 (exec-delete editor range)28 (exec-insert editor (car range) (car recv)))))2930(define-file-cmd (pipe exec-pipe (make-range))31 (parse-cmd-char #\|)32 (parse-token (char-set-complement (char-set #\newline))))3334;;;;35;; The ctags command.36;;;;3738(define (exec-tag editor name)39 (let* ((cmd (string-append "!" "readtags -n - " name))40 (out (car (read-from cmd))))41 (if (null? out)42 (editor-error editor (string-append "tag not found: " name))43 (let* ((tags (parse-tags out))44 (tag (select-tag tags)))45 (unless (equal? (tag-file tag) (text-editor-filename editor))46 (%exec-edit editor (tag-file tag)))47 (let* ((addrlst (parse parse-addrs (tag-regex tag)))48 (lpair (addrlst->lpair editor addrlst)))49 (exec-print editor lpair))))))5051(define-file-cmd (tag exec-tag)52 (parse-cmd-char #\T)53 (parse-token char-set:graphic))5455;;;;56;; The FZF command.57;;;;5859(define (exec-fzf editor)60 (let* ((cmd (string-append "!" "fzf"))61 (out (read-from cmd)))62 (unless (null? (car out))63 (%exec-edit editor (caar out)))))6465(define-file-cmd (fzf exec-fzf)66 (parse-cmd-char #\F))6768;;;;69;; The scroll command.70;;;;7172(define (exec-scroll editor start %amount)73 (let* ((amount (if %amount74 %amount75 (max 0 (- (terminal-rows) 2)))) ;; -2 for cur/nxt prompt76 (end (addr->line editor (make-addr77 (cons 'nth-line78 (min79 (editor-lines editor)80 (+ start amount)))))))81 (exec-print editor (cons start end))))8283(define-file-cmd (scroll exec-scroll (make-addr '(current-line) '(+1)))84 (parse-cmd-char #\z)85 (parse-optional parse-digits))8687;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8889(cond-expand90 ((or chicken-script compiling)91 (edward-main))92 (else #t))