Permalink
Browse files

Hook core files into quickfix window

Thanks to Isaac Schlueter for pointing out a way to load the core files
into memory.

Fixes #1
  • Loading branch information...
1 parent fa73dd7 commit ee880a8c4b5d9767609ac6e793175c555bd3b617 @felixge committed Dec 22, 2011
Showing with 39 additions and 7 deletions.
  1. +0 −7 Readme.md
  2. +39 −0 ftplugin/javascript.vim
View
7 Readme.md
@@ -42,11 +42,4 @@ The quickfix window generated by this plugin:
![Screenshot 3](https://github.com/felixge/vim-nodejs-errorformat/raw/master/screenshots/3.png)
-## Known Problems
-
-* Node core modules are listed in the quickfix window, but can't be opened
- because node.js does not install those files on your local system. I am
- looking for ideas on a clever hack, otherwise I'll make an option for hiding
- those files from the error list.
-
[pathogen]: https://github.com/tpope/vim-pathogen
View
39 ftplugin/javascript.vim
@@ -1,3 +1,8 @@
+if exists('g:loaded_nodejs_errorformat')
+ finish
+endif
+let g:loaded_nodejs_errorformat = 1
+
let &makeprg="node %"
" Error: bar
@@ -15,3 +20,37 @@ let &errorformat .= '%A%f:%l,%Z%p%m' . ','
" Ignore everything else
let &errorformat .= '%-G%.%#'
+
+function! HookCoreFilesIntoQuickfixWindow()
+ let files = getqflist()
+ for i in files
+ let filename = bufname(i.bufnr)
+
+ " Non-existing file in the quickfix list, assume a core file
+ if !filereadable(filename)
+ " Open a new split / buffer for loading this core file
+ execute 'split ' filename
+ " Make this buffer modifiable
+ set modifiable
+ " Set the buffer options
+ setlocal buftype=nofile bufhidden=hide
+ " Clear all previous buffer contents
+ execute ':1,%d'
+ " Load the node.js core file (thanks @izs for pointing this out!)
+ execute 'read !node -e "process.binding(\"natives\").' expand('%:r') '"'
+ " Delete the first line, always empty for some reason
+ execute ':1d'
+ " Tell vim to treat this buffer as a JS file
+ set filetype=javascript
+ " No point in making this file writable
+ setlocal nomodifiable
+ " Point our quickfix entry to this (our current) buffer
+ let i.bufnr = bufnr("%")
+ " Close the split, so our little hack stays in the background
+ close
+ endif
+ endfor
+ call setqflist(files)
+endfunction
+
+au QuickfixCmdPost make call HookCoreFilesIntoQuickfixWindow()

0 comments on commit ee880a8

Please sign in to comment.