Lint string, macros.el
More of the same type of linting... basically preferring `namespace-` instead of `namespace/`.
This commit is contained in:
parent
158f810981
commit
a638e15c0d
36 changed files with 176 additions and 204 deletions
|
|
@ -1,5 +1,9 @@
|
|||
;;; macros.el --- Helpful variables for making my ELisp life more enjoyable -*- lexical-binding: t -*-
|
||||
;; Authpr: William Carroll <wpcarro@gmail.com>
|
||||
|
||||
;; Author: William Carroll <wpcarro@gmail.com>
|
||||
;; 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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue