emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Small improvements to ruby-mode


From: Dmitry Gutov
Subject: Re: Small improvements to ruby-mode
Date: Tue, 02 Jul 2013 22:38:10 +0400
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7

Hmm, I don't see either of these problems with the current trunk. Have you checked for stale ruby-mode.elc or a rogue ruby-mode.el installed via ELPA?

I did encounter the following semi-known issue:

Putting the cursor on one of the 4 lines after "elsif" in the second example and pressing `C-M-p' moves it to the "add_offence" line.

And pressing `C-M-n' after that moves it to the "end" closing the "operands.each" block.

Pressing `C-M-p' or `C-M-n' on the `elsif' line misbehaves similarly.

I'll see about fixing that.

On 02.07.2013 19:46, Bozhidar Batsov wrote:
Here's a bit of code:

            operands.each do |op|
               if LITERALS.include?(op.type)
                 add_offence(:warning, op.loc.expression,
                             format(MSG, op.loc.expression.source))

               end
             end

Placing the cursor somewhere in the `if` yields totally crazy results
(or even errors from time to time - "setq: Wrong type argument:
number-or-marker-p, nil") when calling `ruby-beginning-of-block` and
`ruby-end-of-block`. I'd expect `ruby-beginning-of-block` to go to the
`each` line and `ruby-beginning-of-block` to go to the `end` of the
block in question. There's also the question if constructs ending with
an `end` should be treated as blocks as well - that might be useful to
develop scope highlighting tools without a lot of custom code.

def-end, if-end, etc, are already treated as blocks.

Regarding the other problem I mentioned - mark defun doesn't always work
correctly:

         def check_for_literal(node)
           cond, = *node

           # if the code node is literal we obviously have a problem
           if LITERALS.include?(cond.type)
             add_offence(:warning, cond.loc.expression,
                         format(MSG, cond.loc.expression.source))
           elsif [:and, :or].include?(cond.type)
             # alternatively we have to consider a logical node with a
             # literal argument
             *operands = *cond
             operands.each do |op|
               if LITERALS.include?(op.type)
                 add_offence(:warning, op.loc.expression,
                             format(MSG, op.loc.expression.source))

               end
             end
           end
         end

Place the cursor inside the innermost `if` near the end of the defun and
try `C-M-h` there - you'll see that only a portion of the defun will be
marked.

`mark-defun' call `beginning-of-defun' and `end-of-defun', and they work pretty reliably here.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]