From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.help Subject: Re: Ruby and RubyOn Rails setup - Cannot enable indentation and snippets Date: Tue, 01 Jan 2013 13:24:57 -0100 Message-ID: <87han12d6u.fsf@yandex.ru> References: <558f5257-18a8-46c4-8a41-71ea6066449e@googlegroups.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1357050319 30488 80.91.229.3 (1 Jan 2013 14:25:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 1 Jan 2013 14:25:19 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Sayth Renshaw Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jan 01 15:25:35 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Tq2mc-0006gV-Do for geh-help-gnu-emacs@m.gmane.org; Tue, 01 Jan 2013 15:25:34 +0100 Original-Received: from localhost ([::1]:40216 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tq2mK-0007if-Nn for geh-help-gnu-emacs@m.gmane.org; Tue, 01 Jan 2013 09:25:16 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:38924) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tq2mB-0007gV-Gg for help-gnu-emacs@gnu.org; Tue, 01 Jan 2013 09:25:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tq2m5-0003dr-SY for help-gnu-emacs@gnu.org; Tue, 01 Jan 2013 09:25:07 -0500 Original-Received: from mail-la0-f49.google.com ([209.85.215.49]:56476) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tq2m5-0003cO-Dg for help-gnu-emacs@gnu.org; Tue, 01 Jan 2013 09:25:01 -0500 Original-Received: by mail-la0-f49.google.com with SMTP id fk20so4854621lab.22 for ; Tue, 01 Jan 2013 06:24:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-type; bh=q5MvX47EssHB/eePqLJJmy+/oBG/O55B2JKIQjo6NrY=; b=OZmmFuKVh4RvJHB8+xzHEfe6Ors532bX+jvO6w3VsHHuSCEc1MsNcCs1ETnAJ0KLMv 0Gr2ZsSemB1PfR6Crdn4+9gpv34hAFycOm0AMnt4zX4EC+sUtFNwRmPYdx23nFWma9C8 E1ODPQHkoiFLMK19Tz3Zi1Jfu8HPd2JjGRgazTqOsq6VHKn/aI8hgquAyolMxEeBxoWb kDlNQAMrtKkOvphO2s/+OpFX6p80gRPyVSM7qZXeUN/I6eIq8b4vxJxCTt/fNWlSdV1G th8T6xk9UaQ3mNWtdy97MpK6saUxcSyqmPfR3YzqTOu+wKJrgt9YafZ/gSPH7UnO2P2n a2Yw== X-Received: by 10.152.108.48 with SMTP id hh16mr40817688lab.25.1357050299654; Tue, 01 Jan 2013 06:24:59 -0800 (PST) Original-Received: from SOL ([178.252.98.87]) by mx.google.com with ESMTPS id gr12sm16457770lab.3.2013.01.01.06.24.57 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 01 Jan 2013 06:24:58 -0800 (PST) In-Reply-To: <558f5257-18a8-46c4-8a41-71ea6066449e@googlegroups.com> (Sayth Renshaw's message of "Tue, 1 Jan 2013 04:27:00 -0800 (PST)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (windows-nt) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.215.49 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:88383 Archived-At: Hi Sayth, Sayth Renshaw 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