diff --git a/ChangeLog b/ChangeLog index 5580ba55e9d836beb66fff6ed574d3f576a0a0d4..5edc922818cc1bf18af4d127c44d4e0c80a5693c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,8 @@ 2012-12-31 Chris Allegretta <chrisa@asty.org> * src/*: Introduce (basic) vim-style file locks. Does not allow vim to recover - our files, and doesn't yet support setting the file as modified; just lets a - vim user know we're editing a file. Commands line "-G" or "--locking", nanorc - option "locking". New functions src/files.c:do_lockfile(), write_lockfile(), - and delete_lockfile(). + our changes, and just lets a vim user know we're editing a file. Commands line "-G" + or "--locking", nanorc option "locking". New functions + src/files.c:do_lockfile(), write_lockfile(), and delete_lockfile(). 2012-02-05 Chris Allegretta <chrisa@asty.org> * src/*: Fix overlapping strings highlighting each other. new variables in edit_draw diff --git a/src/files.c b/src/files.c index f15a05f8b6fd5981ff85a3d1ef7910535a85c357..25609e1244388ea2ea11a7135efac617c2d63e02 100644 --- a/src/files.c +++ b/src/files.c @@ -182,8 +182,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi bytes 28-44 - username of who created the lock bytes 68-100 - hostname of where the lock was created bytes 108-876 - filename the lock is for - byte 1018 - 0x55 if file is modified - (TODO: set if 'modified' == TRUE) + byte 1007 - 0x55 if file is modified Looks like VIM also stores undo state in this file so we're gonna have to figure out how to slap a 'OMG don't use recover @@ -200,6 +199,8 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi strncpy(&lockdata[28], mypwuid->pw_name, 16); strncpy(&lockdata[68], myhostname, 31); strncpy(&lockdata[108], origfilename, 768); + if (modified == TRUE) + lockdata[1007] = 0x55; wroteamt = fwrite(lockdata, sizeof(char), lockdatalen, filestream); if (wroteamt < lockdatalen) { diff --git a/src/winio.c b/src/winio.c index 6869232491fbcc04c1e0f2891495f49b54348ba9..bd3c8033e0c6ed9e9549259aef1b1f58c373fd14 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2259,11 +2259,16 @@ void set_modified(void) openfile->modified = TRUE; titlebar(NULL); #ifndef NANO_TINY - if (ISSET(LOCKING) && openfile->lock_filename == NULL) - /* Translators: Try to keep this at most 80 characters. */ - statusbar(_("Warning: Modifying a file which is not locked, check directory permission?")); + if (ISSET(LOCKING)) { + if (openfile->lock_filename == NULL) { + /* Translators: Try to keep this at most 80 characters. */ + statusbar(_("Warning: Modifying a file which is not locked, check directory permission?")); + } else { + write_lockfile(openfile->lock_filename, + get_full_path(openfile->filename), TRUE); + } + } #endif - } }