From 067086adff7134f970a141269856f65ef195f2db Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 24 Aug 2021 20:34:12 +0200 Subject: incdec: Add comments to describe Bash functions --- incdec | 5 +++++ incdec.m4.bash | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/incdec b/incdec index 85336fc..671dff3 100644 --- a/incdec +++ b/incdec @@ -1,3 +1,4 @@ +# Increment or decrement a number on the current line. function __readline_incdec { local increment_by="$1" local backward="$2" @@ -56,6 +57,7 @@ print $output; READLINE_LINE="$line" } +# Increment the nearest number to the left of point by 1. function __readline_incdec_increment { local old_line_length="${#READLINE_LINE}" @@ -63,11 +65,13 @@ function __readline_incdec_increment { local new_line_length="${#READLINE_LINE}" + # If a negative sign was removed, keep point where it was. if [ "$old_line_length" -gt "$new_line_length" ]; then READLINE_POINT="$(($READLINE_POINT - 1))" fi } +# Decrement the nearest number to the left of point by 1. function __readline_incdec_decrement { local old_line_length="${#READLINE_LINE}" @@ -75,6 +79,7 @@ function __readline_incdec_decrement { local new_line_length="${#READLINE_LINE}" + # If a negative sign was added, keep point where it was. if [ "$old_line_length" -lt "$new_line_length" ]; then READLINE_POINT="$(($READLINE_POINT + 1))" fi diff --git a/incdec.m4.bash b/incdec.m4.bash index 45fac7c..0ec0f51 100644 --- a/incdec.m4.bash +++ b/incdec.m4.bash @@ -1,3 +1,4 @@ +# Increment or decrement a number on the current line. function __readline_incdec { local increment_by="$1" local backward="$2" @@ -15,6 +16,7 @@ INCLUDE_INCDEC_PL READLINE_LINE="$line" } +# Increment the nearest number to the left of point by 1. function __readline_incdec_increment { local old_line_length="${#READLINE_LINE}" @@ -22,11 +24,13 @@ function __readline_incdec_increment { local new_line_length="${#READLINE_LINE}" + # If a negative sign was removed, keep point where it was. if [ "$old_line_length" -gt "$new_line_length" ]; then READLINE_POINT="$(($READLINE_POINT - 1))" fi } +# Decrement the nearest number to the left of point by 1. function __readline_incdec_decrement { local old_line_length="${#READLINE_LINE}" @@ -34,6 +38,7 @@ function __readline_incdec_decrement { local new_line_length="${#READLINE_LINE}" + # If a negative sign was added, keep point where it was. if [ "$old_line_length" -lt "$new_line_length" ]; then READLINE_POINT="$(($READLINE_POINT + 1))" fi -- cgit v1.2.3