From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark Skilbeck Newsgroups: gmane.emacs.help Subject: Re: Problem setting frame title on startup Date: Sat, 16 Mar 2013 10:24:34 +0000 Message-ID: <20130316102434.GA3320@earth> References: <20130315195145.GA18986@earth> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1363429494 493 80.91.229.3 (16 Mar 2013 10:24:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 16 Mar 2013 10:24:54 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Ian van der Neut Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Mar 16 11:25:19 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 1UGoIb-00030z-Ie for geh-help-gnu-emacs@m.gmane.org; Sat, 16 Mar 2013 11:25:13 +0100 Original-Received: from localhost ([::1]:39912 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGoIE-00032s-On for geh-help-gnu-emacs@m.gmane.org; Sat, 16 Mar 2013 06:24:50 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:52026) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGoI2-000324-NG for help-gnu-emacs@gnu.org; Sat, 16 Mar 2013 06:24:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UGoI1-0007XB-GZ for help-gnu-emacs@gnu.org; Sat, 16 Mar 2013 06:24:38 -0400 Original-Received: from [2a01:7e00::f03c:91ff:fedf:c65b] (port=38403 helo=mail.iammark.us) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGoI1-0007Uq-8B for help-gnu-emacs@gnu.org; Sat, 16 Mar 2013 06:24:37 -0400 Original-Received: from mail.iammark.us (host86-177-244-9.range86-177.btcentralplus.com [86.177.244.9]) by mail.iammark.us (Postfix) with ESMTPSA id 62A81AEE7; Sat, 16 Mar 2013 10:24:35 +0000 (GMT) Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a01:7e00::f03c:91ff:fedf:c65b 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:89552 Archived-At: 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. > > In the documentation of after-make-frame-functions it is claimed that the > new frame is passed as an argument, but when I do: > (defun set-project-in-frame-title (frame) > (interactive) > (select-frame frame) > (setq projectname (getenv "project")) > (message "Project: %s" projectname) > (if projectname > (modify-frame-parameters frame (list (cons 'title (concat > (buffer-name) " [" projectname "]")))) > (modify-frame-parameters frame (list (cons 'title (buffer-name)))) > ) ;; if projectname > ) > > 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 Queer. The following works fine for me (I've removed the duplication of the modify-frame-parameters): (defun set-project-title-in-frame (frame) (interactive) (setq project-name (getenv "projectname")) (setq project-title (concat (buffer-name) (if project-name (concat " [" project-name "]")))) (modify-frame-parameters frame `((title . ,project-title)))) (add-hook 'after-make-frame-functions 'set-project-title-in-frame) Also note that you have "project" rather than "projectname" in your GETENV call; but that may just be a typo. > > Thank you very much for any help, > > Ian. > - mgs