emacs: Set font according to screen DPI

This commit is contained in:
Erwin Boskma 2023-11-14 14:44:16 +01:00
parent 7ad29c469c
commit 5f351fe376
Signed by: erwin
SSH key fingerprint: SHA256:9LmFDe1C6jSrEyqxxvX8NtJBmcbB105XoqyUZF092bg
4 changed files with 51 additions and 64 deletions

View file

@ -55,11 +55,11 @@ Setting =lexical-binding= to =t= can improve startup time. This has to be first!
This sets some variables with my personal preferences for easy customization
#+begin_src emacs-lisp
(defvar my/default-font "Monaspace Argon-16")
(defvar my/variable-width-font "Iosevka Aile-16")
(defvar my/comment-font "Monaspace Radon-16")
(defvar my/default-font-height 13)
(defvar my/default-font-weight 'normal)
(defvar my/default-font "Monaspace Neon")
(defvar my/variable-width-font "Iosevka Aile")
(defvar my/comment-font "Monaspace Radon")
(defvar my/default-font-height 120)
(defvar my/default-font-weight 'light)
(defvar my/default-font-width 'normal)
(defvar my/variable-width-font-height 1.1)
(defvar my/config-file-path (expand-file-name "config.org" user-emacs-directory))
@ -366,7 +366,7 @@ Prefer to open frames in a horizontal split and make sure they're of a decent wi
#+begin_src emacs-lisp
(setq split-height-threshold nil
window-min-width 120)
window-min-width 100)
#+end_src
Set fill column to 80
@ -423,16 +423,30 @@ I prefer the [[https://draculatheme.com][dracula theme]]
Set fonts.
#+begin_src emacs-lisp
(defun my/set-font-size (&optional frame)
(let* ((frame (or frame (selected-frame)))
(geometry (frame-monitor-attribute 'geometry frame))
(mm-size (frame-monitor-attribute 'mm-size frame))
(width-px (caddr geometry))
(width-mm (car mm-size))
(width-in (/ width-mm 25.4))
(display-dpi (/ width-px width-in))
(font-height (cond
((< display-dpi 110) 120)
((< display-dpi 130) 140)
((< display-dpi 160) 160)
(t 160))))
(set-face-attribute 'default frame :height font-height)))
(add-hook 'server-after-make-frame-hook 'my/set-font-size)
(defun my/setup-fonts ()
; Monospace
(set-face-attribute 'default nil :font my/default-font)
(set-face-attribute 'font-lock-comment-face nil :font my/comment-font)
; Variable pitch
(set-face-attribute 'variable-pitch nil
:font my/variable-width-font
:height my/variable-width-font-height))
(set-face-attribute 'default nil :family my/default-font :weight 'light)
(set-face-attribute 'font-lock-comment-face nil :font my/comment-font)
(set-face-attribute 'variable-pitch nil
:font my/variable-width-font
:height my/variable-width-font-height))
(add-hook 'after-init-hook 'my/setup-fonts)
(add-hook 'server-after-make-frame-hook 'my/setup-fonts)
#+end_src
Emoji support
@ -1254,19 +1268,19 @@ Prefer local packages from =node_modules= to global ones
Add support for Elixir with [[https://github.com/elixir-editors/emacs-elixir][elixir-mode]]. The =elixir-format= hook sets up the correct formatter configuration when in a =projectile= project.
#+begin_src emacs-lisp
(use-package elixir-mode
:after eglot
:hook ((elixir-format . (lambda ()
(if (projectile-project-p)
(setq elixir-format-arguments
(list "--dot-formatter"
(concat (locate-dominating-file buffer-file-name ".formatter.exs") ".formatter.exs")))
(setq elixir-format-arguments nil))))
(elixir-mode . (lambda () (add-hook 'before-save-hook 'elixir-format nil t)))
(elixir-mode . eglot-ensure))
:config
;; (setq lsp-elixir-server-command '("elixir-ls"))
(add-to-list 'auto-mode-alist '("\\.[hl]eex\\'" . elixir-mode)))
(use-package elixir-mode
:after eglot
:hook ((elixir-format . (lambda ()
(if (projectile-project-p)
(setq elixir-format-arguments
(list "--dot-formatter"
(concat (locate-dominating-file buffer-file-name ".formatter.exs") ".formatter.exs")))
(setq elixir-format-arguments nil))))
(elixir-mode . (lambda () (add-hook 'before-save-hook 'elixir-format nil t)))
(elixir-mode . eglot-ensure))
:config
;; (setq lsp-elixir-server-command '("elixir-ls"))
(add-to-list 'auto-mode-alist '("\\.[hl]eex\\'" . elixir-mode)))
#+end_src
Add a [[https://github.com/ayrat555/mix.el][mix]] minor mode to call =mix= tasks from emacs.
@ -1469,15 +1483,15 @@ Tell =nil= to use =nixpkgs-fmt= for formatting nix files.
#+begin_src emacs-lisp
(with-eval-after-load 'eglot
(add-to-list 'eglot-server-programs
'(nix-mode . ("nil" :initializationOptions
`(:nil (:formatting (:command ["nixpkgs-fmt"])))))))
`(nix-mode . ("nil" :initializationOptions
(:formatting (:command ["nixpkgs-fmt"]))))))
#+end_src
*** Common Lisp
Common Lisp does not use =lsp-mode=, but has it's own environment: [[https://github.com/slime/slime][SLIME]] or Superior Lisp Interaction Mode for Emacs.
#+begin_src emacs-lisp
#+begin_src emacs-lisp :tangle no
(use-package slime
:init
(setq slime-lisp-implementations
@ -1491,6 +1505,13 @@ Common Lisp does not use =lsp-mode=, but has it's own environment: [[https://git
(lisp-mode . (lambda () (slime-mode t)))
(inferior-lisp-mode . (lambda () (inferior-slime-mode t))))
#+end_src
[[https://github.com/joaotavora/sly][SLY]] is a fork of SLIME, by the same author as =eglot=, with improved UX
#+begin_src emacs-lisp
(use-package sly)
#+end_src
*** Clojure
Similar to =lisp=, there is [[https://github.com/clojure-emacs/cider][CIDER]] (Clojure Interactive Development Environment that Rocks) for Clojure(Script)

View file

@ -142,7 +142,6 @@ in
(nil.overrideAttrs (_: { doCheck = false; }))
nixpkgs-fmt
python3
# (tree-sitter.withPlugins builtins.attrValues)
] ++
(with aspellDicts; [ en en-computers en-science fy nl ]);

View file

@ -22,5 +22,4 @@ _final: prev: {
patches = (prevAttrs.patches or [ ]) ++ [ ./ddccontrol-db/0001-add-del41d9.patch ];
});
monaspace = prev.pkgs.callPackage ../pkgs/monaspace { };
}

View file

@ -1,32 +0,0 @@
{ lib, stdenvNoCC, fetchzip }:
stdenvNoCC.mkDerivation rec {
pname = "monaspace";
version = "1.000";
src = fetchzip {
url = "https://github.com/githubnext/monaspace/releases/download/v${version}/monaspace-v${version}.zip";
hash = "sha256-H8NOS+pVkrY9DofuJhPR2OlzkF4fMdmP2zfDBfrk83A=";
stripRoot = false;
};
outputs = [ "out" ];
installPhase = ''
runHook preInstall
mkdir -p $out/share/fonts/monaspace
mkdir -p $out/share/fonts/monaspace-variable
cp monaspace-v${version}/fonts/otf/*.otf $out/share/fonts/monaspace
cp monaspace-v${version}/fonts/variable/*.ttf $out/share/fonts/monaspace-variable
runHook postInstall
'';
meta = with lib; {
description = "Monaspace";
longDescription = "An innovative superfamily of fonts for code.";
homepage = "https://monaspace.githubnext.com/";
license = licenses.ofl;
platforms = platforms.all;
maintainers = with maintainers; [ AndersonTorres ];
};
}