Emacs: Using a major-mode's font-locking only for mmm-mode - ruby-on-rails

I've got MMM-mode set up to edit .html.erb files, but indentation does not work in the ruby sections, and all the different electric behaviours of ruby-mode do the wrong thing. I've changed this sub-mode from ruby-moode to fundamental-mode, and it works much better.
I want to still use ruby-mode's font-locking though, is this possible/easy? Any hints on where to start.
Elisp is comfortable to me, but I don't have too much time right now to dig too deeply myself. Hopefully someone will have a snippet?

I see you haven't yet found an answer. Dunno whether it will be better for this, but you might consider using MuMaMo instead of MMM.

To answer the question, you would define a major mode deriving from fundamental-mode, and in its body just copy the font-lock-related lines from the ruby-mode definition body, the ones setting font-lock- variables and also syntax-propertize-function. Naturally , you need to (require 'ruby-mode) somewhere.
But for .html.erb files I can now recommend using mmm-erb, which was not available when this question was asked.

Related

Code commenter gem

I was sure a few months ago there was a gem that made sure you've commented every single line of code. Or at least every single action. If you hadn't, it brought your attention to it after you'd run some sort of rake task.
Can't remember for the life of me what it was called.
But is it a good idea to comment every single line of code? I say yes, it solidifies your knowledge, gives you a last change to catch bugs/security holes and eases future development.
However, projects in github and really sparsely commented. Personally, I need to comment most lines before I start to realise what a piece of code does. Is this not the case for most? Do comments just trip the code ninjas up?
Commenting every single line of code is a horrible idea:
It's noisy and obfuscates the source
It becomes out of date trivially easily
Things to comment:
Tricky and/or hacky code
Complicated algorithms
Why something is doing what it's doing
Those comments should almost always live at the method level.
If a code block needs a comment it should probably be a method
If a line of code needs a comment it should probably be refactored
Code should speak for itself as much as possible. Appropriate naming goes a long way to eliminating the need for wads of commenting. Some documentation may absolutely be necessary, but in the case of large structural comments, it may make more sense to keep it out of the code, and in your wiki.
No, it's not a good idea to comment every line of code. A lot of code is self-explanatory. In fact, you should strive to make your code self-explanatory.
For example, you would never want to comment the following:
sum = 1 + 3
You should save your comments for things that need explaining.
What I think you mean is a gem that enforces proper documentation. Documentation is a comment that explains the purpose of a method or class, as well as details its parameters and return values.
Regarding the gem you're thinking of, it may be rubocop.

How do I add a wireshark column that will display the value of an HTTP Request Query Parameter?

For example :
If I had http://somepage.com/somefolder/someresouce?p1=value&p2=value&p3=value
I would like to see a column that would display the value of p2 if it existed in the request.
I googled, asked people around but can't find a good answer.
If think creating a dissector might help, but I don't want to write a new dissector for http.. that's an overkill.
And there is no http.request.queryParams["p2"] syntax for use of Custom Column type.
Thanks in advance!
Edit : I solved my own Question, adding the best implementation so far in my own answer below.
Well, the solution was indeed in dissectors.
Wireshark help is not very good, the examples are ok though.
The main problem was that wireshark help defines that you can write your lua script, and place it in the plugins directory, which is searched recursively for lua files.
I did place my lua there and nothing worked, After almost 2 hours of fiddling, I found out instead of putting it in the plugins directory, it had to be in plugins//myScript.lua in order to work...
Now just to share my work :
To answer my own question :
http://pastebin.com/eANEut92

What exactly does $:.unshift(File.expand_path("../../lib", __FILE__)) do?

There are a lot of threads on here about this already I know but none of the titles have this worded exactly like I did. I hope that we can clear this up a bit.
$:.unshift(File.expand_path("../../lib", __FILE__))
You see something like this in a lot of Ruby code.
Opinions vary whether this is proper or not.
Can we get a little explaination for each of its parts? There realy is a lot going on here. I only understand some of it.
$: holds Load path for scripts and binary modules by load or require. . And Array#unshift will prepend the new path to $:. File#expand_path Converts a pathname to an absolute pathname. __FILE__ is already answered here What does __FILE__ mean in Ruby?.

In rails.vim why do I get "E345 can't find file in path" errors?

I've been learning Ruby/Rails with vim. Tim Pope's rails.vim seems like a really good tool to traverse files with, but I keep getting these pesky "E345 can't find file in path" errors. I'm not vim expert yet, so the solution isn't obvious. Additionally, I've tried this and it doesn't apply to my problem.
As an example of the problem. I have a method format_name defined in app/helpers/application_helper.rb and it is used in app/helpers/messages_helper.rb. Within the latter file I put my cursor over the usage of format_name and then hit gf and I get that error. Similar disfunction with commands like ]f and [f
However, it works sometimes. I was able to gf from user to the app/models/user.rb
Ideas?
I think that is a limitation of rails.vim. It does not support “finding” bare methods. Supporting something like that would require one of the following:
an exhaustive search of all the source files for each “find” request
(which could be expensive with large projects),
“dumb” indexing of method names
(e.g. Exuberant Ctags and gControl-]; see :help g_CTRL-]), or
smart enough parsing of the code to make a good guess where the method might be defined
(which is hard to do properly).
If you know where the method is, you can extend many of the navigation commands with a method name:
:Rhelper application#format_name
But, you do not have to type all of that in. Assuming the cursor is on format_name you can probably just type:RhTabspaceappTab#Control-R Control-W (see :help c_CTRL-R_CTRL-W).

Problems with Netbeans re: Rails erb/rhtml intellisense?

I've been using Netbeans for Rails and like it a lot, considering how little I paid for it. But something that bothers me is that when I'm editing an RHTML or ERB file, it doesn't do the code autocomplete - or at least not reliably. Sometimes it shows the appropriate variables and methods that are available on an object after you type the dot operator. Sometimes it ignores the instance variables. Is there a solution for this? (Please don't say RadRails).
Oh and one more thing in case anyone has solved this: considering how often I have to type <% when I'm in a Rails template, I wish there was some hotkey for autotyping the tag . . . ? I always have to stop and look down at my keyboard to find the < and % keys before I can type the tag so it's not as trivial as it might sound.
I believe you're looking for something like this:
http://ruby.netbeans.org/codetemplates-rhtml.html
Type in one of the triggers, then hit the tab key to expand it to the code as given.
Also, you might want to explore using HAML. It's much easier on the hands.

Resources