Skip to content

Instantly share code, notes, and snippets.

@markrwilliams
Created March 12, 2013 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markrwilliams/5144078 to your computer and use it in GitHub Desktop.
Save markrwilliams/5144078 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)))))))
@markrwilliams
Copy link
Author

(add-hook 'python-mode-hook (lambda ()
                          (local-unset-key "\C-c\C-s")
                          (local-set-key "\C-c\C-s"
                                         'python-swap-quotes)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment