Fix bug in exec-path-from-shell hook, simplify font setup
Some checks failed
/ Test config on 20 (push) Failing after 48s

This commit is contained in:
Maciej 2025-01-05 17:34:12 +02:00
parent b0361861b4
commit 0ec8f700af
Signed by: maciej
GPG key ID: 41D62D42D3B0D765
4 changed files with 75 additions and 86 deletions

View file

@ -1,14 +1,8 @@
# My emacs config # Emacs configuration
Contains config I use for the following languages/modes: This is the repository of my emacs configuration that I use on both MacOS and Linux. There are some additional configuration properties to use with BSD when I was testing it, but it is best treated as abandoned.
* Elixir I predominantly write Elixir, so that part is the most polished bit of the configuration but it also works for Ruby, Rust, Go, Javascript/Typescript and Kotlin. I use emacs for programming, so there is no org-mode, GTD, email or RSS here. I use deft to keep some programming notes here and there.
* Ruby
* Rust
* Markdown
* HTML and compatibile (ERB)
As of current iteration, I avoid usage of Evil modes, instead focusing of usage of Emacs functionality.
## Installation ## Installation
@ -19,6 +13,5 @@ git clone git@github.com:maciej-szlosarczyk/emacs.git ~/.emacs.d
And then put the following lines into init.el And then put the following lines into init.el
```emacs ```emacs
(add-to-list 'load-path (concat user-emacs-directory "lisp"))
(require 'icejam-custom-init) (require 'icejam-custom-init)
``` ```

View file

@ -101,15 +101,13 @@
;; :if (memq window-system '(x mac ns)) ;; :if (memq window-system '(x mac ns))
:ensure t :ensure t
:defer t :defer t
:hook ((elpaca-after-init . exec-path-from-shell-initalize)) :hook ((elpaca-after-init . exec-path-from-shell-initialize))
:config :config
(declare-function exec-path-from-shell-initialize "exec-path-from-shell") (declare-function exec-path-from-shell-initialize "exec-path-from-shell")
(add-to-list 'exec-path "/usr/local/bin") (add-to-list 'exec-path "/usr/local/bin")
(dolist (var '("DEFT_PATH" "LANG" "LC_CTYPE")) (dolist (var '("DEFT_PATH" "LANG" "LC_CTYPE"))
(add-to-list 'exec-path-from-shell-variables var))) (add-to-list 'exec-path-from-shell-variables var)))
;; (use-package envrc :ensure t :hook (elpaca-after-init . envrc-global-mode))
(use-package direnv :ensure t :defer t (use-package direnv :ensure t :defer t
:hook ((elpaca-after-init . direnv-mode))) :hook ((elpaca-after-init . direnv-mode)))

View file

