@@ -9351,48 +9351,36 @@ spaces, or alternatively a TAB should be used as the separator."
9351
9351
(goto-char begin)
9352
9352
(markdown-table-align)))
9353
9353
9354
- (defun markdown-insert-table ()
9355
- "Insert a new table."
9354
+ (defun markdown-insert-table (&optional rows columns align)
9355
+ "Insert an empty pipe table.
9356
+ Optional arguments ROWS, COLUMNS, and ALIGN specify number of
9357
+ rows and columns and the column alignment."
9356
9358
(interactive)
9357
- (let ((table-column (string-to-number (read-string "column size: ")))
9358
- (table-row (string-to-number (read-string "row size: ")))
9359
- (align-type (read-string "align type (left, right, center (default)): "))
9360
- (content "")
9361
- (align-counter 1)
9362
- (align "|")
9363
- (header-counter 1)
9364
- (header "|")
9365
- (row-counter 1)
9366
- (column-counter 1))
9367
-
9368
- (cond ((equal align-type "left") (setq content ":---"))
9369
- ((equal align-type "right") (setq content "---:"))
9370
- ((equal align-type "center") (setq content "---"))
9371
- (t (setq content "---")))
9372
-
9373
- (while (<= align-counter table-column)
9374
- (setq align (concat align content "|"))
9375
- (setq align-counter (1+ align-counter)))
9376
- (setq align (concat align "\n"))
9377
-
9378
- (while (<= header-counter table-column)
9379
- (setq header (concat header (read-string (concat "header " (number-to-string header-counter) ": ")) "|"))
9380
- (setq header-counter (1+ header-counter)))
9381
- (setq header (concat header "\n"))
9382
-
9383
- (insert header)
9384
- (insert align)
9385
-
9386
- (while (<= row-counter table-row)
9387
- (setq column-counter 1)
9388
- (while (<= column-counter (1+ table-column))
9389
- (insert "|")
9390
- (setq column-counter (1+ column-counter)))
9391
- (if (< row-counter table-row)
9392
- (insert "\n"))
9393
- (setq row-counter (1+ row-counter)))
9394
- (markdown-table-align)
9395
- ))
9359
+ (let* ((rows (or rows (string-to-number (read-string "Row size: "))))
9360
+ (columns (or columns (string-to-number (read-string "Column size: "))))
9361
+ (align (or align (read-string "Alignment ([l]eft, [r]ight, [c]enter): ")))
9362
+ (align (cond ((equal align "l") ":--")
9363
+ ((equal align "r") "--:")
9364
+ ((equal align "c") ":-:")
9365
+ (t "---")))
9366
+ (pos (point))
9367
+ (indent (make-string (current-column) ?\ ))
9368
+ (line (concat
9369
+ (apply 'concat indent "|"
9370
+ (make-list columns " |")) "\n"))
9371
+ (hline (apply 'concat indent "|"
9372
+ (make-list columns (concat align "|")))))
9373
+ (if (string-match
9374
+ "^[ \t]*$" (buffer-substring-no-properties
9375
+ (point-at-bol) (point)))
9376
+ (beginning-of-line 1)
9377
+ (newline))
9378
+ (dotimes (_ rows) (insert line))
9379
+ (goto-char pos)
9380
+ (if (> rows 1)
9381
+ (progn
9382
+ (end-of-line 1) (insert (concat "\n" hline)) (goto-char pos)))
9383
+ (markdown-table-align)))
9396
9384
9397
9385
9398
9386
;;; ElDoc Support
0 commit comments