;;; ll --- ll -*- lexical-binding: t -*- ;;; Commentary: This is not the best version of this file; don't bother edit. ;;; Code: (require 'cl-lib) (defun ll-buffer-string (&optional beg end prop) (or beg (setf beg (point-min))) (or end (setf end (point-max))) (when-let* ((f (if prop #'buffer-substring #'buffer-substring-no-properties))) (funcall f beg end))) ;; ----- ;; eieio ;; ----- (defmacro ~ (spec-list object &rest body) `(with-slots ,spec-list ,object ,@body)) (defmacro @ (obj slot) `(oref ,obj ,slot)) ;; ------- ;; buffers ;; ------- (defun pop-buff (&optional buffer-or-name action norecord) (or buffer-or-name (setf buffer-or-name (current-buffer))) (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))) ;; --------------------------------- ;; `message', `insert', 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) `(and (listp ,object) (<= 1 (length ,object)))) (defmacro su (object) `(and (stringp ,object) (<= 1 (length ,object)))) (defmacro sequ (object) `(and (sequencep ,object) (<= 1 (length ,object)))) (defmacro l (object) `(listp ,object)) (defmacro s (object) `(stringp ,object)) (defmacro seq (object) `(sequencep ,object)) (defmacro !l (object) `(not (listp ,object))) (defmacro !s (object) `(not (stringp ,object))) (defmacro !seq (object) `(not (sequencep ,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)) ;; ------- ;; 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))) (defun in (a b c) (and (numberp a) (numberp b) (numberp c) (<= a b) (< b c))) (defmacro ni (object) `(integerp ,object)) (defmacro !ni (object) `(not (integerp ,object))) (defmacro nf (object) `(floatp ,object)) (defmacro !nf (object) `(not (floatp ,object))) (defmacro num-seq (beg end &optional inc) `(or inc 1) `(number-sequence ,beg ,end ,inc)) ;; ------- ;; logical ;; ------- (defmacro ! (object) `(not ,object)) (defmacro & (&rest conditions) `(and ,@conditions)) (defun nand (&rest conditions) (when (member nil conditions) t)) (defun nor (&rest conditions) (unless (member t conditions) t)) ;; ----------- ;; `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)) ;; --- ;; mod ;; --- (defmacro m (x &optional y) `(mod ,x ,(if (z y) 1 y))) (defmacro r (arg &optional devisor) (round arg devisor)) ;; ---- ;; math ;; ---- (defmacro ** (arg1 arg2) `(expt ,arg1 ,arg2)) (defmacro // (number &rest divisors) `(/ ,number ,@divisors 1.0)) ;; -------- ;; interval ;; -------- (cl-defmethod <=-< ((beg number) (n number) (end number)) (& `(<= ,beg ,n) `(< ,n ,end))) (defalias 'half-open #'<=-<) ;; --------------- ;; increment field ;; --------------- (defmacro ++ (place &optional x) (or x (setf x 1)) `(cl-incf ,place ,x)) (defmacro -- (place &optional x) (or x (setf x 1)) `(cl-decf ,place ,x)) ;; ------------------- ;; `display-graphic-p' ;; ------------------- (defmacro gfx (&optional display) `(display-graphic-p ,display)) ;; ------ ;; colors ;; ------ (defmacro face-bg (f) `(face-background ,f)) (defmacro face-fg (f) `(face-foreground ,f)) (defmacro set-bg (f) `(set-background-color ,f)) (defmacro set-fg (f) `(set-foreground-color ,f)) (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)) (str (read-string psf nil nil def))) (if (string= str "?") ($ "No help yet.") 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)))))) (cl-defmethod seq-butlast ((l sequence) &optional (n 1)) (seq-take l (- (length l) n))) (cl-defmethod seq-last ((l sequence) &optional (n 1)) (seq-subseq l (- (length l) n))) (cl-defmethod luki-shift ((l list) &optional (n 1)) (let ((len (length l))) (if (or (zerop len) (zerop n)) l (setf n (mod n len)) (append (last l n) (butlast l n))))) (cl-defmethod goto-bol-next-line (&optional (chars 0) (lines 1)) (goto-char (+ chars (pos-bol (1+ lines))))) (provide 'll) ;; ll.el ends her