Write core initfiles + defuns

This commit is contained in:
Henrik Lissner 2015-06-15 09:05:52 +02:00
parent c0661f5293
commit b998f4ab08
52 changed files with 2444 additions and 706 deletions

View file

@ -1,3 +1,5 @@
;;; core-editor.el
;; see lib/editor-defuns.el
;;;; Editor behavior ;;;;;;;;;;;;;;;;
(setq-default
@ -12,7 +14,7 @@
fill-column 80
;; Sane scroll settings
scroll-margin 5
scroll-margin 0
scroll-conservatively 9999
scroll-preserve-screen-position t
@ -27,61 +29,14 @@
truncate-partial-width-windows nil)
;; Modes 'n hooks ;;;;;;;;;;;;;;;;;;;
(@associate text-mode :match "/LICENSE[^/]*$")
(@associate sh-mode :match "zsh\\(env\\|rc\\)?$")
(@associate sh-mode :match "z\\(profile\\|login\\|logout\\)?$")
(@associate sh-mode :match "zsh/")
(@associate applescript-mode :match "\\.applescript$")
(@associate emacs-lisp-mode :match "Cask$")
(@associate emacs-lisp-mode :match "\\.el\\.gz$")
(@associate makefile-gmake-mode :match "/Makefile$")
(@associate nxml-mode :match "\\.plist$")
(@add-hook help-mode 'visual-line-mode)
(@add-hook python-mode 'electric-indent-local-mode)
(@add-hook emacs-lisp-mode 'turn-on-eldoc-mode)
(@add-hook eldoc-mode (diminish 'eldoc-mode " ?"))
(@add-hook makefile-mode 'narf|enable-tabs) ; Use normal tabs in makefiles
;; Fix code folding
;; (@add-hook prog-mode (unless (bound-and-true-p hs-minor-mode)
;; (hs-minor-mode 1)
;; (diminish 'hs-minor-mode)))
(@add-hook find-file 'narf|update-scratch-buffer-cwd)
;; (add-hook 'before-save-hook 'delete-trailing-whitespace)
;; If file is oversized...
(@add-hook find-file (when (> (buffer-size) (* 1024 1024))
(setq buffer-read-only t)
(buffer-disable-undo)
(fundamental-mode)
(visual-line-mode)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (global-whitespace-mode 1) ; Show whitespace
(global-font-lock-mode t) ; Enable syntax highlighting for older emacs
(global-auto-revert-mode 1) ; revert buffers for changed files
(electric-indent-mode -1)
(winner-mode 1) ; window config undo/redo
;; Automatic minor modes ;;;;;;;;;;;
(defvar narf/auto-minor-mode-alist ()
"Alist of filename patterns vs correpsonding minor mode functions,
see `auto-mode-alist' All elements of this alist are checked, meaning
you can enable multiple minor modes for the same regexp.")
(defun narf|enable-minor-mode-maybe ()
"Check file name against `narf/auto-minor-mode-alist'."
"Check file name against `narf-auto-minor-mode-alist'."
(when buffer-file-name
(let ((name buffer-file-name)
(remote-id (file-remote-p buffer-file-name))
(alist narf/auto-minor-mode-alist))
(alist narf-auto-minor-mode-alist))
;; Remove backup-suffixes from file name.
(setq name (file-name-sans-versions name))
;; Remove remote file name identification.
@ -93,11 +48,63 @@ you can enable multiple minor modes for the same regexp.")
(funcall (cdar alist) 1))
(setq alist (cdr alist))))))
(@add-hook find-file 'narf|enable-minor-mode-maybe)
(add-hook! find-file 'narf|enable-minor-mode-maybe)
;; Modes 'n hooks ;;;;;;;;;;;;;;;;;;;
(associate! text-mode :match "/LICENSE[^/]*$")
(associate! sh-mode :match "z\\(profile\\|login\\|logout\\)?$")
(associate! sh-mode :match "zsh/")
(associate! applescript-mode :match "\\.applescript$")
(associate! emacs-lisp-mode :match "Cask$")
(associate! emacs-lisp-mode :match "\\.el\\.gz$")
(associate! makefile-gmake-mode :match "/Makefile$")
(associate! nxml-mode :match "\\.plist$")
(add-hook! help-mode 'visual-line-mode)
(add-hook! python-mode 'electric-indent-local-mode)
(add-hook! makefile-mode 'narf|enable-tabs) ; Use normal tabs in makefiles
(add-hook! before-save 'delete-trailing-whitespace)
(add-hook! eldoc-mode (diminish 'eldoc-mode " ?"))
;; Line wrapping
(add-hook! text-mode 'narf|enable-hard-wrap)
(add-hook! prog-mode 'narf|enable-comment-hard-wrap)
(add-hook! auto-fill-mode (diminish 'auto-fill-function))
;; If file is oversized...
(add-hook! find-file
(when (> (buffer-size) (* 1024 1024))
(setq buffer-read-only t)
(buffer-disable-undo)
(fundamental-mode)
(visual-line-mode)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (global-whitespace-mode 1) ; Show whitespace
(global-font-lock-mode t) ; Enable syntax highlighting for older emacs
(global-auto-revert-mode 1) ; revert buffers for changed files
(electric-indent-mode -1)
;; window config undo/redo
(winner-mode 1)
(add-hook! after-init (setq winner-boring-buffers narf-ignore-buffers))
;; Plugins ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package undo-tree
:defer t
:config
;; Shut up undo-tree's constant complaining: http://youtu.be/Z6woIRLnbmE
(defadvice undo-tree-load-history-hook (around undo-tree-load-history-shut-up activate)
(shut-up! ad-do-it))
(defadvice undo-tree-save-history-hook (around undo-tree-save-history-shut-up activate)
(shut-up! ad-do-it)))
(use-package ace-jump-mode
:functions (ace-jump-char-category ace-jump-do)
:commands (ace-jump-line-mode ace-jump-char-mode
@ -122,17 +129,13 @@ you can enable multiple minor modes for the same regexp.")
(char-to-string query-char-2))))))
(use-package ace-link
:commands
(ace-link-info ace-link-help ace-link-compilation ace-link-custom ace-link-org)
:commands (ace-link-info ace-link-help ace-link-compilation ace-link-custom ace-link-org)
:init
(after "help-mode"
(bind motion :map help-mode-map "go" 'ace-link-help))
(after "compile"
(bind motion :map compilation-mode-map "go" 'ace-link-compilation))
(after "info"
(bind motion :map Info-mode-map "go" 'ace-link-info))
(after "org"
(bind motion :map org-mode-map "go" 'ace-link-org)))
(bind!
(:after help-mode :map help-mode-map :m "go" 'ace-link-help)
(:after compile :map compilation-mode-map :m "go" 'ace-link-compilation)
(:after info :map Info-mode-map :m "go" 'ace-link-info)
(:after org :map org-mode-map :m "go" 'ace-link-org)))
(use-package ace-window
:commands ace-window
@ -147,77 +150,83 @@ you can enable multiple minor modes for the same regexp.")
(use-package expand-region
:commands (er/expand-region er/contract-region er/mark-symbol er/mark-word))
(use-package goto-last-change :defer 3)
(use-package goto-last-change :commands goto-last-change)
(use-package hl-todo
:commands hl-todo-mode
:init
(@add-hook prog-mode 'hl-todo-mode)
(defvar hl-todo-keyword-faces)
'(("\\(\\bTODO\\((.*)\\)?:?\\)" . "#cc9393")
("\\(\\bNOTE\\((.*)\\)?:?\\)" . "#d0bf8f")
("\\(\\bFIXME\\((.*)\\)?:?\\)" . "#cc9393")))
(add-hook! prog-mode 'hl-todo-mode)
(defvar hl-todo-keyword-faces
'(("TODO" . "#cc9393")
("NOTE" . "#d0bf8f")
("FIXME" . "#cc9393"))))
(use-package hideshow
:diminish hs-minor-mode
:init (@add-hook (prog-mode org-mode) 'hs-minor-mode))
:commands (hs-minor-mode hs-toggle-hiding hs-already-hidden-p)
:diminish hs-minor-mode)
(use-package rainbow-delimiters
:commands rainbow-delimiters-mode
:init (@add-hook (emacs-lisp-mode js2-mode scss-mode) 'rainbow-delimiters-mode)
:init (add-hook! (emacs-lisp-mode js2-mode scss-mode) 'rainbow-delimiters-mode)
:config (setq rainbow-delimiters-outermost-only-face-count 1))
(use-package rotate-text :commands (rotate-word-at-point rotate-region))
(use-package rotate-text :commands (rotate-word-at-point rotate-region))
(use-package smart-forward
:commands (smart-up smart-down smart-left smart-right))
(use-package smart-forward :commands (smart-up smart-down smart-left smart-right))
(use-package smartparens
:diminish smartparens-mode
:commands smartparens-global-mode
:init (@add-init-hook evil-insert-state-entry 'smartparens-global-mode)
:functions sp-insert-pair
:commands (smartparens-global-mode
sp-pair
sp-local-pair
sp-point-in-string-or-comment)
:init (add-hook! evil-insert-state-entry (unless smartparens-global-mode (smartparens-global-mode 1)))
:config
(progn
(setq blink-matching-paren t
sp-autowrap-region nil ; let evil-surround handle this
sp-highlight-pair-overlay nil
sp-show-pair-delay 0)
(setq blink-matching-paren t
sp-autowrap-region nil ; let evil-surround handle this
sp-highlight-pair-overlay nil
sp-show-pair-delay 0)
(use-package smartparens-config)
(require 'smartparens-config)
;; Handle newlines + spaces
(sp-pair "{" "}" :post-handlers '(("||\n[i]" "RET") ("| " " ")) :unless '(sp-point-before-word-p sp-point-before-same-p))
(sp-pair "(" ")" :post-handlers '(("||\n[i]" "RET") ("| " " ")) :unless '(sp-point-before-word-p sp-point-before-same-p))
;; Auto-close more conservatively
(sp-pair "[" nil :unless '(sp-point-before-word-p sp-point-before-same-p))
(sp-pair "'" nil :unless '(sp-point-after-word-p sp-point-before-word-p sp-point-before-same-p))
(sp-pair "\"" nil :unless '(sp-point-after-word-p sp-point-before-word-p sp-point-before-same-p))
(sp-with-modes '(json-mode js2-mode ruby-mode enh-ruby-mode python-mode)
(sp-local-pair "[" nil :post-handlers '(("||\n[i]" "RET"))))
(sp-with-modes '(c-mode c++-mode objc-mode java-mode scss-mode css-mode php-mode)
(sp-local-pair "/* " " */" :post-handlers '(("||\n[i]" "RET")))
(sp-local-pair "/**" "*/" :post-handlers '(("||\n[i]" "RET"))))
(sp-with-modes '(c-mode c++-mode objc-mode java-mode) ; Support for generics
(sp-local-pair "<" ">" :when '(sp-point-after-word-p) :unless '(sp-point-before-same-p)))
(sp-with-modes '(objc-mode scss-mode css-mode)
(sp-local-pair "/*\n" "\n */" :post-handlers '(("||[i]" "RET"))))
(sp-with-modes '(c-mode c++-mode php-mode java-mode)
(sp-local-pair "/*" "" :post-handlers '((" ||\n[i]*/" "RET"))))
;; Handle newlines + spaces
(sp-pair "{" "}"
:post-handlers '(("||\n[i]" "RET") ("| " " "))
:unless '(sp-point-before-word-p sp-point-before-same-p))
(sp-pair "(" ")"
:post-handlers '(("||\n[i]" "RET") ("| " " "))
:unless '(sp-point-before-word-p sp-point-before-same-p))
;; Auto-close more conservatively
(sp-pair "[" nil :unless '(sp-point-before-word-p sp-point-before-same-p))
(sp-pair "'" nil :unless '(sp-point-after-word-p sp-point-before-word-p sp-point-before-same-p))
(sp-pair "\"" nil :unless '(sp-point-after-word-p sp-point-before-word-p sp-point-before-same-p))
(sp-with-modes '(json-mode js2-mode ruby-mode enh-ruby-mode python-mode)
(sp-local-pair "[" nil :post-handlers '(("||\n[i]" "RET"))))
(sp-with-modes '(c-mode c++-mode objc-mode java-mode scss-mode css-mode php-mode)
(sp-local-pair "/* " " */" :post-handlers '(("||\n[i]" "RET")))
(sp-local-pair "/**" "*/" :post-handlers '(("||\n[i]" "RET"))))
(sp-with-modes '(c-mode c++-mode objc-mode java-mode) ; Support for generics
(sp-local-pair "<" ">" :when '(sp-point-after-word-p) :unless '(sp-point-before-same-p)))
(sp-with-modes '(objc-mode scss-mode css-mode)
(sp-local-pair "/*\n" "\n */" :post-handlers '(("||[i]" "RET"))))
(sp-with-modes '(c-mode c++-mode php-mode java-mode)
(sp-local-pair "/*" "" :post-handlers '((" ||\n[i]*/" "RET"))))
(sp-with-modes '(markdown-mode org-mode)
(sp-local-pair "*" "*" :unless '(sp-point-after-bol-p sp-point-before-same-p sp-point-after-same-p)))
(after "yasnippet"
(advice-add 'yas-expand :before 'sp-remove-active-pair-overlay))))
(after! yasnippet
(advice-add 'yas-expand :before 'sp-remove-active-pair-overlay)))
(use-package smex
:commands (smex smex-major-mode-commands smex-initialize smex-update)
:init (setq smex-save-file (! (expand-file-name "smex-items" TMP-DIR)))
:config
(smex-initialize)
: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))
(provide 'core-editor)
;;; core-editor.el ends here