@ -78,6 +78,7 @@
;; I don't know why this needs to be here and with a lisp directory, but ;; I don't know why this needs to be here and with a lisp directory, but
;; normal subdirs.el file doesn't work. ;; normal subdirs.el file doesn't work.
(add-to-list 'load-path (concat user-emacs-directory "lisp"))
(add-to-list 'load-path (concat user-emacs-directory "lisp/themes")) (add-to-list 'load-path (concat user-emacs-directory "lisp/themes"))
(add-to-list 'load-path (concat user-emacs-directory "lisp/langs")) (add-to-list 'load-path (concat user-emacs-directory "lisp/langs"))

View file

@ -9,6 +9,7 @@
;; Set font stuff ;; Set font stuff
;;; Code: ;;; Code:
(use-package dash :ensure t :defer t)
;; (defconst icejam-font "Monoid" ;; (defconst icejam-font "Monoid"
;; (defconst icejam-font "Fira Mono" ;; (defconst icejam-font "Fira Mono"
@ -27,21 +28,27 @@
;; (defconst icejam-font "Victor Mono Medium" "Default font.") ;; (defconst icejam-font "Victor Mono Medium" "Default font.")
;; (defconst icejam-font "Iosevka Term" "Default font.") ;; (defconst icejam-font "Iosevka Term" "Default font.")
(defconst icejam-font "Iosevka Comfy Motion" "Default font.") (defconst icejam-font-family "Iosevka Comfy Motion" "Default font.")
(defconst icejam-markdown-font-family "Iosevka Term" "Font used to render code blocks in markdown.")
(defconst icejam-font-size 14 (defconst icejam-font-height 14
"Default size of then font. "Default height of then font.
It is used to calculated the size in relation to the screen It is used to calculated the height in relation to the screen
in `icejam-set-font-to-screen`.") in `icejam-set-font-to-screen`.")
(defcustom icejam-mut-font (defcustom icejam-mut-font-family
icejam-font icejam-font-family
"Current font, defaults to the one loaded in the beginning." "Current font, defaults to the one loaded in the beginning."
:type 'string :type 'string
:group 'icejam) :group 'icejam)
(defcustom icejam-mut-font-size (defcustom icejam-mut-markdown-font-family
icejam-font-size icejam-markdown-font-family
"Current font size." "Current markdown font family, defaults to the one loaded in the beginning."
:type 'string
:group 'icejam)
(defcustom icejam-mut-font-height
icejam-font-height
"Current font height."
:type 'integer :type 'integer
:group 'icejam) :group 'icejam)
@ -50,85 +57,75 @@ in `icejam-set-font-to-screen`.")
(defvar lsp-ui-doc-frame-hook) (defvar lsp-ui-doc-frame-hook)
(defun icejam-set-lsp-ui-font-hook () (defun icejam-set-lsp-ui-font-hook ()
"Reset LSP IO font to specified `icejam-font` and `icejam-font-size`." "Reset LSP IO font to specified `icejam-font` and `icejam-font-height`."
(setopt lsp-ui-doc-frame-hook nil) (setopt lsp-ui-doc-frame-hook nil)
(add-hook 'lsp-ui-doc-frame-hook (add-hook
'lsp-ui-doc-frame-hook
(lambda (frame _w) (lambda (frame _w)
(set-face-attribute (set-face-attribute 'default frame
'default frame :font :family icejam-mut-font-family
(format "%s %d" icejam-mut-font (- icejam-mut-font-size 2)))))) :height (-> icejam-mut-font-height (- 2) (* 10))))))
(defun icejam-set-font (name size) (defun icejam-set-font (family height)
"Set font to NAME and its SIZE to X pixels." "Set font to FAMILY and its HEIGHT to X.
(interactive "sNew font: \nnEnter size for %s: ")
(setopt icejam-mut-font name)
(setopt icejam-mut-font-size size)
(set-face-attribute 'default nil :font (format "%s %d" name size)) Not all faces will be set to this value. Some of them look better with being
slightly smaller than the default face, by 1 point. Those are: `tooltip',
`company-tooltip', `company-tooltip-annotation', `company-tooltip-mouse'.
;; Set completion and modeline font to be 1 pixel point smaller than Modeline faces (`mode-line' and `mode-line-inactive') look better if they are
;; the general font two points smaller."
;; (set-face-attribute (interactive "sNew font: \nnEnter height for %s: ")
;; 'markdown-code-face nil :font (format "%s %d" name (- size 1))) (setopt icejam-mut-font-family family)
(set-face-attribute (setopt icejam-mut-font-height height)
'tooltip nil :font (format "%s %d" name (- size 1)))
(set-face-attribute ;; Set default font.
'company-tooltip nil :font (format "%s %d" name (- size 1))) (set-face-attribute 'default nil :family family :height (-> height (* 10)))
(set-face-attribute
'company-tooltip-annotation nil :font (format "%s %d" name (- size 1))) ;; Some font faces look better when they are 1 point smaller.
(set-face-attribute (dolist (face '(tooltip
'company-tooltip-mouse nil :font (format "%s %d" name (- size 1))) company-tooltip
(set-face-attribute company-tooltip-annotation
'mode-line nil :font (format "%s %d" name (- size 1))) company-tooltip-mouse))
(set-face-attribute (set-face-attribute face nil :height (-> height (- 1) (* 10))))
'mode-line-inactive nil :font (format "%s %d" name (- size 1)))
;; And some, mainly in modeline with 2 points.
(dolist (face '(mode-line mode-line-inactive))
(set-face-attribute face nil :height (-> height (- 2) (* 10))))
;; Call LSP-UI hook ;; Call LSP-UI hook
(icejam-set-lsp-ui-font-hook)) (icejam-set-lsp-ui-font-hook))
(defun icejam-set-font-to-screen () (defun icejam-set-font-to-screen ()
"Automatically set font size to suit the monitor." "Automatically set font height to suit the monitor."
;; If display is set to emulate FullHD resultion or less, make the font
;; smaller.
(interactive) (interactive)
(cond ((eq (x-display-list) nil)) ;; Only do anything if there's a display at all.
;; built-in screen (if (x-display-list)
((>= 1050 (x-display-pixel-height)) (cond
(icejam-set-font icejam-font icejam-font-size)) ;; LG 27" screen connected to a MacBook.
;; 4K screen on a Mac
((>= 1080 (x-display-pixel-height)) ((>= 1080 (x-display-pixel-height))
(icejam-set-font icejam-font icejam-font-size)) (icejam-set-font icejam-font-family icejam-font-height))
;; Other screens
((>= 1120 (x-display-pixel-height))
(icejam-set-font icejam-font icejam-font-size))
;; MacBook 14" built-in screen.
((>= 1440 (x-display-pixel-height)) ((>= 1440 (x-display-pixel-height))
(icejam-set-font icejam-font (+ icejam-font-size 3))) (icejam-set-font icejam-font-family (+ icejam-font-height 3)))
((>= 1920 (x-display-pixel-height))
(icejam-set-font icejam-font icejam-font-size))
;; 4K screen on Windows or Linux ;; 4K screen on Windows or Linux
((>= 2160 (x-display-pixel-height)) ((>= 2160 (x-display-pixel-height))
(icejam-set-font icejam-font (- icejam-font-size 3))) (icejam-set-font icejam-font-family (- icejam-font-height 3))))))
;; Default ;; Run the above function once, after elpaca finishes all downloads.
(t (icejam-set-font icejam-font (- icejam-font-size 3))))) (add-hook 'elpaca-after-init-hook 'icejam-set-font-to-screen)
;; Do it automatically on startup (defun icejam-set-font-height (height)
(icejam-set-font-to-screen) "Set font to a specified HEIGHT."
(interactive "nEnter height for font: ")
(icejam-set-font icejam-mut-font-family height))
(defun icejam-set-font-size (size) (defun icejam-set-font-height-for-this-frame (new-height)
"Set font to a specified SIZE." "Set font NEW-HEIGHT for this frame only."
(interactive "nEnter size for font: ") (interactive "nEnter new height for font in this frame: ")
(icejam-set-font icejam-mut-font size)) (set-frame-font (format "%s %d" icejam-mut-font-family new-height)))
(defun icejam-set-font-size-for-this-frame (new-size)
"Set font NEW-SIZE for this frame only."
(interactive "nEnter new size for font in this frame: ")
(set-frame-font (format "%s %d" icejam-mut-font new-size)))
;; Remove ugly black line ;; Remove ugly black line
(set-face-attribute 'vertical-border nil :foreground (set-face-attribute 'vertical-border nil :foreground