From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ian van der Neut Newsgroups: gmane.emacs.help Subject: Re: Problem setting frame title on startup Date: Sat, 16 Mar 2013 12:26:10 +0100 Message-ID: References: <20130315195145.GA18986@earth> <20130316102434.GA3320@earth> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=e0cb4efe3396c7f04c04d809052e X-Trace: ger.gmane.org 1363433187 30932 80.91.229.3 (16 Mar 2013 11:26:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 16 Mar 2013 11:26:27 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Mar 16 12:26:53 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UGpGG-0006qU-1A for geh-help-gnu-emacs@m.gmane.org; Sat, 16 Mar 2013 12:26:52 +0100 Original-Received: from localhost ([::1]:46173 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGpFt-0004XE-2W for geh-help-gnu-emacs@m.gmane.org; Sat, 16 Mar 2013 07:26:29 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:34511) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGpFe-0004X1-LX for help-gnu-emacs@gnu.org; Sat, 16 Mar 2013 07:26:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UGpFb-0001Aa-Jm for help-gnu-emacs@gnu.org; Sat, 16 Mar 2013 07:26:14 -0400 Original-Received: from mail-la0-x234.google.com ([2a00:1450:4010:c03::234]:57447) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGpFb-0001AR-5u for help-gnu-emacs@gnu.org; Sat, 16 Mar 2013 07:26:11 -0400 Original-Received: by mail-la0-f52.google.com with SMTP id fs12so4632421lab.11 for ; Sat, 16 Mar 2013 04:26:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=sSr1ZdVxS/epW7caH0ANHp/alHG+qntXn+wyxD8IozQ=; b=EBim1DzqHw/EokJHTfNU3+ywVl076LtdCnheHKfxubueYxM/Kbvlp0HtOZ7zW0y/6/ pTkYzSipPXzjSVCxFYNj+35m1dLJ1zbcu9hPmaJJItaVvt92HFeyBzgwxo+QumqRFWe2 /xH0hvmTSSWq2Pb8wLLG1Zhgm9PMKnpSWPSC/080mgCjDkr/+zc4WdbsnHIBBPamdP/B ND7dAbvYLQ/4Twe3dA/nJ0NO1i42lAufZn233u8FWltVmyHd4fmmaSzKA7VxJInEnVgh D5n9ZYCOM5pQtCEt8e7YdF5h+RU8oCpz37HwxH0kWIIP/vlkouyJtlj+Y3rw3jbR6dWI gy/Q== X-Received: by 10.112.42.37 with SMTP id k5mr3871762lbl.49.1363433170133; Sat, 16 Mar 2013 04:26:10 -0700 (PDT) Original-Received: by 10.112.42.226 with HTTP; Sat, 16 Mar 2013 04:26:10 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::234 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:89554 Archived-At: --e0cb4efe3396c7f04c04d809052e Content-Type: text/plain; charset=ISO-8859-1 Well, the following works exactly as I want it in emacsclient/daemon mode (which is what I use pretty much all the time): (defun set-project-in-frame-title (frame) (interactive) (select-frame frame) ;; Doen't seem to make a difference if you uncomment this or not. (setq project-name (getenv "project")) (message "Project: %s" project-name) (if project-name (setq frame-title-format (concat "%b (%*) [" project-name "] ")) (setq frame-title-format (concat "%b (%*)")))) (add-hook 'after-make-frame-functions 'set-project-in-frame-title) In normal mode (just starting 'emacs filename' from the command line, rather than emacsclient) it doesn't show the project name until I open a new frame, then both frames get the right frame title. Thank you for your help, Ian. PS. The reason I wanted this, is that I often work on multiple projects at the same time. (or multiple mercurial repositories of the same source code) and I like to see in the frame title which one I'm having in front of me. Each also has its own daemon: emacs --daemon=project Some shell scripting makes sure that the proper daemon is automatically started if it's not running already. On Sat, Mar 16, 2013 at 12:04 PM, Ian van der Neut wrote: > > > > On Sat, Mar 16, 2013 at 11:24 AM, Mark Skilbeck wrote: > >> On Sat, Mar 16, 2013 at 10:47:54AM +0100, Ian van der Neut wrote: >> > On Fri, Mar 15, 2013 at 8:51 PM, Mark Skilbeck wrote: >> > >> > > Use modify-frame-parameters: >> > > >> > > (modify-frame-parameters nil '((title . "test"))) >> > > >> > > >> > Hi, thank you for your reply. >> > >> > After some searching and reading docs I changed the code to >> > >> > (defun set-project-in-frame-title () >> > (interactive) >> > ;;(select-frame frame) >> > (setq projectname (getenv "project")) >> > (message "Project: %s" projectname) >> > (if projectname >> > (modify-frame-parameters nil (list (cons 'title (concat >> > (buffer-name) " [" projectname "]")))) >> > (modify-frame-parameters frame (list (cons 'title (buffer-name)))) >> > ) ;; if projectname >> > ) >> > >> > But it doesn't really make any difference. I figured out however, that I >> > probably need a hook to be executed when a frame is opened: >> > >> > (add-hook 'after-make-frame-functions 'set-project-in-frame-title) >> > >> > >> > But, this doesn't work exactly right either. I get the buffer-name of >> the >> > previous buffer. E.g. when I start emacs: >> > >> > export projectname="myproject" >> > emacs myfile >> > >> > The frame title has: >> > >> > *scratch* [myproject] >> >> Hum. I suppose this is because when a frame is created, the hook >> is run before the new buffer (i.e., myfile) is created, and therefore >> (current-buffer) points to the default buffer (in your case, *scratch*). >> I'm not sure how to remedy this as my Emacs hacking isn't much good. >> >> One thought would be to hook into the buffer change event, and update the >> title that way; but, of course, that will change the title whenever you >> change buffers, which may or may not be desirable. >> > > > That would be desirable, the buffer name in the title should reflect the > buffer in the frame. > > >> >> > >> > I get an error: >> > Wrong number of arguments: (lambda (frame) (interactive) (select-frame >> > frame) (setq projectname (getenv project)) (message Project: %s >> > projectname) (if projectname (modify-frame-parameters frame (list (cons >> > (quote title) (concat (buffer-name) [ projectname ])))) >> > (modify-frame-parameters frame (list (cons (quote title) >> > (buffer-name)))))), 0 >> >> > Argh... my bad. Somewhere in my ~/.emacs there was still a call to > set-project-in-frame-title without any argument. > > >> Also note that you have "project" rather than "projectname" in your >> GETENV call; but that may just be a typo. >> > > Yes, it was a typo in the email :) > > >> Thank you so far. Not quite there yet though... :) > > Ian. > -- One man's "magic" is another man's engineering. "Supernatural" is a null word. -- Excerpt from the notebooks of Lazarus Long, from Robert Heinlein's "Time Enough for Love" --e0cb4efe3396c7f04c04d809052e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Well, the following works exactly as I want= it in emacsclient/daemon mode (which is what I use pretty much all the tim= e):

(defun set-project-in-frame-title (frame)
=A0 (interactive) =A0 (select-frame frame) ;; Doen't seem to make a difference if you unc= omment this or not.
=A0 (setq project-name (getenv "project"))=
=A0 (message "Project: %s" project-name)
=A0 (if project-n= ame
=A0=A0=A0=A0=A0 (setq frame-title-format (concat "%b (%*) [" proj= ect-name "] "))
=A0=A0=A0 (setq frame-title-format (concat &qu= ot;%b (%*)"))))
(add-hook 'after-make-frame-functions 'set-= project-in-frame-title)

In normal mode (just starting 'emacs filename' from the c= ommand line, rather than emacsclient) it doesn't show the project name = until I open a new frame, then both frames get the right frame title.

Thank you for your help,

Ian.

PS. The reason = I wanted this, is that I often work on multiple projects at the same time. = (or multiple mercurial repositories of the same source code) and I like to = see in the frame title which one I'm having in front of me. Each also h= as its own daemon: emacs --daemon=3Dproject Some shell scripting makes sure= that the proper daemon is automatically started if it's not running al= ready.


On Sat, Mar 16, 2013 at 12:04 PM, Ian van der Neut <ivdneut@gmail.c= om> wrote:



On Sat, Mar 16, 2013 at 11:24 AM, Mark Skilbeck &= lt;m@iammark.us> wrote:
On Sat, Mar 16,= 2013 at 10:47:54AM +0100, Ian van der Neut wrote:
> On Fri, Mar 15, 2013 at 8:51 PM, Mark Skilbeck <m@iammark.us> wrote:
>
> > Use modify-frame-parameters:
> >
> > =A0 =A0 (modify-frame-parameters nil '((title . "test&qu= ot;)))
> >
> >
> Hi, thank you for your reply.
>
> After some searching and reading docs I changed the code to
>
> (defun set-project-in-frame-title ()
> =A0 (interactive)
> =A0 ;;(select-frame frame)
> =A0 (setq projectname (getenv "project"))
> =A0 (message "Project: %s" projectname)
> =A0 (if projectname
> =A0 =A0 =A0 (modify-frame-parameters nil (list (cons 'title (conca= t
> (buffer-name) " [" projectname "]"))))
> =A0 =A0 (modify-frame-parameters frame (list (cons 'title (buffer-= name))))
> =A0 =A0 ) ;; if projectname
> )
>
> But it doesn't really make any difference. I figured out however, = that I
> probably need a hook to be executed when a frame is opened:
>
> (add-hook 'after-make-frame-functions 'set-project-in-frame-ti= tle)
>
>
> But, this doesn't work exactly right either. I get the buffer-name= of the
> previous buffer. E.g. when I start emacs:
>
> export projectname=3D"myproject"
> emacs myfile
>
> The frame title has:
>
> *scratch* [myproject]

Hum. I suppose this is because when a frame is created, the hoo= k
is run before the new buffer (i.e., myfile) is created, and therefore
(current-buffer) points to the default buffer (in your case, *scratch*). I'm not sure how to remedy this as my Emacs hacking isn't much good= .

One thought would be to hook into the buffer change event, and update the title that way; but, of course, that will change the title whenever you
change buffers, which may or may not be desirable.

That would be desirable, the buffer name in the= title should reflect the buffer in the frame.
=A0

>
> I get an error:
> Wrong number of arguments: (lambda (frame) (interactive) (select-frame=
> frame) (setq projectname (getenv project)) (message Project: %s
> projectname) (if projectname (modify-frame-parameters frame (list (con= s
> (quote title) (concat (buffer-name) =A0[ projectname ]))))
> (modify-frame-parameters frame (list (cons (quote title)
> (buffer-name)))))), 0


Argh... my bad. Somewhere in my ~/.em= acs there was still a call to set-project-in-frame-title without any argume= nt.


Also note that you have "project" rather than "projectname&q= uot; in your
GETENV call; but that may just be a typo.

Yes, it was a typo in the email :)
=A0
Thank you so far. Not quite there yet though.= .. :)

<= span class=3D"">
Ian.
=



--
One man's &quo= t;magic" is another man's engineering. "Supernatural" is= a null word.
-- Excerpt from the notebooks of Lazarus Long, from= Robert Heinlein's "Time Enough for Love"
--e0cb4efe3396c7f04c04d809052e--