Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anuvyklack/emacs
https://github.com/anuvyklack/emacs
Last synced: 9 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/anuvyklack/emacs
- Owner: anuvyklack
- Created: 2020-09-01T18:45:37.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-09-01T18:58:50.000Z (over 4 years ago)
- Last Synced: 2024-10-29T21:13:23.809Z (about 2 months ago)
- Language: Emacs Lisp
- Size: 15.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
Awesome Lists containing this project
README
# -*- evil-shift-width: 2; fill-column: 80; comment-column: 75; -*-
#+title: Emacs configuration with Org Mode
#+author: Yuriy Artemyev
#+email: [email protected]
#+startup: content
#+property: header-args :tangle "./init.el" :results silent
# :tangle (identity user-init-file)
* =init.el= preamble
Good Emacs Lisp file starts with such commentary:#+begin_src emacs-lisp
;;; init.el --- Emacs main configuration file -*- lexical-binding: t; buffer-read-only: t; no-byte-compile: t -*-
;;;
;;; Commentary:
;;; Emacs config by Yuriy Artemyev.
;;; This file was automatically generated by `org-babel-tangle'.
;;; Do not change this file. Main config is located in .config/emacs/README.org
;;;
;;; Code:
#+end_src* =early-init.el=
:properties:
:header-args+: :tangle "./early-init.el"
:end:
These settings are going into different init file: =earli-init.el=.
We are going to use some speedup tricks from [[https://github.com/hlissner/doom-emacs][doom-emacs]] here.
** Preamble#+begin_src emacs-lisp
;;; early-init.el --- early configurations -*- lexical-binding: t; buffer-read-only: t; no-byte-compile: t -*-
;;;
;;; Commentary:
;;; Emacs confi by Andrey Orst.
;;; This file was automatically generated by `org-babel-tangle'.
;;; Do not change this file. Main config is located in .config/emacs/README.org
;;;
;;; Code:
#+end_src** COMMENT Garbage Collection
The main problem with Emacs startup is garbage collection system. It
is invoked so many times on startup that it causes quite big impact on
startup time. We're talking /seconds/. One can raise limit when to
trigger garbage collection, but this will end up in unpleasant editing
experience. So I'm declaring these variables to store default values
for the GC, to restore them after initialization is finished:#+begin_src emacs-lisp
(defvar aorst--gc-cons-threshold gc-cons-threshold)
(defvar aorst--gc-cons-percentage gc-cons-percentage)
(defvar aorst--file-name-handler-alist file-name-handler-alist)
#+end_srcNow we can tweak CG. We need to raise threshold to prevent it running:
#+begin_src emacs-lisp
(setq-default gc-cons-threshold 402653184
gc-cons-percentage 0.6
inhibit-compacting-font-caches t
message-log-max 16384
file-name-handler-alist nil)
#+End_srcThen we need a hook that restores initial values once initialization
done:#+begin_src emacs-lisp
(add-hook 'after-init-hook
(lambda ()
(setq gc-cons-threshold aorst--gc-cons-threshold
gc-cons-percentage aorst--gc-cons-percentage
file-name-handler-alist aorst--file-name-handler-alist)))
#+end_src** Native Compiled Emacs Lisp
There's a very interesting project that I'm currently using, called [[http://akrl.sdf.org/gccemacs.html][gccemacs]].
It provides a way to compile Emacs Lisp into native code, thus making Emacs
much more robust and snappy. In order to compile everything that Emacs loads
asynchronously we can set this variable to =true=.#+begin_src emacs-lisp
(defvar comp-deferred-compilation)
(setq comp-deferred-compilation t)
#+end_srcThis way I can compile Emacs from source as I usually do, and then continue
using it as normal, and Emacs will do it's native compilation in background
for every loaded package. That's amazing!** =straight.el= and =use-package=
Straight is an alternative way to manage package installations. It is
a purely functional package manager. It installs packages from Git
repositories listed on ELPA and MELPA, or from Git URL.=Straight.el= settings:
#+begin_src emacs-lisp
(custom-set-variables
'(straight-repository-branch "develop")
'(straight-check-for-modifications '(check-on-save find-when-checking))
'(straight-vc-git-default-clone-depth 1)
;; '(straight-use-package-by-default t)
)
#+end_srcBootstrap =Straight.el=:
#+begin_src emacs-lisp
(defvar bootstrap-version)
(defvar straight-repository-branch)
(setq straight-repository-branch "develop")
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
#+end_srcNow we can install =use-package= with it:
#+begin_src emacs-lisp
(straight-use-package 'use-package)
#+end_src#+begin_src emacs-lisp
;; (setq use-package-always-defer t
;; ;; use-package-minimum-reported-time .001
;; ;; use-package-verbose t
;; ;; use-package-compute-statistics t
;; )
#+end_src** Garbage Collector Magic Hack
[[https://gitlab.com/koral/gcmh][Source]]#+begin_src emacs-lisp
(use-package gcmh
:straight t
:init
(gcmh-mode 1))
#+end_src** COMMENT User Interface AORST
Prevent the glimpse of un-styled Emacs by disabling these UI elements
early.#+begin_src emacs-lisp
(setq initial-frame-alist '((width . 170)
(height . 56)
(tool-bar-lines . 0)
(left-fringe . 0)
(right-fringe . 0)
(bottom-divider-width . 0)
(right-divider-width . 1))
default-frame-alist initial-frame-alist)
#+end_srcResizing frame is also expensive so we inhibit it, and latest patch to
Emacs introduced =x-gtk-resize-child-frames= variable that fixes the
issue with child frames not being resized correctly under GNOME
Shell, so let's set it to =resize-mode=.#+begin_src emacs-lisp
(setq frame-inhibit-implied-resize t
x-gtk-resize-child-frames 'resize-mode)
#+end_src** COMMENT Visual settings old
Arbitrary frame size and position.
Useful functions:
- set-frame-height
- set-frame-width
- set-frame-size
- set-frame-position#+begin_src emacs-lisp
(when window-system
(set-frame-size (selected-frame) 120 35)
(set-frame-position (selected-frame) 100 70))(setq scroll-preserve-screen-position nil)
;; ;; Set size parameters of ‘initial-frame-alist’ or
;; ;; ‘default-frame-alist’. E.g.,
;; (add-to-list 'default-frame-alist '(height . 24))
;; (add-to-list 'default-frame-alist '(width . 80));; (set-frame-font "Liga Inconsolata LGC NF-10.6")
;; (set-frame-font "Liga Inconsolata LGC NF OT-10.5");; (set-frame-font "PragmataPro-11.5")
(set-frame-font "PragmataPro Mono-11.7:antialias=subpixel")
;; (set-frame-font "PragmataPro Mono-11.7:antialias=natural")
;; (set-frame-font "Pragmata Pro Mono-11.7:antialias=natural");; (set-frame-font "Symbola-11.7")
;; set-fontset-font
;; (set-frame-font "Victor Mono-10.7")
;; (set-frame-font "Operator Mono-11.5")
;; (set-frame-font "Input-11.5")
;; (set-frame-font "Fira Code-10.7")(setq-default frame-background-mode 'dark)
(setq frame-resize-pixelwise t)
;; ;; Fullscreen by default, as early as possible.
;; (add-to-list 'default-frame-alist '(fullscreen . maximized));; Disable otiose GUI settings: they just waste space.
;; fringe-mode is especially ruinous performance-wise.
(when (window-system)
(tool-bar-mode -1)
(menu-bar-mode -1)
(scroll-bar-mode -1)
(tooltip-mode -1)
;; (fringe-mode 10) ;; Margin from the frame in pixels
(fringe-mode -1) ;; Margin from the frame in pixels
(blink-cursor-mode -1)
);; (global-linum-mode t) ;; show line numbers
;; (global-hl-line-mode) ;; highlight the line with cursor
;; Say to Emacs that it should split frame vertically rather than
;; horizontally when Emacs has the choice (eg when bringing up help).
(setq split-height-threshold nil)
;; How many columns emacs should have in a frame to split a window
;; vertically but not horizontally.
(setq split-width-threshold 150)(add-to-list 'display-buffer-alist
;; '("*Help*" display-buffer-same-window)
;; Open *Help* buffers into vertical split on the left
'("*Help"
(display-buffer-reuse-window display-buffer-in-side-window)
(side . left)
(slot . 1)
(window-width . 0.5)
(reusable-frames . nil))
)
#+end_src** Early =package.el= settings
=package.el= initialization is expensive so we disable it at startup:#+begin_src emacs-lisp
(setq package-enable-at-startup nil)
#+end_src** ~(provide 'early-init)~
This concludes the =early-init.el= file.#+begin_src emacs-lisp
(provide 'early-init)
;;; early-init.el ends here
#+end_src** COMMENT Loading =early-init.el= in Emacs 26 and earlier
:properties:
:header-args+: :tangle "./init.el"
:end:
Before Emacs 27 there were no such thing as =eraly-init.el=, so if I
will use older Emacs with this configuration it will miss settings
that are done there. This code manually loads this file in such case:#+begin_src emacs-lisp
(unless (featurep 'early-init)
(message "not early-init")
(load (expand-file-name "early-init" user-emacs-directory)))
#+end_src* Variables
#+begin_src emacs-lisp
(setq init-file (expand-file-name "init.el" user-emacs-directory)
config-org-file (expand-file-name "README.org" user-emacs-directory))
#+end_src* User Interface
Arbitrary frame size and position. Use functions `set-frame-height`,
`set-frame-width`, `set-frame-size`, and `set-frame-position`.#+begin_src emacs-lisp
(when window-system
;; (set-frame-size (selected-frame) 92 35)
(set-frame-size (selected-frame) 145 53)
(set-frame-position (selected-frame) 500 70)
);; ;; Set size parameters of ‘initial-frame-alist’ or
;; ;; ‘default-frame-alist’. E.g.,
;; (add-to-list 'default-frame-alist '(height . 24))
;; (add-to-list 'default-frame-alist '(width . 80));; Iosevka is my font of choice, but don't freak out if it's present.
;; (ignore-errors (set-frame-font "Iosevka-13"))
(set-frame-font "Liga Inconsolata LGC NF OT-12.0")
;; (set-frame-font "PragmataPro-10.5");; (setq-default frame-background-mode 'dark)
;;
;; (setq frame-resize-pixelwise t)
;;
;; ;; ;; Fullscreen by default, as early as possible.
;; ;; (add-to-list 'default-frame-alist '(fullscreen . maximized))
;;
;; ;; Disable otiose GUI settings: they just waste space.
;; ;; fringe-mode is especially ruinous performance-wise.
;; (when (window-system)
;; (tool-bar-mode -1)
;; (menu-bar-mode -1)
;; (scroll-bar-mode -1)
;; (tooltip-mode -1)
;; ;; (fringe-mode 10) ;; Margin from the frame in pixels
;; (fringe-mode -1) ;; Margin from the frame in pixels
;; (blink-cursor-mode -1)
;; )
;;
;; ;; (global-linum-mode t) ;; show line numbers
;;
;; ;; (global-hl-line-mode) ;; highlight the line with cursor
;;
;; ;; Say to Emacs that it should split frame vertically rather than
;; ;; horizontally when Emacs has the choice (eg when bringing up help).
;; (setq split-height-threshold nil)
;; ;; How many columns emacs should have in a frame to split a window
;; ;; vertically but not horizontally.
;; (setq split-width-threshold 150)
;;
;; (add-to-list 'display-buffer-alist
;; ;; '("*Help*" display-buffer-same-window)
;; ;; Open *Help* buffers into vertical split on the left
;; '("*Help"
;; (display-buffer-reuse-window display-buffer-in-side-window)
;; (side . left)
;; (slot . 1)
;; (window-width . 0.5)
;; (reusable-frames . nil))
;; )
#+end_src* Customize
Store customize settgins in separate file.#+begin_src emacs-lisp
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(when (file-exists-p custom-file) (load custom-file))
#+end_src* General settings
Better-defaults:
#+begin_src emacs-lisp
(use-package better-defaults
:straight t)
#+end_src#+begin_src emacs-lisp
(setq-default indent-tabs-mode nil ; no tab characters in files
tab-width 4
comment-empty-lines t ; comment empty lines
;; При обращении к файлу уже открытому в буфере Emacs-а
;; по другому имени (по символической или жёсткой
;; ссылке), Emacs откроет уже существующий буфер, а не
;; создасть новый.
find-file-existing-other-name t
;; delete-indentation t
)
#+end_src* Libraries
** emacs-async
[[https://github.com/jwiegley/emacs-async][Source]]
=async.el= is a module for doing asynchronous processing in Emacs.#+begin_src emacs-lisp
(use-package async
:straight t)
#+end_src* Color themes
** Doom-themes#+begin_src emacs-lisp
(use-package doom-themes
:straight t
:config
;; Global settings (defaults)
(setq
doom-themes-enable-bold nil ; if nil, bold is universally disabled
doom-themes-enable-italic t) ; if nil, italics is universally disabled
(load-theme 'doom-one t)
;; (load-theme 'doom-gruvbox t)
;; (load-theme 'doom-material t)
;; (load-theme 'doom-peacoc t)
;; (load-theme 'doom-nova t)
)
#+end_src** COMMENT Tron
#+begin_src emacs-lisp
(use-package tron-legacy-theme
:straight t
:config
(setq tron-legacy-theme-vivid-cursor t)
(setq tron-legacy-theme-softer-bg t)
(load-theme 'tron-legacy t)
)
#+end_srcChange comment color:
#+begin_src emacs-lisp
(custom-theme-set-faces
'tron-legacy
'(font-lock-comment-face ((t (:foreground "#758b9c" :slant normal))))
;; '(font-lock-comment-face ((t (:foreground "#758b9c" :slant italic))))
;; '(font-lock-comment-face ((t (:foreground "#6a8193" :slant italic))))
)
#+end_src** COMMENT Afternoon
#+begin_src emacs-lisp
(use-package afternoon-theme
:straight (:depth 1)
:config
(load-theme 'afternoon t)
)
#+end_src** COMMENT Elemental-theme
#+begin_src emacs-lisp
(use-package elemental-theme
:straight (:host github :repo "zk-phi/elemental-theme"))
#+end_src** COMMENT Gruvbox
#+begin_src emacs-lisp
(use-package gruvbox-theme
:straight t
:config
;; (load-theme 'gruvbox t)
;; (load-theme 'gruvbox-dark-soft t)
(load-theme 'gruvbox-dark-hard t)
)
#+end_src** COMMENT One Dark
#+begin_src emacs-lisp
(use-package atom-one-dark-theme
:straight t
:config
(load-theme 'atom-one-dark t))
#+end_srcChange comment color:
#+begin_src emacs-lisp
(custom-theme-set-faces
'atom-one-dark
'(font-lock-comment-face ((t (:foreground "#758b9c" :slant normal))))
;; '(font-lock-comment-face ((t (:foreground "#758b9c" :slant italic))))
;; '(font-lock-comment-face ((t (:foreground "#6a8193" :slant italic))))
)
#+end_src** COMMENT Zerodark
#+begin_src emacs-lisp
(use-package zerodark-theme
:straight t
:config
(load-theme 'zerodark t)
;; Optionally setup the modeline
(zerodark-setup-modeline-format)
)
#+end_src** COMMENT Srcery
#+begin_src emacs-lisp
(use-package srcery-theme
:straight t
:config
(load-theme 'srcery t)
)
#+end_src** COMMENT Nord
#+begin_src emacs-lisp
(use-package nord-theme
:straight t
:config
(load-theme 'nord t)
)
#+end_src* Filetypes (Major-modes)
** Emacs-lisp
My emacs lisp mode settings.#+begin_src emacs-lisp
(add-hook 'emacs-lisp-mode-hook
(lambda ()
(setq lisp-indent-offset 2
evil-shift-width lisp-indent-offset)
)
)
#+end_src** COMMENT Python
#+begin_src emacs-lisp
(add-hook 'python-mode-hook
(lambda ()
;; (setq python-indent-offset 4)
(setq indent-tabs-mode nil
tab-width 4 ;; how many spaces show in TAB character
tab-stop-list 4
evil-shift-width 4)
)
)
#+end_src** COMMENT Text-mode
[[https://stackoverflow.com/questions/69934/set-4-space-indent-in-emacs-in-text-mode][Source]]#+begin_src emacs-lisp
(add-hook 'text-mode-hook
(lambda ()
(abbrev-mode 1)
(auto-fill-mode 1)
(setq tab-stop-list (number-sequence 4 200 4))))
#+end_src* Evil
** Evil itself#+begin_src emacs-lisp
(use-package evil
:straight (:depth 1)
:init ;; tweak evil's configuration before loading it
(setq evil-search-module 'evil-search)
(setq evil-ex-complete-emacs-commands nil)
(setq evil-vsplit-window-right t)
(setq evil-split-window-below t)
(setq evil-shift-round nil)
(setq evil-want-C-u-scroll t)
(setq evil-want-keybinding nil)
;; (setq evil-want-integration nil)
:config ;; tweak evil after loading it
(evil-mode 1);; example how to map a command in normal mode (called 'normal state' in evil)
(define-key evil-normal-state-map (kbd ", w") 'evil-window-vsplit)
)
#+end_src** evil-collection
#+begin_src emacs-lisp
(use-package evil-collection
:straight (:depth 1)
:after evil
;; :straight (drag-stuff :type git :host github :repo "rejeep/drag-stuff.el"
;; :fork (:host github
;; :repo "your-name/el-patch")))
:config
(evil-collection-init))
#+end_src** evil-commentary
Use =gc{motion}= to comment target or =gcc= to comment line.
#+begin_src emacs-lisp
(use-package evil-commentary
:straight (:depth 1)
:after evil
:config
(evil-commentary-mode)
)
#+end_src** evil-org-mode
#+begin_src emacs-lisp
(use-package evil-org
:straight (:depth 1)
:after org
:config
(add-hook 'org-mode-hook 'evil-org-mode)
(add-hook 'evil-org-mode-hook
(lambda () (evil-org-set-key-theme)))
(require 'evil-org-agenda)
(evil-org-agenda-set-keys)
;; (setq org-special-ctrl-a/e t)(with-eval-after-load 'evil-maps
;; (define-key evil-motion-state-map (kbd "SPC") nil)
(define-key evil-motion-state-map (kbd "RET") nil) ; отменить привязку клавиши Enter в evil-mode.
;; (define-key evil-motion-state-map (kbd "TAB") nil)
)
)
#+end_src** Surround
#+begin_src emacs-lisp
(use-package evil-surround
:straight t
:after evil
:config
(global-evil-surround-mode 1))
#+end_src* Plugins
** Org-mode
*** Org-mode as major mode settingsEmacs settings which will be enabled only when org-mode will be set as a buffer
major mode:#+begin_src emacs-lisp
(add-hook 'org-mode-hook
(lambda ()
(setq fill-column 80) ;; set textwidth to 80;; Включить автоматический пренос строк (auto fill mode).
;; When enabled `auto-fill-function` variable is not nil.
;; The same as: (auto-fill-mode 1).
(turn-on-auto-fill)
)
)
#+end_src*** Org-mode settings for it self
Source code block indentation / editing / syntax highlighting:
Use ~:custom~ instead of ~setq~ in ~:config~, since the former doesn't require
package.#+begin_src emacs-lisp
(use-package org
:straight (:type built-in)
;; :init
:custom
;; ------------------- Appearance (Внешний вид) -------------------------
;; Turn on ‘org-indent-mode’ on startup, which softly indent text
;; according to outline structure.
(org-startup-indented t);; See also "org-indent.el" which does level-dependent indentation in a
;; virtual way, i.e. at display time in Emacs.
(org-adapt-indentation nil)
;; WARNING: Seams it doesn't work with ‘org-startup-indented’.
(org-odd-levels-only t);; Скрывать символы разметки такие как '*..*' чтобы отображать текст
;; жирным, или '~..~' для кода и т.д.
(org-hide-emphasis-markers nil)(org-tags-column -75) ;; Прижимать тэги с 75 колонке справа.
;; The maximum level for Imenu access to Org headlines.
(org-imenu-depth 20);; Show inline images by default in org-mode
(org-startup-with-inline-images t)
(org-image-actual-width '(400));; ;; Строка, которая будет использована для обозначения свёрнугото блока
;; ;; текста. По умолчанию -- три точки.
;; (org-ellipsis "↴") ;; ↴, ▼, ▶, ⤵
;; ----------------------------------------------------------------------;; --------------------- Source code blocks ----------------------------
(org-src-fontify-natively t) ;; Fontify code in code blocks.;; Edit src block buffer to the right of the current window, keeping all
;; other windows.
(org-src-window-setup 'split-window-right)
;; (org-src-window-setup 'current-window) ;; edit in current window;; WARNING: It seems that this variable has been removed in current
;; versions of org-mode.
;; If non-nil, blank lines are removed when exiting the code edit buffer.
(org-src-strip-leading-and-trailing-blank-lines t);; Put two spaces additional to indentation at the beginning
;; of the line in source blocks.
(org-edit-src-content-indentation 2)
(org-src-preserve-indentation nil);; If non-nil, the effect of TAB in a code block is as if it were
;; issued in the language major mode buffer.
(org-src-tab-acts-natively t)
;; ----------------------------------------------------------------------;; ---------------------------- Links -----------------------------------
;; Enter откроет сслыку при условии, что курсор находится на ней.
;; Follow org links by press Enter with point on it.
(org-return-follows-link t);; ;; Follow org links by press Tab with point on it.
;; (org-tab-follows-link t)
;; ----------------------------------------------------------------------:config
;; Languages which can be evaluated in Org buffers.
(org-babel-do-load-languages 'org-babel-load-languages '((python . t)
(emacs-lisp . t)
(shell . t)))
:hook
;; (org-mode . prettify-symbols-mode)
;; (org-mode . (lambda () (setq prettify-symbols-alist
;; '(("[ ]" . "☐")
;; ("[X]" . "☑") ;; ✔
;; ("[-]" . "◿"))))) ;; ◪, ⬔
(org-babel-after-execute . org-redisplay-inline-images))
#+end_srcOrg 9.2 introduced a new template expansion mechanism, combining
~org-insert-structure-template~ bound to =C-c C-,=. The previous
~easy-templates~ mechanism (=