1. edx :: adding Backup, Restore, and purge to the top-line menu
- Posted by K_D_R Apr 08, 2013
- 1488 views
- Last edited Apr 10, 2013
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
2. Re: edx :: adding Backup, Restore, and purge to the top-line menu
- Posted by K_D_R Apr 10, 2013
- 1412 views
-- modified "mods" routine: If the current file is a -- backup file with one or more "~" appended to the file_name, -- this routine will compare the current file with the base -- file which is the file which would be overwritten, with -- the restore command, "ESCAPE & "R". For example, if the -- current file is "edx.ex~~", this routine will execute: -- shell(compare_cmd edx.ex edx.ex~~ | more) -- If the current file does not have a "~" in the extension, -- it will perform as before. elsif command[1] = 'm' then save_file(TEMPFILE) if stop then stop = FALSE if match("~", file_name) then -- show differences between original source file and the current file, if -- current file is a backup file with one or more "~" appended to the extension command = compare_cmd & file_name[1..match("~", file_name)-1] else -- show differences between the current file buffer and file on disk command = compare_cmd & file_name end if shell(command & " " & TEMPFILE & " | more") normal_video() goto_line(0, b_col) editbuff = TRUE end if
3. Re: edx :: adding Backup, Restore, and purge to the top-line menu
- Posted by K_D_R Apr 10, 2013
- 1388 views
IMPORTANT: The restore routine in the original post did not report the name of the "restore to"
file correctly. I have corrected the editor in the original post. The backup file would have been restored to the proper file, but the name of the file reported on top line would have an extra character, probably a "~". This is the corrected routine:
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 in the original post. 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 in the original post. end if