Last active
September 26, 2018 02:29
-
-
Save Digicrat/ed040fc853b895b38b371cfe032fe74e to your computer and use it in GitHub Desktop.
My Emacs Configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Melpa Package Manager (requires Emacs >= 24.1) | |
;; Originally pointed to http://melpa.milkbox.net/packages/ | |
;; Without this M-x package-refresh-contents fails on most installations | |
(if (and (>= emacs-major-version 24) | |
(>= emacs-minor-version 1)) | |
(progn | |
(require 'package) | |
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) | |
) | |
) | |
(when (< emacs-major-version 24) | |
;; For important compatibility libraries like cl-lib | |
(add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/"))) | |
(package-initialize) | |
;; Enable CUA mode (traditional copy-cut-select keyboard shortcuts) | |
(cua-mode t) | |
;; Matching paren highlighting | |
(show-paren-mode 1) | |
(column-number-mode 1) | |
;; Use spaces instead of tabs by default | |
(setq-default indent-tabs-mode nil) | |
;; Show info when matching paren is off screen | |
(defadvice show-paren-function | |
(after show-matching-paren-offscreen activate) | |
"If the matching paren is offscreen, show the matching line in the | |
echo area. Has no effect if the character before point is not of | |
the syntax class ')'." | |
(interactive) | |
(let* ((cb (char-before (point))) | |
(matching-text (and cb | |
(char-equal (char-syntax cb) ?\) ) | |
(blink-matching-open)))) | |
(when matching-text (message matching-text)))) | |
;; Custom command to add a shortcut for Find-in-Files aka rgrep, untested | |
(global-set-key (kbd "M-s") 'rgrep) | |
;; Go to line | |
(global-set-key "\C-l" 'goto-line) | |
;; Switch Buffers | |
(global-set-key (kbd "<C-tab>") 'other-window) | |
(global-set-key (kbd "<C-S-tab>") 'other-window) | |
;; Installs keybindings to shift betwen windows | |
(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) | |
(global-set-key (kbd "C-c <down>") 'windmove-down) | |
;; Bookmarks Feature | |
(require 'bm) | |
;; Boookmarks in margin | |
(global-set-key (kbd "<left-fringe> <mouse-5>") 'bm-next-mouse) | |
(global-set-key (kbd "<left-fringe> <mouse-4>") 'bm-previous-mouse) | |
(global-set-key (kbd "<left-fringe> <mouse-1>") 'bm-toggle-mouse) | |
(setq bm-marker 'bm-marker-right) ;; Do we want this? | |
;; Make the bookmarks persistent ;; @TODO: Check bm.el, additional hooks may be needed | |
(setq-default bm-buffer-persistence t) | |
;; Bookmarks style configuration | |
(setq bm-highlight-style 'bm-highlight-only-line) | |
;; Bookmarks (TextPad / M$ Visual Studio style) key setup. | |
(global-set-key (kbd "<C-f2>") 'bm-toggle) | |
(global-set-key (kbd "<f2>") 'bm-next) | |
(global-set-key (kbd "<S-f2>") 'bm-previous) | |
(global-set-key (kbd "<M-f2>") 'bm-bookmark-show-annotation) ;; Maybe change from Meta to Cmd? | |
(global-set-key (kbd "<M-S-f2>") 'bm-bookmark-annotate) | |
; Bookmark bindings for cases where F-keys don't work reliably | |
(global-set-key (kbd "M-O j") 'bm-toggle) ; Mac Num * key | |
(global-set-key (kbd "M-O k") 'bm-next) ; Mac Num + | |
(global-set-key (kbd "M-O m") 'bm-previous); Mac Num - | |
(global-set-key (kbd "M-O M") 'bm-bookmark-annotate); Mac Num Enter | |
(global-set-key (kbd "M-O n") 'bm-bookmark-show-annotation); Mac Num - | |
;;; Comment/Uncomment Region (note: may change to a different key later) | |
(global-set-key (kbd "<f3>") 'comment-region) | |
(global-set-key (kbd "<S-f3>") 'uncomment-region) | |
;; Tags: Go to previous location | |
(global-set-key (kbd "C-.") 'pop-tag-mark) | |
;; CTags Command | |
(defun create-tags (dir-name) | |
"Create tags file." | |
(interactive "DDirectory: ") | |
(cd dir-name) | |
(shell-command | |
"find . -name \"*.[chCH]\" -print | etags -" | |
) | |
) | |
;; Allow desktop-save to restore TRAMP-mode buffers | |
(setq desktop-files-not-to-save "^$") | |
;; Non-copy delete word | |
(defun delete-word (arg) | |
"Delete characters backward until encountering the beginning of a word. | |
With argument ARG, do this that many times." | |
(interactive "p") | |
(delete-region (point) (progn (backward-word arg) (point)))) | |
(global-set-key (kbd "<C-backspace>") 'delete-word) | |
;; Diff Tools | |
(require 'ediff-trees) | |
(global-set-key (kbd "s-SPC") 'ediff-trees-examine-next) | |
(global-set-key (kbd "S-s-SPC") 'ediff-trees-examine-previous) | |
;; Magit Configuration | |
; Fix Diff Highlight Colors | |
(eval-after-load 'magit | |
'(progn | |
(set-face-foreground 'magit-diff-add "green3") | |
(set-face-foreground 'magit-diff-del "red3") | |
(unless window-system | |
(set-face-background 'magit-item-highlight "black")))) | |
; Automatic (subtle) current line highlighting | |
(global-hl-line-mode 1) | |
(set-face-background hl-line-face "gray13") | |
;; ANSI Color Mode | |
(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t) | |
(defun display-ansi-colors () | |
(interactive) | |
(ansi-color-apply-on-region (point-min) (point-max))) | |
;; Column highlighting | |
(require 'column-marker) | |
;; Auto Reload Tags files without prompt | |
(setq-default tags-revert-without-query t) | |
;; Show Current Function Name in Buffer | |
(which-function-mode t) | |
;; .mak files should use Makefile mode | |
(add-to-list 'auto-mode-alist '("\\.mak\\'" . makefile-mode)) | |
;; Use cperl-mode instead of the default perl-mode | |
(add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode)) | |
(add-to-list 'interpreter-mode-alist '("perl" . cperl-mode)) | |
(add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode)) | |
(add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode)) | |
(add-hook 'cperl-mode-hook 'n-cperl-mode-hook t) | |
(defun n-cperl-mode-hook () | |
(setq cperl-indent-level 4) | |
(setq cperl-continued-statement-offset 0) | |
(setq cperl-extra-newline-before-brace t) | |
(set-face-background 'cperl-array-face "wheat") | |
(set-face-background 'cperl-hash-face "wheat") | |
) | |
;; Configure Global Indentation Styles | |
(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. | |
'(c-basic-offset 3) | |
'(c-default-style | |
(quote | |
((c-mode . "stroustrup") | |
(java-mode . "java") | |
(c++-mode . "stroustrup") | |
(other . "gnu")))) | |
'(c-echo-syntactic-information-p t) | |
'(c-font-lock-extra-types (quote ("\\sw+_type"))) | |
'(c-tab-always-indent t) | |
'(ecb-source-path (quote ("~/Code/SPP/dev"))) | |
'(indent-tabs-mode nil) | |
'(inhibit-startup-screen t) | |
'(ps-printer-name-option "-d") | |
'(scroll-bar-mode (quote right)) | |
'(tab-width 4)) | |
(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. | |
'(bm-fringe-persistent-face ((t (:background "brown" :foreground "White")))) | |
'(bm-persistent-face ((t (:background "red" :foreground "White"))))) | |
;; Search all open buffers | |
(defun my-multi-occur-in-matching-buffers (regexp &optional allbufs) | |
"Show all lines matching REGEXP in all buffers." | |
(interactive (occur-read-primary-args)) | |
(multi-occur-in-matching-buffers ".*" regexp)) | |
(global-set-key (kbd "s-s") 'my-multi-occur-in-matching-buffers) | |
;; Switch between horizontal and vertical split | |
; https://stackoverflow.com/questions/14881020/emacs-shortcut-to-switch-from-a-horizontal-split-to-a-vertical-split-in-one-move | |
(defun toggle-window-split () | |
(interactive) | |
(if (= (count-windows) 2) | |
(let* ((this-win-buffer (window-buffer)) | |
(next-win-buffer (window-buffer (next-window))) | |
(this-win-edges (window-edges (selected-window))) | |
(next-win-edges (window-edges (next-window))) | |
(this-win-2nd (not (and (<= (car this-win-edges) | |
(car next-win-edges)) | |
(<= (cadr this-win-edges) | |
(cadr next-win-edges))))) | |
(splitter | |
(if (= (car this-win-edges) | |
(car (window-edges (next-window)))) | |
'split-window-horizontally | |
'split-window-vertically))) | |
(delete-other-windows) | |
(let ((first-win (selected-window))) | |
(funcall splitter) | |
(if this-win-2nd (other-window 1)) | |
(set-window-buffer (selected-window) this-win-buffer) | |
(set-window-buffer (next-window) next-win-buffer) | |
(select-window first-win) | |
(if this-win-2nd (other-window 1)))))) | |
(global-set-key (kbd "C-x |") 'toggle-window-split) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment