@ -81,18 +81,16 @@
;; Learn how to do custom mode for jumping back
;; - Expand-region does strange things with the region. Eg. C-s-' after moving cursor, expand region then type over (damn it; it went away after re-evaluating .emacs)
;; - Start using Abbrev more
;;*- Create an explicit setup for jump to go back to last location (don't rely on marks; just store position)
;; i.e. Reliable quick mark set and return for jumping to X from Y then going back to Y
;; This would be useful without jumping too. Basically just use register and one key to set/jump to (C- vs C-S)
;; - It seems like iy-goto-char will eventually trip me up in its temporary mode (so far it's fine)
;; - Seems like it would be cool to have a "copy to references" thing which would take marked and
;; put it in a references.org file or something for deep code reading dives (what about projects?)
;; - Command to close all dired buffers
;; - User-specific emacs configs (see http://whattheemacsd.com/ "Need different settings for different machines")
;; - Organize this file (org mode supported via outshine.el?)
;; - Make it so mark is cleared if arrow key away
;; - Make it so mark is cleared if arrow key away (has to do with expand-region)
;; - Find file in dir (basically ido find file but actually useful; how does it work?)
;; - Macoy-Codesearch should have something for whole word searches as well as sanitizing regex symbols
;; I tried to do this but it doesn't work :/
;;*- IMPORTANT Codesearch ignore autogenerated files (maybe during building index?)
;; - Codesearch doesn't seem to actually be updating during index (wtf?)
;; - Isearch: Make reversing the isearch not find the same thing again
@ -101,18 +99,22 @@
;; to the last search until you get to the original place, then it clears the search. This is confusing :(
;; - Mysterious thing which deletes the last half of the buffer (c-remove-stale-state-cache-backwards?)
;; - Codesearch: Regex filtering doesn't work (try e.g. "myfunc(")
;;
;; - Fix window splitting on Linux/4k
;; - Feature: filter lines in file (good for codesearch results etc.). Extra cool = as you type (hard) (install something for this)
;; keep-lines does this, although not as you type, and requires modifying the buffer (make a func which dupes and does it)
;; Use (clone-indirect-buffer) (https://www.gnu.org/software/emacs/manual/html_node/emacs/Indirect-Buffers.html)?
;;;;
;; Criticism improvements:
;; - [DONE] Select word at point
;; - [DONE] Reopen closed file
;; - [DONE-ish] Get find references working
;; - [DONE] Autorevert if no modifications (do tell me in modeline that this happened)
;; - [DONE] Faster/better Ag
;; - [DONE] Swiper is too damn slow
;; Eventually make tags-search and tags-loop-continue async and list results in a buffer
;; - Faster browse symbols (first, figure out where most symbols come from and eliminate; then separate projects?)
;; Separate lists by first letter for x26 speedup? (kindof defeats purpose if not knowing first letter)
;; Copy swiper-all requiring multiple letters? (this doesn't seem to help too much)
;; - Swiper is too damn slow
;; Emacs Notes
;; C-h k <the keybind> to find what a key does
@ -189,6 +191,10 @@
;; care too much about losing our frame configurations so this is okay
(setq desktop-restore-frames nil)
;; For theming: Make base16 not have distinct fringes, for a more minimal look
(require 'base16-theme)
(setq base16-distinct-fringe-background nil)
;; Automatically revert buffers if file changes underneath (unless there are unsaved changes)
(global-auto-revert-mode 1)
@ -199,6 +205,10 @@
;; Set cursor to I-beam
(modify-all-frames-parameters (list (cons 'cursor-type '(bar . 2))))
;; 4k monitor demands extra thicc cursor
(when (string-equal (user-login-name) "macoy")
(modify-all-frames-parameters (list (cons 'cursor-type '(bar . 3))))
)
;; Templates/Snippets
(yas-global-mode 1)
@ -207,6 +217,11 @@
(setq org-startup-indented t)
;; My org files
(when (string-equal (user-login-name) "macoy")
(setq org-agenda-files (list "~/Dropbox/Org/1_Calendar.org"
"~/Dropbox/Org/0_Dump.org"))
)
(when (string-equal (user-login-name) "mmadson")
(setq org-agenda-files (list "C:/Users/mmadson/Dropbox/Org/1_Calendar.org"
"C:/Users/mmadson/Dropbox/Org/0_Dump.org"))
@ -238,6 +253,7 @@
"*vc-change-log*"
"*vc-diff*"
"*xref*"
"*Macoy-Select-Search*"
))
(mapcar
(lambda (buffer-to-kill)
@ -249,38 +265,40 @@
)
;; Store recently closed files so we can easily reopen them
(setq macoy-recently-killed-files (list))
(defun macoy-on-kill-buffer ()
(when buffer-file-name
(push buffer-file-name macoy-recently-killed-files)
)
)
(add-hook 'kill-buffer-hook 'macoy-on-kill-buffer)
(defun macoy-reopen-last-killed-file ()
"Open the last killed file (stored in macoy-recently-killed-files)"
(interactive)
(unless macoy-recently-killed-files
(message "There are no recently closed buffers")
)
(when macoy-recently-killed-files
(find-file (pop macoy-recently-killed-files))
)
)
(defun macoy-reopen-recent-killed-file ()
"Pick from the list of recently killed files"
(interactive)
(unless macoy-recently-killed-files
(message "There are no recently closed buffers")
)
(when macoy-recently-killed-files
(find-file (ido-completing-read "Reopen file: " macoy-recently-killed-files))
)
)
(global-set-key (kbd "C-S-t") 'macoy-reopen-last-killed-file)
(global-set-key (kbd "C-M-t") 'macoy-reopen-recent-killed-file)
(recentf-mode 1)
(global-set-key (kbd "C-S-t") 'recentf-open-files)
;; (setq macoy-recently-killed-files (list))
;; (defun macoy-on-kill-buffer ()
;; (when buffer-file-name
;; (push buffer-file-name macoy-recently-killed-files)
;; )
;; )
;; (add-hook 'kill-buffer-hook 'macoy-on-kill-buffer)
;; (defun macoy-reopen-last-killed-file ()
;; "Open the last killed file (stored in macoy-recently-killed-files)"
;; (interactive)
;; (unless macoy-recently-killed-files
;; (message "There are no recently closed buffers")
;; )
;; (when macoy-recently-killed-files
;; (find-file (pop macoy-recently-killed-files))
;; )
;; )
;; (defun macoy-reopen-recent-killed-file ()
;; "Pick from the list of recently killed files"
;; (interactive)
;; (unless macoy-recently-killed-files
;; (message "There are no recently closed buffers")
;; )
;; (when macoy-recently-killed-files
;; (find-file (ido-completing-read "Reopen file: " macoy-recently-killed-files))
;; )
;; )
;; (global-set-key (kbd "C-S-t") 'macoy-reopen-last-killed-file)
;; (global-set-key (kbd "C-M-t") 'macoy-reopen-recent-killed-file)
;; Quickly search the web
;; See https://github.com/hrs/engine-mode for more browsers
@ -398,12 +416,55 @@
(require 'smooth-scrolling)
(smooth-scrolling-mode 1)
;; Custom place saving (to get back to where you where after a jump or something)
;; Store what we last did for the toggle
(setq macoy-place-last-operation "load")
;; Quick save place and jump back to it
(defun macoy-save-place ()
"Store the current position in a register"
(interactive)
(point-to-register ?=)
(setq macoy-place-last-operation "save")
(message "Point saved")
)
(defun macoy-load-place ()
"Go to the last position saved in the macoy register"
(interactive)
(jump-to-register ?=)
(setq macoy-place-last-operation "load")
(message "Point loaded")
)
(defun macoy-save-place-then-call (function-to-call)
"Save the place then call function-to-call"
(interactive)
(call-interactively 'macoy-save-place)
(call-interactively function-to-call)
)
(defun macoy-save-or-load-place ()
"Either save or load the place, depending on what was done previously"
(interactive)
(if (string-equal macoy-place-last-operation "load")
(call-interactively 'macoy-save-place)
(call-interactively 'macoy-load-place)
)
)
(global-set-key (kbd "C-=") 'macoy-save-or-load-place)
(global-set-key (kbd "C-+") 'macoy-save-place)
;; 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)
(global-set-key (kbd "C-S-g") (lambda () (interactive) (macoy-save-place-then-call
'avy-goto-line)))
(global-set-key (kbd "C-S-j") (lambda () (interactive) (macoy-save-place-then-call
'avy-goto-char)))
(global-set-key (kbd "C-j") (lambda () (interactive) (macoy-save-place-then-call
'avy-goto-word-or-subword-1)))
(defun macoy-quick-jump-copy-paste ()
"Use Avy to jump to a position, select something, then jump back and paste it"
@ -436,7 +497,9 @@
(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
@ -453,6 +516,99 @@
(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
;;
;; Macoy-select-search: given a search string, select from many different types of search methods
;;
(setq macoy-select-search-buf-name "*Macoy-Select-Search*")
(setq macoy-select-search-search "")
;; Copied from ag/dwim-at-point in ag.el
(defun macoy-dwim-at-point ()
"If there's an active selection, return that.
Otherwise, get the symbol at point, as a string."
(cond ((use-region-p)
(buffer-substring-no-properties (region-beginning) (region-end)))
((symbol-at-point)
(substring-no-properties
(symbol-name (symbol-at-point))))))
;; Copied from ag/read-from-minibuffer in ag.el
(defun macoy-read-from-minibuffer (prompt)
"Read a value from the minibuffer with PROMPT.
If there's a string at point, offer that as a default."
(let* ((suggested (macoy-dwim-at-point))
(final-prompt
(if suggested
(format "%s (default %s): " prompt suggested)
(format "%s: " prompt)))
;; Ask the user for input, but add `suggested' to the history
;; so they can use M-n if they want to modify it.
(user-input (read-from-minibuffer
final-prompt
nil nil nil nil suggested)))
;; Return the input provided by the user, or use `suggested' if
;; the input was empty.
(if (> (length user-input) 0)
user-input
suggested)))
(defun macoy-select-do-search (search-function &rest after-search-args)
"Using `search-function', execute the search"
(interactive)
(message default-directory)
(kill-buffer macoy-select-search-buf-name)
(apply search-function macoy-select-search-search after-search-args)
)
(setq macoy-select-search-key-descriptions "Select search:
\ta - Ag (in same directory as file)
\tb - Ag (browse for directory)
\tc - Codesearch (with filter)")
(defvar macoy-select-search-minor-mode-map
(let ((map (make-sparse-keymap)))
;; Ag with default directory
(define-key map (kbd "a") (lambda () (interactive) (macoy-select-do-search
'ag default-directory)))
;; Ag with browse directory
(define-key map (kbd "b") (lambda () (interactive) (macoy-select-do-search
'ag (read-directory-name "Directory: "))))
;; Codesearch with filter
(define-key map (kbd "c") (lambda () (interactive) (macoy-select-do-search
'macoy-codesearch-search-with-filter)))
map)
"macoy-select-search-minor-mode keymap.")
(define-minor-mode macoy-select-search-minor-mode
"A minor mode for selecting the search function which should be used."
:init-value nil
:lighter " MacoySelectSearch")
(defun macoy-select-search (string)
(interactive (list (macoy-read-from-minibuffer "Search string")))
;; Only search if search string
(when string
;; Hang on to the search string
(setq macoy-select-search-search string)
;; Create a buffer `macoy-select-search-buf-name'
(get-buffer-create macoy-select-search-buf-name)
;; Switch to the `macoy-select-search-buf-name' buffer
;; (switch-to-buffer-other-window macoy-select-search-buf-name)
(switch-to-buffer macoy-select-search-buf-name)
(insert macoy-select-search-key-descriptions)
;; Set its major mode to `special-mode'
(special-mode) ; a read-only major mode
;; As you are now in the `macoy-select-search-buf-name' buffer, you can do the below:
;; - hit `q' to quit the current window *without* killing `macoy-select-search-buf-name'
;; - hit `C-u q' to quit the current window *and* kill `macoy-select-search-buf-name'
(macoy-select-search-minor-mode 1)
))
;; Searching in files (Ag)
;; Make ag.el reuse the same *ag* buffer for all your searches:
(setq ag-reuse-buffers 't)
@ -597,11 +753,7 @@
(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
@ -745,7 +897,7 @@
;; Find references via tags-search. This is my find-references replacement
(defun macoy-tags-search ()
"Pick tag with macoy-ido-find-tag then run tags-search (or search marked)"
"Pick tag with ` macoy-ido-find-tag' then run ` tags-search' (or search marked)"
(interactive)
(if (use-region-p)
(tags-search (buffer-substring (region-beginning) (region-end)))
@ -918,6 +1070,26 @@
;; Build systems
;;
(defun build-universal-jam ()
"Build using jam (select directory first)"
(interactive)
(message "Building macoy-fuzzy")
(let ((default-directory (read-directory-name "Directory: ")))
(compile
"jam -j4 -q")
)
)
(defun build-universal-jam-clean ()
"Build using jam (select directory first)"
(interactive)
(message "Building macoy-fuzzy")
(let ((default-directory (read-directory-name "Directory: ")))
(compile
"jam clean")
)
)
;; An example build command
;; (defun build-MasterSolution-MsBuild-CompileCommand ()
;; "Run MSBuild on MasterSolution via compile-command"
@ -986,11 +1158,12 @@
)
)
;; For versions newer than 25.3 or something :(
(defun string-join (sl delim)
(mapconcat 'identity sl delim))
(defun macoy-multiple-cursors-copy()
"Copy at multiple cursors using macoy-multiple-cursors-buffers"
"Copy at multiple cursors using ` macoy-multiple-cursors-buffers' "
(interactive)
(setq macoy-multiple-cursors-buffers nil)
(mc/for-each-cursor-ordered
@ -1003,7 +1176,7 @@
)
(defun macoy-multiple-cursors-cut()
"Cut at multiple cursors using macoy-multiple-cursors-buffers"
"Cut at multiple cursors using ` macoy-multiple-cursors-buffers' "
(interactive)
(setq macoy-multiple-cursors-buffers nil)
(mc/for-each-cursor-ordered
@ -1015,7 +1188,7 @@
)
(defun macoy-multiple-cursors-paste()
"Paste at multiple cursors using macoy-multiple-cursors-buffers"
"Paste at multiple cursors using ` macoy-multiple-cursors-buffers' "
(interactive)
(setq macoy-mc-buffer-index 0)
(mc/for-each-cursor-ordered
@ -1102,6 +1275,31 @@
;;
;; Auto Theming
;;
;; Follow the instructions at https://github.com/makuto/auto-base16-theme to get all this set up
(when (string-equal (user-login-name) "mmadson")
(setq macoy-auto-theme-schemer2-bin "c:/Users/mmadson/go/bin/schemer2.exe")
(setq macoy-auto-theme-script-dir "f:/gitRepos/auto-base16-theme")
(setq macoy-auto-theme-output-file "c:/Users/mmadson/AppData/Roaming/.emacs.d/elpa/base16-theme-20180320.2254/base16-my-auto-theme.el")
)
(when (string-equal (user-login-name) "macoy")
(setq macoy-auto-theme-schemer2-bin "schemer2")
(setq macoy-auto-theme-script-dir "~/Development/code/repositories/auto-base16-theme")
(setq macoy-auto-theme-output-file "~/.emacs.d/elpa/base16-theme-20180320.2254/base16-my-auto-theme.el")
)
(defun macoy-generate-auto-theme ()
"Create a base16 auto-theme using AutoBase16Theme.py based on the image selected."
(interactive)
(let ((default-directory macoy-auto-theme-script-dir))
(compile
(format "%s -format img::colors -in \"%s\" -out colors.txt && python3 AutoBase16Theme.py emacs-base16-theme-template.el %s"
macoy-auto-theme-schemer2-bin (read-file-name "Image: ") macoy-auto-theme-output-file))
)
)
;; Reference Windows command:
;;c:/Users/mmadson/go/bin/schemer2.exe -format img::colors -in C:/Users/mmadson/Downloads/Wallpapers/32\ -\ fHFDkjY.jpg -out colors.txt && python3 AutoBase16Theme.py emacs-base16-theme-template.el c:/Users/mmadson/AppData/Roaming/.emacs.d/elpa/base16-theme-20180320.2254/base16-my-auto-theme.el
;;
@ -1262,7 +1460,17 @@
(define-key compilation-mode-map (kbd "n") 'compilation-next-error)
(define-key compilation-mode-map (kbd "p") 'compilation-previous-error)
;;
;; Make bindings work with org-mode
;;
(defun macoy-org-insert-heading-respect-content-before ()
"The same as `org-insert-heading-respect-content' only do it before current heading"
(interactive)
(call-interactively 'org-previous-visible-heading)
(call-interactively 'org-insert-heading-respect-content)
)
(with-eval-after-load 'org
(define-key org-mode-map (kbd "C-<tab>") nil)
(define-key org-mode-map (kbd "C-j") nil)
@ -1284,6 +1492,9 @@
(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)
;; I already have a convention where C-Enter and C-S-Enter open up new lines; let's make org follow that
(define-key org-mode-map (kbd "C-S-<return>") 'macoy-org-insert-heading-respect-content-before)
)
;; Make bindings work with magit
@ -1305,14 +1516,7 @@
["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)))
'(custom-enabled-themes (quote (base16-my-auto)))
'(diary-entry-marker (quote font-lock-variable-name-face))
'(ediff-split-window-function (quote split-window-horizontally))
'(emms-mode-line-icon-image-cache
@ -1378,9 +1582,6 @@ static char *gnus-pointer[] = {
(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-y" "C-<insert>" "C-<insertchar>")))
'(simpleclip-cut-keystrokes (quote ("C-u" "C-S-<insert>")))
'(simpleclip-paste-keystrokes (quote ("C-v" "S-<insert>" "S-<insertchar>")))
'(tab-width 4)
'(vc-annotate-background "#2B2B2B")
'(vc-annotate-color-map
@ -1430,8 +1631,8 @@ static char *gnus-pointer[] = {
;; Make fringe same color as background. We still want fringe for wrap indicators
;; If you change your theme you should run this code again
;; Note that the vertical border uses the fringe color before we set it to default
;; TODO: Should this be (setq base16-distinct-fringe-background nil) instead?
(set-face-background 'fringe (face-background 'default))
;; Commented because above we set base16-distinct-fringe-background to nil
;; (set-face-background 'fringe (face-background 'default))
;; Make avy faces beautiful
;; Note that we swap foreground and background to emulate the inverse-video setting (there's probably