diff --git a/core/core-defuns.el b/core/core-defuns.el index 7601f89fb..4a08ea81c 100644 --- a/core/core-defuns.el +++ b/core/core-defuns.el @@ -231,6 +231,12 @@ Examples: (setq i (1+ i))) `(progn ,@(apply #'nconc (delete nil (delete (list nil) (reverse forms)))))))) +(defmacro def-repeat! (command next-func prev-func) + "Repeat motions with SPC/S-SPC" + `(defadvice ,command + (before ,(intern (format "narf-space--%s" (symbol-name command))) activate) + (define-key evil-motion-state-map (kbd "SPC") ',next-func) + (define-key evil-motion-state-map (kbd "S-SPC") ',prev-func))) ;; (defun narf|update-scratch-buffer-cwd (&optional dir) ; see core-editor.el diff --git a/core/core-evil.el b/core/core-evil.el index 86a53ea85..e16afd675 100644 --- a/core/core-evil.el +++ b/core/core-evil.el @@ -96,13 +96,6 @@ (add-hook! isearch-mode (setq echo-keystrokes 0)) (add-hook! isearch-mode-end (setq echo-keystrokes 0.02)) - ;; Repeat motions with SPC/S-SPC - (defmacro def-repeat! (command next-func prev-func) - `(defadvice ,command - (before ,(intern (format "narf-space--%s" (symbol-name command))) activate) - (define-key evil-motion-state-map (kbd "SPC") ',next-func) - (define-key evil-motion-state-map (kbd "S-SPC") ',prev-func))) - (after! evil-snipe (def-repeat! evil-snipe-f evil-snipe-repeat evil-snipe-repeat-reverse) (def-repeat! evil-snipe-F evil-snipe-repeat evil-snipe-repeat-reverse) diff --git a/core/defuns/macros-company.el b/core/defuns/macros-company.el index a22b37b63..41cd122c7 100644 --- a/core/defuns/macros-company.el +++ b/core/defuns/macros-company.el @@ -6,7 +6,7 @@ "Register a company backend for a mode." (let* ((hooks (if (listp hooks) hooks (list hooks))) (def-name (intern (format "narf--init-company-%s" - (s-join "-" (mapcar 'symbol-name hooks))))) + (mapconcat 'identity (mapcar 'symbol-name hooks) "-")))) (quoted (eq (car-safe backends) 'quote))) `(progn (defun ,def-name () diff --git a/core/defuns/macros-editor.el b/core/defuns/macros-editor.el index 0a8406b76..358c7e0ad 100644 --- a/core/defuns/macros-editor.el +++ b/core/defuns/macros-editor.el @@ -3,12 +3,11 @@ ;;;###autoload (defmacro def-electric! (modes &rest rest) (declare (indent 1)) - (let ((modes (if (listp modes) modes (list modes))) + (let ((modes (-list modes)) (chars (plist-get rest :chars)) (words (plist-get rest :words))) (when (or chars words) - (let ((fn-name (intern (format "narf--electric-%s" - (s-join "-" (mapcar 'symbol-name modes)))))) + (let ((fn-name (intern (format "narf--electric-%s" (s-join "-" (mapcar 'symbol-name modes)))))) `(progn (defun ,fn-name () (electric-indent-local-mode +1) @@ -16,5 +15,21 @@ ,(if words `(setq narf-electric-indent-words ',words))) (add-hook! ,modes ',fn-name)))))) +;;;###autoload +(defmacro def-rotate! (modes &rest rest) + (declare (indent 1)) + (let ((modes (if (listp modes) modes (list modes))) + (symbols (plist-get rest :symbols)) + (words (plist-get rest :words)) + (patterns (plist-get rest :patterns))) + (when (or symbols words patterns) + (let ((fn-name (intern (format "narf--rotate-%s" (s-join "-" (mapcar 'symbol-name modes)))))) + `(progn + (defun ,fn-name () + ,(if symbols `(setq-local rotate-text-local-symbols ',symbols)) + ,(if words `(setq-local rotate-text-local-words ',words)) + ,(if patterns `(setq-local rotate-text-local-patterns ',patterns))) + (add-hook! ,modes ',fn-name)))))) + (provide 'macros-editor) ;;; macros-editor.el ends here diff --git a/core/defuns/macros-eval.el b/core/defuns/macros-eval.el new file mode 100644 index 000000000..5b2b1ea58 --- /dev/null +++ b/core/defuns/macros-eval.el @@ -0,0 +1,21 @@ +;;; macros-eval.el + +;;;###autoload +(defmacro def-builder! (mode command &optional build-file) + "Register major/minor MODE with build COMMAND. If FILES are provided, do an additional +check to make sure they exist in the project root." + (let ((fn (intern (format "narf--init-builder-%s" mode)))) + `(progn + (defun ,fn () + (when (or (null ,build-file) + (narf/project-has-files ,build-file)) + (setq narf--build-command '(,command . ,build-file)))) + (add-hook! ,mode ',fn)))) + +;;;###autoload +(defmacro def-repl! (mode command) + "Define a REPL for a mode." + `(push '(,mode . ,command) rtog/mode-repl-alist)) + +(provide 'macros-eval) +;;; macros-eval.el ends here diff --git a/core/defuns/macros-evil.el b/core/defuns/macros-evil.el index e9e83ec7a..73f19a45b 100644 --- a/core/defuns/macros-evil.el +++ b/core/defuns/macros-evil.el @@ -14,7 +14,7 @@ ;;;###autoload (defmacro def-tmp-excmd! (cmd-on cmd-off &rest commands) - "Creates on-off defuns for a set of ex commands, named CMD-ON and CMD-OFF." + "Creates a toggle for a set of ex commands, named CMD-ON and CMD-OFF." (declare (indent 2)) `(progn (defun ,cmd-on (&rest _) @@ -24,19 +24,15 @@ (mapc (lambda (cmd) (narf/evil-ex-undefine-cmd (car cmd))) ',commands)))) - ;; Shortcuts for the evil expression register ;;;###autoload -(defmacro $= (str &rest args) - `(calc-eval (format ,str ,@args))) +(defmacro $= (str &rest args) `(calc-eval (format ,str ,@args))) ;;;###autoload -(defmacro $r (char) - `(evil-get-register ,char)) +(defmacro $r (char) `(evil-get-register ,char)) ;;;###autoload -(defmacro $expand (path) - `(evil-ex-replace-special-filenames ,path)) +(defmacro $expand (path) `(evil-ex-replace-special-filenames ,path)) (provide 'macros-evil) ;;; macros-evil.el ends here diff --git a/core/defuns/macros-quickrun.el b/core/defuns/macros-quickrun.el deleted file mode 100644 index b40594266..000000000 --- a/core/defuns/macros-quickrun.el +++ /dev/null @@ -1,17 +0,0 @@ -;;; macros-quickrun.el - -;;;###autoload -(defmacro def-builder! (mode command &optional build-file) - "Register major/minor MODE with build COMMAND. If FILES are provided, do an -additional check to make sure they exist in the project root." - `(add-hook! ,mode - (when (or (null ,build-file) - (narf/project-has-files ,build-file)) - (setq narf--build-command '(,command . ,build-file))))) - -;;;###autoload -(defmacro def-repl! (mode command) - `(push '(,mode . ,command) rtog/mode-repl-alist)) - -(provide 'macros-quickrun) -;;; macros-quickrun.el ends here diff --git a/core/defuns/macros-spaceline.el b/core/defuns/macros-spaceline.el index b0625acae..79f80e288 100644 --- a/core/defuns/macros-spaceline.el +++ b/core/defuns/macros-spaceline.el @@ -1,18 +1,17 @@ ;;; defuns-spaceline.el ;;;###autoload -(defmacro def-env-command! (mode command) +(defmacro def-version-cmd! (modes command) "Define a COMMAND for MODE that will set `narf--env-command' when that mode is activated, which should return the version number of the current environment. It is used by `narf|spaceline-env-update' to display a version number in the modeline. For instance: - (def-env-command! ruby-mode \"ruby --version | cut -d' ' -f2\") + (def-version-cmd! ruby-mode \"ruby --version | cut -d' ' -f2\") This will display the ruby version in the modeline in ruby-mode buffers. It is cached the first time." (add-hook! (focus-in find-file) 'narf|spaceline-env-update) - `(add-hook ',(intern (format "%s-hook" (symbol-name mode))) - (lambda () (setq narf--env-command ,command)))) + `(add-hook! ,modes (setq narf--env-command ,command))) (provide 'defuns-spaceline) ;;; defuns-spaceline.el ends here