2

Is there an approved way for to query whether a document is open an editor in Linux?

For example, if a document is being edited we may want to warn that a document is open and should be saved before a git merge or pull. We might also want to avoid automated housekeeping (removing trailing whitespace etc.) on files being actively edited.

There are three obvious but flawed methods.

  1. Test whether the file is open using lsof. However most editors do not leave the file open while editing the document.
  2. Check whether an editor window is open with wmctrl -l. This is limited to X editors, and even then only if the document is the active tab.
  3. See if there is a temporary file. For example, if the file .foo.swp exists we might presume the file foo is open in vim, particularly if .foo.swp is newer than foo. However, there isn't a uniform naming scheme across editors, and some editors like LyX may not create the temporary file instantly.

So is there a recommended way of telling whether a document is open in an editor that works on all editors (or at least editors compliant with some Gnome/KDE/other standard)?

2
  • 1
    A number of editor monitor for changes and warn you if the the file has been changed while you are editing it. Others will reload and merge changes into the edit buffer. What issue are you trying to avoid?
    – BillThor
    Commented Apr 4, 2016 at 4:31
  • None of the editors I use do a three way merge, and anyway I'd like to avoid three way merges. I guess sending a "Save All" message to all editors prior to housekeeping tasks would be good enough for me, but LyX doesn't warn that the file is changed until I try to save, and then I have to do a manual 3-way merge. Is when to warn about editing a changed file part of some standard or HIG?
    – gmatht
    Commented Apr 4, 2016 at 6:10

1 Answer 1

0

Each user should have their own work area and control their git activity. Why would you inflict automated format changes on user's content while they are working on it? The conditions you are controlling for should be relatively rare occurrences. If they aren't, then there may be issues with the workflow.

Automated cleanup actions such as formatting changes should be applied to unmodified code. When using version control, they should be a separate commit. Such changes should be relatively easy to merge.

I am not aware of any standards as to when or if to warn about changed files. However, many editors now at least warn before overwriting changed files. Additionally, there may be version control integration either as built-in functionality or via a plugin.

It appears LyX 2.1 has basic GIT functionality built-in. This may help with your issues with open files.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .