;;; -*- lexical-binding: t -*- ;; ;; ----------------------------------------------------------------------- (require 'cl-lib) (cl-pushnew "." load-path :test #'string=) ;; -------------------------------------------------------------------------- (require 'luki-dwim) ;; -------------------------------------------------------------------------- (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) ;; -------------------------------------------------------------------------- (defun luki-replace-regexp (re rep &optional beg end not-rev) (interactive `(,(read-string "re: ") ,(read-string "replace: ") ,@(use-region) ,current-prefix-arg)) (or beg (setq beg (point-min))) (or end (setq end (point-max))) (pcase-let ((`(,strt ,sfun ,stop) (if not-rev (list beg #'re-search-forward end) (list end #'re-search-backward beg)))) (save-excursion (cl-loop initially do (goto-char strt) with c = 0 while (apply sfun re stop '(t)) do (replace-match rep) (cl-incf c) finally do (message "replaced: %d" c))))) (defalias 'luki-rr #'luki-replace-regexp) (defun luki-files () (interactive) (let* ((fs (directory-files "." nil "^[[:alnum:]-]*.el$")) (not-these (list "luki-lisp.el" "luki-dwim.el"))) (with-temp-buffer (dolist (f fs) (unless (member f not-these) (when (find-file f) (luki-replace) (save-buffer))))))) (defun luki-replace () (interactive) (cl-loop with beg = nil initially do (goto-char (point-min)) (unless (search-forward "luki-lisp" nil t) (luki-rek)) (setq beg (pos-bol 2)) for (elisp luki) in '( ("(car\\b" "(1st" ) ("(cadr\\b" "(2nd" ) ("(caddr\\b" "(3rd" ) ("(cadddr\\b" "(4th" ) ("(caddddr\\b" "(5st" ) ("(cadddddr\\b" "(6nd" ) ("(caddddddr\\b" "(7rd" ) ("(cadddddddr\\b" "(8th" ) ("(nth 0\\b" "(0i" ) ("(nth 1\\b" "(1i" ) ("(nth 2\\b" "(2i" ) ("(nth 3\\b" "(3i" ) ("(nth 4\\b" "(4i" ) ("(nth 5\\b" "(5i" ) ("(nth 6\\b" "(6i" ) ("(nth 7\\b" "(7i" ) ("(format\\b" "(@f" ) ("(message\\b" "($" ) ("(with-slots\\b" "(~" ) ("(and\\b" "(&" ) ("(cl-decf\\b" "(--" ) ("(cl-incf\\b" "(++" ) ("(expt\\b" "(**" ) ("(goto-char (point-max))\\b" "(goto-end)") ("(goto-char (point-min))\\b" "(goto-beg)") ("(interactive\\b" "(i" ) ("(lambda\\b" "(L" ) ("(length\\b" "(---" ) ("(listp\\b" "(l" ) ("(mod\\b" "(m" ) ("(not\\b" "(!" ) ("(numberp\\b" "(n" ) ("(oref\\b" "(@" ) ("(provide\\b" "(<-" ) ("(require\\b" "(->" ) ("(zerop\\b" "(z" ) ("(display-graphic-p\\b" "(gfx" ) ) do (luki-replace-regexp elisp luki beg) finally do (goto-char beg))) ;; -------------------------------------------------------------------------- ;; 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)) ;; -------------------------------------------------------------------------- ;; 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))) ;; -------------------------------------------------------------------------- ;; predicates (defmacro lu (object) ; list useful `(and (listp ,object) (not (zerop (length ,object))))) (defmacro l (object) `(listp ,object)) (defmacro z (number) `(and (numberp ,number) (zerop ,number))) (defmacro !z (number) `(or (not (numberp ,number)) (not (zerop ,number)))) (defmacro n (object) `(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)