summaryrefslogtreecommitdiff
path: root/config.org
blob: a082f4820878ac4bdda026fc08bcce404ebb5cbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#+TITLE: My configuration
#+AUTHOR: Andrew Guschin
#+PROPERTY: tangle yes

* Basic settings

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))

  (add-to-list 'default-frame-alist
               '(font . "FiraCode Nerd Font 15"))
#+END_SRC

Menu bar looks okay in macOS because it's contained in global menu bar of OS for focused window.
I'd say that bar without application's menu looks strange on macOS. On linux menu is attached to
every client, so this doesn't look that good, so it better be turned off.
#+BEGIN_SRC emacs-lisp
  (when (eq system-type 'gnu/linux)
    (menu-bar-mode -1))
  (when (eq system-type 'darwin)
    (menu-bar-mode t))
#+END_SRC

Disable more of unneeded app decorations (now for all OSes), enable some niceties, and disable
several annoying things. Looks like pixel scrolling works only on macOS.
#+BEGIN_SRC emacs-lisp
  (tool-bar-mode -1)
  (toggle-scroll-bar -1)
  (xterm-mouse-mode t)
  (buffer-face-mode t)
  (pixel-scroll-precision-mode t)
  (setq frame-resize-pixelwise t)
  (setq-default fill-column 100)
  (global-display-fill-column-indicator-mode t)
  (global-set-key (kbd "C-<wheel-up>") 'ignore)
  (global-set-key (kbd "C-<wheel-down>") 'ignore)
  (setq ring-bell-function 'ignore)
#+END_SRC

#+BEGIN_SRC emacs-lisp
  (setq-default indent-tabs-mode nil)
  (setq-default tab-width 4)
  (setq-default c-default-style "bsd")
  (setq-default c-basic-offset 4)
#+END_SRC

* Package management
Several packages are not present in GNU ELPA, so I need to add MELPA archive.
#+BEGIN_SRC emacs-lisp
  (add-to-list 'package-archives
               '("melpa" . "https://melpa.org/packages/") t)
#+END_SRC

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))
  (require 'use-package)
#+END_SRC

* Plugins

** Theme
Install some nice theme. It is loaded in the beginning of the config, so after bootstrapping emacs
should be restarted. Or this theme can be loaded by hand...
#+BEGIN_SRC emacs-lisp
  (use-package ayu-theme)
#+END_SRC

** evil-mode
Emacs is great operating system that doesn't have good editor.

It is useful to enable relative numbering of lines in normal state, for easier use of motions. But
in insert mode it is not so useful, so this turns on regular numbering for this mode.
#+BEGIN_SRC emacs-lisp
  (use-package evil
    :hook
    (evil-insert-state-entry . (lambda () (setq display-line-numbers t)))
    :hook
    (evil-normal-state-entry . (lambda () (setq display-line-numbers 'relative)))
    :config
    (evil-mode 1))
  (add-hook 'prog-mode-hook
            (lambda () (display-line-numbers-mode t)))
#+END_SRC

** magit
Just great git client. I don't have any configurations for it yet.
#+BEGIN_SRC emacs-lisp
  (use-package magit)
#+END_SRC

** lisp packages
#+BEGIN_SRC emacs-lisp
  (use-package paredit
    :hook
    (emacs-lisp-mode . paredit-mode))
  (use-package rainbow-delimiters
    :hook
    (emacs-lisp-mode . rainbow-delimiters-mode))
#+END_SRC

** exec-path-from-shell
#+BEGIN_SRC emacs-lisp
  (use-package exec-path-from-shell
    :config
    (when (memq window-system '(mac ns x))
      (setenv "EMACS" "emacs")
      (setq exec-path-from-shell-variables
            '("PATH" "CARGO_HOME" "RUSTUP_HOME" "GOPATH"
              "RYE_HOME" "NPM_CONFIG_USERCONFIG"
              "STACK_ROOT" "GHCUP_USE_XDG_DIRS"))
      (exec-path-from-shell-initialize)))
#+END_SRC

** LSP
#+BEGIN_SRC emacs-lisp
  (use-package lsp-mode
    :init
    ;; set prefix for lsp-command-keymap (few alternatives - "C-l", "C-c l")
    (setq lsp-keymap-prefix "C-c l")
    (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
#+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

#+BEGIN_SRC emacs-lisp
  (setq custom-file (expand-file-name "custom.el" user-emacs-directory))
  (load custom-file)
#+END_SRC