End matching

S

Steve Litt

Hi all,

That's it, THAT'S IT! I'm tired of forgetting an end or inserting
one too many, and traipsing through the whole program to find it.
Vim doesn't really match End statements with their keywords.

So I'm going to write an end matching program. Could somebody please
list all the keywords that are ended by "end"? Do any of these
keywords ever not end in "end"?

Thanks

SteveT

Steve Litt
http://www.troubleshooters.com
(e-mail address removed)
 
R

Robert Klemme

Steve said:
Hi all,

That's it, THAT'S IT! I'm tired of forgetting an end or inserting
one too many, and traipsing through the whole program to find it.
Vim doesn't really match End statements with their keywords.

So I'm going to write an end matching program. Could somebody please
list all the keywords that are ended by "end"? Do any of these
keywords ever not end in "end"?

"class", "module", "def", "do", "begin", "while", "until", "if",
"unless" - control flow statements can be used as post expression in which
case they do not end in "end":

puts foo if foo > 10

You might be able to make your life easier by using a Ruby parser. There
are even implementation(s) in Ruby.

Btw, there's an easier cure for this: just get used to typing the "end"
immediately after typing the starting token, then go back a word and type
the containing text. Same works for all sorts of brackets etc.

Kind regards

robert
 
J

Jim Freeze

Hi all,

That's it, THAT'S IT! I'm tired of forgetting an end or inserting
one too many, and traipsing through the whole program to find it.
Vim doesn't really match End statements with their keywords.

The rubyvim doesn't match 'end'? I used to use this,
but haven't needed it for years.
 
J

James Edward Gray II

Hi all,

That's it, THAT'S IT! I'm tired of forgetting an end or inserting
one too many, and traipsing through the whole program to find it.
Vim doesn't really match End statements with their keywords.

So I'm going to write an end matching program. Could somebody please
list all the keywords that are ended by "end"? Do any of these
keywords ever not end in "end"?

class / module / def
begin / do
if / unless (end not requires when used as statement modifiers)
while / until (end not requires when used as statement modifiers)

Hope that's all of them, but I may have missed some.

James Edward Gray II
 
J

James Edward Gray II

Btw, there's an easier cure for this:
Definitely.

just get used to typing the "end" immediately after typing the
starting token

Or better have your editor do that busy work for you.

Proper indentation should make missing ends very obvious as well.

James Edward Gray II
 
P

Paul Battley

So I'm going to write an end matching program. Could somebody please
list all the keywords that are ended by "end"? Do any of these
keywords ever not end in "end"?

One wrinkle: 'do' does not always end in 'end'. It can be a method,
and is used as such in DBI (e.g. 'dbh.do(...)'). It should be easy
enough to handle that case by checking for a preceding period,
however.

Paul.
 
H

Hugh Sasse

Hi all,

That's it, THAT'S IT! I'm tired of forgetting an end or inserting
one too many, and traipsing through the whole program to find it.

It's a bit of a problem, I agree. I usually create them when I
create the /if|def|do|case|module|class|while/ and create the contents after.

There have been limitations imposed on Ruby by having the parser
implemented in YACC which have come up before. One is that it is
nontrivial to get really good error diagnostics out.
Vim doesn't really match End statements with their keywords.

:he matchit

You need to do a little installation of matchit for it to work
properly, because vim defaults to behaving like VI.
So I'm going to write an end matching program. Could somebody please
list all the keywords that are ended by "end"? Do any of these
keywords ever not end in "end"?

Before you go to the trouble of all that, whwat is your vimrc like?
maybe there are more things you can turn on that will help.

Mine, somewhat pruned, is like this:
<quote>
set autoindent
set expandtab
set shiftwidth=2 " Mostly Ruby development -- std convention 2, not 4
set textwidth=68 " Do want this generally applied now...
"set ttyscroll=0
"
runtime ftplugin/man.vim
filetype plugin on "if you want the ftplugin to run
filetype indent on "if you want indenting support
syntax on
autocmd FileType * exec('setlocal dict+='.$VIMRUNTIME.'/syntax/'.expand('<amatch>').'.vim')
runtime plugin/matchit.vim

"nmap <M-R> :exe ":undo|:set paste|:normal .:set nopaste"

"Give a status line always
set ls=2
Thanks

SteveT
Hugh
 
J

James Edward Gray II

One wrinkle: 'do' does not always end in 'end'. It can be a method,
and is used as such in DBI (e.g. 'dbh.do(...)'). It should be easy
enough to handle that case by checking for a preceding period,
however.

I imagine all the words in that list have the same issue.

Checking for the period is a good start, but watch out for edge cases:

send:)do, *args)

James Edward Gray II
 
B

Bill Guindon

I imagine all the words in that list have the same issue.

Checking for the period is a good start, but watch out for edge cases:

send:)do, *args)

and speaking of 'cases', don't forget 'case'.
 
E

Eero Saynatkari

Steve said:
Hi all,

That's it, THAT'S IT! I'm tired of forgetting an end or inserting
one too many, and traipsing through the whole program to find it.
Vim doesn't really match End statements with their keywords.

So I'm going to write an end matching program. Could somebody please
list all the keywords that are ended by "end"? Do any of these
keywords ever not end in "end"?

Actually, I recommend a proactive approach: just condition
yourself to input the ending character at the same time you
write the starting block. So, type a 'do', type an 'end' and
then backtrack your cursor betwixt.

Also, the better editors support brace/block matching. Vim's
'%' works in most ruby instances, for example.
Thanks

SteveT


E
 
M

Martin DeMello

James Edward Gray II said:
I imagine all the words in that list have the same issue.

Checking for the period is a good start, but watch out for edge cases:

send:)do, *args)

Would probablly be better to check for everything that *can* precede the
'do' and have it be a real end-ended do.

martin
 
D

Doug H

Has anyone ever written a proposal for optional labels after an "end".
I've written a parser for another language that allows that. So for
example you can type "end class" at the end of a class. If you forget
to type an "end def" inside the class it will tell you the error you
made more clearly instead of matching "end class". And you can still
just type "end" alone to match anything.

Oh, and just to mention this for the heck of it (not that it should be
seriously considered for ruby), you can actually parse the same code
with no "end" at all if the lines in a block are all indented the same.
You don't need the colon like in python. Just noting that after
seeing a failed ruby proposal that seemed to imply the colon was
required: http://www.rcrchive.net/rcr/show/299
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top