From: pjb@informatimago.com (Pascal J. Bourguignon)
To: help-gnu-emacs@gnu.org
Subject: Re: How does emacsclient create it's first frame
Date: Tue, 12 Jan 2010 11:09:10 +0100 [thread overview]
Message-ID: <873a2bocs9.fsf@hubble.informatimago.com> (raw)
In-Reply-To: mailman.1256.1263289245.18930.help-gnu-emacs@gnu.org
Alex Bennee <kernel-hacker@bennee.com> writes:
> I've now got a working "edit server" in elisp which will respond to
> edit requests from Google Chrome. However it has a small problem when
> creating new frames.
>
> If there is a frame already visible then the (make-frame) invocation
> works as expected. However as I'm running this server inside an emacs
> --daemon invocation the default state if for no frame to be displayed.
>
> Indeed if you manually try a (make-frame) in this state then emacs
> will complain:
>
> 09:03 alex@trent/i686 [emacs_chrome.git] >emacsclient -e '(make-frame)'
> *ERROR*: Unknown terminal type
>
> I've been trying to find how the emacsclient causes the first frame to
> appear but I'm having trouble finding the client code in the emacs src
> tree. Can anyone offer any pointers as to how to do this from scratch?
I use make-frame-on-display.
Here is a little script I use:
----(mfod)-----------------------------------------------------------------
#!/bin/bash
#**************************************************************************
#FILE: mfod
#LANGUAGE: bash shell
#SYSTEM: unix
#USER-INTERFACE: NONE
#DESCRIPTION
#
# Shows all the emacs servers available, and let the user select one
# on which to open a new frame.
#
#AUTHORS
# <PJB> Pascal J. Bourguignon <pjb@informatimago.com>
#MODIFICATIONS
# 2009-09-12 <PJB> Created.
#BUGS
#LEGAL
# GPL
#
# Copyright Pascal J. Bourguignon 2009 - 2010
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version
# 2 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA 02111-1307 USA
#**************************************************************************
sockets=()
for socket in /tmp/emacs$UID/server /tmp/emacs$UID/server-* ; do
if [ -r $socket ] ; then
sockets[${#sockets[@]}]=$socket
fi
done
servers=()
frames=()
for socket in ${sockets[@]} ; do
frame=$(emacsclient --socket-name="${socket}" --eval '(mapcar (function frame-name) (frame-list))' 2>/dev/null || echo DEAD)
if [ "$frame" = "DEAD" ] ; then
# let's check there's no emacs process at that pid
server_pid="${socket/*server-}"
ps -p "$server_pid" | grep -s -q emacs || rm -f "${socket}"
else
servers[${#servers[@]}]="${socket}"
frames[${#frames[@]}]="${frame}"
fi
done
case ${#servers[@]} in
0)
printf "There is no emacs server.\n"
exit 0
;;
1)
server=${servers[0]}
;;
*)
choice=-1
while [ $choice -lt 0 -o ${#sockets[@]} -le $choice ] ; do
i=0
while [ $i -lt ${#servers[@]} ] ; do
printf "%2d) %-30s %s\n" "$i" "${servers[$i]}" "${frames[$i]}"
i=$(( $i + 1 ))
done
read -p 'What instance do you want a frame from? ' index
case x$index in
x[Nn][Oo][Nn][Ee]|x[Cc][Aa][Nn][Cc][Ee][Ll]|x[Qq][Uu][Ii][Tt]|x[Aa][Bb][Oo][Rr][Tt])
exit 0
;;
x*[^0-9]*)
# search the index response into the frames lists.
lindex=$( echo "$index" | tr '[:upper:]' '[:lower:]')
choice=0
found=no
while [ $choice -lt ${#frames[@]} -a $found = no ] ; do
eval f=$(echo "${frames[$choice]}" | tr '[:upper:]' '[:lower:]')
for frame in ${f[@]} ; do
if [ "$frame" = "$lindex" ] ; then
found=yes
break
fi
done
if [ $found = no ] ; then
choice=$(( $choice + 1 ))
fi
done
if [ $found = no ] ; then
printf "Please enter an integer between 0 and %d inclusive.\n" "$(( ${#servers[@]} - 1 ))"
choice=-1
fi
;;
x*)
choice=$index
if [ $choice -lt 0 -o ${#servers[@]} -le $choice ] ; then
printf "Please enter an integer between 0 and %d inclusive.\n" "$(( ${#servers[@]} - 1 ))"
fi
;;
esac
done
server=${servers[$choice]}
;;
esac
emacsclient --socket-name=${server} --no-wait --eval '(make-frame-on-display "'$DISPLAY'")'
#### THE END ####
------------------------------------------------------------------------
--
__Pascal Bourguignon__ http://www.informatimago.com/
next parent reply other threads:[~2010-01-12 10:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.1256.1263289245.18930.help-gnu-emacs@gnu.org>
2010-01-12 10:09 ` Pascal J. Bourguignon [this message]
2010-01-12 12:24 ` How does emacsclient create it's first frame Alex Bennee
2010-01-12 9:40 Alex Bennee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=873a2bocs9.fsf@hubble.informatimago.com \
--to=pjb@informatimago.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.