Question

Using emacs -nw I would like to make hooks so that certain modes (for writing prose) gives me a narrow centered frame. This

(set-frame-width (selected-frame) 100)

... sets a narrower frame but aligned to the left.

How do I center it? And how do I set a hook that changes the frame when I switch mode?

No correct solution

OTHER TIPS

Try using the hooks after-make-frame-functions and after-change-major-mode-hook.

(Dunno how much these will help with emacs -nw, though.)

The following link to a gist on Github written by @ieure appears to resolve your issue as to centering:

https://gist.github.com/ieure/80638


See also the following two (2) libraries written by @Drew:

http://emacswiki.org/emacs/frame-fns.el

http://emacswiki.org/emacs/frame-cmds.el


Here are a few examples. On a screen with 1920 x 1080 pixels, my maximum frame-height is 52 and my maximum frame-width is 172. The function below that is named minimize changes the size of all open frames and places the reduced frames to the left side of the screen, because I like to type notes in Emacs while I'm looking at another application -- e.g., Adobe Acrobat.

When using set-frame-position, the numbers are x and y coordinates starting with the upper left-hand corner of the screen. For example, a frame with (set-frame-position (selected-frame) 300 300) will be to the lower-right of another frame with (set-frame-position (selected-frame) 0 0).

(add-hook 'text-mode-hook (lambda ()
  (set-frame-height (selected-frame) 20)
  (set-frame-width (selected-frame) 80)
  (set-frame-position (selected-frame) 400 400) ))

(defun minimize ()
(interactive)
  (dolist (frame (frame-list))
    (set-frame-height frame 52)
    (set-frame-width frame 50)
    (set-frame-position frame 0 0) ))

(defun maximize ()
(interactive)
  (dolist (frame (frame-list))
    (set-frame-height frame 52)
    (set-frame-width frame 172)
    (set-frame-position frame 0 0) ))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top