dotfiles/.config/emacs/core/earnecore-display.el

169 lines
5.3 KiB
EmacsLisp

;;; earnecore-display.el --- Display -*- lexical-binding: t; -*-
;; Copyright (C) 2020-2021 earnest ma
;; SPDX-License-Identifier: MIT
;; Author: earnest ma <me@earne.link>
;;; Code:
;; Misc
(setq frame-title-format (list "%b %* " earnemacs-daemon-name "@" system-name)
truncate-string-ellipsis ""
use-file-dialog nil
use-dialog-box nil)
;; Show column number in modeline
(setq-default column-number-mode t)
;; Font: More set below, this is just in case for the daemon
(add-to-list 'default-frame-alist '(font . "Fira Code 11"))
;; Modeline
(use-package doom-modeline
:demand
:init (doom-modeline-mode 1)
:config
(display-time-mode 1)
(if (equal "Battery status not available"
(battery))
()
(display-battery-mode 1)))
;; Dashboard
(use-package dashboard
:demand
;; Prevent issues when opening through Daemon - will see scratch buffer instead
:if (< (length command-line-args) 2)
:config
(dashboard-setup-startup-hook)
;; Customizations
(setq dashboard-banner-logo-title "Welcome to earnemacs!")
(setq dashboard-startup-banner 'logo)
(setq dashboard-set-footer nil)
(setq dashboard-items
'((recents . 5)
(bookmarks . 5)
(agenda . 5)
(projects . 5))))
;; Tabs
(use-package tab-bar
:straight nil
:bind
(:map tab-prefix-map
("n" . tab-next)
("p" . tab-previous)
("t" . tab-new)
("x" . tab-close)
("X" . tab-close-other)
("C-x" . tab-bar-undo-close-tab))
:general
(earnemacs-spc-def "T" '(:keymap tab-prefix-map :wk "Tab"))
:init
(tab-bar-mode))
;; Scrolling
(setq mouse-wheel-scroll-amount '(2 ((shift) . 1)))
(setq mouse-wheel-progressive-speed nil)
(setq mouse-wheel-follow-mouse 't)
(setq scroll-step 1)
;; Frame opacity
(defun earnemacs-adjust-opacity (frame incr)
"Adjust the background opacity of FRAME by increment INCR.
From purcell/emacs.d"
(unless (display-graphic-p frame)
(error "Cannot adjust opacity of this frame"))
(let* ((oldalpha (or (frame-parameter frame 'alpha) 100))
;; The 'alpha frame param became a pair at some point in
;; emacs 24.x, e.g. (100 100)
(oldalpha (if (listp oldalpha) (car oldalpha) oldalpha))
(newalpha (+ incr oldalpha)))
(when (and (<= frame-alpha-lower-limit newalpha) (>= 100 newalpha))
(modify-frame-parameters frame (list (cons 'alpha newalpha))))))
(earnemacs-spc-def
;; Frame opacity keybindings
"t0" '(:def (lambda () (interactive) (modify-frame-parameters nil
`((alpha . 100))))
:wk "Reset transparency")
"t-" '(:def (lambda () (interactive) (earnemacs-adjust-opacity nil -10))
:wk "Decrease transparency")
"t=" '(:def (lambda () (interactive) (earnemacs-adjust-opacity nil 10))
:wk "Increase transparency"))
;; Increase/ decrease font size
(defun font-name-replace-size (font-name new-size)
(let ((parts (split-string font-name "-")))
(setcar (nthcdr 7 parts) (format "%d" new-size))
(mapconcat 'identity parts "-")))
(defun increment-default-font-height (delta)
"Adjust the default font height by DELTA on every frame.
The pixel size of the frame is kept (approximately) the same.
DELTA should be a multiple of 10, in the units used by the
:height face attribute. From purcell/emacs.d"
(let* ((new-height (+ (face-attribute 'default :height) delta))
(new-point-height (/ new-height 10)))
(dolist (f (frame-list))
(with-selected-frame f
;; Latest 'set-frame-font supports a "frames" arg, but
;; we cater to Emacs 23 by looping instead.
(set-frame-font (font-name-replace-size (face-font 'default)
new-point-height)
t)))
(set-face-attribute 'default nil :height new-height)
(message "default font size is now %d" new-point-height)))
;; Functions, keybindings for size
(defun increase-default-font-height ()
(interactive)
(increment-default-font-height 10))
(defun decrease-default-font-height ()
(interactive)
(increment-default-font-height -10))
(earnemacs-spc-def
;; -/+ zooms in/out using `text-scale-...'
"z0" 'text-scale-adjust
"z-" 'text-scale-decrease
"z=" 'text-scale-increase
;; Shift -/+ increases the default font height
"z+" 'increase-default-font-height
"z_" 'decrease-default-font-height)
;; -
;; Setup font/ transparency/ display of frame
(defun earnemacs--frame-hook ()
"Font and transparency settings. This is in a hook because Emacs doesn't
really like setting fonts/ transparency when run through a daemon."
(if (not (null earnemacs-transparent-frame))
(modify-all-frames-parameters `((alpha . 95))))
(set-face-attribute 'default nil
:font "Fira Code"
:height earnemacs-default-face-height)
(set-face-attribute 'fixed-pitch nil
:font "Fira Code"
:height earnemacs-fixed-face-height)
(set-face-attribute 'variable-pitch nil
:font "FiraGO"
:height earnemacs-variable-face-height))
;; Run earnemacs--frame-hook, if daemon nothing will happen, but the hook will
;; set everything when it needs to.
(earnemacs--frame-hook)
(add-hook 'server-after-make-frame-hook 'earnemacs--frame-hook)
;; Give focus when a new client frame is created
(add-hook 'server-after-make-frame-hook
(lambda () (select-frame-set-input-focus (selected-frame))))
(provide 'earnecore-display)
;;; earnecore-display.el ends here