all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Problem setting frame title on startup
@ 2013-03-15 19:24 Ian van der Neut
  2013-03-15 19:51 ` Mark Skilbeck
  0 siblings, 1 reply; 7+ messages in thread
From: Ian van der Neut @ 2013-03-15 19:24 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1266 bytes --]

Hello all,

rather a lisp newbie and been searching all over, but can't figure it out.
I have the code below:

(provide 'ian-project)
;; Based on the presence of the 'project' environment variable,
;; display the project name in the frame title and the mode line.
(defun set-project-in-frame-title ()
  (interactive)
  (setq projectname (getenv "project"))
  (message "Project: %s" projectname)
  (if projectname
      (setq-default frame-title-format (concat "%b (%*) [" projectname "]
"))
    (setq frame-title-format (concat "%b (%*)"))
    ) ;; if projectname
)

And in my ~/.emacs I have:

(require 'ian-project)
(set-project-in-frame-title)

The message "Project: <projectname>" is displayed in the *Messages* buffer
on startup, however, the project name does not end up in the frame title,
unless I execute the function by hand:
M-x set-project-in-frame-title()

My emacs version is:
GNU Emacs 24.2.1 (x86_64-redhat-linux-gnu, GTK+ Version 3.6.4)
 of 2013-02-02 on buildvm-04.phx2.fedoraproject.org

Thank you very much in advance for any pointers as to what I may be missing.

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"

[-- Attachment #2: Type: text/html, Size: 1716 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Problem setting frame title on startup
  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
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Skilbeck @ 2013-03-15 19:51 UTC (permalink / raw)
  To: Ian van der Neut; +Cc: help-gnu-emacs

Use modify-frame-parameters:

    (modify-frame-parameters nil '((title . "test")))

On Fri, Mar 15, 2013 at 08:24:20PM +0100, Ian van der Neut wrote:
> Hello all,
> 
> rather a lisp newbie and been searching all over, but can't figure it out.
> I have the code below:
> 
> (provide 'ian-project)
> ;; Based on the presence of the 'project' environment variable,
> ;; display the project name in the frame title and the mode line.
> (defun set-project-in-frame-title ()
>   (interactive)
>   (setq projectname (getenv "project"))
>   (message "Project: %s" projectname)
>   (if projectname
>       (setq-default frame-title-format (concat "%b (%*) [" projectname "]
> "))
>     (setq frame-title-format (concat "%b (%*)"))
>     ) ;; if projectname
> )
> 
> And in my ~/.emacs I have:
> 
> (require 'ian-project)
> (set-project-in-frame-title)
> 
> The message "Project: <projectname>" is displayed in the *Messages* buffer
> on startup, however, the project name does not end up in the frame title,
> unless I execute the function by hand:
> M-x set-project-in-frame-title()
> 
> My emacs version is:
> GNU Emacs 24.2.1 (x86_64-redhat-linux-gnu, GTK+ Version 3.6.4)
>  of 2013-02-02 on buildvm-04.phx2.fedoraproject.org
> 
> Thank you very much in advance for any pointers as to what I may be missing.
> 
> 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"



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Problem setting frame title on startup
  2013-03-15 19:51 ` Mark Skilbeck
@ 2013-03-16  9:47   ` Ian van der Neut
  2013-03-16 10:24     ` Mark Skilbeck
  0 siblings, 1 reply; 7+ messages in thread
From: Ian van der Neut @ 2013-03-16  9:47 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 3623 bytes --]

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]

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

Thank you very much for any help,

Ian.




