Skip to content

Instantly share code, notes, and snippets.

@Unitech
Created October 9, 2011 08:49
Show Gist options
  • Save Unitech/1273463 to your computer and use it in GitHub Desktop.
Save Unitech/1273463 to your computer and use it in GitHub Desktop.
Indent in ruby
;;
;; Permits to indent like that :
;; class Comment < ActiveRecord::Base
;; after_create :send_email_to_author,
;; :if => :author_wants_emails?,
;; :unless => Proc.new { |comment| comment.post.ignore_comments? }
;; end
;;
(defadvice ruby-indent-line (after line-up-args activate)
(let (indent prev-indent arg-indent)
(save-excursion
(back-to-indentation)
(when (zerop (car (syntax-ppss)))
(setq indent (current-column))
(skip-chars-backward " \t\n")
(when (eq ?, (char-before))
(ruby-backward-sexp)
(back-to-indentation)
(setq prev-indent (current-column))
(skip-syntax-forward "w_.")
(skip-chars-forward " ")
(setq arg-indent (current-column)))))
(when prev-indent
(let ((offset (- (current-column) indent)))
(cond ((< indent prev-indent)
(indent-line-to prev-indent))
((= indent prev-indent)
(indent-line-to arg-indent)))
(when (> offset 0) (forward-char offset))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment