Code covered by the BSD License  

Highlights from
proj

from proj by Daniel Ennis
Manage the multiple m-files of a project.

proj(projname,action,mfile)
% PROJ opens,closes, modifies, or displays a projects contents.
% A project is generally a collection of matlab functions and scripts
% that are frequently opened together and worked on collectively.
% This function facilitates opening and closing the many files that
% comprise a project and has some basic project building tools.  If you
% work on many projects at once this can be a convenient tool to
% re-establish the "working state" of a project and to put it away when you
% switch to work on something else.
%
% SYNTAX:  proj NAME open             -- Open the files in the project called NAME
%          proj NAME close            -- Close the files in the project called NAME
%          proj NAME                  -- Toggle open/close state of project (NOT IMPLEMENTED)
%          proj NAME add    MFILE     -- Add the file MFILE to the projects list
%          proj NAME rem    MFILE     -- Remove the file MFILE to the projects list
%          proj NAME remove MFILE     -- Remove the file MFILE to the projects list
%          proj NAME list             -- Display project filenames in console
%
% PROJ file format is a simple *.MAT file containing a field fname that is
% a cell array of each filename within the project. 
%
% Example:
%
%   proj proj_getdown add funky_function.m  % Establish a project and add a file
%   proj proj_getdown add jivey_function.m  % Add another file (files are added only if they are found in the directory or on your path)
%   proj proj_getdown list                  % List the files in a project
%   proj proj_getdown open                  % Open the files in the project
%   proj proj_getdown close                 % Close the files in the project
%   proj proj_getdown rem funky_function    % Remove the function (appends ".m" if necessary)
%
% DBE 2005/06/26

function proj(projname,action,mfile)

switch lower(action)
  case 'open'
    proj_open(projname);
  case 'close'
    proj_close(projname);
  case 'list'
    proj_list(projname);
  case 'add'
    proj_add(projname,mfile);
  case {'rem','remove'}
    proj_remove(projname,mfile);
  otherwise
    error('PROJ.M could not able to interpret 3rd input.');
end

function proj_open(projname);
proj_data=load_structure(projname);
for k=1:size(proj_data.fname,2)
  open(proj_data.fname{k});
end
return

function proj_close(projname);
proj_data=load_structure(projname);
for k=1:size(proj_data.fname,2)
  tmp=which(proj_data.fname{k});
  com.mathworks.mlservices.MLEditorServices.closeDocument(tmp);  % Wow what a hack!  Ugh!  Thanks to PB on TMW Newsgroup
end
return

function proj_list(projname);
if ~isempty(which(projname)) | ~isempty(which([projname,'.mat']))
  proj_data=load_structure(projname);
  for k=1:size(proj_data.fname,2)
    disp(proj_data.fname{k});
  end
else
  error(['Could not find the project file entitled: ',projname]);
end
return

function proj_add(projname,mfile);
if ~isempty(which(projname)) | ~isempty(which([projname,'.mat']))  % If project already exists...
  proj_data=load_structure(projname);
  tmp=which(mfile);
  if ~isempty(tmp)
    proj_data.fname{end+1}=tmp;
  else
    error(['Could not find ',mfile,' on the users path.  M-file NOT added to project.']);
%     proj_data.fname{end+1}=mfile;
  end
else % Project does not appear to exist...
  ANS=input('Project does not already exist.  Create it? [Y/n]','s');
  switch lower(ANS)
    case {'y',''}
      proj_data.fname{1}=which(mfile);
    case 'n'
      return;
    otherwise
      error('Input not understood.');
  end
end

save(projname,'proj_data');

return

function proj_remove(projname,mfile);
proj_data=load_structure(projname);
ind=1;
ind_remove=[];
while ind<=size(proj_data.fname,2)
  if strcmp(proj_data.fname{ind},mfile) | strcmp(proj_data.fname{ind},which(mfile)) | strcmp(proj_data.fname{ind},[mfile,'.m'])
    ind_remove=ind;
  end
  ind=ind+1;
end
if isempty(ind_remove), error(['Unable to find ',mfile,' in project.  Could not remove it.']); end
ind_keep=setdiff(1:size(proj_data.fname,2),ind_remove);
for k=1:length(ind_keep)
  tmp_fname{k}=proj_data.fname{k};
end
proj_data.fname=tmp_fname;
save(projname,'proj_data');
return

Contact us at files@mathworks.com