Text editing question

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Text editing question

Steve C. Thompson
Hi Group,

Apologies in advance for being a bit off topic.  I have a
question about automatically indenting your code.  For example,
say you have

for i = 1 : 10
  a = i;
end

then you want to add a second loop some time later:

for j = 1 : 10
for i = 1 : 10
  a = i;
  b = j;
end
end

The code should read like:

for j = 1 : 10
  for i = 1 : 10
    a = i;
    b = j
  end
end

Instead of manually indenting the inner loop, I want to do this
automatically.  I know that Matlab's text editor has the
capability. I've also learned that xemacs can do this with:
Cmds > Indent > Region.  But I'm a Vim user.  Does anyone know
how to do this in Vim?

Thanks,
Steve



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Text editing question

kamaraju
Steve C. Thompson wrote:

>Hi Group,
>
>Apologies in advance for being a bit off topic.  I have a
>question about automatically indenting your code.  For example,
>say you have
>
>for i = 1 : 10
>  a = i;
>end
>
>then you want to add a second loop some time later:
>
>for j = 1 : 10
>for i = 1 : 10
>  a = i;
>  b = j;
>end
>end
>
>The code should read like:
>
>for j = 1 : 10
>  for i = 1 : 10
>    a = i;
>    b = j
>  end
>end
>
>Instead of manually indenting the inner loop, I want to do this
>automatically.  I know that Matlab's text editor has the
>capability. I've also learned that xemacs can do this with:
>Cmds > Indent > Region.  But I'm a Vim user.  Does anyone know
>how to do this in Vim?
>
>Thanks,
>Steve
>
>  
>
Select the region that you want to format and hit =

Why are you asking this question here? There is a separate vim users
mailing list available. More info on the vim lists can be found at

http://www.vim.org/maillist.php#vim

raju


--
Kamaraju S Kusumanchi
http://www.people.cornell.edu/pages/kk288/
http://malayamaarutham.blogspot.com/



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Text editing question

kamaraju
Steve C. Thompson wrote:

