Re: ed.ex :: auto-loading directory files into ed.ex's file_history
- Posted by K_D_R Jan 23, 2012
- 1267 views
Well, making each new directory visited the current directory, proved to be "problematic". My current solution is to make the newly visited directory the current directory, only to load its files into the file_history with the path prepended so that all files not located in the startup directory, have absolute paths. Once the new directory files, with absolute paths, have been loaded into the file_history, the startup directory is immediately made the current directory again.
-- this routine is called only once procedure load_startup_directory_files() object tmp = {} integer r = 0 tmp = dir("*.*") if not atom(tmp)then if length(tmp)>1 then for x = 1 to length(tmp) do file_history = update_history(file_history, tmp[x][D_NAME]) end for end if else file_history &= tmp end if end procedure load_startup_directory_files() -- this routine is called when a file is created or -- opened in a new directory -- the path is received from the "new file" routine: procedure load_files_from_new_directory(sequence path) object tmp = {} integer r = 0 tmp = dir("*.*") if not atom(tmp)then if length(tmp)>1 then for x = 1 to length(tmp) do -- the path & SLASH are prepended to the file name file_history = update_history(file_history, sprintf("%s", {path & SLASH & tmp[x][D_NAME]})) end for -- command history update with templates, no need to type in long paths: command_history = update_history(command_history, sprintf("ls %s", {path & SLASH})) command_history = update_history(command_history, sprintf("ls *.ex *.e %s", {path & SLASH})) end if end if -- at the end of code which processes the "new file" ESCAPE + 'n' command insert -- the following code: elsif command[1] = 'n' then -- insert these lines: if absolute_path(answer) then path = (dirname(answer)) if chdir(dirname(answer)) then load_files_from_new_directory(path) chdir(init_curdir()) elsif match(".html", answer) then system_exec(BROWSER & " " & answer, 0) end if end if file_name = answer stop = TRUE end if -- between this line: if length(answer) != 0 then -- and these lines: file_name = answer stop = TRUE end if -- in the procedure: procedure ed(sequence command) -- insert this line: load_startup_directory_files() -- before this line: if length(command) >= 3 then