#! /usr/bin/ruby -w # Create a skeleton matlab function from the command line: # i.e matlabSkell.rb '[c, d] = makeMovie(a, b) % optional desc.' # should create something like: # # filename: makeMovie.m # function [c, d] = makeMovie(input) % optional desc. # % function a = makeMovie(input) # % optional description here. # % # % Matt Foster # # Use with the following in your .vimrc # map #5 :execute MatSkell() # # " Create a skeleton m file using the function prototype that is the current # " line. # function MatSkell() # let s:line = getline(".") # let s:output = system("matlabSkell.rb \'" . s:line . "\'") # :execute ":e " . s:output # endfunction owner = "Matt Foster " proto = ARGV[0].to_s proto =~ /^(.*\s+=\s+(.*)\(.*\));?\s*%?\s*(.*)$/ funcProto = "function #{$1}" desc = $3 filename = "#{$2}.m" printf filename if File.exist?(filename) exit 1 end file = File.new(filename, "w") file.puts(funcProto) file.puts("% #{funcProto}") if desc != nil and desc != "" file.puts("%\t#{desc}") end file.puts("%") file.puts("% #{owner}") file.close