I'd like to create a few routines for manipulating function arguments in buffers, which of course requires me to first locate the arguments. Suppose that I'm operating on a buffer with a programming language with a C-like syntax, then I could search for the commas to delimit arguments. The difficulty arises when you have arguments that are calls to other functions, because those can also include commas that I wouldn't want to consider, as in the following example (the carrots point to the commas that I want to find).
somefun(w, f(x1, g(y1, y2)), h(z1, z2))
^ ^
Assuming that I've already located the start of the arguments list, my current plan is to repeatedly use forward-sexp
to advance past the nested elements in the syntax tree and then check if the next non-whitespace character is a comma. But is there a more robust or idiomatic way to approach this?
semantic
are fairly limited, I think maybe it would be better to have an imperfect solution that is more widely applicable. In particular, the language that I use most, R, isn't supported.(forward-sexp)
solution in many Emacs modules, and it work surprisingly well. I would recommend you to use it over a "full parser" solution, as they tend to break when the program isn't syntactically correct, which they sometimes aren't when you're in the middle of an edit.