edx :: adding Backup, Restore, and purge to the top-line menu

new topic     » topic index » view thread      » older message » newer message

IMPORTANT EDIT: The Restore Routine did not report the name of the original file correctly. The files would have been restored to the proper file name, but the message on ed.ex's top line would have reported the file name incorrectly. That has been fixed by:

elsif command[1] = 'R' then 
   if restore(file_name) then 
       set_top_line( sprintf("%s successfully restored to %s - reload file", {file_name, file_name[1..match("-", file_name)]-1}) )  --<----- the -1 had been omitted. 
  else 
      set_top_line( sprintf("Could not restore %s to %s - reload file", {file_name, file_name[1..match("-", file_name)]-1}) )  --<----- the -1 had been omitted. 
  end if 

This is an example of why I like ed.ex so much. It is jaw-dropingly easy to modify and "extend". So, now that I have serviceable backup, restore, and purge_backup routines:
http://openeuphoria.org/forum/121303.wc?last_id=0 ...

 
 
-- first, change the declaration: 
constant E_FILES  
-- to: 
sequence E_FILES 
 
-- next: 
-- add include backup.e before the routine: 
include backup.e 
get_escape(boolean help) 
 
-- insert the backup related menu items into the list of "first_bold("menu-items"): 
 
    first_bold("replace ") 
    if match("~", file_name) then 
	     
	    -- if you load a file with a "~" suffix 
	    -- reload the file - hit ESCAPE & 'n' & CR 
	    -- then the backup file will be displayed 
	    -- with syncolor. 
	    E_FILES &= file_name 
	    remove_dups(E_FILES, RD_SORT) 
	     
	    first_bold("Restore ") 
	    first_bold("purge ") 
	     
    else 
	     
	    first_bold("Backup ") 
	     
    end if 
 
first_bold("lines ") 
 
-- a few lines down prepend "BRp" to the sequence of hot-keys in: 
command = key_gets("BRphcqswned..."... 
IMPORTANT EDIT: Restore routine 
-- insert the calling routines into the list of elsif clauses: 
    elsif command[1] = 'B' then 
	if backup(file_name, 0) then    -- 0 = safe backup, 1 = overwrite 
	    set_top_line( sprintf("%s successfully backed up!", {file_name}) ) 
	else 
	    set_top_line( sprintf("Could Not backup %s!", {file_name}) ) 
	end if 
	 
    elsif command[1] = 'R' then 
	if restore(file_name) then 
	    set_top_line( sprintf("%s successfully restored to %s - reload file", {file_name, file_name[1..match("-", file_name)]-1}) ) 
	else 
	    set_top_line( sprintf("Could not restore %s to %s - reload file", {file_name, file_name[1..match("-", file_name)]-1}) ) 
	end if 
	 
    elsif command[1] = 'p' then 
	if purge_backup_file(file_name) then 
	    file_history = remove_item(file_name, file_history) 
	    set_top_line( sprintf("%s on disk has been deleted!", {file_name}) ) 
	else 
	    set_top_line( sprintf("%s on disk could not be be deleted!", {file_name}) ) 
	end if 
 
-- you know what... I just posted an include file version of Jiri Babor's "tidy.ex"  
-- to the RDS user contribution page, so lets add a source code "beautifier feature 
-- to ed.ex. Don't forget to prepend 't' to the list of hot-keys above. 
 
elsif command[1] = 't' then 
	tmsg = tidy(file_name) 
	set_top_line("") 
	set_top_line(tmsg) 
 
-- 
--  now ed.ex has backup/restore capabilities and a source code "beautifier" to boot! 
-- 
 

Comments and suggestions for improvements will always be appreciated.

Ken Rhodes

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu