From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: How does emacsclient create it's first frame Date: Tue, 12 Jan 2010 11:09:10 +0100 Organization: Informatimago Message-ID: <873a2bocs9.fsf@hubble.informatimago.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1263294028 9413 80.91.229.12 (12 Jan 2010 11:00:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 12 Jan 2010 11:00:28 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jan 12 12:00:19 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NUeTv-0003h8-ID for geh-help-gnu-emacs@m.gmane.org; Tue, 12 Jan 2010 12:00:15 +0100 Original-Received: from localhost ([127.0.0.1]:43667 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NUeTw-0007zg-7N for geh-help-gnu-emacs@m.gmane.org; Tue, 12 Jan 2010 06:00:16 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 143 Original-X-Trace: individual.net Oa3ChxtdXFwyf01sXLZUNg3f0uTo8Hu7bGxOwzbODlkN6qJl0k Cancel-Lock: sha1:NjYwZTFlMjYzNmIzYzRhOWUzNmZiNzc5Y2Y5ZDQ3MzM5YzhjYTFhOA== sha1:Ux87YqpXExBHnJt84i1888fOiLo= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.101 (Gnus v5.10.10) Emacs/22.3 (gnu/linux) Original-Xref: news.stanford.edu gnu.emacs.help:176119 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:71190 Archived-At: Alex Bennee 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 # Pascal J. Bourguignon #MODIFICATIONS # 2009-09-12 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/