From 7775d2fa80c23631f023590f6331c1d567525d1c Mon Sep 17 00:00:00 2001 From: Andrew Guschin Date: Tue, 26 Nov 2024 20:39:01 +0400 Subject: update config.org Changes: - Add simple welcome screen instead of default one - Move the last unnamed section into Basic config - Optimize startup time by using always-defer in use-package - Add some QoL plugins: docker, vterm, origami, diff-hl, benchmark-init - Fix C-u in evil mode - Add magit-todos plugin - Add web-mode plugin for frontend development and integrate it into lsp-mode - Add treesitter plugin - Add spell checker configuration --- config.org | 209 ++++++++++++++++++++++++++++++++++++++++++++---------- scratch-splash.el | 70 ++++++++++++++++++ 2 files changed, 240 insertions(+), 39 deletions(-) create mode 100644 scratch-splash.el diff --git a/config.org b/config.org index 3222a2e..e6454a8 100644 --- a/config.org +++ b/config.org @@ -4,12 +4,32 @@ * Basic settings +This replaces default Emacs welcome screen with custom simple splash. This is based on some +combination of https://github.com/rougier/emacs-splash and splash screen of +https://github.com/rougier/nano-emacs. Big thanks to original author, but I wanted simple splash +screen that doesn't disappear after I start pressing buttons. + +I also want for this splash screen to be able to respond to window size changes, but for now I like +it as it is. +#+BEGIN_SRC emacs-lisp + (setq inhibit-startup-screen t) + (setq inhibit-startup-message t) + (setq inhibit-startup-echo-area-message t) + (setq initial-scratch-message nil) + (setq initial-buffer-choice nil) + (load-file (expand-file-name "scratch-splash.el" user-emacs-directory)) + (add-hook 'window-setup-hook 'scratch-splash) +#+END_SRC + This starts with some settings that are useful for already initialized configuration. I set up theme first thing so that the default one doesn't blind me at night. Also set up the correct font. #+BEGIN_SRC emacs-lisp (when (package-installed-p 'ayu-theme) (load-theme 'ayu-grey t)) + ;; (when (package-installed-p 'kaolin-themes) + ;; (load-theme 'kaolin-breeze t)) + (add-to-list 'default-frame-alist '(font . "FiraCode Nerd Font 15")) #+END_SRC @@ -28,6 +48,7 @@ Disable more of unneeded app decorations (now for all OSes), enable some nicetie several annoying things. Looks like pixel scrolling works only on macOS. #+BEGIN_SRC emacs-lisp (tool-bar-mode -1) + (scroll-bar-mode -1) (toggle-scroll-bar -1) (xterm-mouse-mode t) (buffer-face-mode t) @@ -42,11 +63,30 @@ several annoying things. Looks like pixel scrolling works only on macOS. #+BEGIN_SRC emacs-lisp (setq-default indent-tabs-mode nil) - (setq-default tab-width 4) + (setq-default tab-width 8) (setq-default c-default-style "bsd") (setq-default c-basic-offset 4) #+END_SRC +#+BEGIN_SRC emacs-lisp + (defun my-backup-file-name (fpath) + "Return a new file path of a given file path. If the new path's + directories does not exist, create them." + (let* ((backupRootDir (expand-file-name "backup" user-emacs-directory)) + (filePath (replace-regexp-in-string "[A-Za-z]:" "" fpath )) ; remove Windows driver letter in path, for example, “C:” + (backupFilePath (replace-regexp-in-string "//" "/" (concat backupRootDir filePath "~") ))) + (make-directory (file-name-directory backupFilePath) (file-name-directory backupFilePath)) + backupFilePath)) + (setq make-backup-file-name-function 'my-backup-file-name) +#+END_SRC + +I don't want this autogenerated code to be added to main config file automatically. Now it will be +placed in its own file and won't annoy me. +#+BEGIN_SRC emacs-lisp + (setq custom-file (expand-file-name "custom.el" user-emacs-directory)) + (load custom-file) +#+END_SRC + * Package management Several packages are not present in GNU ELPA, so I need to add MELPA archive. #+BEGIN_SRC emacs-lisp @@ -57,10 +97,11 @@ Several packages are not present in GNU ELPA, so I need to add MELPA archive. For package management I use use-package with always-ensure flag turned on. That way on new installs this config bootstraps itself. #+BEGIN_SRC emacs-lisp - (setq-default use-package-always-ensure t) (unless (package-installed-p 'use-package) (package-refresh-contents) (package-install 'use-package)) + (setq-default use-package-always-ensure t) + (setq-default use-package-always-defer t) (require 'use-package) #+END_SRC @@ -71,6 +112,23 @@ Install some nice theme. It is loaded in the beginning of the config, so after b should be restarted. Or this theme can be loaded by hand... #+BEGIN_SRC emacs-lisp (use-package ayu-theme) + (use-package kaolin-themes) + (use-package auto-dark + :custom + (auto-dark-themes '((ayu-grey) (kaolin-breeze)))) +#+END_SRC + +** Small plugins +#+BEGIN_SRC emacs-lisp + (use-package adoc-mode) + (use-package docker :bind ("C-c d" . docker)) + (use-package vterm) + (use-package origami :hook ((prog-mode . origami-mode))) + (use-package diff-hl + :hook ((text-mode . diff-hl-mode) + (prog-mode . diff-hl-mode) + (dired-mode . diff-hl-dired-mode))) + (use-package benchmark-init) #+END_SRC ** evil-mode @@ -81,27 +139,46 @@ in insert mode it is not so useful, so this turns on regular numbering for this But in some major modes evil shadows their keymaps, so I set their initial state to emacs's keymaps. #+BEGIN_SRC emacs-lisp + (global-display-line-numbers-mode -1) (use-package evil :config - (evil-mode t) (evil-set-initial-state 'dired-mode 'emacs) (evil-set-initial-state 'eshell-mode 'emacs) (evil-set-initial-state 'shell-mode 'emacs) (evil-set-initial-state 'buffer-menu-mode 'emacs) + (evil-set-initial-state 'fundamental-mode 'emacs) + (define-key universal-argument-map (kbd "C-u") nil) + (define-key evil-motion-state-map (kbd "C-u") 'evil-scroll-up) :hook - (evil-insert-state-entry . (lambda () (setq-local display-line-numbers t))) - :hook - (evil-normal-state-entry . (lambda () (setq-local display-line-numbers 'relative)))) + ((prog-mode . evil-mode) + (text-mode . evil-mode) + (prog-mode . display-line-numbers-mode) + (text-mode . display-line-numbers-mode) + (evil-insert-state-entry . (lambda () (setq-local display-line-numbers t))) + (evil-normal-state-entry . (lambda () (setq-local display-line-numbers 'relative))))) +#+END_SRC - (global-display-line-numbers-mode -1) - (add-hook 'prog-mode-hook - (lambda () (display-line-numbers-mode t))) +I use `C-u` keymap from vim very often, but in emacs it is bound to 'universal argument'. +Universal argument is quite useful in some circumstances, but scrolling is used much more often. +So this remaps universal argument to `C-f`, and scrolling to `C-u`. +#+BEGIN_SRC emacs-lisp + (define-key global-map (kbd "C-f") 'universal-argument) + (define-key universal-argument-map (kbd "C-u") nil) + (define-key universal-argument-map (kbd "C-f") 'universal-argument-more) + (define-key global-map (kbd "C-u") 'kill-whole-line) + (eval-after-load 'evil-maps + '(progn + (define-key evil-motion-state-map (kbd "C-f") nil) + )) #+END_SRC ** magit Just great git client. I don't have any configurations for it yet. #+BEGIN_SRC emacs-lisp (use-package magit) + (use-package magit-todos + :after magit + :config (magit-todos-mode 1)) #+END_SRC ** lisp packages @@ -115,10 +192,15 @@ Just great git client. I don't have any configurations for it yet. #+END_SRC ** exec-path-from-shell +I like to follow XDG Base Directory specification, and have many environment variables for tools, +that don't use XDG directories. To use these tools within Emacs, I need to get some variables, that +are set within my `.profile`. #+BEGIN_SRC emacs-lisp (use-package exec-path-from-shell :config (when (memq window-system '(mac ns x)) + ;; I set up this variable, so that shell would know that it is being executed from emacs, and + ;; not really interactively (setenv "EMACS" "emacs") (setq exec-path-from-shell-variables '("PATH" "CARGO_HOME" "RUSTUP_HOME" "GOPATH" @@ -128,40 +210,89 @@ Just great git client. I don't have any configurations for it yet. #+END_SRC ** LSP +Configuration for some languages that I used in Emacs. Not all the languages that I used, but most +recent ones. If I decide to try something new, or open some old project in Emacs, this config +(probably) will be updated. #+BEGIN_SRC emacs-lisp - (use-package lsp-mode + (use-package lsp-mode + :init + ;; set prefix for lsp-command-keymap (few alternatives - "C-l", "C-c l") + (setq lsp-keymap-prefix "C-l") + (use-package company) + (use-package rust-mode) + (use-package go-mode) + (use-package lsp-java + :custom (setq lsp-java-server-install-dir + (concat (getenv "HOME") "/.local/share/jdtls/"))) + (use-package web-mode) + ;; if you want which-key integration + ;;(lsp-mode . lsp-enable-which-key-integration)) + :hook ((lsp-mode . company-mode) + (rust-mode . lsp) + (go-mode . lsp) + (java-mode . lsp) + (c++-mode . lsp) + (web-mode . lsp)) + :commands lsp + ;; Saved in case I use vue.js with lsp some other time + ;; :custom + ;; (lsp-clients-typescript-plugins + ;; (vector (list :name "@vue/typescript-plugin" + ;; :location (concat (getenv "BUN_INSTALL") + ;; "/install/global/node_modules/@vue/typescript-plugin") + ;; :languages (vector "typescript" "javascript" "vue")))) + ) + (use-package flycheck :hook (after-init . #'global-flyckeck-mode)) + (use-package lsp-ui :commands lsp-ui-mode) + (use-package helm-lsp :commands helm-lsp-workspace-symbol) +#+END_SRC + +Web development tools need more configuration, than most other languages. So all of this +configuration is done inside web-mode, because most web projects are used with multiple language +servers (most of the time with multiple for single buffer, even). +#+BEGIN_SRC emacs-lisp + (use-package web-mode :init - ;; set prefix for lsp-command-keymap (few alternatives - "C-l", "C-c l") - (setq lsp-keymap-prefix "C-c l") - (use-package company :init (company-mode t)) - (use-package rust-mode) - (use-package lsp-java) - (setq lsp-java-server-install-dir - (concat (getenv "HOME") "/.local/share/jdtls/")) - ;; if you want which-key integration - ;;(lsp-mode . lsp-enable-which-key-integration)) - :hook ((rust-mode . lsp) - (java-mode . lsp) - (c++-mode . lsp)) - :commands lsp) - (use-package lsp-ui :commands lsp-ui-mode) - (use-package helm-lsp :commands helm-lsp-workspace-symbol) -#+END_SRC - -* Something + (use-package prettier-js) + (use-package typescript-mode) + (use-package vue-mode) + (use-package svelte-mode) + (use-package lsp-tailwindcss + :after lsp-mode + :init (setq lsp-tailwindcss-add-on-mode t)) + :after lsp-mode + :hook ((web-mode . prettier-js-mode)) + :mode (("\\.ts\\'" . web-mode) + ("\\.js\\'" . web-mode) + ("\\.vue\\'" . web-mode) + ("\\.tsx\\'" . web-mode) + ("\\.jsx\\'" . web-mode)) + :config + (setq web-mode-markup-indent-offset 2) + (setq web-mode-css-indent-offset 2) + (setq web-mode-code-indent-offset 2) + (setq web-mode-script-padding 0) + (setq web-mode-style-padding 0) + (setq web-mode-block-padding 0) + (setq web-mode-content-types-alist + '(("jsx" . "\\.js[x]?\\'")))) +#+END_SRC + +** Tree-sitter #+BEGIN_SRC emacs-lisp - (defun my-backup-file-name (fpath) - "Return a new file path of a given file path. If the new path's - directories does not exist, create them." - (let* ((backupRootDir (expand-file-name "backup" user-emacs-directory)) - (filePath (replace-regexp-in-string "[A-Za-z]:" "" fpath )) ; remove Windows driver letter in path, for example, “C:” - (backupFilePath (replace-regexp-in-string "//" "/" (concat backupRootDir filePath "~") ))) - (make-directory (file-name-directory backupFilePath) (file-name-directory backupFilePath)) - backupFilePath)) - (setq make-backup-file-name-function 'my-backup-file-name) + (use-package tree-sitter + :init + (use-package tree-sitter-langs) + ;; (global-tree-sitter-mode) + :hook (tree-sitter-after-on . tree-sitter-hl-mode)) #+END_SRC +** Spelling #+BEGIN_SRC emacs-lisp - (setq custom-file (expand-file-name "custom.el" user-emacs-directory)) - (load custom-file) + (setq ispell-program-name "hunspell") + (add-hook 'text-mode-hook 'flyspell-mode) + (add-hook 'prog-mode-hook 'flyspell-prog-mode) + (add-hook 'text-mode-hook 'ispell-minor-mode) + (add-hook 'prog-mode-hook 'ispell-minor-mode) #+END_SRC + diff --git a/scratch-splash.el b/scratch-splash.el new file mode 100644 index 0000000..ffa4323 --- /dev/null +++ b/scratch-splash.el @@ -0,0 +1,70 @@ +;; --------------------------------------------------------------------- +;; Copyright (C) 2020 - Nicolas .P Rougier +;; Copyright (C) 2020 - N Λ N O developers +;; +;; 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 3 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, see . +;; --------------------------------------------------------------------- +;; +;; Note: The screen is not shown if there are opened file buffers. For +;; example, if you start emacs with a filename on the command +;; line, the splash screen is not shown. +;; +;; This is based on some combination of: +;; - https://github.com/rougier/nano-emacs +;; - https://github.com/rougier/emacs-splash +(require 'cl-lib) + +(defun scratch-splash () + "Emacs splash screen" + + (interactive) + + (let* ((splash-buffer (get-buffer-create "*splash*")) + (height (round (- (window-body-height nil) 1) )) + (width (round (window-body-width nil) )) + (padding-center (- (/ height 2) 1))) + + ;; If there are buffer associated with filenames, + ;; we don't show the splash screen. + (if (eq 0 (length (cl-loop for buf in (buffer-list) + if (buffer-file-name buf) + collect (buffer-file-name buf)))) + (with-current-buffer splash-buffer + (erase-buffer) + + (setq-local line-spacing 0) + (setq-local vertical-scroll-bar nil) + (setq-local horizontal-scroll-bar nil) + (setq-local fill-column width) + (face-remap-add-relative 'link :underline nil) + + (insert-char ?\n padding-center) + + (insert-text-button " www.gnu.org " + 'action (lambda (_) (browse-url "https://www.gnu.org")) + 'help-echo "Visit www.gnu.org website" + 'follow-link t) + (center-line) (insert "\n") + (insert (concat + (propertize "GNU Emacs" 'face 'bold) + " version " + (format "%d.%d" emacs-major-version emacs-minor-version))) + (center-line) + + (read-only-mode t) + (display-buffer-same-window splash-buffer nil) + ) + ))) + +(provide 'scratch-splash) -- cgit v1.2.3