The answer to this question generally is to use block-commenting. That's essentially what you're asking for by asking for a
) envelope. Think of your
(off as starting a comment block and the corresponding
) as ending it.
Unlike Common Lisp, Emacs Lisp doesn't provide a block-commenting feature. That is, it provides only a
comment-start string, which is
";", and no
comment-end string -- that's the empty string,
But you can use the ordinary end-of-line commenting (
;) to achieve the effect of block-commenting, provided you have a command that not only lets you (1) comment out code that might, itself, contain comments -- in other words, nest commented code, but also (2) unnest a given level of such a (pseudo) block comment.
The standard command
comment-region comes close to this description. And the standard command
comment-dwim also comes (less) close to it.
comment-region lets you nest and unnest a given number of
comment-dwim doesn't do (un)nesting well. It tries to both comment out a region and add an end-of-line comment (or reposition such an existing comment).
I use my command
comment-region-lines, from library
misc-cmds.el. It does what
comment-region does, except that it comments or uncomments whole lines. I bind it to
C-x C-; (which by default is bound
comment-line). And I use
M-; (bound to
comment-dwim) only for end-of-line commenting.
Here's the doc of standard command
Comment or uncomment each line in the region.
C-u prefix arg, uncomment each line in region
ARG means use
ARG comment characters.
ARG is negative, delete that many comment characters instead.
The strings used as comment starts are built from
comment-padding; the strings used as comment ends are built
By default, the
comment-start markers are inserted at the
current indentation of the region, and comments are terminated on
each line (even for syntaxes in which newline does not end the
comment and blank lines do not get comments). This can be
In your question you also speak about the distraction that commenting code can introduce. For that, I suggest command
https://www.emacswiki.org/emacs/HideOrIgnoreComments from my library
It hides the comments in the active region (or the whole buffer, if no active region). With a prefix arg it shows the hidden comments.
Or use command
hide/show-comments-toggle, which toggles hiding/showing commented text.
There's also Lisp macro
with-comments-hidden, for hiding/ignoring comments while executing some code, i.e., when you want some code to ignore the commented text.
And there are some user options that control comment hiding:
hide-whitespace-before-comment-flag – If non-
nil then whitespace preceding a comment is hidden. Empty lines (newline chars) are not hidden, however.
ignore-comments-flag – If
with-comments-hidden does not ignore comments.
show-invisible-comments-shows-all – If non-
nil then showing comments after hiding them shows all text that was invisible, however it was made so. The default is
nil: make visible only text that was made invisible by