Skip to content

Instantly share code, notes, and snippets.

@DogLooksGood
Created December 10, 2019 03:01
Show Gist options
  • Save DogLooksGood/647de0cea46199462d5a58f96336bae4 to your computer and use it in GitHub Desktop.
Save DogLooksGood/647de0cea46199462d5a58f96336bae4 to your computer and use it in GitHub Desktop.
A command to comment clojure code
(defun user/clojure-comment ()
(interactive)
(cond
((not current-prefix-arg)
(save-mark-and-excursion
(if (equal "#_" (buffer-substring-no-properties (point) (+ 2 (point))))
(while (equal "#_" (buffer-substring-no-properties (point) (+ 2 (point))))
(delete-char 2))
(progn
(unless (or (equal (char-after) 40)
(equal (char-after) 91)
(equal (char-after) 123))
(backward-up-list))
(if (string-suffix-p "#_" (buffer-substring-no-properties (line-beginning-position) (point)))
(while (string-suffix-p "#_" (buffer-substring-no-properties (line-beginning-position) (point)))
(delete-char -2))
(insert "#_"))))))
((numberp current-prefix-arg)
(let* ((curr-sym (symbol-at-point))
(curr-sym-name (symbol-name curr-sym))
(line (buffer-substring-no-properties (point) (line-end-position)))
(i 0))
(save-mark-and-excursion
(when curr-sym
(unless (string-prefix-p curr-sym-name line)
(backward-sexp))
(while (< i current-prefix-arg)
(insert "#_")
(setq i (1+ i)))))))
((equal '(4) current-prefix-arg)
(save-mark-and-excursion
(unless (and (equal (char-after) 40)
(equal (point) (line-beginning-position)))
(beginning-of-defun)
(if (equal "#_" (buffer-substring-no-properties (point) (+ 2 (point))))
(delete-char 2)
(insert "#_")))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment