Nice-i-fied emacs init file.

This commit is contained in:
tastytea 2019-03-22 09:03:23 +01:00
parent 7627103cba
commit cae46baae8
2 changed files with 145 additions and 138 deletions

281
init.el
View File

@ -1,5 +1,5 @@
;;; init.el --- tastytea's Emacs init file. ;;; init.el --- tastytea's Emacs init file.
;;; Time-stamp: <2019-03-22 07:40:06 CET> ;;; Time-stamp: <2019-03-22 09:02:46 CET>
;;; Commentary: ;;; Commentary:
;;; I am using this file with Emacs 26, but most of it will probably work with ;;; I am using this file with Emacs 26, but most of it will probably work with
@ -14,10 +14,10 @@
'("melpa" . "https://melpa.org/packages/") t) '("melpa" . "https://melpa.org/packages/") t)
(package-initialize) (package-initialize)
;; Add path for custom packages ;; Add path for custom packages.
(add-to-list 'load-path "~/.emacs.d/custom-packages/") (add-to-list 'load-path "~/.emacs.d/custom-packages/")
;; Install use-package if necessary ;; Install use-package if necessary.
(unless (package-installed-p 'use-package) (unless (package-installed-p 'use-package)
(package-refresh-contents) (package-refresh-contents)
(package-install 'use-package)) (package-install 'use-package))
@ -25,67 +25,69 @@
(eval-when-compile (eval-when-compile
(require 'use-package)) (require 'use-package))
;; Always install packages if they are not present ;; Always install packages if they are not present.
(require 'use-package-ensure) (require 'use-package-ensure)
(setq use-package-always-ensure t) (setq use-package-always-ensure t)
;; autocompile files as needed. ;; autocompile files as needed.
(use-package auto-compile (use-package auto-compile
:init :init
;; Use uncompiled file if it is newer than the compiled one ;; Use uncompiled file if it is newer than the compiled one.
(setq load-prefer-newer t) (setq load-prefer-newer t)
:config :config
(auto-compile-on-load-mode)) (auto-compile-on-load-mode))
;; ;; Benchmark initialization ;; ;; Benchmark for startup-file.
;; (use-package benchmark-init ;; (use-package benchmark-init
;; :config ;; :config
;; ;; To disable collection of benchmark data after init is done. ;; ;; To disable collection of benchmark data after init is done.
;; (add-hook 'after-init-hook 'benchmark-init/deactivate)) ;; (add-hook 'after-init-hook 'benchmark-init/deactivate))
;; Update packages if at least auto-package-update-interval (7) days have passed ;; Update packages if at least 7 days have passed.
(use-package auto-package-update (use-package auto-package-update
:custom
(auto-package-update-delete-old-versions t)
(auto-package-update-interval 7)
(auto-package-update-hide-results nil)
:config :config
(setq auto-package-update-delete-old-versions t)
;; (setq auto-package-update-hide-results t)
(auto-package-update-maybe)) (auto-package-update-maybe))
;;;;;;;;;;;;;;;;;;;; Global variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;; Global variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Determine if we run on a slow computer ;; Determine if we run on a slow computer.
(defvar slow-computer nil) (defvar slow-computer nil)
(if (member (system-name) '("steuerbeamter" "azimuth" "localhost")) (if (member (system-name) '("steuerbeamter" "azimuth" "localhost"))
(setq slow-computer t)) ; localhost is schnibble (setq slow-computer t)) ; localhost is schnibble
;;;;;;;;;;;;;;;;;;;; Configure some essential things ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;; Configure some essential things ;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Set garbage collection threshold to 100 MiB (or 20 MiB) to speed up init ;; Set garbage collection threshold to 100 MiB (or 20 MiB) to speed up init.
;; It is reset at the end of the file ;; It is reset at the end of the file.
(if slow-computer (if slow-computer
(setq gc-cons-threshold (* 20 1024 1024)) (setq gc-cons-threshold (* 20 1024 1024))
(setq gc-cons-threshold (* 100 1024 1024))) (setq gc-cons-threshold (* 100 1024 1024)))
;; Accelerate startup by not printing so much ;; Accelerate startup by not printing so much.
(setf inhibit-startup-screen t (setf inhibit-startup-screen t
inhibit-startup-echo-area-message t inhibit-startup-echo-area-message t
inhibit-startup-message t) inhibit-startup-message t)
;; Just type y/n instead of yes/no when prompted ;; Just type y/n instead of yes/no when prompted.
(defalias 'yes-or-no-p 'y-or-n-p) (defalias 'yes-or-no-p 'y-or-n-p)
;; Hide toolbar ;; Hide toolbar.
(tool-bar-mode -1) (tool-bar-mode -1)
;; Save cursor position ;; Save cursor position.
(use-package saveplace (use-package saveplace
:config :config
(save-place-mode t)) (save-place-mode t))
;; Delete selection when you start to write ;; Delete selection when you start to write.
(delete-selection-mode t) (delete-selection-mode t)
;; Save minibuffer history ;; Save minibuffer history.
(savehist-mode t) (savehist-mode t)
;; Save backups in ~/.emacs.d/ and keep more versions ;; Save backups in ~/.emacs.d/ and keep more versions.
(setq backup-directory-alist (setq backup-directory-alist
`(("." . ,(concat user-emacs-directory "backups")))) `(("." . ,(concat user-emacs-directory "backups"))))
(setq delete-old-versions t (setq delete-old-versions t
@ -93,16 +95,12 @@
;; kept-old-versions 2 ;; kept-old-versions 2
version-control t) version-control t)
;; ;; Needed for do-all-symbols ;; Set some personal information.
;; (use-package cl) (setq user-full-name "tastytea"
;; Personal information
(setq user-login-name "tastytea"
user-full-name "tastytea"
user-mail-address "tastytea@tastytea.de") user-mail-address "tastytea@tastytea.de")
;; kill-region (cut) and kill-ring-save (copy) act on the current line if no ;; kill-region (cut) and kill-ring-save (copy) act on the current line if no
;; text is visually selected ;; text is visually selected.
;; https://www.emacswiki.org/emacs/WholeLineOrRegion ;; https://www.emacswiki.org/emacs/WholeLineOrRegion
(put 'kill-ring-save 'interactive-form (put 'kill-ring-save 'interactive-form
'(interactive '(interactive
@ -116,13 +114,13 @@
(list (region-beginning) (region-end)) (list (region-beginning) (region-end))
(list (line-beginning-position) (line-beginning-position 2))))) (list (line-beginning-position) (line-beginning-position 2)))))
;; Banish customizations to another file ;; Banish customizations to another file.
(setq custom-file (concat user-emacs-directory "custom.el")) (setq custom-file (concat user-emacs-directory "custom.el"))
;; Scoll 1 line at a time ;; Scroll 1 line at a time.
(setq mouse-wheel-scroll-amount '(1 ((shift) . 1))) (setq mouse-wheel-scroll-amount '(1 ((shift) . 1)))
;; Scroll before cursor has reached top/bottom ;; Scroll before cursor has reached top/bottom.
(use-package smooth-scrolling (use-package smooth-scrolling
:config :config
(smooth-scrolling-mode 1)) (smooth-scrolling-mode 1))
@ -130,7 +128,7 @@
;; Paste text where the cursor is, not where the mouse is. ;; Paste text where the cursor is, not where the mouse is.
(setq mouse-yank-at-point t) (setq mouse-yank-at-point t)
;; Put scrollbar to the right side ;; Put scrollbar to the right side.
(if (display-graphic-p) (if (display-graphic-p)
(set-scroll-bar-mode 'right)) (set-scroll-bar-mode 'right))
@ -138,14 +136,14 @@
(use-package bind-key (use-package bind-key
:config :config
(bind-keys (bind-keys
;; Scroll in other window ;; Scroll in other window.
("S-<prior>" . scroll-other-window-down) ("S-<prior>" . scroll-other-window-down)
("S-<next>" . scroll-other-window) ("S-<next>" . scroll-other-window)
;; Switch window ;; Switch window
("C-<tab>" . other-window) ("C-<tab>" . other-window)
;; Reduce whitespace around point to 0 or 1, according to context ;; Reduce whitespace around cursor to 0 or 1, according to context.
("C-<delete>" . fixup-whitespace) ("C-<delete>" . fixup-whitespace)
;; Scroll without moving the cursor ;; Scroll without moving the cursor.
("M-<down>" . scroll-up-line) ("M-<down>" . scroll-up-line)
("M-<up>" . scroll-down-line))) ("M-<up>" . scroll-down-line)))
@ -159,11 +157,12 @@
(progn (progn
(message "RTags is not installed!") (message "RTags is not installed!")
(rtags-install))) (rtags-install)))
(define-key c-mode-base-map (kbd "M-.") 'rtags-find-symbol-at-point)
(define-key c-mode-base-map (kbd "M-,") 'rtags-find-references-at-point)
(define-key c-mode-base-map (kbd "M-?") 'rtags-display-summary)
(rtags-enable-standard-keybindings) (rtags-enable-standard-keybindings)
:bind
(:map c-mode-base-map
("M-." . rtags-find-symbol-at-point)
("M-," . rtags-find-references-at-point)
("M-?" . rtags-display-summary))
:hook :hook
(c++-mode . (rtags-start-process-unless-running)) (c++-mode . (rtags-start-process-unless-running))
(c-mode . (rtags-start-process-unless-running)) (c-mode . (rtags-start-process-unless-running))
@ -173,49 +172,51 @@
:after (flycheck rtags) :after (flycheck rtags)
:demand t :demand t
:config :config
;; ensure that we use only rtags checking ;; ensure that we use only rtags checking.
;; https://github.com/Andersbakken/rtags#optional-1 ;; https://github.com/Andersbakken/rtags#optional-1
(defun setup-flycheck-rtags () (defun my/setup-flycheck-rtags ()
(flycheck-select-checker 'rtags) (flycheck-select-checker 'rtags)
(setq-local flycheck-highlighting-mode nil)) ; Can't disable RTags overlay (setq-local flycheck-highlighting-mode nil)) ; Can't disable RTags overlay.
:hook :hook
(c-mode-hook . #'setup-flycheck-rtags) (c-mode-hook . #'my/setup-flycheck-rtags)
(c++-mode-hook . #'setup-flycheck-rtags)) (c++-mode-hook . #'my/setup-flycheck-rtags))
(use-package company-rtags (use-package company-rtags
:after (company rtags) :after (company rtags)
:custom
(rtags-completions-enabled t)
:config :config
;; (setq rtags-autostart-diagnostics t) ;; (setq rtags-autostart-diagnostics t)
;; (rtags-diagnostics) ;; (rtags-diagnostics)
(setq rtags-completions-enabled t)
(push 'company-rtags company-backends)) (push 'company-rtags company-backends))
;; cmake integration ;; cmake integration.
(use-package cmake-ide (use-package cmake-ide
:unless slow-computer :unless slow-computer
:custom
(cmake-ide-build-dir "build")
:config :config
(setq cmake-ide-build-dir "build")
(cmake-ide-setup)) (cmake-ide-setup))
;;;;;;;;;;;;;;;;;;;; Programming / other ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;; Programming / other ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Online documentation mode ;; Online documentation mode.
(use-package eldoc (use-package eldoc
:hook :hook
(prog-mode . turn-on-eldoc-mode)) (prog-mode . turn-on-eldoc-mode))
;; Syntax checking ;; Syntax checking with many plugins.
(use-package flycheck (use-package flycheck
:unless slow-computer :unless slow-computer
:config :config
(global-flycheck-mode)) (global-flycheck-mode))
;; Autocompletion ;; Autocompletion mode with many plugins.
(use-package company (use-package company
:unless slow-computer :unless slow-computer
:hook :hook
(after-init . global-company-mode)) (after-init . global-company-mode))
;; Fuzzy autocompletion ;; Fuzzy autocompletion for company.
(use-package company-flx (use-package company-flx
:after company :after company
:config :config
@ -227,7 +228,7 @@
(setq c-default-style "linux" (setq c-default-style "linux"
c-basic-offset 4) c-basic-offset 4)
;; Project management ;; Automatic project management.
(use-package projectile (use-package projectile
:unless slow-computer :unless slow-computer
:after neotree :after neotree
@ -240,7 +241,7 @@
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -G 'Unix Makefiles' .." -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -G 'Unix Makefiles' .."
projectile-project-compilation-cmd "cmake --build .") projectile-project-compilation-cmd "cmake --build .")
(defun projectile-kill-buffers-and-change-tabbar-grouping () (defun my/projectile-kill-buffers-and-change-tabbar-grouping ()
"Kill project buffers and change tabbar-ruler grouping to user-buffers." "Kill project buffers and change tabbar-ruler grouping to user-buffers."
(interactive) (interactive)
(projectile-kill-buffers) (projectile-kill-buffers)
@ -248,37 +249,37 @@
:bind :bind
("C-c p" . 'projectile-command-map) ("C-c p" . 'projectile-command-map)
(:map projectile-command-map (:map projectile-command-map
("k" . 'projectile-kill-buffers-and-change-tabbar-grouping))) ("k" . 'my/projectile-kill-buffers-and-change-tabbar-grouping)))
;; Debugger ;; GUI for gdb and other debuggers.
(use-package realgud (use-package realgud
:config :config
(defun load-realgud () (defun my/load-realgud ()
(load-library "realgud")) (load-library "realgud"))
:hook :hook
(c++-mode . load-realgud) (c++-mode . my/load-realgud)
(c-mode . load-realgud)) (c-mode . my/load-realgud))
;; Highlight TODO, FIXME, NOTE and so on. ;; Highlight TODO, FIXME, NOTE and so on.
(use-package hl-todo (use-package hl-todo
:hook :hook
(prog-mode . hl-todo-mode)) (prog-mode . hl-todo-mode))
;; Better commenting ;; Better commenting.
(use-package smart-comment (use-package smart-comment
:bind :bind
("C-x c" . smart-comment)) ("C-x c" . smart-comment))
;; Toggle betweeen beginning/end of line and beginning/end of code ;; Toggle betweeen beginning/end of line and beginning/end of code.
(use-package mwim (use-package mwim
:bind :bind
("<home>" . mwim-beginning-of-line-or-code) ("<home>" . mwim-beginning-of-line-or-code)
("<end>" . mwim-end-of-line-or-code)) ("<end>" . mwim-end-of-line-or-code))
;; Auto-type closing brackets ;; Auto-type closing brackets.
(electric-pair-mode t) (electric-pair-mode t)
;; Folding ;; Fold code.
(use-package fold-dwim (use-package fold-dwim
:bind :bind
("<f7>" . fold-dwim-toggle) ("<f7>" . fold-dwim-toggle)
@ -286,58 +287,60 @@
:hook :hook
(prog-mode . hs-minor-mode)) (prog-mode . hs-minor-mode))
;; Highlight indentation levels ;; Highlight indentation levels.
(use-package highlight-indent-guides (use-package highlight-indent-guides
:config :custom
(setq highlight-indent-guides-method 'character (highlight-indent-guides-method 'character)
highlight-indent-guides-responsive 'top) (highlight-indent-guides-responsive 'top)
:hook :hook
(prog-mode . highlight-indent-guides-mode)) (prog-mode . highlight-indent-guides-mode))
;; Tries to find structures and jumps to them.
(use-package imenu-anywhere (use-package imenu-anywhere
:after ido-completing-read+ :after ido-completing-read+
:bind :bind
("M-i" . imenu-anywhere)) ("M-i" . imenu-anywhere))
;;;;;;;;;;;;;;;;;;;; Appearance ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;; Appearance ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Icons (required by doom) ;; Icons (required by doom).
(use-package all-the-icons (use-package all-the-icons
:config :config
(unless (file-exists-p "~/.local/share/fonts/all-the-icons.ttf") (unless (file-exists-p "~/.local/share/fonts/all-the-icons.ttf")
(all-the-icons-install-fonts t))) (all-the-icons-install-fonts t)))
;; Theme ;; Themes for doom-modeline.
(use-package doom-themes (use-package doom-themes
:unless slow-computer :unless slow-computer
:after (all-the-icons neotree) :after (all-the-icons neotree)
:custom
(doom-neotree-file-icons 'icons)
:config :config
(load-theme 'doom-molokai t) (load-theme 'doom-molokai t)
(doom-themes-neotree-config) (doom-themes-neotree-config))
:custom
(doom-neotree-file-icons 'icons))
;; Modeline ;; Neat modeline.
(use-package doom-modeline (use-package doom-modeline
:after all-the-icons :after all-the-icons
:init :init
;; Show column numbers in modeline (column-number-mode t) ; Show column numbers in modeline.
(column-number-mode t)
:config :config
(setq doom-modeline-minor-modes t) (setq doom-modeline-minor-modes t)
:hook (after-init . doom-modeline-mode)) :hook
(after-init . doom-modeline-mode))
;; Misc ;; Miscellaneous visual improvements.
(set-face-font 'default "Source Code Pro") (set-face-font 'default "Source Code Pro")
(global-hl-line-mode t) (global-hl-line-mode t) ; Highlight current line.
(if (>= emacs-major-version 26) (size-indication-mode) ; Buffer size display in the modeline.
(use-package display-line-numbers (show-paren-mode t) ; Visualize matching parens.
:config ;; Show line numbers on the left of the buffer.
(global-display-line-numbers-mode))) (use-package display-line-numbers
(size-indication-mode) :if (>= emacs-major-version 26)
(show-paren-mode t) :config
(global-display-line-numbers-mode))
;;;;;;;;;;;;;;;;;;;; Misc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;; Misc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Directory tree ;; Show directory tree in a window.
(use-package neotree (use-package neotree
:demand t :demand t
:after all-the-icons :after all-the-icons
@ -345,16 +348,16 @@
(neo-smart-open t) (neo-smart-open t)
(neo-show-updir-line t) ; Disabled by doom-themes? (neo-show-updir-line t) ; Disabled by doom-themes?
(neo-window-width 30) (neo-window-width 30)
;; (setq neo-theme (if (display-graphic-p) 'icons 'arrow))
:bind :bind
("<f8>" . neotree-toggle)) ("<f8>" . neotree-toggle))
;; Git integration.
(use-package magit (use-package magit
:unless slow-computer :unless slow-computer
:init :init
(use-package git-commit) (use-package git-commit)
:config :config
(defun my-magit-kill-buffers (arg) (defun my/magit-kill-buffers (arg)
"Restore window configuration and kill all Magit buffers." "Restore window configuration and kill all Magit buffers."
(interactive) (interactive)
(let ((buffers (magit-mode-get-buffers))) (let ((buffers (magit-mode-get-buffers)))
@ -367,64 +370,65 @@
;; ("q" . my-magit-kill-buffers)) ;; ("q" . my-magit-kill-buffers))
:custom :custom
;; What's better, mapping q or binding the function here? ;; What's better, mapping q or binding the function here?
(magit-bury-buffer-function 'my-magit-kill-buffers)) (magit-bury-buffer-function 'my/magit-kill-buffers))
;; Draw line in column 80 ;; Draw line in column 80
(use-package fill-column-indicator (use-package fill-column-indicator
:after company :after company
:config :config
;; ;; TODO: Find out why I can't put this in :init or :config ;; ;; TODO: Find out why I can't put this in :init or :config.
;; (define-globalized-minor-mode global-fci-mode fci-mode ;; (define-globalized-minor-mode global-fci-mode fci-mode
;; (lambda () (fci-mode t))) ;; (lambda () (fci-mode t)))
;; (global-fci-mode t) ;; (global-fci-mode t)
;; Fix bug with fci + company ;; Fix bug with fci + company.
(defun on-off-fci-before-company(command) (defun my/on-off-fci-before-company(command)
(when (string= "show" command) (when (string= "show" command)
(turn-off-fci-mode)) (turn-off-fci-mode))
(when (string= "hide" command) (when (string= "hide" command)
(turn-on-fci-mode))) (turn-on-fci-mode)))
(advice-add 'company-call-frontends :before #'on-off-fci-before-company) (advice-add 'company-call-frontends :before #'my/on-off-fci-before-company)
;; Add global fci-mode
:hook :hook
(prog-mode . fci-mode) (prog-mode . fci-mode)
(text-mode . fci-mode) (text-mode . fci-mode)
:custom :custom
(fci-rule-column 80)) (fci-rule-column 80))
;; Interactive substring matching ;; Interactive substring matching.
(use-package ido (use-package ido
:defer 1 :defer 1
:config :config
(ido-mode t) (ido-mode t)
(ido-everywhere t)) (ido-everywhere t))
;; Flexible matching for ido.
(use-package flx-ido (use-package flx-ido
:after ido :after ido
:custom
(setq ido-enable-flex-matching t
ido-ignore-extensions t ; Ignore extension like ~ and .o.
ido-use-virtual-buffers t)) ; Keep history of recently opened buffers.
:config :config
(flx-ido-mode t) (flx-ido-mode t)
(setq ido-enable-flex-matching t
ido-ignore-extensions t
ido-use-virtual-buffers t)) ; Keep history of recently opened buffers
;; Replaces stock emacs completion with ido completion wherever it is possible ;; Replaces stock emacs completion with ido completion wherever it is possible.
(use-package ido-completing-read+ (use-package ido-completing-read+
:unless slow-computer :unless slow-computer
:after ido :after ido
:config :config
(ido-ubiquitous-mode t)) (ido-ubiquitous-mode t))
;; Tab bar ;; Advanced tab bar.
(use-package tabbar-ruler (use-package tabbar-ruler
:unless slow-computer :unless slow-computer
:after projectile :after projectile
:init :init
(setq tabbar-ruler-global-tabbar t) (setq tabbar-ruler-global-tabbar t)
:config :config
;; (tabbar-ruler-group-by-projectile-project) ; Group by projectile ;; (tabbar-ruler-group-by-projectile-project) ; Group by projectile.
;; (tabbar-ruler-group-buffer-groups) ; Group by file type ;; (tabbar-ruler-group-buffer-groups) ; Group by file type.
(tabbar-ruler-group-user-buffers) ; Group by frame (tabbar-ruler-group-user-buffers) ; Group by frame.
;; (mode-icons-mode 0) ; Disable modeline symbols ;; (mode-icons-mode 0) ; Disable modeline symbols.
;; I have to define these 2 times, don't know why. ;; I have to define these 2 times, don't know why.
(set-face-attribute 'tabbar-selected nil (set-face-attribute 'tabbar-selected nil
@ -438,7 +442,7 @@
:family "Sans Serif" :family "Sans Serif"
:italic t) :italic t)
(add-hook 'projectile-after-switch-project-hook ; Does not work under :hook (add-hook 'projectile-after-switch-project-hook ; Does not work under :hook.
'tabbar-ruler-group-by-projectile-project) 'tabbar-ruler-group-by-projectile-project)
:bind :bind
("C-<prior>" . 'tabbar-ruler-tabbar-backward-tab) ("C-<prior>" . 'tabbar-ruler-tabbar-backward-tab)
@ -456,19 +460,19 @@
:family "Sans Serif" :family "Sans Serif"
:italic t))) :italic t)))
;; Keybinding for whitespace, don't visualise newlines ;; Visualize whitespace.
(use-package whitespace (use-package whitespace
:config :config
(delete 'newline-mark whitespace-style) ; $ at eol (delete 'newline-mark whitespace-style) ; Don't paint $ at eol.
(delete 'lines whitespace-style) ; Don't paint lines red if too long. (delete 'lines whitespace-style) ; Don't paint lines red if too long.
;; Don't show dots in company menu ;; Don't show dots in company menu.
(defun on-off-whitespace-before-company(command) (defun my/on-off-whitespace-before-company(command)
(when (string= "show" command) (when (string= "show" command)
(whitespace-mode -1)) (whitespace-mode -1))
(when (string= "hide" command) (when (string= "hide" command)
(whitespace-mode t))) (whitespace-mode t)))
(advice-add 'company-call-frontends (advice-add 'company-call-frontends
:before #'on-off-whitespace-before-company) :before #'my/on-off-whitespace-before-company)
:bind :bind
("C-x w" . 'whitespace-mode) ("C-x w" . 'whitespace-mode)
:hook :hook
@ -476,24 +480,27 @@
:custom-face :custom-face
(whitespace-space ((nil :foreground "gray18")))) (whitespace-space ((nil :foreground "gray18"))))
;; Spell checking ;; Spell checking.
(use-package flyspell (use-package flyspell
:unless slow-computer
:custom
(ispell-dictionary "english")
:config :config
(defun toggle-flyspell () (defun my/toggle-flyspell ()
"Toggle flyspell-mode and run flyspell-buffer after activating" "Toggle flyspell-mode and run flyspell-buffer after activating."
(interactive) (interactive)
(if (bound-and-true-p flyspell-mode) (if (bound-and-true-p flyspell-mode)
(flyspell-mode 0) (flyspell-mode 0)
(flyspell-mode) (flyspell-mode)
(flyspell-buffer))) (flyspell-buffer)))
(setq ispell-dictionary "english")
:bind :bind
("<f6>" . toggle-flyspell) ("<f6>" . my/toggle-flyspell)
:hook :hook
;; Spellcheck comments.
(c++-mode . flyspell-prog-mode) (c++-mode . flyspell-prog-mode)
(c-mode . flyspell-prog-mode)) (c-mode . flyspell-prog-mode))
;; Multiple cursors ;; Multiple cursors.
(use-package multiple-cursors (use-package multiple-cursors
:init :init
(global-unset-key (kbd "M-<down-mouse-1>")) (global-unset-key (kbd "M-<down-mouse-1>"))
@ -501,7 +508,7 @@
("C-x M-m" . mc/edit-lines) ("C-x M-m" . mc/edit-lines)
("M-<mouse-1>" . mc/add-cursor-on-click)) ("M-<mouse-1>" . mc/add-cursor-on-click))
;; If 2 files with same name, append directory name after the filename ;; If 2 files have the same name, append directory name after the filename.
(use-package uniquify (use-package uniquify
:defer 1 :defer 1
:ensure nil ; Included in emacs :ensure nil ; Included in emacs
@ -510,30 +517,31 @@
(uniquify-buffer-name-style 'post-forward) (uniquify-buffer-name-style 'post-forward)
(uniquify-strip-common-suffix t)) (uniquify-strip-common-suffix t))
;; Delete old buffers ;; Delete old buffers.
;; https://www.emacswiki.org/emacs/CleanBufferList ;; https://www.emacswiki.org/emacs/CleanBufferList
(use-package midnight (use-package midnight
:init :init
(setq midnight-delay 0) ; 0 seconds after "midnight" (setq midnight-delay 0) ; 0 seconds after "midnight"
:custom
(clean-buffer-list-delay-general 1) ; Clean normal bufs after 1d.
(clean-buffer-list-delay-special (* 30 60)) ; Clean special bufs after 30m.
:config :config
(setq midnight-period (* 1 60 60) ; Clean every 1 hours (setq clean-buffer-list-kill-regexps ; Add these to special buffers.
clean-buffer-list-delay-general 1 ; Clean normal bufs after 1d
clean-buffer-list-delay-special (* 30 60) ; Clean special bufs after 30m
clean-buffer-list-kill-regexps ; Add these to special buffers
(nconc clean-buffer-list-kill-regexps (nconc clean-buffer-list-kill-regexps
'("\\`magit-?.*:" '("\\`magit-?.*:"
"\\.log\\'"))) "\\.log\\'")))
(setq midnight-period (* 1 60 60)) ; Clean every 1 hours.
(midnight-mode t)) (midnight-mode t))
;; The string Time-stamp: <> in the first 8 lines of the file will be updated ;; The string Time-stamp: <> in the first 8 lines of the file will be updated
;; with the current timestamp. ;; with the current timestamp.
(use-package time-stamp (use-package time-stamp
:config :custom
(setq time-stamp-format "%:y-%02m-%02d %02H:%02M:%02S %Z") (time-stamp-format "%:y-%02m-%02d %02H:%02M:%02S %Z")
:hook :hook
(before-save . time-stamp)) (before-save . time-stamp))
;; Edit multiple regions in the same way simultaneously ;; Edit multiple regions in the same way simultaneously.
(use-package iedit (use-package iedit
:bind :bind
("C-;" . iedit-mode)) ("C-;" . iedit-mode))
@ -551,7 +559,7 @@
;; The mode is not turned on? ;; The mode is not turned on?
("\\`'\\*Easy-hugo\\*\\'" . easy-hugo-mode)) ("\\`'\\*Easy-hugo\\*\\'" . easy-hugo-mode))
;; Automatically insert text in new files ;; Automatically insert text in new files.
(use-package autoinsert (use-package autoinsert
:init :init
;; I only use it in here for now ;; I only use it in here for now
@ -562,7 +570,6 @@
(yas-minor-mode t) (yas-minor-mode t)
(yas-expand-snippet (buffer-string) (point-min) (point-max))) (yas-expand-snippet (buffer-string) (point-min) (point-max)))
:config :config
;; (define-auto-insert "\.cpp" . ["c++" my/autoinsert-yas-expand])
(add-to-list 'auto-insert-alist (add-to-list 'auto-insert-alist
'(("\\.\\(cpp\\|cc\\|cxx\\|c\\+\\+\\)\\'" . "C++ program") . '(("\\.\\(cpp\\|cc\\|cxx\\|c\\+\\+\\)\\'" . "C++ program") .
["cpp" my/autoinsert-yas-expand])) ["cpp" my/autoinsert-yas-expand]))
@ -571,7 +578,7 @@
["hpp" my/autoinsert-yas-expand])) ["hpp" my/autoinsert-yas-expand]))
:custom :custom
(auto-insert-directory (concat user-emacs-directory "auto-insert")) (auto-insert-directory (concat user-emacs-directory "auto-insert"))
(auto-insert-query nil) ; Always insert (auto-insert-query nil) ; Don't ask before inserting.
:hook :hook
(find-file . auto-insert)) (find-file . auto-insert))
@ -583,8 +590,8 @@
(adoc-mode . visual-line-mode)) (adoc-mode . visual-line-mode))
(use-package markdown-mode (use-package markdown-mode
:init :custom
(setq markdown-command "markdown2") (markdown-command "markdown2")
:mode :mode
(("README\\.md\\'" . gfm-mode) (("README\\.md\\'" . gfm-mode)
("\\.md\\'" . markdown-mode) ("\\.md\\'" . markdown-mode)
@ -607,14 +614,14 @@
(nginx-mode . company-nginx-keywords)) (nginx-mode . company-nginx-keywords))
;;;;;;;;;;;;;;;;;;;; Server / Remote editing ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;; Server / Remote editing ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Edit remote files ;; Edit remote files.
(use-package tramp (use-package tramp
:unless slow-computer :unless slow-computer
:defer 1 :defer 1
:config :config
;; ssh is faster than scp and supports ports ;; ssh is faster than scp and supports ports.
(setq tramp-default-method "ssh") (setq tramp-default-method "ssh")
;; Add verification code support ;; Add verification code support.
(customize-set-variable (customize-set-variable
'tramp-password-prompt-regexp 'tramp-password-prompt-regexp
(concat (concat
@ -625,13 +632,13 @@
"Verification code") "Verification code")
t) t)
".*:\0? *")) ".*:\0? *"))
;; Respect remote PATH ;; Respect remote PATH.
(add-to-list 'tramp-remote-path 'tramp-own-remote-path)) (add-to-list 'tramp-remote-path 'tramp-own-remote-path))
;; Run server if: ;; Run server if:
;; - Our EUID is not 0 ;; - Our EUID is not 0,
;; - We are not logged in via SSH ;; - We are not logged in via SSH,
;; - It is not already running ;; - It is not already running.
(unless (equal (user-real-uid) 0) (unless (equal (user-real-uid) 0)
(unless (getenv "SSH_CONNECTION") (unless (getenv "SSH_CONNECTION")
(use-package server (use-package server
@ -639,15 +646,15 @@
:init :init
(setq server-use-tcp t (setq server-use-tcp t
server-port 51313 server-port 51313
server-auth-key server-auth-key ; 64 chars, saved in ~/.emacs.d/server/server.
"phahw2ohVoh0oopheish7IVie9desh8aequeenei3uo8wahShe%thuadaeNa4ieh") "phahw2ohVoh0oopheish7IVie9desh8aequeenei3uo8wahShe%thuadaeNa4ieh")
:config :config
(unless (server-running-p) (unless (server-running-p)
(server-start)) (server-start))
))) )))
;; Set garbage collection threshold to original value ;; Set garbage collection threshold to original value.
(setq gc-cons-threshold (car (get 'gc-cons-threshold 'standard-value))) (setq gc-cons-threshold (car (get 'gc-cons-threshold 'standard-value)))
(provide 'init) (provide 'init)
;;; init.el ends here ;;; init.el ends here.

View File

@ -1,2 +1,2 @@
127.0.0.1:51313 31524 127.0.0.1:51313 15932
phahw2ohVoh0oopheish7IVie9desh8aequeenei3uo8wahShe%thuadaeNa4ieh phahw2ohVoh0oopheish7IVie9desh8aequeenei3uo8wahShe%thuadaeNa4ieh