commit aee00d4d144e9030990a7a0d53376830df503a77
parent 7f801743736ee515cccc1e8dc6ca7c74a674cd03
Author: David Lawrence Ramsey <pooka109@gmail.com>
Date: Wed, 5 Jul 2006 18:42:22 +0000
if the mark isn't on, allow Meta-} and Meta-{ to indent and unindent
only the current line, just as it would if the mark covered only the
current line, instead of displaying a statusbar message and quitting
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3758 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Diffstat:
5 files changed, 46 insertions(+), 37 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -14,6 +14,14 @@ CVS code -
actually blanked. Changes to do_help(), do_continue(),
handle_sigwinch(), and update_statusbar_line(). (DLR)
(DLR)
+ - If the mark isn't on, allow Meta-} and Meta-{ to indent and
+ unindent only the current line, just as it would if the mark
+ covered only the current line, instead of displaying a
+ statusbar message and quitting. Changes to shortcut_init(),
+ do_indent_marked() (renamed do_indent()),
+ do_indent_marked_void() (renamed do_indent_void()), and
+ do_unindent_marked_void() (renamed do_unindent()). (DLR,
+ suggested by John M. Gabriele)
- browser.c:
do_browser()
- Refactor the mouse support, modeling it after do_mouse() for
diff --git a/src/global.c b/src/global.c
@@ -349,8 +349,8 @@ void shortcut_init(bool unjustify)
const char *nano_whereis_next_msg = N_("Repeat last search");
const char *nano_copy_msg =
N_("Copy the current line and store it in the cutbuffer");
- const char *nano_indentmarked_msg = N_("Indent marked text");
- const char *nano_unindentmarked_msg = N_("Unindent marked text");
+ const char *nano_indent_msg = N_("Indent the current line");
+ const char *nano_unindent_msg = N_("Unindent the current line");
#endif
const char *nano_forward_msg = N_("Move forward one character");
const char *nano_back_msg = N_("Move back one character");
@@ -588,12 +588,12 @@ void shortcut_init(bool unjustify)
NANO_COPY_ALTKEY, NOVIEW, do_copy_text);
sc_init_one(&main_list, NANO_NO_KEY, N_("Indent Text"),
- IFHELP(nano_indentmarked_msg, FALSE), NANO_INDENTMARKED_KEY,
- NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_indent_marked_void);
+ IFHELP(nano_indent_msg, FALSE), NANO_INDENT_KEY, NANO_NO_KEY,
+ NANO_NO_KEY, NOVIEW, do_indent_void);
sc_init_one(&main_list, NANO_NO_KEY, N_("Unindent Text"),
- IFHELP(nano_unindentmarked_msg, TRUE), NANO_UNINDENTMARKED_KEY,
- NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_unindent_marked_void);
+ IFHELP(nano_unindent_msg, TRUE), NANO_UNINDENT_KEY, NANO_NO_KEY,
+ NANO_NO_KEY, NOVIEW, do_unindent);
#endif
sc_init_one(&main_list, NANO_FORWARD_KEY, N_("Forward"),
diff --git a/src/nano.h b/src/nano.h
@@ -547,8 +547,8 @@ typedef struct rcoption {
#define NANO_DELETE_KEY NANO_CONTROL_D
#define NANO_BACKSPACE_KEY NANO_CONTROL_H
#define NANO_TAB_KEY NANO_CONTROL_I
-#define NANO_INDENTMARKED_KEY NANO_ALT_RCURLYBRACKET
-#define NANO_UNINDENTMARKED_KEY NANO_ALT_LCURLYBRACKET
+#define NANO_INDENT_KEY NANO_ALT_RCURLYBRACKET
+#define NANO_UNINDENT_KEY NANO_ALT_LCURLYBRACKET
#define NANO_SUSPEND_KEY NANO_CONTROL_Z
#define NANO_ENTER_KEY NANO_CONTROL_M
#define NANO_TOFILES_KEY NANO_CONTROL_T
diff --git a/src/proto.h b/src/proto.h
@@ -613,9 +613,9 @@ void do_delete(void);
void do_backspace(void);
void do_tab(void);
#ifndef NANO_TINY
-void do_indent_marked(ssize_t cols);
-void do_indent_marked_void(void);
-void do_unindent_marked_void(void);
+void do_indent(ssize_t cols);
+void do_indent_void(void);
+void do_unindent(void);
#endif
void do_enter(void);
#ifndef NANO_TINY
diff --git a/src/text.c b/src/text.c
@@ -191,12 +191,12 @@ void do_tab(void)
}
#ifndef NANO_TINY
-/* Indent or unindent all lines covered by the mark len columns,
- * depending on whether len is positive or negative. If the
- * TABS_TO_SPACES flag is set, indent/unindent by len spaces.
- * Otherwise, indent/unindent by (len / tabsize) tabs and (len %
- * tabsize) spaces. */
-void do_indent_marked(ssize_t cols)
+/* Indent or unindent the current line (or all lines covered by the mark
+ * if the mark is on) len columns, depending on whether len is positive
+ * or negative. If the TABS_TO_SPACES flag is set, indent/unindent by
+ * len spaces. Otherwise, indent/unindent by (len / tabsize) tabs and
+ * (len % tabsize) spaces. */
+void do_indent(ssize_t cols)
{
bool indent_changed = FALSE;
/* Whether any indenting or unindenting was done. */
@@ -212,13 +212,6 @@ void do_indent_marked(ssize_t cols)
assert(openfile->current != NULL && openfile->current->data != NULL);
- /* If the mark isn't on, indicate it on the statusbar and get
- * out. */
- if (!openfile->mark_set) {
- statusbar(_("No lines selected, nothing to do!"));
- return;
- }
-
/* If cols is zero, get out. */
if (cols == 0)
return;
@@ -233,9 +226,15 @@ void do_indent_marked(ssize_t cols)
} else
indent_changed = TRUE;
- /* Get the coordinates of the marked text. */
- mark_order((const filestruct **)&top, &top_x,
- (const filestruct **)&bot, &bot_x, NULL);
+ /* If the mark is on, use all lines covered by the mark. */
+ if (openfile->mark_set)
+ mark_order((const filestruct **)&top, &top_x,
+ (const filestruct **)&bot, &bot_x, NULL);
+ /* Otherwise, use the current line. */
+ else {
+ top = openfile->current;
+ bot = top;
+ }
if (!unindent) {
/* Set up the text we'll be using as indentation. */
@@ -260,7 +259,7 @@ void do_indent_marked(ssize_t cols)
line_indent[line_indent_len] = '\0';
}
- /* Go through each line of the marked text. */
+ /* Go through each line of the text. */
for (f = top; f != bot->next; f = f->next) {
size_t line_len = strlen(f->data);
size_t indent_len = indent_length(f->data);
@@ -276,8 +275,8 @@ void do_indent_marked(ssize_t cols)
openfile->totsize += line_indent_len;
/* Keep track of the change in the current line. */
- if (f == openfile->mark_begin && openfile->mark_begin_x >=
- indent_len)
+ if (openfile->mark_set && f == openfile->mark_begin &&
+ openfile->mark_begin_x >= indent_len)
openfile->mark_begin_x += line_indent_len;
if (f == openfile->current && openfile->current_x >=
@@ -311,7 +310,7 @@ void do_indent_marked(ssize_t cols)
openfile->totsize -= indent_shift;
/* Keep track of the change in the current line. */
- if (f == openfile->mark_begin &&
+ if (openfile->mark_set && f == openfile->mark_begin &&
openfile->mark_begin_x > indent_new) {
if (openfile->mark_begin_x <= indent_len)
openfile->mark_begin_x = indent_new;
@@ -347,16 +346,18 @@ void do_indent_marked(ssize_t cols)
}
}
-/* Indent all lines covered by the mark tabsize columns. */
-void do_indent_marked_void(void)
+/* Indent the current line, or all lines covered by the mark if the mark
+ * is on, tabsize columns. */
+void do_indent_void(void)
{
- do_indent_marked(tabsize);
+ do_indent(tabsize);
}
-/* Unindent all lines covered by the mark tabsize columns. */
-void do_unindent_marked_void(void)
+/* Unindent the current line, or all lines covered by the mark if the
+ * mark is on, tabsize columns. */
+void do_unindent(void)
{
- do_indent_marked(-tabsize);
+ do_indent(-tabsize);
}
#endif /* !NANO_TINY */