mitranim / gow

Missing watch mode for Go commands. Watch Go files and execute a command like "go run" or "go test"
The Unlicense
747 stars 29 forks source link

Ignoring Emacs' lock files: `.#file.go` #40

Open tommie opened 11 months ago

tommie commented 11 months ago

Emacs writes a temporary file as soon as you start editing a file. When you hit save, it removes the temporary file.

This triggers gow, since the extension is still .go. It's a bit ugly, though perhaps not the end of the world.

To avoid flag chaos, I think reading patterns from a file is probably nicest, but I could imagine using .gitignore-style patterns fits more with gows current style.

Would you be open to an ignore prefix flag, an ignore pattern [1] flag, or perhaps reading a .gowignore file?

And thanks for writing gow! It replaces an inotifywatch | while read; go make ; done loop I've used previously. Much neater.

  1. E.g. using https://pkg.go.dev/github.com/sabhiram/go-gitignore
mitranim commented 11 months ago

Thanks for notifying me about the issue. I only use Sublime Text these days and didn't know about the Emacs behavior. I wonder how many people couldn't use gow because of this and didn't report it.

Sounds vaguely related to #32, in the sense that both issues can be generalized to supporting patterns (such as glob patterns) for watch and ignore paths. I even have a tentative local implementation using filepath.Match. We could also introduce easily togglabble support for ignoring editor temporary files, which could in the future be extended for non-Emacs.

I'm unfamiliar with Emacs and can easily miss things. Would you care to explain where it creates temporary files and what are the rules for file names?

tommie commented 11 months ago

I was somewhat wrong. It's a broken symlink, used as a lock: https://www.gnu.org/software/emacs/manual/html_node/elisp/File-Locks.html

The name is constructed by prepending .# to the file name of the buffer.

So a file name a/b.go will have a lock file name a/.#b.go.

Emacs' auto-save files for file a/b.go are by default named a/#b.go#, so it's not a problem: https://www.gnu.org/software/emacs/manual/html_node/emacs/Auto-Save-Files.html

mitranim commented 11 months ago

I'm considering mirroring watchexec by adding support for gitignore patterns:

tommie commented 11 months ago

Using .gitignore is probably not great: I generate Protobuf files, and the files I want in my build are separate from what I want in Git. In other situations, I use a symlink if I want to use .gitignore for other purposes. I suggest using a dedicated name. Perhaps using an env var to override the per-directory name?

For the convenience flag, couldn't this just be a ~/.config/gow/ignore file? Git reads these files:

I'm in big favor of using the gitignore syntax in a file, rather than a command line flag, though. (I realize I could write a shell script, but meh. :)

mitranim commented 11 months ago

It sounds like you want generated Go files to trigger gow, and it makes sense to me. Some people want a slightly different workflow where running go generate is part of a gow rerun, and generated files should be ignored to avoid infinite restarting; see #37. I think wanting to use .gitignore to exclude any generated files is fairly common, so there's value in having a flag just for that.

We could support a flag for custom paths to gitignore files. We could also generalize and support gow config files. There's value in both. Dedicated ignore files can use the appropriate syntax, with comments and syntax highlighting. Support for gow config files has been a consideration for a while, but didn't seem like a priority because all my projects use makefiles, which fulfills the same function but better. If someone really wants gow config files, I lean towards JSON with comments and trailing commas, and merging all such files from the current directory up, like ./.gow.json, then ../.gow.json, and so on. Should automatically include ~/.gow.json if your project is somewhere under ~.

tommie commented 11 months ago

That's one way of doing configuration files.

The other is to split it up and use already-established file formats for specific tasks, like ignore-patterns. This is what Git does, and since it sounded like you wanted to be Git-compatible, I suggested ignore files in the XDG config directory as the "global" setting. If you're reading ./.gitignore, it would be terribly confusing if you didn't also read the other ignore files Git uses. At that point, then reading an additional, gow-specific, file of the same format would be trivial.

gitslim commented 2 days ago

If you are not using simultaneous editing, you can disable file locking feature:

(setq create-lockfiles nil)