- Add the ability to open a file on a specified column as well
as a specified line, by allowing an argument of the form
+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_line()
- Set placewewant properly after cutting a line, to avoid a
sc_init_one(&main_list, NANO_GOTOLINE_KEY, go_to_line_msg,
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,
IFHELP(nano_replace_msg, NANO_ALT_REPLACE_KEY),
* followed by at least one other argument, the filename it
* applies to. */
if (i < argc - 1 && argv[i][0] == '+' && iline == 1 &&
- icol == 1) {
+ icol == 1)
parse_line_column(&argv[i][1], &iline, &icol);
- } else {
+ else {
load_buffer(argv[i]);
- if (iline > 1) {
- do_gotoline(iline, FALSE);
+ if (iline > 1 || icol > 1) {
+ do_gotolinecolumn(iline, icol - 1, FALSE, FALSE,
+ FALSE);
iline = 1;
- }
-
- if (icol > 1) {
- current_x = actual_x(current->data, icol - 1);
icol = 1;
}
}
titlebar(NULL);
display_main_list();
- if (startline > 1)
- do_gotoline(startline, FALSE);
-
- if (startcol > 1)
- current_x = actual_x(current->data, startcol - 1);
+ if (startline > 1 || startcol > 1)
+ do_gotolinecolumn(startline, startcol, FALSE, FALSE, FALSE);
#ifndef NANO_SMALL
/* Return here after a SIGWINCH. */
*real_current, size_t *real_current_x, bool wholewords, bool
*canceled);
void do_replace(void);
-void do_gotoline(int line, bool save_pos);
-void do_gotoline_void(void);
+void do_gotolinecolumn(int line, ssize_t column, bool use_answer, bool
+ interactive, bool save_pos);
+void do_gotolinecolumn_void(void);
#if defined(ENABLE_MULTIBUFFER) || !defined(DISABLE_SPELLER)
void do_gotopos(int line, size_t pos_x, int pos_y, size_t pos_pww);
#endif
#ifndef NANO_SMALL
search_history.current = search_history.next;
#endif
- do_gotoline(-1, FALSE); /* Put answer up on the
- * statusbar and fall
- * through. */
+ do_gotolinecolumn(1, 1, TRUE, TRUE, FALSE);
+ /* Put answer up on the statusbar and
+ * fall through. */
default:
return -1;
}
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);
- int i = statusq(FALSE, gotoline_list, line < 0 ? ans : "",
+ int i = statusq(FALSE, gotoline_list, use_answer ? ans : "",
#ifndef NANO_SMALL
NULL,
#endif
/* Do a bounds check. Display a warning on an out-of-bounds
* 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)
statusbar(_("Come on, be reasonable"));
display_main_list();
return;
}
+ } else {
+ if (line < 1)
+ line = 1;
+
+ if (column < 1)
+ column = 1;
}
if (current->lineno > line) {
;
}
- current_x = 0;
+ current_x = actual_x(current->data, column - 1);
/* If save_pos is TRUE, don't change the cursor position when
* updating the edit window. */
edit_update(save_pos ? NONE : CENTER);
- placewewant = 0;
+ placewewant = xplustabs();
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)
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. */
current_y = pos_y;
- do_gotoline(line, TRUE);
-
- /* Make sure that the x-coordinate is sane here. */
- current_x = strlen(current->data);
- if (pos_x < current_x)
- current_x = pos_x;
+ do_gotolinecolumn(line, pos_x, FALSE, FALSE, TRUE);
/* Set the rest of the coordinates up. */
placewewant = pos_pww;
if (line != 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;
free(str_line);
* "dest = mallocstrcpy(dest, 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