2000-08-06 21:13:45 +00:00
|
|
|
/* $Id$ */
|
2000-06-19 04:22:15 +00:00
|
|
|
/**************************************************************************
|
|
|
|
* move.c *
|
|
|
|
* *
|
2009-12-02 03:36:22 +00:00
|
|
|
* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, *
|
|
|
|
* 2008, 2009 Free Software Foundation, Inc. *
|
2000-06-19 04:22:15 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
2007-08-11 05:17:36 +00:00
|
|
|
* the Free Software Foundation; either version 3, or (at your option) *
|
2000-06-19 04:22:15 +00:00
|
|
|
* any later version. *
|
|
|
|
* *
|
2005-05-15 19:57:17 +00:00
|
|
|
* This program is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
|
|
|
* General Public License for more details. *
|
2000-06-19 04:22:15 +00:00
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software *
|
2005-05-15 19:57:17 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
|
|
|
|
* 02110-1301, USA. *
|
2000-06-19 04:22:15 +00:00
|
|
|
* *
|
|
|
|
**************************************************************************/
|
|
|
|
|
2005-12-08 02:47:10 +00:00
|
|
|
#include "proto.h"
|
2001-04-28 18:03:52 +00:00
|
|
|
|
2000-06-19 04:22:15 +00:00
|
|
|
#include <string.h>
|
2004-05-22 20:15:20 +00:00
|
|
|
#include <ctype.h>
|
2000-06-19 04:22:15 +00:00
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move to the first line of the file. */
|
2004-07-02 14:31:03 +00:00
|
|
|
void do_first_line(void)
|
2004-05-23 21:33:23 +00:00
|
|
|
{
|
2009-11-16 04:28:40 +00:00
|
|
|
openfile->current = openfile->edittop = openfile->fileage;
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current_x = 0;
|
2005-07-14 18:01:08 +00:00
|
|
|
openfile->placewewant = 0;
|
|
|
|
|
2009-11-14 19:57:38 +00:00
|
|
|
edit_refresh_needed = 1;
|
2004-05-23 21:33:23 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move to the last line of the file. */
|
2004-07-02 14:31:03 +00:00
|
|
|
void do_last_line(void)
|
2004-05-23 21:33:23 +00:00
|
|
|
{
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current = openfile->filebot;
|
2005-11-05 17:50:06 +00:00
|
|
|
openfile->current_x = strlen(openfile->filebot->data);
|
|
|
|
openfile->placewewant = xplustabs();
|
2005-08-16 01:27:05 +00:00
|
|
|
openfile->current_y = editwinrows - 1;
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2009-11-14 19:57:38 +00:00
|
|
|
edit_refresh_needed = 1;
|
2004-05-23 21:33:23 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move up one page. */
|
2004-07-02 14:31:03 +00:00
|
|
|
void do_page_up(void)
|
2000-07-03 04:24:39 +00:00
|
|
|
{
|
2009-11-24 17:15:53 +00:00
|
|
|
int i, skipped = 0;
|
2005-07-17 00:01:18 +00:00
|
|
|
|
2005-07-16 22:50:30 +00:00
|
|
|
/* If there's less than a page of text left on the screen, put the
|
|
|
|
* cursor at the beginning of the first line of the file, and then
|
|
|
|
* update the edit window. */
|
2010-01-13 03:21:19 +00:00
|
|
|
if (openfile->current->lineno == 1 || (!ISSET(SOFTWRAP) &&
|
|
|
|
openfile->current->lineno <= editwinrows - 2)) {
|
2005-07-16 22:50:30 +00:00
|
|
|
do_first_line();
|
2005-07-17 00:01:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-07-16 22:50:30 +00:00
|
|
|
|
2005-07-17 00:01:18 +00:00
|
|
|
/* If we're not in smooth scrolling mode, put the cursor at the
|
|
|
|
* beginning of the top line of the edit window, as Pico does. */
|
2009-11-24 17:15:53 +00:00
|
|
|
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2005-07-17 00:01:18 +00:00
|
|
|
if (!ISSET(SMOOTH_SCROLL)) {
|
2003-09-07 23:57:24 +00:00
|
|
|
#endif
|
2005-07-17 00:01:18 +00:00
|
|
|
openfile->current = openfile->edittop;
|
|
|
|
openfile->placewewant = 0;
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2005-07-17 00:01:18 +00:00
|
|
|
}
|
2003-09-07 23:57:24 +00:00
|
|
|
#endif
|
2000-07-03 04:24:39 +00:00
|
|
|
|
2009-11-24 17:15:53 +00:00
|
|
|
for (i = editwinrows - 2; i - skipped > 0 && openfile->current !=
|
|
|
|
openfile->fileage; i--) {
|
2005-07-17 00:01:18 +00:00
|
|
|
openfile->current = openfile->current->prev;
|
2009-11-26 18:23:00 +00:00
|
|
|
if (ISSET(SOFTWRAP) && openfile->current) {
|
2009-11-24 17:15:53 +00:00
|
|
|
skipped += strlenpt(openfile->current->data) / COLS;
|
2009-11-26 18:23:00 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, "do_page_up: i = %d, skipped = %d based on line %ld len %d\n", i, (unsigned long) skipped,
|
|
|
|
openfile->current->lineno, strlenpt(openfile->current->data));
|
|
|
|
#endif
|
|
|
|
}
|
2009-11-24 17:15:53 +00:00
|
|
|
}
|
2005-07-14 22:15:09 +00:00
|
|
|
|
2005-07-17 00:01:18 +00:00
|
|
|
openfile->current_x = actual_x(openfile->current->data,
|
|
|
|
openfile->placewewant);
|
2005-07-14 22:15:09 +00:00
|
|
|
|
2009-11-24 17:15:53 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, "do_page_up: openfile->current->lineno = %lu, skipped = %d\n", (unsigned long) openfile->current->lineno, skipped);
|
|
|
|
#endif
|
|
|
|
|
2005-07-17 00:01:18 +00:00
|
|
|
/* Scroll the edit window up a page. */
|
2010-01-13 03:21:19 +00:00
|
|
|
edit_update(NONE);
|
2000-07-03 04:24:39 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move down one page. */
|
2004-07-02 14:31:03 +00:00
|
|
|
void do_page_down(void)
|
2002-09-06 20:35:28 +00:00
|
|
|
{
|
2005-07-17 00:01:18 +00:00
|
|
|
int i;
|
|
|
|
|
2005-07-16 22:50:30 +00:00
|
|
|
/* If there's less than a page of text left on the screen, put the
|
|
|
|
* cursor at the beginning of the last line of the file, and then
|
|
|
|
* update the edit window. */
|
2009-11-16 04:28:40 +00:00
|
|
|
if (openfile->current->lineno + maxrows - 2 >=
|
2005-07-17 00:01:18 +00:00
|
|
|
openfile->filebot->lineno) {
|
2005-07-16 22:50:30 +00:00
|
|
|
do_last_line();
|
2005-07-17 00:01:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-07-14 22:15:09 +00:00
|
|
|
|
2005-07-17 00:01:18 +00:00
|
|
|
/* If we're not in smooth scrolling mode, put the cursor at the
|
|
|
|
* beginning of the top line of the edit window, as Pico does. */
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2005-07-17 00:01:18 +00:00
|
|
|
if (!ISSET(SMOOTH_SCROLL)) {
|
2002-12-22 16:30:00 +00:00
|
|
|
#endif
|
2005-07-17 00:01:18 +00:00
|
|
|
openfile->current = openfile->edittop;
|
|
|
|
openfile->placewewant = 0;
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2005-07-17 00:01:18 +00:00
|
|
|
}
|
2003-09-07 23:57:24 +00:00
|
|
|
#endif
|
2002-09-06 20:35:28 +00:00
|
|
|
|
2009-11-16 04:28:40 +00:00
|
|
|
for (i = maxrows - 2; i > 0 && openfile->current !=
|
|
|
|
openfile->filebot; i--) {
|
2005-07-17 00:01:18 +00:00
|
|
|
openfile->current = openfile->current->next;
|
2009-11-16 04:28:40 +00:00
|
|
|
#ifdef DEBUG
|
2009-11-24 17:15:53 +00:00
|
|
|
fprintf(stderr, "do_page_down: moving to line %lu\n", (unsigned long) openfile->current->lineno);
|
2009-11-16 04:28:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
2005-07-14 22:15:09 +00:00
|
|
|
|
2005-07-17 00:01:18 +00:00
|
|
|
openfile->current_x = actual_x(openfile->current->data,
|
|
|
|
openfile->placewewant);
|
2005-07-14 22:15:09 +00:00
|
|
|
|
2005-07-17 00:01:18 +00:00
|
|
|
/* Scroll the edit window down a page. */
|
2010-01-13 03:21:19 +00:00
|
|
|
edit_update(NONE);
|
2002-09-06 20:35:28 +00:00
|
|
|
}
|
|
|
|
|
2005-07-20 19:24:11 +00:00
|
|
|
#ifndef DISABLE_JUSTIFY
|
2005-11-10 05:26:37 +00:00
|
|
|
/* Move up to the beginning of the last beginning-of-paragraph line
|
2005-12-08 07:09:08 +00:00
|
|
|
* before the current line. If allow_update is TRUE, update the screen
|
|
|
|
* afterwards. */
|
2005-07-20 19:24:11 +00:00
|
|
|
void do_para_begin(bool allow_update)
|
|
|
|
{
|
2009-01-25 07:25:17 +00:00
|
|
|
filestruct *current_save = openfile->current;
|
2005-07-20 19:24:11 +00:00
|
|
|
const size_t pww_save = openfile->placewewant;
|
|
|
|
|
2005-11-03 21:08:39 +00:00
|
|
|
if (openfile->current != openfile->fileage) {
|
2005-07-20 19:24:11 +00:00
|
|
|
do {
|
|
|
|
openfile->current = openfile->current->prev;
|
|
|
|
openfile->current_y--;
|
|
|
|
} while (!begpar(openfile->current));
|
|
|
|
}
|
|
|
|
|
2005-11-09 04:20:55 +00:00
|
|
|
openfile->current_x = 0;
|
|
|
|
openfile->placewewant = 0;
|
|
|
|
|
2005-07-20 19:24:11 +00:00
|
|
|
if (allow_update)
|
|
|
|
edit_redraw(current_save, pww_save);
|
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move up to the beginning of the last beginning-of-paragraph line
|
|
|
|
* before the current line, and update the screen afterwards. */
|
2005-07-20 19:24:11 +00:00
|
|
|
void do_para_begin_void(void)
|
|
|
|
{
|
|
|
|
do_para_begin(TRUE);
|
|
|
|
}
|
|
|
|
|
2005-11-10 05:26:37 +00:00
|
|
|
/* Move down to the beginning of the last line of the current paragraph.
|
|
|
|
* Then move down one line farther if there is such a line, or to the
|
2005-12-08 07:09:08 +00:00
|
|
|
* end of the current line if not. If allow_update is TRUE, update the
|
|
|
|
* screen afterwards. A line is the last line of a paragraph if it is
|
|
|
|
* in a paragraph, and the next line either is the beginning line of a
|
|
|
|
* paragraph or isn't in a paragraph. */
|
2005-07-20 19:24:11 +00:00
|
|
|
void do_para_end(bool allow_update)
|
|
|
|
{
|
2009-01-25 07:25:17 +00:00
|
|
|
filestruct *const current_save = openfile->current;
|
2005-07-20 19:24:11 +00:00
|
|
|
const size_t pww_save = openfile->placewewant;
|
|
|
|
|
2005-11-03 21:08:39 +00:00
|
|
|
while (openfile->current != openfile->filebot &&
|
|
|
|
!inpar(openfile->current))
|
2005-07-20 19:24:11 +00:00
|
|
|
openfile->current = openfile->current->next;
|
|
|
|
|
2005-11-03 21:08:39 +00:00
|
|
|
while (openfile->current != openfile->filebot &&
|
2005-07-20 19:24:11 +00:00
|
|
|
inpar(openfile->current->next) &&
|
|
|
|
!begpar(openfile->current->next)) {
|
|
|
|
openfile->current = openfile->current->next;
|
|
|
|
openfile->current_y++;
|
|
|
|
}
|
|
|
|
|
2005-11-09 04:20:55 +00:00
|
|
|
if (openfile->current != openfile->filebot) {
|
2005-07-20 19:24:11 +00:00
|
|
|
openfile->current = openfile->current->next;
|
2005-11-09 04:20:55 +00:00
|
|
|
openfile->current_x = 0;
|
|
|
|
openfile->placewewant = 0;
|
|
|
|
} else {
|
|
|
|
openfile->current_x = strlen(openfile->current->data);
|
|
|
|
openfile->placewewant = xplustabs();
|
|
|
|
}
|
2005-07-20 19:24:11 +00:00
|
|
|
|
|
|
|
if (allow_update)
|
|
|
|
edit_redraw(current_save, pww_save);
|
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move down to the beginning of the last line of the current paragraph.
|
|
|
|
* Then move down one line farther if there is such a line, or to the
|
|
|
|
* end of the current line if not, and update the screen afterwards. */
|
2005-07-20 19:24:11 +00:00
|
|
|
void do_para_end_void(void)
|
|
|
|
{
|
|
|
|
do_para_end(TRUE);
|
|
|
|
}
|
|
|
|
#endif /* !DISABLE_JUSTIFY */
|
|
|
|
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move to the next word in the file. If allow_punct is TRUE, treat
|
|
|
|
* punctuation as part of a word. If allow_update is TRUE, update the
|
|
|
|
* screen afterwards. Return TRUE if we started on a word, and FALSE
|
|
|
|
* otherwise. */
|
2005-07-20 21:31:19 +00:00
|
|
|
bool do_next_word(bool allow_punct, bool allow_update)
|
|
|
|
{
|
|
|
|
size_t pww_save = openfile->placewewant;
|
2009-01-25 07:25:17 +00:00
|
|
|
filestruct *current_save = openfile->current;
|
2005-07-20 21:31:19 +00:00
|
|
|
char *char_mb;
|
|
|
|
int char_mb_len;
|
|
|
|
bool end_line = FALSE, started_on_word = FALSE;
|
|
|
|
|
|
|
|
assert(openfile->current != NULL && openfile->current->data != NULL);
|
|
|
|
|
|
|
|
char_mb = charalloc(mb_cur_max());
|
|
|
|
|
|
|
|
/* Move forward until we find the character after the last letter of
|
|
|
|
* the current word. */
|
|
|
|
while (!end_line) {
|
|
|
|
char_mb_len = parse_mbchar(openfile->current->data +
|
2005-07-26 06:13:45 +00:00
|
|
|
openfile->current_x, char_mb, NULL);
|
2005-07-20 21:31:19 +00:00
|
|
|
|
|
|
|
/* If we've found it, stop moving forward through the current
|
|
|
|
* line. */
|
|
|
|
if (!is_word_mbchar(char_mb, allow_punct))
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* If we haven't found it, then we've started on a word, so set
|
|
|
|
* started_on_word to TRUE. */
|
|
|
|
started_on_word = TRUE;
|
|
|
|
|
|
|
|
if (openfile->current->data[openfile->current_x] == '\0')
|
|
|
|
end_line = TRUE;
|
|
|
|
else
|
|
|
|
openfile->current_x += char_mb_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move forward until we find the first letter of the next word. */
|
|
|
|
if (openfile->current->data[openfile->current_x] == '\0')
|
|
|
|
end_line = TRUE;
|
|
|
|
else
|
|
|
|
openfile->current_x += char_mb_len;
|
|
|
|
|
|
|
|
for (; openfile->current != NULL;
|
|
|
|
openfile->current = openfile->current->next) {
|
|
|
|
while (!end_line) {
|
|
|
|
char_mb_len = parse_mbchar(openfile->current->data +
|
2005-07-26 06:13:45 +00:00
|
|
|
openfile->current_x, char_mb, NULL);
|
2005-07-20 21:31:19 +00:00
|
|
|
|
|
|
|
/* If we've found it, stop moving forward through the
|
|
|
|
* current line. */
|
|
|
|
if (is_word_mbchar(char_mb, allow_punct))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (openfile->current->data[openfile->current_x] == '\0')
|
|
|
|
end_line = TRUE;
|
|
|
|
else
|
|
|
|
openfile->current_x += char_mb_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we've found it, stop moving forward to the beginnings of
|
|
|
|
* subsequent lines. */
|
|
|
|
if (!end_line)
|
|
|
|
break;
|
|
|
|
|
2005-11-03 21:08:39 +00:00
|
|
|
if (openfile->current != openfile->filebot) {
|
2005-07-20 21:31:19 +00:00
|
|
|
end_line = FALSE;
|
|
|
|
openfile->current_x = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(char_mb);
|
|
|
|
|
2007-01-01 05:15:32 +00:00
|
|
|
/* If we haven't found it, move to the end of the file. */
|
2005-11-03 21:38:51 +00:00
|
|
|
if (openfile->current == NULL)
|
2005-07-20 21:31:19 +00:00
|
|
|
openfile->current = openfile->filebot;
|
|
|
|
|
|
|
|
openfile->placewewant = xplustabs();
|
|
|
|
|
|
|
|
/* If allow_update is TRUE, update the screen. */
|
|
|
|
if (allow_update)
|
|
|
|
edit_redraw(current_save, pww_save);
|
|
|
|
|
|
|
|
/* Return whether we started on a word. */
|
|
|
|
return started_on_word;
|
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move to the next word in the file, treating punctuation as part of a
|
|
|
|
* word if the WORD_BOUNDS flag is set, and update the screen
|
|
|
|
* afterwards. */
|
2005-07-20 21:31:19 +00:00
|
|
|
void do_next_word_void(void)
|
|
|
|
{
|
2005-08-10 22:12:28 +00:00
|
|
|
do_next_word(ISSET(WORD_BOUNDS), TRUE);
|
2005-07-20 21:31:19 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move to the previous word in the file. If allow_punct is TRUE, treat
|
|
|
|
* punctuation as part of a word. If allow_update is TRUE, update the
|
|
|
|
* screen afterwards. Return TRUE if we started on a word, and FALSE
|
|
|
|
* otherwise. */
|
2005-07-20 21:31:19 +00:00
|
|
|
bool do_prev_word(bool allow_punct, bool allow_update)
|
|
|
|
{
|
|
|
|
size_t pww_save = openfile->placewewant;
|
2009-01-25 07:25:17 +00:00
|
|
|
filestruct *current_save = openfile->current;
|
2005-07-20 21:31:19 +00:00
|
|
|
char *char_mb;
|
|
|
|
int char_mb_len;
|
|
|
|
bool begin_line = FALSE, started_on_word = FALSE;
|
|
|
|
|
|
|
|
assert(openfile->current != NULL && openfile->current->data != NULL);
|
|
|
|
|
|
|
|
char_mb = charalloc(mb_cur_max());
|
|
|
|
|
|
|
|
/* Move backward until we find the character before the first letter
|
|
|
|
* of the current word. */
|
|
|
|
while (!begin_line) {
|
|
|
|
char_mb_len = parse_mbchar(openfile->current->data +
|
2005-07-26 06:13:45 +00:00
|
|
|
openfile->current_x, char_mb, NULL);
|
2005-07-20 21:31:19 +00:00
|
|
|
|
|
|
|
/* If we've found it, stop moving backward through the current
|
|
|
|
* line. */
|
|
|
|
if (!is_word_mbchar(char_mb, allow_punct))
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* If we haven't found it, then we've started on a word, so set
|
|
|
|
* started_on_word to TRUE. */
|
|
|
|
started_on_word = TRUE;
|
|
|
|
|
|
|
|
if (openfile->current_x == 0)
|
|
|
|
begin_line = TRUE;
|
|
|
|
else
|
|
|
|
openfile->current_x = move_mbleft(openfile->current->data,
|
|
|
|
openfile->current_x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move backward until we find the last letter of the previous
|
|
|
|
* word. */
|
|
|
|
if (openfile->current_x == 0)
|
|
|
|
begin_line = TRUE;
|
|
|
|
else
|
|
|
|
openfile->current_x = move_mbleft(openfile->current->data,
|
|
|
|
openfile->current_x);
|
|
|
|
|
|
|
|
for (; openfile->current != NULL;
|
|
|
|
openfile->current = openfile->current->prev) {
|
|
|
|
while (!begin_line) {
|
|
|
|
char_mb_len = parse_mbchar(openfile->current->data +
|
2005-07-26 06:13:45 +00:00
|
|
|
openfile->current_x, char_mb, NULL);
|
2005-07-20 21:31:19 +00:00
|
|
|
|
|
|
|
/* If we've found it, stop moving backward through the
|
|
|
|
* current line. */
|
|
|
|
if (is_word_mbchar(char_mb, allow_punct))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (openfile->current_x == 0)
|
|
|
|
begin_line = TRUE;
|
|
|
|
else
|
|
|
|
openfile->current_x =
|
|
|
|
move_mbleft(openfile->current->data,
|
|
|
|
openfile->current_x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we've found it, stop moving backward to the ends of
|
|
|
|
* previous lines. */
|
|
|
|
if (!begin_line)
|
|
|
|
break;
|
|
|
|
|
2005-11-03 21:08:39 +00:00
|
|
|
if (openfile->current != openfile->fileage) {
|
2005-07-20 21:31:19 +00:00
|
|
|
begin_line = FALSE;
|
|
|
|
openfile->current_x = strlen(openfile->current->prev->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-01 05:15:32 +00:00
|
|
|
/* If we haven't found it, move to the beginning of the file. */
|
2005-07-20 21:31:19 +00:00
|
|
|
if (openfile->current == NULL)
|
|
|
|
openfile->current = openfile->fileage;
|
|
|
|
/* If we've found it, move backward until we find the character
|
|
|
|
* before the first letter of the previous word. */
|
|
|
|
else if (!begin_line) {
|
|
|
|
if (openfile->current_x == 0)
|
|
|
|
begin_line = TRUE;
|
|
|
|
else
|
|
|
|
openfile->current_x = move_mbleft(openfile->current->data,
|
|
|
|
openfile->current_x);
|
|
|
|
|
|
|
|
while (!begin_line) {
|
2005-07-26 06:13:45 +00:00
|
|
|
char_mb_len = parse_mbchar(openfile->current->data +
|
|
|
|
openfile->current_x, char_mb, NULL);
|
2005-07-20 21:31:19 +00:00
|
|
|
|
|
|
|
/* If we've found it, stop moving backward through the
|
|
|
|
* current line. */
|
|
|
|
if (!is_word_mbchar(char_mb, allow_punct))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (openfile->current_x == 0)
|
|
|
|
begin_line = TRUE;
|
|
|
|
else
|
|
|
|
openfile->current_x =
|
|
|
|
move_mbleft(openfile->current->data,
|
|
|
|
openfile->current_x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we've found it, move forward to the first letter of the
|
|
|
|
* previous word. */
|
|
|
|
if (!begin_line)
|
|
|
|
openfile->current_x += char_mb_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(char_mb);
|
|
|
|
|
|
|
|
openfile->placewewant = xplustabs();
|
|
|
|
|
|
|
|
/* If allow_update is TRUE, update the screen. */
|
|
|
|
if (allow_update)
|
|
|
|
edit_redraw(current_save, pww_save);
|
|
|
|
|
|
|
|
/* Return whether we started on a word. */
|
|
|
|
return started_on_word;
|
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move to the previous word in the file, treating punctuation as part
|
|
|
|
* of a word if the WORD_BOUNDS flag is set, and update the screen
|
|
|
|
* afterwards. */
|
2005-07-20 21:31:19 +00:00
|
|
|
void do_prev_word_void(void)
|
|
|
|
{
|
2005-08-10 22:12:28 +00:00
|
|
|
do_prev_word(ISSET(WORD_BOUNDS), TRUE);
|
2005-07-20 21:31:19 +00:00
|
|
|
}
|
2005-11-15 03:17:35 +00:00
|
|
|
#endif /* !NANO_TINY */
|
2005-07-20 21:31:19 +00:00
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move to the beginning of the current line. If the SMART_HOME flag is
|
|
|
|
* set, move to the first non-whitespace character of the current line
|
2006-04-24 19:44:04 +00:00
|
|
|
* if we aren't already there, or to the beginning of the current line
|
2005-12-08 07:09:08 +00:00
|
|
|
* if we are. */
|
2005-07-20 19:24:11 +00:00
|
|
|
void do_home(void)
|
|
|
|
{
|
|
|
|
size_t pww_save = openfile->placewewant;
|
|
|
|
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2005-07-20 19:24:11 +00:00
|
|
|
if (ISSET(SMART_HOME)) {
|
|
|
|
size_t current_x_save = openfile->current_x;
|
|
|
|
|
|
|
|
openfile->current_x = indent_length(openfile->current->data);
|
|
|
|
|
|
|
|
if (openfile->current_x == current_x_save ||
|
|
|
|
openfile->current->data[openfile->current_x] == '\0')
|
|
|
|
openfile->current_x = 0;
|
|
|
|
|
|
|
|
openfile->placewewant = xplustabs();
|
|
|
|
} else {
|
|
|
|
#endif
|
|
|
|
openfile->current_x = 0;
|
|
|
|
openfile->placewewant = 0;
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2005-07-20 19:24:11 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (need_horizontal_update(pww_save))
|
|
|
|
update_line(openfile->current, openfile->current_x);
|
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move to the end of the current line. */
|
2005-07-20 19:24:11 +00:00
|
|
|
void do_end(void)
|
|
|
|
{
|
|
|
|
size_t pww_save = openfile->placewewant;
|
|
|
|
|
|
|
|
openfile->current_x = strlen(openfile->current->data);
|
|
|
|
openfile->placewewant = xplustabs();
|
|
|
|
|
|
|
|
if (need_horizontal_update(pww_save))
|
|
|
|
update_line(openfile->current, openfile->current_x);
|
|
|
|
}
|
|
|
|
|
2006-07-06 22:17:47 +00:00
|
|
|
/* If scroll_only is FALSE, move up one line. If scroll_only is TRUE,
|
|
|
|
* scroll up one line without scrolling the cursor. */
|
|
|
|
void do_up(
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
bool scroll_only
|
|
|
|
#else
|
|
|
|
void
|
|
|
|
#endif
|
|
|
|
)
|
2000-06-19 04:22:15 +00:00
|
|
|
{
|
2006-07-06 22:17:47 +00:00
|
|
|
/* If we're at the top of the file, or if scroll_only is TRUE and
|
|
|
|
* the top of the file is onscreen, get out. */
|
|
|
|
if (openfile->current == openfile->fileage
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
|| (scroll_only && openfile->edittop == openfile->fileage)
|
|
|
|
#endif
|
|
|
|
)
|
2004-07-02 14:31:03 +00:00
|
|
|
return;
|
2003-09-07 23:57:24 +00:00
|
|
|
|
2009-09-03 23:29:14 +00:00
|
|
|
assert(ISSET(SOFTWRAP) || openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);
|
2005-03-09 20:35:10 +00:00
|
|
|
|
2005-07-16 22:35:11 +00:00
|
|
|
/* Move the current line of the edit window up. */
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current = openfile->current->prev;
|
|
|
|
openfile->current_x = actual_x(openfile->current->data,
|
|
|
|
openfile->placewewant);
|
2004-05-28 20:44:09 +00:00
|
|
|
|
2006-07-06 22:17:47 +00:00
|
|
|
/* If scroll_only is FALSE and if we're on the first line of the
|
|
|
|
* edit window, scroll the edit window up one line if we're in
|
|
|
|
* smooth scrolling mode, or up half a page if we're not. If
|
|
|
|
* scroll_only is TRUE, scroll the edit window up one line
|
|
|
|
* unconditionally. */
|
2009-09-03 23:29:14 +00:00
|
|
|
if (openfile->current_y == 0 || (ISSET(SOFTWRAP) && openfile->edittop->lineno == openfile->current->next->lineno)
|
2006-07-06 22:17:47 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
|| scroll_only
|
|
|
|
#endif
|
|
|
|
)
|
2006-07-19 00:14:52 +00:00
|
|
|
edit_scroll(UP_DIR,
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2006-07-06 22:17:47 +00:00
|
|
|
(ISSET(SMOOTH_SCROLL) || scroll_only) ? 1 :
|
2003-09-07 23:57:24 +00:00
|
|
|
#endif
|
2010-01-13 03:21:19 +00:00
|
|
|
editwinrows / 2 + 1);
|
2006-07-06 22:17:47 +00:00
|
|
|
|
|
|
|
/* If we're below the first line of the edit window, update the
|
2006-07-06 20:36:01 +00:00
|
|
|
* line we were on before and the line we're on now. The former
|
|
|
|
* needs to be redrawn if we're not on the first page, and the
|
|
|
|
* latter needs to be drawn unconditionally. */
|
2006-07-06 22:17:47 +00:00
|
|
|
if (openfile->current_y > 0) {
|
2005-07-16 22:50:30 +00:00
|
|
|
if (need_vertical_update(0))
|
|
|
|
update_line(openfile->current->next, 0);
|
|
|
|
update_line(openfile->current, openfile->current_x);
|
|
|
|
}
|
2002-07-19 01:08:59 +00:00
|
|
|
}
|
2000-06-19 04:22:15 +00:00
|
|
|
|
2006-07-06 22:17:47 +00:00
|
|
|
/* Move up one line. */
|
|
|
|
void do_up_void(void)
|
|
|
|
{
|
|
|
|
do_up(
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
FALSE
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Scroll up one line without scrolling the cursor. */
|
2005-10-24 02:12:09 +00:00
|
|
|
void do_scroll_up(void)
|
|
|
|
{
|
2006-07-06 22:17:47 +00:00
|
|
|
do_up(TRUE);
|
2005-10-24 02:12:09 +00:00
|
|
|
}
|
2006-07-06 22:17:47 +00:00
|
|
|
#endif
|
2005-10-24 02:12:09 +00:00
|
|
|
|
2006-07-06 22:17:47 +00:00
|
|
|
/* If scroll_only is FALSE, move down one line. If scroll_only is TRUE,
|
|
|
|
* scroll down one line without scrolling the cursor. */
|
|
|
|
void do_down(
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
bool scroll_only
|
|
|
|
#else
|
|
|
|
void
|
|
|
|
#endif
|
|
|
|
)
|
2002-12-22 16:30:00 +00:00
|
|
|
{
|
2009-08-30 03:50:16 +00:00
|
|
|
bool onlastline = FALSE;
|
|
|
|
|
2005-07-14 18:01:08 +00:00
|
|
|
/* If we're at the bottom of the file, get out. */
|
2005-11-03 21:08:39 +00:00
|
|
|
if (openfile->current == openfile->filebot)
|
2004-07-02 14:31:03 +00:00
|
|
|
return;
|
2002-07-19 01:08:59 +00:00
|
|
|
|
2009-08-30 03:50:16 +00:00
|
|
|
|
|
|
|
assert(ISSET(SOFTWRAP) || openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);
|
2005-06-28 18:57:28 +00:00
|
|
|
|
2005-07-16 22:35:11 +00:00
|
|
|
/* Move the current line of the edit window down. */
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current = openfile->current->next;
|
|
|
|
openfile->current_x = actual_x(openfile->current->data,
|
|
|
|
openfile->placewewant);
|
2002-07-19 01:08:59 +00:00
|
|
|
|
2009-08-30 03:50:16 +00:00
|
|
|
if (ISSET(SOFTWRAP)) {
|
2009-11-26 18:23:00 +00:00
|
|
|
if (openfile->current->lineno - openfile->edittop->lineno >= maxrows)
|
2009-08-30 03:50:16 +00:00
|
|
|
onlastline = TRUE;
|
|
|
|
}
|
|
|
|
|
2006-07-06 22:17:47 +00:00
|
|
|
/* If scroll_only is FALSE and if we're on the first line of the
|
|
|
|
* edit window, scroll the edit window down one line if we're in
|
|
|
|
* smooth scrolling mode, or down half a page if we're not. If
|
|
|
|
* scroll_only is TRUE, scroll the edit window down one line
|
|
|
|
* unconditionally. */
|
2009-08-30 03:50:16 +00:00
|
|
|
if (onlastline || openfile->current_y == editwinrows - 1
|
2006-07-06 22:17:47 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
|| scroll_only
|
|
|
|
#endif
|
2010-01-13 03:21:19 +00:00
|
|
|
) {
|
2006-07-19 00:14:52 +00:00
|
|
|
edit_scroll(DOWN_DIR,
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2006-07-06 22:17:47 +00:00
|
|
|
(ISSET(SMOOTH_SCROLL) || scroll_only) ? 1 :
|
2003-09-07 23:57:24 +00:00
|
|
|
#endif
|
2010-01-13 03:21:19 +00:00
|
|
|
editwinrows / 2 + 1);
|
2006-07-06 22:17:47 +00:00
|
|
|
|
2010-01-13 03:21:19 +00:00
|
|
|
edit_refresh_needed = TRUE;
|
|
|
|
}
|
2006-07-06 22:17:47 +00:00
|
|
|
/* If we're above the last line of the edit window, update the line
|
2006-07-06 20:36:01 +00:00
|
|
|
* we were on before and the line we're on now. The former needs to
|
|
|
|
* be redrawn if we're not on the first page, and the latter needs
|
|
|
|
* to be drawn unconditionally. */
|
2009-08-30 03:50:16 +00:00
|
|
|
if (ISSET(SOFTWRAP) || openfile->current_y < editwinrows - 1) {
|
2005-07-16 22:50:30 +00:00
|
|
|
if (need_vertical_update(0))
|
|
|
|
update_line(openfile->current->prev, 0);
|
|
|
|
update_line(openfile->current, openfile->current_x);
|
|
|
|
}
|
2000-06-19 04:22:15 +00:00
|
|
|
}
|
2005-10-24 02:12:09 +00:00
|
|
|
|
2006-07-06 22:17:47 +00:00
|
|
|
/* Move down one line. */
|
|
|
|
void do_down_void(void)
|
|
|
|
{
|
|
|
|
do_down(
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
FALSE
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Scroll down one line without scrolling the cursor. */
|
2005-10-24 02:12:09 +00:00
|
|
|
void do_scroll_down(void)
|
|
|
|
{
|
2006-07-06 22:17:47 +00:00
|
|
|
do_down(TRUE);
|
2005-10-24 02:12:09 +00:00
|
|
|
}
|
2006-07-06 22:17:47 +00:00
|
|
|
#endif
|
2000-06-19 04:22:15 +00:00
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move left one character. */
|
2005-09-13 04:53:44 +00:00
|
|
|
void do_left(void)
|
2000-06-19 04:22:15 +00:00
|
|
|
{
|
2005-07-08 20:09:16 +00:00
|
|
|
size_t pww_save = openfile->placewewant;
|
|
|
|
|
|
|
|
if (openfile->current_x > 0)
|
|
|
|
openfile->current_x = move_mbleft(openfile->current->data,
|
|
|
|
openfile->current_x);
|
|
|
|
else if (openfile->current != openfile->fileage) {
|
2006-07-06 22:17:47 +00:00
|
|
|
do_up_void();
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current_x = strlen(openfile->current->data);
|
2000-06-19 04:22:15 +00:00
|
|
|
}
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->placewewant = xplustabs();
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2005-09-13 04:53:44 +00:00
|
|
|
if (need_horizontal_update(pww_save))
|
2005-07-08 20:09:16 +00:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
2000-06-19 04:22:15 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move right one character. */
|
2005-09-13 04:53:44 +00:00
|
|
|
void do_right(void)
|
2000-06-19 04:22:15 +00:00
|
|
|
{
|
2005-07-08 20:09:16 +00:00
|
|
|
size_t pww_save = openfile->placewewant;
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
assert(openfile->current_x <= strlen(openfile->current->data));
|
2002-09-06 20:35:28 +00:00
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
if (openfile->current->data[openfile->current_x] != '\0')
|
|
|
|
openfile->current_x = move_mbright(openfile->current->data,
|
|
|
|
openfile->current_x);
|
2005-11-03 21:08:39 +00:00
|
|
|
else if (openfile->current != openfile->filebot) {
|
2006-07-06 22:17:47 +00:00
|
|
|
do_down_void();
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current_x = 0;
|
2000-06-19 04:22:15 +00:00
|
|
|
}
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->placewewant = xplustabs();
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2005-09-13 04:53:44 +00:00
|
|
|
if (need_horizontal_update(pww_save))
|
2005-07-08 20:09:16 +00:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
2000-06-19 04:22:15 +00:00
|
|
|
}
|