Browse Source

emacs.el: Refactor to alternate structure

master
John 2 years ago
parent
commit
c9424816a4
No account linked to committer's email address
1 changed files with 324 additions and 362 deletions
  1. 324
    362
      etc/emacs/emacs.el

+ 324
- 362
etc/emacs/emacs.el View File

@@ -1,9 +1,8 @@
;; /etc/emacs/default.el

;; When Emacs is opened we should first adjust the appearance to what we
;; desire so that while configurations are being parsed we do not see the
;; default theme. We will disable various tool bars before they
;; initialize, then set the theme and font appearance.
;;;
;;; Startup
;;;

(when (fboundp 'menu-bar-mode) (menu-bar-mode -1))
(when (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
@@ -16,13 +15,6 @@
:family "Monospace" :weight 'normal
:width 'normal :height 96)


;; In this section we will set some ideal default behaviors such as
;; inhibiting any unwanted initial buffers, forcing utf-8 encoding,
;; showing column numbers in the mode line, enabling the visual-bell
;; which disables the audible bell, and moving custom configuration
;; to another file as to not append this to the bottom of this file.

(setq
;; Misc
initial-scratch-message nil
@@ -36,145 +28,102 @@
set-language-environment "UTF-8"
set-locale-environment "en_US.UTF-8")

;; Environment Variables
(setenv "EDITOR" "emacsclient")
(setenv "GIT_EDITOR" "emacsclient")
(setenv "GOPATH" (getenv "GOPATH"))
(setenv "MANPATH" (getenv "MANPATH"))
(setenv "PATH" (getenv "PATH"))
(setenv "PROMPT_COMMAND" "")
(setenv "SHELL" (getenv "SHELL"))
(setenv "TERM" (getenv "TERM"))


;;;
;;; Normalization
;;;

(setq
;; Cut/Paste
require-final-newline t
save-interprogram-paste-before-kill t
select-enable-primary nil

;; Display
column-number-mode t
visible-bell t

;; Indentation
c-basic-offset 4
cperl-indent-level 4
js-indent-level 4
tab-width 4
indent-tabs-mode nil)

(fset 'yes-or-no-p 'y-or-n-p) ;; Shorter y/n prompts
(global-visual-line-mode t) ;; Globally enable word-wrap
(show-paren-mode t) ;; Highlight matching parenthesis


;; Whenever possible, we should not load custom configurations until
;; after Emacs has finished initializing. This section relies on the
;; 'after-init-hook' to accomplish this.

(add-hook
'after-init-hook
(lambda()
(add-hook 'before-save-hook 'delete-trailing-whitespace)

(add-hook 'lisp-mode-hook
(lambda()
(add-hook 'before-save-hook
(lambda() (untabify (point-min)(point-max))))
(linum-mode)))

(add-hook 'prog-mode-hook
(lambda()
(linum-mode)))

(add-hook 'text-mode-hook
(lambda()
(add-hook 'before-save-hook
(lambda() (untabify (point-min)(point-max))))
(linum-mode)))

(add-hook 'c-mode-hook
(lambda()
(add-to-list 'auto-mode-alist '("\\.h\\'" . c-mode))
(setq indent-tabs-mode 1)))

(add-hook 'c++-mode-hook
(lambda()
(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
(setq indent-tabs-mode 1)))

(add-hook 'python-mode-hook
(lambda()
(add-hook 'before-save-hook
(lambda() (untabify (point-min)(point-max))))))

(setq
;; Cut/Paste
require-final-newline t
save-interprogram-paste-before-kill t
select-enable-primary nil

;; Display
column-number-mode t
visible-bell t

;; Indentation
c-basic-offset 4
cperl-indent-level 4
js-indent-level 4
tab-width 4
indent-tabs-mode nil

;; Mouse
mouse-wheel-follow-mouse 't
mouse-wheel-progressive-speed nil
mouse-wheel-scroll-amount '(3 ((shift) . 3))
mouse-yank-at-point t

;; Scrolling
auto-window-vscroll nil
scroll-conservatively 101
scroll-down-aggressively 0.0
scroll-margin 0
scroll-preserve-screen-position 1
scroll-step 1
scroll-up-aggressively 0.0)

;; Shorter y/n prompts
(fset 'yes-or-no-p 'y-or-n-p)

;; Globally enable word-wrap
(global-visual-line-mode t)

;; Highlight matching parenthesis
(show-paren-mode t)

;; Enable mouse support in terminal
(xterm-mouse-mode t)

;; Environment Variables
(setenv "EDITOR" "emacsclient")
(setenv "GIT_EDITOR" "emacsclient")
(setenv "GOPATH" (getenv "GOPATH"))
(setenv "MANPATH" (getenv "MANPATH"))
(setenv "PATH" (getenv "PATH"))
(setenv "PROMPT_COMMAND" "")
(setenv "SHELL" (getenv "SHELL"))
(setenv "TERM" (getenv "TERM"))

;; Buffers
(global-set-key (kbd "C-x x") 'kill-buffer-and-window)
(global-set-key (kbd "<C-tab>") 'next-buffer)
(global-set-key (kbd "<C-iso-lefttab>") 'previous-buffer)
(global-set-key (kbd "M--") (lambda() (interactive)
(split-window-vertically)
(other-window 1 nil)
(switch-to-next-buffer)))
(global-set-key (kbd "M-=") (lambda() (interactive)
(split-window-horizontally)
(other-window 1 nil)
(switch-to-next-buffer)))

;; Comment or uncomment the highlighted region
(global-set-key (kbd "C-c c") 'comment-or-uncomment-region)

;; Mouse
(global-set-key (kbd "<mouse-4>") (lambda() (interactive)
(scroll-down 3)))
(global-set-key (kbd "<mouse-5>") (lambda() (interactive)
(scroll-up 3)))

;; Movement
(global-set-key (kbd "<M-down>") 'windmove-down)
(global-set-key (kbd "<M-left>") 'windmove-left)
(global-set-key (kbd "<M-right>") 'windmove-right)
(global-set-key (kbd "<M-up>") 'windmove-up)
(global-set-key (kbd "C-c <down>") 'windmove-down)
(global-set-key (kbd "C-c <left>") 'windmove-left)
(global-set-key (kbd "C-c <right>") 'windmove-right)
(global-set-key (kbd "C-c <up>") 'windmove-up)

;; Autoload custom file
(if (file-exists-p custom-file)
(load custom-file)
(write-region "" nil custom-file))))


;; Package management in Emacs has a few hiccups and this section is
;; meant to mitigate them. We will set the repositories to use and the
;; order in which to use them so that we are using stable packages
;; whenever possible. Additionally, we will install use-package if it is
;; not already present and set 'ensure' on all future use-package
;; declarations.
;;;
;;; Input
;;;

;; Enable mouse support in terminal
(xterm-mouse-mode t)

(setq
;; Mouse
mouse-wheel-follow-mouse 't
mouse-wheel-progressive-speed nil
mouse-wheel-scroll-amount '(3 ((shift) . 3))
mouse-yank-at-point t

;; Scrolling
auto-window-vscroll nil
scroll-conservatively 101
scroll-down-aggressively 0.0
scroll-margin 0
scroll-preserve-screen-position 1
scroll-step 1
scroll-up-aggressively 0.0)

;; Buffers
(global-set-key (kbd "C-x x") 'kill-buffer-and-window)
(global-set-key (kbd "<C-tab>") 'next-buffer)
(global-set-key (kbd "<C-iso-lefttab>") 'previous-buffer)
(global-set-key (kbd "M--") (lambda() (interactive)
(split-window-vertically)
(other-window 1 nil)
(switch-to-next-buffer)))
(global-set-key (kbd "M-=") (lambda() (interactive)
(split-window-horizontally)
(other-window 1 nil)
(switch-to-next-buffer)))

;; Comment or uncomment the highlighted region
(global-set-key (kbd "C-c c") 'comment-or-uncomment-region)

;; Mouse
(global-set-key (kbd "<mouse-4>") (lambda() (interactive)
(scroll-down 3)))
(global-set-key (kbd "<mouse-5>") (lambda() (interactive)
(scroll-up 3)))

;; Movement
(global-set-key (kbd "<M-down>") 'windmove-down)
(global-set-key (kbd "<M-left>") 'windmove-left)
(global-set-key (kbd "<M-right>") 'windmove-right)
(global-set-key (kbd "<M-up>") 'windmove-up)
(global-set-key (kbd "C-c <down>") 'windmove-down)
(global-set-key (kbd "C-c <left>") 'windmove-left)
(global-set-key (kbd "C-c <right>") 'windmove-right)
(global-set-key (kbd "C-c <up>") 'windmove-up)


;;;
;;; Package Management
;;;

(require 'package)
(setq package-user-dir "~/.emacs.d/pkg/"
@@ -196,11 +145,9 @@
(setq use-package-always-ensure t)


;; This section contains use-package definitions for any package that
;; currently ships with Emacs. If the package does not exist such as
;; with older versions, they will be installed. Extra consideration has
;; been taken to only apply settings when a package is used as to reduce
;; the time needed to initialize Emacs.
;;;
;;; Utilities
;;;

(use-package async
:config (async-bytecomp-package-mode '(all)))
@@ -212,77 +159,63 @@

(use-package auto-dictionary)

(use-package eshell
(use-package cmake-ide
:config (cmake-ide-setup))

(use-package company
:config
(setq eshell-cmpl-cycle-completions nil
eshell-error-if-no-glob t
eshell-hist-ignoredups t
eshell-history-size 4096
eshell-prefer-lisp-functions t
eshell-save-history-on-exit t
eshell-scroll-to-bottom-on-input nil
eshell-scroll-to-bottom-on-output nil
eshell-scroll-show-maximum-output nil

eshell-visual-commands
'("alsamixer" "htop" "top" "nano" "vi" "vim" "less" "ssh" "tail"
"watch")

eshell-prompt-regexp "^[^#$\n]*[#$] "

eshell-prompt-function
(lambda nil
(concat
"[" (user-login-name) "@" (system-name) " "
(if (string= (eshell/pwd) (getenv "HOME"))
"~" (eshell/basename (eshell/pwd)))
"]"
(if (= (user-uid) 0) "# " "$ "))))
(add-hook 'prog-mode-hook 'company-mode)
(add-hook 'text-mode-hook 'company-mode))

(defun eshell/clear()
(interactive)
(recenter 0))
(use-package company-irony
:config (add-to-list 'company-backends 'company-irony))

(defun eshell-new()
"Open a new instance of eshell."
(interactive)
(eshell 'N)))
(use-package company-irony-c-headers
:config
(add-to-list 'company-backends
'(company-irony-c-headers company-irony)))

(use-package eww
(use-package counsel
:bind (("<f1> f" . counsel-describe-function)
("<f1> l" . counsel-find-library)
("<f1> v" . counsel-describe-variable)
("<f2> i" . counsel-info-lookup-symbol)
("<f2> u" . counsel-unicode-char)
("C-S-o" . counsel-rhythmbox)
("C-c g" . counsel-git)
("C-c j" . counsel-git-grep)
("C-c l" . counsel-ag)
("C-r" . counsel-minibuffer-history)
("C-x C-f" . counsel-find-file)
("C-x l" . counsel-locate)
("M-x" . counsel-M-x)))

(use-package diff-hl
:config
(setq browse-url-browser-function 'eww-browse-url
shr-blocked-images "")
(add-hook 'prog-mode-hook 'diff-hl-mode)
(add-hook 'text-mode-hook 'diff-hl-mode))

(defun eww-toggle-images()
"Toggle blocking images in eww."
(interactive)
(if (bound-and-true-p shr-blocked-images)
(setq shr-blocked-images nil)
(setq shr-blocked-images ""))
(eww-reload))
(use-package eww-lnum
:config
(define-key eww-mode-map "f" 'eww-lnum-follow)
(define-key eww-mode-map "F" 'eww-lnum-universal))

(defun eww-new()
"Open a new instance of eww."
(interactive)
(let ((url (read-from-minibuffer "Enter URL or keywords: ")))
(switch-to-buffer (generate-new-buffer "*eww*"))
(eww-mode)
(eww url))))
(use-package flycheck
:config (add-hook 'prog-mode-hook 'flycheck-mode))

(use-package gnus
(use-package flymake)

(use-package flyspell
:config
(gnus-add-configuration
'(article
(horizontal 1.0
(vertical 25 (group 1.0))
(vertical 1.0
(summary 0.25 point)
(article 1.0)))))
(gnus-add-configuration
'(summary
(horizontal 1.0
(vertical 25 (group 1.0))
(vertical 1.0 (summary 1.0 point))))))
(add-hook 'flyspell-mode-hook (auto-dictionary-mode 1))
(add-hook 'markdown-mode-hook 'flyspell-mode)
(add-hook 'prog-mode-hook 'flyspell-prog-mode)
(add-hook 'text-mode-hook 'flyspell-mode))

(use-package highlight-indent-guides
:config
(add-hook 'prog-mode-hook 'highlight-indent-guides-mode)
(setq highlight-indent-guides-method 'character))

(use-package ibuffer
:bind ("C-x C-b" . ibuffer)
@@ -293,13 +226,51 @@
(ibuffer-do-sort-by-major-mode)
(ibuffer-auto-mode t))))

(use-package scratch
(use-package irony
:config
(defun scratch-new()
"Open a new scratch buffer."
(interactive)
(switch-to-buffer (generate-new-buffer "*scratch*"))
(lisp-mode)))
(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'c-mode-hook 'irony-mode)
(add-hook 'objc-mode-hook 'irony-mode)
(add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
(define-key irony-mode-map [remap completion-at-point] 'counsel-irony)
(define-key irony-mode-map [remap complete-symbol] 'counsel-irony)
(setq irony-additional-clang-options '("-std=c++14")))

(use-package ivy
:bind (("C-c C-r" . ivy-resume)
("<f6>" . ivy-resume))
:config
(ivy-mode 1)
(setq ivy-use-virtual-buffers t
enable-recursive-minibuffers t))

(use-package linum
:config
(add-hook 'lisp-mode-hook 'linum-mode)
(add-hook 'prog-mode-hook 'linum-mode)
(add-hook 'text-mode-hook 'linum-mode))

(use-package no-littering
:config
(setq
auto-save-file-name-transforms
`((".*" ,(no-littering-expand-var-file-name "auto-save/") t))))

(use-package rainbow-delimiters
:config
(add-hook 'markdown-mode-hook 'rainbow-delimiters-mode)
(add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
(add-hook 'text-mode-hook 'rainbow-delimiters-mode))

(use-package smartparens
:config
(add-hook 'markdown-mode-hook 'smartparens-mode)
(add-hook 'prog-mode-hook 'smartparens-mode)
(add-hook 'text-mode-hook 'smartparens-mode)
(setq
sp-highlight-pair-overlay nil
sp-highlight-wrap-overlay nil
sp-highlight-wrap-tag-overlay nil))

(use-package server
:bind ("C-x C-c" . server-stop)
@@ -325,32 +296,39 @@
(package-refresh-contents))
(package-utils-upgrade-all)))

(use-package swiper
:bind ("C-s" . swiper))

(use-package undo-tree
:config (global-undo-tree-mode))

(use-package xclip
:config (xclip-mode 1))


;; This section defines additional packages which typically do not ship
;; with emacs that will be installed and configured when issued.
;;;
;;; Applications
;;;

(use-package circe
:config
(if (file-exists-p "~/.emacs.d/circe.el")
(load-file "~/.emacs.d/circe.el"))

(setq circe-default-part-message ""
circe-default-quit-message ""
circe-format-server-topic "*** Topic change by {userhost}: {topic-diff}"
circe-reduce-lurker-spam t
circe-use-cycle-completion t
lui-fill-type nil
lui-flyspell-alist '((".*" "american"))
lui-flyspell-p t
lui-time-stamp-format "%H:%M:%S"
lui-time-stamp-position 'left-margin)
(setq
circe-default-part-message ""
circe-default-quit-message ""
circe-format-server-topic "*** Topic change by {userhost}: {topic-diff}"
circe-reduce-lurker-spam t
circe-use-cycle-completion t
lui-fill-type nil
lui-flyspell-alist '((".*" "american"))
lui-flyspell-p t
lui-time-stamp-format "%H:%M:%S"
lui-time-stamp-position 'left-margin)

(require 'circe-chanop)
(enable-circe-color-nicks)

(defun my-circe-set-margin() (setq left-margin-width 9))
(setf (cdr (assoc 'continuation fringe-indicator-alist)) nil)

@@ -375,75 +353,136 @@
(add-hook 'circe-message-option-functions 'my-circe-message-option-chanserv)
(add-hook 'lui-mode-hook (lambda() (my-lui-setup) (my-circe-set-margin))))

(use-package cmake-ide
:config (cmake-ide-setup))

(use-package cmake-mode)
(use-package elfeed
:bind ("C-x w" . elfeed)
:config
(setq
elfeed-search-filter "@1-week-ago +unread "
url-queue-timeout 30)
(if (file-exists-p "~/.emacs.d/elfeed.el")
(load-file "~/.emacs.d/elfeed.el")))

(use-package company
(use-package eshell
:config
(add-hook 'prog-mode-hook 'company-mode)
(add-hook 'text-mode-hook 'company-mode))
(setq
eshell-cmpl-cycle-completions nil
eshell-error-if-no-glob t
eshell-hist-ignoredups t
eshell-history-size 4096
eshell-prefer-lisp-functions t
eshell-save-history-on-exit t
eshell-scroll-to-bottom-on-input nil
eshell-scroll-to-bottom-on-output nil
eshell-scroll-show-maximum-output nil

eshell-visual-commands
'("alsamixer" "atop" "htop" "less" "mosh" "nano" "ssh" "tail"
"top" "vi" "vim" "watch" )

eshell-prompt-regexp "^[^#$\n]*[#$] "
eshell-prompt-function
(lambda nil
(concat
"[" (user-login-name) "@" (system-name) " "
(if (string= (eshell/pwd) (getenv "HOME"))
"~" (eshell/basename (eshell/pwd)))
"]"
(if (= (user-uid) 0) "# " "$ "))))

(use-package company-irony
:config (add-to-list 'company-backends 'company-irony))
(defun eshell/clear()
(interactive)
(recenter 0))

(use-package company-irony-c-headers
(defun eshell-new()
"Open a new instance of eshell."
(interactive)
(eshell 'N)))

(use-package eww
:config
(add-to-list 'company-backends
'(company-irony-c-headers company-irony)))
(setq
browse-url-browser-function 'eww-browse-url
shr-blocked-images "")

(use-package counsel
:bind (("<f1> f" . counsel-describe-function)
("<f1> l" . counsel-find-library)
("<f1> v" . counsel-describe-variable)
("<f2> i" . counsel-info-lookup-symbol)
("<f2> u" . counsel-unicode-char)
("C-S-o" . counsel-rhythmbox)
("C-c g" . counsel-git)
("C-c j" . counsel-git-grep)
("C-c l" . counsel-ag)
("C-r" . counsel-minibuffer-history)
("C-x C-f" . counsel-find-file)
("C-x l" . counsel-locate)
("M-x" . counsel-M-x)))
(defun eww-toggle-images()
"Toggle blocking images in eww."
(interactive)
(if (bound-and-true-p shr-blocked-images)
(setq shr-blocked-images nil)
(setq shr-blocked-images ""))
(eww-reload))

(use-package diff-hl
:config
(add-hook 'prog-mode-hook 'diff-hl-mode)
(add-hook 'text-mode-hook 'diff-hl-mode))
(defun eww-new()
"Open a new instance of eww."
(interactive)
(let ((url (read-from-minibuffer "Enter URL or keywords: ")))
(switch-to-buffer (generate-new-buffer "*eww*"))
(eww-mode)
(eww url))))

(use-package dockerfile-mode)
(use-package gist)

(use-package elfeed
:bind ("C-x w" . elfeed)
(use-package gnus
:config
(setq elfeed-search-filter "@1-week-ago +unread "
url-queue-timeout 30)
(gnus-add-configuration
'(article
(horizontal 1.0
(vertical 25 (group 1.0))
(vertical 1.0
(summary 0.25 point)
(article 1.0)))))
(gnus-add-configuration
'(summary
(horizontal 1.0
(vertical 25 (group 1.0))
(vertical 1.0 (summary 1.0 point))))))

(if (file-exists-p "~/.emacs.d/elfeed.el")
(load-file "~/.emacs.d/elfeed.el")))
(use-package magit)
(use-package pdf-tools)
(use-package ranger)
(use-package realgud)

(use-package eww-lnum
(use-package scratch
:config
(define-key eww-mode-map "f" 'eww-lnum-follow)
(define-key eww-mode-map "F" 'eww-lnum-universal))
(defun scratch-new()
"Open a new scratch buffer."
(interactive)
(switch-to-buffer (generate-new-buffer "*scratch*"))
(lisp-mode)))

(use-package flycheck
:config (add-hook 'prog-mode-hook 'flycheck-mode))

(use-package flymake)
;;;
;;; Language Modes
;;;

(use-package flyspell
:config
(add-hook 'flyspell-mode-hook (auto-dictionary-mode 1))
(add-hook 'markdown-mode-hook 'flyspell-mode)
(add-hook 'prog-mode-hook 'flyspell-prog-mode)
(add-hook 'text-mode-hook 'flyspell-mode))
(add-hook 'before-save-hook 'delete-trailing-whitespace)

(use-package gist)
(add-hook 'lisp-mode-hook
(lambda()
(add-hook 'before-save-hook
(lambda()
(untabify (point-min)(point-max))))))

(add-hook 'text-mode-hook
(lambda()
(add-hook 'before-save-hook
(lambda()
(untabify (point-min)(point-max))))))

(add-hook 'c-mode-hook
(lambda()
(add-to-list 'auto-mode-alist '("\\.h\\'" . c-mode))
(setq indent-tabs-mode 1)))

(add-hook 'c++-mode-hook
(lambda()
(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
(setq indent-tabs-mode 1)))

(use-package cmake-mode)
(use-package dockerfile-mode)
(use-package gitconfig-mode)
(use-package gitignore-mode)

(use-package go-mode
:config
@@ -453,88 +492,11 @@
(setq tab-width 4
indent-tabs-mode 1))))

(use-package haml-mode)

(use-package highlight-indent-guides
:config
(add-hook 'prog-mode-hook 'highlight-indent-guides-mode)

(setq highlight-indent-guides-method 'character))

(use-package irony
:config
(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'c-mode-hook 'irony-mode)
(add-hook 'objc-mode-hook 'irony-mode)
(add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
(define-key irony-mode-map [remap completion-at-point] 'counsel-irony)
(define-key irony-mode-map [remap complete-symbol] 'counsel-irony)


(setq irony-additional-clang-options '("-std=c++14")))

(use-package ivy
:bind (("C-c C-r" . ivy-resume)
("<f6>" . ivy-resume))
:config
(ivy-mode 1)
(setq ivy-use-virtual-buffers t
enable-recursive-minibuffers t))

(use-package json-mode)

(use-package less-css-mode)

(use-package lua-mode)

(use-package magit)

(use-package meson-mode)

(use-package nginx-mode)

(use-package no-littering
:config
(setq auto-save-file-name-transforms
`((".*" ,(no-littering-expand-var-file-name "auto-save/") t))))

(use-package nov
:config (add-to-list 'auto-mode-alist '("\\.epub\\'" . nov-mode)))

(use-package pdf-tools)

(use-package php-mode)

(use-package rainbow-delimiters
:config
(add-hook 'markdown-mode-hook 'rainbow-delimiters-mode)
(add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
(add-hook 'text-mode-hook 'rainbow-delimiters-mode))

(use-package realgud)

(use-package rjsx-mode)

(use-package ranger)

(use-package scss-mode)

(use-package smartparens
:config
(add-hook 'markdown-mode-hook 'smartparens-mode)
(add-hook 'prog-mode-hook 'smartparens-mode)
(add-hook 'text-mode-hook 'smartparens-mode)

(setq sp-highlight-pair-overlay nil
sp-highlight-wrap-overlay nil
sp-highlight-wrap-tag-overlay nil))

(use-package swiper
:bind ("C-s" . swiper))

(use-package systemd)

(use-package undo-tree
:config (global-undo-tree-mode))

(use-package yaml-mode)

Loading…
Cancel
Save