reddit / emacs

Position new frame relative to current frame

rt49 · 2022-09-13 04:15
Hi, I found the code below on StackOverflow and have it bound to Cmd-n. It creates a new frame with an empty buffer. Currently, the position of the new frame is set to (left: 100, top: 100). How do I make the position of the new frame relative (or even the same) to the frame where I'm calling this function from? Any help much appreciated! ​ (defun my-new-buffer-frame () "Create a new frame with a new empty buffer." (interactive) (let ((buffer (generate-new-buffer "untitled"))) (set-buffer-major-mode buffer) (display-buffer-pop-up-frame buffer '((pop-up-frame-parameters . ( (left . 100) (top . 100)))))))
rpluim · 2022-09-13 09:38
There's no builtin way of specifying that, so you have to do the calculation yourself: (defun my-new-buffer-frame () "Create a new frame with a new empty buffer." (interactive) (let ((buffer (generate-new-buffer "untitled")) (frame-pos (alist-get 'outer-position (frame-geometry)))) (set-buffer-major-mode buffer) (display-buffer-pop-up-frame buffer `((pop-up-frame-parameters . ( (left . ,(+ (car frame-pos) 100)) (top . ,(+ (cdr frame-pos) 100))))))))
rswgnu · 2022-09-13 09:57
The interactive HyControl window and frame management subsystem within the Hyperbole package does this automatically when creating or duplicating frames. Then it makes it trivial to move frames around the screen as well. All single char commands utilize a sticky prefix arg that let’s you set char or pixel-level movement. And then you can brace-enclose and type out any series of commands in any buffer to create a hyperbutton that executes them whenever you want. Way cool.
rt49 · 2022-09-13 11:15
This is exactly what I was after. Thanks a lot!
[deleted] · 2022-09-15 14:04
Testing.