Calling elisp code when awakening from sleep - emacs

I'd like to configure emacs a little differently when coming in over remote desktop. I can detect the rdp session, but I'd like to automatically run the function that checks when emacs wakes from sleep. I believe Windows issues a PBT_APMRESUMESUSPEND event when awakening because of user activity -- is there a way to hook this from within emacs?
This would be for emacs 24.4 on Windows. Some code or a pointer to the right documentation would be great. I've looked but am not seeing anything -- maybe I'm not looking in the right place. Thanks in advance.

I don't know of any hooks that are triggered in your situation, would it be possible to solve your situation using the input focus hooks?
Specifically, focus-in-hook.

Related

How do I figure out which extension or service is making a VS Code Helper process use 100% CPU?

Every so often the fans on my MacBook Pro start revving up and certain things in VS Code stop working, such as indentation and autocomplete etc.
When this happens I use Alfred App to figure out which process is causing an issue and it's usually one or more of the Code Helper processes launched by VS Code. Sometimes they'll a couple of them using way over 100% of the CPU. I kill the processes and then VS Code prompts me that the extension host has quit and to restart it. Once I do that the extensions start working again as normal. And then the whole thing repeats, just not all the time. For instance I'm writing this message now and Code is fine and not doing anything.
I'm wondering how do I debug this and figure out whether it's Code itself or an Extension causing the issue? If so how do I find out which extension it is?
Process Explorer is builtin in vscode.
It can be opened using menu by going Help => Open Process Explorer

What code should I use? sys.exit() or some other thing I haven't found?

I'm a high school student in a class that is using Python 2 on Enthought Canopy Windows Edition. I often get stuck in coding loops, but the only way I can get out is by closing out all forms of open Enthought. Is there any more reliable way to do it? I've been using sys.exit(0), but it doesn't work correctly, and is leaving my coding in a jam. I can't even test it without it getting me stuck. Anyone know how to fix this issue?
If your code is already running, then you can't reliably type a command to stop it, because the prompt won't necessarily be live then.
Often you can use the Run menu's "Interrupt kernel" command, and you should usually be able to use "Restart kernel", though this doesn't work all the time.

How can I know whether process has a windows or not?

Sometimes my program is finished incorrectly. GUI is gone but processes still present in the system. So I need to verify whether the program finishes correctly or not by checking GUI presence. Could anyone help me with it?
It looks like what you need is WASP.
You can use WASP's Select-Window to list all window handles.
You can then use Select-Window Myapp* to set focus on the window, if required.

how to restore escreen configuration on emacs startup?

Is there a way to restore all escreen screens and window configurations on emacs startup?
I tried to add the (escreen-configuration-alist) to desktop-saved-globals with no result.
I also tried to execute some code manually, but whenever I run (escreen-restore-screen-map screen-map) with screen-map being export of current escreen screen map, I get "wrong argument type window-configuration-p".
Not an elisp expert and a little bit stuck.
If there's no luck with escreen, maybe el-screen has the needed functionality?
Thanks.
Actually, escreen use the window configuration as defined in Emacs. Unfortunately window configuration is hard coded in C and there is no serialization. So you cannot save/restore between sessions but simply register it.
The only way is to rewrite window configuration in Emacs Lisp. HIROSE Yuuji wrote his own window configuration and it works great! I enhanced it to support frames and escreen case and post it on github: https://github.com/martialboniou/revive-plus
I provided this package WITHOUT ANY WARRANTY. No unit test, for instance, but it should work. Let me know (it's a fresh hack so there will be refactoring soon)!

In Emacs how to prevent the same buffer from showing up in different windows in the same frame?

I'm not sure how to comprehensively accomplish this.
Currently I build my own bzr Emacs on Windows, so I can see that `display-buffer' now takes a SPECIFIERS option, which could be interesting, but I couldn't find concrete examples of how to use it.
But this problem really has to be solved before display-buffer is called.
For example a Help window previously was visiting Buffer-A, but I've visited Buffer-A in another window while reading the help. Now when I quit the Help window, Buffer-A appears there as well. I want some other useful buffer to appear there.
I have some experimental code that appears to work here.
I emphasize experimental. This could melt your Emacs.
I'd appreciate it if you could contact me on github or here to let me know your experiences with this.
Emacs 24 is not yet released. They have changed the buffer-display/window behavior and Lisp interfaces several times over the release's development period. The current status of the release is pretest, so development is supposedly stopped, except for bug fixes.
However, ongoing emacs-devel#gnu.org discussions show that things are still in flux wrt buffer display and windows.
Your best bet is to check the latest doc and code (which might not correspond exactly, at this point).