colortoint() and parse_color() in rcfile.c, new code in
edit_add() in winio.c to actually do the highlighting. It's
not even close to pretty yet :P
+ - Many int/long alignments (David Lawrence Ramsey).
- files.c:
+ - Fixes for tab completion and screen refresh (David Lawrence
+ Ramsey).
add_open_file()
- Get rid of unsetting MARK_ISSET because otherwise writing
marked text will automatically unset the marker with
we have _POSIX_VDISABLE or not (more Hurd fixes)
help_init()
- Typo fixes and additions to the new help texts.
+ do_curpos()
+ - Now takes arg for constant updating to always show the cursor
+ position (David Lawrence Ramsey).
+ do_wrap()
+ - Many fixes (David Lawrence Ramsey).
- po/de.po:
- German translation updates (Karl Eichwalder).
- po/ru.po:
- Fix incorrect number of rc options (David Lawrence Ramsey).
- po/sv.po:
- Updated Swedish translation (Christian Rose).
-- po/sv.po:
+- po/da.po:
- Updated Danish translation (Keld Simonsen).
- po/es.po:
- Style updates to Spanish translation (Santiago Vila).
that could create them are taken care of elsewhere) */
add_open_file(1, 0);
- free_filestruct(current);
+ free_filestruct(fileage);
new_file();
UNSET(MODIFIED);
}
{
filestruct *tmp;
- if (!current || !filename)
+ if (!fileage || !current || !filename)
return 1;
/* first, if duplicate checking is allowed, do it */
open_files = make_new_node(NULL);
/* if open_files->file is NULL at the nrealloc() below, we get a
- segfault */
- open_files->file = open_files;
+ segfault
+ open_files->file = open_files; */
}
else if (!update) {
/* save current line number */
open_files->lineno = current->lineno;
- /* save current filestruct */
+ /* save current filestruct and restore full file position afterward */
open_files->file = nmalloc(sizeof(filestruct));
- while (current->prev)
- current = current->prev;
- open_files->file = copy_filestruct(current);
+ open_files->file = copy_filestruct(fileage);
do_gotopos(open_files->lineno, open_files->file_current_x, open_files->file_current_y, open_files->file_placewewant);
/* save current modification status */
coordinate, place we want */
do_gotopos(open_files->lineno, open_files->file_current_x, open_files->file_current_y, open_files->file_placewewant);
+ /* restore the bottom of the file */
+ filebot = current;
+ while (filebot->next)
+ filebot = filebot->next;
+
/* set up modification status and update the titlebar */
if (open_files->file_modified)
SET(MODIFIED);
clearok(topwin, FALSE);
titlebar(NULL);
- /* if we're constantly displaying the cursor position, update it */
+ /* if we're constantly displaying the cursor position, update it (and do so
+ unconditionally, in the rare case that the character count is the same
+ but the line count isn't) */
if (ISSET(CONSTUPDATE))
- do_cursorpos();
+ do_cursorpos(0);
/* now we're done */
return 0;
/* This function now has an arg which refers to how much the
* statusbar (place) should be advanced, i.e. the new cursor pos.
*/
-char *input_tab(char *buf, int place, int *lastWasTab, int *newplace)
+char *input_tab(char *buf, int place, int *lastWasTab, int *newplace, int *list)
{
/* Do TAB completion */
static int num_matches = 0, match_matches = 0;
int longestname = 0, is_dir = 0;
char *foo;
+ *list = 0;
+
if (*lastWasTab == FALSE) {
char *tmp, *copyto, *matchBuf;
/* Ok -- the last char was a TAB. Since they
* just hit TAB again, print a list of all the
* available choices... */
- if (matches && num_matches > 0) {
+ if (matches && num_matches > 1) {
/* Blank the edit window, and print the matches out there */
blank_edit();
}
free(foo);
wrefresh(edit);
+ *list = 1;
} else
beep();
}
- edit_refresh();
+ /* Only refresh the edit window if we don't have a list of filename
+ matches on it */
+ if (*list == 0)
+ edit_refresh();
curs_set(1);
return buf;
}
sc_init_one(&main_list[10], NANO_CURSORPOS_KEY, _("Cur Pos"),
nano_cursorpos_msg,
- 0, NANO_CURSORPOS_FKEY, 0, VIEW, do_cursorpos);
+ 0, NANO_CURSORPOS_FKEY, 0, VIEW, do_cursorpos_void);
sc_init_one(&main_list[11], NANO_SPELL_KEY, _("To Spell"),
nano_spell_msg, 0, NANO_SPELL_FKEY, 0, NOVIEW, do_spell);
down = 1;
}
+ /* Subtract length of original line, plus one for the newline, from
+ totsize. */
+ totsize -= (strlen(inptr->data) + 1);
+
temp->data = charalloc(strlen(&inptr->data[current_word_start]) + 1);
strcpy(temp->data, &inptr->data[current_word_start]);
inptr->data = nrealloc(inptr->data, last_word_end + 2);
inptr->data[last_word_end + 1] = 0;
+
+ /* Now add lengths of new lines, plus two for the newlines, to totsize. */
+ totsize += (strlen(inptr->data) + strlen(temp->data) + 2);
+
} else
/* Category 1b: one word on the line and word not taking up whole line
(i.e. there are spaces at the beginning of the line) */
if (current_x >= current_word_start) {
right = current_x - current_word_start;
- /* Decrease totsize by the number of spaces we removed, less
- one for the new line we're replacing the spaces with. */
- totsize -= (current_word_start - 1);
current_x = 0;
#ifndef NANO_SMALL
if (ISSET(AUTOINDENT)) {
down = 1;
}
+ /* Subtract length of original line, plus one for the newline, from
+ totsize. */
+ totsize -= (strlen(inptr->data) + 1);
+
null_at(&inptr->data, current_x);
+ /* Now add lengths of new lines, plus two for the newlines, to totsize. */
+ totsize += (strlen(inptr->data) + strlen(temp->data) + 2);
+
if (ISSET(MARK_ISSET) && (mark_beginbuf == inptr)) {
mark_beginbuf = temp;
mark_beginx = 0;
if (!isspace((int) input_char)) {
i = current_word_start - 1;
- /* Decrement totsize each time we remove a space. */
while (isspace((int) inptr->data[i])) {
i--;
- totsize--;
assert(i >= 0);
}
- /* And increment it to account for the blank line we're
- replacing the spaces with. */
- totsize++;
} else if (current_x <= last_word_end)
i = last_word_end - 1;
else
i = current_x;
+ /* Subtract length of original line, plus one for the newline, from
+ totsize. */
+ totsize -= (strlen(inptr->data) + 1);
+
inptr->data = nrealloc(inptr->data, i + 2);
inptr->data[i + 1] = 0;
+
+ /* Now add lengths of new lines, plus two for the newlines, to totsize. */
+ totsize += (strlen(inptr->data) + strlen(temp->data) + 2);
+
}
i = current_word_start - 1;
current_x = current_word_start;
+ /* Subtract length of original line, plus one for the newline, from
+ totsize. */
+ totsize -= (strlen(inptr->data) + 1);
+
null_at(&inptr->data, current_word_start);
- /* Increment totsize to account for the new line that
- will be added below, so that it won't end up being
- short by one. */
- totsize++;
+ /* Now add lengths of new lines, plus two for the newlines, to totsize. */
+ totsize += (strlen(inptr->data) + strlen(temp->data) + 2);
}
current_x = current_word_start;
i = current_word_start - 1;
- /* Decrement totsize each time we remove a space. */
while (isspace((int) inptr->data[i])) {
i--;
- totsize--;
assert(i >= 0);
- inptr->data = nrealloc(inptr->data, i + 2);
- inptr->data[i + 1] = 0;
}
- /* And increment it to account for the blank line we're
- replacing the spaces with. */
- totsize++;
+
+ /* Subtract length of original line, plus one for the newline, from
+ totsize. */
+ totsize -= (strlen(inptr->data) + 1);
+
+ inptr->data = nrealloc(inptr->data, i + 2);
+ inptr->data[i + 1] = 0;
+
+ /* Now add lengths of new lines, plus two for the newlines, to totsize. */
+ totsize += (strlen(inptr->data) + strlen(temp->data) + 2);
}
}
{
filestruct *foo;
+ /* blbf -> blank line before filebot (see below) */
+ int blbf = 0;
+
+ if (current->next == filebot && !strcmp(current->data, ""))
+ blbf = 1;
+
if (current_x != strlen(current->data)) {
/* Let's get dangerous */
memmove(¤t->data[current_x], ¤t->data[current_x + 1],
align(¤t->data);
- /* Now that we have a magic lnie again, we can check for both being
- on the line before filebot as well as at filebot */
- } else if (current->next != NULL && current->next != filebot) {
+ /* Now that we have a magic line again, we can check for both being
+ on the line before filebot as well as at filebot; it's a special
+ case if we're on the line before filebot and it's blank, since we
+ should be able to delete it */
+ } else if (current->next != NULL && (current->next != filebot || blbf)) {
current->data = nrealloc(current->data,
strlen(current->data) +
strlen(current->next->data) + 1);
int keyhandled; /* Have we handled the keystroke yet? */
int i, modify_control_seq;
char *argv0;
- long constcheck; /* Check to constantly update */
#ifdef _POSIX_VDISABLE
struct termios term;
reset_cursor();
while (1) {
- constcheck = current->lineno + current_x + current_y + totsize;
#ifndef DISABLE_MOUSE
currshortcut = main_list;
if (ISSET(DISABLE_CURPOS))
UNSET(DISABLE_CURPOS);
else if (ISSET(CONSTUPDATE))
- if (constcheck != current->lineno + current_x + current_y + totsize)
- do_cursorpos();
+ do_cursorpos(1);
reset_cursor();
wrefresh(edit);
#endif
int do_writeout(char *path, int exiting, int append);
-int do_gotoline(long line, int save_pos);
+int do_gotoline(int line, int save_pos);
int do_replace_loop(char *prevanswer, filestruct *begin, int *beginx,
int wholewords, int *i);
int do_find_bracket(void);
#if defined (ENABLE_MULTIBUFFER) || !defined (DISABLE_SPELLER)
-void do_gotopos(long line, int pos_x, int pos_y, int pos_placewewant);
+void do_gotopos(int line, int pos_x, int pos_y, int pos_placewewant);
#endif
/* Now in move.c */
int do_right(void);
int check_wildcard_match(const char *text, const char *pattern);
-char *input_tab(char *buf, int place, int *lastWasTab, int *newplace);
+char *input_tab(char *buf, int place, int *lastWasTab, int *newplace, int *list);
char *real_dir_from_tilde(char *buf);
void shortcut_init(int unjustify);
#endif
int do_page_up(void), do_page_down(void);
-int do_cursorpos(void), do_spell(void);
+int do_cursorpos(int constant), do_cursorpos_void(void), do_spell(void);
int do_up(void), do_down (void), do_right(void), do_left (void);
int do_home(void), do_end(void), total_refresh(void), do_mark(void);
int do_delete(void), do_backspace(void), do_tab(void), do_justify(void);
/* We found an instance */
current_x_find = found - fileptr->data;
-#if 0
+#if 1
/* Ensure we haven't wrapped around again! */
if ((search_last_line) && (current_x_find >= beginx)) {
if (!quiet)
search_last_line = 1;
/* Make sure we haven't passed the begining of the string */
-#if 0 /* Is this required here ? */
+#if 1 /* Is this required here ? */
if (!(&fileptr->data[current_x_find] - fileptr->data))
current_x_find++;
#endif
/* We found an instance */
current_x_find = found - fileptr->data;
-#if 0
+#if 1
/* Ensure we haven't wrapped around again! */
if ((search_last_line) && (current_x_find < beginx)) {
if (!quiet)
}
/* Cleanup */
+ totsize -= strlen(current->data);
free(current->data);
current->data = copy;
+ totsize += strlen(current->data);
/* Stop bug where we replace a substring of the replacement text */
current_x += strlen(last_replace) - 1;
display_main_list();
}
-int do_gotoline(long line, int save_pos)
+int do_gotoline(int line, int save_pos)
{
- long i = 1;
+ int i = 1;
if (line <= 0) { /* Ask for it */
- long j = 0;
+ int j = 0;
j = statusq(0, goto_list, GOTO_LIST_LEN, "", _("Enter line number"));
if (j != 0) {
}
#if (defined ENABLE_MULTIBUFFER || !defined DISABLE_SPELLER)
-void do_gotopos(long line, int pos_x, int pos_y, int pos_placewewant)
+void do_gotopos(int line, int pos_x, int pos_y, int pos_placewewant)
{
/* since do_gotoline() resets the x-coordinate but not the
y-coordinate, set the coordinates up this way */
current_y = pos_y;
do_gotoline(line, 1);
+
+ /* recalculate the x-coordinate and place we want, just in case their
+ values are insane; if they aren't, they won't be changed by this */
+ current_x = pos_x;
+ pos_placewewant = xplustabs();
+ pos_x = actual_x(current, pos_placewewant);
+
+ /* set the rest of the coordinates up */
current_x = pos_x;
placewewant = pos_placewewant;
update_line(current, pos_x);
/* Get the input from the kb; this should only be called from statusq */
int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen,
- int start_x)
+ int start_x, int list)
{
int kbinput = 0, j = 0, x = 0, xend;
int x_left = 0, inputlen, tabbed = 0;
if (allowtabs) {
shift = 0;
inputbuf = input_tab(inputbuf, (x - x_left),
- &tabbed, &shift);
+ &tabbed, &shift, &list);
x += shift;
if (x - x_left > strlen(inputbuf))
x = strlen(inputbuf) + x_left;
virt_cur_x--;
if (i < mark_beginx)
virt_mark_beginx--;
- } else if (realdata[i] >= 1 && realdata[i] <= 26) {
+ } else if (realdata[i] < 32) {
/* Treat control characters as ^letter */
fileptr->data[pos++] = '^';
fileptr->data[pos++] = realdata[i] + 64;
char foo[133];
int ret;
+#ifndef DISABLE_TABCOMP
+ int list;
+#endif
+
bottombars(s, slen);
va_start(ap, msg);
#endif
- ret = nanogetstr(tabs, foo, def, s, slen, (strlen(foo) + 3));
+#ifndef DISABLE_TABCOMP
+ ret = nanogetstr(tabs, foo, def, s, slen, (strlen(foo) + 3), list);
+#else
+ /* if we've disabled tab completion, the value of list won't be
+ used at all, so it's safe to use 0 (NULL) as a placeholder */
+ ret = nanogetstr(tabs, foo, def, s, slen, (strlen(foo) + 3), 0);
+#endif
#ifdef ENABLE_COLOR
color_off(bottomwin, COLOR_STATUSBAR);
do_last_line();
break;
case NANO_CANCEL_KEY:
+#ifndef DISABLE_TABCOMP
+ /* if we've done tab completion, there might be a list of
+ filename matches on the edit window at this point; make sure
+ they're cleared off */
+ if (list)
+ edit_refresh();
+#endif
return -1;
default:
blank_statusbar();
current_y--;
}
-int do_cursorpos(void)
+int do_cursorpos(int constant)
{
filestruct *fileptr;
float linepct = 0.0, bytepct = 0.0;
long i = 0;
+ static long old_i = -1, old_totsize = -1;
if (current == NULL || fileage == NULL)
return 0;
i += current_x;
+ if (old_i == -1)
+ old_i = i;
+
+ if (old_totsize == -1)
+ old_totsize = totsize;
+
if (totlines > 0)
linepct = 100 * current->lineno / totlines;
linepct, bytepct);
#endif
- statusbar(_("line %d of %d (%.0f%%), character %ld of %ld (%.0f%%)"),
- current->lineno, totlines, linepct, i, totsize, bytepct);
+ /* if constant is zero, display the position on the statusbar
+ unconditionally; otherwise, only display the position when the
+ character values have changed */
+ if (!constant || (old_i != i || old_totsize != totsize)) {
+ statusbar(_("line %d of %d (%.0f%%), character %ld of %ld (%.0f%%)"),
+ current->lineno, totlines, linepct, i, totsize, bytepct);
+ }
+
+ old_i = i;
+ old_totsize = totsize;
+
reset_cursor();
return 1;
}
+int do_cursorpos_void(void)
+{
+ return do_cursorpos(0);
+}
+
/* Our broken, non-shortcut list compliant help function.
But, hey, it's better than nothing, and it's dynamic! */
int do_help(void)