more LINE,COLUMN-related work: fix problems parsing it, and allow it at
the (soon-to-be-renamed) "Go to Line" prompt git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2522 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
60a9bddcf6
commit
9245f97960
|
@ -16,7 +16,9 @@ CVS code -
|
||||||
- Add the ability to open a file on a specified column as well
|
- Add the ability to open a file on a specified column as well
|
||||||
as a specified line, by allowing an argument of the form
|
as a specified line, by allowing an argument of the form
|
||||||
+LINE,COLUMN. New function parse_line_column(); changes to
|
+LINE,COLUMN. New function parse_line_column(); changes to
|
||||||
main(), nano.1, and nano.texi. (DLR, suggested by PFTank)
|
main(), do_gotoline() (renamed do_gotolinecolumn()),
|
||||||
|
do_gotoline_void() (renamed do_gotolinecolumn_void()), nano.1,
|
||||||
|
and nano.texi. (DLR, suggested by PFTank)
|
||||||
- cut.c:
|
- cut.c:
|
||||||
cut_line()
|
cut_line()
|
||||||
- Set placewewant properly after cutting a line, to avoid a
|
- Set placewewant properly after cutting a line, to avoid a
|
||||||
|
|
|
@ -480,7 +480,8 @@ void shortcut_init(bool unjustify)
|
||||||
|
|
||||||
sc_init_one(&main_list, NANO_GOTOLINE_KEY, go_to_line_msg,
|
sc_init_one(&main_list, NANO_GOTOLINE_KEY, go_to_line_msg,
|
||||||
IFHELP(nano_gotoline_msg, NANO_GOTOLINE_ALTKEY),
|
IFHELP(nano_gotoline_msg, NANO_GOTOLINE_ALTKEY),
|
||||||
NANO_GOTOLINE_FKEY, NANO_NO_KEY, VIEW, do_gotoline_void);
|
NANO_GOTOLINE_FKEY, NANO_NO_KEY, VIEW,
|
||||||
|
do_gotolinecolumn_void);
|
||||||
|
|
||||||
sc_init_one(&main_list, NANO_REPLACE_KEY, replace_msg,
|
sc_init_one(&main_list, NANO_REPLACE_KEY, replace_msg,
|
||||||
IFHELP(nano_replace_msg, NANO_ALT_REPLACE_KEY),
|
IFHELP(nano_replace_msg, NANO_ALT_REPLACE_KEY),
|
||||||
|
|
20
src/nano.c
20
src/nano.c
|
@ -4446,18 +4446,15 @@ int main(int argc, char **argv)
|
||||||
* followed by at least one other argument, the filename it
|
* followed by at least one other argument, the filename it
|
||||||
* applies to. */
|
* applies to. */
|
||||||
if (i < argc - 1 && argv[i][0] == '+' && iline == 1 &&
|
if (i < argc - 1 && argv[i][0] == '+' && iline == 1 &&
|
||||||
icol == 1) {
|
icol == 1)
|
||||||
parse_line_column(&argv[i][1], &iline, &icol);
|
parse_line_column(&argv[i][1], &iline, &icol);
|
||||||
} else {
|
else {
|
||||||
load_buffer(argv[i]);
|
load_buffer(argv[i]);
|
||||||
|
|
||||||
if (iline > 1) {
|
if (iline > 1 || icol > 1) {
|
||||||
do_gotoline(iline, FALSE);
|
do_gotolinecolumn(iline, icol - 1, FALSE, FALSE,
|
||||||
|
FALSE);
|
||||||
iline = 1;
|
iline = 1;
|
||||||
}
|
|
||||||
|
|
||||||
if (icol > 1) {
|
|
||||||
current_x = actual_x(current->data, icol - 1);
|
|
||||||
icol = 1;
|
icol = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4498,11 +4495,8 @@ int main(int argc, char **argv)
|
||||||
titlebar(NULL);
|
titlebar(NULL);
|
||||||
display_main_list();
|
display_main_list();
|
||||||
|
|
||||||
if (startline > 1)
|
if (startline > 1 || startcol > 1)
|
||||||
do_gotoline(startline, FALSE);
|
do_gotolinecolumn(startline, startcol, FALSE, FALSE, FALSE);
|
||||||
|
|
||||||
if (startcol > 1)
|
|
||||||
current_x = actual_x(current->data, startcol - 1);
|
|
||||||
|
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
/* Return here after a SIGWINCH. */
|
/* Return here after a SIGWINCH. */
|
||||||
|
|
|
@ -516,8 +516,9 @@ ssize_t do_replace_loop(const char *needle, const filestruct
|
||||||
*real_current, size_t *real_current_x, bool wholewords, bool
|
*real_current, size_t *real_current_x, bool wholewords, bool
|
||||||
*canceled);
|
*canceled);
|
||||||
void do_replace(void);
|
void do_replace(void);
|
||||||
void do_gotoline(int line, bool save_pos);
|
void do_gotolinecolumn(int line, ssize_t column, bool use_answer, bool
|
||||||
void do_gotoline_void(void);
|
interactive, bool save_pos);
|
||||||
|
void do_gotolinecolumn_void(void);
|
||||||
#if defined(ENABLE_MULTIBUFFER) || !defined(DISABLE_SPELLER)
|
#if defined(ENABLE_MULTIBUFFER) || !defined(DISABLE_SPELLER)
|
||||||
void do_gotopos(int line, size_t pos_x, int pos_y, size_t pos_pww);
|
void do_gotopos(int line, size_t pos_x, int pos_y, size_t pos_pww);
|
||||||
#endif
|
#endif
|
||||||
|
|
39
src/search.c
39
src/search.c
|
@ -255,9 +255,9 @@ int search_init(bool replacing, bool use_answer)
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
search_history.current = search_history.next;
|
search_history.current = search_history.next;
|
||||||
#endif
|
#endif
|
||||||
do_gotoline(-1, FALSE); /* Put answer up on the
|
do_gotolinecolumn(1, 1, TRUE, TRUE, FALSE);
|
||||||
* statusbar and fall
|
/* Put answer up on the statusbar and
|
||||||
* through. */
|
* fall through. */
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -969,11 +969,12 @@ void do_replace(void)
|
||||||
replace_abort();
|
replace_abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_gotoline(int line, bool save_pos)
|
void do_gotolinecolumn(int line, ssize_t column, bool use_answer, bool
|
||||||
|
interactive, bool save_pos)
|
||||||
{
|
{
|
||||||
if (line <= 0) { /* Ask for it. */
|
if (interactive) { /* Ask for it. */
|
||||||
char *ans = mallocstrcpy(NULL, answer);
|
char *ans = mallocstrcpy(NULL, answer);
|
||||||
int i = statusq(FALSE, gotoline_list, line < 0 ? ans : "",
|
int i = statusq(FALSE, gotoline_list, use_answer ? ans : "",
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
NULL,
|
NULL,
|
||||||
#endif
|
#endif
|
||||||
|
@ -998,12 +999,19 @@ void do_gotoline(int line, bool save_pos)
|
||||||
|
|
||||||
/* Do a bounds check. Display a warning on an out-of-bounds
|
/* Do a bounds check. Display a warning on an out-of-bounds
|
||||||
* line number only if we hit Enter at the statusbar prompt. */
|
* line number only if we hit Enter at the statusbar prompt. */
|
||||||
if (!parse_num(answer, &line) || line < 1) {
|
if (!parse_line_column(answer, &line, &column) || line < 1 ||
|
||||||
|
column < 1) {
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
statusbar(_("Come on, be reasonable"));
|
statusbar(_("Come on, be reasonable"));
|
||||||
display_main_list();
|
display_main_list();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (line < 1)
|
||||||
|
line = 1;
|
||||||
|
|
||||||
|
if (column < 1)
|
||||||
|
column = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current->lineno > line) {
|
if (current->lineno > line) {
|
||||||
|
@ -1016,33 +1024,28 @@ void do_gotoline(int line, bool save_pos)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
current_x = 0;
|
current_x = actual_x(current->data, column - 1);
|
||||||
|
|
||||||
/* If save_pos is TRUE, don't change the cursor position when
|
/* If save_pos is TRUE, don't change the cursor position when
|
||||||
* updating the edit window. */
|
* updating the edit window. */
|
||||||
edit_update(save_pos ? NONE : CENTER);
|
edit_update(save_pos ? NONE : CENTER);
|
||||||
|
|
||||||
placewewant = 0;
|
placewewant = xplustabs();
|
||||||
display_main_list();
|
display_main_list();
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_gotoline_void(void)
|
void do_gotolinecolumn_void(void)
|
||||||
{
|
{
|
||||||
do_gotoline(0, FALSE);
|
do_gotolinecolumn(1, 1, FALSE, TRUE, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(ENABLE_MULTIBUFFER) || !defined(DISABLE_SPELLER)
|
#if defined(ENABLE_MULTIBUFFER) || !defined(DISABLE_SPELLER)
|
||||||
void do_gotopos(int line, size_t pos_x, int pos_y, size_t pos_pww)
|
void do_gotopos(int line, size_t pos_x, int pos_y, size_t pos_pww)
|
||||||
{
|
{
|
||||||
/* Since do_gotoline() resets the x-coordinate but not the
|
/* Since do_gotolinecolumn() resets the x-coordinate but not the
|
||||||
* y-coordinate, set the coordinates up this way. */
|
* y-coordinate, set the coordinates up this way. */
|
||||||
current_y = pos_y;
|
current_y = pos_y;
|
||||||
do_gotoline(line, TRUE);
|
do_gotolinecolumn(line, pos_x, FALSE, FALSE, TRUE);
|
||||||
|
|
||||||
/* Make sure that the x-coordinate is sane here. */
|
|
||||||
current_x = strlen(current->data);
|
|
||||||
if (pos_x < current_x)
|
|
||||||
current_x = pos_x;
|
|
||||||
|
|
||||||
/* Set the rest of the coordinates up. */
|
/* Set the rest of the coordinates up. */
|
||||||
placewewant = pos_pww;
|
placewewant = pos_pww;
|
||||||
|
|
|
@ -124,9 +124,10 @@ bool parse_line_column(const char *str, int *line, ssize_t *column)
|
||||||
|
|
||||||
if (line != NULL) {
|
if (line != NULL) {
|
||||||
if (comma != NULL) {
|
if (comma != NULL) {
|
||||||
char *str_line = mallocstrncpy(NULL, str, comma - str);
|
char *str_line = mallocstrncpy(NULL, str, comma - str + 1);
|
||||||
|
str_line[comma - str] = '\0';
|
||||||
|
|
||||||
if (!parse_num(str_line, line))
|
if (str_line[0] != '\0' && !parse_num(str_line, line))
|
||||||
retval = FALSE;
|
retval = FALSE;
|
||||||
|
|
||||||
free(str_line);
|
free(str_line);
|
||||||
|
@ -358,7 +359,8 @@ char *mallocstrncpy(char *dest, const char *src, size_t n)
|
||||||
* "dest = mallocstrcpy(dest, src);". */
|
* "dest = mallocstrcpy(dest, src);". */
|
||||||
char *mallocstrcpy(char *dest, const char *src)
|
char *mallocstrcpy(char *dest, const char *src)
|
||||||
{
|
{
|
||||||
return mallocstrncpy(dest, src, src == NULL ? 1 : strlen(src) + 1);
|
return mallocstrncpy(dest, src, (src == NULL) ? 1 :
|
||||||
|
strlen(src) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free the malloc()ed string at dest and return the malloc()ed string
|
/* Free the malloc()ed string at dest and return the malloc()ed string
|
||||||
|
|
Loading…
Reference in New Issue