This might be a little more reliable:
(defun toggle-quotes () (interactive) (save-excursion (let ((start (nth 8 (syntax-ppss))) (quote-length 0) sub kind replacement) (goto-char start) (setq sub (buffer-substring start (progn (forward-sexp) (point))) kind (aref sub 0)) (while (char-equal kind (aref sub 0)) (setq sub (substring sub 1) quote-length (1+ quote-length))) (setq sub (substring sub 0 (- (length sub) quote-length))) (goto-char start) (delete-region start (+ start (* 2 quote-length) (length sub))) (setq kind (if (char-equal kind ?\") ?\' ?\")) (loop for i from 0 for c across sub for slash = (char-equal c ?\\) then (if (and (not slash) (char-equal c ?\\)) t nil) do (unless slash (when (member c '(?\" ?\')) (aset sub i (if (char-equal kind ?\") ?\' ?\"))))) (setq replacement (make-string quote-length kind)) (insert replacement sub replacement))))
It will use the syntax information from the buffer to find the quotation marks at the beginning of the line (which indicates that the lines are quoted), and also try to flip the quotes inside the line unless they are flushed with a backslash - which looks like a normal case.
PS. I just realized that you also wanted him to find the triple quotation marks, so she leaves.
user797257
source share