Commit c7acf69c authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

add smart home key

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1751 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 90 additions and 7 deletions
+90 -7
...@@ -53,6 +53,16 @@ CVS code - ...@@ -53,6 +53,16 @@ CVS code -
- Wrap the long jump code in NANO_SMALL #ifdefs, since we only - Wrap the long jump code in NANO_SMALL #ifdefs, since we only
use it if we're resizing the window, which is disabled when use it if we're resizing the window, which is disabled when
NANO_SMALL is defined. (DLR) NANO_SMALL is defined. (DLR)
- Add smart home key option, accessible via -A/--smarthome on
the command line, "set smarthome" in the rcfile, and the
Meta-H toggle in the edit window. Smart home works as
follows: When Home is pressed anywhere but at the very
beginning of non-whitespace characters on a line, the cursor
will jump to that beginning (either forwards or backwards).
If the cursor is already at that position, it will jump to the
true beginning of the line. This option is disabled in tiny
mode. Changes to do_home(), nanogetstr(), etc. (DLR;
suggested by Stephan T. Lavavej)
- files.c: - files.c:
add_open_file() add_open_file()
- Rearrange the NANO_SMALL #ifdef so that the code to set the - Rearrange the NANO_SMALL #ifdef so that the code to set the
...@@ -231,6 +241,7 @@ CVS code - ...@@ -231,6 +241,7 @@ CVS code -
- nano.1: - nano.1:
- Document restricted mode. (IO ERROR) DLR: Add minor - Document restricted mode. (IO ERROR) DLR: Add minor
modifications to account for the above changes. modifications to account for the above changes.
- Document the smart home key option. (DLR)
- nano.texi: - nano.texi:
- Fix toggle inaccuracies: Meta-L now toggles line wrapping, and - Fix toggle inaccuracies: Meta-L now toggles line wrapping, and
Meta-< and Meta-> aren't toggles. (DLR) Meta-< and Meta-> aren't toggles. (DLR)
...@@ -239,9 +250,11 @@ CVS code - ...@@ -239,9 +250,11 @@ CVS code -
- Fix version number inaccuracies: Search/replace history and - Fix version number inaccuracies: Search/replace history and
sorting/uniqueness filtering for the internal spell chacker sorting/uniqueness filtering for the internal spell chacker
were added in nano 1.1.99pre1. (DLR) were added in nano 1.1.99pre1. (DLR)
- Document the smart home key option. (DLR)
- nanorc.sample: - nanorc.sample:
- Add missing mouse entry, and update the nanorc sample regexes - Add missing mouse entry, and update the nanorc sample regexes
to account for the backupdir and mouse options. (DLR) to account for the backupdir and mouse options. (DLR)
- Add smarthome description. (DLR)
- README.CVS: - README.CVS:
- Increase the minimum required autoconf version to 2.54, and - Increase the minimum required autoconf version to 2.54, and
change the recommended automake version 1.7 to the minimum change the recommended automake version 1.7 to the minimum
......
...@@ -35,6 +35,13 @@ replace" and "go to line number". ...@@ -35,6 +35,13 @@ replace" and "go to line number".
.B \+\fILINE\fP .B \+\fILINE\fP
Places cursor at \fILINE\fP on startup. Places cursor at \fILINE\fP on startup.
.TP .TP
.B \-A (\-\-smarthome)
Make the Home key smarter. When Home is pressed anywhere but at the
very beginning of non-whitespace characters on a line, the cursor will
jump to that beginning (either forwards or backwards). If the cursor is
already at that position, it will jump to the true beginning of the
line.
.TP
.B \-B (\-\-backup) .B \-B (\-\-backup)
When saving a file, back up the previous version of it to the current When saving a file, back up the previous version of it to the current
filename suffixed with a ~. filename suffixed with a ~.
......
...@@ -108,6 +108,13 @@ acts like Delete on your system. ...@@ -108,6 +108,13 @@ acts like Delete on your system.
\fBset/unset regexp\fP \fBset/unset regexp\fP
Do regular expression searches by default. Do regular expression searches by default.
.TP .TP
\fBset/unset smarthome\fP
Make the Home key smarter. When Home is pressed anywhere but at the
very beginning of non-whitespace characters on a line, the cursor will
jump to that beginning (either forwards or backwards). If the cursor is
already at that position, it will jump to the true beginning of the
line.
.TP
\fBset/unset smooth\fP \fBset/unset smooth\fP
Use smooth scrolling by default. Use smooth scrolling by default.
.TP .TP
......
...@@ -79,6 +79,13 @@ ...@@ -79,6 +79,13 @@
## Do extended regular expression searches by default. ## Do extended regular expression searches by default.
# set regexp # set regexp
## Make the Home key smarter. When Home is pressed anywhere but at the
## very beginning of non-whitespace characters on a line, the cursor
## will jump to that beginning (either forwards or backwards). If the
## cursor is already at that position, it will jump to the true
## beginning of the line.
# set smarthome
## Use smooth scrolling as the default. ## Use smooth scrolling as the default.
# set smooth # set smooth
...@@ -208,7 +215,7 @@ ...@@ -208,7 +215,7 @@
## highlight possible errors and parameters ## highlight possible errors and parameters
#color brightwhite "^ *(set|unset|syntax|color).*$" #color brightwhite "^ *(set|unset|syntax|color).*$"
## set, unset and syntax ## set, unset and syntax
#color cyan "^ *(set|unset) +(autoindent|backup|backupdir|const|cut|fill|historylog|mouse|multibuffer|noconvert|nofollow|nohelp|nowrap|operatingdir|preserve|quotestr|rebinddelete|regexp|smooth|speller|suspend|tabsize|tempfile|view)" #color cyan "^ *(set|unset) +(autoindent|backup|backupdir|const|cut|fill|historylog|mouse|multibuffer|noconvert|nofollow|nohelp|nowrap|operatingdir|preserve|quotestr|rebinddelete|regexp|smarthome|smooth|speller|suspend|tabsize|tempfile|view)"
#color green "^ *(set|unset|syntax)\>" #color green "^ *(set|unset|syntax)\>"
## colors ## colors
#color yellow "^ *color +(bright)?(white|black|red|blue|green|yellow|magenta|cyan)(,(white|black|red|blue|green|yellow|magenta|cyan))?\>" #color yellow "^ *color +(bright)?(white|black|red|blue|green|yellow|magenta|cyan)(,(white|black|red|blue|green|yellow|magenta|cyan))?\>"
......
...@@ -107,6 +107,13 @@ Email bug reports to @email{nano@@nano-editor.org}. ...@@ -107,6 +107,13 @@ Email bug reports to @email{nano@@nano-editor.org}.
@table @code @table @code
@item -A, --smarthome
Make the Home key smarter. When Home is pressed anywhere but at the
very beginning of non-whitespace characters on a line, the cursor will
jump to that beginning (either forwards or backwards). If the cursor is
already at that position, it will jump to the true beginning of the
line.
@item -B, --backup @item -B, --backup
When saving a file, back up the previous version of it to the current When saving a file, back up the previous version of it to the current
filename suffixed with a ~. filename suffixed with a ~.
...@@ -346,6 +353,9 @@ toggles the -D (@code{--dos}) command line flag. ...@@ -346,6 +353,9 @@ toggles the -D (@code{--dos}) command line flag.
@item Multiple Files Toggle (Meta-F) @item Multiple Files Toggle (Meta-F)
toggles the -F (@code{--multibuffer}) command line flag. toggles the -F (@code{--multibuffer}) command line flag.
@item Backup File Toggle (Meta-H)
toggles the -A (@code{--smarthome}) command line flag.
@item AutoIndent Toggle (Meta-I) @item AutoIndent Toggle (Meta-I)
toggles the -i (@code{--autoindent}) command line flag. toggles the -i (@code{--autoindent}) command line flag.
......
...@@ -231,7 +231,7 @@ void toggle_init(void) ...@@ -231,7 +231,7 @@ void toggle_init(void)
char *toggle_const_msg, *toggle_autoindent_msg, *toggle_suspend_msg, char *toggle_const_msg, *toggle_autoindent_msg, *toggle_suspend_msg,
*toggle_nohelp_msg, *toggle_cuttoend_msg, *toggle_nohelp_msg, *toggle_cuttoend_msg,
*toggle_noconvert_msg, *toggle_dos_msg, *toggle_mac_msg, *toggle_noconvert_msg, *toggle_dos_msg, *toggle_mac_msg,
*toggle_backup_msg, *toggle_smooth_msg; *toggle_backup_msg, *toggle_smooth_msg, *toggle_smarthome_msg;
#ifndef DISABLE_MOUSE #ifndef DISABLE_MOUSE
char *toggle_mouse_msg; char *toggle_mouse_msg;
#endif #endif
...@@ -263,6 +263,7 @@ void toggle_init(void) ...@@ -263,6 +263,7 @@ void toggle_init(void)
toggle_mac_msg = _("Writing file in Mac format"); toggle_mac_msg = _("Writing file in Mac format");
toggle_backup_msg = _("Backing up file"); toggle_backup_msg = _("Backing up file");
toggle_smooth_msg = _("Smooth scrolling"); toggle_smooth_msg = _("Smooth scrolling");
toggle_smarthome_msg = _("Smart home key");
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
toggle_syntax_msg = _("Color syntax highlighting"); toggle_syntax_msg = _("Color syntax highlighting");
#endif #endif
...@@ -296,6 +297,7 @@ void toggle_init(void) ...@@ -296,6 +297,7 @@ void toggle_init(void)
toggle_init_one(TOGGLE_BACKUP_KEY, toggle_backup_msg, BACKUP_FILE); toggle_init_one(TOGGLE_BACKUP_KEY, toggle_backup_msg, BACKUP_FILE);
} }
toggle_init_one(TOGGLE_SMOOTH_KEY, toggle_smooth_msg, SMOOTHSCROLL); toggle_init_one(TOGGLE_SMOOTH_KEY, toggle_smooth_msg, SMOOTHSCROLL);
toggle_init_one(TOGGLE_SMARTHOME_KEY, toggle_smarthome_msg, SMART_HOME);
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
toggle_init_one(TOGGLE_SYNTAX_KEY, toggle_syntax_msg, COLOR_SYNTAX); toggle_init_one(TOGGLE_SYNTAX_KEY, toggle_syntax_msg, COLOR_SYNTAX);
#endif #endif
......
...@@ -23,14 +23,32 @@ ...@@ -23,14 +23,32 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include <assert.h> #include <assert.h>
#include "proto.h" #include "proto.h"
#include "nano.h" #include "nano.h"
int do_home(void) int do_home(void)
{ {
current_x = 0; #ifndef NANO_SMALL
placewewant = 0; if (ISSET(SMART_HOME)) {
int old_current_x = current_x;
for (current_x = 0; isblank(current->data[current_x]) &&
current->data[current_x] != '\0'; current_x++)
;
if (current_x == old_current_x || current->data[current_x] == '\0')
current_x = 0;
placewewant = xplustabs();
} else {
#endif
current_x = 0;
placewewant = 0;
#ifndef NANO_SMALL
}
#endif
check_statblank(); check_statblank();
update_line(current, current_x); update_line(current, current_x);
return 1; return 1;
......
...@@ -633,6 +633,7 @@ void usage(void) ...@@ -633,6 +633,7 @@ void usage(void)
print1opt("-h, -?", "--help", _("Show this message")); print1opt("-h, -?", "--help", _("Show this message"));
print1opt(_("+LINE"), "", _("Start at line number LINE")); print1opt(_("+LINE"), "", _("Start at line number LINE"));
#ifndef NANO_SMALL #ifndef NANO_SMALL
print1opt("-A", "--smarthome", _("Enable smart home key"));
print1opt("-B", "--backup", _("Backup existing files on save")); print1opt("-B", "--backup", _("Backup existing files on save"));
print1opt("-D", "--dos", _("Write file in DOS format")); print1opt("-D", "--dos", _("Write file in DOS format"));
print1opt("-E", "--backupdir=[dir]", _("Directory for writing backup files")); print1opt("-E", "--backupdir=[dir]", _("Directory for writing backup files"));
...@@ -3057,6 +3058,7 @@ int main(int argc, char *argv[]) ...@@ -3057,6 +3058,7 @@ int main(int argc, char *argv[])
{"nohelp", 0, 0, 'x'}, {"nohelp", 0, 0, 'x'},
{"suspend", 0, 0, 'z'}, {"suspend", 0, 0, 'z'},
#ifndef NANO_SMALL #ifndef NANO_SMALL
{"smarthome", 0, 0, 'A'},
{"backup", 0, 0, 'B'}, {"backup", 0, 0, 'B'},
{"dos", 0, 0, 'D'}, {"dos", 0, 0, 'D'},
{"backupdir", 1, 0, 'E'}, {"backupdir", 1, 0, 'E'},
...@@ -3085,11 +3087,11 @@ int main(int argc, char *argv[]) ...@@ -3085,11 +3087,11 @@ int main(int argc, char *argv[])
#endif #endif
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
while ((optchr = getopt_long(argc, argv, "h?BDE:FHIMNQ:RST:VY:Zabcdefgijklmo:pr:s:tvwxz", while ((optchr = getopt_long(argc, argv, "h?ABDE:FHIMNQ:RST:VY:Zabcdefgijklmo:pr:s:tvwxz",
long_options, NULL)) != -1) { long_options, NULL)) != -1) {
#else #else
while ((optchr = while ((optchr =
getopt(argc, argv, "h?BDE:FHIMNQ:RST:VY:Zabcdefgijklmo:pr:s:tvwxz")) != -1) { getopt(argc, argv, "h?ABDE:FHIMNQ:RST:VY:Zabcdefgijklmo:pr:s:tvwxz")) != -1) {
#endif #endif
switch (optchr) { switch (optchr) {
...@@ -3103,6 +3105,9 @@ int main(int argc, char *argv[]) ...@@ -3103,6 +3105,9 @@ int main(int argc, char *argv[])
/* Pico compatibility flags */ /* Pico compatibility flags */
break; break;
#ifndef NANO_SMALL #ifndef NANO_SMALL
case 'A':
SET(SMART_HOME);
break;
case 'B': case 'B':
SET(BACKUP_FILE); SET(BACKUP_FILE);
break; break;
......
...@@ -278,6 +278,7 @@ typedef struct historyheadtype { ...@@ -278,6 +278,7 @@ typedef struct historyheadtype {
#define HISTORY_CHANGED (1<<27) #define HISTORY_CHANGED (1<<27)
#define HISTORYLOG (1<<28) #define HISTORYLOG (1<<28)
#define RESTRICTED (1<<29) #define RESTRICTED (1<<29)
#define SMART_HOME (1<<30)
/* Control key sequences, changing these would be very very bad. */ /* Control key sequences, changing these would be very very bad. */
#define NANO_CONTROL_SPACE 0 #define NANO_CONTROL_SPACE 0
...@@ -446,6 +447,7 @@ typedef struct historyheadtype { ...@@ -446,6 +447,7 @@ typedef struct historyheadtype {
#define TOGGLE_NOCONVERT_KEY NANO_ALT_N #define TOGGLE_NOCONVERT_KEY NANO_ALT_N
#define TOGGLE_BACKUP_KEY NANO_ALT_B #define TOGGLE_BACKUP_KEY NANO_ALT_B
#define TOGGLE_SYNTAX_KEY NANO_ALT_Y #define TOGGLE_SYNTAX_KEY NANO_ALT_Y
#define TOGGLE_SMARTHOME_KEY NANO_ALT_H
#endif /* !NANO_SMALL */ #endif /* !NANO_SMALL */
#define MAIN_VISIBLE 12 #define MAIN_VISIBLE 12
......
...@@ -80,6 +80,7 @@ const static rcoption rcopts[] = { ...@@ -80,6 +80,7 @@ const static rcoption rcopts[] = {
{"regexp", USE_REGEXP}, {"regexp", USE_REGEXP},
#endif #endif
#ifndef NANO_SMALL #ifndef NANO_SMALL
{"smarthome", SMART_HOME},
{"smooth", SMOOTHSCROLL}, {"smooth", SMOOTHSCROLL},
#endif #endif
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER
......
...@@ -1332,7 +1332,18 @@ int nanogetstr(int allowtabs, const char *buf, const char *def, ...@@ -1332,7 +1332,18 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
break; break;
#endif #endif
case NANO_HOME_KEY: case NANO_HOME_KEY:
x = 0; #ifndef NANO_SMALL
if (ISSET(SMART_HOME)) {
int old_x = x;
for (x = 0; isblank(answer[x]) && x < xend; x++)
;
if (x == old_x || x == xend)
x = 0;
} else
#endif
x = 0;
break; break;
case NANO_END_KEY: case NANO_END_KEY:
x = xend; x = xend;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment