Permalink
Cannot retrieve contributors at this time
Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up
Fetching contributors…
| ;; Added by Package.el. This must come before configurations of | |
| ;; installed packages. Don't delete this line. If you don't want it, | |
| ;; just comment it out by adding a semicolon to the start of the line. | |
| ;; You may delete these explanatory comments. | |
| (package-initialize) | |
| ;; | |
| ;; Added by Macoy | |
| ;; | |
| ;; Macoy's .emacs | |
| ;; Goal: Make a dev environment with Sublime Text 3-like keybindings and features: | |
| ;; - [Done] Code completion | |
| ;; - [Done] Goto definition | |
| ;; - [Done] Multiple cursors | |
| ;; - [Done] Templates | |
| ;; - [Done] Workspaces ("desktops" by emacs terminology) | |
| ;; - [WIP] Build systems | |
| ;; - [Done] One keypress builds | |
| ;; - [WIP] Quick jump to compilation error | |
| ;; - Easy add build system | |
| ;; - [Done] Fuzzy file opening | |
| ;; - [Done] Fuzzy editor command execution | |
| ;; - [Done] Standard clipboard behavior (no copy on mark, no copy on kill etc., only on C-c!) | |
| ;; | |
| ;; Ways Emacs excels over Sublime: | |
| ;; - More keyboard-only friendly | |
| ;; - More configurable | |
| ;; - Registers (for positions and saving strings) | |
| ;; - More minimal appearance | |
| ;; - Built-in help (Sublime's documentation can be spotty; Emacs docs can be too complicated) | |
| ;; | |
| ;; Setup | |
| ;; 1. Install all packages in emacsPackages.txt | |
| ;; 2. Add macoyCopy, macoyCut, and macoyPaste to mc/cmds-to-run-once and restart Emacs | |
| ;; | |
| ;; TODO (there are more scattered around this file): | |
| ;; - TAGS has to be set up per-project; doesn't allow cross-repository finding afaik | |
| ;; It does, you just need to set tags-table-list. | |
| ;; See https://www.gnu.org/software/emacs/manual/html_node/emacs/Select-Tags-Table.html | |
| ;; - Would be nice to have buffers and files merged like Sublime's C-p (but not essential) | |
| ;; - Buffer reverting automatically instantly if no changes, otherwise prompt the file has | |
| ;; been changed underneath and ask to reload or save over | |
| ;; - Tab key behavior confuses me especially in plaintext files | |
| ;; - Get back and forward working (back doesn't work too well) | |
| ;; - Compilation-* commands for jumping between errors | |
| ;; These do exist already, but you need to use emacs compile | |
| ;; - Build system selection via Ido custom list (like Sublime's C-S-b) | |
| ;; - Ag filter files | |
| ;; - Determine what smooth-scrolling actually does (if anything) | |
| ;; - Copy line when nothing is marked | |
| ;; - Ido jump to file anywhere does more harm than good (especially when creating new files) | |
| ;; - Python indentation is godawful | |
| ;; - Multiple cursors copy and cut when whole line selected | |
| ;; Emacs Notes | |
| ;; C-h k <the keybind> to find what a key does | |
| ;; C-h b to list all bindings (should've used this more when fighting binds...) | |
| ;; C-q = quoted-insert "insert the next character, whatever it is" e.g. useful for inserting <tab> | |
| ;; Enable MELPA | |
| (require 'package) | |
| (let* ((no-ssl (and (memq system-type '(windows-nt ms-dos)) | |
| (not (gnutls-available-p)))) | |
| (proto (if no-ssl "http" "https"))) | |
| ;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired | |
| (add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t) | |
| ;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t) | |
| (when (< emacs-major-version 24) | |
| ;; For important compatibility libraries like cl-lib | |
| (add-to-list 'package-archives '("gnu" . (concat proto "://elpa.gnu.org/packages/"))))) | |
| (package-initialize) | |
| ;; Some settings from http://ergoemacs.org/emacs/emacs_make_modern.html | |
| ;; make cursor movement stop in between camelCase words. (don't) | |
| (global-subword-mode 0) | |
| ;; Themes are generally safe | |
| (setq custom-safe-themes t) | |
| ;; make typing delete/overwrites selected text | |
| (delete-selection-mode 1) | |
| ;; turn on highlighting current line | |
| (global-hl-line-mode 1) | |
| ;; remember cursor position, for emacs 25.1 or later | |
| (save-place-mode 1) | |
| ;; stop creating those backup~ files | |
| (setq make-backup-files nil) | |
| ;; stop creating those #auto-save# files | |
| (setq auto-save-default nil) | |
| ;; Don't create lock files | |
| (setq create-lockfiles nil) | |
| ;; save/restore opened files | |
| (desktop-save-mode 1) | |
| ;; Set cursor to I-beam | |
| (modify-all-frames-parameters (list (cons 'cursor-type '(bar . 2)))) | |
| ;; Smex: Smart M-x completion | |
| (smex-initialize) | |
| (global-set-key (kbd "M-x") 'smex) | |
| (global-set-key (kbd "M-X") 'smex-major-mode-commands) | |
| ;; This is your old M-x. | |
| (global-set-key (kbd "C-M-x") 'execute-extended-command) | |
| ;; Ido enable (this might be unnecessary as Emacs comes with it by default now) | |
| (require 'ido) | |
| (ido-mode t) | |
| ;; Ido display vertically (closer to Sublime) | |
| (ido-vertical-mode 1) | |
| ;; Ido vertical use up and down to navigate options, left-right for history/directories | |
| (setq ido-vertical-define-keys 'C-n-C-p-up-down-left-right) | |
| ;; Ido flx settings: make ido have fuzzy sublime-like matching | |
| (require 'flx-ido) | |
| (ido-mode 1) | |
| (ido-everywhere 1) | |
| (flx-ido-mode 1) | |
| ;; disable ido faces to see flx highlights. | |
| (setq ido-enable-flex-matching t) | |
| (setq ido-use-faces nil) | |
| ;; Projectile: this does "project" stuff like quick find https://github.com/bbatsov/projectile | |
| ;; C-p for ctrl-p-like find | |
| (require 'projectile) | |
| ;; Ignore autogenerated files. Doesn't work. I used customize-group projectile for ignored dirs | |
| ;; which can be found near the bottom of this file | |
| (setq projectile-globally-ignored-files | |
| (append '("AutoGen" | |
| "*_ast.*" | |
| "3rdparty/Node/*") | |
| projectile-globally-ignored-files)) | |
| (projectile-mode 1) | |
| ;; Dumb-jump: Goto definition https://github.com/jacktasia/dumb-jump | |
| ;; (Doesn't work; use TAGS instead) | |
| ;;(dumb-jump-mode) | |
| ;; Powerline: nicer status bar | |
| (require 'powerline) | |
| (powerline-default-theme) | |
| ;; powerline-default-theme | |
| ;; powerline-center-theme | |
| ;; powerline-center-evil-theme | |
| ;; powerline-vim-theme | |
| ;; powerline-nano-theme | |
| ;; Instead of wrapping at character, wrap at word. This slightly improves readability | |
| (setq visual-line-fringe-indicators '(left-curly-arrow right-curly-arrow)) | |
| (global-visual-line-mode 1) | |
| ;; After wrapping, try to line up the text with the wrapped line column | |
| (define-globalized-minor-mode my-global-adaptive-wrap-mode adaptive-wrap-prefix-mode | |
| (lambda () (adaptive-wrap-prefix-mode 1))) | |
| (my-global-adaptive-wrap-mode 1) | |
| ;; C indentation settings | |
| ;; bsd AKA Allman https://www.emacswiki.org/emacs/IndentingC | |
| (setq c-default-style "bsd" | |
| c-basic-offset 4 | |
| tab-width 4 | |
| indent-tabs-mode t) | |
| ;; Doesn't quite work | |
| ;; (defun infer-indentation-style () | |
| ;; ;; if our source file uses tabs, we use tabs, if spaces spaces, and if | |
| ;; ;; neither, we use the current indent-tabs-mode | |
| ;; (let ((space-count (how-many "^ " (point-min) (point-max))) | |
| ;; (tab-count (how-many "^\t" (point-min) (point-max)))) | |
| ;; (if (> space-count tab-count) | |
| ;; ;; ((message "Indent using space") | |
| ;; (setq indent-tabs-mode nil)) | |
| ;; (if (> tab-count space-count) | |
| ;; ;; ((message "Indent using tab") | |
| ;; (setq indent-tabs-mode t)))) | |
| ;; (add-hook 'c-mode-common-hook | |
| ;; (lambda () (setq indent-tabs-mode nil) | |
| ;; (infer-indentation-style))) | |
| ;; (add-hook 'lisp-mode-hook | |
| ;; (lambda () (setq indent-tabs-mode nil) | |
| ;; (infer-indentation-style))) | |
| ;; Detect which indentation style a file is using and use that (doesn't work) | |
| (setq dtrt-indent-mode 1) | |
| ;; https://www.emacswiki.org/emacs/SmoothScrolling | |
| ;; scroll one line at a time (less "jumpy" than defaults) | |
| (setq mouse-wheel-scroll-amount '(2 ((shift) . 2))) ;; Two lines at a time | |
| (setq mouse-wheel-progressive-speed nil) ;; don't accelerate scrolling | |
| ;; (setq mouse-wheel-follow-mouse 't) ;; scroll window under mouse | |
| ;;(setq scroll-step 1) ;; keyboard scroll one line at a time | |
| ;; (setq scroll-conservatively 10000) | |
| ;; (setq auto-window-vscroll nil) | |
| (require 'smooth-scrolling) | |
| (smooth-scrolling-mode 1) | |
| ;; Quick jumping. Ace-jump-mode didn't work for me | |
| ;; Hit keybind, then type first letter of word. Type letter for correct word to jump to | |
| (require 'avy) | |
| (global-set-key (kbd "C-S-g") 'avy-goto-line) | |
| (global-set-key (kbd "C-S-j") 'avy-goto-char) | |
| (global-set-key (kbd "C-j") 'avy-goto-word-or-subword-1) | |
| ;; Make garbage collection happen less often (https://github.com/lewang/flx) | |
| ;; This probably doesn't actually do anything | |
| (setq gc-cons-threshold 20000000) | |
| ;; Show whitespace (damnit emacs don't use spaces for indentation!) (doesn't quite work) | |
| ;;(require 'whitespace) | |
| ;;(global-whitespace-mode 0) | |
| (setq whitespace-style '(faces tabs tabs-mark spaces space-mark)) | |
| (setq whitespace-line-column 100) | |
| (setq whitespace-newline nil) | |
| ;; Multiple cursors | |
| (require 'multiple-cursors) | |
| ;; Make sure to change this in my-keys-minor-mode-map too | |
| (global-set-key (kbd "C-d") 'mc/mark-next-like-this) | |
| ;;(global-set-key (kbd "C-<") 'mc/mark-previous-like-this) | |
| (global-set-key (kbd "M-<f3>") 'mc/mark-all-like-this) | |
| ;; Make <return> insert a newline; multiple-cursors-mode can still be disabled with C-g. | |
| (define-key mc/keymap (kbd "<return>") nil) | |
| ;; Adds one cursor to each line in the current region. | |
| (global-set-key (kbd "C-S-l") 'mc/edit-lines) | |
| ;; Note that in my-keys I define cut, copy, and paste overrides which work with simpleclip & mc | |
| ;; Searching in files (Ag) | |
| ;; Make ag.el reuse the same *ag* buffer for all your searches: | |
| (setq ag-reuse-buffers 't) | |
| ;; TODO: Figure out how to ignore files | |
| ;; Doesn't work (sometimes it will search for "--" or some other random thing seemingly) | |
| ;;(setq ag-arguments '("--before" "3" "--after" "3")) | |
| (global-set-key (kbd "C-S-f") 'ag) | |
| ;; Simpleclip makes system clipboard and emacs kill ring separate | |
| ;; This is sane copy paste behavior | |
| (require 'simpleclip) | |
| (simpleclip-mode 1) | |
| ;; Clang format | |
| ;; Looks for .clang-format in project dir | |
| (require 'clang-format) | |
| (defun macoy-clang-format-region-or-buffer () | |
| "Format the region if one is selected, otherwise format the buffer" | |
| (interactive) | |
| (if (use-region-p) | |
| (call-interactively 'clang-format-region) | |
| (call-interactively 'clang-format-buffer) | |
| ) | |
| ) | |
| (global-set-key (kbd "C-M-a") 'macoy-clang-format-region-or-buffer) | |
| ;; Not sure if this actually does anything | |
| ;; https://www.reddit.com/r/emacs/comments/7uq9w1/replace_emacs_c_autoformatting_with_clangformat/ | |
| (fset 'c-indent-region 'clang-format-region) | |
| ;; Don't prompt me to load tags | |
| (setq tags-revert-without-query 1) | |
| ;; Refresh and load tags | |
| ;; TODO: Use projectile refresh ctags instead | |
| (if (eq system-type 'gnu/linux) | |
| (setq ctags-path "ctags") | |
| (setq ctags-path "C:/programsMacoy/ctags58/ctags.exe") | |
| ) | |
| ;;(setq ctags-path "C:/Program Files/Git/usr/bin/echo.exe") | |
| ;;(setq ctags-directories (list )) | |
| ;;(setq ctags-args | |
| ;; (list "-e" "--verbose" "--recurse=yes" "*.c" "*.cpp" "*.h" "*.hpp" "%s")) | |
| ;;(n 'ctags-args ' | |
| (defun generateTags () | |
| "Create tags file" | |
| ;; Doesn't do anything for start-process | |
| ;;(let ((default-directory "F:/CJUNCTIONS/src/"))) | |
| (message "Running CTags") | |
| (let ((ctagsProc (start-process "CTags" "*CTags-out*" ctags-path "-e" "-f" | |
| ;; Output location | |
| "F:/CJUNCTIONS/src/TAGS" | |
| ;; (concat (projectile-project-root) "TAGS") | |
| ;; Additional arguments | |
| "--verbose" "--recurse=yes" "--languages=C,C++" | |
| ;; Annoyingly there doesn't seem to be wildcard matching for folders (at least | |
| ;; not on Windows) | |
| "--exclude=F:/CJUNCTIONS/src/Utilities\\Bin" | |
| ;; Includes | |
| ;; (projectile-project-root) ;; HOME_ONLY | |
| "F:/CJUNCTIONS/src/Core" | |
| ))) | |
| (set-process-sentinel ctagsProc | |
| (lambda (ctagsProc _string) | |
| (call-interactively 'macoy-ido-find-tag-refresh)))) | |
| ) | |
| (defun loadTagsFromParent () | |
| (let ((my-tags-file (locate-dominating-file default-directory "TAGS"))) | |
| (when my-tags-file | |
| (message "Loading tags file: %s" my-tags-file) | |
| (visit-tags-table my-tags-file))) | |
| ) | |
| ;; This isn't really necessary because attempting a goto definition will automatically do this | |
| ;;(global-set-key (kbd "C-<f5>") (lambda () (interactive) (loadTagsFromParent))) | |
| (global-set-key (kbd "C-<f5>") (lambda () (interactive) (generateTags))) | |
| ;; Tags keybinding | |
| (global-set-key (kbd "<f12>") 'xref-find-definitions) | |
| (global-set-key (kbd "M-g") 'xref-find-definitions-other-window) | |
| (global-set-key (kbd "S-<f12>") 'xref-find-apropos) | |
| (global-set-key (kbd "C-S-d") 'macoy-ido-find-tag) | |
| ;; Auto-complete | |
| ;; This will at least work for local completions | |
| (global-auto-complete-mode) | |
| ;; Don't start auto-completion until three characters have been typed | |
| ;; Performance becomes problematic with as many tags as I have so this is necessary | |
| ;; See https://github.com/auto-complete/auto-complete/blob/master/doc/manual.md | |
| (setq ac-auto-start 3) | |
| ;; Auto-complete using etags | |
| ;; Doesn't work because codebase is too big :( | |
| ;;(custom-set-variables | |
| ;; '(ac-etags-requires 1)) | |
| ;; | |
| ;;(eval-after-load "etags" | |
| ;; '(progn | |
| ;; (ac-etags-setup))) | |
| ;; | |
| ;;(add-hook 'c-mode-common-hook 'ac-etags-ac-setup) | |
| ;; Auto complete using company | |
| ;; Doesn't work because codebase is too big | |
| ;;(global-company-mode) | |
| ;;'(company-global-modes '(not company-clang)) | |
| ;;(add-hook 'c-mode-common-hook | |
| ;; (lambda () | |
| ;; (setq company-backends '(company-etags)))) | |
| ;; Custom fuzzy completion stuff | |
| (defun macoy-ido-example () | |
| "Test ido custom" | |
| (interactive) | |
| (setq mylist (list "red" "blue" "yellow" "clear" "i-dont-know")) | |
| (ido-completing-read "What, ... is your favorite color? " mylist)) | |
| ;; Fuzzy find tag like Sublime's C-S-r | |
| ;; Also used for auto-completion | |
| ;; From https://www.emacswiki.org/emacs/InteractivelyDoThings#CompleteFindTagUsingIdo | |
| (setq macoy-tag-names (list "empty (run macoy-ido-find-tag-refresh")) | |
| (defun macoy-ido-find-tag-refresh () | |
| "Refresh ido tag list" | |
| (interactive) | |
| (message "Refreshing ido tags list") | |
| ;; tags-completion-table() early-outs if the table has already been created | |
| ;; This is problematic if TAGS has changed | |
| ;; Clearing it here ensures the table won't get out of sync | |
| (setq tags-completion-table nil) | |
| (tags-completion-table) | |
| ;; Reset to remove "empty" value as well as avoid duplicates | |
| (setq macoy-tag-names nil) | |
| (mapcar (lambda (x) | |
| (push (prin1-to-string x t) macoy-tag-names)) | |
| tags-completion-table) | |
| (message "Refreshing ido tags list done")) | |
| (defun macoy-ido-find-tag () | |
| "Find a tag using ido" | |
| (interactive) | |
| (xref-find-definitions (ido-completing-read "Tag: " macoy-tag-names))) | |
| ;; For reference (see https://github.com/auto-complete/auto-complete/blob/master/doc/manual.md) | |
| ;; (defun mysource2-candidates () | |
| ;; '("Foo" "Bar" "Baz" "macoyTest2" "what" "zoooo")) | |
| ;; (defvar ac-source-mysource2 | |
| ;; '((candidates . mysource2-candidates))) | |
| (defvar ac-source-macoy-ido-tags | |
| '(;;(init . macoy-ido-find-tag-refresh) ;; Commented because it runs every time (unnecessary) | |
| (candidates . macoy-tag-names) | |
| (cache))) | |
| (setq-default ac-sources '(ac-source-macoy-ido-tags)) | |
| ;; Autocomplete from precompiled tags list (normal tags source is too slow) | |
| ;; Make sure auto-complete knows about yasnippets | |
| ;; From https://github.com/joaotavora/yasnippet/issues/336 | |
| (require 'auto-complete-config) | |
| (setq-default ac-sources '( | |
| ac-source-yasnippet | |
| ac-source-words-in-same-mode-buffers | |
| ac-source-macoy-ido-tags | |
| )) | |
| ;; Templates/Snippets | |
| (yas-global-mode 1) | |
| ;; cquery language server | |
| ;; Doesn't work | |
| ;;(require 'cquery) | |
| ;;(setq cquery-executable "F:/gitRepos/cquery/cmakeBuild/x64/Debug/cquery.exe") | |
| ;; If marked, use swiper to search mark | |
| (defun macoy-swiper-search-mark () | |
| "If marked, use swiper to search mark. Otherwise, open swiper normally" | |
| (interactive) | |
| ;; This isn't sufficient for my purposes; it's nice to search e.g. thing->thing | |
| ;;(swiper (thing-at-point 'symbol)) | |
| (if (use-region-p) | |
| (swiper (buffer-substring (region-beginning) (region-end))) | |
| (swiper) | |
| )) | |
| ;; Use swiper for search instead of isearch (use e.g. space to fuzzy search) | |
| (global-set-key (kbd "C-f") 'macoy-swiper-search-mark) | |
| ;; | |
| ;; Faster desktop creation/switching | |
| ;; | |
| (setq macoy-desktop-dir "~/.emacs.d/macoy-desktops/") | |
| (unless (file-exists-p macoy-desktop-dir) | |
| (make-directory macoy-desktop-dir) | |
| ) | |
| (defun macoy-save-desktop (new-desktop-name) | |
| "Save a desktop to the desktop registry for easy switching" | |
| (interactive "sNew desktop name:") | |
| (let ((new-desktop (concat macoy-desktop-dir new-desktop-name))) | |
| (make-directory new-desktop) | |
| (desktop-save new-desktop) | |
| (message "Created desktop at %s" new-desktop) | |
| )) | |
| (defun macoy-switch-desktop () | |
| "Use ido to list desktops to switch to" | |
| (interactive) | |
| (desktop-change-dir | |
| (concat macoy-desktop-dir | |
| (ido-completing-read "Switch Desktop:" | |
| (remove "." | |
| (remove ".." | |
| (directory-files macoy-desktop-dir))))))) | |
| ;; Open file in explorer | |
| (defun browse-file-directory () | |
| "Open the current file's directory however the OS would." | |
| (interactive) | |
| (if default-directory | |
| (browse-url-of-file (expand-file-name default-directory)) | |
| (error "No `default-directory' to open"))) | |
| ;; | |
| ;; Source control | |
| ;; | |
| (defun svn-check-for-modifications-src () | |
| "Open the TortoiseSVN Check for Modifications window" | |
| (interactive) | |
| (message "Checking for modifications") | |
| (start-process "CheckForModifications" nil | |
| "tortoiseproc" "/command:repostatus" "/path:F:\\CJUNCTIONS\\src")) | |
| (defun svn-show-log-src () | |
| "Open the TortoiseSVN Log window" | |
| (interactive) | |
| (message "SVN Log") | |
| (start-process "SVNLog" nil | |
| "tortoiseproc" "/command:log" "/path:F:\\CJUNCTIONS\\src")) | |
| (defun svn-update-src () | |
| "Open the TortoiseSVN Update window" | |
| (interactive) | |
| (message "SVN Update") | |
| (start-process "SVNUpdate" nil | |
| "tortoiseproc" "/command:update" "/path:F:\\CJUNCTIONS\\src")) | |
| ;; | |
| ;; Build systems | |
| ;; | |
| (defun buildStop () | |
| "Stop Incredibuild" | |
| (message "Stopping build") | |
| (start-process "Build" "*Build-out*" "BuildConsole.exe" | |
| "/Stop") | |
| ) | |
| (global-set-key (kbd "M-<f7>") (lambda () (interactive) (buildStop))) | |
| ;; | |
| ;; Custom multiple cursors cut/copy/paste handling | |
| ;; | |
| (setq macoy-multiple-cursors-buffers nil) | |
| (setq macoy-mc-buffer-index 0) | |
| (defun macoy-mc-copy () | |
| (interactive) | |
| (if (use-region-p) | |
| (push (buffer-substring (region-beginning) (region-end)) macoy-multiple-cursors-buffers) | |
| ;; TODO: Copy whole line if no region | |
| (message "TODO: Copy whole line if no region selected") | |
| ) | |
| ) | |
| (defun macoy-mc-cut () | |
| (interactive) | |
| ;; TODO: Cut whole line if no region | |
| (unless (use-region-p) | |
| (message "TODO: Cut whole line if no region selected") | |
| ) | |
| (when (use-region-p) | |
| (push (buffer-substring (region-beginning) (region-end)) macoy-multiple-cursors-buffers) | |
| (kill-region (region-beginning) (region-end))) | |
| ) | |
| (defun macoy-mc-paste () | |
| (interactive) | |
| ;; Delete selected text before insert if necessary | |
| (when (use-region-p) | |
| (delete-region (region-beginning) (region-end)) | |
| ) | |
| ;; If no macoy-multiple-cursors-buffers the user probably did a simple copy so paste that | |
| (unless macoy-multiple-cursors-buffers | |
| (call-interactively 'simpleclip-paste) | |
| ) | |
| (when macoy-multiple-cursors-buffers | |
| (insert (nth macoy-mc-buffer-index macoy-multiple-cursors-buffers)) | |
| ;; Set up next cursor buffer index | |
| ;; Ensure we don't go out of range of the buffers | |
| ;; Sublime's behavior is to just paste all buffers at all marks, so our solution is different here | |
| (setq macoy-mc-buffer-index (min | |
| (+ macoy-mc-buffer-index 1) | |
| (- (length macoy-multiple-cursors-buffers) 1))) | |
| ) | |
| ) | |
| (defun macoy-multiple-cursors-copy() | |
| "Copy at multiple cursors using macoy-multiple-cursors-buffers" | |
| (interactive) | |
| (setq macoy-multiple-cursors-buffers nil) | |
| (mc/for-each-cursor-ordered | |
| (mc/execute-command-for-fake-cursor 'macoy-mc-copy cursor)) | |
| ;; Append happens in reverse | |
| (setq macoy-multiple-cursors-buffers (reverse macoy-multiple-cursors-buffers)) | |
| ;; Adding newline isn't correct but emacs won't copy the newline. It is slightly more useful | |
| ;; to paste things with the newlines when collapsing multiple selections | |
| (simpleclip-set-contents (string-join macoy-multiple-cursors-buffers "\n")) | |
| ) | |
| (defun macoy-multiple-cursors-cut() | |
| "Copy at multiple cursors using macoy-multiple-cursors-buffers" | |
| (interactive) | |
| (setq macoy-multiple-cursors-buffers nil) | |
| (mc/for-each-cursor-ordered | |
| (mc/execute-command-for-fake-cursor 'macoy-mc-cut cursor)) | |
| (setq macoy-multiple-cursors-buffers (reverse macoy-multiple-cursors-buffers)) | |
| ;; Adding newline isn't correct but emacs won't copy the newline. It is slightly more useful | |
| ;; to paste things with the newlines when collapsing multiple selections | |
| (simpleclip-set-contents (string-join macoy-multiple-cursors-buffers "\n")) | |
| ) | |
| (defun macoy-multiple-cursors-paste() | |
| "Paste at multiple cursors using macoy-multiple-cursors-buffers" | |
| (interactive) | |
| (setq macoy-mc-buffer-index 0) | |
| (mc/for-each-cursor-ordered | |
| (mc/execute-command-for-fake-cursor 'macoy-mc-paste cursor)) | |
| ) | |
| (defun macoy-test-multiple-cursors-print-list() | |
| "Print buffers" | |
| (interactive) | |
| (message "%d in buffer" (length macoy-multiple-cursors-buffers)) | |
| (dolist (buffer macoy-multiple-cursors-buffers) | |
| (message "Buffer: %s" buffer)) | |
| ) | |
| ;; | |
| ;; Custom copy/cut/paste functions so one key can work for simpleclip and multiple-cursors | |
| ;; Make sure to add these to mc/cmds-to-run-once and restart Emacs | |
| (defun macoyCopy () | |
| (interactive) | |
| ;; Clear buffers here in case they aren't using multiple cursors | |
| ;; Then, if they paste in multiple-cursors-mode it will paste simpleclip | |
| (setq macoy-multiple-cursors-buffers nil) | |
| (if (bound-and-true-p multiple-cursors-mode) | |
| (call-interactively 'macoy-multiple-cursors-copy) ;; Was kill-ring-save | |
| (call-interactively 'simpleclip-copy)) | |
| ) | |
| (defun macoyCut () | |
| (interactive) | |
| ;; Clear buffers here in case they aren't using multiple cursors | |
| ;; Then, if they paste in multiple-cursors-mode it will paste simpleclip | |
| (setq macoy-multiple-cursors-buffers nil) | |
| (if (bound-and-true-p multiple-cursors-mode) | |
| (call-interactively 'macoy-multiple-cursors-cut) ;; Was kill-region | |
| (call-interactively 'simpleclip-cut)) | |
| ) | |
| (defun macoyPaste () | |
| (interactive) | |
| (if (bound-and-true-p multiple-cursors-mode) | |
| (call-interactively 'macoy-multiple-cursors-paste) ;; Was yank | |
| (call-interactively 'simpleclip-paste)) | |
| ) | |
| ;; | |
| ;; | |
| ;; Macoy's keybinds which require better override | |
| (defvar my-keys-minor-mode-map | |
| (let ((map (make-sparse-keymap))) | |
| (define-key map (kbd "C-d") 'mc/mark-next-like-this) | |
| (define-key map (kbd "C-M-a") 'macoy-clang-format-region-or-buffer) | |
| ;; Custom copy/paste functions for working with simpleclip and multiple-cursors | |
| (define-key map (kbd "C-c") 'macoyCopy) | |
| (define-key map (kbd "C-v") 'macoyPaste) | |
| (define-key map (kbd "C-x") 'macoyCut) | |
| ;; In case you need the dumb copy paste (or multiple cursors clipboard after exiting mc) | |
| (define-key map (kbd "C-S-c") 'kill-ring-save) | |
| (define-key map (kbd "C-S-v") 'yank) | |
| (define-key map (kbd "C-S-x") 'kill-region) | |
| (define-key map (kbd "M-a") 'tags-query-replace) | |
| (define-key map (kbd "M-j") 'pop-global-mark) | |
| ;; Overrides c-indent-line-or-region (this should be in C mode only, plus <tab>) | |
| ;;(define-key map (kbd "C-i") 'clang-format) | |
| map) | |
| "my-keys-minor-mode keymap.") | |
| (define-minor-mode my-keys-minor-mode | |
| "A minor mode so that my key settings override annoying major modes." | |
| :init-value t | |
| :lighter " my-keys") | |
| (my-keys-minor-mode 1) | |
| ;; | |
| ;; Macoy's Keybind overrides | |
| ;; | |
| ;; Many come from http://ergoemacs.org/emacs/emacs_make_modern.html | |
| ;; make {copy, cut, paste, undo} have {C-c, C-x, C-v, C-z} keys | |
| ;;(cua-mode 1) (disabled in favor of simpleclip) | |
| (global-set-key (kbd "C-z") 'undo) | |
| ;; Ctrl shift P like sublime for commands | |
| (global-set-key (kbd "C-S-p") 'smex) | |
| ;; Save As. was nil | |
| (global-set-key (kbd "C-S-s") 'write-file) | |
| ;; Close. was kill-region | |
| (global-set-key (kbd "C-w") 'kill-buffer) | |
| ;; Select All. was move-beginning-of-line | |
| (global-set-key (kbd "C-a") 'mark-whole-buffer) | |
| ;; Open. was open-line | |
| (global-set-key (kbd "C-o") 'ido-find-file) | |
| ;; Save. was isearch-forward | |
| (global-set-key (kbd "C-s") 'save-buffer) | |
| ;; Save As. was nil | |
| (global-set-key (kbd "C-S-s") 'write-file) | |
| ;; Find. was forward-char | |
| ;; Replaced by swiper above | |
| ;;(global-set-key (kbd "C-f") 'isearch-forward) | |
| ;; Switch buffers. Was backward-char | |
| (global-set-key (kbd "C-b") 'ido-switch-buffer) | |
| ;; Switch desktops | |
| (global-set-key (kbd "C-S-b") 'macoy-switch-desktop) | |
| ;; Create desktop | |
| (global-set-key (kbd "M-d") 'macoy-save-desktop) | |
| ;; Switch windows via ctrl-page up and down | |
| (global-set-key (kbd "C-<next>") 'other-window) | |
| (global-set-key (kbd "C-<prior>") 'previous-multiframe-window) | |
| ;; Switch windows via ctrl tab | |
| (global-set-key (kbd "C-<tab>") 'other-window) | |
| (global-set-key (kbd "C-S-<tab>") 'previous-multiframe-window) | |
| ;; Find file in project (via projectile) was previous-line | |
| (global-set-key (kbd "C-p") 'projectile-find-file) | |
| ;; Revert buffer | |
| (global-set-key (kbd "<f5>") 'revert-buffer) | |
| ;; Kill line like Sublime | |
| (global-set-key (kbd "C-S-k") 'kill-whole-line) | |
| ;; Go to first character of line, not beginning of line. Was move-beginning-of-line | |
| (global-set-key (kbd "<home>") 'back-to-indentation) | |
| ;; Toggle comment lines (same keybind as Sublime). This also works for regions | |
| (global-set-key (kbd "C-/") 'comment-line) | |
| ;; Simpleclip cut copy paste (not sure if this is essential due to customize-group settings) | |
| ;; These are also set in my-keys mode with macoyCopy functions for multiple-cursors support, | |
| ;; overriding these defaults | |
| (global-set-key (kbd "C-c") 'simpleclip-copy) | |
| (global-set-key (kbd "C-x") 'simpleclip-cut) | |
| (global-set-key (kbd "C-v") 'simpleclip-paste) | |
| ;; point-to-register and jump-to-register (was reverse search) | |
| (global-set-key (kbd "C-r") 'jump-to-register) | |
| (global-set-key (kbd "C-S-r") 'point-to-register) | |
| ;; copy-to-register and insert-register | |
| (global-set-key (kbd "M-r") 'insert-register) | |
| (global-set-key (kbd "M-R") 'copy-to-register) | |
| ;; Move to beginning/end of function | |
| (global-set-key (kbd "M-<up>") 'c-beginning-of-defun) | |
| (global-set-key (kbd "M-<down>") 'c-end-of-defun) | |
| ;; Window management | |
| ;; Split horizonal (was transpose-chars) | |
| (global-set-key (kbd "C-t") 'split-window-horizontally) | |
| (global-set-key (kbd "C-S-t") 'split-window-vertically) | |
| (global-set-key (kbd "C-S-w") 'delete-window) | |
| ;; Go back (unfortunately no forward yet) | |
| (global-set-key (kbd "M-j") 'pop-global-mark) | |
| ;; Replace all of a tag in all files | |
| (global-set-key (kbd "M-a") 'tags-query-replace) | |
| ;; Make bindings work with org-mode | |
| (with-eval-after-load 'org | |
| (define-key org-mode-map (kbd "C-<tab>") nil) | |
| (define-key org-mode-map (kbd "C-j") nil) | |
| (define-key org-mode-map (kbd "C") nil) | |
| ;; Don't mess with my arrow keys. I use them a lot | |
| (define-key org-mode-map (kbd "C-S-<down>") nil) | |
| (define-key org-mode-map (kbd "C-S-<left>") nil) | |
| (define-key org-mode-map (kbd "C-S-<right>") nil) | |
| (define-key org-mode-map (kbd "C-S-<up>") nil) | |
| (define-key org-mode-map (kbd "M-S-<down>") nil) | |
| (define-key org-mode-map (kbd "M-S-<left>") nil) | |
| (define-key org-mode-map (kbd "M-S-<right>") nil) | |
| (define-key org-mode-map (kbd "M-S-<up>") nil) | |
| (define-key org-mode-map (kbd "M-<down>") nil) | |
| (define-key org-mode-map (kbd "M-<left>") nil) | |
| (define-key org-mode-map (kbd "M-<right>") nil) | |
| (define-key org-mode-map (kbd "M-<up>") nil) | |
| (define-key org-mode-map (kbd "S-<down>") nil) | |
| (define-key org-mode-map (kbd "S-<left>") nil) | |
| (define-key org-mode-map (kbd "S-<right>") nil) | |
| (define-key org-mode-map (kbd "S-<up>") nil) | |
| ) | |
| ;; | |
| ;; Hand-written by Macoy end | |
| ;; | |
| (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. | |
| '(ansi-color-faces-vector | |
| [default default default italic underline success warning error]) | |
| '(ansi-color-names-vector | |
| ["black" "red3" "ForestGreen" "yellow3" "blue" "magenta3" "DeepSkyBlue" "gray50"]) | |
| '(ansi-term-color-vector | |
| [unspecified "#ffffff" "#c82829" "#718c00" "#eab700" "#4271ae" "#8959a8" "#4271ae" "#4d4d4c"] t) | |
| '(back-button-global-backward-keystrokes (quote ("S-<backspace>"))) | |
| '(back-button-global-forward-keystrokes (quote ("S-<delete>"))) | |
| '(back-button-global-keystrokes (quote ("C-S-x <C-SPC>"))) | |
| '(back-button-local-backward-keystrokes (quote ("S-<backspace>"))) | |
| '(back-button-local-forward-keystrokes (quote ("S-<delete>"))) | |
| '(back-button-local-keystrokes (quote ("C-S-x <C-SPC>"))) | |
| '(back-button-smartrep-prefix "C-S-x") | |
| '(custom-enabled-themes (quote (base16-ashes))) | |
| '(desktop-registry-registry | |
| (quote | |
| ((".emacs.d" . "c:/Users/mmadson/AppData/Roaming/.emacs.d") | |
| ("starterSrc" . "c:/SublimeProjects/emacsDesktops/starterSrc")))) | |
| '(diary-entry-marker (quote font-lock-variable-name-face)) | |
| '(emms-mode-line-icon-image-cache | |
| (quote | |
| (image :type xpm :ascent center :data "/* XPM */ | |
| static char *note[] = { | |
| /* width height num_colors chars_per_pixel */ | |
| \" 10 11 2 1\", | |
| /* colors */ | |
| \". c #1fb3b3\", | |
| \"# c None s None\", | |
| /* pixels */ | |
| \"###...####\", | |
| \"###.#...##\", | |
| \"###.###...\", | |
| \"###.#####.\", | |
| \"###.#####.\", | |
| \"#...#####.\", | |
| \"....#####.\", | |
| \"#..######.\", | |
| \"#######...\", | |
| \"######....\", | |
| \"#######..#\" };"))) | |
| '(fci-rule-color "#383838") | |
| '(gnus-logo-colors (quote ("#2fdbde" "#c0c0c0")) t) | |
| '(gnus-mode-line-image-cache | |
| (quote | |
| (image :type xpm :ascent center :data "/* XPM */ | |
| static char *gnus-pointer[] = { | |
| /* width height num_colors chars_per_pixel */ | |
| \" 18 13 2 1\", | |
| /* colors */ | |
| \". c #1fb3b3\", | |
| \"# c None s None\", | |
| /* pixels */ | |
| \"##################\", | |
| \"######..##..######\", | |
| \"#####........#####\", | |
| \"#.##.##..##...####\", | |
| \"#...####.###...##.\", | |
| \"#..###.######.....\", | |
| \"#####.########...#\", | |
| \"###########.######\", | |
| \"####.###.#..######\", | |
| \"######..###.######\", | |
| \"###....####.######\", | |
| \"###..######.######\", | |
| \"###########.######\" };")) t) | |
| '(large-file-warning-threshold 40000000) | |
| '(linum-format " %7i ") | |
| '(org-support-shift-select t) | |
| '(package-archives | |
| (quote | |
| (("marmalade" . "https://marmalade-repo.org/packages/") | |
| ("gnu" . "http://elpa.gnu.org/packages/") | |
| ("melpa" . "http://melpa.org/packages/")))) | |
| '(package-selected-packages | |
| (quote | |
| (adaptive-wrap web-beautify etags-select desktop-registry simpleclip yasnippet swiper company ac-etags auto-complete clang-format avy ace-jump-mode ag xah-find dtrt-indent flx-ido ido-vertical-mode sublime-themes smooth-scrolling alect-themes base16-theme powerline darktooth-theme dumb-jump projectile smex fiplr helm-dash better-defaults multiple-cursors zenburn-theme marmalade-demo))) | |
| '(pos-tip-background-color "#36473A") | |
| '(pos-tip-foreground-color "#FFFFC8") | |
| '(projectile-globally-ignored-directories | |
| (quote | |
| (".idea" ".ensime_cache" ".eunit" ".git" ".hg" ".fslckout" "_FOSSIL_" ".bzr" "_darcs" ".tox" ".svn" ".stack-work" "AutoGen" "obj140"))) | |
| '(projectile-indexing-method (quote native)) | |
| '(simpleclip-copy-keystrokes (quote ("C-c" "C-<insert>" "C-<insertchar>"))) | |
| '(simpleclip-cut-keystrokes (quote ("C-x" "C-S-<insert>"))) | |
| '(simpleclip-paste-keystrokes (quote ("C-v" "S-<insert>" "S-<insertchar>"))) | |
| '(tab-width 4) | |
| '(vc-annotate-background "#2B2B2B") | |
| '(vc-annotate-color-map | |
| (quote | |
| ((20 . "#BC8383") | |
| (40 . "#CC9393") | |
| (60 . "#DFAF8F") | |
| (80 . "#D0BF8F") | |
| (100 . "#E0CF9F") | |
| (120 . "#F0DFAF") | |
| (140 . "#5F7F5F") | |
| (160 . "#7F9F7F") | |
| (180 . "#8FB28F") | |
| (200 . "#9FC59F") | |
| (220 . "#AFD8AF") | |
| (240 . "#BFEBBF") | |
| (260 . "#93E0E3") | |
| (280 . "#6CA0A3") | |
| (300 . "#7CB8BB") | |
| (320 . "#8CD0D3") | |
| (340 . "#94BFF3") | |
| (360 . "#DC8CC3")))) | |
| '(vc-annotate-very-old-color "#DC8CC3")) | |
| (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 "Ubuntu Mono" :foundry "outline" :slant normal :weight normal :height 120 :width normal))))) |