Kasper Daniel Hansen
khans****@stat*****
Mon Feb 19 04:23:39 JST 2007
This is my solution, based on some advice from Seiji-san regarding two things: 1) I want to be able to maximize Emacs so that it covers all of the available screen, including the menu bar and the dock (this is called presentation mode in some applications) 2) I am regularly using an external monitor and want to change my emacs settings (especially font and window size) between my laptop and my external display My solution uses two functions mac-switch-display which switches between window configurations and mac-resize-display which switches between normal and full screen mode. The two functions are bound to M- f1 and M-f2. I never use more than a single frame, so I am not sure how it works with several frames. The settings are defined in the variable mac-display-list and should be quite obvious. The positions are in pixels and the sizes are in characters. It seems like Emacs _needs_ a character based frame size. For that reason it may be difficult to _exact;_ cover the entire screen estate (I have a few pixels worth of empty space, when maximizing on my laptop). For obvious reasons, a character based width is very dependent on the font you are using, so I gave up on auto-setting it. In case you need to discover what the position/size of you frame is for configuration purpose, entering these lines into the scratch buffer will help: (frame-parameter (selected-frame) 'font) (frame-parameter (selected-frame) 'height) (frame-parameter (selected-frame) 'left) (frame-parameter (selected-frame) 'top) You use them by placing the cursor at the end of the line _right next to the last )_ and then press C-x C-e. Without further ado, here is the relevant part from my dot-emacs: (setq mac-display-list '((external . ((name . "external") (font . "-*-*-medium-r-normal--16-*-*-*-*-*-fontset- hiraginokaku") (normalsize . (110 48)) (normalposition . (0 22)) (maxsize . (164 49)))) (laptop . ((name . "laptop") (font . "-*-*-medium-r-normal--14-*-*-*-*-*-fontset-hiraginokaku") (normalsize . (80 38)) (normalposition . (0 22)) (maxsize . (124 39)))) )) (defun mac-switch-display () "Switches the display type between laptop and external" (interactive) (cond ((equal (cdr (assoc 'name mac-current-display)) "laptop") (setq mac-current-display (cdr (assoc 'external mac-display-list)))) ((equal (cdr (assoc 'name mac-current-display)) "external") (setq mac-current-display (cdr (assoc 'laptop mac-display-list)))) ) (apply 'set-frame-size (cons (selected-frame) (cdr (assoc 'normalsize mac-current-display)))) (apply 'set-frame-position (cons (selected-frame) (cdr (assoc 'normalposition mac-current-display)))) (apply 'set-frame-font (list (cdr (assoc 'font mac-current- display)))) ) (defun mac-resize-display () "Resizes the display. Toggles between the maxed and normal display size. If the current displaysize is smaller than the normal display size, switch to the normal display size. All sizes are frame widths" (interactive) (cond ((< (frame-parameter (selected-frame) 'width) (car (cdr (assoc 'normalsize mac-current-display)))) (mac-show-menu-bar) (apply 'set-frame-position (cons (selected-frame) (cdr (assoc 'normalposition mac-current-display)))) (apply 'set-frame-size (cons (selected-frame) (cdr (assoc 'normalsize mac-current-display)))) ) ((< (frame-parameter (selected-frame) 'width) (car (cdr (assoc 'maxsize mac-current-display)))) (mac-hide-menu-bar) (set-frame-position (selected-frame) 0 0) (apply 'set-frame-size (cons (selected-frame) (cdr (assoc 'maxsize mac-current-display)))) ) ((= (frame-parameter (selected-frame) 'width) (car (cdr (assoc 'maxsize mac-current-display)))) (mac-show-menu-bar) (apply 'set-frame-position (cons (selected-frame) (cdr (assoc 'normalposition mac-current-display)))) (apply 'set-frame-size (cons (selected-frame) (cdr (assoc 'normalsize mac-current-display)))) ) )) (if (eq window-system 'mac) (progn (require 'carbon-font) (setq mac-current-display (cdr (assoc 'external mac-display-list))) (mac-switch-display) (global-set-key (kbd "<M-f1>") 'mac-resize-display) (global-set-key (kbd "<M-f2>") 'mac-switch-display) )) Kasper