aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--incdec.bash37
-rw-r--r--incdec.m4.bash34
-rw-r--r--incdec.m4.pl2
3 files changed, 57 insertions, 16 deletions
diff --git a/incdec.bash b/incdec.bash
index 029d4ea..7144282 100644
--- a/incdec.bash
+++ b/incdec.bash
@@ -23,7 +23,7 @@ function __readline_incdec {
local increment_by="$1"
local backward="$2"
- line=$(perl -s -e '
+ result="$(perl -s -e '
sub incdec {
my ($line, $increment_by, $point_position, $is_backward) = @_;
@@ -76,28 +76,38 @@ my ($output, $start_position) = incdec(
$point_position,
$backward
);
-print $output;
+print "$start_position\#$output";
' \
-- \
-line="$READLINE_LINE" \
-increment_by="$increment_by" \
-point_position="$READLINE_POINT" \
-backward="$backward"
- )
+ )"
- READLINE_LINE="$line"
+ echo "$result"
}
# Increment the nearest number to the left of point by 1.
function __readline_incdec_increment {
local old_line_length="${#READLINE_LINE}"
- __readline_incdec 1 1
+ result="$(__readline_incdec 1 1)"
+
+ line="${result#*#}"
+ READLINE_LINE="$line"
local new_line_length="${#READLINE_LINE}"
+ local start_position="${result%#*}"
+ echo "$start_position .. $READLINE_POINT"
+
# If a negative sign was removed, keep point where it was.
- if [ "$old_line_length" -gt "$new_line_length" ]; then
+ if [ \
+ "$old_line_length" -gt "$new_line_length" \
+ -a \
+ "$start_position" -le "$READLINE_POINT" \
+ ]; then
READLINE_POINT="$(($READLINE_POINT - 1))"
fi
}
@@ -106,12 +116,23 @@ function __readline_incdec_increment {
function __readline_incdec_decrement {
local old_line_length="${#READLINE_LINE}"
- __readline_incdec -1 1
+ result="$(__readline_incdec -1 1)"
+
+ line="${result#*#}"
+ READLINE_LINE="$line"
local new_line_length="${#READLINE_LINE}"
+ local start_position="${result%#*}"
+ echo "$start_position .. $READLINE_POINT"
+
+ # TODO: Point should only move when it's over the number. No, actually when it's >= the start of the number.
# If a negative sign was added, keep point where it was.
- if [ "$old_line_length" -lt "$new_line_length" ]; then
+ if [ \
+ "$old_line_length" -lt "$new_line_length" \
+ -a \
+ "$start_position" -le "$READLINE_POINT" \
+ ]; then
READLINE_POINT="$(($READLINE_POINT + 1))"
fi
}
diff --git a/incdec.m4.bash b/incdec.m4.bash
index ff6bb57..61e7f47 100644
--- a/incdec.m4.bash
+++ b/incdec.m4.bash
@@ -23,7 +23,7 @@ function __readline_incdec {
local increment_by="$1"
local backward="$2"
- line=$(perl -s -e '
+ result="$(perl -s -e '
INCLUDE_INCDEC_PL
' \
-- \
@@ -31,21 +31,31 @@ INCLUDE_INCDEC_PL
-increment_by="$increment_by" \
-point_position="$READLINE_POINT" \
-backward="$backward"
- )
+ )"
- READLINE_LINE="$line"
+ echo "$result"
}
# Increment the nearest number to the left of point by 1.
function __readline_incdec_increment {
local old_line_length="${#READLINE_LINE}"
- __readline_incdec 1 1
+ result="$(__readline_incdec 1 1)"
+
+ line="${result#*#}"
+ READLINE_LINE="$line"
local new_line_length="${#READLINE_LINE}"
+ local start_position="${result%#*}"
+ echo "$start_position .. $READLINE_POINT"
+
# If a negative sign was removed, keep point where it was.
- if [ "$old_line_length" -gt "$new_line_length" ]; then
+ if [ \
+ "$old_line_length" -gt "$new_line_length" \
+ -a \
+ "$start_position" -le "$READLINE_POINT" \
+ ]; then
READLINE_POINT="$(($READLINE_POINT - 1))"
fi
}
@@ -54,13 +64,23 @@ function __readline_incdec_increment {
function __readline_incdec_decrement {
local old_line_length="${#READLINE_LINE}"
- __readline_incdec -1 1
+ result="$(__readline_incdec -1 1)"
+
+ line="${result#*#}"
+ READLINE_LINE="$line"
local new_line_length="${#READLINE_LINE}"
+ local start_position="${result%#*}"
+ echo "$start_position .. $READLINE_POINT"
+
# TODO: Point should only move when it's over the number. No, actually when it's >= the start of the number.
# If a negative sign was added, keep point where it was.
- if [ "$old_line_length" -lt "$new_line_length" ]; then
+ if [ \
+ "$old_line_length" -lt "$new_line_length" \
+ -a \
+ "$start_position" -le "$READLINE_POINT" \
+ ]; then
READLINE_POINT="$(($READLINE_POINT + 1))"
fi
}
diff --git a/incdec.m4.pl b/incdec.m4.pl
index b5d3c72..cd31dc5 100644
--- a/incdec.m4.pl
+++ b/incdec.m4.pl
@@ -6,4 +6,4 @@ my ($output, $start_position) = incdec(
$point_position,
$backward
);
-print $output;
+print "$start_position\#$output";