Skip to content

Instantly share code, notes, and snippets.

@veirus veirus/base.el
Created Jan 4, 2019

Embed
What would you like to do?
Emacs config
;;; Package --- Summary
;;; Commentary:
;;; General Emacs configuration
;;; Code:
;;; Закрывать *scratch* при запуске.
(kill-buffer "*scratch*")
;; (desktop-save-mode 1)
(fset 'yes-or-no-p 'y-or-n-p)
(global-hl-line-mode 1)
;; IDO plugin {{{1
(require 'ido)
(ido-mode t)
(icomplete-mode t)
(ido-everywhere t)
(setq ido-vitrual-buffers t)
(setq ido-enable-flex-matching t)
;;; show choices vertically
(if (version< emacs-version "25")
(progn
(make-local-variable 'ido-separator)
(setq ido-separator "\n"))
(progn
(make-local-variable 'ido-decorations)
(setf (nth 2 ido-decorations) "\n")))
;; IDO }}}1
;; Inhibit startup/splash screen
(setq inhibit-splash-screen t
inhibit-startup-message t
;; экран приветствия можно вызвать комбинацией C-h C-a
inhibit-startup-echo-area-message t)
;; Doesn't work if splash screen enabled
(setq default-directory "~/")
;; Save backups in specific directory
(setq backup-directory-alist `(("." . "~/.emacs.d/saves")))
;; syntax highlighting
;; (require 'font-lock)
;; включено с версии Emacs-22. Нo на всякий случай:
;; (global-font-lock-mode t)
;; (setq font-lock-maximum-decoration t)
;; Electric-modes settings
;; (electric-pair-mode 1) ;; автозакрытие {},[],() с переводом курсора внутрь скобок
;; (electric-indent-mode -1) ;; отключить индентацию electric-indent-mod'ом (default in Emacs-24.4)
(setq redisplay-dont-pause t) ;; лучшая отрисовка буфера
(setq ring-bell-function 'ignore) ;; отключить звуковой сигнал
(setq display-buffer-reuse-frames t) ;; If a frame alredy opened, use it!
;;; Copy orgmode links
(defun my-yank-org-link (text)
(if (derived-mode-p 'org-mode)
(insert text)
(string-match org-bracket-link-regexp text)
(insert (substring text (match-beginning 1) (match-end 1)))))
(defun my-org-retrieve-url-from-point ()
(interactive)
(let* ((link-info (assoc :link (org-context)))
(text (when link-info
;; org-context seems to return nil if the current element
;; starts at buffer-start or ends at buffer-end
(buffer-substring-no-properties (or (cadr link-info) (point-min))
(or (caddr link-info) (point-max))))))
(if (not text)
(error "Not in org link")
(add-text-properties 0 (length text) '(yank-handler (my-yank-org-link)) text)
(kill-new text))))
(defun my-smarter-kill-ring-save ()
(interactive)
(if (region-active-p)
(call-interactively #'kill-ring-save)
(when (eq major-mode 'org-mode)
(call-interactively #'my-org-retrieve-url-from-point))))
(defalias 'color 'load-theme)
;;; Color themes
;; (use-package dracula-theme
;; :config
;; (load-theme 'dracula-theme t))
;; (use-package zenburn-theme
;; :config
;; (load-theme 'zenburn-theme t))
;; (use-package material-theme
;; :config
;; (load-theme 'material-theme t))
(use-package sublime-themes
:config
;; (add-to-list 'custom-theme-load-path "~/.emacs.d/themes")
(load-theme 'brin))
;; (use-package kaolin-themes
;; :config
;; (load-theme 'kaolin-dark t)
;; (use-package all-the-icons)
;; (kaolin-treemacs-theme))
;; ========================================
;; https://blog.aaronbieber.com/2015/05/24/from-vim-to-emacs-in-fourteen-days.html
(require 'package)
(package-initialize nil)
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/"))
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(add-to-list 'package-archives '("melpa-stable" . "http://stable.melpa.org/packages/"))
(setq package-enable-at-startup nil)
;; ========================================
;; Don't litter my init file
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(load custom-file 'noerror)
;; ========================================
;; Package manager
(unless (package-installed-p 'use-package)
(message "EMACS install use-package.el")
(package-refresh-contents)
(package-install 'use-package))
(eval-when-compile
(require 'use-package))
(setq use-package-always-ensure t)
;; ========================================
;; https://dunmaksim.blogspot.com/2017/07/emacs-use-package.html
;;; Указываем откуда брать части настроек.
(defconst user-init-dir
(cond ((boundp 'user-emacs-directory) user-emacs-directory)
((boundp 'user-init-directory) user-init-directory)
(t "~/.emacs.d/")))
;;; Функция для загрузки настроек из указанного файла.
(defun load-user-file (file)
(interactive "f")
"Load a file in current user's configuration directory"
(load-file (expand-file-name file user-init-dir)))
;;; Части конфигурации. Порядок не имеет принципиального значения,
;;; однако я рекомендую некоторые базовые вещи помещать в начало,
;;; чтобы не было необходимости вспоминать базовые команды EMACS
;;; если в результате улучшения сломается один из базовых конфигов.
(load-user-file "base.el")
(load-user-file "visual.el")
(load-user-file "packages.el")
(load-user-file "colors.el")
(load-user-file "mappings.el")
;; ========================================
;;; mappings.el --- Summary
;;; Commentary:
;;; Custom mappings {{{1
;;; Code:
;; Vim mappings
;; (require 'evil)
;; (evil-mode t)
;; определение клавиатурных комбинаций для внутренних подрежимов org-mode
;; (global-set-key "\C-ca" 'org-agenda)
;; (global-set-key "\C-cb" 'org-iswitchb)
;; (global-set-key "\C-cl" 'org-store-link)
;; font size +-
(global-set-key (kbd "C-+") 'text-scale-increase)
(global-set-key (kbd "C--") 'text-scale-decrease)
;; Quick access to init.el
(defun find-user-init-file ()
"Edit the `user-init-file', in another window."
(interactive)
(find-file-other-window user-init-file))
(global-set-key (kbd "<f12>") 'find-user-init-file)
;; Quick access to recent files
(recentf-mode 1)
(setq recentf-max-menu-items 25)
(global-set-key "\C-x\ \C-r" 'recentf-open-files)
;;; Open at startup
(recentf-open-files)
;; Bind non standard completion
;;(global-set-key "\M- " 'hippie-expand)
;; Custom mappings }}}1
;;; Package --- Summary
;;; Commentary:
;;; Install and configure packages
;;; Code:
(use-package diminish)
;;; Этот модуль отвечает за подсказки и автозавершение. Он новее, чем
;;; autocomplete, и активно развивается. Большая часть плагинов
;;; дополнения сейчас пишется именно под него.
(use-package company
:ensure t
:diminish company-mode
:config (setq company-backends (remove 'company-ropemacs company-backends) company-tooltip-limit
20 company-tooltip-align-annotations t)
(global-company-mode 1))
;; powerline
(use-package powerline
:diminish indent-guide-mode
)
(use-package airline-themes
:requires powerline
:config
(load-theme 'airline-molokai)
(setq
;; powerline-utf-8-separator-left #xe0b0
;; powerline-utf-8-separator-right #xe0b2
;; airline-utf-glyph-separator-left #xe0b0
;; airline-utf-glyph-separator-right #xe0b2
;; airline-utf-glyph-subseparator-left #xe0b1
airline-utf-glyph-subseparator-right #xe0b3
;; airline-utf-glyph-branch #xe0a0
;; airline-utf-glyph-readonly #xe0a2
airline-utf-glyph-linenumber #xe0a1)
)
;;; Иконки в статус-баре
(use-package mode-icons
:config (mode-icons-mode 1))
;;; Показ отступов во всех режимах
(use-package indent-guide
:diminish indent-guide-mode
:config
(indent-guide-global-mode 1))
;;; Дерево отмены
(use-package undo-tree
:diminish undo-tree-mode
:config (global-undo-tree-mode 1))
;;; Цветные скобочки
(use-package rainbow-delimiters
:init (add-hook 'prog-mode-hook #'rainbow-delimiters-mode)
(setq rainbow-delimiters-max-face-count 9))
;;; Evil-mode
(use-package evil
:ensure t
:config
(evil-mode 1)
(use-package evil-leader
:ensure t
:diminish evil-leader-mode
:config
(global-evil-leader-mode)
(evil-leader/set-leader "<SPC>")
(evil-leader/set-key
"e" 'find-file
"b" 'switch-to-buffer
"k" 'kill-buffer
"v" 'exchange-point-and-mark))
(use-package evil-surround
:ensure t
:diminish evil-surround-mode
:config
(global-evil-surround-mode))
(use-package evil-indent-textobject
:ensure t)
(use-package evil-rsi
:ensure t
:diminish evil-rsi-mode
:config
(evil-rsi-mode))
(use-package evil-snipe
:ensure t
:diminish evil-snipe-mode
:config
(evil-snipe-mode +1)
(evil-snipe-override-mode +1)
(setq evil-snipe-scope 'visible
evil-snipe-repeat-scope 'visible
evil-snipe-repeat-keys nil
evil-snipe-use-vim-sneak-bindings 1))
(use-package evil-space
:ensure t)
)
;;; Helm
(use-package helm
:ensure t
:commands helm-mode
:config
(helm-mode 1)
(setq helm-quick-update t
helm-buffers-fuzzy-matching t)
:bind (("C-c v" . helm-show-kill-ring)
("M-x" . helm-M-x)
("C-x C-b" . helm-buffers-list)
("C-x C-f" . helm-find-files)
))
;;; Org-mode {{{
(use-package org
:ensure t
:defer t
:commands (org-capture)
:bind (("C-c c" . org-capture)
("C-c l" . org-store-link)
("C-c a" . org-agenda)
("C-c b" . org-iswitchb)
("C-c y" . my-smarter-kill-ring-save))
:config
(setq show-trailing-whitespace t)
(use-package evil-org
:ensure t
:after org
:config
(add-hook 'org-mode-hook 'evil-org-mode)
(add-hook 'evil-org-mode-hook
(lambda ()
(evil-org-set-key-theme)
(evil-leader/set-key-for-mode 'org-mode
"r" 'org-refile
"n" 'org-add-note)))
(require 'evil-org-agenda)
(evil-org-agenda-set-keys))
;; (use-package org-evil
;; :ensure t
;; :config
;; (evil-define-minor-mode-key 'normal 'org-evil-heading-mode
;; "@" 'org-refile)
;; (evil-define-minor-mode-key 'normal 'org-evil-heading-mode
;; "#" 'org-add-note))
(use-package org-bullets
:ensure t
:config
(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
(setq org-bullets-bullet-list '("")))
;; org-mode END }}}
)
;;; Package --- Summary
;;; Commentary:
;;; Visual settings
;;; Code:
;; Visual stuff {{{1
;;; Transparency
;; (set-frame-parameter (selected-frame) 'alpha '(85 85))
;; (add-to-list 'default-frame-alist '(alpha 85 85))
;;; GUI customizations
(tool-bar-mode -1)
(scroll-bar-mode -1)
;;; Fonts
;;;; (set-face-attribute 'default nil :family "DejaVu Sans Mono for Powerline")
;;;; (set-face-attribute 'default nil :height 120)
;;;; or like this:
(set-face-attribute 'default nil :family "DejaVu Sans Mono for Powerline" :height 120)
;;; Line numbers on the left and column number in the status line
(global-linum-mode t)
(column-number-mode t)
;;; Highlight matching parens
(show-paren-mode t)
;;; Display the name of the current buffer in the title bar
(setq frame-title-format "%b - Emacs")
;;; whitespace display
(global-whitespace-mode)
(setq whitespace-global-modes
'(not magit-mode git-commit-mode))
(setq whitespace-style '(face trailing tabs))
;;; Change cursor color depending on mode
;; https://juanjoalvarez.net/es/detail/2014/sep/19/vim-emacsevil-chaotic-migration-guide/
;; This is something that I liked to have in Vim. Fortunately, you can
;; also have it in Emacs. Unfortunately, I’ve been unable to get in
;; working on non-GUI emacs:
(setq evil-emacs-state-cursor '("red" box))
(setq evil-normal-state-cursor '("green" box))
(setq evil-visual-state-cursor '("orange" box))
(setq evil-insert-state-cursor '("red" bar))
(setq evil-replace-state-cursor '("red" bar))
(setq evil-operator-state-cursor '("red" hollow))
;; Visual stuff }}}1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.