;;; -*- lexical-binding: t -*- (require 'cl-lib) ;; ----- ;; eieio ;; ----- (defmacro ~ (spec-list object &rest body) `(with-slots ,spec-list ,object ,@body)) (defmacro @ (obj slot) `(oref ,obj ,slot)) ;; ------- ;; buffers ;; ------- (defmacro pop-buff (buffer-or-name &optional action norecord) `(pop-to-buffer ,buffer-or-name ,action ,norecord)) ;; ------- ;; windows ;; -------- (defmacro win-beg (&optional window) `(window-start ,window)) (defmacro win-end (&optional window update) `(window-end ,window ,(not update))) ;; ------------------------------ ;; output: `message' and `format' ;; ------------------------------ (defmacro $ (format-string &rest args) `(message ,format-string ,@args)) (defmacro @i (&rest args) `(insert ,@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 s2b (string &optional base) `(string-to-number ,string (or ,base 2))) (defmacro s< (s1 s2) `(string-lessp ,s1 ,s2)) (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) `(not (and (numberp ,number) (zerop ,number)))) (defmacro n (object) `(numberp ,object)) (defmacro !n (object) `(not (numberp ,object))) (defmacro ni (object) `(integerp ,object)) (defmacro !ni (object) `(not (integerp ,object))) (defmacro num-seq (beg end &optional inc) `(or inc 1) `(number-sequence ,beg ,end ,inc)) ;; ------- ;; 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-char' ;; ----------- (defmacro goto-beg () `(goto-char ,(point-min))) (defmacro goto-end () `(goto-char ,(point-max))) ;; --------------------- ;; `require' & `provide' ;; --------------------- (defmacro -> (feature &optional filename noerror) `(require ,feature ,filename ,noerror)) (defmacro <- (feature &optional subfeatures) `(provide ,feature ,subfeatures)) ;; -------------------------- ;; `interactive' and `lambda' ;; -------------------------- (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)) ;; ------ ;; colors ;; ------ (defmacro face-fg (face) `(face-foreground ,face)) (defmacro face-bg (face) `(face-background ,face)) (defmacro set-fg (face) `(set-foreground-color ,face)) (defmacro set-bg (face) `(set-background-color ,face)) ;; ----------------------------------------------------------------------------- (defun luki-me () (cl-loop with beg = (float-time) with pow = 22 with res = nil repeat (** 2 pow) do (setf res (1+ (1- (+ 1 (- 1 (* 1 (/ 1 (** 1 (sqrt 1))))))))) with end = (float-time) with tme = (- end beg) finally ($ "[ problem size: 2^%d ] result computed in in %.2f s: %d]" pow tme res))) ;; (luki-me) (defun luki-read-str (&optional ps def) (let* ((ps1 (@f "%s: " (or ps "input: "))) (psd (& def (@f "%s[%s] " ps1 def))) (psf (or psd ps1))) (read-string psf nil nil def))) ;; (luki-read-str) (defmacro luki-pushlast (e lst) (declare (debug (form gv-place))) (macroexp-let2 macroexp-copyable-p x e (gv-letplace (get set) lst (funcall set `(append ,get (cons ,e nil)))))) ;; (setq lst '(1 2 3)) ; (1 2 3) ;; (setq lst-2 nil) ; (1 2 3) ;; (luki-pushlast 4 lst) ; (1 2 3 4) (defun luki-shift (l) (append (last l) (butlast l))) ;; ----------------------------------------------------------------------------- (provide 'luki-lisp)