Giant refactor! (part 1)

This commit is contained in:
Henrik Lissner 2016-05-20 19:08:02 -04:00
parent f38d868504
commit a984bf4f26
20 changed files with 490 additions and 541 deletions

View file

@ -1,18 +1,6 @@
;;; my-bindings.el
;; Minimalistic key mapping! Why go so far for this?
;; ...
;; Uh. Good question.
(eval-when-compile (require 'core-defuns))
;; See `narf-leader-prefix' & `narf-localleader-prefix' in ../core/core.el
(map!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Global keymaps ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
"M-x" 'helm-M-x
"A-x" 'helm-M-x
"M-;" 'eval-expression
@ -31,9 +19,8 @@
"M-t" 'narf:tab-create
"M-T" 'narf/tab-display
"A-`" 'os-switch-to-term
"C-`" 'narf/popup-messages
"C-`" 'narf/popup-toggle
"C-~" 'narf:repl
"M-`" 'narf/popup-toggle
"M-w" 'narf/close-window-or-tab
"M-W" 'delete-frame
@ -46,10 +33,10 @@
"C-h" 'evil-window-left
"C-l" 'evil-window-right
"A-j" (λ! (narf/evil-window-resize 'below))
"A-k" (λ! (narf/evil-window-resize 'above))
"A-h" (λ! (narf/evil-window-resize 'left))
"A-l" (λ! (narf/evil-window-resize 'right))
"A-j" 'narf/evil-window-resize-d
"A-k" 'narf/evil-window-resize-u
"A-h" 'narf/evil-window-resize-l
"A-l" 'narf/evil-window-resize-r
"C-<escape>" 'evil-emacs-state
:e "C-<escape>" 'evil-normal-state
@ -95,11 +82,6 @@
:i "<A-backspace>" 'evil-delete-backward-word
:i "<A-delete>" (λ! (evil-forward-word) (evil-delete-backward-word)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Local keymaps ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
:m ";" 'evil-ex
(:leader
:nv "," 'narf/helm-buffers-dwim
@ -252,9 +234,9 @@
;; aliases for %
:m "%" 'evilmi-jump-items
:m [tab] (λ! (if (ignore-errors (hs-already-hidden-p))
(hs-toggle-hiding)
(call-interactively 'evilmi-jump-items)))
:m [tab] (λ! (if (ignore-errors (hs-already-hidden-p))
(hs-toggle-hiding)
(call-interactively 'evilmi-jump-items)))
;; Textmate-esque newlines
:i "<backspace>" 'backward-delete-char-untabify
@ -297,6 +279,22 @@
"C-S-w" (λ! (ace-window 4)) ; swap windows
"C-C" (λ! (ace-window 16))) ; delete windows
;; `evil-multiedit'
:v "R" 'evil-multiedit-match-all
:n "M-C-D" 'evil-multiedit-restore
:nv "M-d" 'evil-multiedit-match-and-next
:nv "M-D" 'evil-multiedit-match-and-prev
(:map evil-multiedit-state-map
:v "RET" 'evil-multiedit-toggle-or-restrict-region)
;; `yasnippet'
:i [(tab)] 'yas-expand
:v "<backtab>" 'narf/yas-insert-snippet
;; `auto-yasnippet'
:i "<C-tab>" 'aya-expand
:nv "<C-tab>" 'aya-create
;; Vim omni-complete emulation
:i "C-SPC" 'narf/company-complete
(:prefix "C-x"
@ -333,93 +331,10 @@
(:after help-mode
(:map help-map
"e" 'narf/popup-messages
;; Remove slow/annoying help subsections
"h" nil
"g" nil)
"e" 'narf/popup-messages)
(:map help-mode-map
:n "]]" 'help-go-forward
:n "[[" 'help-go-back
:n "<escape>" 'narf/popup-close)))
;; Line-wise mouse selection on margin
(global-set-key (kbd "<left-margin> <down-mouse-1>") 'narf/mouse-drag-line)
(global-set-key (kbd "<left-margin> <mouse-1>") 'narf/mouse-select-line)
(global-set-key (kbd "<left-margin> <drag-mouse-1>") 'narf/mouse-select-line)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Keymap fixes ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; This section is dedicated to bindings that "fix" certain keys so that they behave more
;; like vim (or how I like it).
;; Restores "dumb" indentation to the tab key. This rustles a lot of peoples' jimmies,
;; apparently, but it's how I like it.
(map! :i "<tab>" 'narf/dumb-indent
:i "<backtab>" 'narf/dumb-dedent
:i "<C-tab>" 'indent-for-tab-command
;; No dumb-tab for lisp
(:map lisp-mode-map :i [remap narf/dumb-indent] 'indent-for-tab-command)
(:map emacs-lisp-mode-map :i [remap narf/dumb-indent] 'indent-for-tab-command)
;; Highjacks space/backspace to:
;; a) delete spaces on either side of the cursor, if present ( | ) -> (|)
;; b) allow backspace to delete space-indented blocks intelligently
;; c) and not do any of this magic when inside a string
:i "SPC" 'narf/inflate-space-maybe
:i [remap backward-delete-char-untabify] 'narf/deflate-space-maybe
:i [remap newline] 'narf/newline-and-indent
;; Smarter move-to-beginning-of-line
:i [remap move-beginning-of-line] 'narf/move-to-bol
;; Restore bash-esque keymaps in insert mode; C-w and C-a already exist
:i "C-e" 'narf/move-to-eol
:i "C-u" 'narf/backward-kill-to-bol-and-indent
;; Fixes delete
:i "<kp-delete>" 'delete-char
;; Fix osx keymappings and then some
:i "<M-left>" 'narf/move-to-bol
:i "<M-right>" 'narf/move-to-eol
:i "<M-up>" 'beginning-of-buffer
:i "<M-down>" 'end-of-buffer
:i "<C-up>" 'smart-up
:i "<C-down>" 'smart-down
;; Fix emacs motion keys
:i "A-b" 'evil-backward-word-begin
:i "A-w" 'evil-forward-word-begin
:i "A-e" 'evil-forward-word-end
;; Textmate-esque insert-line before/after
:i "<M-return>" 'evil-open-below
:i "<S-M-return>" 'evil-open-above
;; insert lines in-place)
:n "<M-return>" (λ! (save-excursion (evil-insert-newline-below)))
:n "<S-M-return>" (λ! (save-excursion (evil-insert-newline-above)))
;; Make ESC quit all the things
(:map (minibuffer-local-map
minibuffer-local-ns-map
minibuffer-local-completion-map
minibuffer-local-must-match-map
minibuffer-local-isearch-map)
[escape] 'abort-recursive-edit
"C-r" 'evil-paste-from-register)
(:map (evil-ex-search-keymap read-expression-map)
"C-w" 'backward-kill-word
"C-u" 'backward-kill-sentence
"C-b" 'backward-word)
(:map evil-ex-completion-map "C-a" 'move-beginning-of-line)
(:map view-mode-map "<escape>" 'View-quit-all))
:n "[[" 'help-go-back)))
;; Common unicode characters
(map! :i "A-o" (λ! (insert "ø"))

View file

@ -1,91 +1,104 @@
;;; my-commands.el
(evil-define-operator narf:evil-ex-global (beg end pattern command &optional invert)
"Rewritten :g[lobal] that will highlight buffer matches. Takes the same arguments."
:motion mark-whole-buffer :move-point nil
(interactive "<r><g//><!>")
(evil-ex-global beg end pattern command invert))
(evil-define-operator narf:align (&optional beg end bang pattern)
"Ex interface to `align-regexp'. Accepts vim-style regexps."
(interactive "<r><!><//>")
(align-regexp
beg end
(concat "\\(\\s-*\\)"
(if bang
(regexp-quote pattern)
(evil-transform-vim-style-regexp pattern)))
1 1))
;;; Rewritten commands
(ex! "g[lobal]" 'narf:evil-ex-global)
;;; Custom commands
;; Emacs utilities
(evil-ex-define-cmd "echo" 'narf:echo)
(evil-ex-define-cmd "minor" 'helm-describe-modes) ; list minor modes
(ex! "echo" 'narf:echo)
(ex! "minor" 'helm-describe-modes) ; list minor modes
;; Quick mapping keys to commands, allows :nmap \m !make
(evil-ex-define-cmd "nmap" 'narf:nmap)
(evil-ex-define-cmd "imap" 'narf:imap)
(evil-ex-define-cmd "vmap" 'narf:vmap)
(evil-ex-define-cmd "mmap" 'narf:mmap)
(evil-ex-define-cmd "omap" 'narf:omap)
(ex! "imap" 'narf:imap)
(ex! "mmap" 'narf:mmap)
(ex! "nmap" 'narf:nmap)
(ex! "omap" 'narf:omap)
(ex! "vmap" 'narf:vmap)
;; Editing
(evil-ex-define-cmd "@" 'narf/evil-macro-on-all-lines) ; run macro on each line
(evil-ex-define-cmd "al[ign]" 'narf:align) ; align by regexp
(evil-ex-define-cmd "na[rrow]" 'narf:narrow) ; narrow buffer to selection
(evil-ex-define-cmd "ref[actor]" 'emr-show-refactor-menu) ; open emr menu
(evil-ex-define-cmd "retab" 'narf:whitespace-retab)
(evil-ex-define-cmd "settr[im]" 'narf:toggle-delete-trailing-whitespace)
(evil-ex-define-cmd "snip[pets]" 'narf:yas-snippets) ; visit a snippet
(evil-ex-define-cmd "tsnip[pets]" 'narf:yas-file-templates) ; visit a file template
(evil-ex-define-cmd "wal[ign]" 'narf:whitespace-align) ; align spaces
(evil-ex-define-cmd "rec[ent]" 'narf:helm-recentf) ; show recent files in helm
(evil-ex-define-cmd "reo[rient]" 'narf/window-reorient) ; scroll all windows to left
(evil-ex-define-cmd "ie[dit]" 'evil-multiedit-ex-match)
(evil-ex-define-cmd "htmle[nt]" 'narf/html-entities) ; encode/decode html entities
(ex! "@" 'narf/evil-macro-on-all-lines)
(ex! "al[ign]" 'narf:align)
(ex! "htmle[nt]" 'narf/html-entities) ; encode/decode html entities
(ex! "ie[dit]" 'evil-multiedit-ex-match)
(ex! "na[rrow]" 'narf:narrow)
(ex! "rec[ent]" 'narf:helm-recentf) ; show recent files
(ex! "ref[actor]" 'emr-show-refactor-menu)
(ex! "reo[rient]" 'narf/window-reorient) ; scroll all windows to left
(ex! "retab" 'narf:whitespace-retab)
(ex! "settr[im]" 'narf:toggle-delete-trailing-whitespace)
(ex! "snip[pets]" 'narf:yas-snippets) ; open snippet
(ex! "tsnip[pets]" 'narf:yas-file-templates) ; open file template
(ex! "wal[ign]" 'narf:whitespace-align) ; align by spaces
;; External resources
(evil-ex-define-cmd "dash" 'narf:dash) ; look up in Dash.app
(evil-ex-define-cmd "http" 'httpd-start) ; start http server
(evil-ex-define-cmd "re[gex]" 'narf:regex) ; open re-builder
(evil-ex-define-cmd "repl" 'narf:repl) ; invoke or send to repl
(evil-ex-define-cmd "t[mux]" 'narf:tmux) ; send to tmux
(evil-ex-define-cmd "tcd" 'narf:tmux-cd) ; cd to default-directory in tmux
(evil-ex-define-cmd "x" 'narf:send-to-scratch-or-org)
(ex! "dash" 'narf:dash) ; look up in Dash.app
(ex! "http" 'httpd-start) ; start http server
(ex! "re[gex]" 'narf:regex) ; open re-builder
(ex! "repl" 'narf:repl) ; invoke or send to repl
(ex! "t[mux]" 'narf:tmux) ; send to tmux
(ex! "tcd" 'narf:tmux-cd) ; cd to default-directory in tmux
(ex! "x" 'narf:send-to-scratch-or-org)
;; GIT
(evil-ex-define-cmd "gbr[owse]" 'narf:git-remote-browse) ; show file in github/gitlab
(ex! "ga[dd]" 'narf/vcs-stage-hunk)
(ex! "gbr[owse]" 'narf:git-remote-browse) ; show file in github/gitlab
(ex! "gre[vert]" 'narf/vcs-revert-hunk)
;; Dealing with buffers
(evil-ex-define-cmd "k[ill]" 'narf/kill-real-buffer) ; Kill current buffer
(evil-ex-define-cmd "k[ill]all" 'narf:kill-all-buffers) ; Kill all buffers (bang = in project)
(evil-ex-define-cmd "k[ill]buried" 'narf:kill-buried-buffers) ; Kill all buried buffers (bang = in project)
(evil-ex-define-cmd "k[ill]o" 'narf:kill-other-buffers) ; kill all other buffers
(evil-ex-define-cmd "k[ill]unreal" 'narf/kill-unreal-buffers) ; kill unreal buffers
(evil-ex-define-cmd "k[ill]match" 'narf:kill-matching-buffers) ; kill buffers that match regexp
(evil-ex-define-cmd "l[ast]" 'narf/popup-last-buffer) ; pop up last popup
(evil-ex-define-cmd "m[sg]" 'narf/popup-messages) ; open *messages* in popup
(ex! "k[ill]" 'narf/kill-real-buffer) ; Kill current buffer
(ex! "k[ill]all" 'narf:kill-all-buffers) ; Kill buffers (bang = in project)
(ex! "k[ill]b" 'narf:kill-buried-buffers) ; Kill buried buffers
(ex! "k[ill]m" 'narf:kill-matching-buffers) ; kill buffers by regexp
(ex! "k[ill]o" 'narf:kill-other-buffers) ; kill other buffers
(ex! "k[ill]u" 'narf/kill-unreal-buffers) ; kill unreal buffers
(ex! "l[ast]" 'narf/popup-last-buffer) ; pop up last popup
(ex! "m[sg]" 'narf/popup-messages) ; open *messages* in popup
;; Project navigation
(evil-ex-define-cmd "a" 'helm-projectile-find-other-file) ; open alternate file
(evil-ex-define-cmd "ag" 'narf:helm-ag-search) ; project text search
(evil-ex-define-cmd "ag[cw]d" 'narf:helm-ag-search-cwd) ; current directory search
(evil-ex-define-cmd "cd" 'narf:cd)
(evil-ex-define-cmd "se[arch]" 'narf:helm-swoop) ; in-file search
(ex! "a" 'helm-projectile-find-other-file)
(ex! "ag" 'narf:helm-ag-search)
(ex! "ag[cw]d" 'narf:helm-ag-search-cwd)
(ex! "cd" 'narf:cd)
(ex! "se[arch]" 'narf:helm-swoop) ; in-file search
;; Project tools
(evil-ex-define-cmd "ma[ke]" 'narf:build)
(evil-ex-define-cmd "build" 'narf:build)
(ex! "build" 'narf:build)
(ex! "ma[ke]" 'narf:build)
;; File operations
(evil-ex-define-cmd "mv" 'narf:file-move)
(evil-ex-define-cmd "rm" 'narf:file-delete) ; rm[!]
(ex! "mv" 'narf:file-move)
(ex! "rm" 'narf:file-delete)
;; Presentation/demo
(evil-ex-define-cmd "big" 'big-mode)
(evil-ex-define-cmd "full[scr]" 'narf:toggle-fullscreen)
(ex! "big" 'big-mode)
(ex! "full[scr]" 'narf:toggle-fullscreen)
;; Sessions/tabs
(evil-ex-define-cmd "sl[oad]" 'narf:load-session)
(evil-ex-define-cmd "ss[ave]" 'narf:save-session)
(evil-ex-define-cmd "tabs" 'narf/tab-display)
(evil-ex-define-cmd "tabn[ew]" 'narf:tab-create)
(evil-ex-define-cmd "tabr[ename]" 'narf:tab-rename)
(evil-ex-define-cmd "tabc[lose]" 'narf:kill-tab)
(evil-ex-define-cmd "tabc[lose]o" 'narf:kill-other-tabs)
(evil-ex-define-cmd "tabn[ext]" 'narf:switch-to-tab-right)
(evil-ex-define-cmd "tabp[rev]" 'narf:switch-to-tab-left)
(evil-ex-define-cmd "tabl[ast]" 'narf:switch-to-tab-last)
(ex! "sl[oad]" 'narf:load-session)
(ex! "ss[ave]" 'narf:save-session)
(ex! "tabc[lose]" 'narf:kill-tab)
(ex! "tabc[lose]o" 'narf:kill-other-tabs)
(ex! "tabl[ast]" 'narf:switch-to-tab-last)
(ex! "tabn[ew]" 'narf:tab-create)
(ex! "tabn[ext]" 'narf:switch-to-tab-right)
(ex! "tabp[rev]" 'narf:switch-to-tab-left)
(ex! "tabr[ename]" 'narf:tab-rename)
(ex! "tabs" 'narf/tab-display)
;; Org-mode
(evil-ex-define-cmd "link" 'narf:org-link)
(evil-ex-define-cmd "att[ach]" 'narf:org-attach) ; attach file to org file
(evil-ex-define-cmd "org" 'narf:org-helm-search) ; search org notes
(ex! "att[ach]" 'narf:org-attach) ; attach file to org file
(ex! "link" 'narf:org-link)
(ex! "org" 'narf:org-helm-search) ; search org notes
;; Plugins
(after! flycheck
(evil-ex-define-cmd "er[rors]" (λ! (flycheck-buffer) (flycheck-list-errors))))
(ex! "er[rors]" 'narf/flycheck-errors)
;; Debuggers
(evil-ex-define-cmd "debug" 'narf:debug)
(ex! "debug" 'narf:debug)
(provide 'my-commands)
;;; my-commands.el ends here