[PATCH] notmuch-emacs-mua: do not create a frame by default with --client

Tomi Ollila tomi.ollila at iki.fi
Sun May 10 11:45:20 PDT 2015


On Sat, May 09 2015, Jani Nikula <jani at nikula.org> wrote:

> Make the default behaviour for --client the same as emacsclient
> default: do not create a new frame. Add a new option --create-frame,
> passing the same option to emacsclient to create a frame.

I apologize for not testing the previous version beyond the initial failure
of running notmuch-emacs-mua w/o the --client...

... as now further testing shows IMO a expectation problem when plain
--client argument is given -- it behaves similar to

emacsclient -a '' --no-wait /dev/null

(currently I don't have access to X environment so I cannot check this
fully, anyway try this without emacs server running to see yourselves)

IMO the interface would be cleaner if these would pairs be somewhat analogous:


notmuch-emacs-mua --client
emacsclient -a '' /dev/null

and

notmuch-emacs-mua --client --no-wait
emacsclient -a '' --no-wait /dev/null


this also makes documentation so much easier


Tomi



>
> ---
>
> v2: fix killing frame with --create-frame
>
> v3: fix --create-frame w/o --client parameter check
> ---
>  doc/man1/notmuch-emacs-mua.rst | 14 +++++++++-----
>  notmuch-emacs-mua              | 30 +++++++++++++++++++++---------
>  2 files changed, 30 insertions(+), 14 deletions(-)
>
> diff --git a/doc/man1/notmuch-emacs-mua.rst b/doc/man1/notmuch-emacs-mua.rst
> index 36b51cdc3b18..e39d9e5fba1f 100644
> --- a/doc/man1/notmuch-emacs-mua.rst
> +++ b/doc/man1/notmuch-emacs-mua.rst
> @@ -18,10 +18,6 @@ Supported options for **notmuch-emacs-mua** include
>      ``-h, --help``
>          Display help.
>
> -    ``--client``
> -        Use emacsclient, rather than emacs. This will start
> -        an emacs daemon process if necessary.
> -
>      ``-s, --subject=``\ <subject>
>          Specify the subject of the message.
>
> @@ -38,7 +34,15 @@ Supported options for **notmuch-emacs-mua** include
>          Specify a file to include into the body of the message.
>
>      ``--no-window-system``
> -        Even if a window system is available, use the current terminal
> +        Even if a window system is available, use the current terminal.
> +
> +    ``--client``
> +        Use **emacsclient**, rather than **emacs**. This will start
> +        an emacs daemon process if necessary.
> +
> +    ``--create-frame``
> +         When --client is specified, create a new frame instead of trying
> +         to use the current Emacs frame.
>
>      ``--print``
>          Output the resulting elisp to stdout instead of evaluating it.
> diff --git a/notmuch-emacs-mua b/notmuch-emacs-mua
> index 79714305b3e2..102410a23f3e 100755
> --- a/notmuch-emacs-mua
> +++ b/notmuch-emacs-mua
> @@ -34,12 +34,12 @@ EMACS=${EMACS-emacs}
>  EMACSCLIENT=${EMACSCLIENT-emacsclient}
>
>  PRINT_ONLY=
> +NO_WINDOW=
>  USE_EMACSCLIENT=
> -CLIENT_TYPE="-c"
> +CREATE_FRAME=
>
>  # The crux of it all: construct an elisp progn and eval it.
>  ELISP="(prog1 'done (require 'notmuch) (notmuch-mua-new-mail)"
> -ELISP="${ELISP} (setq message-exit-actions (list #'save-buffers-kill-terminal))"
>
>  # Short options compatible with mutt(1).
>  while getopts :s:c:b:i:h opt; do
> @@ -63,7 +63,7 @@ while getopts :s:c:b:i:h opt; do
>                   opt=${opt%%=*}
>                   ;;
>               # Long options without arguments.
> -             --help|--print|--no-window-system|--client)
> +             --help|--print|--no-window-system|--client|--create-frame)
>                   ;;
>               *)
>                   echo "$0: unknown long option ${opt}, or argument mismatch." >&2
> @@ -81,9 +81,6 @@ while getopts :s:c:b:i:h opt; do
>       --help|h)
>           exec man notmuch-emacs-mua
>           ;;
> -     --client)
> -         USE_EMACSCLIENT="yes"
> -         ;;
>       --subject|s)
>           ELISP="${ELISP} (message-goto-subject) (insert \"${OPTARG}\")"
>           ;;
> @@ -103,7 +100,13 @@ while getopts :s:c:b:i:h opt; do
>           PRINT_ONLY=1
>           ;;
>       --no-window-system)
> -         CLIENT_TYPE="-t"
> +         NO_WINDOW="-nw"
> +         ;;
> +     --client)
> +         USE_EMACSCLIENT="yes"
> +         ;;
> +     --create-frame)
> +         CREATE_FRAME="--create-frame"
>           ;;
>       *)
>           # We should never end up here.
> @@ -122,6 +125,15 @@ for arg; do
>      ELISP="${ELISP} (message-goto-to) (insert \"${arg}, \")"
>  done
>
> +# If reusing a frame in emacsclient, don't kill the buffer.
> +if [ -n "$CREATE_FRAME" ]; then
> +    if [ -z "$USE_EMACSCLIENT" ]; then
> +     echo "$0: --create-frame is only applicable with --client." >&2
> +     exit 1
> +    fi
> +    ELISP="${ELISP} (setq message-exit-actions (list #'save-buffers-kill-terminal))"
> +fi
> +
>  # End progn.
>  ELISP="${ELISP})"
>
> @@ -132,7 +144,7 @@ fi
>
>  if [ -n "$USE_EMACSCLIENT" ]; then
>      # Evaluate the progn.
> -    exec ${EMACSCLIENT} ${CLIENT_TYPE} -a '' --eval "${ELISP}"
> +    exec ${EMACSCLIENT} ${CREATE_FRAME} ${NO_WINDOW} -a '' --eval "${ELISP}"
>  else
> -    exec ${EMACS} --eval "${ELISP}"
> +    exec ${EMACS} ${NO_WINDOW} --eval "${ELISP}"
>  fi
> --
> 2.1.4


More information about the notmuch mailing list