The ciiiircle of liiiife

This commit is contained in:
Henrik Lissner 2015-11-25 06:00:49 -05:00
parent 0923903e93
commit 03c6c05677
29 changed files with 287 additions and 465 deletions

View file

@ -3,85 +3,93 @@
(use-package autoinsert
:defer t
:init
(setq auto-insert-query nil) ; Don't prompt before insertion
(setq auto-insert-alist '())
(setq auto-insert-query nil ; Don't prompt before insertion
auto-insert-alist '())
:config
(auto-insert-mode 1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun auto-insert-template (rule)
(define-auto-insert
(nth 0 rule)
(vector `(lambda () (narf/auto-insert-snippet ,(nth 1 rule) ',(nth 2 rule) ,(nth 3 rule))))))
(add-template! "/\\.gitignore$" "__" 'gitignore-mode)
(mapc 'auto-insert-template
`(;; General
("/\\.gitignore$" "__" gitignore-mode)
;; C/C++
(add-template! "/Makefile$" "__" 'makefile-gmake-mode)
(add-template! "/main\\.\\(cc\\|cpp\\)$" "__main.cpp" 'c++-mode)
(add-template! "/win32_\\.\\(cc\\|cpp\\)$" "__winmain.cpp" 'c++-mode)
(add-template! "\\.\\([Hh]\\|hpp\\)$" "__.h" 'c++-mode)
(add-template! "\\.\\(cc\\|cpp\\)$" "__.cpp" 'c++-mode)
(add-template! "\\.c$" "__.c" 'c-mode)
;; C/C++
("/Makefile$" "__" makefile-gmake-mode)
("/main\\.\\(cc\\|cpp\\)$" "__main.cpp" c++-mode)
("/win32_\\.\\(cc\\|cpp\\)$" "__winmain.cpp" c++-mode)
("\\.\\([Hh]\\|hpp\\)$" "__.h" c++-mode)
("\\.\\(cc\\|cpp\\)$" "__.cpp" c++-mode)
("\\.c$" "__.c" c-mode)
;; Elisp
(add-template! "\\.emacs\\.d/.+\\.el$" "__initfile" 'emacs-lisp-mode)
(add-template! "\\.emacs\\.d/private/\\(snippets\\|templates\\)/.+$" "__" 'snippet-mode)
;; Elisp
("\\.emacs\\.d/.+\\.el$" "__initfile" emacs-lisp-mode)
("\\.emacs\\.d/private/\\(snippets\\|templates\\)/.+$" "__" snippet-mode)
;; Go
(add-template! "/main\\.go$" "__main.go" 'go-mode t)
(add-template! "\\.go$" "__.go" 'go-mode)
;; Go
("/main\\.go$" "__main.go" go-mode t)
("\\.go$" "__.go" go-mode)
;; HTML
(add-template! "\\.html$" "__.html" 'web-mode)
;; HTML
("\\.html$" "__.html" web-mode)
;; java
(add-template! "/src/.+/.+\\.java$" "__" 'java-mode)
(add-template! "/main\\.java$" "__main" 'java-mode)
(add-template! "/build\\.gradle$" "__build.gradle" 'android-mode)
;; java
("/src/.+/.+\\.java$" "__" java-mode)
("/main\\.java$" "__main" java-mode)
("/build\\.gradle$" "__build.gradle" android-mode)
;; Javascript
(add-template! "\\.lbaction/.+/Info.plist$" "__Info.plst" 'lb6-mode)
(add-template! "\\.lbaction/.+/\\(default\\|suggestions\\)\\.js$" "__default.js" 'lb6-mode)
(add-template! "/package\\.json$" "__package.json" 'json-mode)
(add-template! "\\.\\(json\\|jshintrc\\)$" "__" 'json-mode)
;; Javascript
("\\.lbaction/.+/Info.plist$" "__Info.plst" lb6-mode)
("\\.lbaction/.+/\\(default\\|suggestions\\)\\.js$" "__default.js" lb6-mode)
("/package\\.json$" "__package.json" json-mode)
("\\.\\(json\\|jshintrc\\)$" "__" json-mode)
;; Lua
(add-template! "/main\\.lua$" "__main.lua" 'love-mode)
(add-template! "/conf\\.lua$" "__conf.lua" 'love-mode)
;; Lua
("/main\\.lua$" "__main.lua" love-mode)
("/conf\\.lua$" "__conf.lua" love-mode)
;; Markdown
(add-template! "\\.md$" "__" 'markdown-mode)
(add-template! "/_posts/.+\\.md$" "__jekyll-post" 'markdown-mode)
(add-template! "/_layouts/.+\\.html$" "__jekyll-layout.html" 'web-mode)
;; Markdown
("\\.md$" "__" markdown-mode)
;; PHP
(add-template! "\\.class\\.php$" "__.class.php" 'php-mode)
(add-template! "\\.php$" "__" 'php-mode)
;; Org
(,(format "%s.+\\.org$" org-directory-contacts) "__contact.org" org-mode)
(,(format "%s.+\\.org$" org-directory-projects) "__projects.org" org-mode)
(,(format "%s.+\\.org$" org-directory-invoices) "__invoices.org" org-mode)
;; Python
;; (add-template! "tests?/test_.+\\.py$" "__" 'nose-mode)
;; (add-template! "/setup\\.py$" "__setup.py" 'python-mode)
(add-template! "\\.py$" "__" 'python-mode)
;; PHP
("\\.class\\.php$" "__.class.php" php-mode)
("\\.php$" "__" php-mode)
;; Ruby
(add-template! "/\\.rspec$" "__.rspec" 'rspec-mode)
(add-template! "/spec_helper\\.rb$" "__helper" 'rspec-mode t)
(add-template! "_spec\\.rb$" "__" 'rspec-mode t)
(add-template! "/Rakefile$" "__Rakefile" 'enh-ruby-mode t)
(add-template! "/Gemfile$" "__Gemfile" 'enh-ruby-mode t)
(add-template! "\\.gemspec$" "__.gemspec" 'enh-ruby-mode t)
(add-template! "/lib/.+\\.rb$" "__module" 'enh-ruby-mode t)
(add-template! "\\.rb$" "__" 'enh-ruby-mode)
;; Python
;;"tests?/test_.+\\.py$" "__" nose-mode)
;;"/setup\\.py$" "__setup.py" python-mode)
("\\.py$" "__" python-mode)
;; Rust
(add-template! "/Cargo.toml$" "__Cargo.toml" 'rust-mode)
(add-template! "/main\\.rs$" "__main.rs" 'rust-mode)
;; Ruby
("/\\.rspec$" "__.rspec" rspec-mode)
("/spec_helper\\.rb$" "__helper" rspec-mode t)
("_spec\\.rb$" "__" rspec-mode t)
("/Rakefile$" "__Rakefile" enh-ruby-mode t)
("/Gemfile$" "__Gemfile" enh-ruby-mode t)
("\\.gemspec$" "__.gemspec" enh-ruby-mode t)
("/lib/.+\\.rb$" "__module" enh-ruby-mode t)
("\\.rb$" "__" enh-ruby-mode)
;; SCSS
(add-template! "/master\\.scss$" "__master.scss" 'scss-mode)
(add-template! "/normalize\\.scss$" "__normalize.scss" 'scss-mode)
(add-template! "\\.scss$" "__" 'scss-mode)
;; Rust
("/Cargo.toml$" "__Cargo.toml" rust-mode)
("/main\\.rs$" "__main.rs" rust-mode)
;; Shell scripts
(add-template! "\\.z?sh$" "__" 'sh-mode)
)
;; SCSS
("/master\\.scss$" "__master.scss" scss-mode)
("/normalize\\.scss$" "__normalize.scss" scss-mode)
("\\.scss$" "__" scss-mode)
;; Shell scripts
("\\.z?sh$" "__" sh-mode)
)))
(provide 'core-auto-insert)
;;; core-auto-insert.el ends here

View file

@ -243,8 +243,8 @@ to abort the minibuffer."
(let (message-log-max)
(if (and delete-selection-mode transient-mark-mode mark-active)
(setq deactivate-mark t)
(when (get-buffer "*Completions*")
(delete-windows-on "*Completions*"))
;; (when (get-buffer "*Completions*")
;; (delete-windows-on "*Completions*"))
(abort-recursive-edit))))
(after! evil

View file

@ -23,7 +23,7 @@
hscroll-step 5
hscroll-margin 6
shift-select-mode nil
shift-select-mode t
tabify-regexp "^\t* [ \t]+"
whitespace-style '(face tabs tab-mark)
whitespace-display-mappings
@ -219,28 +219,13 @@ details on NORECORD.")
t))
(sp-local-pair 'web-mode "<" nil :when '(sp-web-mode-is-code-context))))
;; (use-package smex
;; :commands (smex smex-major-mode-commands smex-initialize smex-update)
;; :init (setq smex-save-file (concat narf-temp-dir "smex-items"))
;; :config (smex-initialize)
;; ;; Hook up smex to auto-update, rather than update on every run
;; (defun smex-update-after-load (unused)
;; (when (boundp 'smex-cache) (smex-update)))
;; (add-hook 'after-load-functions 'smex-update-after-load))
(use-package help-fns+ ; Improved help commands
:commands (describe-buffer describe-command describe-file
describe-keymap describe-option describe-option-of-type))
(use-package saveplace
:defer t
:config (setq save-place-file (concat narf-temp-dir "saveplace"))
:init
;; Save cursor location across sessions. Only save for files that exist.
(add-hook! find-file
(when (file-exists-p (buffer-file-name))
(require 'saveplace)
(setq save-place t))))
(require 'saveplace)
(setq save-place-file (concat narf-temp-dir "saveplace"))
(save-place-mode +1)
(provide 'core-editor)
;;; core-editor.el ends here

View file

@ -29,10 +29,19 @@
evil-echo-state nil
evil-ex-substitute-global t
evil-normal-state-tag "N"
evil-insert-state-tag "I"
evil-visual-state-tag "V"
evil-emacs-state-tag "E"
evil-operator-state-tag "O"
evil-motion-state-tag "M"
evil-replace-state-tag "R"
evil-iedit-state-tag "R+"
;; Color-coded state cursors
evil-default-cursor "orange"
evil-normal-state-cursor 'box
evil-emacs-state-cursor 'bar
evil-emacs-state-cursor '("cyan" box)
evil-insert-state-cursor 'bar
evil-visual-state-cursor 'hollow
evil-iedit-state-cursor 'box)
@ -49,13 +58,20 @@
(advice-add 'extract-rectangle-line :filter-args 'narf*evil-extract-rectangle-line-fix)
;; modes to map to different default states
(dolist (mode-map '((cider-repl-mode . emacs)
(comint-mode . emacs)
(term-mode . emacs)
(Info-mode . emacs)
(help-mode . normal)
(message-mode . normal)
(compilation-mode . normal)))
(dolist (mode-map '((cider-repl-mode . emacs)
(comint-mode . emacs)
(term-mode . emacs)
(Info-mode . emacs)
(view-mode . emacs)
(help-mode . normal)
(message-mode . normal)
(compilation-mode . normal)
(inferior-emacs-lisp-mode . emacs)
(calendar-mode . emacs)
(Man-mode . emacs)
(grep-mode . emacs)
(image-mode . emacs)
))
(evil-set-initial-state `,(car mode-map) `,(cdr mode-map)))
;; Switch to normal mode before switching windows
@ -232,9 +248,9 @@
(use-package evil-jumper
:init
(setq evil-jumper-file (concat narf-temp-dir "jumplist")
evil-jumper-auto-center t
evil-jumper-auto-save-interval 3600))
(setq evil-jumper-auto-center nil
evil-jumper-auto-save-interval 3600)
:config (global-evil-jumper-mode +1))
(use-package evil-matchit
:commands (evilmi-jump-items evilmi-text-object global-evil-matchit-mode)

View file

@ -84,7 +84,10 @@
;; Hide mode-line in helm windows
(advice-add 'helm-display-mode-line :override 'narf*helm-hide-modeline)
(helm-mode 1))
(helm-mode 1)
;; Don't override evil-ex's completion
(setq completion-in-region-function helm--old-completion-in-region-function))
(use-package projectile
:diminish projectile-mode

View file

@ -22,6 +22,8 @@
(" *Org todo*" :position bottom :height 5)
("*Org Links*" :position bottom :height 2)
("^\\*CPU-Profiler-Report .+\\*$" :regexp t :position bottom :height 0.35)
("*ruby*" :position bottom :height 0.3 :stick t)
("*ielm*" :position bottom :height 0.3 :stick t)
))
(popwin-mode 1)

View file

@ -15,5 +15,18 @@
(add-to-list 'quickrun-file-alist '("\\.gvy$" . "groovy")))
(use-package repl-toggle
:commands (rtog/toggle-repl rtog/add-repl)
:config
(setq rtog/goto-buffer-fun 'popwin:pop-to-buffer
rtog/mode-repl-alist
'((php-mode . php-boris)
(python-mode . run-python)
(lua-mode . run-lua)
(emacs-lisp-mode . ielm)
(ruby-mode . inf-ruby)
(js2-mode . nodejs-repl)))
)
(provide 'core-quickrun)
;;; core-quickrun.el ends here

View file

@ -351,7 +351,8 @@ iedit."
;; Initialize modeline
(spaceline-install
;; Left side
'(narf-anzu narf-iedit narf-evil-substitute
'((evil-state :face highlight-face :when active)
narf-anzu narf-iedit narf-evil-substitute
(narf-buffer-path remote-host)
narf-buffer-modified
narf-vc

View file

@ -33,6 +33,8 @@
;; Create a new workgroup on switch-project
(setq projectile-switch-project-action 'narf/wg-projectile-switch-project))
(add-hook! wg-before-switch-to-workgroup 'popwin:close-popup-window)
;; Initialize!
(add-hook! after-init
(workgroups-mode 1)

View file

@ -52,6 +52,7 @@
"<S-tab>" 'yas-prev-field
"<M-backspace>" 'narf/yas-clear-to-sof
"<escape>" 'evil-normal-state
[backspace] 'narf/yas-backspace
"<delete>" 'narf/yas-delete)
@ -69,7 +70,8 @@
;; right due to an off-by-one issue.
(defadvice yas-expand-snippet (around yas-expand-snippet-visual-line activate)
(when (narf/evil-visual-line-state-p)
(ad-set-arg 2 (1- (ad-get-arg 2)))) ad-do-it))
(ad-set-arg 2 (1- (ad-get-arg 2)))) ad-do-it)
)
(provide 'core-yasnippet)
;;; core-yasnippet.el ends here

View file

@ -69,24 +69,25 @@
(cons (format "\\%s{" command) "}")))
;;;###autoload (autoload 'narf/evil-macro-on-all-lines "defuns-evil" nil t)
(evil-define-operator narf/evil-macro-on-all-lines (beg end &optional arg)
"Apply macro to each line. Courtesy of PythonNut/emacs-config"
(evil-with-state
(evil-normal-state)
(goto-char end)
(evil-visual-state)
(goto-char beg)
(evil-ex-normal (region-beginning) (region-end)
(concat "@"
(single-key-description
(read-char "What macro?"))))))
(evil-define-operator narf/evil-macro-on-all-lines (beg end &optional macro)
"Apply macro to each line."
:motion nil
:move-point nil
(interactive "<r><a>")
(unless (and beg end)
(setq beg (region-beginning)
end (region-end)))
(evil-ex-normal beg end
(concat "@"
(single-key-description
(or macro (read-char "@-"))))))
;;;###autoload
(defmacro define-text-object! (key start-regex end-regex)
(let ((inner-name (make-symbol "narf--inner-name"))
(outer-name (make-symbol "narf--outer-name")))
`(progn
(evil-define-text-object ,inner-name (count &optional beg end type)
(evil-define-text-object ,"inner"-name (count &optional beg end type)
(evil-select-paren ,start-regex ,end-regex beg end type count nil))
(evil-define-text-object ,outer-name (count &optional beg end type)
(evil-select-paren ,start-regex ,end-regex beg end type count t))

View file

@ -38,8 +38,8 @@
;; Ex-mode interface for `helm-ag'. If `bang', then `search' is interpreted as
;; regexp.
;;;###autoload (autoload 'narf:helm-search "defuns-helm" nil t)
(evil-define-operator narf:helm-search (beg end &optional search hidden-files-p pwd-p regex-p)
;;;###autoload (autoload 'narf:helm-ag-search "defuns-helm" nil t)
(evil-define-operator narf:helm-ag-search (beg end &optional search hidden-files-p pwd-p regex-p)
:type inclusive
:repeat nil
(interactive "<r><a><!>")
@ -61,25 +61,25 @@
:keymap helm-ag-map
:input input)))
;;;###autoload (autoload 'narf:helm-regex-search "defuns-helm" nil t)
(evil-define-operator narf:helm-regex-search (beg end &optional search bang)
;;;###autoload (autoload 'narf:helm-ag-regex-search "defuns-helm" nil t)
(evil-define-operator narf:helm-ag-regex-search (beg end &optional search bang)
:type inclusive :repeat nil
(interactive "<r><a><!>")
(narf:helm-search beg end search bang nil t))
(narf:helm-ag-search beg end search bang nil t))
;;;###autoload (autoload 'narf:helm-regex-cwd "defuns-helm" nil t)
(evil-define-operator narf:helm-search-cwd (beg end &optional search bang)
;;;###autoload (autoload 'narf:helm-ag-search-cwd "defuns-helm" nil t)
(evil-define-operator narf:helm-ag-search-cwd (beg end &optional search bang)
;; Ex-mode interface for `helm-do-ag'. If `bang', then `search' is interpreted
;; as regexp
:type inclusive :repeat nil
(interactive "<r><a><!>")
(narf:helm-search beg end search bang t nil))
(narf:helm-ag-search beg end search bang t nil))
;;;###autoload (autoload 'narf:helm-regex-search-cwd "defuns-helm" nil t)
(evil-define-operator narf:helm-regex-search-cwd (beg end &optional search bang)
;;;###autoload (autoload 'narf:helm-ag-regex-search-cwd "defuns-helm" nil t)
(evil-define-operator narf:helm-ag-regex-search-cwd (beg end &optional search bang)
:type inclusive :repeat nil
(interactive "<r><a><!>")
(narf:helm-search beg end search bang t t))
(narf:helm-ag-search beg end search bang t t))
;; Ex-mode interface for `helm-swoop', `helm-multi-swoop-all' (if `bang'), or
;; `helm-css-scss' and `helm-css-scss-multi' (if `bang') if major-mode is

View file

@ -3,16 +3,14 @@
;;;###autoload
(defun narf|yas-before-expand ()
"Switch to insert mode when expanding a template via backtab, or go back to
normal mode if there are no fields."
;; Strip out the shitespace before a line selection.
"Strip out the shitespace before a line selection."
(when (narf/evil-visual-line-state-p)
(setq yas-selected-text
(replace-regexp-in-string
"\\(^ *\\|\n? $\\)" ""
(buffer-substring-no-properties (region-beginning)
(1- (region-end))))))
(evil-insert-state +1))
(setq-local
yas-selected-text
(replace-regexp-in-string
"\\(^ *\\|\n? $\\)" ""
(buffer-substring-no-properties (region-beginning)
(1- (region-end)))))))
;;;###autoload
(defun narf|yas-after-expand ()
@ -26,7 +24,10 @@ normal mode if there are no fields."
normal mode if there are no fields."
(interactive)
(yas-insert-snippet)
(evil-insert-state +1))
(let* ((snippet (first (yas--snippets-at-point)))
(fields (yas--snippet-fields snippet)))
(evil-insert-state +1)
(when fields (evil-change-state 'normal))))
;;;###autoload
(defun narf/yas-goto-start-of-field ()

View file

@ -1,21 +0,0 @@
;;; macros-auto-insert.el
;; for ../core-auto-insert.el
;;;###autoload
(defmacro add-template! (regexp-or-major-mode uuid yas-mode &optional project-only)
`(define-auto-insert ,(if (stringp regexp-or-major-mode)
regexp-or-major-mode
(eval regexp-or-major-mode))
(lambda ()
(unless (or (and ,project-only (not (narf/project-p)))
(not (or (eq major-mode ,yas-mode)
(and (boundp ,yas-mode)
(symbol-value ,yas-mode)))))
(insert ,uuid)
(yas-expand-from-trigger-key)
(if (string-equal ,uuid (s-trim (buffer-string)))
(erase-buffer)
(evil-insert-state 1))))))
(provide 'macros-auto-insert)
;;; macros-auto-insert.el ends here