Can regex be used to change array index in emacs?
eg. for some C code change:
int my_array[4]; my_array[0] = 1; my_array[1] = 2; my_array[2] = 3;
in
int my_array[4]; my_array[1] = 1; my_array[2] = 2; my_array[3] = 3;
replace [i] with [i+1] operation?
[i]
[i+1]
Something like that?
Mx query-replace-regexp my_array\[\([0-9]+\)\] RET my_array[\,(1+ \#1)]
\, in the replacement string, any lisp expression can be replaced.
(last edit: using \#1 instead of (string-to-int \1) )
\#1
(string-to-int \1)
increment:
Mx query-replace-regexp \[\([0-9]+\)\] RET [\,(1+ \#1)]
decrement:
Mx query-replace-regexp \[\([0-9]+\)\] RET [\,(1- \#1)]
Source: https://habr.com/ru/post/1385856/More articles:MPI memory leak - memory-leaksDiv floating side by side with overflow? - cssWhy does int become a string after reading from the database? - databaseHow to get information about the name and OS version in C # on Windows Mobile 7? - c #HttpClient on Android: NoHttpResponseException root cause In my project, right? - androidHow many built-in features are required to approve the Apple App Store? - iosPython callback inside class - functionHow to save only the last entry in the second level cache? - cachingAjax tracking Google Analytics events on html page not working - javascriptOpening a new window creates a new session - javascriptAll Articles