This question is about changing the behavior of
comment-dwim when no active region is defined. The current behavior is defined below (from
C-h k), which is kind of complicated and not what doing what I mean:
comment-dwim is an interactive compiled Lisp function.
It is bound to M-;.
Call the comment command you want (Do What I Mean). If the region is active and ‘transient-mark-mode’ is on, call ‘comment-region’ (unless it only consists of comments, in which case it calls ‘uncomment-region’).
Else, if the current line is empty, call ‘comment-insert-comment-function’ if it is defined, otherwise insert a comment and indent it. ...
What I find useful is to just comment out the current line (i.e. use the current line as the region) if no active region is defined. This is similar to other IDEs such as Eclipse and VS code. The current behavior in some modes break a line where the point is, and inserts a new comment line, which is not really what I need. Probably it has its use cases, but I would find it more natural just to comment out the whole line if there is no defined region.
I know very little elisp, and especially don't know how to change the behavior of an existing function such as
comment-dwim (maybe by using a hook function somehow?).
Could someone help explain how to modify the behavior of
comment-dwim so that the current line is used as the region when no region is defined?
This is with Emacs 28, and the specific function is
paredit-comment-dwim, which I guess is a derived function of