Skip to content

Commit

Permalink
Tidying main.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
WGUNDERWOOD committed May 18, 2024
1 parent 81502b1 commit f53e4be
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ E = m c^2
</tr>
</table>

-Very good run-time performance
-Extremely fast run-time performance
- 🔧 No configuration necessary
- 📟 Command-line interface
- 📜 Handles LaTeX file types `.tex`, `.bib`, `.cls`, and `.sty`
Expand Down
2 changes: 2 additions & 0 deletions notes.org
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
** Ignore source lines
** Documentation
** Find todos
** \item should be on a new line
* Bugs
** Handle list items and comments properly
** Handle verbatim and ignores better
** Only print ignore warnings once
** Off by one in linums?
* Logging
** Store all logs on the fly in a vector
** Print them all at the end in an intelligent way
Expand Down
13 changes: 12 additions & 1 deletion src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::logging::*;
use crate::subs::*;
use crate::wrap::*;
use crate::Cli;
use log::Level::Error;
use log::Level::{Error, Info};

const MAX_PASS: usize = 10;

Expand Down Expand Up @@ -51,6 +51,17 @@ pub fn format_file(
args: &Cli,
logs: &mut Vec<Log>,
) -> String {
if args.verbose {
record_log(
logs,
Info,
None,
filename.to_string(),
None,
None,
"Begin indenting.".to_string(),
);
}
let mut new_file = remove_extra_newlines(file);
new_file = begin_end_environments_new_line(&new_file);
new_file = remove_tabs(&new_file);
Expand Down
4 changes: 2 additions & 2 deletions src/indent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ pub fn apply_indent(
let mut verbatim_count = 0;

for (linum, line) in file.lines().enumerate() {
if RE_VERBATIM_BEGIN.is_match(line) {
verbatim_count += 1;
if RE_VERBATIM_END.is_match(line) {
verbatim_count -= 1;
}
ignore = get_ignore(line, linum, ignore, filename, logs, pass, true);
if verbatim_count == 0 && !is_ignored(&ignore) {
Expand Down
14 changes: 1 addition & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Parser;
use log::Level::{Error, Info};
use log::Level::Error;
#[allow(unused_imports)]
use rstest::rstest;
#[allow(unused_imports)]
Expand Down Expand Up @@ -38,18 +38,6 @@ fn main() {

for filename in &args.filenames {
let mut logs: Vec<Log> = vec![];
if args.verbose {
record_log(
&mut logs,
Info,
None,
filename.to_string(),
None,
None,
"Begin indenting.".to_string(),
);
}

let extension_valid = check_extension_valid(filename);
if extension_valid {
let file = fs::read_to_string(filename).unwrap();
Expand Down
8 changes: 7 additions & 1 deletion src/regexes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
use lazy_static::lazy_static;
use regex::Regex;

const LISTS: [&str; 4] = ["itemize", "enumerate", "description", "inlineroman"];
const LISTS: [&str; 5] = [
"itemize",
"enumerate",
"description",
"inlineroman",
"inventory",
];

lazy_static! {
pub static ref RE_NEWLINES: Regex = Regex::new(r"\n\n\n+").unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/wrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ pub fn wrap(
let mut verbatim_count = 0;
let mut ignore = Ignore::new();
for (linum, line) in file.lines().enumerate() {
if RE_VERBATIM_BEGIN.is_match(line) {
verbatim_count += 1;
if RE_VERBATIM_END.is_match(line) {
verbatim_count -= 1;
}
ignore = get_ignore(line, linum, ignore, filename, logs, pass, false);
if line_needs_wrap(line) && verbatim_count == 0 && !is_ignored(&ignore)
Expand Down

0 comments on commit f53e4be

Please sign in to comment.