0

I have the following code to store the position where to put the initial frame (fxpos and fypos).

My problem is that when I run a new emacs session, the defcustom commands are resetting the values back to 8. What can I do to avoid this?

(defgroup frame-pos nil
  "Set position of frame."
  :group 'convenience)

(defcustom fxpos 8
  "X position of initial frame."
  :type 'integer
  :group 'frame-pos)

(defcustom fypos 8
  "Y position of initial frame."
  :type 'integer
  :group 'frame-pos)

(defun frame-shift (frame)

  (let* ( (lft (car (frame-position)))
          (top (cdr (frame-position)))
          (wdt (frame-outer-width frame))
          (hgt (frame-outer-height frame))
          (fxmid (+ lft (/ wdt 2)))
          (fymid (+ top (/ hgt 2)))
          (mgm (cdr (assq 'geometry (frame-monitor-attributes frame))))
          (mxmid (+ (nth 0 mgm) (/ (nth 2 mgm) 2)))
          (mymid (+ (nth 1 mgm) (/ (nth 3 mgm) 2)))
          (nlft (+ lft (- mxmid fxmid)))
          (ntop (+ top (- mymid fymid))) )

    (custom-declare-variable 'fxpos nlft)
    (custom-declare-variable 'fypos ntop)))
7
  • The only way for emacs sessions to communicate is through the file system: save the settings to a file in the old session and read them in from the file in the new session.
    – NickD
    Sep 17 at 21:46
  • I want emacs to display as usual when the values are not set. Emacs decides where to put the initial frame. Unless the user decides to call the function that computes a centered position.
    – konmi
    Sep 17 at 21:56
  • I thought the way to save options in emacs is through defcustom.
    – konmi
    Sep 17 at 21:57
  • The way for users to set customisation is through defcustom. That that involve storing in a file system as well?
    – konmi
    Sep 17 at 22:06
  • 3
    Does this answer your question? How to make size of Emacs frame persistent?
    – Drew
    Sep 17 at 22:09

1 Answer 1

0

I vote to close the question as a duplicate. But if others don't also vote that way then here's the answer: initial-frame-alist.

initial-frame-alist is a variable defined in frame.el.

Its value is nil

Alist of parameters for the initial X window frame.

You can set this in your init file; for example,

(setq initial-frame-alist
      '((top . 1) (left . 1) (width . 80) (height . 55)))

Parameters specified here supersede the values given in default-frame-alist.

If the value calls for a frame without a minibuffer, and you have not created a minibuffer frame on your own, a minibuffer frame is created according to minibuffer-frame-alist.

You can specify geometry-related options for just the initial frame by setting this variable in your init file; however, they won’t take effect until Emacs reads your init file, which happens after creating the initial frame. If you want the initial frame to have the proper geometry as soon as it appears, you need to use this three-step process:

  • Specify X resources to give the geometry you want.
  • Set default-frame-alist to override these options so that they don’t affect subsequent frames.
  • Set initial-frame-alist in a way that matches the X resources, to override what you put in default-frame-alist.

This variable may be risky if used as a file-local variable. You can customize this variable.

Probably introduced at or before Emacs version 24.1.

2
  • I am really struggling with this. Here one is hardwiring the values, so that every time one calls emacs, the initial frame uses the hardwired values. Thus, it is not possible for the user to call a function that determines the position of the frame, and then be able to store them for future sessions in variables.
    – konmi
    Sep 17 at 23:22
  • Chicken, meet the egg...
    – NickD
    Sep 17 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.