--- src/emacs.c.orig 2017-08-24 01:04:59.000000000 +0000 +++ src/emacs.c 2017-08-28 13:47:52.000000000 +0000 @@ -24,6 +24,8 @@ #include <errno.h> #include <fcntl.h> #include <stdio.h> +#include <stdlib.h> +#include <string.h> #include <sys/types.h> #include <sys/file.h> @@ -754,6 +756,25 @@ #ifdef DARWIN_OS if (!initialized) unexec_init_emacs_zone (); + + /* Imaxima won't work properly if PATH does not contain the + MacPorts directory. The following code is a workaround to + avoid this problem. */ + { + char *oldpath = getenv("PATH"); + if (!oldpath) {oldpath = "";} + size_t oldpathsize = strlen(oldpath) + 1; + if (!strstr(oldpath, "__PREFIX__/bin")) { + char *newpath; + size_t newpathsize = oldpathsize + strlen("__PREFIX__/bin:"); + if ((newpath = (char *)malloc(newpathsize)) != NULL) { + strlcpy(newpath, "__PREFIX__/bin:", newpathsize); + strlcat(newpath, oldpath, newpathsize); + setenv("PATH", newpath, 1); + free(newpath); + } + } + } #endif atexit (close_output_streams);