-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add markdown-insert-table
#369
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -579,6 +579,14 @@ can obtain a list of all keybindings by pressing <kbd>C-c C-h</kbd>. | |
correctly when calculating column widths, however, columns | ||
containing hidden markup may not always be aligned properly. | ||
|
||
<kbd>C-c C-t</kbd> (`markdown-insert-table`) is a general command for | ||
inserting new table. Specify table size, table align and table header in | ||
minibuffer when executing `markdown-insert-table`. | ||
- Specify row size. | ||
- Specify column size. | ||
- Specify table align: right, left or center. | ||
- Specify header contetnts. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spelling: "contents" |
||
|
||
* Viewing Modes: | ||
|
||
Read-only viewing modes, `markdown-view-mode` and `gfm-view-mode` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5404,6 +5404,7 @@ Assumes match data is available for `markdown-regex-italic'." | |
(define-key map (kbd "C-c C-t s") 'markdown-insert-header-setext-2) | ||
(define-key map (kbd "C-c C-t t") 'markdown-insert-header-setext-1) | ||
(define-key map (kbd "C-c C-i") 'markdown-insert-image) | ||
(define-key map (kbd "C-c C-t") 'markdown-insert-table) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C-c C-t is actually a prefix to heading (titling) commands (which can be seen a couple of lines above). We'd need to find a new keybinding. Perhaps C-c C-s t, which would be under |
||
(define-key map (kbd "C-c C-x m") 'markdown-insert-list-item) ;; C-c C-j | ||
(define-key map (kbd "C-c C-x C-x") 'markdown-toggle-gfm-checkbox) ;; C-c C-d | ||
(define-key map (kbd "C-c -") 'markdown-insert-hr) | ||
|
@@ -5528,6 +5529,8 @@ See also `markdown-mode-map'.") | |
:enable (markdown-table-at-point-p)] | ||
["Insert Column" markdown-table-insert-column | ||
:enable (markdown-table-at-point-p)] | ||
["Insert Table" markdown-insert-table | ||
:enable (markdown-table-at-point-p)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the predicate should be |
||
"--" | ||
["Convert Region to Table" markdown-table-convert-region] | ||
["Sort Table Lines" markdown-table-sort-lines | ||
|
@@ -9335,6 +9338,49 @@ spaces, or alternatively a TAB should be used as the separator." | |
(goto-char begin) | ||
(markdown-table-align))) | ||
|
||
(defun markdown-insert-table () | ||
"Insert a new table." | ||
(interactive) | ||
(let ((table-column (string-to-number (read-string "column size: "))) | ||
(table-row (string-to-number (read-string "row size: "))) | ||
(align-type (read-string "align type: ")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a helpful tip in the prompt such as "(left, right, center (default)):" |
||
(content "") | ||
(align-counter 1) | ||
(align "|") | ||
(header-counter 1) | ||
(header "|") | ||
(row-counter 1) | ||
(column-counter 1)) | ||
|
||
(cond ((equal align-type "left") (setq content ":---")) | ||
((equal align-type "right") (setq content "---:")) | ||
((equal align-type "center") (setq content "---")) | ||
(t (user-error "Speficy align-type: left, right or center"))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps centered should be the pass-through default? |
||
|
||
(while (<= align-counter table-column) | ||
(setq align (concat align content "|")) | ||
(setq align-counter (1+ align-counter))) | ||
(setq align (concat align "\n")) | ||
|
||
(while (<= header-counter table-column) | ||
(setq header (concat header (read-string (concat "header " (number-to-string header-counter) ": ")) "|")) | ||
(setq header-counter (1+ header-counter))) | ||
(setq header (concat header "\n")) | ||
|
||
(insert header) | ||
(insert align) | ||
|
||
(while (<= row-counter table-row) | ||
(setq column-counter 1) | ||
(while (<= column-counter (1+ table-column)) | ||
(insert "|") | ||
(setq column-counter (1+ column-counter))) | ||
(if (< row-counter table-row) | ||
(insert "\n")) | ||
(setq row-counter (1+ row-counter))) | ||
(markdown-table-align) | ||
)) | ||
|
||
|
||
;;; ElDoc Support | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating the docs. Please update this line with the new keybinding (see below).