Skip to main content
Don't repeat the `assq`
Source Link
Toby Speight
  • 81.8k
  • 14
  • 101
  • 309
(let* ((dmal (car (display-monitor-attributes-list))) ; first monitor only
       (width (nth 3geometry (assq 'geometry dmal)))
       (heightwidth (nth 43 geometry))
       (assqheight 'geometry(nth dmal)4 geometry)))
  ;; your code
  )
(let* ((dmal (car (display-monitor-attributes-list))) ; first monitor only
       (width (nth 3 (assq 'geometry dmal)))
       (height (nth 4 (assq 'geometry dmal))))
  ;; your code
  )
(let* ((dmal (car (display-monitor-attributes-list))) ; first monitor
       (geometry (assq 'geometry dmal))
       (width (nth 3 geometry))
       (height (nth 4 geometry)))
  ;; your code
  )
Don't use X functions on non-X platforms; use less opaque int->float conversion
Source Link
Toby Speight
  • 81.8k
  • 14
  • 101
  • 309

You'll want to guard the function so you don't try to call it on non-X displays (e.g. emacs -nw):

(when window-system
        ;; your code
      )

You might want to access (display-monitor-attributes-list) to be more platform portable than the X11 functions (but you'll need to do a bit more work to extract the relevant properties:

(let* ((dmal (car (display-monitor-attributes-list))) ; first monitor only
       (width (nth 3 (assq 'geometry dmal)))
       (height (nth 4 (assq 'geometry dmal))))
  ;; your code
  )

The test is very specific - you might want to add other, larger screens:

(and (>= (x-display-pixel-width) 3840)
     (>= (x-display-pixel-width) 2160))

Consider measuring the pixel pitch rather than the overall size:

(< (/ (* 1.0float (display-mm-height)) (x-display-pixel-width)) 0.1)

Reduce the duplication:

(setq-default dotspacemacs-default-font
              (list "Source Code Pro" :size
                    (if (and (eq 3840 (x-display-pixel-width))
                             (eq 2160 (x-display-pixel-height)))
                        34
                      18)))

Support more than two sizes:

(setq-default dotspacemacs-default-font
              (list "Source Code Pro" :size
                    (cond ((<= 3840 (x-display-pixel-width))
                           34)
                          ((<= 1920 (x-display-pixel-width))
                           18)
                          (t
                           12))))

You'll want to guard the function so you don't try to call it on non-X displays (e.g. emacs -nw):

(when window-system
        ;; your code
      )

The test is very specific - you might want to add other, larger screens:

(and (>= (x-display-pixel-width) 3840)
     (>= (x-display-pixel-width) 2160))

Consider measuring the pixel pitch rather than the overall size:

(< (/ (* 1.0 (display-mm-height)) (x-display-pixel-width)) 0.1)

Reduce the duplication:

(setq-default dotspacemacs-default-font
              (list "Source Code Pro" :size
                    (if (and (eq 3840 (x-display-pixel-width))
                             (eq 2160 (x-display-pixel-height)))
                        34
                      18)))

Support more than two sizes:

(setq-default dotspacemacs-default-font
              (list "Source Code Pro" :size
                    (cond ((<= 3840 (x-display-pixel-width))
                           34)
                          ((<= 1920 (x-display-pixel-width))
                           18)
                          (t
                           12))))

You'll want to guard the function so you don't try to call it on non-X displays (e.g. emacs -nw):

(when window-system
        ;; your code
      )

You might want to access (display-monitor-attributes-list) to be more platform portable than the X11 functions (but you'll need to do a bit more work to extract the relevant properties:

(let* ((dmal (car (display-monitor-attributes-list))) ; first monitor only
       (width (nth 3 (assq 'geometry dmal)))
       (height (nth 4 (assq 'geometry dmal))))
  ;; your code
  )

The test is very specific - you might want to add other, larger screens:

(and (>= (x-display-pixel-width) 3840)
     (>= (x-display-pixel-width) 2160))

Consider measuring the pixel pitch rather than the overall size:

(< (/ (float (display-mm-height)) (x-display-pixel-width)) 0.1)

Reduce the duplication:

(setq-default dotspacemacs-default-font
              (list "Source Code Pro" :size
                    (if (and (eq 3840 (x-display-pixel-width))
                             (eq 2160 (x-display-pixel-height)))
                        34
                      18)))

Support more than two sizes:

(setq-default dotspacemacs-default-font
              (list "Source Code Pro" :size
                    (cond ((<= 3840 (x-display-pixel-width))
                           34)
                          ((<= 1920 (x-display-pixel-width))
                           18)
                          (t
                           12))))
Source Link
Toby Speight
  • 81.8k
  • 14
  • 101
  • 309

You'll want to guard the function so you don't try to call it on non-X displays (e.g. emacs -nw):

(when window-system
        ;; your code
      )

The test is very specific - you might want to add other, larger screens:

(and (>= (x-display-pixel-width) 3840)
     (>= (x-display-pixel-width) 2160))

Consider measuring the pixel pitch rather than the overall size:

(< (/ (* 1.0 (display-mm-height)) (x-display-pixel-width)) 0.1)

Reduce the duplication:

(setq-default dotspacemacs-default-font
              (list "Source Code Pro" :size
                    (if (and (eq 3840 (x-display-pixel-width))
                             (eq 2160 (x-display-pixel-height)))
                        34
                      18)))

Support more than two sizes:

(setq-default dotspacemacs-default-font
              (list "Source Code Pro" :size
                    (cond ((<= 3840 (x-display-pixel-width))
                           34)
                          ((<= 1920 (x-display-pixel-width))
                           18)
                          (t
                           12))))