From a638e15c0dd14a25e6f032b08de5ee1575677497 Mon Sep 17 00:00:00 2001 From: William Carroll Date: Mon, 31 Aug 2020 23:28:47 +0100 Subject: Lint string, macros.el More of the same type of linting... basically preferring `namespace-` instead of `namespace/`. --- emacs/.emacs.d/wpc/macros.el | 64 ++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 44 deletions(-) (limited to 'emacs/.emacs.d/wpc/macros.el') diff --git a/emacs/.emacs.d/wpc/macros.el b/emacs/.emacs.d/wpc/macros.el index 5f7c93902e3e..e7fd16229efb 100644 --- a/emacs/.emacs.d/wpc/macros.el +++ b/emacs/.emacs.d/wpc/macros.el @@ -1,5 +1,9 @@ ;;; macros.el --- Helpful variables for making my ELisp life more enjoyable -*- lexical-binding: t -*- -;; Authpr: William Carroll + +;; Author: William Carroll +;; Version: 0.0.1 +;; URL: https://git.wpcarro.dev/wpcarro/briefcase +;; Package-Requires: ((emacs "24")) ;;; Commentary: ;; This file contains helpful variables that I use in my ELisp development. @@ -9,51 +13,44 @@ ;;; Code: +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Dependencies +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + (require 'f) (require 'string) (require 'symbol) -;; TODO: Support `xi' lambda shorthand macro. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Library +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defmacro enable (mode) +(defmacro macros-enable (mode) "Helper for enabling `MODE'. Useful in `add-hook' calls. Some modes, like `linum-mode' need to be called as `(linum-mode 1)', so `(add-hook mode #'linum-mode)' won't work." `#'(lambda nil (,mode 1))) -(defmacro disable (mode) +(defmacro macros-disable (mode) "Helper for disabling `MODE'. Useful in `add-hook' calls." `#'(lambda nil (,mode -1))) -(defmacro add-hooks (modes callback) - "Add multiple `MODES' for the `CALLBACK'. -Usage: (add-hooks '(one-mode-hook 'two-mode-hook) #'fn)" - `(dolist (mode ,modes) - (add-hook mode ,callback))) - -(defmacro add-hook-before-save (mode f) +(defmacro macros-add-hook-before-save (mode f) "Register a hook, `F', for a mode, `MODE' more conveniently. Usage: (add-hook-before-save 'reason-mode-hook #'refmt-before-save)" `(add-hook ,mode (lambda () (add-hook 'before-save-hook ,f)))) -;; TODO: Debug. -(defmacro macros/ilambda (&rest body) - "Surrounds `BODY' with an interactive lambda function." - `(lambda () - (interactive) - ,@body)) - ;; TODO: Privatize? -(defun namespace () +(defun macros--namespace () "Return the namespace for a function based on the filename." (->> (buffer-file-name) f-filename f-base)) -(defmacro macros/comment (&rest _) +(defmacro macros-comment (&rest _) "Empty comment s-expresion where `BODY' is ignored." `nil) @@ -64,31 +61,10 @@ Usage: (add-hook-before-save 'reason-mode-hook #'refmt-before-save)" `(lambda (,sym) (->> ,sym ,@forms)))) -;; TOOD: Support this. -(cl-defmacro macros/test - (&key function - test - args - expect - equality) - (let* ((namespace (namespace)) - (test-name (string/->symbol - (s-concat namespace - "/" - "test" - "/" - (s-chop-prefix - (s-concat namespace "/") - (symbol/to-string function)))))) - `(ert-deftest ,test-name () - ,test - (should (,equality (apply ,function ,args) - ,expect))))) - -(defmacro macros/support-file-extension (ext mode) +(defmacro macros-support-file-extension (ext mode) "Register MODE to automatically load with files ending with EXT extension. -Usage: (macros/support-file-extension \"pb\" protobuf-mode)" - (let ((extension (string/format "\\.%s\\'" ext))) +Usage: (macros-support-file-extension \"pb\" protobuf-mode)" + (let ((extension (string-format "\\.%s\\'" ext))) `(add-to-list 'auto-mode-alist '(,extension . ,mode)))) (provide 'macros) -- cgit 1.4.1