diff --git a/src/buffer/line.rs b/src/buffer/line.rs index 2142af7..79abdb0 100644 --- a/src/buffer/line.rs +++ b/src/buffer/line.rs @@ -217,10 +217,9 @@ impl Line { pub fn grapheme_at_index<'a>(&'a self, index: usize) -> &'a str { - let mut iter = self.grapheme_iter(); let mut i = 0; - for g in iter { + for g in self.grapheme_iter() { if i == index { return g; } diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index c4f30d5..051ff78 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -399,11 +399,10 @@ impl Buffer { let mut s = String::with_capacity(pos_b - pos_a); - let mut iter = self.grapheme_iter_at_index(pos_a); let mut i = 0; let i_end = pos_b - pos_a; - for g in iter { + for g in self.grapheme_iter_at_index(pos_a) { if i == i_end { break; } diff --git a/src/files.rs b/src/files.rs index 2416581..7f95322 100644 --- a/src/files.rs +++ b/src/files.rs @@ -5,12 +5,12 @@ use std::old_path::Path; use buffer::line::{line_ending_to_str}; use buffer::Buffer as TextBuffer; + pub fn save_buffer_to_file(tb: &TextBuffer, path: &Path) -> IoResult<()> { // TODO: make save atomic - let mut iter = tb.line_iter(); let mut f = BufferedWriter::new(try!(File::create(path))); - for l in iter { + for l in tb.line_iter() { let _ = f.write_str(l.as_str()); let _ = f.write_str(line_ending_to_str(l.ending)); } diff --git a/src/formatter.rs b/src/formatter.rs index 80735a5..2c7dc9b 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -2,7 +2,6 @@ use buffer::line::Line; use buffer::Buffer; -use std::cmp::max; #[derive(Copy, PartialEq)] pub enum RoundingBehavior { @@ -40,7 +39,7 @@ pub trait LineFormatter { fn index_offset_vertical_v2d(&self, buf: &Buffer, index: usize, offset: isize, rounding: (RoundingBehavior, RoundingBehavior)) -> usize { // TODO: handle rounding modes // TODO: do this with bidirectional line iterator - let (mut line_i, mut col_i) = buf.index_to_line_col(index); + let (mut line_i, col_i) = buf.index_to_line_col(index); let (mut y, x) = self.index_to_v2d(buf.get_line(line_i), col_i); let mut new_y = y as isize + offset; @@ -48,7 +47,7 @@ pub trait LineFormatter { let mut line; loop { line = buf.get_line(line_i); - let (mut h, _) = self.dimensions(line); + let (h, _) = self.dimensions(line); if new_y >= 0 && new_y < h as isize { y = new_y as usize; @@ -90,7 +89,7 @@ pub trait LineFormatter { let (line_i, col_i) = buf.index_to_line_col(index); let line = buf.get_line(line_i); - let (v, h) = self.index_to_v2d(line, col_i); + let (v, _) = self.index_to_v2d(line, col_i); let new_col_i = self.v2d_to_index(line, (v, horizontal), (RoundingBehavior::Floor, rounding)); return (index + new_col_i) - col_i; diff --git a/src/term_ui/formatter.rs b/src/term_ui/formatter.rs index 76093df..3e3141c 100644 --- a/src/term_ui/formatter.rs +++ b/src/term_ui/formatter.rs @@ -70,13 +70,11 @@ impl LineFormatter for ConsoleLineFormatter { } - fn v2d_to_index(&self, line: &Line, v2d: (usize, usize), rounding: (RoundingBehavior, RoundingBehavior)) -> usize { + fn v2d_to_index(&self, line: &Line, v2d: (usize, usize), _: (RoundingBehavior, RoundingBehavior)) -> usize { // TODO: handle rounding modes let mut i = 0; - let mut pos = (0, 0); - for (_, _pos, _) in self.iter(line) { - pos = _pos; + for (_, pos, _) in self.iter(line) { if pos.0 > v2d.0 { break; } diff --git a/src/term_ui/mod.rs b/src/term_ui/mod.rs index e5d9e1d..5c14e8d 100644 --- a/src/term_ui/mod.rs +++ b/src/term_ui/mod.rs @@ -362,13 +362,11 @@ impl TermUI { let mut screen_line = c1.0 as isize - vis_line_offset as isize; let screen_col = c1.1 as isize; - let mut line_iter = editor.buffer.line_iter_at_index(starting_line); - for line in line_iter { - let mut g_iter = editor.formatter.iter(line); + for line in editor.buffer.line_iter_at_index(starting_line) { // Loop through the graphemes of the line and print them to // the screen. - for (g, (pos_y, pos_x), width) in g_iter { + for (g, (pos_y, pos_x), width) in editor.formatter.iter(line) { // Calculate the cell coordinates at which to draw the grapheme let px = pos_x as isize + screen_col - editor.view_pos.1 as isize; let py = pos_y as isize + screen_line;