magit/magit — pull request #1397 by tarsius (2014-06-08 06:06:23+00:00)
Title: try harder to locate a suitable emacsclient executable

This, together with the improved "teach git how to call home" implementation in `with-editor` will hopefully put an end users not being able to commit. Unless of course I made some mistake. Which is were you guys come into play... could you please review this patch. Also maybe someone knows the answers to the embedded questions.

By the way, there is no hurry. I am gone for a week. I mean look outside (well I suppose that depends on where you live - here it's nice :-)

---

Improve how the default value of `magit-emacsclient-executable` is
determined.

Until now we searched for an executable with a version suffix that
matches the `emacs-version` of the current Emacs instance. If that
failed, we gave up on the subminor part and tried again, until we
finally looked for an executable with no version suffix at all. This
last case is not uncommon at all. And also problematic because we end
up using whatever comes first on `exec-path`.

To partially fix that prepend `invocation-directory` to the used path.
Also continue to work around the various crazy ways Emacs is packaged
on OS X, in each case adding yet another directory to the path.

And last but not least, run `/path/to/emacsclient --version` for each
executable and compare that, and compare that with the version of the
current Emacs instance. This avoids *not* using the best available
client, just because it doesn't have a version suffix.

If that fails repeat the search, this time looking just for MAJOR.MINOR,
and if that fails, try just MAJOR. If that fails too, then we give up
and show a warning.

(Most likely no suitable client exists because the Emacs build system by
default only appends a version suffix to the emacs executable but not to
that of the emacsclient executable. To avoid overriding on versions
emacsclient when building another version, users have to use either
`./configure --prefix` or `./configure --program-suffix`.)

The search is performed by `locate-file-internal' (up to three times).
The version test is performed by its PREDICATE. But because it expects
an actual name as FILENAME - not a regular expression - we have to use
SUFFIXES for the various expected version suffixes, e.g for the current
Emacs release the members of SUFFIXES are "24.3.2", "-24.3.2", "24.3",
"-24.3", "24", "-24", and "". And on Windows also "23.3.2.exe" etc.