> On Fri, Mar 15, 2013 at 08:24:20PM +0100, Ian van der Neut wrote:
> > Hello all,
> >
> > rather a lisp newbie and been searching all over, but can't figure it
> out.
> > I have the code below:
> >
> > (provide 'ian-project)
> > ;; Based on the presence of the 'project' environment variable,
> > ;; display the project name in the frame title and the mode line.
> > (defun set-project-in-frame-title ()
> >   (interactive)
> >   (setq projectname (getenv "project"))
> >   (message "Project: %s" projectname)
> >   (if projectname
> >       (setq-default frame-title-format (concat "%b (%*) [" projectname "]
> > "))
> >     (setq frame-title-format (concat "%b (%*)"))
> >     ) ;; if projectname
> > )
> >
> > And in my ~/.emacs I have:
> >
> > (require 'ian-project)
> > (set-project-in-frame-title)
> >
> > The message "Project: <projectname>" is displayed in the *Messages*
> buffer
> > on startup, however, the project name does not end up in the frame title,
> > unless I execute the function by hand:
> > M-x set-project-in-frame-title()
> >
> > My emacs version is:
> > GNU Emacs 24.2.1 (x86_64-redhat-linux-gnu, GTK+ Version 3.6.4)
> >  of 2013-02-02 on buildvm-04.phx2.fedoraproject.org
> >
> > Thank you very much in advance for any pointers as to what I may be
> missing.
> >
> > 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"
>



-- 
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"

[-- Attachment #2: Type: text/html, Size: 5169 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Problem setting frame title on startup
  2013-03-16  9:47   ` Ian van der Neut
@ 2013-03-16 10:24     ` Mark Skilbeck
  2013-03-16 11:04       ` Ian van der Neut
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Skilbeck @ 2013-03-16 10:24 UTC (permalink / raw)
  To: Ian van der Neut; +Cc: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Problem setting frame title on startup
  2013-03-16 10:24     ` Mark Skilbeck
@ 2013-03-16 11:04       ` Ian van der Neut
  2013-03-16 11:26         ` Ian van der Neut
  0 siblings, 1 reply; 7+ messages in thread
From: Ian van der Neut @ 2013-03-16 11:04 UTC (permalink / raw)
  To: Mark Skilbeck; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 2638 bytes --]

On Sat, Mar 16, 2013 at 11:24 AM, Mark Skilbeck <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:
> > >
> > >     (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.

[-- Attachment #2: Type: text/html, Size: 4014 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Problem setting frame title on startup
  2013-03-16 11:04       ` Ian van der Neut
@ 2013-03-16 11:26         ` Ian van der Neut
  2013-03-18  5:40           ` XeCycle
  0 siblings, 1 reply; 7+ messages in thread
From: Ian van der Neut @ 2013-03-16 11:26 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 4174 bytes --]

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 <ivdneut@gmail.com>wrote:

>
>
>
> On Sat, Mar 16, 2013 at 11:24 AM, Mark Skilbeck <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:
>> > >
>> > >     (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"

[-- Attachment #2: Type: text/html, Size: 6302 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Problem setting frame title on startup
  2013-03-16 11:26         ` Ian van der Neut
@ 2013-03-18  5:40           ` XeCycle
  0 siblings, 0 replies; 7+ messages in thread
From: XeCycle @ 2013-03-18  5:40 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1122 bytes --]

Ian van der Neut <ivdneut@gmail.com> writes:

[...]

> 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.

If Emacs is started as `emacs --daemon`, there would be no frame
while executing .emacs.  If not started as a daemon, there would
be one, but after-make-frame-functions won't be executed for this
frame.

Therefore I wrote this macro:

(require 'cl)
(defmacro do-frames (&rest body)
  (let ((frame (gensym)))
    `(progn
       (dolist (,frame (frame-list))
         (select-frame ,frame)
         ,@body)
       (add-hook 'after-make-frame-functions
                 (lambda (new-frame)
                   (select-frame new-frame)
                   ,@body)))))

And (do-frames (what-ever you-like)) would work for all frames,
either started as daemon or not.

-- 
Carl Lei (XeCycle)
Department of Physics, Shanghai Jiao Tong University
OpenPGP public key: 7795E591
Fingerprint: 1FB6 7F1F D45D F681 C845 27F7 8D71 8EC4 7795 E591

[-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-03-18  5:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2013-03-16 11:04       ` Ian van der Neut
2013-03-16 11:26         ` Ian van der Neut
2013-03-18  5:40           ` XeCycle

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.