How do I run a command just after the emacs frame has been rendered?
Asked Answered
Y

2

2

I'm trying to figure out how to use Emacs Code Browser (ECB) and one of the things you can do with it is set ecb-windows-width to decide how wide the ecb windows are. The problem is this sequence:

  1. Frame pops up on screen.
  2. ecb-activate gets called, scaled according to ecb-windows-width.
  3. default-frame-alist parameters kick in, frame gets resized.

The problem is that due to this order the width of the ecb window is set before the frame gets resized, and then doesn't get scaled.

So I'd like to run ecb-redraw-layout (or ideally just ecb-activate), but it has to happen after #3. Otherwise, some sort of ecb-dynamic-width-scale option would also work.

For what it's worth, ecb-auto-activate doesn't work, so I can't find out if that would solve it.

Yasminyasmine answered 17/5, 2009 at 22:37 Comment(1)
Sounds like a bug, you should email the maintainers of ecb.Episiotomy
Y
2

It looks like I've found a workaround.

  1. Set ecb-fix-window-size to true.
  2. When the frame loads, ecb-activate is called and the ecb windows are scaled proportionally to the frame size.
  3. Then default-frame-alist kicks in and frame gets resized, but the ecb windows have a fixed size and don't get scaled.

Quite hackish because you're setting the width according to the default frame size that comes up first, not the size you actually use. But oh well.

Yasminyasmine answered 17/5, 2009 at 23:34 Comment(0)
O
1

I'm unfamiliar with ECB, but after-make-frame-functions might be helpful in running the functions you want (or running some hook function where you want to do special things with the ecb frame).

after-make-frame-functions is a list of functions that take one argument (the newly created frame), and is run after the frame is created. This doesn't apply to the initial emacs frame (on startup) because your .emacs is read after the frame is already created.

Obcordate answered 17/5, 2009 at 22:56 Comment(2)
Yeah, I tried that hook but it doesn't seem to actually call the function, nothing happens. In fact if I just do this: (add-hook 'after-make-frame-functions '(lambda () (setq xx 1))) and then try to evaluate xx after emacs has started it turns out the variable hasn't been set.Yasminyasmine
The hook-function must take a single frame parameter. So, after I do the following, and call (make-frame), the variable xx does get set to 1. I haven't tried it for the main emacs frame (that is, after launching emacs): (add-hook 'after-make-frame-functions (lambda (the-frame) (setq xx 1)))Obcordate

© 2022 - 2024 — McMap. All rights reserved.