From 53879f252880f383160f28f3299f2b9d5b732693 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 20 Apr 2016 21:36:32 -0400 Subject: [PATCH] General cleanup --- core/core-editor.el | 28 +++++---- core/core-sessions.el | 24 ++++---- core/defuns/defuns-workgroup.el | 7 +++ modules/module-haskell.el | 4 +- modules/module-js.el | 102 +++++++++++++++----------------- modules/module-julia.el | 2 +- modules/module-php.el | 1 - modules/module-processing.el | 8 ++- modules/module-rust.el | 8 +-- modules/module-text.el | 4 -- modules/module-web.el | 9 ++- 11 files changed, 96 insertions(+), 101 deletions(-) diff --git a/core/core-editor.el b/core/core-editor.el index b0e16c8dc..339645a29 100644 --- a/core/core-editor.el +++ b/core/core-editor.el @@ -191,6 +191,14 @@ enable multiple minor modes for the same regexp.") ;; Plugins ;; +(use-package editorconfig + :config + ;; Don't affect lisp indentation (only `tab-width') + (setq editorconfig-indentation-alist + (delq (assq 'emacs-lisp-mode editorconfig-indentation-alist) + editorconfig-indentation-alist)) + (editorconfig-mode +1)) + (use-package ace-window :commands ace-window :config (setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l) @@ -202,12 +210,6 @@ enable multiple minor modes for the same regexp.") :config (setq avy-all-windows nil avy-background t)) -(use-package editorconfig - :config - ;; Don't affect lisp indentation (just `tab-width') - (setq editorconfig-indentation-alist (delq (assq 'emacs-lisp-mode editorconfig-indentation-alist) editorconfig-indentation-alist)) - (editorconfig-mode +1)) - (use-package emr :commands (emr-initialize emr-show-refactor-menu emr-declare-command) :config (define-key popup-menu-keymap [escape] 'keyboard-quit)) @@ -215,8 +217,7 @@ 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 - :commands goto-last-change) +(use-package goto-last-change :commands goto-last-change) (use-package hideshow :commands (hs-minor-mode hs-toggle-hiding hs-already-hidden-p) @@ -300,13 +301,14 @@ enable multiple minor modes for the same regexp.") (use-package re-builder :commands (re-builder reb-mode-buffer-p) - :init (add-hook! reb-mode 'narf|reb-cleanup) + :init + (add-hook 'reb-mode-hook 'narf|reb-cleanup) + (evil-set-initial-state 'reb-mode 'insert) :config (setq reb-re-syntax 'string) - (evil-set-initial-state 'reb-mode 'insert) - - (map! :map rxt-help-mode-map :n [escape] 'kill-buffer-and-window) - (map! :map reb-mode-map + (map! :map rxt-help-mode-map + :n [escape] 'kill-buffer-and-window + :map reb-mode-map :n "C-g" 'reb-quit :n [escape] 'reb-quit :n [backtab] 'reb-change-syntax)) diff --git a/core/core-sessions.el b/core/core-sessions.el index 66b991f49..2d34f35ed 100644 --- a/core/core-sessions.el +++ b/core/core-sessions.el @@ -5,6 +5,14 @@ ;; code to make a permanent frame header to display these some day) ;; 2. Session persistence +(defvar narf-wg-frames '() + "A list of all the frames opened as separate workgroups. See +defuns/defuns-workgroups.el.") + +(defvar narf-wg-names '() + "A list of fixed names for workgroups. If a name is set, workgroup names aren't +automatically renamed to the project name.") + (use-package workgroups2 :when (display-graphic-p) :init @@ -36,18 +44,11 @@ wg-list-display-decor-previous-left "" wg-list-display-decor-previous-right "") - (add-hook! emacs-startup (workgroups-mode +1)) + (add-hook 'emacs-startup-hook 'workgroups-mode) :config (unless (file-exists-p wg-workgroup-directory) (mkdir wg-workgroup-directory)) - (defvar narf-wg-frames '() - "A list of all the frames opened as separate workgroups. See -defuns/defuns-workgroups.el.") - (defvar narf-wg-names '() - "A list of fixed names for workgroups. If a name is set, workgroup names aren't -automatically renamed to the project name.") - ;; Remember the set names in between sessions (add-to-list 'savehist-additional-variables 'narf-wg-names) @@ -55,14 +56,11 @@ automatically renamed to the project name.") ;; Create a new workgroup on switch-project (setq projectile-switch-project-action 'narf/wg-projectile-switch-project)) - ;; Seriously, don't mess with the modeline! `wg-mode-line-display-on' isn't enough + ;; `wg-mode-line-display-on' wasn't enough (advice-add 'wg-change-modeline :override 'ignore) ;; Don't remember popup and neotree windows - (add-hook! kill-emacs - (narf/popup-close-all) - (when (and (featurep 'neotree) (neo-global--window-exists-p)) - (neotree-hide))) + (add-hook 'kill-emacs-hook 'narf|wg-cleanup) ;; This helps abstract some of the underlying functions away, just in case I want to ;; switch to a different package in the future, like persp-mode, eyebrowse or wconf. diff --git a/core/defuns/defuns-workgroup.el b/core/defuns/defuns-workgroup.el index eb42d6794..1ee97d3c6 100644 --- a/core/defuns/defuns-workgroup.el +++ b/core/defuns/defuns-workgroup.el @@ -1,5 +1,11 @@ ;;; defuns-workgroup.el +;;;###autoload +(defun narf|wg-cleanup () + (narf/popup-close-all) + (when (and (featurep 'neotree) (neo-global--window-exists-p)) + (neotree-hide))) + ;;;###autoload (defun narf/wg-projectile-switch-project () (narf:workgroup-new nil (file-name-nondirectory (directory-file-name (narf/project-root))) t)) @@ -9,6 +15,7 @@ (interactive "") (unless (wg-workgroup-list) (wg-create-workgroup wg-first-wg-name)) + (narf|wg-cleanup) (wg-save-session-as (if session-name (concat wg-workgroup-directory session-name) (if bang diff --git a/modules/module-haskell.el b/modules/module-haskell.el index a260ac174..7d67d3f27 100644 --- a/modules/module-haskell.el +++ b/modules/module-haskell.el @@ -10,13 +10,13 @@ (define-repl! haskell-mode switch-to-haskell) (add-hook! haskell-mode '(interactive-haskell-mode flycheck-mode)) :config - (add-to-list 'completion-ignored-extensions ".hi")) + (push ".hi" completion-ignored-extensions)) (use-package inf-haskell :commands (inferior-haskell-mode inf-haskell-mode switch-to-haskell) :init (evil-set-initial-state 'inferior-haskell-mode 'emacs) :config - (define-key inf-haskell-mode-map (kbd "ESC ESC") 'narf/popup-close)) + (map! :map inf-haskell-mode-map "ESC ESC" 'narf/popup-close)) (provide 'module-haskell) ;;; module-haskell.el ends here diff --git a/modules/module-js.el b/modules/module-js.el index 378e646c5..3c65a974a 100644 --- a/modules/module-js.el +++ b/modules/module-js.el @@ -4,13 +4,16 @@ :mode "\\.js$" :interpreter "node" :init + (add-hook 'js2-mode-hook '(tern-mode emr-initialize)) (define-repl! js2-mode nodejs-repl) (define-docset! js2-mode "js,javascript,nodejs,angularjs,express,jquery,mongoose") + (define-company-backend! js2-mode (tern)) (add-hook! js2-mode (electric-indent-local-mode +1) (setq electric-indent-chars '(?} ?\) ?.) narf-electric-indent-words '("||" "&&"))) + :config (setq-default js2-skip-preprocessor-directives t @@ -22,66 +25,55 @@ ;; Launchbar API "LaunchBar" "File" "Action" "HTTP" "include" "Lib")) + (require 'tern) + (require 'company-tern) + ;; [pedantry intensifies] (defadvice js2-mode (after js2-mode-rename-modeline activate) (setq mode-name "JS2")) - (map! :map js2-mode-map - (:localleader :nv ";" 'narf/append-semicolon)) + (map! :map js2-mode-map (:localleader :nv ";" 'narf/append-semicolon)) - (after! web-beautify - (add-hook! js2-mode (setenv "jsbeautify_indent_size" (int-to-string js2-basic-offset))) - (map! :map js2-mode-map :m "gQ" 'web-beautify-js)) - - (use-package tern - :commands tern-mode - :init (add-hook 'js2-mode-hook 'tern-mode) - :config - (require 'company-tern) - (define-company-backend! js2-mode (tern))) - - (use-package js2-refactor - :init (add-hook 'js2-mode-hook 'emr-initialize) - :config - (require 'emr) - (mapc (lambda (x) - (let ((command-name (car x)) - (title (cadr x)) - (region-p (caddr x)) - predicate) - (setq predicate (cond ((eq region-p 'both) nil) - (t (if region-p - (lambda () (use-region-p)) - (lambda () (not (use-region-p))))))) - (emr-declare-command - (intern (format "js2r-%s" (symbol-name command-name))) - :title title :modes 'js2-mode :predicate predicate))) - '((extract-function "extract function" t) - (extract-method "extract method" t) - (introduce-parameter "introduce parameter" t) - (localize-parameter "localize parameter" nil) - (expand-object "expand object" nil) - (contract-object "contract object" nil) - (expand-function "expand function" nil) - (contract-function "contract function" nil) - (expand-array "expand array" nil) - (contract-array "contract array" nil) - (wrap-buffer-in-iife "wrap buffer in ii function" nil) - (inject-global-in-iife "inject global in ii function" t) - (add-to-globals-annotation "add to globals annotation" nil) - (extract-var "extract variable" t) - (inline-var "inline variable" t) - (rename-var "rename variable" nil) - (var-to-this "var to this" nil) - (arguments-to-object "arguments to object" nil) - (ternary-to-if "ternary to if" nil) - (split-var-declaration "split var declaration" nil) - (split-string "split string" nil) - (unwrap "unwrap" t) - (log-this "log this" 'both) - (debug-this "debug this" 'both) - (forward-slurp "forward slurp" nil) - (forward-barf "forward barf" nil))))) + (require 'js2-refactor) + (require 'emr) + (mapc (lambda (x) + (let ((command-name (car x)) + (title (cadr x)) + (region-p (caddr x)) + predicate) + (setq predicate (cond ((eq region-p 'both) nil) + (t (if region-p + (lambda () (use-region-p)) + (lambda () (not (use-region-p))))))) + (emr-declare-command + (intern (format "js2r-%s" (symbol-name command-name))) + :title title :modes 'js2-mode :predicate predicate))) + '((extract-function "extract function" t) + (extract-method "extract method" t) + (introduce-parameter "introduce parameter" t) + (localize-parameter "localize parameter" nil) + (expand-object "expand object" nil) + (contract-object "contract object" nil) + (expand-function "expand function" nil) + (contract-function "contract function" nil) + (expand-array "expand array" nil) + (contract-array "contract array" nil) + (wrap-buffer-in-iife "wrap buffer in ii function" nil) + (inject-global-in-iife "inject global in ii function" t) + (add-to-globals-annotation "add to globals annotation" nil) + (extract-var "extract variable" t) + (inline-var "inline variable" t) + (rename-var "rename variable" nil) + (var-to-this "var to this" nil) + (arguments-to-object "arguments to object" nil) + (ternary-to-if "ternary to if" nil) + (split-var-declaration "split var declaration" nil) + (split-string "split string" nil) + (unwrap "unwrap" t) + (log-this "log this" 'both) + (debug-this "debug this" 'both) + (forward-slurp "forward slurp" nil) + (forward-barf "forward barf" nil)))) (use-package jsx-mode :mode "\\.jsx$") diff --git a/modules/module-julia.el b/modules/module-julia.el index 50faf19db..5b4842e2b 100644 --- a/modules/module-julia.el +++ b/modules/module-julia.el @@ -6,7 +6,7 @@ :init (define-repl! julia-mode narf/julia-repl) (evil-set-initial-state 'inferior-julia-mode 'emacs) - (add-to-list 'editorconfig-indentation-alist '(julia-mode julia-indent-offset))) + (push '(julia-mode julia-indent-offset) editorconfig-indentation-alist)) (provide 'module-julia) ;;; module-julia.el ends here diff --git a/modules/module-php.el b/modules/module-php.el index 3fbcd4bb1..ba630650c 100644 --- a/modules/module-php.el +++ b/modules/module-php.el @@ -45,7 +45,6 @@ (use-package php-refactor-mode :init (add-hook! php-mode '(turn-on-eldoc-mode emr-initialize php-refactor-mode)) :config - (require 'emr) (mapc (lambda (x) (let ((command-name (car x)) (title (cadr x)) diff --git a/modules/module-processing.el b/modules/module-processing.el index 7c6e91fc3..e8d34f40b 100644 --- a/modules/module-processing.el +++ b/modules/module-processing.el @@ -4,13 +4,16 @@ :when IS-MAC :commands (processing-mode processing-find-sketch) :mode "\\.pde$" + :init + (define-builder! processing-mode processing-sketch-build) + (add-hook 'processing-compilation-mode-hook 'narf|hide-mode-line) + :config (setq processing-location "/usr/local/bin/processing-java" processing-application-dir "/Applications/Processing.app" processing-sketchbook-dir "~/Dropbox/work/pde" processing-output-dir "/tmp") - (define-builder! processing-mode processing-sketch-build) (after! quickrun (quickrun-add-command "processing" `((:command . ,processing-location) @@ -21,7 +24,7 @@ (map! :map processing-mode-map :nv "M-r" 'processing-sketch-run - :m "gD" 'processing-find-in-reference + :m "gd" 'processing-find-in-reference :m "gF" 'processing-find-sketch (:localleader "e" 'processing-export-application @@ -29,7 +32,6 @@ "e" 'processing-open-examples "o" 'processing-open-sketchbook)) - (add-hook 'processing-compilation-mode-hook 'narf|hide-mode-line) (add-hook! processing-mode (setq-local company-backends '((company-keywords :with diff --git a/modules/module-rust.el b/modules/module-rust.el index 914ea5150..6be310fc7 100644 --- a/modules/module-rust.el +++ b/modules/module-rust.el @@ -6,8 +6,8 @@ (define-builder! rust-mode "cargo run" "Cargo.toml") (define-builder! toml-mode "cargo run" "Cargo.toml") - (use-package flycheck-rust - :config (add-hook 'rust-mode-hook 'flycheck-mode)) + (require 'flycheck-rust) + (add-hook 'rust-mode-hook 'flycheck-mode) (use-package racer :preface @@ -15,12 +15,12 @@ racer-rust-src-path (concat narf-ext-dir "/rust/src/")) :when (file-exists-p racer-cmd) :config + (define-company-backend! rust-mode (racer)) (map! :map rust-mode-map :m "gd" 'racer-find-definition) ;; TODO Unit test keybinds - (add-hook! rust-mode '(racer-mode eldoc-mode flycheck-rust-setup)) - (define-company-backend! rust-mode (racer)))) + (add-hook! rust-mode '(racer-mode eldoc-mode flycheck-rust-setup)))) (provide 'module-rust) ;;; module-rust.el ends here diff --git a/modules/module-text.el b/modules/module-text.el index be59ab048..a51477454 100644 --- a/modules/module-text.el +++ b/modules/module-text.el @@ -2,10 +2,6 @@ (use-package markdown-mode :mode ("\\.md$" "/README$") - :functions (markdown-use-region-p - markdown-unwrap-things-in-region - markdown-wrap-or-insert - markdown-unwrap-thing-at-point) :init (add-hook 'markdown-mode-hook 'turn-on-auto-fill) :config diff --git a/modules/module-web.el b/modules/module-web.el index b80f3b4d7..9faa76314 100644 --- a/modules/module-web.el +++ b/modules/module-web.el @@ -80,11 +80,10 @@ (use-package web-beautify :commands (web-beautify-js web-beautify-css web-beautify-html) :init - (add-hook! (web-mode css-mode) (setenv "jsbeautify_indent_size" tab-width)) - (after! web-mode - (map! :map web-mode-map - (:after web-mode :m "gQ" 'web-beautify-html) - (:after css-mode :m "gQ" 'web-beautify-css)))) + (add-hook! (web-mode css-mode js2-mode) (setenv "jsbeautify_indent_size" (int-to-string tab-width))) + (map! (:after web-mode :map web-mode-map :m "gQ" 'web-beautify-html) + (:after css-mode :map css-mode-map :m "gQ" 'web-beautify-css) + (:after js2-mode :map js2-mode-map :m "gQ" 'web-beautify-js))) (use-package emmet-mode :commands (emmet-mode)