Adding a newline after a comment block in Doom Emacs


Adding a newline at the end of a comment block is something that always bothered me in Doom Emacs.

The default behaviour when pressing o is to expand the comment section to the new line, but sometimes that’s not what I want.

The solution was to edit my config.el to add this:

(defun append-line-comment-block ()
  "Appends a new line after a comment block without expanding it.
Calls `evil-append-line` and `+default/newline` in sequence."
  (interactive)
  (call-interactively 'evil-append-line)
  (call-interactively '+default/newline)
  )

(map!
  (:prefix "g"
    :desc "New line after comment block" :n "o" #'append-line-comment-block
   ))

Now I have two options.

Using o I can expand the comment block with a new line:

/**
 *
 */|  <~ pressing `o` with cursor here
 
 |
 V

/**
 *
 *
 */| <~ gives me a new line inside of the block

Using g o I can add an empty line below the comment block:

/**
 *
 */| <~ pressing `g o` with the cursor here
 
 |
 V

/**
 *
 */
| <~ gives me a new empty line below the block

Related Posts

Resizing and moving windows in Doom Emacs

Setting up TabNine on Doom Emacs

The correct docker-compose setup for Wordpress and Nginx

PureScript Date and Time guide

Adding live css and js reload to Yesod

A quick overview of Purescript package managers as of October 2018

Optional elements and properties in Halogen

Simple AJAX in Purescript

Automatically adding (or removing) a prefix to a record labels in Purescript

Adding static files to Yesod