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

Comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (5)
    As of 2015-07-05 05:08 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (60 votes), past polls