magit / with-editor

Use the Emacsclient as the $EDITOR of child processes
http://magit.vc/manual/with-editor
GNU General Public License v3.0
185 stars 44 forks source link

"cannot determine a suitable Emacsclient" with nix-pkgs emacs #62

Closed simonmichael closed 5 years ago

simonmichael commented 5 years ago

Thanks for with-editor and magit. Emacs installed with nix-env fails to find an emacsclient here. (I removed emacs-plus from homebrew but that didn't help.)

with-editor: /Users/simon/.emacs.d/elpa/with-editor-20181113.1845/with-editor.el
emacs: /nix/store/pyfdhlfcwpb6cvbbbjkp26hvp7rnkjkg-emacs-26.1/Applications/Emacs.app/Contents/MacOS/Emacs (26.1)
system:
  system-type: darwin
  system-configuration: x86_64-apple-darwin17.7.0
  system-configuration-options: --prefix=/nix/store/pyfdhlfcwpb6cvbbbjkp26hvp7rnkjkg-emacs-26.1 --with-modules --with-ns --disable-ns-self-contained CFLAGS=-DMAC_OS_X_VERSION_MAX_ALLOWED=101200
server:
  server-running-p: nil
  server-process: nil
  server-use-tcp: nil
  server-name: server
  server-socket-dir: /var/folders/r7/f9j9c2zd1k97v47cr84j_qvc0000gn/T//emacs501
    ERROR: not an accessible directory
  server-auth-dir: ~/.emacs.d/server/
    WARNING: not an accessible directory
with-editor-emacsclient-executable:
 value:   nil (nil)
 default: nil (nil)
 funcall: nil (nil)
path:
  $PATH: "/Users/simon/bin.local:/Users/simon/bin:/Users/simon/src/hledger/bin:/Users/simon/src/hledger/extra:/Users/simon/.local/bin:/Users/simon/.cabal/bin:/usr/local/bin:/usr/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/Applications/splunk/bin:/Users/simon/src/PLAINTEXTACCOUNTING/beancount/bin"
  exec-path: (/usr/bin /bin /usr/sbin /sbin /nix/store/pyfdhlfcwpb6cvbbbjkp26hvp7rnkjkg-emacs-26.1/libexec/emacs/26.1/x86_64-apple-darwin17.7.0 /Users/simon/bin.local /Users/simon/bin /Users/simon/src/hledger/bin /Users/simon/src/hledger/extra /Users/simon/.local/bin /Users/simon/.cabal/bin /usr/local/bin /usr/local/sbin /opt/local/bin /opt/local/sbin /usr/bin /usr/sbin /bin /sbin /Applications/splunk/bin /Users/simon/src/PLAINTEXTACCOUNTING/beancount/bin)
  with-editor-emacsclient-path:
    /nix/store/pyfdhlfcwpb6cvbbbjkp26hvp7rnkjkg-emacs-26.1/Applications/Emacs.app/Contents/MacOS (t)
    /nix/store/pyfdhlfcwpb6cvbbbjkp26hvp7rnkjkg-emacs-26.1/libexec/emacs/26.1/x86_64-apple-darwin17.7.0 (t)
    /Users/simon/bin.local (t)
    /Users/simon/bin (t)
    /Users/simon/src/hledger/bin (t)
    /Users/simon/src/hledger/extra (nil)
    /Users/simon/.local/bin (t)
    /Users/simon/.cabal/bin (t)
    /usr/local/bin (t)
    /usr/local/sbin (t)
    /opt/local/bin (nil)
    /opt/local/sbin (nil)
    /usr/bin (t)
      /usr/bin/emacsclient (22.1)
    /usr/sbin (t)
    /bin (t)
    /sbin (t)
    /Applications/splunk/bin (nil)
    /Users/simon/src/PLAINTEXTACCOUNTING/beancount/bin (nil)
tarsius commented 5 years ago

Usually the issue is that the proper emacsclient executable cannot be determined. It appears that the issue in this case is that the server cannot even be started.

The relevant part of the output should look something like this:

server:
  server-running-p: t
  server-process: #<process server>
  server-use-tcp: nil
  server-name: server
  server-socket-dir: /tmp/emacs1000
    server
  server-auth-dir: ~/.emacs.d/server/
    WARNING: not an accessible directory

Try starting the server manually and take note of the errors doing that throws at you. It probably has something to do with /var/folders/r7/f9j9c2zd1k97v47cr84j_qvc0000gn/T//emacs501 not being an accessible directory. That's probably a Nix thing--it probably should just use /tmp/emacs<PID> like everyone else.

simonmichael commented 5 years ago

Thanks for the hints @tarsius. I believe that long tmp folder path is a mac thing. It does seem accessible, my user can read/write there. I found that M-x server-start works without error, and then I could use /Users/simon/.nix-profile/bin/emacsclient without error. /usr/bin/emacsclient does not work of course. This one is first in path, at least for GUI-invoked apps, and I think that might be the issue. Unfortunately it's hard to remove in OSX Mojave.

tarsius commented 5 years ago

I found that M-x server-start works without error,

However this part

server:
  server-running-p: nil

indicates that with-editor failed to start the server.

You could probably add (server-start) to your init file to work around that. If that does work, then you might also want to investigate why doing that explicitly succeeds but fails when done by with-editor--setup.

tarsius commented 5 years ago

But maybe the failure to start the server is due to the failure to locate the appropriate emacsclient; I didn't have to deal with such issues in a while. Even if it is not, then the latter is simply another issue we have to deal with before you can start committing.

with-editor has to find the emacsclient executable based on the location of the emacs executable from which the current instance was started (and by comparing their version strings). While not trivial that is simple enough on reasonable operating systems, where the two executables are located in the same directory and we only have to compare the versions. On macOS this is a whole other story because here the two executables are not located in the same directory. To add insult to injury the relative path from the emacs to the emacsclient executable is different depending on who did the packaging and the phase of the moon.

Your emacs executable is at /nix/store/XXXX-emacs-26.1/Applications/Emacs.app/Contents/MacOS/Emacs. Search nearby directories for the emacsclient executable and report your findings. We probably have to add yet another kludge for this particular packaging of Emacs on macOS.

tarsius commented 5 years ago

It does seem accessible, my user can read/write there.

file-accessible-directory-p disagrees.