I would find it incredibly useful if I could do a Find/Replace such that I could reliably rename symbols like variables and function names. I envision that this would be based on scopes and that it would constrain Find/Replace to exact matches of entire scopes. In Erlang this would enable me to rename variables by doing a Find/Replace of exact scope match for variable.other.erlang.
On Mar 29, 2008, at 10:37 PM, Alain O'Dea wrote:
I would find it incredibly useful if I could do a Find/Replace such that I could reliably rename symbols like variables and function names. I envision that this would be based on scopes and that it would constrain Find/Replace to exact matches of entire scopes. In Erlang this would enable me to rename variables by doing a Find/ Replace of exact scope match for variable.other.erlang.
Actually, search and replace is more powerful than the scope matching in language grammars. Find and replace regex can match multiple lines.
What you could do is look at the language definition file and find out the regex that's used to scope variables and then modify it to search and replace the specific variables you're looking for.
Maybe this could be automated in a command somehow. But, currently TextMate wouldn't be able to do what you're asking in any but the currently open document, since it doesn't even parse any files that it doesn't have open, and a command isn't capable of accessing the parsed version of any but the frontmost document anyway.
Maybe you could do something with a ruby script that parses all the files in the project or something similar and asks you what variables you want to replace.
Personally, I wouldn't touch something like this because of the pain that it would take to debug it.
On 30-Mar-08, at 3:18 PM, Thomas Aylott - subtleGradient wrote:
On Mar 29, 2008, at 10:37 PM, Alain O'Dea wrote:
I would find it incredibly useful if I could do a Find/Replace such that I could reliably rename symbols like variables and function names. I envision that this would be based on scopes and that it would constrain Find/Replace to exact matches of entire scopes. In Erlang this would enable me to rename variables by doing a Find/ Replace of exact scope match for variable.other.erlang.
Actually, search and replace is more powerful than the scope matching in language grammars. Find and replace regex can match multiple lines.
What you could do is look at the language definition file and find out the regex that's used to scope variables and then modify it to search and replace the specific variables you're looking for.
Maybe this could be automated in a command somehow. But, currently TextMate wouldn't be able to do what you're asking in any but the currently open document, since it doesn't even parse any files that it doesn't have open, and a command isn't capable of accessing the parsed version of any but the frontmost document anyway.
Maybe you could do something with a ruby script that parses all the files in the project or something similar and asks you what variables you want to replace.
Personally, I wouldn't touch something like this because of the pain that it would take to debug it.
I see how your suggestion would work for Erlang, where variables are lexically distinct from other symbols. However, just grabbing the regex for variables from the language file won't suffice because it loses the state/context in which that regex validly extracts variables from the stream of text. Even in Erlang, this is a problem because capitalized words (which Erlang's variables must be) can appear in comments, strings, and other contexts where they are not logically variables.
You mentioned by that a command isn't capable of accessing the parsed version of any of the frontmost document. Does that mean that the parsed version of the frontmost document is somehow accessible to commands? That would be immensely useful to me for a variety of purposes.
On Mar 31, 2008, at 8:32 PM, Alain O'Dea wrote:
You mentioned by that a command isn't capable of accessing the parsed version of any of the frontmost document. Does that mean that the parsed version of the frontmost document is somehow accessible to commands? That would be immensely useful to me for a variety of purposes.
From r948 in the release notes:
[NEW] One can now access the document as parsed by TextMate. To do so, create a new command (in the bundle editor), locate the command’s plist on disk, add the key inputFormat with a value of xml to this plist, and relaunch TextMate to have it use this modified command (it’s a new experimental feature, thus no UI for this). The input fed to the command will be wrapped in tags corresponding to the scope names. It also has the usual entity escapes. This form is probably not valid XML (because of the scope names which do not make for good tag names), but a simple regexp substitution should be able to convert it into something more useful, so I opted for using this “raw” representation, rather than turn it into XHTML with class arguments or similar. The Experimental bundle (at the Bundles svn repository) has a View Document as HTML command which converts the XML to XHTML with a minimal style sheet.