Skip to content

Instantly share code, notes, and snippets.

@DogLooksGood
Created July 18, 2019 22:06
Show Gist options
  • Save DogLooksGood/00b4a2d37617f1f9ae22c713bea8f2b2 to your computer and use it in GitHub Desktop.
Save DogLooksGood/00b4a2d37617f1f9ae22c713bea8f2b2 to your computer and use it in GitHub Desktop.
Auto semicolon/colon and singlequote/doublequote
(defun user/lisp-semicolon ()
"Will insert a semicolon if we are at the beginning of the line,
otherwise will insert a colon."
(interactive)
(if (or (nth 3 (syntax-ppss))
(save-mark-and-excursion
(while (equal (char-before) 59)
(backward-char))
(equal (point) (line-beginning-position))))
(call-interactively 'paredit-semicolon)
(insert ":")))
(defun user/lisp-singlequote ()
"Will insert singlequote if we are after a whitespace or newline,
otherwise will insert a doublequote and convert previous singlequote to doublequote."
(interactive)
(if (or (equal (char-before) 10)
(equal (char-before) 32))
(insert "'")
(if (and (not (nth 3 (syntax-ppss)))
(save-mark-and-excursion
(while (and (char-before) (not (equal (char-before) 39)))
(backward-char))
(when (char-before)
(backward-delete-char 1)
(insert "\"")
t)))
(insert "\"")
(insert "'"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment