Skip to content
Browse files

make RunCurrentSketch output path configurable

  • Loading branch information...
1 parent 41c1333 commit e0d7860596e6edef964e4575e977f6222eea2b21 @goonzoid committed
Showing with 35 additions and 16 deletions.
  1. +17 −14 README.md
  2. +18 −2 ftplugin/reprocessed.vim
View
31 README.md
@@ -12,8 +12,7 @@ Please note that this plugin has currently only been tested on OS X.
* Syntax highlighting
* Documentation lookup
-* Run sketches from within vim (experimental and potentially dangerous,
-read below for more info)
+* Run sketches from within vim
### Looking up documentation
@@ -36,21 +35,26 @@ to make a copy of that documentation elsewhere on the filesystem.
### Running sketches from within vim
-__WARNING:__ If you have a directory inside your sketch directory called "bin"
-then it will be destroyed when you run your sketch using this method. This is
-because `processing-java` requires an output directory to be specified, which
-reprocessed specifies as "bin" in the same directory of your sketch.
-`processing-java` will stomp on this directory without warning because we're
-using the `--force` option, which is required to prevent you having to delete
-the directory manually after each run. I plan to make this path configurable
-at some point in the future, but until then, __you have been warned!__
-
This feature requires the `processing-java` command to be available on your
`PATH`. On Linux & Windows you'll need to add it manually, but on OS X you should
-be able to install this from within the Pocessing app. See the [processing wiki]
+be able to install this from within Processing.app. See the [processing wiki]
(http://wiki.processing.org/w/Command_Line) for more information.
-Another requirement is that your directory structure follow the pattern that
+__WARNING:__ If you have a directory inside your sketch directory called "bin"
+then it will be destroyed when you run your sketch using this method, unless you
+have explicitly configured reprocessed to use a different path using
+`processing_output_dir`.
+If for some reason you need to specify the output directory for `processing-java`
+to some path other than "bin", then you can do so with the following line in your
+.vimrc:
+
+ let processing_output_dir="output/"
+
+The path you set is relative to the current sketch directory. Note that
+reprocessed will run `processing-java` with the `--force` option, and so this
+directory will get nuked every time you run your sketch. __You have been warned!__
+
+One other requirement is that your directory structure follow the pattern that
Processing expects: your sketch file should have the same name as the directory
in which it exists. If you created your sketch using the Processing app then
this is unlikely to be an issue, but it's something to be aware of if you're
@@ -88,6 +92,5 @@ Just clone it:
## TODO
* Cleanup and update syntax file for Processing 2
-* Make processing-java output path configurable
* Make processing-java run key command configurable
View
20 ftplugin/reprocessed.vim
@@ -12,8 +12,24 @@ setlocal suffixesadd=.pde
setlocal commentstring=//\ %s
let b:undo_ftplugin = "setlocal cin< cink< fo< sua< cms<"
-nmap <buffer> <leader>r :w\|:!processing-java --sketch=%:p:h --output=%:p:h/bin --force --run<cr>
-
+" Run sketches from within vim
+function! RunCurrentSketch()
+ let output_dir = "bin"
+ if exists("g:processing_output_dir")
+ let output_dir = g:processing_output_dir
+ let has_leading_slash = match(output_dir, "/") == 0
+ if has_leading_slash
+ let output_dir = substitute(output_dir, "/", "", "")
+ endif
+ endif
+ let cmd_string = ":!processing-java --sketch=%:p:h --output=%:p:h/{0} --force --run"
+ let cmd_string = substitute(cmd_string, "{0}", output_dir, "")
+ :w
+ exec cmd_string
+endfunction
+nnoremap <buffer> <leader>r :call RunCurrentSketch()<cr>
+
+" Documentation lookup
if has("python")
if exists("g:processing_doc_path")
let g:processing_doc_style = "local"

0 comments on commit e0d7860

Please sign in to comment.
Something went wrong with that request. Please try again.