Hi Martin,

This was a great "today-I-learned" thread.

Both of your suggested solutions work:
- Using frame-text-width/height instead of frame-pixel-width/height is the right thing to do. I misunderstood frame-text-* fns to return the parameters in text char widths and frame-pixel-* fns to return the parameters in pixels.
- In emacs 25+, frame-inhibit-implied-resize can be set to '(menu-bar-lines) to prevent frame resize when toggling the menu bar.

Thank you!

On Tue, Sep 15, 2015 at 4:33 AM martin rudalics <rudalics@gmx.at> wrote:
 >    (set-frame-width nil width nil t)
 >    (message "%s" (cons width (frame-text-width))))

Sorry.  Without the ‘sit-for’ this is confusing.  So this

(let ((width (frame-pixel-width)))
   (setq frame-resize-pixelwise t)
   (set-frame-width nil (+ width 20) nil t)
   (sit-for 2)
   (set-frame-width nil width nil t)
   (sit-for 2)
   (message "%s" (cons width (frame-pixel-width))))

is bad while this

(let ((width (frame-text-width)))
   (setq frame-resize-pixelwise t)
   (set-frame-width nil (+ width 20) nil t)
   (sit-for 2)
   (set-frame-width nil width nil t)
   (sit-for 2)
   (message "%s" (cons width (frame-text-width))))

should do what you want.

martin