04
Sep 08

Emacs Lisp – Block Commenting Ruby Code

These days I’m working to become proficient in Emacs (I’ve recently switched from Vim, as Greg mentioned on his blog). With that comes all kinds of things like org-mode, yasnippet, and lots of keyboard combinations.

A part of this current effort I’m learning Emacs Lisp right now. There’s probably a better way to do block comment cycling in Ruby, but this was good practice on writing some simple elisp functions.

(defun ruby-comment-region ()
  "In Ruby, comment out the current region with =begin/=end statements."
  (interactive)
  (save-excursion
    (goto-char (point))
    (insert "=end")
    (goto-char (mark))
    (insert "=begin\n")))

(defun ruby-uncomment-region ()
  "In Ruby, uncomment the current region -- remove =begin/=end statements."
  (interactive)
  (save-excursion
    (if (re-search-backward "^=begin")
        (replace-match ""))
    (if (re-search-forward "^=end")
        (replace-match ""))))

2 Responses to “Emacs Lisp – Block Commenting Ruby Code”

  1. HeresTomWithTheWeather Says:

    judas!!

  2. andy Says:

    I know I know, it’s terrible. I still call it Escape-Meta-Alt-Ctrl-Shift. Of course, my VAX/VMS coworkers said the same thing when I left EDT for Vim!

Leave a Reply


Copyright © 2010 ANDY PAYNE
Powered by WordPress and Theme Lab