The patch below will make Emacs version detection more robust.

Rationale: Some users symlink /usr/bin/emacs to a microemacs variant.
Depending on the variant, current version detection will exit with an
error, output an empty version, or hang with the editor waiting for
user interaction. The patch should fix this for most microemacs
flavours. (Not for all of them, unfortunately. Some will start up
interactively even if TERM is unset.)

Please review. I intend to commit the changes in a few days.

Ulrich


--- elisp-common.eclass 16 Mar 2013 08:55:30 -0000      1.84
+++ elisp-common.eclass 29 Jul 2013 11:44:46 -0000
@@ -173,16 +173,28 @@
 # Output version of currently active Emacs.
 
 elisp-emacs-version() {
-       local ret
+       local version ret
        # The following will work for at least versions 18-24.
        echo "(princ emacs-version)" >"${T}"/emacs-version.el
-       ${EMACS} ${EMACSFLAGS} -l "${T}"/emacs-version.el
+       version=$(
+               # EMACS could be a microemacs variant that ignores the -batch
+               # option and would therefore hang, waiting for user interaction.
+               # Redirecting stdin and unsetting TERM and DISPLAY will cause
+               # most of them to exit with an error.
+               unset TERM DISPLAY
+               ${EMACS} ${EMACSFLAGS} -l "${T}"/emacs-version.el </dev/null
+       )
        ret=$?
        rm -f "${T}"/emacs-version.el
        if [[ ${ret} -ne 0 ]]; then
                eerror "elisp-emacs-version: Failed to run ${EMACS}"
+               return ${ret}
+       fi
+       if [[ -z ${version} ]]; then
+               eerror "elisp-emacs-version: Could not determine Emacs version"
+               return 1
        fi
-       return ${ret}
+       echo "${version}"
 }
 
 # @FUNCTION: elisp-need-emacs

Reply via email to