all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: Sayth Renshaw <flebber.crue@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Ruby and RubyOn Rails setup - Cannot enable indentation and snippets
Date: Tue, 01 Jan 2013 13:24:57 -0100	[thread overview]
Message-ID: <87han12d6u.fsf@yandex.ru> (raw)
In-Reply-To: <558f5257-18a8-46c4-8a41-71ea6066449e@googlegroups.com> (Sayth Renshaw's message of "Tue, 1 Jan 2013 04:27:00 -0800 (PST)")

Hi Sayth,

Sayth Renshaw <flebber.crue@gmail.com> writes:
> I have been trying to configure emacs24 now for sometime to be good using ruby and later rails. I am on Fedora 18.
>
> Well the biggest issue I have is that emacs will not indent ruby correctly, well it doesn't indent at all.

Please open an .rb file in Emacs, evaluate (M-:) the following
expressions and send the values returned (for long values, you can look
in the *Messages* buffer, or use esk-eval-and-replace from emacs-starter-kit):

major-mode
indent-line-function
(find-library-name "ruby-mode")
emacs-version

> I have tried several variations all done by hand by myself, emacs-starter-kit with ruby loaded, prelude emacs(indents end keyword correctly but does not indent the block) with ruby loaded and cannot get proper indentation, snippets and/or autocompletion. I can get some bits in the installs but it is not ideal.

That sounds positively broken.

> By default Sublime text2 does all this and I cannot manage to emacs configured.
>
> This is my .emacs(left out references to marmalade etc) I put together using ruby-mode, rinari, rsense and yasnippet.
> I get the features of rsense, however I cannot get it to indent correctly or have yasnippet insert snippet from tab press.
>
> Example indentation
>
> Correct
> multi_array.each do
>   x.each do |y|
>     puts y
>
>   end
> end
>
> Emacs
> multi_array.each do
> x.each do |y|
> puts y
> end
> end

ruby-mode indents that fine out of the box (emacs -Q), no setup
required. No other packages you mentioned mess with indentation, so
there must be something wrong with the setup.

> If anyone can advise on what to improve it would be greatly appreciated.
>
> (setq-default indent-tabs-mode nil)    ; use only spaces and no tabs
> (setq default-tab-width 4)
>
> (require 'pep8)
> (require 'pylint)
>
> ;; org mode
> (add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
>
>  (global-set-key "\C-cl" 'org-store-link)
>  (global-set-key "\C-cc" 'org-capture)
>  (global-set-key "\C-ca" 'org-agenda)
>  (global-set-key "\C-cb" 'org-iswitchb)

The stuff above is largely irrelevant.

> (require 'yasnippet-bundle)

Yasnippet bundles are largely deprecated. I'm not sure if that's the
source of your problem, but if all else fails, try to install yasnippet
from git (https://github.com/capitaomorte/yasnippet/), or from Melpa,
mentioned in the README there.

Also note that in recent versions, all variable and function names have
had slashes replaces with dashes.

> (yas/global-mode)
> (add-hook 'rinari-minor-mode-hook
>           #'(lambda ()
>               (setq yas/mode-symbol 'rails-mode)))
>
> (add-hook 'ruby-mode-hook
>           #'(lambda ()
>               (setq yas/mode-symbol 'ruby-mode)))

There's no reason to set yas/mode-symbol to 'ruby-mode, the major mode
name is already included in the list of symbols to look up.
And since rinari-minor-mode-hook runs after ruby-mode-hook, the value
just gets overwritten.

Do you have a separate rails-mode snippet directory? If not, you can
remove both `add-hook' forms above.

If you do, on the other hand, you need to add its parent directory to
yas-snippet-dirs.

> (setq ruby-indent-level 4)

The example at the beginning of your email has a 2-space indentation.
Why are you setting this to 4?

> (require 'rinari)
> (add-to-list 'load-path "/home/sayth/.emacs.d/rhtml")
> (require 'rhtml-mode)

rhtml-mode is also irrelevant.

> (autoload 'ruby-mode "ruby-mode"
>     "Mode for editing ruby source files")
> (add-to-list 'auto-mode-alist '("\\.rb$" . ruby-mode))
> (add-to-list 'interpreter-mode-alist '("ruby" . ruby-mode))

The above settings are already included in the default Emacs installation.

> (autoload 'run-ruby "inf-ruby"
>     "Run an inferior Ruby process")
> (autoload 'inf-ruby-keys "inf-ruby"
>     "Set local key defs for inf-ruby in ruby-mode")

If you installed inf-ruby from Elpa, you can remove these, too.

> (add-hook 'ruby-mode-hook
>     '(lambda ()
>         (inf-ruby-keys)))
>
> (setq load-path (cons (expand-file-name "~/.emacs.d/rails-reloaded") load-path))
>   (require 'rails-autoload)

I'd like know what gave you the impression that installing
rails-reloaded is a good idea. Here's a recent user complaint:

http://stackoverflow.com/questions/13890831/emacs-rails-reloaded-does-not-work

Anyway, since you're having problems with your setup, you should build
it gradually, first make sure the indentation works, then yasnippet,
then code completion, which is the most problematic of the three.

emacs-rails-reloaded, or the original emacs-rails, don't help with any
of those (except for having an additional set of snippets, I guess), so
there's no reason to complicate your config, for now.

> (setq rsense-home "/home/sayth/opt/rsense-0.3")
> (add-to-list 'load-path (concat rsense-home "/etc"))
> (require 'rsense)
> (add-hook 'ruby-mode-hook
>           (lambda ()
>             (add-to-list 'ac-sources 'ac-source-rsense-method)
>             (add-to-list 'ac-sources 'ac-source-rsense-constant)))

This looks good, but in my experience, RSense doesn't work with Rails
projects (or, rather, usually doesn't show any useful completions).
I guess this is listed as "Large project" in the "Limitations" section of
RSense user manual.

*shameless plug warning*

You can try Robe (https://github.com/dgutov/robe) for a less clever, but
more comprehensive completion. It falls back to "all methods in all
classes" approach much more often, though, and should still be
considered WIP.

--Dmitry



  reply	other threads:[~2013-01-01 14:24 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-01 12:27 Ruby and RubyOn Rails setup - Cannot enable indentation and snippets Sayth Renshaw
2013-01-01 14:24 ` Dmitry Gutov [this message]
     [not found] ` <mailman.16475.1357050313.855.help-gnu-emacs@gnu.org>
2013-01-02 13:24   ` Sayth Renshaw
2013-01-02 14:52     ` Dmitry Gutov
     [not found]     ` <mailman.16528.1357138350.855.help-gnu-emacs@gnu.org>
2013-01-03  6:25       ` Sayth Renshaw
2013-01-03 14:23         ` Dmitry Gutov
2013-01-03 15:15           ` Dmitry Gutov
2013-01-04 11:11             ` Sayth Renshaw
2013-01-04 16:11               ` Dmitry Gutov
     [not found]                 ` <CAN2of03ausUrsd9LNqoN=r4o3YmD8YF=8ObiHqQxEx4QaUvKHw@mail.gmail.com>
2013-01-05  5:42                   ` Dmitry Gutov
2013-01-05 12:53                     ` Sayth Renshaw
2013-01-05 13:04                       ` Sayth Renshaw
2013-01-05 14:59                       ` Dmitry Gutov
2013-01-05 21:07                         ` Sayth Renshaw

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87han12d6u.fsf@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=flebber.crue@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.