Created
October 18, 2015 18:10
-
-
Save teaforthecat/454784f099d49a474e15 to your computer and use it in GitHub Desktop.
one function with a few lines addded to keep the structure of lisp forms when commenting a form inside another form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun comment-sexp--raw () | |
"Comment the sexp at point or ahead of point." | |
(pcase (or (bounds-of-thing-at-point 'sexp) | |
(save-excursion | |
(skip-chars-forward "\r\n[:blank:]") | |
(bounds-of-thing-at-point 'sexp))) | |
(`(,l . ,r) | |
(goto-char r) | |
(skip-chars-forward "\r\n[:blank:]") | |
(save-excursion | |
;; comment internal forms without breaking the structure | |
(if (looking-at " *\)") ;;[:blank:] didn't work here(?) | |
(progn | |
(goto-char r) | |
(newline-and-indent))) | |
(comment-region l r)) | |
(skip-chars-forward "\r\n[:blank:]")))) |
What I mean is: comment-region
is usually supposed to take care of inserting newlines and ensuring the code remains valid.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey there. I'm having a look at this now.
Could you exemplify a case where the previous code didn't work?