Use Mq in Emacs without turning all my code into comments

Say that you write such code (using ruby ​​mode, but I saw how it happens in other modes):

# This is a comment. def foo puts "foo!" end 

If you put a dot on the first line and press Mq, you get the following:

 # This is a comment. def foo puts "foo!" end 

How to avoid this? I am using version 21.3.

Explanation: This does not happen when I add an empty line between the comment and the code. In the process, when I want to replenish my comments, I spend an annoying three-step process:

  • I add an empty line before and after the comment
  • Md
  • delete blank lines

It would be much nicer if Mq handled repeated additions of comments without the need to add and remove empty lines. Emacs already knows which text is a comment, so there should be a way to do this.

+4
source share
4 answers

filladapt.el does the trick. This is with the latest version of RubyMode .

Using these two packages solves the Mq problem you see. (Using GNU Emacs 22.1)

Looking at the code for ruby ​​mode, it looks like he configured the variables to control the filling of the paragraph as follows:

 (make-local-variable 'paragraph-start) (setq paragraph-start (concat "$\\|" page-delimiter)) (make-local-variable 'paragraph-separate) (setq paragraph-separate paragraph-start) (make-local-variable 'paragraph-ignore-fill-prefix) (setq paragraph-ignore-fill-prefix t) 

What can be added to the custom hook for your current ruby ​​or in any main mode in which you want the filling behavior to execute as you described, provided that you use filladapt.el.

+5
source

Mq is required to fill in the paragraph, what he does is trying to intelligently turn the text into a paragraph. It has functions that try to guess the "fill-prefix" that seems to be happening to you.

You can untie Mq if you don't like it.

 (global-unset-key (kbd "Mq")) 
+1
source

Filling comments works in sh-mode .

Perhaps you should report a bug in ruby-mode support?

+1
source

You need to be in Ruby mode for Emacs to understand that " # This is a comment. " Is a comment. If you are in native mode, it will treat everything as a text paragraph, which makes you think that the text on the next line is part of the same paragraph.

Below are some instructions for setting up Ruby mode if you do not already have one.

0
source

All Articles