all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Mark Skilbeck <m@iammark.us>
To: Ian van der Neut <ivdneut@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Problem setting frame title on startup
Date: Sat, 16 Mar 2013 10:24:34 +0000	[thread overview]
Message-ID: <20130316102434.GA3320@earth> (raw)
In-Reply-To: <CANyFcg1cF8PdYjC+WFcLMOGqJGKhwSyK3cUOmGgaRL46+bWT4Q@mail.gmail.com>

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:
> >
> >     (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



  reply	other threads:[~2013-03-16 10:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-15 19:24 Problem setting frame title on startup Ian van der Neut
2013-03-15 19:51 ` Mark Skilbeck
2013-03-16  9:47   ` Ian van der Neut
2013-03-16 10:24     ` Mark Skilbeck [this message]
2013-03-16 11:04       ` Ian van der Neut
2013-03-16 11:26         ` Ian van der Neut
2013-03-18  5:40           ` XeCycle

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=20130316102434.GA3320@earth \
    --to=m@iammark.us \
    --cc=help-gnu-emacs@gnu.org \
    --cc=ivdneut@gmail.com \
    /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.