Rinari Coding information in Buffer

9 views
Skip to first unread message

Ulrich Wolf

unread,
Aug 19, 2008, 8:47:22 PM8/19/08
to emacs-o...@googlegroups.com
Hi,

I'm using rinari quite happily but on every save it puts the coding
information like

# -*- coding: utf-8 -*-

on the beginning of every buffer, when there is an umlaut in it. This
may be ok for controllers and model files, but more often than not, it
does this also with views, which is most annoying. Is this a feature or
a bug? Anyone knows how can I get rid of it?
My rinari version is of 07/28/08

Thanks
Ulrich

Steve Purcell

unread,
Aug 22, 2008, 6:05:49 AM8/22/08
to emacs-o...@googlegroups.com
Hi Ulrich,

That seems to be a "feature" of the upstream ruby-mode version that
has been bundled with rinari.

I've patched Rinari's ruby-mode.el locally, so that you can turn off
the magic comments using emacs' customize interface or a "(setq ruby-
insert-encoding-magic-comment nil)" in your .emacs. The patch is
included below.

(Perhaps someone better-connected than me would like to try to get
this change accepted upstream, by Matz or whoever...)

Hope that helps,

-Steve


diff --git a/ruby-mode.el b/ruby-mode.el
index c995003..a94d649 100644
--- a/ruby-mode.el
+++ b/ruby-mode.el
@@ -188,6 +188,10 @@ Also ignores spaces after parenthesis when 'space."
"Alist to map encoding name from emacs to ruby."
:group 'ruby)

+(defcustom ruby-insert-encoding-magic-comment t
+ "*Insert a magic emacs 'coding' comment upon save if this is non-
nil."
+ :type 'boolean :group 'ruby)
+
(defcustom ruby-use-encoding-map t
"*Use `ruby-encoding-map' to set encoding magic comment if this is
non-nil."
:type 'boolean :group 'ruby)
@@ -296,7 +300,8 @@ Also ignores spaces after parenthesis when 'space."
((forward-char)))))
(insert coding-system)))
((looking-at "\\s *#.*coding\\s *[:=]"))
- (t (insert "# -*- coding: " coding-system " -*-\n")))))))
+ (t (when ruby-insert-encoding-magic-comment
+ (insert "# -*- coding: " coding-system " -*-
\n"))))))))

;;;###autoload
(defun ruby-mode ()

Ulrich Wolf

unread,
Aug 22, 2008, 8:54:55 AM8/22/08
to emacs-o...@googlegroups.com
Thanks Steve,

your patch works fine. Another reason to stick to emacs.

Ulrich


Eric Schulte

unread,
Aug 22, 2008, 10:11:34 AM8/22/08
to emacs-o...@googlegroups.com
Steve,

Thanks for the patch, I have applied it to the ruby-mode bundled with
rinari.

My impression is that it is difficult to get Matz's attention for
emacs related queries, e.g. signing FSF papers.

Thanks -- Eric

--
schulte


Steve Purcell

unread,
Aug 22, 2008, 10:17:22 AM8/22/08
to emacs-o...@googlegroups.com
Yay, thanks Eric.

-Steve

Phil Hagelberg

unread,
Aug 22, 2008, 1:03:29 PM8/22/08
to emacs-o...@googlegroups.com
"Eric Schulte" <schult...@gmail.com> writes:

> Thanks for the patch, I have applied it to the ruby-mode bundled with
> rinari.
>
> My impression is that it is difficult to get Matz's attention for
> emacs related queries, e.g. signing FSF papers.

Sad but true. I may be able to get him to sign the papers at RubyConf,
but by then it will probably be too late for inclusion in Emacs 23.

As for this patch, a better solution may be to make it insert the header
comment, but use whatever comment syntax that mode had defined rather
than just using "#". (In other words, insert the coding info and use
`comment-region' on it.) That way Emacs will still have the coding
information necessary. Of course, being able to disable it entirely is
still good, but I think this would be better. I can implement this once
I get back to hacking on ruby-mode.el (if nobody has gotten to it by
then.)

-Phil

Eric Schulte

unread,
Aug 22, 2008, 1:35:37 PM8/22/08
to emacs-o...@googlegroups.com
On Friday, August 22, at 10:03, Phil Hagelberg wrote:
...

>
> As for this patch, a better solution may be to make it insert the header
> comment, but use whatever comment syntax that mode had defined rather
> than just using "#". (In other words, insert the coding info and use
> `comment-region' on it.) That way Emacs will still have the coding
> information necessary. Of course, being able to disable it entirely is
> still good, but I think this would be better. I can implement this once
> I get back to hacking on ruby-mode.el (if nobody has gotten to it by
> then.)
>
> -Phil

I know this wasn't intended as an open call for suggestions/requests
for ruby-mode.el, but taking it as such :)

- sexp movement (foward-sexp, backward-sexp, kill-sexp) is not
reliable especially around comments and strings, when this type of
movement works reliably (as it does when editing lisp in emacs) it
GREATLY simplifies code navigation and re-ordering
- syntax highlighting and indentation don't work as expected for some
of the fancier ruby literals %q %w etc.

I'm sure there's more... likewise if I find time, I will make the
commenting change

On a related note, is there currently a `master' location for
ruby-mode.el? If not for the time being I'd be happy to maintain, add
patches etc.. for the ruby-mode.el in rinari.

On another related note, does git/github have any mechanism for
including files in one git repo from another git repo?

thanks,

--
schulte


Steve Purcell

unread,
Aug 22, 2008, 2:13:02 PM8/22/08
to emacs-o...@googlegroups.com
What ruby-mode files wouldn't use '#' for comments? Or are you
thinking of somehow inserting appropriate comments into buffers with
ruby-mode in MMM/MuMaMo blocks?

My intention with the patch was to retain the logic for updating the
magic comment if present, but allow the user to choose whether to
insert such comments in new files. I'd imagine that covers the vast
majority of use cases, and that any smarter scheme would yield
diminishing returns.

I was surprised to find the magic comment code in ruby-mode at all, to
be honest -- it doesn't seem to be Ruby-specific, and I'd think that a
general library could (or should) exist to provide that functionality.

-Steve

Jorge Calás Lozano

unread,
Aug 22, 2008, 10:39:35 PM8/22/08
to emacs-o...@googlegroups.com
> On a related note, is there currently a `master' location for
> ruby-mode.el? If not for the time being I'd be happy to maintain, add
> patches etc.. for the ruby-mode.el in rinari.

That would be great!

> On another related note, does git/github have any mechanism for
> including files in one git repo from another git repo?

git help submodule

> thanks,

thanks you ... for the code ;)

joahking

unread,
Sep 8, 2008, 7:35:05 AM9/8/08
to Rails On Emacs
hello,
some observations on the subject,

I just updated my repo with eschulte's one to get rid of the # -*-
coding: utf-8 -*- on views, but it wont go

here is what I found: if your view starts with ruby-code (e.g. <%
content_for ... -%>) emacs will take your whole view as a ruby-file

workaround: if I leave the first line blank and start coding on the
second the issue is gone and no # -*- coding: utf-8 -*- on first line

maybe helps someone

hey, great work guys
joaquin

Steve Purcell

unread,
Sep 8, 2008, 8:20:39 AM9/8/08
to emacs-o...@googlegroups.com
Insertion of the magic comments is still enabled by default. Either
use the customize interface to disable it, or put the following in
your .emacs or init.el --

(setq ruby-insert-encoding-magic-comment nil)

It certainly does seem wrong that the comments would get inserted at
the beginning of .erb files, but the above setting will give you the
result you want.

-Steve

Reply all
Reply to author
Forward
0 new messages