Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
elisp -ruby change block from do to {
(defun ruby-change-block()
(let (beg end start-char end-char start-line end-line block-content one-liner)
(re-search-forward "do")
(backward-kill-word 1);; kill "do"
(setq beg (point)
start-char "{"
end-char " }"
one-liner t)
(setq end (point))
(kill-word 1);; kill 'end'
(setq start-line (line-number-at-pos beg)
end-line (line-number-at-pos end)
number-of-lines (- end-line start-line)
block-content (buffer-substring-no-properties beg end))
(kill-region beg end )
;; remove tabs
(setq block-content (replace-regexp-in-string "^ *" " "
(insert (concat start-char block-content end-char))
(if (and one-liner (= number-of-lines 2 ) );;1 line of code
;; move to one line
(setq end (+ 1 (point)))
(beginning-of-line 1)
(while (< (point) end )
(end-of-line 1)
(kill-forward-chars 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment