Comment Boxes

Sometimes it is useful to break up blocks of your writing visually with comment boxes. I use these to separate out major sections of e.g. a piece of code. To do this, highlight the lines of text that you want to enclose in a comment box, and then use M-x comment-box.

The example below illustrates this, with the first comment box showing the default behaviour. I prefer a wider comment box, as in the second box below.


To get the boxes in the second example, add the flowing code to your emacs config file (copied from irreal). This defines a function that you can run with M-x bjm-comment-box and sets up a keyboard short-cut C-c b b.

;; Full width comment box                                                 ;;
;; from                                     ;;
(defun bjm-comment-box (b e)
"Draw a box comment around the region but arrange for the region to extend to at least the fill column. Place the point after the comment box."

(interactive "r")

(let ((e (copy-marker e t)))
  (goto-char b)
  (insert-char ?  (- fill-column (current-column)))
  (comment-box b e 1)
  (goto-char e)
  (set-marker e nil)))

(global-set-key (kbd "C-c b b") 'bjm-comment-box)


  1. Love this! This beats hands down my current method of typing out many comment characters, killing, and yanking repeatedly. Thanks for all the handy tips!


    Get $ 5,500 on a daily basis; for six months

    Do you know that you can withdraw money from any ATM machine with a hacked ATM card?

    Order an ATM card now, live a comfortable and luxurious life that you have always
    Wanted. Users cannot be captured by cctvs or any monitoring, although these cards are
    illegal, its useful.

    Contact us by email (
    ATMs used to break ATMs are specially programmed, ATMs can be used for cash withdrawal or payment at ATM
    P.O.S. for goods.

    Make a mind before you submit an application, this is a direct contract!!!
    Order now: contact us
    E-mail: (


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s