/
screen-setups.el
120 lines (103 loc) · 4.04 KB
/
screen-setups.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
;;;; use bundled sets of font and dimensions
;;; Time-stamp: <2007-03-04 11:46:41 jcgs>
;; This program is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by the
;; Free Software Foundation; either version 2 of the License, or (at your
;; option) any later version.
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License along
;; with this program; if not, write to the Free Software Foundation, Inc.,
;; 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(provide 'screen-setups)
(require 'cl)
;; (cdr (assoc 'font (frame-parameters)))
;; use x-list-fonts to get possibilities
(setq try-fonts-old-font (cdr (assoc 'font (frame-parameters)))
try-fonts-old-width (screen-width)
try-fonts-old-height (screen-height))
(defun try-fonts-restore ()
(interactive)
(set-default-font try-fonts-old-font)
(set-screen-width try-fonts-old-width)
(set-screen-height try-fonts-old-height))
(defun try-fonts (pattern)
(interactive "sTry fonts matching: ")
(switch-to-buffer (get-buffer-create "*Fonts*"))
(erase-buffer)
(let ((fonts (x-list-fonts pattern))
(most-lines 0)
(most-lines-font nil)
)
(setq try-fonts-old-font (cdr (assoc 'font (frame-parameters)))
try-fonts-old-width (screen-width)
try-fonts-old-height (screen-height))
(set-screen-height 8)
(set-screen-width 96)
(while fonts
(set-default-font (car fonts))
(insert (format "%S: %dx%d\n" (car fonts) (frame-width) (frame-height)))
(goto-char (point-max))
;; need to maximize frame after setting each font, for this to make sense:
(if (> (frame-height) most-lines)
(setq most-lines (frame-height)
most-lines-font (car fonts)))
(sit-for 1)
(setq fonts (cdr fonts)))
(try-fonts-restore)
(message "%s was the font with most lines, at %d" most-lines-font most-lines)))
(defvar screen-setups
'(("normal" "6x10" 80 24))
"Some bundled named lists of font, frame width, frame height.
These are meant as pre-packaged frame setups, to be set appropriately
on each host / X-server on which you run Emacs. I set them up so that
on each of my machines, Emacs takes all the display space available
to it -- why would I want to look at anything else? ;-)")
;;;###autoload
(defun get-screen-setup (&rest names)
"Select the first screen setup that exists, from NAMES."
(catch 'found
(while names
(let ((this (assoc (car names) screen-setups)))
(if this
(throw 'found this)
(setq names (cdr names)))))
(assoc "normal" screen-setups)))
(defvar current-screen-setup-name nil
"The current screen setup, as last set by use-screen-setup.")
;;;###autoload
(defun use-screen-setup (name)
"Use screen setup NAME."
(interactive
(list
(completing-read "Use screen setup: "
screen-setups
nil
t)))
(let ((setup (get-screen-setup name)))
(if setup
(let* ((fp (frame-parameters))
(oldfont (assoc 'font fp))
)
(message "Using screen setup %S" setup)
(when oldfont
(message "Changing font from %S to %S" (cdr oldfont) (second setup)))
(condition-case evar
(progn
(set-frame-font (second setup))
(setq current-screen-setup-name name)
(message "Changing size from %dx%d to %dx%d"
(cdr (assoc 'width fp)) (cdr (assoc 'height fp))
(third setup) (fourth setup))
(set-frame-width (selected-frame) (third setup))
(set-frame-height (selected-frame) (fourth setup))
(setq buffers-menu-max-size (/ (* 3 (fourth setup)) 4)))
(error "Failed to select font %s: error %s" (second setup) evar)))
(message "No such screen setup"))))
(defvar default-screen-setup "normal"
"Which screen setup to start with.
Will normally be pre-set from host-setup.el")
(use-screen-setup default-screen-setup)
;;; end of screen-setups.el