94 lines
1.9 KiB
EmacsLisp
94 lines
1.9 KiB
EmacsLisp
(defun matrgen (rows cols)
|
|
"Generate 2D matrix pattern with `rows' rows and `cols' columns"
|
|
(interactive "nRows:\nnCols:")
|
|
(when (and (> rows 0) (> cols 0))
|
|
(if (= rows 1)
|
|
; If there's only one row, just use square brackets
|
|
; Eg: [1,2,3,4]
|
|
(progn
|
|
(insert "[ ")
|
|
(dotimes (c cols)
|
|
(insert "_ "))
|
|
(insert " ]\n"))
|
|
|
|
(progn
|
|
; Draw top part
|
|
(insert "⎡ ")
|
|
(dotimes (c cols)
|
|
(insert "_ "))
|
|
(insert " ⎤\n")
|
|
|
|
; Draw middle part
|
|
(dotimes (r (- rows 2))
|
|
(insert "⎢ ")
|
|
(dotimes (c cols)
|
|
(insert "_ "))
|
|
(insert " ⎥\n"))
|
|
|
|
; Draw bottom part
|
|
(insert "⎣ ")
|
|
(dotimes (c cols)
|
|
(insert "_ "))
|
|
(insert " ⎦\n")))))
|
|
|
|
|
|
|
|
; (defun matrgen (rows cols)
|
|
; (interactive "nRows:\nnCols:")
|
|
; (when (> rows 0)
|
|
; (if (= rows 1)
|
|
; (progn
|
|
; (insert "[ ")
|
|
; (dotimes (c cols)
|
|
; (insert "_ "))
|
|
; (insert " ]\n"))
|
|
;
|
|
; (progn
|
|
; (insert "⎡ ")
|
|
; (dotimes (c cols)
|
|
; (insert "_ "))
|
|
; (insert " ⎤\n")
|
|
;
|
|
; (dotimes (r (- rows 2))
|
|
; (insert "⎢ ")
|
|
; (dotimes (c cols)
|
|
; (insert "_ "))
|
|
; (insert " ⎥\n"))
|
|
;
|
|
; (insert "⎣ ")
|
|
; (dotimes (c cols)
|
|
; (insert "_ "))
|
|
; (insert " ⎦\n")))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; (dotimes (r (- rows 2))
|
|
; (insert "⎢ ")
|
|
; (dotimes (c cols)
|
|
; (insert "_ "))
|
|
; (insert "⎥\n")))
|
|
|
|
|
|
; (defun matrgen (rows cols)
|
|
; (interactive "nRows:\nnCols:")
|
|
; (dotimes (i rows)
|
|
; (insert "⎢ ")
|
|
; (dotimes (i cols)
|
|
; (insert "_ "))
|
|
; (insert "⎥\n")))
|
|
|
|
|
|
;(insert (format "%d %d" rows cols))))
|
|
|
|
|
|
|
|
;(message "%s %s" (number-to-string rows) (number-to-string cols)))
|
|
|
|
;(insert "hi " (number-to-string rows) "."))
|
|
|
|
;(insert "hi " string "."))
|
|
;(insert "\\label{" string "} \\index{\\nameref{" string "}}"))
|