Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hi all,
here is my new .vimrc script for
- compiling my script
- IF there is an error, it opens a new tab, where it jumps to the line of the first error, and displays all the errors in a QuickFix buffer under the code (so, all my previous buffers are preserved and it doesn't "move them around")
- ELSE (no errors) it executes the script
This is all fairly common, but i added a feature :
by pressing
;f
it sets $CURRENT_FILE_TO_RUN to the path of the current active file. Then, when i press
;r
from any other file or tab, it runs the "current file to run" (the one chosen with ;f).

In its current version, you MUST have this line in all your perl files, i'm sure it's possible to not need this, i just didn't find how on my computer

" CAREFUL : i MUST have exactly this line in my Perl files : use Vi::QuickFix 'C:/quickfix_errors_tmp.err';

EXAMPLE SCENARIO :
It's very useful to me when i'm trying to make a test pass. I press ;f on the test file. Then I open other files in other buffers and/or tabs to modify them and try to make the test pass, and when i want to run the test, i just have to press ;r.
Then if there are errors it jumps to them, i correct them, press ;r to re-run the test, until the test passes. Then, i press ;qq to close the two buffer of the tab opened by QuickFix (there must be a better way to implement ;qq, but it works fine like this for me)

I also added ;R to run the current active file (and not the "file to run").

I hope this helps other people. Here is the code, to paste in .vimrc

""""""""""""""""""""""""""" " COMPILE, JUMP TO ERROR, and RUN the "CURRENT FILE TO RUN" " CAREFUL : i MUST have exactly this line in my Perl files : " use Vi::QuickFix 'C:/quickfix_errors_tmp.err'; let $ERROR_FILE = "C:/quickfix_errors_tmp.err" map ;r :call MakeWithCopenAndCfileInNewTab()<CR><CR> "current file to make must be the current one... let $CURRENT_FILE_TO_RUN = "%" let $PERL_COMPILE = "perl\\ -Ilib\\ -c\\ " function SetMakeprg() exe ":set makeprg=" . $PERL_COMPILE . $CURRENT_FILE_TO_RUN endfunction autocmd FileType perl call SetMakeprg() autocmd FileType perl set errorformat=%f:%l:%m autocmd FileType perl set autowrite "...unless we choose the file that we are reading as the "current file + to run" map ;f :call SetActiveFileToRun()<CR> function SetActiveFileToRun() let $CURRENT_FILE_TO_RUN=bufname("%") call SetMakeprg() endfunction " print who is the "current file to run" map ;F :call TellAndStop("The \"file to run\" with ;r is " \ . $CURRENT_FILE_TO_RUN \ . "\nUse ;R to run the active buffer file instead" ) "Compile, jump to first error (with QuickFix), and execute if there's +no error "From Marc Jessome, by email, 14th July 2012. "I modified the "for e in qflist "if !e.valid "by replacing it with "if len(qflist)>1 " because the elements of my qflist were not valid until i used :cfile function MakeWithCopenAndCfileInNewTab() make let qflist = getqflist() if len(qflist)>1 tabnew copen cfile $ERROR_FILE else exe "!perl\ -Ilib\ " . $CURRENT_FILE_TO_RUN endif endfunction " tells something to the user, and asks to press a button function TellAndStop(text) call inputsave() let name = input(a:text . "\npress Enter...") call inputrestore() endfunction "run the current file, not the "current_file_to_make" map ;R :call MakeTheCurrentFile()<CR> function MakeTheCurrentFile() "copy the "current_file_to_make" to a buffer let $BUF=$CURRENT_FILE_TO_RUN "compile+run the current file let $CURRENT_FILE_TO_RUN=bufname('%') call SetMakeprg() call MakeWithCopenAndCfileInNewTab() "retrieve the "current_file_to_make" path (from the buffer) let $CURRENT_FILE_TO_RUN=$BUF call SetMakeprg() endfunction "used for QuickFix to open its window after i compile set switchbuf=useopen " to quit a tab with 2 buffers open map ;qq :q<CR>:q<CR> " END of : COMPILE, JUMP TO ERROR, and RUN the "CURRENT FILE TO RUN " """"""""""""""""""""
BE CAREFUL (this happened to me) : if 'makeprg' is set to a value somewhere else in your .vimrc file, be careful that it doesn't override the value set by this code

Please enjoy it, improve it, and share what you've improved.

PS : i think i didn't put this message in the right place. Feel free to move it.


In reply to .vimrc script for "setting a current file to run", for which to compile, jump to errors, and run by mascip
in thread Editing features for advanced users by gmax

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-19 10:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found