Commit ca5031ac authored by John van Groningen's avatar John van Groningen

add incrementing or decrementing integers in a selection

parent 05dfd9a2
Pipeline #40626 passed with stage
in 47 seconds
......@@ -985,6 +985,8 @@ editMenu altgr_workaround mEditId editRecId mFileSaveId mFileRevertId {mn_und, m
:+: MenuItem "Add Pre&fix" [ MenuId (mg_edt!!5), MenuFunction (noLS add_prefix_selection)]
:+: MenuItem "Remove Pref&ix" [ MenuId (mg_edt!!6), MenuFunction (noLS rem_prefix_selection)]
:+: MenuItem "Change Prefi&x..." [ MenuId (mg_edt!!7), MenuFunction (noLS change_prefix_dlog)]
:+: MenuItem "I&ncrement Integers" [ MenuId (mg_edt!!8), MenuFunction (noLS increment_integers_in_selection)]
:+: MenuItem "De&crement Integers" [ MenuId (mg_edt!!9), MenuFunction (noLS decrement_integers_in_selection)]
:+: MenuSeparator []
:+: MenuItem "Next &Window"
[ MenuModsFunction stackfun
......
......@@ -202,7 +202,7 @@ iniGeneral
(mEdCopyId,env) = openId env
(mEdPasteId,env) = openId env
(mEdClearId,env) = openId env
(edToolsIds,env) = openIds 8 env
(edToolsIds,env) = openIds 10 env
(mdCmpId,env) = openId env
(mdChkId,env) = openId env
(mdGenId,env) = openId env
......
......@@ -17,3 +17,7 @@ shift_selection_right :: !*(PSt General) -> *PSt General
shift_selection_left :: !*(PSt General) -> *PSt General
// block outdent
increment_integers_in_selection :: !*(PSt General) -> *PSt General
decrement_integers_in_selection :: !*(PSt General) -> *PSt General
......@@ -193,3 +193,84 @@ where
| n_spaces < size string && string.[n_spaces] == ' '
= count_spaces_at_begin (inc n_spaces) string
= n_spaces
increment_integers_in_selection :: !*(PSt General) -> *PSt General
increment_integers_in_selection ps
= replace_lines_and_redraw increment_prefix ps
where
increment_prefix text_tab_width line
= increment_integers 0 line
increment_integers i line
| i<size line
| line.[i]<'0' || line.[i]>'9'
= increment_integers (i+1) line
# after_digits_i = skip_digits (i+1) line
| not (i>0 && line.[i-1]=='-')
# (n_extra_chars,line) = increment_integer (after_digits_i-1) i line
= increment_integers (after_digits_i+n_extra_chars) line
# after_zeros_i = skip_zeros i line
| after_digits_i==after_zeros_i
# line = line % (0,i-2) +++ "1" +++ line % (after_zeros_i,size line-1)
= increment_integers i line
| after_digits_i==i+1 && line.[i]=='1'
# line = line % (0,i-2) +++ "0" +++ line % (after_digits_i,size line-1)
= increment_integers i line
# (n_extra_chars,line) = decrement_integer (after_digits_i-1) i line
= increment_integers (after_digits_i+n_extra_chars) line
= line
decrement_integers_in_selection :: !*(PSt General) -> *PSt General
decrement_integers_in_selection ps
= replace_lines_and_redraw decrement_prefix ps
where
decrement_prefix text_tab_width line
= decrement_integers 0 line
decrement_integers i line
| i<size line
| line.[i]<'0' || line.[i]>'9'
= decrement_integers (i+1) line
# after_digits_i = skip_digits (i+1) line
| not (i>0 && line.[i-1]=='-')
# after_zeros_i = skip_zeros i line
| after_digits_i==after_zeros_i
# line = line % (0,i-1) +++ "-1" +++ line % (after_zeros_i,size line-1)
= decrement_integers (i+2) line
| after_digits_i==i+1 && line.[i]=='1'
= decrement_integers (i+1) (line:=(i,'0'))
# (n_extra_chars,line) = decrement_integer (after_digits_i-1) i line
= decrement_integers (after_digits_i+n_extra_chars) line
# (n_extra_chars,line) = increment_integer (after_digits_i-1) i line
= decrement_integers (after_digits_i+n_extra_chars) line
= line
increment_integer :: !Int !Int !{#Char} -> (!Int,!{#Char})
increment_integer digit_i first_digit_i line
# digit = line.[digit_i]
| digit<>'9'
= (0,line:=(digit_i,inc digit))
| digit_i<>first_digit_i
= increment_integer (digit_i-1) first_digit_i (line:=(digit_i,'0'))
= (1,line % (0,digit_i-1) +++ "10" +++ line % (digit_i+1,size line-1))
decrement_integer :: !Int !Int !{#Char} -> (!Int,!{#Char})
decrement_integer digit_i first_digit_i line
# digit = line.[digit_i]
| digit>'1'
= (0,line:=(digit_i,dec digit))
| digit=='1'
| digit_i<>first_digit_i
= (0,line:=(digit_i,dec digit))
= (-1,line % (0,digit_i-1)+++line % (digit_i+1,size line-1))
= decrement_integer (digit_i-1) first_digit_i (line:=(digit_i,'9'))
skip_digits i line
| i<size line && (line.[i]>='0' && line.[i]<='9')
= skip_digits (i+1) line
= i;
skip_zeros i line
| i<size line && line.[i]=='0'
= skip_zeros (i+1) line
= 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