Skip to content

Instantly share code, notes, and snippets.

@benzap
Last active September 14, 2023 14:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benzap/2895437 to your computer and use it in GitHub Desktop.
Save benzap/2895437 to your computer and use it in GitHub Desktop.
Emacs Configuration
;; add our main ~/.emacs.d/ to the load-path (if it hasn't already been done)
;;(add-to-list 'load-path "~/.emacs.d/")
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("marmalade" . "http://marmalade-repo.org/packages/")
("melpa" . "http://melpa.milkbox.net/packages/")))
(package-initialize)
;; Package Require function. It resolves any require dependencies
;; through the package manager.
(setq package-refresh-first-time nil)
(defun package-require (package-name)
"tries to require. If it fails, it retrieves the package and
tries to require again"
(if (not (require package-name nil t))
(progn
(if (not package-refresh-first-time)
(save-excursion
(package-refresh-contents)
(setq package-refresh-contents t)))
(package-install package-name)
(require package-name nil t))))
;;name of the klipmark computer
(setq klipmark-computer "CAMARO")
;; setting up shortcuts for klipmark
(defun klipmark-delete-qdms-txt ()
(interactive)
"deletes the qdms.txt file from the system"
(let* ((klipmark-log-filename "qdms.txt")
(klipmark-log-root "c:/")
(klipmark-log-filepath (concat klipmark-log-root klipmark-log-filename)))
(delete-file klipmark-log-filepath)))
(defun klipmark-reload-galaxy-service ()
(interactive)
"reloads the galaxy service"
(let* ((klipmark-galaxy-service-name "QDMS")
(klipmark-shell-sequence (concat
(format "sc stop %s && " klipmark-galaxy-service-name)
(format "sc start %s" klipmark-galaxy-service-name))))
(message klipmark-shell-sequence)
(shell-command klipmark-shell-sequence)
))
;;klipmark keybindings
(global-set-key (kbd "C-M-d") 'klipmark-reload-galaxy-service)
(global-set-key (kbd "C-M-o") 'klipmark-delete-qdms-txt)
;;;; Check if the system is windows, linux, or macos
;; Check if system is Darwin/Mac OS X
(defun system-type-is-darwin ()
(interactive)
"Return true if system is darwin-based (Mac OS X)"
(string-equal system-type "darwin")
)
;; Check if system is GNU/Linux
(defun system-type-is-gnu ()
(interactive)
"Return true if system is GNU/Linux-based"
(string-equal system-type "gnu/linux")
)
;; Check if system is Win32
(defun system-type-is-win32 ()
(interactive)
"Return true if system is GNU/Linux-based"
(string-equal system-type "windows-nt")
)
;;http://tinyurl.com/kk9eb
(if (system-type-is-win32)
(progn
(set-default-font
"-outline-Consolas-normal-r-normal-normal-14-97-96-96-c-*-iso8859-1")
(add-hook 'before-make-frame-hook
(lambda ()
(set-frame-font
"-outline-Consolas-normal-r-normal-normal-14-97-96-96-c-*-iso8859-1")
))))
;; Main Configuration
;;The window you will see everytime you start up emacs
;; setup a desktop saving, starting emacs will load the previous emacs files that were open
;;(require 'desktop)
;;(desktop-save-mode t)
(setq inhibit-splash-screen t)
(menu-bar-mode 0)
;only when it's in a window system
(when window-system
(toggle-scroll-bar -1)
(tool-bar-mode -1)
)
(global-set-key (kbd "C-; t")
'(lambda ()
(interactive)
(set-variable 'tab-width 4)))
(global-set-key (kbd "C-; C-t")
'(lambda ()
(interactive)
(set-variable 'tab-width 4)))
;;interesting package for producing keychords with
;; (key-chord-define-global )
(package-require 'key-chord)
(key-chord-mode 1)
;;for jumping around
(package-require 'ace-jump-mode)
(global-set-key (kbd "C-'") 'ace-jump-mode)
(package-require 'expand-region)
(key-chord-define-global ",." 'er/expand-region)
(key-chord-define-global "<M" 'backward-list)
(key-chord-define-global ">?" 'forward-list)
(key-chord-define-global "jj" 'ace-jump-mode)
(key-chord-define-global "yy" 'yank-pop)
;;iy-go-to-char better navigation
(package-require 'iy-go-to-char)
(global-set-key (kbd "M-m") 'iy-go-to-char)
(global-set-key (kbd "C-c C-r") 'rename-sgml-tag)
;;setting cursor movement for alt key plus ijkl
(global-set-key (kbd "M-j") 'backward-char)
(global-set-key (kbd "M-l") 'forward-char)
(global-set-key (kbd "M-i") 'previous-line)
(global-set-key (kbd "M-k") 'next-line)
(defun cursor-jump-up ()
(interactive)
(forward-line -4))
(global-set-key (kbd "M-<up>") 'cursor-jump-up)
(defun cursor-jump-down()
(interactive)
(forward-line 4))
(global-set-key (kbd "M-<down>") 'cursor-jump-down)
;; Push mark when using ido-imenu
(package-require 'idomenu)
(defvar push-mark-before-goto-char nil)
(defadvice goto-char (before push-mark-first activate)
(when push-mark-before-goto-char
(push-mark)))
(defun ido-imenu-push-mark ()
(interactive)
(let ((push-mark-before-goto-char t))
(idomenu)))
(global-set-key (kbd "C-x C-i") 'idomenu)
;;add multiple-cursors support
(package-require 'multiple-cursors)
(global-set-key (kbd "C-.") 'mc/mark-next-like-this)
(global-set-key (kbd "C-,") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-!") 'mc/mark-all-like-this)
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
;add ibuffers
(global-set-key (kbd "C-x C-b") 'ibuffer)
(autoload 'ibuffer "ibuffer" "List buffers." t)
;;show matching parenthesis
(show-paren-mode 1)
;;change tab widths
(setq tab-width 4)
;;(setq 'c-basic-offset 'tab-width)
;;(setq 'cperl-indent-level 'tab-width)
;;add support for better file browsing
(setq ido-enable-flex-matching t)
(setq ido-everywhere t)
(ido-mode 1)
(package-require 'ido-hacks)
(package-require 'undo-tree)
(global-undo-tree-mode)
;;remove annoying backups, just use git
(setq backup-inhibited t)
;;disable auto save
(setq auto-save-default nil)
;;zone out the display when it goes idle for a given length of tim
(setq zone-idle-time 300)
(setq zone-timer (run-with-idle-timer zone-idle-time t 'zone))
(setq zone-programs [
zone-pgm-drip
zone-pgm-drip-fretfully
])
;;size of tabs
(setq tab-width 4)
(put 'narrow-to-region 'disabled nil)
;;setting to make it so you don't need to provide a full yes or no response
(defalias 'yes-or-no-p 'y-or-n-p)
(package-require 'coffee-mode)
(package-require 'yasnippet)
(yas-global-mode 1)
(package-require 'auto-complete)
;;for auto-complete to be setup correctly
(when (require 'auto-complete-config nil t)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/elpa/auto-complete-20130724.1750/dict")
(add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
(ac-config-default)
(ac-set-trigger-key "TAB")
(ac-set-trigger-key "<tab>")
;;(setq ac-sources (append '(ac-source-yasnippet) ac-sources))
;;change colours for auto-complete-mode
(set-face-background 'ac-candidate-face "LightGray")
(set-face-underline 'ac-candidate-face "LimeGreen")
(set-face-background 'ac-selection-face "DarkGreen")
)
;;org-mode setup!!!!!
(when (require 'org-install nil t)
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)
(setq org-log-done t)
(setq org-agenda-files (list "~/org/apersonal.org"
"~/org/diet.org"
"~/org/exercise.org"
"~/org/journal.org"
"~/org/tasks.org"
"~/org/finance.org"
"~/org/notes.org"))
(setq org-directory "~/org")
(setq org-default-notes-file (concat org-directory "/refile.org"))
(define-key global-map "\C-cc" 'org-capture)
;;adding autocommit hook this will automatically commit and push the
;; org file after it's been saved
(package-require 'git-auto-commit-mode)
;;perform correct pushing after commit command
(defadvice gac-commit (after gac-push-alt ())
"Performs a simple shell-based push using git"
(shell-command "git push"))
(ad-activate 'gac-commit)
(defun git-auto-commit-hook ()
;;check if we're currently in an org-agenda file
(let ((filelist org-agenda-files))
(if (member (concat org-directory "/" (buffer-name)) org-agenda-files)
(git-auto-commit-mode 1))
))
(add-hook 'find-file-hook 'git-auto-commit-hook)
;;Custom Agenda Commands
(setq org-agenda-custom-commands
'(("w" . "Work Related Searches")
("wa" "All Work" tags-todo "WORK")
("wi" "iFIDS Work" tags-todo "WORK|IFIDS")
("g" "Groceries and Shopping" tags-todo "FOOD|SHOP")
("b" "Books" tags "BOOK")))
(setq org-capture-templates
'(("t" "Todo Task" entry (file+headline "~/org/tasks.org" "Tasks")
"* TODO %? %^g")
("p" "Project Task" entry (file+headline "~/org/tasks.org" "Projects")
"* TODO %? %^g")
("w" "Work Task" entry (file+headline "~/org/tasks.org" "Work")
"* TODO %? %^g")
("j" "Journal" entry (file+datetree "~/org/journal.org")
"* %?\nEntered on %U\n %i\n %a")
("f" "Food Entry" entry (file+headline "~/org/diet.org" "Refile")
"* %U - %?:FOOD:")
("r" "Refile" entry (file+headline "~/org/tasks.org" "Refile")
"* %U - %? %^g:NOTE:")))
)
;to visualize graphviz files
(package-require 'graphviz-dot-mode)
;;plantuml cool stuff
;;(package-require 'plantuml-mode)
(add-to-list 'load-path "~/.emacs.d/plantuml-server")
(when (require 'plantuml-server nil t)
(global-set-key (kbd "C-c s") 'plantuml-eval-to-browser)
(global-set-key (kbd "C-c d") 'plantuml-eval-to-other-window)
)
(add-to-list 'auto-mode-alist '("\\.plant$" . plantuml-mode))
;mercurial sane status reports
(package-require 'monky)
(setq monky-process-type 'cmdserver)
;git sane status reports
(package-require 'magit)
(package-require 'lua-mode)
(autoload 'lua-mode "lua-mode" "Lua editing mode." t)
(add-to-list 'auto-mode-alist '("\\.lua$" . lua-mode))
(add-to-list 'interpreter-mode-alist '("lua" . lua-mode))
(setq lua-indent-level 4)
(add-hook 'lua-mode-hook (lambda () (setq tab-width 4)))
;;color theme
(if (not (window-system))
(progn
(package-require 'color-theme)
(color-theme-initialize)
(color-theme-jsc-dark))
(progn
(package-require 'waher-theme)
(load-theme 'waher t t)))
;;global keys
;;used like M-x instead
(global-set-key (kbd "C-; C-;") 'execute-extended-command)
(global-set-key (kbd "C-; ;") 'execute-extended-command)
;;can also be used to evaluate sexp
(global-set-key (kbd "C-; C-e") 'eval-last-sexp)
(global-set-key (kbd "C-; e") 'eval-last-sexp)
;;compile code
(global-set-key (kbd "C-; C-c") 'compile)
(global-set-key (kbd "C-; c") 'compile)
;;comment and uncomment code quickly
(global-set-key (kbd "C-c C-c") 'comment-or-uncomment-region)
;;fix issues with c++11 variables not being understood
(require 'font-lock)
(defun --copy-face (new-face face)
"Define NEW-FACE from existing FACE."
(copy-face face new-face)
(eval `(defvar ,new-face nil))
(set new-face new-face))
(--copy-face 'font-lock-label-face ; labels, case, public, private, proteced, namespace-tags
'font-lock-keyword-face)
(--copy-face 'font-lock-doc-markup-face ; comment markups such as Javadoc-tags
'font-lock-doc-face)
(--copy-face 'font-lock-doc-string-face ; comment markups
'font-lock-comment-face)
(global-font-lock-mode t)
(setq font-lock-maximum-decoration t)
(add-hook 'c++-mode-hook
'(lambda()
(font-lock-add-keywords
nil '(;; complete some fundamental keywords
("\\<\\(void\\|unsigned\\|signed\\|char\\|short\\|bool\\|int\\|long\\|float\\|double\\)\\>" . font-lock-keyword-face)
;; add the new C++11 keywords
("\\<\\(alignof\\|alignas\\|constexpr\\|decltype\\|noexcept\\|nullptr\\|static_assert\\|thread_local\\|override\\|final\\)\\>" . font-lock-keyword-face)
("\\<\\(char[0-9]+_t\\)\\>" . font-lock-keyword-face)
;; PREPROCESSOR_CONSTANT
("\\<[A-Z]+[A-Z_]+\\>" . font-lock-constant-face)
;; hexadecimal numbers
("\\<0[xX][0-9A-Fa-f]+\\>" . font-lock-constant-face)
;; integer/float/scientific numbers
("\\<[\\-+]*[0-9]*\\.?[0-9]+\\([ulUL]+\\|[eE][\\-+]?[0-9]+\\)?\\>" . font-lock-constant-face)
;; user-types (customize!)
("\\<[A-Za-z_]+[A-Za-z_0-9]*_\\(t\\|type\\|ptr\\)\\>" . font-lock-type-face)
("\\<\\(xstring\\|xchar\\)\\>" . font-lock-type-face)
))
) t)
;;auto fill mode for all text buffers
(add-hook 'text-mode-hook 'turn-on-auto-fill)
;;autofill toggle
(global-set-key (kbd "C-c q") 'auto-fill-mode)
;;ERC nick coloring
;; Pool of colors to use when coloring IRC nicks
(setq erc-colors-list '("forest green"
"blue"
"red"
"light gray"
"dark orange"
"tomato"
"goldenrod"
"maroon"
"indian red"
"dark khaki"
"orchid"
"SeaGreen3"
"forest green"
"peach puff"
"steel blue"
"medium aquamarine"))
;; special colors for some people
(setq erc-nick-color-alist '(("John" . "blue")
("Bob" . "red")
))
(defun erc-get-color-for-nick (nick)
"Gets a color for NICK. If NICK is in erc-nick-color-alist, use that color, else hash the nick and use a random color from the pool"
(or (cdr (assoc nick erc-nick-color-alist))
(nth
(mod (string-to-number
(substring (md5 (downcase nick)) 0 6) 16)
(length erc-colors-list))
erc-colors-list)))
(defun erc-put-color-on-nick ()
"Modifies the color of nicks according to erc-get-color-for-nick"
(save-excursion
(goto-char (point-min))
(if (looking-at "<\\([^>]*\\)>")
(let ((nick (match-string 1)))
(put-text-property (match-beginning 1) (match-end 1) 'face
(cons 'foreground-color
(erc-get-color-for-nick nick)))))))
(add-hook 'erc-insert-modify-hook 'erc-put-color-on-nick)
(setq erc-lurker-threshold-time 3600)
;;eshell configuration with grep
;;make sure we supply emacs with msys commands
(if (system-type-is-win32)
(setenv "PATH"
(concat
;; Change this with your path to MSYS bin directory
"C:\\MinGW\\msys\\1.0\\bin;"
(getenv "PATH"))))
;;configuring escreen
(package-require 'escreen)
(escreen-install)
(escreen-number-mode 1)
(setq escreen-prefix-char "\C-z")
(global-set-key escreen-prefix-char 'escreen-prefix)
;;Function to prompt before killing the given screen
(defun escreen-prompt-kill-p ()
"Prompts the user whether they want to kill the current screen,
kills the screen if true"
(interactive)
(if (y-or-n-p "Kill Current Escreen?")
(escreen-kill-screen)))
;;function keys can be used to navigate between screens
(global-set-key (kbd "<f9>") 'escreen-create-screen)
(global-set-key (kbd "<f10>") 'escreen-goto-prev-screen)
(global-set-key (kbd "<f11>") 'escreen-goto-next-screen)
;;(global-set-key (kbd "<f12>") 'escreen-kill-screen)
(global-set-key (kbd "<f12>") 'escreen-prompt-kill-p)
;;cc-mode indentation fix
;;fixing indentation for long names
(defun my-indent-setup ()
(c-set-offset 'arglist-intro '+))
(add-hook 'cc-mode-hook 'my-indent-setup)
;;the c/c++ programming style to use
(setq c-default-style "gnu"
c-basic-offset 4)
;;a package explorer plugin
(package-require 'project-explorer)
(global-set-key (kbd "M-p") 'project-explorer-open)
;;replaced with diff-hl
;; (package-require 'git-gutter)
;; (global-git-gutter-mode +1)
;; (global-set-key (kbd "C-x C-g") 'git-gutter:toggle)
(package-require 'diff-hl)
(defun my-diff-hl-find-file-hook ()
(diff-hl-mode))
(add-hook 'find-file-hook 'my-diff-hl-find-file-hook)
;;When on the mac, change the key settings to match other systems
(when (eq system-type 'darwin) ;; mac specific settings
(setq mac-option-modifier 'alt)
(setq mac-command-modifier 'meta)
(setq mac-function-modifier 'control)
(setq mac-control-modifier 'control)
(global-set-key [kp-delete] 'delete-char) ;; sets fn-delete to be right-delete
)
;;smart parenthesis mode
(package-require 'smartparens)
(require 'smartparens-config)
(add-hook 'emacs-lisp-mode-hook 'turn-on-smartparens-mode)
(add-hook 'lisp-interaction-mode-hook 'turn-on-smartparens-mode)
(add-hook 'ielm-mode-hook 'turn-on-smartparens-mode)
(add-hook 'cider-mode-hook 'turn-on-smartparens-mode)
;;setting up clojure
(package-require 'clojure-mode)
(package-require 'dash)
(package-require 'cider)
;;setting up eldoc
(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
(add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
(add-hook 'ielm-mode-hook 'turn-on-eldoc-mode)
(add-hook 'cider-mode-hook 'cider-turn-on-eldoc-mode)
;;(add-hook 'cider-repl-mode-hook 'subword-mode)
(package-require 'rainbow-delimiters)
(package-require 'rainbow-mode)
(defun my-rainbow-find-file-hook ()
(rainbow-mode)
(rainbow-delimiters-mode)
(subword-mode))
(add-hook 'find-file-hook 'my-rainbow-find-file-hook)
;;turn off highlighting the copy regions
(transient-mark-mode 1)
;;sane revert buffer key
(global-set-key (kbd "C-x C-r") 'revert-buffer)
;;set a point with f7
(global-set-key (kbd "<f7>") 'point-to-register)
;;jump to that point with f8
(global-set-key (kbd "<f8>") 'jump-to-register)
;;some custom registers that can be navigated to with <f8>
(set-register ?e '(file . "~/.emacs.el"))
(set-register ?d '(file . "~/org/diet.org"))
(set-register ?t '(file . "~/org/tasks.org"))
(set-register ?x '(file . "~/org/exercise.org"))
(set-register ?j '(file . "~/org/journal.org"))
(set-register ?a '(file . "~/org/apersonal.org"))
(set-register ?n '(file . "~/org/notes.org"))
;;function for compiling code
(global-set-key (kbd "<f5>") 'recompile)
;;web-mode defaults
(package-require 'web-mode)
(add-to-list 'auto-mode-alist '("\\.asp$" . web-mode))
(add-to-list 'auto-mode-alist '("\\.aspx$" . web-mode))
(add-to-list 'auto-mode-alist '("\\.mustache$" . web-mode))
(add-to-list 'auto-mode-alist '("\\.jsp$" . web-mode))
(add-to-list 'auto-mode-alist '("\\.inc$" . web-mode))
;;web-mode hook changes
(defun web-mode-hook ()
"Hooks for web-mode (.asp, .php, .mustache, etc)"
(auto-complete-mode 1)
(setq tab-width 4)
(setq web-mode-markup-indent-offset 2)
(setq web-mode-css-indent-offset 2)
(setq web-mode-code-indent-offset 2))
(add-hook 'web-mode-hook 'web-mode-hook)
;;if the visual-basic-mode.el file exists, add the mode for it
(let ((vb-file "~/.emacs.d/visual-basic-mode.el"))
(when (file-exists-p vb-file)
(progn
(load-file vb-file)
(add-to-list 'auto-mode-alist '("\\.vb$" . visual-basic-mode)))))
;;Installing projectile, project management
(package-require 'projectile)
(projectile-global-mode)
;;install better searching
(package-require 'flx-ido)
(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 ("8aebf25556399b58091e533e455dd50a6a9cba958cc4ebb0aab175863c25b9a4" "b47a3e837ae97400c43661368be754599ef3b7c33a39fd55da03a6ad489aafee" default)))
'(erc-after-connect nil)
'(erc-autojoin-mode t)
'(erc-button-mode t)
'(erc-fill-mode t)
'(erc-irccontrols-mode t)
'(erc-list-mode t)
'(erc-lurker-threshold-time 3600)
'(erc-match-mode t)
'(erc-menu-mode t)
'(erc-move-to-prompt-mode t)
'(erc-netsplit-mode t)
'(erc-networks-mode t)
'(erc-nick "bacon1989")
'(erc-noncommands-mode t)
'(erc-notice-prefix "-- ")
'(erc-pcomplete-mode t)
'(erc-prompt ">>")
'(erc-readonly-mode t)
'(erc-ring-mode t)
'(erc-stamp-mode t)
'(erc-system-name "Who wants to know?")
'(erc-track-minor-mode t)
'(erc-track-mode t)
'(erc-user-full-name "Benjamin Zaporzan")
'(org-agenda-files (quote ("c:/Project.Repositories/iFIDS/Docs/Specification/Spec_BaggageRouting.org" "c:/Project.Repositories/iFIDS/aspsrc/html/App_Code/MediaServer_CS/MediaServer.org" "~/Projects/iFIDSAndroid/readme.org" "~/org/apersonal.org" "~/org/diet.org" "~/org/exercise.org" "~/org/journal.org" "~/org/tasks.org" "~/org/finance.org" "~/org/notes.org"))))
(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.
'(erc-current-nick-face ((t (:foreground "medium slate blue" :weight bold))))
'(erc-input-face ((t (:foreground "slate blue"))))
'(erc-my-nick-face ((t (:background "ivory4" :foreground "dark slate blue" :underline nil :weight bold))))
'(erc-notice-face ((t (:foreground "dim gray" :slant italic :weight thin :height 0.9))))
'(erc-prompt-face ((t (:foreground "dark orange" :weight ultra-bold))))
'(erc-timestamp-face ((t (:foreground "DarkOrange4" :height 0.9)))))
(put 'downcase-region 'disabled nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment