* How does emacsclient create it's first frame
@ 2010-01-12 9:40 Alex Bennee
0 siblings, 0 replies; 3+ messages in thread
From: Alex Bennee @ 2010-01-12 9:40 UTC (permalink / raw)
To: help-gnu-emacs mailing list
Hi,
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?
--
Alex, homepage: http://www.bennee.com/~alex/
http://www.half-llama.co.uk
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How does emacsclient create it's first frame
[not found] <mailman.1256.1263289245.18930.help-gnu-emacs@gnu.org>
@ 2010-01-12 10:09 ` Pascal J. Bourguignon
2010-01-12 12:24 ` Alex Bennee
0 siblings, 1 reply; 3+ messages in thread
From: Pascal J. Bourguignon @ 2010-01-12 10:09 UTC (permalink / raw)
To: help-gnu-emacs
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/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How does emacsclient create it's first frame
2010-01-12 10:09 ` How does emacsclient create it's first frame Pascal J. Bourguignon
@ 2010-01-12 12:24 ` Alex Bennee
0 siblings, 0 replies; 3+ messages in thread
From: Alex Bennee @ 2010-01-12 12:24 UTC (permalink / raw)
To: Pascal J. Bourguignon; +Cc: help-gnu-emacs
2010/1/12 Pascal J. Bourguignon <pjb@informatimago.com>:
> 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.
>
> I use make-frame-on-display.
>
Hmm, I tried that and it works sometimes. Other times the frame
appears but never displays text or focus
until I spin up another frame via emacsclient.
Does emacsclient do anything else in bringing frames to the fore?
--
Alex, homepage: http://www.bennee.com/~alex/
http://www.half-llama.co.uk
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-01-12 12:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.1256.1263289245.18930.help-gnu-emacs@gnu.org>
2010-01-12 10:09 ` How does emacsclient create it's first frame Pascal J. Bourguignon
2010-01-12 12:24 ` Alex Bennee
2010-01-12 9:40 Alex Bennee
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.