calling normal commands from ex/a function

2007-05-16 Thread fREW

Hey everyone,

How do I have a function call Normal commands?  Example: I'd like to
make a function that will open a certain file, and then set the
foldlevel to 1, and then go to the right window.  So I have:

function TodoListMode()
 execute :e ~/.todo.otl
 execute :Calendar
endfunction

and then after the second command I want to do:
ctrlwl
zM
zr

Thanks!

-fREW


Re: calling normal commands from ex/a function

2007-05-16 Thread Robert Cussons

fREW wrote:

Hey everyone,

How do I have a function call Normal commands?  Example: I'd like to
make a function that will open a certain file, and then set the
foldlevel to 1, and then go to the right window.  So I have:

function TodoListMode()
 execute :e ~/.todo.otl
 execute :Calendar
endfunction

and then after the second command I want to do:
ctrlwl
zM
zr

Thanks!

-fREW



Hi fREW,

execute normal! ctrlwl zM zr

would be my guess, but I've never tried writing my own functions, this 
is adapted from someone else's work, so someone else's input would be 
useful :-)


Rob.




Re: calling normal commands from ex/a function

2007-05-16 Thread Charles E Campbell Jr

fREW wrote:


Hey everyone,

How do I have a function call Normal commands?  Example: I'd like to
make a function that will open a certain file, and then set the
foldlevel to 1, and then go to the right window.  So I have:

function TodoListMode()
 execute :e ~/.todo.otl
 execute :Calendar
endfunction

and then after the second command I want to do:
ctrlwl
zM
zr


* may I point out that you're using execute when you don't need to.
* you're already in ex mode; no need to use colons to do ex mode commands
* ctrl-w_l can be performed with wincmd l .
* to perform normal mode commands in a function, use norm! (the 
exclamation prevents any maps from interfering)


So, with these points in mind:

fun! TodoListMode()
 e ~/.todo.otl
 wincmd l
 norm! zMzr
 Calendar
endfun

Now, I confess that I didn't test this...

Regards,
Chip Campbell



Re: calling normal commands from ex/a function

2007-05-16 Thread fREW

On 5/16/07, Charles E Campbell Jr [EMAIL PROTECTED] wrote:

fREW wrote:

 Hey everyone,

 How do I have a function call Normal commands?  Example: I'd like to
 make a function that will open a certain file, and then set the
 foldlevel to 1, and then go to the right window.  So I have:

 function TodoListMode()
  execute :e ~/.todo.otl
  execute :Calendar
 endfunction

 and then after the second command I want to do:
 ctrlwl
 zM
 zr

* may I point out that you're using execute when you don't need to.
* you're already in ex mode; no need to use colons to do ex mode commands
* ctrl-w_l can be performed with wincmd l .
* to perform normal mode commands in a function, use norm! (the
exclamation prevents any maps from interfering)

So, with these points in mind:

fun! TodoListMode()
  e ~/.todo.otl
  wincmd l
  norm! zMzr
  Calendar
endfun

Now, I confess that I didn't test this...

Regards,
Chip Campbell




Thanks for the pointers!

I ended up with this, which doesn't use any normal commands at all ironically.


function! TodoListMode()
 e ~/.todo.otl
 Calendar
 wincmd l
 set foldlevel=1
endfunction

Thanks for the help though, it works just as one would hope now!

-fREW