From 221c5bb8a46f6e1befdb1c955bf0af4131313a48 Mon Sep 17 00:00:00 2001 From: m455 Date: Mon, 3 Jun 2019 22:01:34 -0400 Subject: [PATCH] cleaning up comments --- README.md | 36 ++++++++++++++++++------------------ util.rkt | 37 +++++++++++++++---------------------- 2 files changed, 33 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 317848b..3881f8f 100644 --- a/README.md +++ b/README.md @@ -8,24 +8,24 @@ A easy-to-use todo list program for people who live on the command line # Table of Contents -* [TL;DR](https://github.com/m455/rodo#tldr) -* [New things](https://github.com/m455/rodo#new-things) -* [Todos](https://github.com/m455/rodo#todos) -* [Platforms](https://github.com/m455/rodo#platforms) -* [Requirements](https://github.com/m455/rodo#requirements) - * [Downloading Racket](https://github.com/m455/rodo#downloading-racket) - * [To download Racket using apt](https://github.com/m455/rodo#to-download-racket-using-apt) - * [To download Racket using pacman](https://github.com/m455/rodo#to-download-racket-using-pacman) - * [Downloading the rodo source code](https://github.com/m455/rodo#downloading-the-rodo-source-code) - * [To download the rodo source code](https://github.com/m455/rodo#to-download-the-rodo-source-code) -* [Setup](https://github.com/m455/rodo#setup) - * [Setting up a $PATH](https://github.com/m455/rodo#setting-up-a-path) - * [To set up a $PATH](https://github.com/m455/rodo#to-set-up-a-path) - * [Adding rodo to your $PATH](https://github.com/m455/rodo#adding-rodo-to-your-path) - * [To add rodo to your $PATH](https://github.com/m455/rodo#to-add-rodo-to-your-path) -* [List of commands](https://github.com/m455/rodo#list-of-commands) -* [Usage examples](https://github.com/m455/rodo#usage-examples) -* [Configuration](https://github.com/m455/rodo#configuring-rodo) +- [TL;DR](#tldr) +- [New things](#new-things) +- [Todos](#todos) +- [Platforms](#platforms) +- [Requirements](#requirements) + - [Downloading Racket](#downloading-racket) + - [To download Racket using apt](#to-download-racket-using-apt) + - [To download Racket using pacman](#to-download-racket-using-pacman) + - [Downloading the rodo source code](#downloading-the-rodo-source-code) + - [To download the rodo source code](#to-download-the-rodo-source-code) +- [Setup](#setup) + - [Setting up a $PATH](#setting-up-a-path) + - [To set up a $PATH](#to-set-up-a-path) + - [Adding rodo to your $PATH](#adding-rodo-to-your-path) + - [To add rodo to your $PATH](#to-add-rodo-to-your-path) +- [List of commands](#list-of-commands) +- [Usage examples](#usage-examples) +- [Configuring `rodo`](#configuring-rodo) # TL;DR diff --git a/util.rkt b/util.rkt index a4baa32..765a43f 100644 --- a/util.rkt +++ b/util.rkt @@ -28,7 +28,6 @@ (define (display-hash-ref hash-list key) (display (hash-ref hash-list key))) -;; Just so I don't have to keep typing "#:mode...#:line-mode..." every time (define (file->string-list config:path-to-file-to-file) (let ([todo-list (file:file->lines config:path-to-file-to-file #:mode 'text @@ -38,13 +37,10 @@ (define (list-empty? lst) (list:empty? (file->string-list lst))) -;; Find out which item is being removed by scooping up -;; the number the user entered in the command line -;; arguments (define (get-removed-item lst args) ;; Subtract one from what the user chose, because they are - ;; are actually viewing the list numbers as human numbers - ;; so (actual-number +1) + ;; are actually viewing the list numbers as human numbers, + ;; so what they see is actual-number +1 (list-ref (file->string-list lst) (sub1 (string->number args)))) (define (surround-item-in-quotation-marks args) @@ -56,7 +52,7 @@ (define (prefix-item-with-number lst) (map string-append ;; Note: compose starts from the last element in it's - ;; list, as if it were nested, so that would be add1 here + ;; list, so that would be add1 here (map (compose prefix-item-with-period number->string add1) (list:range (length lst))) lst)) @@ -87,33 +83,30 @@ (check-for-program-directory) (check-for-program-file)) (if - ;; If file exists, see if it's empty, if so - ;; tell the user (list-empty? config:path-to-file) (display-hash-ref messages:messages 'empty-todo-list) - ;; If file isn't empty, display a pretty list (display-prettified-program-file))] - ;; If file doesn't exist, tell the user [else (display-hash-ref messages:messages 'file-not-found) (display-hash-ref messages:messages 'try-init)])) (define (write-item-to-program-file args) - ;; Add item to end of list and write to file + ;; Add an item to the end of a list and write to a file (let ([new-list (append-item-to-end args config:path-to-file)]) (file:display-to-file - (string:string-join new-list "\n") - config:path-to-file + (string:string-join new-list "\n") config:path-to-file #:mode 'text #:exists 'truncate) + ;; After writing to the file, tell the user what was written (display-item-added args))) (define (add-item-to-list args) - (if (and - (check-for-program-directory) - (check-for-program-file)) - ;; The cdr here prevents the command line argument "add" from being added to the file + (if (and (check-for-program-directory) + (check-for-program-file)) + ;; The cdr here prevents the first command line argument ("add") + ;; from being added to the file (write-item-to-program-file (string:string-join (cdr (vector->list args)))) + ;; Else (begin (display-hash-ref messages:messages 'file-not-found) (display-hash-ref messages:messages 'try-init)))) @@ -131,11 +124,11 @@ (define (remove-item-from-list args) (cond [(list-empty? config:path-to-file) (display-hash-ref messages:messages 'empty-todo-list)] - [(and - (check-for-program-directory) - (check-for-program-file)) + [(and (check-for-program-directory) + (check-for-program-file)) (remove-item-from-program-file (vector-ref args 1))] - [(and (not (check-for-program-directory)) (not (check-for-program-file))) + [(and (not (check-for-program-directory)) + (not (check-for-program-file))) (begin (display-hash-ref messages:messages 'file-not-found) (display-hash-ref messages:messages 'try-init))]))