Moves helper functions to separate file

This commit is contained in:
William Carroll 2017-05-31 23:58:17 -04:00
parent 39b0e5056b
commit 23f4e84ada
2 changed files with 480 additions and 439 deletions

View file

@ -113,15 +113,9 @@
(powerline-default-theme)) (powerline-default-theme))
(defun wc/projectile-shell-pop () ;; Load custom Emacs functions
"Opens `ansi-term' at the project root according to Projectile." (load "~/.emacs/wc-helper-functions.lisp")
(interactive)
(let ((default-directory (projectile-project-root)))
(if (get-buffer "*ansi-term*")
(switch-to-buffer "*ansi-term*")
(ansi-term "/bin/zsh"))
(term-send-string (terminal) (format "cd '%s'\n" default-directory))
(get-buffer-process "*ansi-term*")))
;; ERC configuration (IRC in Emacs) ;; ERC configuration (IRC in Emacs)
(use-package erc (use-package erc
@ -130,12 +124,6 @@
(setq erc-autojoin-channels-alist '(("freenode.net" "#emacs" "#elixir")))) (setq erc-autojoin-channels-alist '(("freenode.net" "#emacs" "#elixir"))))
(defun wc/join-erc ()
"Boots `erc' and autojoins channels."
(interactive)
(erc :server "irc.freenode.net" :port "6667" :nick "wpcarro"))
;; Disable fringes in Emacs ;; Disable fringes in Emacs
(fringe-mode 0) (fringe-mode 0)
@ -192,16 +180,6 @@
:ensure t) :ensure t)
(defun wc/bootstrap-ansi-term ()
"Custom `ansi-term' configuration."
(interactive)
(linum-mode nil)
(local-set-key (kbd "C-h") 'evil-window-left)
(local-set-key (kbd "C-l") 'evil-window-right)
(local-set-key (kbd "C-k") 'evil-window-up)
(local-set-key (kbd "C-j") 'evil-window-down)
(define-key term-raw-map (kbd "s-v") 'term-paste))
(defadvice term-sentinel (around my-advice-term-sentinel (proc msg)) (defadvice term-sentinel (around my-advice-term-sentinel (proc msg))
(if (memq (process-status proc) '(signal exit)) (if (memq (process-status proc) '(signal exit))
(let ((buffer (process-buffer proc))) (let ((buffer (process-buffer proc)))
@ -211,15 +189,6 @@
(ad-activate 'term-sentinel) (ad-activate 'term-sentinel)
(defun wc/ansi-term-paste (&optional string)
"Paste into `ansi-term'."
(interactive)
(process-send-string
(get-buffer-process (current-buffer))
(if string string (current-kill 0)))))
;; Ansi-Term ;; Ansi-Term
(use-package term (use-package term
:ensure t :ensure t
@ -330,30 +299,11 @@
(call-interactively 'evil-scroll-line-to-center)) (call-interactively 'evil-scroll-line-to-center))
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/") (add-to-list 'custom-theme-load-path "~/.emacs.d/themes/")
(defun evil-window-vsplit-right () ;; Evil Leader Settings
"Vertically split a window and move right." (use-package evil-leader
(interactive)
(evil-window-vsplit nil)
(evil-window-right 1))
(defun evil-window-split-down ()
"Split a window and move right."
(interactive)
(evil-window-split nil)
(evil-window-down 1))
(defun wc/switch-to-mru-buffer ()
"Switches to the most recently used buffer, including visible buffers."
(interactive)
(switch-to-buffer (other-buffer (current-buffer) t (selected-frame))))
;; Evil Leader Settings
(use-package evil-leader
:ensure t :ensure t
:commands (global-evil-leader-mode) :commands (global-evil-leader-mode)
:config :config
@ -386,68 +336,55 @@
)) ))
;; Evil Match-it ;; Evil Match-it
(use-package evil-matchit (use-package evil-matchit
:ensure t :ensure t
:commands (global-evil-matchit-mode)) :commands (global-evil-matchit-mode))
;; Evil Surround ;; Evil Surround
(use-package evil-surround (use-package evil-surround
:ensure t :ensure t
:commands (global-evil-surround-mode)) :commands (global-evil-surround-mode))
;; Flycheck Mix Settings ;; Flycheck Mix Settings
(use-package flycheck-mix (use-package flycheck-mix
:ensure t :ensure t
:init :init
(flycheck-mix-setup)) (flycheck-mix-setup))
;; Flycheck ;; Flycheck
(use-package flycheck (use-package flycheck
:ensure t :ensure t
:config :config
(setq flycheck-display-errors-function 'ignore)) (setq flycheck-display-errors-function 'ignore))
;; Flycheck Credo Settings ;; Flycheck Credo Settings
(use-package flycheck-credo (use-package flycheck-credo
:ensure t :ensure t
:init :init
(flycheck-credo-setup)) (flycheck-credo-setup))
;; Popwin Settings ;; Popwin Settings
(use-package popwin (use-package popwin
:ensure t) :ensure t)
(defun *-popwin-help-mode-off ()
"Turn `popwin-mode' off for *Help* buffers."
(when (boundp 'popwin:special-display-config) (add-hook 'helm-minibuffer-set-up-hook #'*-popwin-help-mode-off)
(customize-set-variable 'popwin:special-display-config (add-hook 'helm-cleanup-hook #'*-popwin-help-mode-on)
(delq 'help-mode popwin:special-display-config))))
(defun *-popwin-help-mode-on () (setq display-buffer-function 'popwin:display-buffer)
"Turn `popwin-mode' on for *Help* buffers." (setq helm-split-window-preferred-function 'ignore)
(push '("^\*helm .+\*$" :regexp t) popwin:special-display-config)
(when (boundp 'popwin:special-display-config) (push '("^\*helm-.+\*$" :regexp t) popwin:special-display-config)
(customize-set-variable 'popwin:special-display-config
(add-to-list 'popwin:special-display-config 'help-mode nil #'eq))))
(add-hook 'helm-minibuffer-set-up-hook #'*-popwin-help-mode-off)
(add-hook 'helm-cleanup-hook #'*-popwin-help-mode-on)
(setq display-buffer-function 'popwin:display-buffer)
(setq helm-split-window-preferred-function 'ignore)
(push '("^\*helm .+\*$" :regexp t) popwin:special-display-config)
(push '("^\*helm-.+\*$" :regexp t) popwin:special-display-config)
;; Alchemist Settings ;; Alchemist Settings
(use-package alchemist (use-package alchemist
:ensure t :ensure t
:config :config
(setq alchemist-mix-env "prod") (setq alchemist-mix-env "prod")
@ -456,27 +393,12 @@
:init :init
(linum-mode)) (linum-mode))
(defun custom-erlang-mode-hook ()
"Jump to and from Elixir, Erlang, Elixir files."
(define-key erlang-mode-map (kbd "M-,") 'alchemist-goto-jump-back))
(add-hook 'erlang-mode-hook 'custom-erlang-mode-hook) (add-hook 'erlang-mode-hook 'wc/custom-erlang-mode-hook)
(defun helm-ag-neotree-node () ;; NeoTree Settings
"Run Helm-ag on Neotree directory." (use-package neotree
(interactive)
(let ((search-root (neo-buffer--get-filename-current-line)))
(if search-root
;; search directory
(progn
(evil-window-right 1)
(helm-ag search-root))
(message "Could not find directory at point."))))
;; NeoTree Settings
(use-package neotree
:ensure t :ensure t
:bind (:map neotree-mode-map :bind (:map neotree-mode-map
("j" . next-line) ("j" . next-line)
@ -497,47 +419,9 @@
(setq neo-theme (if (display-graphic-p) 'icons 'arrow)) (setq neo-theme (if (display-graphic-p) 'icons 'arrow))
(setq-default neo-show-hidden-files t)) (setq-default neo-show-hidden-files t))
(defun neotree-toggle-project-dir ()
"Toggle neotree sidebar."
(interactive)
(let ((project-dir (projectile-project-root))
(file-name (buffer-file-name)))
(neotree-toggle)
(if project-dir
(if (neo-global--window-exists-p)
(progn
(neotree-dir project-dir)
(neotree-show)
(evil-window-mru)))
(message "Could not find git project root."))))
;; Whitespace Settings
(defun neotree-reveal-current-buffer () (use-package whitespace
"Reveal current buffer in Neotree."
(interactive)
(let ((project-dir (projectile-project-root))
(file-name (buffer-file-name)))
(neotree-show)
(if project-dir
(if (neo-global--window-exists-p)
(progn
(neotree-dir project-dir)
(neotree-find file-name)
(evil-window-mru)))
(message "Could not find git project root."))))
(defun message-project-root ()
"Outputs project-root."
(interactive)
(let (project-dir (projectile-project-root))
(if project-dir
(message "Project dir found!")
(message "No project-dir found."))))
;; Whitespace Settings
(use-package whitespace
:ensure t :ensure t
:commands (whitespace-mode) :commands (whitespace-mode)
:config :config
@ -545,8 +429,8 @@
(setq whitespace-style '(face lines-tail))) (setq whitespace-style '(face lines-tail)))
;; Helm Settings ;; Helm Settings
(use-package helm (use-package helm
:ensure t :ensure t
:commands (helm-mode) :commands (helm-mode)
:bind ( :bind (
@ -566,19 +450,19 @@
(setq helm-locate-fuzzy-match t)) (setq helm-locate-fuzzy-match t))
;; Helm Projectile Settings ;; Helm Projectile Settings
(use-package helm-projectile (use-package helm-projectile
:ensure t) :ensure t)
;; Elm Mode ;; Elm Mode
(use-package elm-mode (use-package elm-mode
:config :config
(add-to-list 'company-backends 'company-elm)) (add-to-list 'company-backends 'company-elm))
;; Company Settings ;; Company Settings
(use-package company (use-package company
:bind ( :bind (
("C-j" . company-select-next) ("C-j" . company-select-next)
("C-k" . company-select-previous)) ("C-k" . company-select-previous))
@ -586,106 +470,63 @@
(setq company-idle-delay 0)) (setq company-idle-delay 0))
(add-hook 'after-init-hook 'evil-mode) (add-hook 'after-init-hook 'evil-mode)
(add-hook 'after-init-hook 'global-whitespace-mode) (add-hook 'after-init-hook 'global-whitespace-mode)
(add-hook 'after-init-hook 'global-hl-line-mode) (add-hook 'after-init-hook 'global-hl-line-mode)
(add-hook 'after-init-hook 'global-linum-mode) (add-hook 'after-init-hook 'global-linum-mode)
(add-hook 'after-init-hook 'global-flycheck-mode) (add-hook 'after-init-hook 'global-flycheck-mode)
(add-hook 'after-init-hook 'global-company-mode) (add-hook 'after-init-hook 'global-company-mode)
(add-hook 'after-init-hook 'projectile-mode) (add-hook 'after-init-hook 'projectile-mode)
(add-hook 'after-init-hook 'helm-mode) (add-hook 'after-init-hook 'helm-mode)
(add-hook 'before-save-hook 'delete-trailing-whitespace) (add-hook 'before-save-hook 'delete-trailing-whitespace)
;; Scrolling Settings ;; Scrolling Settings
(setq scroll-step 1) (setq scroll-step 1)
(setq scroll-conservatively 10000) (setq scroll-conservatively 10000)
;; Properly configure GUI Emacs to use $PATH values ;; Properly configure GUI Emacs to use $PATH values
(when (memq window-system '(mac ns)) (when (memq window-system '(mac ns))
(exec-path-from-shell-initialize)) (exec-path-from-shell-initialize))
;; Emacs backup / autosave files ;; Emacs backup / autosave files
;; (setq-default make-backup-files nil) ;; (setq-default make-backup-files nil)
(setq backup-directory-alist `(("." . "~/.emacs-tmp"))) (setq backup-directory-alist `(("." . "~/.emacs-tmp")))
(setq auto-save-file-name-transforms `((".*" "~/.emacs-tmp/" t))) (setq auto-save-file-name-transforms `((".*" "~/.emacs-tmp/" t)))
;; Automatically follow symlinks ;; Automatically follow symlinks
(setq vc-follow-symlinks t) (setq vc-follow-symlinks t)
;; Commenting / Uncommenting ;; Commenting / Uncommenting
(global-set-key (kbd "C-x C-;") 'comment-or-uncomment-region) (global-set-key (kbd "C-x C-;") 'comment-or-uncomment-region)
;; Fullscreen settings ;; Fullscreen settings
(setq ns-use-native-fullscreen nil) (setq ns-use-native-fullscreen nil)
(global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen) (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
;; General Settings ;; General Settings
;; Hide the menu-bar ;; Hide the menu-bar
(setq ns-auto-hide-menu-bar t) (setq ns-auto-hide-menu-bar t)
;; Native App Settings ;; Native App Settings
(tool-bar-mode -1) (tool-bar-mode -1)
;; Disable GUI scrollbars ;; Disable GUI scrollbars
(when (display-graphic-p) (when (display-graphic-p)
(scroll-bar-mode -1) (scroll-bar-mode -1)
) )
;; Use spaces instead of tabs ;; Use spaces instead of tabs
(setq-default indent-tabs-mode nil) (setq-default indent-tabs-mode nil)
;; Change font settings ;; Change font settings
(add-to-list 'default-frame-alist '(font . "Menlo-12")) (add-to-list 'default-frame-alist '(font . "Menlo-12"))
;; Force save buffers
(defun save-buffer-always ()
"Save the buffer even if it is not modified."
(interactive)
(set-buffer-modified-p t)
(save-buffer))
(global-set-key (kbd "C-x C-s") nil)
(global-set-key (kbd "C-x C-s") 'save-buffer-always)
;; Upgrade all packages
(defun package-upgrade-all ()
"Upgrade all packages automatically without showing *Packages* buffer."
(interactive)
(package-refresh-contents)
(let (upgrades)
(cl-flet ((get-version (name where)
(let ((pkg (cadr (assq name where))))
(when pkg
(package-desc-version pkg)))))
(dolist (package (mapcar #'car package-alist))
(let ((in-archive (get-version package package-archive-contents)))
(when (and in-archive
(version-list-< (get-version package package-alist)
in-archive))
(push (cadr (assq package package-archive-contents))
upgrades)))))
(if upgrades
(when (yes-or-no-p
(message "Upgrade %d package%s (%s)? "
(length upgrades)
(if (= (length upgrades) 1) "" "s")
(mapconcat #'package-desc-full-name upgrades ", ")))
(save-window-excursion
(dolist (package-desc upgrades)
(let ((old-package (cadr (assq (package-desc-name package-desc)
package-alist))))
(package-install package-desc)
(package-delete old-package)))))
(message "All packages are up to date"))))
;; Colorscheme ;; Colorscheme
@ -699,3 +540,4 @@
;; Add transparency ;; Add transparency
(set-frame-parameter (selected-frame) 'alpha '(100 . 100)) (set-frame-parameter (selected-frame) 'alpha '(100 . 100))
(add-to-list 'default-frame-alist '(alpha . (100 . 100))) (add-to-list 'default-frame-alist '(alpha . (100 . 100)))
(put 'narrow-to-region 'disabled nil)

View file

@ -0,0 +1,199 @@
(defun wc/projectile-shell-pop ()
"Opens `ansi-term' at the project root according to Projectile."
(interactive)
(let ((default-directory (projectile-project-root)))
(if (get-buffer "*ansi-term*")
(switch-to-buffer "*ansi-term*")
(ansi-term "/bin/zsh"))
(term-send-string (terminal) (format "cd '%s'\n" default-directory))
(get-buffer-process "*ansi-term*")))
(defun wc/join-erc ()
"Boots `erc' and autojoins channels."
(interactive)
(erc :server "irc.freenode.net" :port "6667" :nick "wpcarro"))
(defun wc/bootstrap-ansi-term ()
"Custom `ansi-term' configuration."
(interactive)
(linum-mode nil)
(local-set-key (kbd "C-h") 'evil-window-left)
(local-set-key (kbd "C-l") 'evil-window-right)
(local-set-key (kbd "C-k") 'evil-window-up)
(local-set-key (kbd "C-j") 'evil-window-down)
(define-key term-raw-map (kbd "s-v") 'term-paste))
(defun wc/ansi-term-paste (&amp;optional string)
"Paste into `ansi-term'."
(interactive)
(process-send-string
(get-buffer-process (current-buffer))
(if string string (current-kill 0)))))
(defun evil-window-vsplit-right ()
"Vertically split a window and move right."
(interactive)
(evil-window-vsplit nil)
(evil-window-right 1))
(defun evil-window-split-down ()
"Split a window and move right."
(interactive)
(evil-window-split nil)
(evil-window-down 1))
(defun wc/switch-to-mru-buffer ()
"Switches to the most recently used buffer, including visible buffers."
(interactive)
(switch-to-buffer (other-buffer (current-buffer) t (selected-frame))))
(defun *-popwin-help-mode-off ()
"Turn `popwin-mode' off for *Help* buffers."
(when (boundp 'popwin:special-display-config)
(customize-set-variable 'popwin:special-display-config
(delq 'help-mode popwin:special-display-config))))
(defun *-popwin-help-mode-on ()
"Turn `popwin-mode' on for *Help* buffers."
(when (boundp 'popwin:special-display-config)
(customize-set-variable 'popwin:special-display-config
(add-to-list 'popwin:special-display-config 'help-mode nil #'eq))))
(defun wc/custom-erlang-mode-hook ()
"Jump to and from Elixir, Erlang, Elixir files."
(define-key erlang-mode-map (kbd "M-,") 'alchemist-goto-jump-back))
(defun helm-ag-neotree-node ()
"Run Helm-ag on Neotree directory."
(interactive)
(let ((search-root (neo-buffer--get-filename-current-line)))
(if search-root
;; search directory
(progn
(evil-window-right 1)
(helm-ag search-root))
(message "Could not find directory at point."))))
(defun neotree-toggle-project-dir ()
"Toggle neotree sidebar."
(interactive)
(let ((project-dir (projectile-project-root))
(file-name (buffer-file-name)))
(neotree-toggle)
(if project-dir
(if (neo-global--window-exists-p)
(progn
(neotree-dir project-dir)
(neotree-show)
(evil-window-mru)))
(message "Could not find git project root."))))
(defun neotree-reveal-current-buffer ()
"Reveal current buffer in Neotree."
(interactive)
(let ((project-dir (projectile-project-root))
(file-name (buffer-file-name)))
(neotree-show)
(if project-dir
(if (neo-global--window-exists-p)
(progn
(neotree-dir project-dir)
(neotree-find file-name)
(evil-window-mru)))
(message "Could not find git project root."))))
(defun save-buffer-always ()
"Save the buffer even if it is not modified."
(interactive)
(set-buffer-modified-p t)
(save-buffer))
(global-set-key (kbd "C-x C-s") nil)
(global-set-key (kbd "C-x C-s") 'save-buffer-always)
;; Upgrade all packages
(defun package-upgrade-all ()
"Upgrade all packages automatically without showing *Packages* buffer."
(interactive)
(package-refresh-contents)
(let (upgrades)
(cl-flet ((get-version (name where)
(let ((pkg (cadr (assq name where))))
(when pkg
(package-desc-version pkg)))))
(dolist (package (mapcar #'car package-alist))
(let ((in-archive (get-version package package-archive-contents)))
(when (and in-archive
(version-list-< (get-version package package-alist)
in-archive))
(push (cadr (assq package package-archive-contents))
upgrades)))))
(if upgrades
(when (yes-or-no-p
(message "Upgrade %d package%s (%s)? "
(length upgrades)
(if (= (length upgrades) 1) "" "s")
(mapconcat #'package-desc-full-name upgrades ", ")))
(save-window-excursion
(dolist (package-desc upgrades)
(let ((old-package (cadr (assq (package-desc-name package-desc)
package-alist))))
(package-install package-desc)
(package-delete old-package)))))
(message "All packages are up to date"))))
(defun message-project-root ()
"Outputs project-root."
(interactive)
(let (project-dir (projectile-project-root))
(if project-dir
(message "Project dir found!")
(message "No project-dir found."))))
;; Upgrade all packages
(defun package-upgrade-all ()
"Upgrade all packages automatically without showing *Packages* buffer."
(interactive)
(package-refresh-contents)
(let (upgrades)
(cl-flet ((get-version (name where)
(let ((pkg (cadr (assq name where))))
(when pkg
(package-desc-version pkg)))))
(dolist (package (mapcar #'car package-alist))
(let ((in-archive (get-version package package-archive-contents)))
(when (and in-archive
(version-list-< (get-version package package-alist)
in-archive))
(push (cadr (assq package package-archive-contents))
upgrades)))))
(if upgrades
(when (yes-or-no-p
(message "Upgrade %d package%s (%s)? "
(length upgrades)
(if (= (length upgrades) 1) "" "s")
(mapconcat #'package-desc-full-name upgrades ", ")))
(save-window-excursion
(dolist (package-desc upgrades)
(let ((old-package (cadr (assq (package-desc-name package-desc)
package-alist))))
(package-install package-desc)
(package-delete old-package)))))
(message "All packages are up to date"))))