0

More specifically, I want to do something like this:

Select some region,

<mark>
int foo(int bar)
{
    bar = do_something(bar);
    return bar + 1;
}
<point>

and then type a command to do like this:

#if 0
int foo(int bar)
{
    bar = do_something(bar);
    return bar + 1;
}
#endif

Write an #if 0 at the beginning of the region, and an #endif at the end. But it could be any arbitrary string really, even /* and */ to comment out the region.

Drew
  • 75,699
  • 9
  • 109
  • 225

1 Answers1

0

Thanks to some nice guy at the Doom Emacs discord server, I got it working:

(defun leo/c-if-0-region (beg end)
  (interactive "r")
  (save-excursion
    (narrow-to-region beg end)
    (set-mark nil)
    (goto-char (point-min))
    (insert "\n#if 0\n")
    (goto-char (point-max))
    (insert "\n#endif\n")
    (widen)))