Commit 14b3ca94 authored by Chris Allegretta's avatar Chris Allegretta
Browse files

- General - New flag RELATIVECHARS to show column positino relative to the...

- General - New flag RELATIVECHARS to show column positino relative to the current line instead of the current file.  New flag -C, --relative, changes to do_cursorpos()


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1046 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 52 additions and 22 deletions
+52 -22
CVS code - CVS code -
- General
- New flag RELATIVECHARS to show column positino relative to
the current line instead of the current file. New flag
-C, --relative, changes to do_cursorpos().
- po/ca.po, po/es.po: - po/ca.po, po/es.po:
- Catalan and Spanish translation updates (Jordi). - Catalan and Spanish translation updates (Jordi).
......
...@@ -409,6 +409,9 @@ void usage(void) ...@@ -409,6 +409,9 @@ void usage(void)
printf(_("Usage: nano [GNU long option] [option] +LINE <file>\n\n")); printf(_("Usage: nano [GNU long option] [option] +LINE <file>\n\n"));
printf(_("Option Long option Meaning\n")); printf(_("Option Long option Meaning\n"));
printf
(_
(" -C --relative Show relative col position with ^C\n"));
#ifndef NANO_SMALL #ifndef NANO_SMALL
printf printf
(_ (_
...@@ -489,6 +492,7 @@ void usage(void) ...@@ -489,6 +492,7 @@ void usage(void)
#else #else
printf(_("Usage: nano [option] +LINE <file>\n\n")); printf(_("Usage: nano [option] +LINE <file>\n\n"));
printf(_("Option Meaning\n")); printf(_("Option Meaning\n"));
printf(_(" -C Show relative col position with ^C\n"));
#ifndef NANO_SMALL #ifndef NANO_SMALL
printf(_(" -D Write file in DOS format\n")); printf(_(" -D Write file in DOS format\n"));
#endif #endif
...@@ -2736,7 +2740,7 @@ int main(int argc, char *argv[]) ...@@ -2736,7 +2740,7 @@ int main(int argc, char *argv[])
{"smooth", 0, 0, 'S'}, {"smooth", 0, 0, 'S'},
#endif #endif
{"keypad", 0, 0, 'K'}, {"keypad", 0, 0, 'K'},
{"relative", 0, 0, 'C'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
#endif #endif
...@@ -2757,15 +2761,18 @@ int main(int argc, char *argv[]) ...@@ -2757,15 +2761,18 @@ int main(int argc, char *argv[])
#endif /* ENABLE_NANORC */ #endif /* ENABLE_NANORC */
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
while ((optchr = getopt_long(argc, argv, "h?DFKMRST:Vabcefgijklmo:pr:s:tvwxz", while ((optchr = getopt_long(argc, argv, "h?CDFKMRST:Vabcefgijklmo:pr:s:tvwxz",
long_options, &option_index)) != EOF) { long_options, &option_index)) != EOF) {
#else #else
while ((optchr = while ((optchr =
getopt(argc, argv, "h?DFKMRST:Vabcefgijklmo:pr:s:tvwxz")) != EOF) { getopt(argc, argv, "h?CDFKMRST:Vabcefgijklmo:pr:s:tvwxz")) != EOF) {
#endif #endif
switch (optchr) { switch (optchr) {
case 'C':
SET(RELATIVECHARS);
break;
#ifndef NANO_SMALL #ifndef NANO_SMALL
case 'D': case 'D':
SET(DOS_FILE); SET(DOS_FILE);
......
...@@ -162,6 +162,7 @@ typedef struct colortype { ...@@ -162,6 +162,7 @@ typedef struct colortype {
#define SMOOTHSCROLL (1<<23) #define SMOOTHSCROLL (1<<23)
#define DISABLE_CURPOS (1<<24) /* Damn, we still need it */ #define DISABLE_CURPOS (1<<24) /* Damn, we still need it */
#define ALT_KEYPAD (1<<25) /* Damn, we still need it */ #define ALT_KEYPAD (1<<25) /* Damn, we still need it */
#define RELATIVECHARS (1<<26)
/* Control key sequences, changing these would be very very bad */ /* Control key sequences, changing these would be very very bad */
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
# Constantly update the cursor position # Constantly update the cursor position
# set const # set const
# Show column position relative to the current line, not the whole file
# set relative
# Use cut to end of line with ^K by default # Use cut to end of line with ^K by default
# set cut # set cut
......
...@@ -41,9 +41,9 @@ ...@@ -41,9 +41,9 @@
#endif #endif
#ifndef DISABLE_WRAPJUSTIFY #ifndef DISABLE_WRAPJUSTIFY
#define NUM_RCOPTS 19 #define NUM_RCOPTS 20
#else #else
#define NUM_RCOPTS 18 #define NUM_RCOPTS 19
#endif #endif
/* Static stuff for the nanorc file */ /* Static stuff for the nanorc file */
...@@ -70,7 +70,8 @@ rcoption rcopts[NUM_RCOPTS] = { ...@@ -70,7 +70,8 @@ rcoption rcopts[NUM_RCOPTS] = {
{"suspend", SUSPEND}, {"suspend", SUSPEND},
{"multibuffer", MULTIBUFFER}, {"multibuffer", MULTIBUFFER},
{"smooth", SMOOTHSCROLL}, {"smooth", SMOOTHSCROLL},
{"keypad", ALT_KEYPAD} {"keypad", ALT_KEYPAD},
{"relative", RELATIVECHARS}
}; };
static int errors = 0; static int errors = 0;
......
...@@ -1586,32 +1586,47 @@ int do_cursorpos(int constant) ...@@ -1586,32 +1586,47 @@ int do_cursorpos(int constant)
{ {
filestruct *fileptr; filestruct *fileptr;
float linepct = 0.0, bytepct = 0.0; float linepct = 0.0, bytepct = 0.0;
long i = 0; long i = 0, j = 0;
static long old_i = -1, old_totsize = -1; static long old_i = -1, old_totsize = -1;
if (current == NULL || fileage == NULL) if (current == NULL || fileage == NULL)
return 0; return 0;
for (fileptr = fileage; fileptr != current && fileptr != NULL;
fileptr = fileptr->next)
i += strlen(fileptr->data) + 1;
if (fileptr == NULL)
return -1;
i += current_x;
if (old_i == -1) if (old_i == -1)
old_i = i; old_i = i;
if (old_totsize == -1) if (old_totsize == -1)
old_totsize = totsize; old_totsize = totsize;
if (totlines > 0) if (ISSET(RELATIVECHARS)) {
linepct = 100 * current->lineno / totlines;
if (strlen(current->data) == 0)
bytepct = 0;
else
bytepct = 100 * current_x / strlen(current->data);
old_i = -1;
i = current_x;
j = strlen(current->data);
if (totsize > 0) } else {
bytepct = 100 * i / totsize; for (fileptr = fileage; fileptr != current && fileptr != NULL;
fileptr = fileptr->next)
i += strlen(fileptr->data) + 1;
if (fileptr == NULL)
return -1;
i += current_x;
j = totsize;
if (totsize > 0)
bytepct = 100 * i / totsize;
}
if (totlines > 0)
linepct = 100 * current->lineno / totlines;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, _("do_cursorpos: linepct = %f, bytepct = %f\n"), fprintf(stderr, _("do_cursorpos: linepct = %f, bytepct = %f\n"),
...@@ -1624,7 +1639,7 @@ int do_cursorpos(int constant) ...@@ -1624,7 +1639,7 @@ int do_cursorpos(int constant)
if (!constant || (old_i != i || old_totsize != totsize)) { if (!constant || (old_i != i || old_totsize != totsize)) {
statusbar(_ statusbar(_
("line %d of %d (%.0f%%), character %ld of %ld (%.0f%%)"), ("line %d of %d (%.0f%%), character %ld of %ld (%.0f%%)"),
current->lineno, totlines, linepct, i, totsize, bytepct); current->lineno, totlines, linepct, i, j, bytepct);
} }
old_i = i; old_i = i;
......
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