From 6ad2e2503947fc8fb17ca18e3806fe0d06b437e8 Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 19 Jun 2017 10:50:04 -0600 Subject: Add autocompletion and rust support --- init.el | 400 ++++++++++++++++++++------------------- local-lib/autocompletion-conf.el | 30 +++ local-lib/rust-conf.el | 32 ++++ 3 files changed, 265 insertions(+), 197 deletions(-) create mode 100644 local-lib/autocompletion-conf.el create mode 100644 local-lib/rust-conf.el diff --git a/init.el b/init.el index 2849e94..a7db81f 100644 --- a/init.el +++ b/init.el @@ -1,197 +1,203 @@ -;;; init.el --- emacs start up -;; Author: jason -;; Created: 03 Dec 2015 -;; Version: 0.2 -;; Keywords: -;; X-URL: https://beehive.io/jason/emacs.d/ -;;; Commentary: -;; -;;; Code: -(defconst emacs-start-time (current-time)) -(setq inhibit-startup-screen t ;; Hide the default startup screen - savehist-file "~/.emacs.d/savehist" - ;; Define where to store recovery files - backup-directory-alist '(("." . "~/.emacs.d/backups")) - ;; Use version numbers for backups. - version-control t - ;; Number of newest versions to keep. - kept-new-versions 10 - ;; Number of oldest versions to keep. - kept-old-versions 0 - ;; Don't ask to delete excess backup versions. - delete-old-versions -1 - ;; Copy all files, don't rename them. - backup-by-copying t - ;; Make backups files under version control. - vc-make-backup-files t - ;; Don't confirm following when opening a symlink - vc-follow-symlinks t) - -(setq package-archives '(("elpa" . "http://elpa.gnu.org/packages/") - ;; For org-mode - ("org" . "http://orgmode.org/elpa/") - ;; melpa builds git repositories and can be unstable - ("melpa" . "http://melpa.org/packages/") - ;; marmalade has maintainers upload versions - ;; ("marmalade" . "https://marmalade-repo.org/packages/") - ;; melpa-stable builds from git tags but may be missing dependencies - ;; ("melpa-stable" . "https://stable.melpa.org/packages/") - ;; Elpy packages for the Python language - ;; ("elpy" . "https://jorgenschaefer.github.io/packages/") - )) - -;; Initializes installed packages -(package-initialize) - -;; Packages are managed by the use-package package, so we need to make sure it's installed -(unless (package-installed-p 'use-package) - (package-refresh-contents) - (package-install 'use-package)) -(eval-when-compile - (require 'use-package)) -;; slight optimization for use-package's :bind directive -(require 'bind-key) - -;; Add local library to the load path -(add-to-list 'load-path "~/.emacs.d/local-lib/") -;; Usernames and passwords are stored in a file that isn't sync'd to VC -(load "~/.emacs.d/secrets" t) - -;; My misc functions -(require 'zzq-funcs) - -(add-hook 'after-init-hook - (lambda () - (progn - ;; Maximize the frame on startup - (toggle-frame-maximized) - ;; Always ensure packages are installed if they are defined with use-package - ;; (setq use-package-always-ensure t) - - ;; Set default encoding to UTF-8 - (set-language-environment "UTF-8") - (set-default-coding-systems 'utf-8) - ;; Hide the toolbar - (tool-bar-mode -1) - ;; Hide the scrollbar - (scroll-bar-mode -1) - ;; no beep and no blinking cursor - (setq ring-bell-function 'ignore - visible-bell nil - ;; display the full file path in the titlebar - frame-title-format - (list (format "%s %%S: %%j " (system-name)) - '(buffer-file-name "%f" (dired-directory dired-directory "%b")))) - - ;; Show matched parens - (show-paren-mode t) - ;; Allow undoing/redoing of window layouts with C-c left/right arrows - (winner-mode 1) - ;; Let y and n be good enough for yes and no questions - (fset 'yes-or-no-p 'y-or-n-p) - ;; Auto-refresh files changed on the file system - (global-auto-revert-mode 1) - ;; Save commands and their history - (savehist-mode +1) - (setq savehist-save-minibuffer-history +1) - (setq savehist-additional-variables - '(kill-ring - search-ring - regexp-search-ring)) - ;; Allow mouse support in xterm - (xterm-mouse-mode 1) - ;; Automatically close parens when opening them - (electric-pair-mode 1) - ;; Ovewrite selected regions with what you're typing/pasting/etc - (delete-selection-mode 1) - ;; A region is only active when it is highlighted (mimics other editors) - (transient-mark-mode 1) - ;;;;;;;;;;; - ;; Hooks ;; - ;;;;;;;;;;; - (add-hook 'write-file-hooks - '(lambda () - ;; delete trailing whitespace from all files - (delete-trailing-whitespace))) - ;;;;;;;;;;;; - ;; Themes ;; - ;;;;;;;;;;;; - (use-package jbeans-theme - :ensure t - :config - (load-theme 'jbeans)) - ;;;;;;;;;;;;;; - ;; Packages ;; - ;;;;;;;;;;;;;; - ;; paradox - A better emacs package manager - (use-package paradox - :ensure t - :config - ;; Use paradox as the default package manager - (paradox-enable)) - ;; which-key - Displays a pop up with hints when pushing key bindings - (use-package which-key - :ensure t - :diminish which-key-mode - :init - (setq which-key-special-keys nil - which-key-use-C-h-commands t - which-key-echo-keystrokes 0.02 - which-key-max-description-length 32 - which-key-sort-order 'which-key-key-order-alpha) - :config - (which-key-mode)) - ;; Ivy, swiper, and counsel for autocompleting emacs things - (use-package ivy - :ensure t - :pin elpa - :diminish ivy-mode - :bind (("C-s" . swiper) - ("M-x" . counsel-M-x) - ("C-x C-f" . counsel-find-file)) - :init - ;; Remove the ^ prefix - (setq ivy-initial-inputs-alist nil - ;; Display recently opened files when switching buffers - ivy-use-virtual-buffers t - ;; Use ivy for magit - magit-completing-read-function 'ivy-completing-read - ;; Use ivy for projectile - projectile-completion-system 'ivy) - :config - (ivy-mode 1)) - ;; avy - A quick way to jump around buffers - (use-package avy - :ensure t - :bind (("C-:" . avy-goto-line))) - ;; Other packages - ;; persp - virtual workspaces - (require 'persp-conf) - ;; powerline - prettier modeline - (require 'powerline-conf) - ;; projectile - utilities for working with projects - (require 'projectile-conf) - - (message "Emacs loaded in %.3fs" - (/ (- (zzq/time-to-msec (current-time)) (zzq/time-to-msec emacs-start-time)) 1000.0)) - ))) ;; End progn/lambda/add-hook after-init-hook - -(custom-set-variables - ;; custom-set-variables was added by Custom. - ;; If you edit it by hand, you could mess it up, so be careful. - ;; Your init file should contain only one such instance. - ;; If there is more than one, they won't work right. - '(custom-safe-themes - (quote - ("64f2981274fd8740b794bce9feee7949ed87b88fc0b4654bd98594e1aa81abcd" default))) - '(package-selected-packages - (quote - (projectile persp-mode avy ivy powerline which-key paradox use-package jbeans-theme))) - '(paradox-github-token t)) - -(custom-set-faces - ;; custom-set-faces was added by Custom. - ;; If you edit it by hand, you could mess it up, so be careful. - ;; Your init file should contain only one such instance. - ;; If there is more than one, they won't work right. - '(default ((t (:family "Inconsolata" :foundry "outline" :slant normal :weight normal :height 79 :width normal))))) +;;; init.el --- emacs start up +;; Author: jason +;; Created: 15 Jun 2017 +;; Version: 2 +;; Keywords: +;; X-URL: https://beehive.io/jason/emacs.d/ +;;; Commentary: +;; +;;; Code: +(defconst emacs-start-time (current-time)) +(setq inhibit-startup-screen t ;; Hide the default startup screen + savehist-file "~/.emacs.d/savehist" + ;; Define where to store recovery files + backup-directory-alist '(("." . "~/.emacs.d/backups")) + ;; Use version numbers for backups. + version-control t + ;; Number of newest versions to keep. + kept-new-versions 10 + ;; Number of oldest versions to keep. + kept-old-versions 0 + ;; Don't ask to delete excess backup versions. + delete-old-versions -1 + ;; Copy all files, don't rename them. + backup-by-copying t + ;; Make backups files under version control. + vc-make-backup-files t + ;; Don't confirm following when opening a symlink + vc-follow-symlinks t) + +(setq package-archives '(("elpa" . "http://elpa.gnu.org/packages/") + ;; For org-mode + ("org" . "http://orgmode.org/elpa/") + ;; melpa builds git repositories and can be unstable + ("melpa" . "http://melpa.org/packages/") + ;; marmalade has maintainers upload versions + ;; ("marmalade" . "https://marmalade-repo.org/packages/") + ;; melpa-stable builds from git tags but may be missing dependencies + ;; ("melpa-stable" . "https://stable.melpa.org/packages/") + ;; Elpy packages for the Python language + ;; ("elpy" . "https://jorgenschaefer.github.io/packages/") + )) + +;; Initializes installed packages +(package-initialize) + +;; Packages are managed by the use-package package, so we need to make sure it's installed +(unless (package-installed-p 'use-package) + (package-refresh-contents) + (package-install 'use-package)) +(eval-when-compile + (require 'use-package)) +;; slight optimization for use-package's :bind directive +(require 'bind-key) + +;; Add local library to the load path +(add-to-list 'load-path "~/.emacs.d/local-lib/") +;; Usernames and passwords are stored in a file that isn't sync'd to VC +(load "~/.emacs.d/secrets" t) + +;; My misc functions +(require 'zzq-funcs) + +(add-hook 'after-init-hook + (lambda () + (progn + ;; Maximize the frame on startup + (toggle-frame-maximized) + ;; Always ensure packages are installed if they are defined with use-package + ;; (setq use-package-always-ensure t) + + ;; Set default encoding to UTF-8 + (set-language-environment "UTF-8") + (set-default-coding-systems 'utf-8) + ;; Hide the toolbar + (tool-bar-mode -1) + ;; Hide the scrollbar + (scroll-bar-mode -1) + ;; no beep and no blinking cursor + (setq ring-bell-function 'ignore + visible-bell nil + ;; display the full file path in the titlebar + frame-title-format + (list (format "%s %%S: %%j " (system-name)) + '(buffer-file-name "%f" (dired-directory dired-directory "%b")))) + + ;; Show matched parens + (show-paren-mode t) + ;; Allow undoing/redoing of window layouts with C-c left/right arrows + (winner-mode 1) + ;; Let y and n be good enough for yes and no questions + (fset 'yes-or-no-p 'y-or-n-p) + ;; Auto-refresh files changed on the file system + (global-auto-revert-mode 1) + ;; Save commands and their history + (savehist-mode +1) + (setq savehist-save-minibuffer-history +1) + (setq savehist-additional-variables + '(kill-ring + search-ring + regexp-search-ring)) + ;; Allow mouse support in xterm + (xterm-mouse-mode 1) + ;; Automatically close parens when opening them + (electric-pair-mode 1) + ;; Ovewrite selected regions with what you're typing/pasting/etc + (delete-selection-mode 1) + ;; A region is only active when it is highlighted (mimics other editors) + (transient-mark-mode 1) + ;;;;;;;;;;; + ;; Hooks ;; + ;;;;;;;;;;; + (add-hook 'write-file-hooks + '(lambda () + ;; delete trailing whitespace from all files + (delete-trailing-whitespace))) + ;;;;;;;;;;;; + ;; Themes ;; + ;;;;;;;;;;;; + (use-package jbeans-theme + :ensure t + :config + (load-theme 'jbeans)) + ;;;;;;;;;;;;;; + ;; Packages ;; + ;;;;;;;;;;;;;; + ;; paradox - A better emacs package manager + (use-package paradox + :ensure t + :config + ;; Use paradox as the default package manager + (paradox-enable)) + ;; which-key - Displays a pop up with hints when pushing key bindings + (use-package which-key + :ensure t + :diminish which-key-mode + :init + (setq which-key-special-keys nil + which-key-use-C-h-commands t + which-key-echo-keystrokes 0.02 + which-key-max-description-length 32 + which-key-sort-order 'which-key-key-order-alpha) + :config + (which-key-mode)) + ;; Ivy, swiper, and counsel for autocompleting emacs things + (use-package ivy + :ensure t + :pin elpa + :diminish ivy-mode + :bind (("C-s" . swiper) + ("M-x" . counsel-M-x) + ("C-x C-f" . counsel-find-file)) + :init + ;; Remove the ^ prefix + (setq ivy-initial-inputs-alist nil + ;; Display recently opened files when switching buffers + ivy-use-virtual-buffers t + ;; Use ivy for magit + magit-completing-read-function 'ivy-completing-read + ;; Use ivy for projectile + projectile-completion-system 'ivy) + :config + (ivy-mode 1)) + ;; avy - A quick way to jump around buffers + (use-package avy + :ensure t + :bind (("C-:" . avy-goto-line))) + + ;; Other packages + ;; autocompletion - auto-completion for programming languages + (require 'autocompletion-conf) + ;; persp - virtual workspaces + (require 'persp-conf) + ;; powerline - prettier modeline + (require 'powerline-conf) + ;; projectile - utilities for working with projects + (require 'projectile-conf) + + ;; Languages + (require 'rust-conf) + + (message "Emacs loaded in %.3fs" + (/ (- (zzq/time-to-msec (current-time)) (zzq/time-to-msec emacs-start-time)) 1000.0)) + ))) ;; End progn/lambda/add-hook after-init-hook + +(custom-set-variables + ;; custom-set-variables was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + '(custom-safe-themes + (quote + ("64f2981274fd8740b794bce9feee7949ed87b88fc0b4654bd98594e1aa81abcd" default))) + '(package-selected-packages + (quote + (racer cargo rust-mode company-quickhelp company projectile persp-mode avy ivy powerline which-key paradox use-package jbeans-theme))) + '(paradox-github-token t)) + +(custom-set-faces + ;; custom-set-faces was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + '(default ((t (:family "Inconsolata" :foundry "outline" :slant normal :weight normal :height 79 :width normal))))) diff --git a/local-lib/autocompletion-conf.el b/local-lib/autocompletion-conf.el new file mode 100644 index 0000000..0b5d200 --- /dev/null +++ b/local-lib/autocompletion-conf.el @@ -0,0 +1,30 @@ +;;; autocompletion-conf.el --- configuration for language auto-complete +;; Author: jason +;; Created: 16 Jun 2017 +;;; Commentary: +;; +;; Configures the auto-completion framework (company-mode) +;; +;;; Code: +(use-package company + :ensure t + :init + (setq + ;; Display the suggestion popup quickly + company-idle-delay 0.4 + ;; Display the suggestion popup after 1 character + company-minimum-prefix-length 1) + :config + (add-hook 'company-mode-hook '(lambda () + (progn + ;; I prefer to use TAB instead of RETURN to finish completion + (define-key company-active-map [return] nil) + (define-key company-active-map [tab] 'company-complete-selection))))) +;; Display documentation in a popup +(use-package company-quickhelp + :ensure t + :config + (add-hook 'company-mode-hook '(lambda () + (progn + (company-quickhelp-mode))))) +(provide 'autocompletion-conf) diff --git a/local-lib/rust-conf.el b/local-lib/rust-conf.el new file mode 100644 index 0000000..a0c7b7d --- /dev/null +++ b/local-lib/rust-conf.el @@ -0,0 +1,32 @@ +;;; rust-conf.el --- configuration for the rust language +;; Author: jason +;; Created: 16 Jun 2017 +;;; Commentary: +;; +;; Installation: +;; * Install Rust: https://www.rust-lang.org/en-US/install.html +;; * Install Racer: https://github.com/racer-rust/racer +;; * Install the Rust source: rustup component add rust-src - This goes to: +;; ~/.multirust/toolchains/[toolchain]/lib/rustlib/src/rust/src +;; * Define the RUST_SRC_PATH environment var to the source directory +;; +;;; Code: +(use-package rust-mode + :ensure t + :commands (rust-mode)) + +(use-package cargo + :ensure t + :commands (cargo-minor-mode)) + +(use-package racer + :ensure t + :commands (racer-mode)) + +(add-hook 'rust-mode-hook (lambda () + (progn + (racer-mode) + (cargo-minor-mode)))) +(add-hook 'racer-mode-hook #'company-mode) + +(provide 'rust-conf) -- cgit v1.2.1