How to swap two arguments for C function calls? eg:
my_function(foo, bar, baz); ~~~~~~~~~~~~~^ (cursor location)
Should be transposed to the right to make:
my_function(bar, foo, baz);
The simple case works for this similar question.
But fails with:
my_function(&foo, *bar, baz); ~~~~~~~~~~~~~ ^ (cursor location)
my_function(&*bar, foo, baz);
From what I can tell this is because these functions rely on
backward-sexp which doesn't account for some characters used in C code.
For reference, this is the code: from https://emacs.stackexchange.com/a/11062/2418
(defun custom-calculate-stops () (save-excursion (let ( (start (condition-case e (while t (backward-sexp)) (error (point)) ) ) stops) (push start stops) (condition-case e (while t (forward-sexp) (when (looking-at "\\s-*,") (push (point) stops)) ) (error (push (point) stops)) ) (nreverse stops)) ) ) (defun custom-transpose-args () (interactive) (when (looking-at "\\s-") (backward-sexp)) (cl-loop with p = (point) with previous = nil for stop on (custom-calculate-stops) for i upfrom 0 when (<= p (car stop)) do (when previous (let* ( (end (cadr stop)) (whole (buffer-substring previous end)) middle last ) (delete-region previous end) (goto-char previous) (setf middle (if (> i 1) (- (car stop) previous) (string-match "[^, \\t]" whole (- (car stop) previous))) last (if (> i 1) (substring whole 0 middle) (concat (substring whole (- (car stop) previous) middle) (substring whole 0 (- (car stop) previous))) ) ) (insert (substring whole middle) last))) (cl-return) end do (setf previous (car stop)) ) )