gow
gow copied to clipboard
Ignoring Emacs' lock files: `.#file.go`
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 gow
s 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.
- E.g. using https://pkg.go.dev/github.com/sabhiram/go-gitignore
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?
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
I'm considering mirroring watchexec
by adding support for gitignore patterns:
- Explicit
-i
would use gitignore matching, rather than exact matching or directory matching. - Add a boolean flag for using
<cwd>/.gitignore
. This is enabled by default inwatchexec
, but for me, that was an annoying gotcha. Make it opt-in ingow
. - Add a multi-string flag for additional paths to gitignore files.
- Consider adding a "convenience" flag for ignoring common temporary/junk directories/files, equivalent to manually adding the corresponding ignore flags. Off the top of my head:
.git
,.DS_Store
,.#*
for Emacs lock files. The list will grow with time.
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:
-
$XDG_CONFIG_HOME/git/ignore
-
$GIT_DIR/info/exclude
-
.gitignore
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. :)
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 ~
.
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.