>On 22 Feb 06 17:58PM, kamaraju kusumanchi wrote:
>  
>
>>Select the region that you want to format and hit =
>>    
>>
>
>This doesn't work for me.  Selecting the text with `v' or with
>the mouse, and hitting `=' does nothing.
>  
>
Hmmm, It works fine here. I am using Debian Sid vim 6.4.7. What is your
OS and vim version?

Also in future, please keep the replies on the list (and no personal
emails please). That way other also the conversation and will be able to
help you.

>>Why are you asking this question here?
>>    
>>
>
>Because the Octave community is knowledgeable, helpful and
>usually friendly.
>  
>
That could be true. But that does not mean that OT can be posted. But I
guess you already know about that.

raju


--
Kamaraju S Kusumanchi
http://www.people.cornell.edu/pages/kk288/
http://malayamaarutham.blogspot.com/



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Text editing question

Stéfan van der Walt
On Wed, Feb 22, 2006 at 07:35:43PM -0500, kamaraju kusumanchi wrote:
> >This doesn't work for me.  Selecting the text with `v' or with
> >the mouse, and hitting `=' does nothing.
> >
> >
> Hmmm, It works fine here. I am using Debian Sid vim 6.4.7. What is your
> OS and vim version?

Doesn't work for me either, using
VIM - Vi IMproved 6.3 (2004 June 7, compiled Aug 22 2005 17:23:42).

And in ~/.vimrc:

set shiftwidth=2
set tabstop=4
set expandtab

To get the tabs working, I use Søren's octave.vim:

http://www.vim.org/scripts/script.php?script_id=1241

As an aside, for syntax highlighting, see:

http://www.octave.org/octave-lists/archive/octave-sources.1998/msg00011.html

(I personally use emacs, but I tried it out and it works, after adding
"syntax on" to ~/.vimrc).

Regards
Stéfan



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Text editing question

kamaraju
Stefan van der Walt wrote:

>On Wed, Feb 22, 2006 at 07:35:43PM -0500, kamaraju kusumanchi wrote:
>  
>
>>>This doesn't work for me.  Selecting the text with `v' or with
>>>the mouse, and hitting `=' does nothing.
>>>
>>>
>>>      
>>>
>>Hmmm, It works fine here. I am using Debian Sid vim 6.4.7. What is your
>>OS and vim version?
>>    
>>
>
>Doesn't work for me either, using
>VIM - Vi IMproved 6.3 (2004 June 7, compiled Aug 22 2005 17:23:42).
>
>And in ~/.vimrc:
>
>set shiftwidth=2
>set tabstop=4
>set expandtab
>
>To get the tabs working, I use Søren's octave.vim:
>
>http://www.vim.org/scripts/script.php?script_id=1241
>
>As an aside, for syntax highlighting, see:
>
>http://www.octave.org/octave-lists/archive/octave-sources.1998/msg00011.html
>
>(I personally use emacs, but I tried it out and it works, after adding
>"syntax on" to ~/.vimrc).
>
>Regards
>Stéfan
>  
>

By default .m files are recognized as matlab files.

I think (in both the above cases) the necessary indentation files are
not sourced properly. Let's try another method.

open the file by using -u NONE option

$gvim -u NONE temp/test2.m

Then paste your unindented code

Then source the appropriate matlab indentation files

On Debian this file is called as

/usr/share/vim/vim64/indent/matlab.vim

So I will be doing

:so /usr/share/vim/vim64/indent/matlab.vim

Then select all the lines with V or v or mouse etc., and then press =

Let me know if this works.

raju

--
Kamaraju S Kusumanchi
http://www.people.cornell.edu/pages/kk288/
http://malayamaarutham.blogspot.com/



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Text editing question

Stéfan van der Walt
On Thu, Feb 23, 2006 at 08:56:24AM -0500, kamaraju kusumanchi wrote:
> Stefan van der Walt wrote:
> >http://www.vim.org/scripts/script.php?script_id=1241
> >http://www.octave.org/octave-lists/archive/octave-sources.1998/msg00011.html
>
> By default .m files are recognized as matlab files.
>
> I think (in both the above cases) the necessary indentation files are
> not sourced properly. Let's try another method.

The scripts above do the job just fine (whereas Vim's built-in MATLAB
mode doesn't recognise keywords like "endwhile", "endif" etc.)  What
we do need to know is what the best way is to have Vim automatically
recognise Octave files and load the appropriate
indentation/highlighting modes.

Stéfan



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Text editing question

Mike Miller-20
On Thu, 23 Feb 2006, Stefan van der Walt wrote:

> What we do need to know is what the best way is to have Vim
> automatically recognise Octave files and load the appropriate
> indentation/highlighting modes.

Do MATLAB m-files ever have lines beginning with '#'?  If not, such lines
are common in Octave, so maybe the existence of one or more such lines
could be used to turn on the Octave mode.

Mike



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Text editing question

Steve C. Thompson
In reply to this post by kamaraju
On 23 Feb 06 08:56AM, kamaraju kusumanchi wrote:

> I think (in both the above cases) the necessary indentation files are
> not sourced properly. Let's try another method.
>
> open the file by using -u NONE option
>
> $gvim -u NONE temp/test2.m
>
> Then paste your unindented code
>
> Then source the appropriate matlab indentation files ...
>
> :so /usr/share/vim/vim64/indent/matlab.vim
>
> Then select all the lines with V or v or mouse etc., and then press =
>
> Let me know if this works.

Consider:

go = 1;
while
for j = 1 : 10
for i = 1 : 10
a = i;
b = j;
end
end
end

On my system [Kubuntu 5.10 (breezy); VIM - Vi IMproved 6.3,
Included patches: 1-78], using .../indent/matlab.vim, along with

  set expandtab
  set tabstop=2
  set shiftwidth=2

results in:

go = 1;
while
  for j = 1 : 10
    for i = 1 : 10
      a = i;
      b = j;
end
end
end

For some reason, the ends don't get properly indented.  The
octave.vim script
(http://www.vim.org/scripts/script.php?script_id=1241) seems to
only provide syntax support for endif, endwhile, and so forth.
But, from my testing, it doesn't help with indenting.

Steve

PS:

> Why are you asking this question here?
One sticking point for Matlab users is abandoning Matlab's text
editor.  Currently, Octave doesn't exactly have a GUI equivalent.
Personally, I get by fine (I think better) running Octave in
terminals, using Vim as my primary text editor.  But this doesn't
appeal to everyone.

Starting the thread here, I think, is appropriate since it falls
in the category of helping Matlab users become GNU Octave users.



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Text editing question

kamaraju
Steve C. Thompson wrote:

>
>
>Consider:
>
>go = 1;
>while
>for j = 1 : 10
>for i = 1 : 10
>a = i;
>b = j;
>end
>end
>end
>
>On my system [Kubuntu 5.10 (breezy); VIM - Vi IMproved 6.3,
>Included patches: 1-78], using .../indent/matlab.vim, along with
>
>  set expandtab
>  set tabstop=2
>  set shiftwidth=2
>
>results in:
>
>go = 1;
>while
>  for j = 1 : 10
>    for i = 1 : 10
>      a = i;
>      b = j;
>end
>end
>end
>
>For some reason, the ends don't get properly indented.  The
>octave.vim script
>(http://www.vim.org/scripts/script.php?script_id=1241) seems to
>only provide syntax support for endif, endwhile, and so forth.
>But, from my testing, it doesn't help with indenting.
>  
>

Yes. That is the behaviour I am also seeing. I reported this as a minor
bug on the Debian BTS

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=354054

I did not have time to look into the indentation script. May be if you
have a patch, the maintainer will be fixing it more quickly.


thanks
raju

--
Kamaraju S Kusumanchi
http://www.people.cornell.edu/pages/kk288/
http://malayamaarutham.blogspot.com/



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------