summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/tissue104
1 files changed, 58 insertions, 46 deletions
diff --git a/bin/tissue b/bin/tissue
index 94f0188..ff593c6 100755
--- a/bin/tissue
+++ b/bin/tissue
@@ -19,7 +19,8 @@
;;; You should have received a copy of the GNU General Public License
;;; along with tissue. If not, see <https://www.gnu.org/licenses/>.
-(import (rnrs io ports)
+(import (rnrs conditions)
+ (rnrs io ports)
(srfi srfi-1)
(srfi srfi-26)
(srfi srfi-37)
@@ -278,9 +279,14 @@ Start $EDITOR to edit issue #ISSUE-NUMBER.
(unless (getenv "EDITOR")
(error "Please set the EDITOR environment variable to your favorite editor. For example,
export EDITOR=emacsclient"))
- (invoke (getenv "EDITOR")
- (issue-file (list-ref (issues)
- (1- (string->number issue-number))))))))
+ (let ((issue-file (issue-file (list-ref (issues)
+ (1- (string->number issue-number))))))
+ ;; Files may be renamed or deleted, but not
+ ;; committed. Therefore, only read the file if it exists.
+ (if (file-exists? issue-file)
+ (invoke (getenv "EDITOR") issue-file)
+ (raise-exception (make-message-condition
+ (string-append "No such file or directory: " issue-file))))))))
(define tissue-show
(match-lambda*
@@ -291,48 +297,54 @@ Show the text of issue #ISSUE-NUMBER.
"
(command-line-program)))
((issue-number)
- (call-with-input-file (issue-file (list-ref (issues)
- (1- (string->number issue-number))))
- (lambda (port)
- (port-transduce
- (compose
- ;; Detect preformatted text blocks.
- (tfold (match-lambda*
- (((pre? . _) line)
- (cons (if (string-prefix? "```" line)
- (not pre?)
- pre?)
- line)))
- (cons #f #f))
- (tmap (lambda (pre?+line)
- (match pre?+line
- ((pre? . line)
- (cond
- ;; Print headlines in bold.
- ((string-prefix? "#" line)
- (display (bold line)))
- ;; Print lists in cyan.
- ((string-prefix? "*" line)
- (display (cyan line)))
- ;; Print links in cyan, but only the actual
- ;; link, and not the => prefix or the label.
- ((string-match "^(=>[ \t]*)([^ ]*)([^\n]*)" line)
- => (lambda (m)
- (display (match:substring m 1))
- (display (cyan (match:substring m 2)))
- (display (match:substring m 3))))
- ;; Print preformatted text backticks in
- ;; magenta.
- ((string-prefix? "```" line)
- (display (magenta line)))
- (else
- ;; If part of preformatted block, print in
- ;; magenta. Else, print in default color.
- (display (if pre? (magenta line) line))))))
- (newline))))
- (const #t)
- get-line-dos-or-unix
- port))))))
+ (let ((issue-file (issue-file (list-ref (issues)
+ (1- (string->number issue-number))))))
+ ;; Files may be renamed or deleted, but not
+ ;; committed. Therefore, only read the file if it exists.
+ (if (file-exists? issue-file)
+ (call-with-input-file (issue-file issue)
+ (lambda (port)
+ (port-transduce
+ (compose
+ ;; Detect preformatted text blocks.
+ (tfold (match-lambda*
+ (((pre? . _) line)
+ (cons (if (string-prefix? "```" line)
+ (not pre?)
+ pre?)
+ line)))
+ (cons #f #f))
+ (tmap (lambda (pre?+line)
+ (match pre?+line
+ ((pre? . line)
+ (cond
+ ;; Print headlines in bold.
+ ((string-prefix? "#" line)
+ (display (bold line)))
+ ;; Print lists in cyan.
+ ((string-prefix? "*" line)
+ (display (cyan line)))
+ ;; Print links in cyan, but only the actual
+ ;; link, and not the => prefix or the label.
+ ((string-match "^(=>[ \t]*)([^ ]*)([^\n]*)" line)
+ => (lambda (m)
+ (display (match:substring m 1))
+ (display (cyan (match:substring m 2)))
+ (display (match:substring m 3))))
+ ;; Print preformatted text backticks in
+ ;; magenta.
+ ((string-prefix? "```" line)
+ (display (magenta line)))
+ (else
+ ;; If part of preformatted block, print in
+ ;; magenta. Else, print in default color.
+ (display (if pre? (magenta line) line))))))
+ (newline))))
+ (const #t)
+ get-line-dos-or-unix
+ port)))
+ (raise-exception (make-message-condition
+ (string-append "No such file or directory: " issue-file))))))))
(define (print-usage)
(format #t "Usage: ~a COMMAND [OPTIONS] [ARGS]