Declare ruby-mode & js2-mode emr refactor defuns

This commit is contained in:
Henrik Lissner 2015-09-13 23:30:08 -04:00
parent 5203f4b5ac
commit 44a9c00e18
2 changed files with 58 additions and 25 deletions

View file

@ -18,7 +18,47 @@
(add-hook! js2-mode (setenv "jsbeautify_indent_size" "4")) (add-hook! js2-mode (setenv "jsbeautify_indent_size" "4"))
(bind! :map js2-mode-map :m "gQ" 'web-beautify-js)) (bind! :map js2-mode-map :m "gQ" 'web-beautify-js))
(after! emr (require 'js2-refactor)) (use-package js2-refactor
:after emr
:init (add-hook! js2-mode 'emr-initialize)
:config
(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))))
;; [pedantry intensifies] ;; [pedantry intensifies]
(defadvice js2-mode (after js2-mode-rename-modeline activate) (defadvice js2-mode (after js2-mode-rename-modeline activate)

View file

@ -76,30 +76,23 @@
:after emr :after emr
:init (add-hook! ruby-mode 'emr-initialize) :init (add-hook! ruby-mode 'emr-initialize)
:config :config
(emr-declare-command 'ruby-toggle-block (mapc (lambda (x)
:title "toggle block" (let ((command-name (car x))
:modes 'enh-ruby-mode (title (cadr x))
:predicate (lambda () (not (use-region-p)))) (region-p (caddr x))
(emr-declare-command 'ruby-refactor-extract-to-method predicate)
:title "extract method" (setq predicate (cond ((eq region-p 'both) nil)
:modes 'enh-ruby-mode (t (if region-p
:predicate (lambda () (use-region-p))) (lambda () (use-region-p))
(emr-declare-command 'ruby-refactor-extract-local-variable (lambda () (not (use-region-p)))))))
:title "extract local variable" (emr-declare-command (intern (format "ruby-%s" (symbol-name command-name)))
:modes 'enh-ruby-mode :title title :modes 'ruby-mode :predicate predicate)))
:predicate (lambda () (use-region-p))) '((toggle-block "toggle block" nil)
(emr-declare-command 'ruby-refactor-extract-constant (refactor-extract-to-method "extract method" t)
:title "extract constant" (refactor-extract-local-variable "extract local variable" t)
:modes 'enh-ruby-mode (refactor-extract-constant "extract constant" t)
:predicate (lambda () (use-region-p))) (refactor-add-parameter "add parameter" nil)
(emr-declare-command 'ruby-refactor-add-parameter (refactor-extract-to-let "extract to let" t))))
:title "add parameter"
:modes 'enh-ruby-mode
:predicate (lambda () (not (use-region-p))))
(emr-declare-command 'ruby-refactor-extract-to-let
:title "extract to let"
:modes 'enh-ruby-mode
:predicate (lambda () (use-region-p))))
(provide 'module-ruby) (provide 'module-ruby)
;;; module-ruby.el ends here ;;; module-ruby.el ends here