Ah, you want a macro which finds all global variables not used anymore in all the source files of the whole project and so are only wasting RAM. I never understood why the compilers/linkers do not report unused global variables. Have you searched if there is a tool which can report which global variables are used/unused for your programming language?
One solution would be to use FindInFiles with results to edit window with ^c and ^s in a loop. For an example how to use ^s and ^c see the power tip
Using "copied" and "selected" variables for dynamic macros. But if you look at
How to link up all files under a folder? how difficult it is to use FindInFiles with results to an edit window because of a timing bug of UltraEdit, this solution cannot be used.
A second solution would be to have a loop which copies the variable name to clipboard and then searches in all other opened files by running a find on every other opened file. This solution would need 2 nested loops, which is not possible and so the "Find in other files" loop must be a submacro. But this solution is not very fast, especially for a project with dozens of source files.
So the best solution would be to write a macro which consists of 3 parts:
The first part finds all the variable names in the current file and copies it to a new file so each variable name is on a single line. Of course, this is more complicated than it looks like because for example for "C/C++" it is not really easy to find a regular expression search string which finds the variable name in all possible cases. I think, it is much easier to copy the whole file with the variable names to a new file and delete everything, which is surely not a variable name (comments, keywords, blank lines and white-spaces). What remains are the variable names. This part depends on the programing language. So I can't help you with that part.
The second part copies the contents of all other open files (except the new file and the file with the variable declarations which should be closed in part 1) together to the new file below the lines with the variable names. That is quite simply and could be realized with something like that:
ClearClipboard
Loop
NextWindow
IfNameIs ""
ExitLoop
EndIf
SelectAll
CopyAppend
EndSelect
Top
EndLoop
Bottom
">
"
Paste
The loop stops when the new file without any file name (because not saved) has again the focus. Then the macro could delete all line and block comments because some global variables maybe exist only anymore in a comment. This is again language dependent.
The new file would look after part 1 and 2 something like that:
Code: Select all
variable_1
variable_2
variable_3
:
:
variable_n
>
content of all source files
with or without any comments
The > character is a marker character which marks the end of the variable list so you can use a loop like this one:
Loop
IfCharIs ">"
ExitLoop
EndIf
:
:
EndLoop
The third part now searches for a variable name in text below (= content of all open files) and if found, deletes the line with the variable and if not found simply continues on next line until end of variable list found. Last
SelectToBottom
Delete
deletes everything from the > marker character till end of the file and the result is a new file which contains only the unused variables.