mirror of
git://git.sv.gnu.org/nano.git
synced 2024-11-22 04:41:21 +03:00
tweaks: rename two variables, one for contrast, another for visibility
Also normalize two bits of whitespace.
This commit is contained in:
parent
a4675acdba
commit
a3a1391a51
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
static char **filelist = NULL;
|
static char **filelist = NULL;
|
||||||
/* The list of files to display in the file browser. */
|
/* The list of files to display in the file browser. */
|
||||||
static size_t filelist_len = 0;
|
static size_t list_length = 0;
|
||||||
/* The number of files in the list. */
|
/* The number of files in the list. */
|
||||||
static size_t width = 0;
|
static size_t width = 0;
|
||||||
/* The number of files that we can display per screen row. */
|
/* The number of files that we can display per screen row. */
|
||||||
@ -40,14 +40,14 @@ static size_t selected = 0;
|
|||||||
/* The currently selected filename in the list; zero-based. */
|
/* The currently selected filename in the list; zero-based. */
|
||||||
|
|
||||||
/* Set filelist to the list of files contained in the directory path,
|
/* Set filelist to the list of files contained in the directory path,
|
||||||
* set filelist_len to the number of files in that list, set longest to
|
* set list_length to the number of files in that list, set longest to
|
||||||
* the width in columns of the longest filename in that list (between 15
|
* the width in columns of the longest filename in that list (between 15
|
||||||
* and COLS), and set width to the number of files that we can display
|
* and COLS), and set width to the number of files that we can display
|
||||||
* per screen row. And sort the list too. */
|
* per screen row. And sort the list too. */
|
||||||
void read_the_list(const char *path, DIR *dir)
|
void read_the_list(const char *path, DIR *dir)
|
||||||
{
|
{
|
||||||
|
size_t path_len = strlen(path), index = 0;
|
||||||
const struct dirent *nextdir;
|
const struct dirent *nextdir;
|
||||||
size_t i = 0, path_len = strlen(path);
|
|
||||||
|
|
||||||
longest = 0;
|
longest = 0;
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ void read_the_list(const char *path, DIR *dir)
|
|||||||
if (name_len > longest)
|
if (name_len > longest)
|
||||||
longest = name_len;
|
longest = name_len;
|
||||||
|
|
||||||
i++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Put 10 characters' worth of blank space between columns of filenames
|
/* Put 10 characters' worth of blank space between columns of filenames
|
||||||
@ -74,32 +74,31 @@ void read_the_list(const char *path, DIR *dir)
|
|||||||
|
|
||||||
rewinddir(dir);
|
rewinddir(dir);
|
||||||
|
|
||||||
free_chararray(filelist, filelist_len);
|
free_chararray(filelist, list_length);
|
||||||
|
|
||||||
filelist_len = i;
|
list_length = index;
|
||||||
|
index = 0;
|
||||||
|
|
||||||
filelist = nmalloc(filelist_len * sizeof(char *));
|
filelist = nmalloc(list_length * sizeof(char *));
|
||||||
|
|
||||||
i = 0;
|
while ((nextdir = readdir(dir)) != NULL && index < list_length) {
|
||||||
|
|
||||||
while ((nextdir = readdir(dir)) != NULL && i < filelist_len) {
|
|
||||||
/* Don't show the "." entry. */
|
/* Don't show the "." entry. */
|
||||||
if (strcmp(nextdir->d_name, ".") == 0)
|
if (strcmp(nextdir->d_name, ".") == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
filelist[i] = nmalloc(path_len + strlen(nextdir->d_name) + 1);
|
filelist[index] = nmalloc(path_len + strlen(nextdir->d_name) + 1);
|
||||||
sprintf(filelist[i], "%s%s", path, nextdir->d_name);
|
sprintf(filelist[index], "%s%s", path, nextdir->d_name);
|
||||||
|
|
||||||
i++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Maybe the number of files in the directory changed between the
|
/* Maybe the number of files in the directory decreased between the
|
||||||
* first time we scanned and the second. i is the actual length of
|
* first time we scanned and the second time. index is the actual
|
||||||
* filelist, so record it. */
|
* length of the file list, so record it. */
|
||||||
filelist_len = i;
|
list_length = index;
|
||||||
|
|
||||||
/* Sort the list of names. */
|
/* Sort the list of names. */
|
||||||
qsort(filelist, filelist_len, sizeof(char *), diralphasort);
|
qsort(filelist, list_length, sizeof(char *), diralphasort);
|
||||||
|
|
||||||
/* Calculate how many files fit on a line -- feigning room for two
|
/* Calculate how many files fit on a line -- feigning room for two
|
||||||
* spaces beyond the right edge, and adding two spaces of padding
|
* spaces beyond the right edge, and adding two spaces of padding
|
||||||
@ -113,7 +112,7 @@ void browser_select_dirname(const char *needle)
|
|||||||
{
|
{
|
||||||
size_t looking_at = 0;
|
size_t looking_at = 0;
|
||||||
|
|
||||||
for (; looking_at < filelist_len; looking_at++) {
|
for (; looking_at < list_length; looking_at++) {
|
||||||
if (strcmp(filelist[looking_at], needle) == 0) {
|
if (strcmp(filelist[looking_at], needle) == 0) {
|
||||||
selected = looking_at;
|
selected = looking_at;
|
||||||
break;
|
break;
|
||||||
@ -122,12 +121,12 @@ void browser_select_dirname(const char *needle)
|
|||||||
|
|
||||||
/* If the sought name isn't found, move the highlight so that the
|
/* If the sought name isn't found, move the highlight so that the
|
||||||
* changed selection will be noticed. */
|
* changed selection will be noticed. */
|
||||||
if (looking_at == filelist_len) {
|
if (looking_at == list_length) {
|
||||||
--selected;
|
--selected;
|
||||||
|
|
||||||
/* Make sure we stay within the available range. */
|
/* Make sure we stay within the available range. */
|
||||||
if (selected >= filelist_len)
|
if (selected >= list_length)
|
||||||
selected = filelist_len - 1;
|
selected = list_length - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +144,7 @@ void browser_refresh(void)
|
|||||||
blank_edit();
|
blank_edit();
|
||||||
|
|
||||||
for (size_t index = selected - selected % (editwinrows * width);
|
for (size_t index = selected - selected % (editwinrows * width);
|
||||||
index < filelist_len && row < editwinrows; index++) {
|
index < list_length && row < editwinrows; index++) {
|
||||||
const char *thename = tail(filelist[index]);
|
const char *thename = tail(filelist[index]);
|
||||||
/* The filename we display, minus the path. */
|
/* The filename we display, minus the path. */
|
||||||
size_t namelen = breadth(thename);
|
size_t namelen = breadth(thename);
|
||||||
@ -283,13 +282,13 @@ void findfile(const char *needle, bool forwards)
|
|||||||
* we've come back to the point where we started. */
|
* we've come back to the point where we started. */
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
if (forwards) {
|
if (forwards) {
|
||||||
if (looking_at++ == filelist_len - 1) {
|
if (looking_at++ == list_length - 1) {
|
||||||
looking_at = 0;
|
looking_at = 0;
|
||||||
statusbar(_("Search Wrapped"));
|
statusbar(_("Search Wrapped"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (looking_at-- == 0) {
|
if (looking_at-- == 0) {
|
||||||
looking_at = filelist_len - 1;
|
looking_at = list_length - 1;
|
||||||
statusbar(_("Search Wrapped"));
|
statusbar(_("Search Wrapped"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -488,8 +487,8 @@ char *browse(char *path)
|
|||||||
selected--;
|
selected--;
|
||||||
|
|
||||||
/* If we're beyond the list, select the last filename. */
|
/* If we're beyond the list, select the last filename. */
|
||||||
if (selected > filelist_len - 1)
|
if (selected > list_length - 1)
|
||||||
selected = filelist_len - 1;
|
selected = list_length - 1;
|
||||||
|
|
||||||
/* If we selected the same filename as last time, fake a
|
/* If we selected the same filename as last time, fake a
|
||||||
* press of the Enter key so that the file is read in. */
|
* press of the Enter key so that the file is read in. */
|
||||||
@ -539,19 +538,19 @@ char *browse(char *path)
|
|||||||
if (selected > 0)
|
if (selected > 0)
|
||||||
selected--;
|
selected--;
|
||||||
} else if (func == do_right) {
|
} else if (func == do_right) {
|
||||||
if (selected < filelist_len - 1)
|
if (selected < list_length - 1)
|
||||||
selected++;
|
selected++;
|
||||||
} else if (func == to_prev_word) {
|
} else if (func == to_prev_word) {
|
||||||
selected -= (selected % width);
|
selected -= (selected % width);
|
||||||
} else if (func == to_next_word) {
|
} else if (func == to_next_word) {
|
||||||
selected += width - 1 - (selected % width);
|
selected += width - 1 - (selected % width);
|
||||||
if (selected >= filelist_len)
|
if (selected >= list_length)
|
||||||
selected = filelist_len - 1;
|
selected = list_length - 1;
|
||||||
} else if (func == do_up) {
|
} else if (func == do_up) {
|
||||||
if (selected >= width)
|
if (selected >= width)
|
||||||
selected -= width;
|
selected -= width;
|
||||||
} else if (func == do_down) {
|
} else if (func == do_down) {
|
||||||
if (selected + width <= filelist_len - 1)
|
if (selected + width <= list_length - 1)
|
||||||
selected += width;
|
selected += width;
|
||||||
} else if (func == to_prev_block) {
|
} else if (func == to_prev_block) {
|
||||||
selected = ((selected / (editwinrows * width)) *
|
selected = ((selected / (editwinrows * width)) *
|
||||||
@ -560,9 +559,9 @@ char *browse(char *path)
|
|||||||
selected = ((selected / (editwinrows * width)) *
|
selected = ((selected / (editwinrows * width)) *
|
||||||
editwinrows * width) + selected % width +
|
editwinrows * width) + selected % width +
|
||||||
editwinrows * width - width;
|
editwinrows * width - width;
|
||||||
if (selected >= filelist_len)
|
if (selected >= list_length)
|
||||||
selected = (filelist_len / width) * width + selected % width;
|
selected = (list_length / width) * width + selected % width;
|
||||||
if (selected >= filelist_len)
|
if (selected >= list_length)
|
||||||
selected -= width;
|
selected -= width;
|
||||||
} else if (func == do_page_up) {
|
} else if (func == do_page_up) {
|
||||||
if (selected < width)
|
if (selected < width)
|
||||||
@ -572,17 +571,17 @@ char *browse(char *path)
|
|||||||
else
|
else
|
||||||
selected -= editwinrows * width;
|
selected -= editwinrows * width;
|
||||||
} else if (func == do_page_down) {
|
} else if (func == do_page_down) {
|
||||||
if (selected + width >= filelist_len - 1)
|
if (selected + width >= list_length - 1)
|
||||||
selected = filelist_len - 1;
|
selected = list_length - 1;
|
||||||
else if (selected + editwinrows * width >= filelist_len)
|
else if (selected + editwinrows * width >= list_length)
|
||||||
selected = (selected + editwinrows * width - filelist_len) %
|
selected = (selected + editwinrows * width - list_length) %
|
||||||
width + filelist_len - width;
|
width + list_length - width;
|
||||||
else
|
else
|
||||||
selected += editwinrows * width;
|
selected += editwinrows * width;
|
||||||
} else if (func == to_first_file) {
|
} else if (func == to_first_file) {
|
||||||
selected = 0;
|
selected = 0;
|
||||||
} else if (func == to_last_file) {
|
} else if (func == to_last_file) {
|
||||||
selected = filelist_len - 1;
|
selected = list_length - 1;
|
||||||
} else if (func == goto_dir) {
|
} else if (func == goto_dir) {
|
||||||
/* Ask for the directory to go to. */
|
/* Ask for the directory to go to. */
|
||||||
if (do_prompt(MGOTODIR, "", NULL,
|
if (do_prompt(MGOTODIR, "", NULL,
|
||||||
@ -616,7 +615,7 @@ char *browse(char *path)
|
|||||||
|
|
||||||
/* In case the specified directory cannot be entered, select it
|
/* In case the specified directory cannot be entered, select it
|
||||||
* (if it is in the current list) so it will be highlighted. */
|
* (if it is in the current list) so it will be highlighted. */
|
||||||
for (size_t j = 0; j < filelist_len; j++)
|
for (size_t j = 0; j < list_length; j++)
|
||||||
if (strcmp(filelist[j], path) == 0)
|
if (strcmp(filelist[j], path) == 0)
|
||||||
selected = j;
|
selected = j;
|
||||||
|
|
||||||
@ -690,9 +689,9 @@ char *browse(char *path)
|
|||||||
|
|
||||||
free(path);
|
free(path);
|
||||||
|
|
||||||
free_chararray(filelist, filelist_len);
|
free_chararray(filelist, list_length);
|
||||||
filelist = NULL;
|
filelist = NULL;
|
||||||
filelist_len = 0;
|
list_length = 0;
|
||||||
|
|
||||||
return chosen;
|
return chosen;
|
||||||
}
|
}
|
||||||
|
@ -2823,8 +2823,8 @@ void do_linter(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tmplint != curlint) {
|
if (tmplint != curlint) {
|
||||||
/* Put the cursor at the reported position, but don't go beyond EOL
|
/* Put the cursor at the reported position, but don't go beyond EOL
|
||||||
* when the second number is a column number instead of an index. */
|
* when the second number is a column number instead of an index. */
|
||||||
goto_line_posx(curlint->lineno, curlint->colno - 1);
|
goto_line_posx(curlint->lineno, curlint->colno - 1);
|
||||||
openfile->current_x = actual_x(openfile->current->data, openfile->placewewant);
|
openfile->current_x = actual_x(openfile->current->data, openfile->placewewant);
|
||||||
titlebar(NULL);
|
titlebar(NULL);
|
||||||
|
@ -841,7 +841,7 @@ int assemble_byte_code(int keycode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* The second digit may be at most 5 if the first was 2. */
|
/* The second digit may be at most 5 if the first was 2. */
|
||||||
if (digit_count == 2) {
|
if (digit_count == 2) {
|
||||||
if (byte < 200 || keycode <= '5') {
|
if (byte < 200 || keycode <= '5') {
|
||||||
byte += (keycode - '0') * 10;
|
byte += (keycode - '0') * 10;
|
||||||
return PROCEED;
|
return PROCEED;
|
||||||
|
Loading…
Reference in New Issue
Block a user