;;; -*- lexical-binding: t -*- ;; ;; ----------------------------------------------------------------------- (defun luki-require () (interactive) (goto-char (point-min)) (re-search-forward "^$") (insert "\n" "(require 'cl-lib)\n" "(cl-pushnew \".\" load-path :test #'string=)\n" "(require 'luki-lisp)\n")) (defalias 'luki-req #'luki-require) (defalias 'luki-rek #'luki-require) ;; -------------------------------------------------------------------------- ;; eieio ;; (`with-slots', `oref') (defmacro ~ (spec-list object &rest body) `(with-slots ,spec-list ,object ,@body)) (defmacro @ (obj slot) `(oref ,obj ,slot)) ;; -------------------------------------------------------------------------- ;; output ;; (`message' and `format') (defmacro $ (format-string &rest args) `(message ,format-string ,@args)) (defmacro @f (string &rest objects) `(format ,string ,@objects)) ;; -------------------------------------------------------------------------- ;; lists (defmacro l= (l1 l2) `(equal ,l1 ,l2)) (defmacro 1st (lst) `(car ,lst)) (defmacro 2nd (lst) `(cadr ,lst)) (defmacro 3rd (lst) `(caddr ,lst)) (defmacro 4th (lst) `(cadddr ,lst)) (defmacro 5th (lst) `(caddddr ,lst)) (defmacro 6th (lst) `(cadddddr ,lst)) (defmacro 7th (lst) `(caddddddr ,lst)) (defmacro 8th (lst) `(cadddddddr ,lst)) (defmacro 0i (lst) `(nth 0 ,lst)) (defmacro 1i (lst) `(nth 1 ,lst)) (defmacro 2i (lst) `(nth 2 ,lst)) (defmacro 3i (lst) `(nth 3 ,lst)) (defmacro 4i (lst) `(nth 4 ,lst)) (defmacro 5i (lst) `(nth 5 ,lst)) (defmacro 6i (lst) `(nth 6 ,lst)) (defmacro 7i (lst) `(nth 7 ,lst)) (defmacro --- (sequence) `(length ,sequence)) (defmacro lu (object) ; list useful `(and (listp ,object) (not (zerop (length ,object))))) (defmacro l (object) `(listp ,object)) ;; -------------------------------------------------------------------------- ;; strings (defmacro s2n (string &optional base) `(string-to-number ,string ,base)) (defmacro s= (s1 s2) `(string-equal ,s1 ,s2)) (defmacro su (object) ; string useful `(and (stringp ,object) (not (zerop (length ,object))))) (defmacro s (object) `(stringp ,object)) (defmacro !s (object) `(not (stringp ,object))) ;; -------------------------------------------------------------------------- ;; numbers (defmacro z (number) `(and (numberp ,number) (zerop ,number))) (defmacro !z (number) `(or (not (numberp ,number)) (not (zerop ,number)))) (defmacro n (object) `(numberp ,object)) (defmacro !n (object) `(not (numberp ,object))) ;; -------------------------------------------------------------------------- ;; logical (defun nand (&rest conditions) (when (member nil conditions) t)) ;; (nand) ; nil ;; (nand 1 2 3) ; nil ;; (nand nil) ; t ;; (nand 1 2 nil 3) ; t ;; (not (and)) ; nil ;; (not (and 1 2 3)) ; nil ;; (not (and nil)) ; t ;; (not (and 1 2 nil 3)) ; t (defun nor (&rest conditions) (unless (member t conditions) t)) ;; (nor (< 1 2) (< 2 3) (< 3 3)) (defmacro ! (object) `(not ,object)) (defmacro & (&rest conditions) `(and ,@conditions)) ;; -------------------------------------------------------------------------- ;; goto (defmacro goto-beg () `(goto-char ,(point-min))) (defmacro goto-end () `(goto-char ,(point-max))) ;; ----------------------------------------------------------------------- ;; `require' and `provide' (defmacro -> (feature &optional filename noerror) `(require ,feature ,filename ,noerror)) (defmacro <- (feature &optional subfeatures) `(provide ,feature ,subfeatures)) ;; -------------------------------------------------------------------------- ;; functions (defmacro i () `(interactive)) (defmacro L (arglist &rest body) `(lambda ,arglist (interactive) ,@body)) ;; -------------------------------------------------------------------------- ;; math (defmacro m (x y) `(mod ,x ,y)) (defmacro ++ (place &optional x) (or x (setq x 1)) `(cl-incf ,place ,x)) (defmacro -- (place &optional x) (or x (setq x 1)) `(cl-decf ,place ,x)) (defmacro ** (arg1 arg2) `(expt ,arg1 ,arg2)) (defmacro // (number &rest divisors) `(/ ,number ,@divisors 1.0)) ;; -------------------------------------------------------------------------- ;; `display-graphic-p' (defmacro gfx (&optional display) `(display-graphic-p ,display)) ;; -------------------------------------------------------------------------- (provide 'luki-lisp)