Skip to content

Instantly share code, notes, and snippets.

@markrwilliams
Created April 21, 2014 23:03
Show Gist options
  • Save markrwilliams/11159500 to your computer and use it in GitHub Desktop.
Save markrwilliams/11159500 to your computer and use it in GitHub Desktop.
(defun python-swap-quotes ()
(interactive)
(save-excursion
(let ((state (syntax-ppss)))
(when (eq 'string (syntax-ppss-context state))
(let* ((left (nth 8 state))
(right (1- (scan-sexps left 1)))
(newquote (if (= ?' (char-after left))
?\" ?')))
(dolist (loc (list left right))
(goto-char loc)
(delete-char 1)
(insert-char newquote 1)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment