-2

What is the best way to generate a markdown table with key bindings in Spacemacs (evil mode)?

Update: To clarify, this question is not about editing markdown, but automatically generating the table content for a large number of key bindings.

This could be an elisp function iterating through the possible single keystrokes (letters, numbers, punctuation, and possibly space and some control characters, with and without modifier keys), seeing what function each key is bound to (if any), and getting the description of the function.

You can do that manually using SPC h d k, but it would be handy to generate a table, given the number of possible key bindings and the way they can depend on the buffer mode and the state.

The table should show single keystrokes (letters, numbers, punctuation) with and without modifiers, the function bound to them, and the first line of the function description.

The result should look something like this:

https://github.com/cjolowicz/howto/blob/master/spacemacs.md

| Key    | Mnemonic     | Description                                                     | Function                   |
| ------ | --------     | --------------------------------------------------------------- | ------------------------   |
| a      | *append*     | Switch to Insert state just after point.                        | `evil-append`              |
| b      | *backward*   | Move the cursor to the beginning of the COUNT-th previous word. | `evil-backward-word-begin` |
| c      | *change*     | Change text from BEG to END with TYPE.                          | `evil-change`              |
| d      | *delete*     | Delete text from BEG to END with TYPE.                          | `evil-delete`              |
| e      | *end*        | Move the cursor to the end of the COUNT-th next word.           | `evil-forward-word-end`    |
| f      | *find*       | Move to the next COUNT’th occurrence of CHAR.                   | `evil-find-char`           |
| g      | *goto*       | (prefix)                                                        |                            |
| h      |              | Move cursor to the left by COUNT characters.                    | `evil-backward-char`       |
| i      | *insert*     | Switch to Insert state just before point.                       | `evil-insert`              |
| j      |              | Move the cursor COUNT lines down.                               | `evil-next-line`           |
| k      |              | Move the cursor COUNT lines up.                                 | `evil-previous-line`       |
| l      |              | Move cursor to the right by COUNT characters.                   | `evil-forward-char`        |
| m      | *mark*       | Set the marker denoted by CHAR to position POS.                 | `evil-set-marker`          |
| n      | *next*       | Goes to the next occurrence.                                    | `evil-ex-search-next`      |
| o      | *open*       | Insert a new line below point and switch to Insert state.       | `evil-open-below`          |
| p      | *paste*      | Disable paste transient state if there is more than 1 cursor.   | `evil-mc-paste-after`      |
| q      |              | Record a keyboard macro into REGISTER.                          | `evil-record-macro`        |
| r      | *replace*    | Replace text from BEG to END with CHAR.                         | `evil-replace`             |
| s      | *substitute* | Change a character.                                             | `evil-substitute`          |
| t      | *to*         | Move before the next COUNT’th occurrence of CHAR.               | `evil-find-char-to`        |
| u      | *undo*       | Undo changes.                                                   | `evil-tree-undo`           |
| v      | *visual*     | Characterwise selection.                                        | `evil-visual-char`         |
| w      | *word*       | Move the cursor to the beginning of the COUNT-th next word.     | `evil-forward-word-begin`  |
| x      | *cross*      | Delete next character.                                          | `evil-delete-char`         |
| y      | *yank*       | Saves the characters in motion into the kill-ring.              | `evil-yank`                |
| z      | *scroll*     | (prefix)                                                        |                            |

(The Mnemonic column would of course be handcrafted.)

Community
  • 1
  • 1
Claudio
  • 3,089
  • 2
  • 18
  • 22
  • 1
    you could iterate over `current-active-maps` and do something like `(insert (substitute-command-keys (concat "\\{" map-name "}")))` – Rorschach Apr 24 '19 at 17:00

1 Answers1

0

The orgtbl-mode minor mode that comes with Org (and therefore Emacs itself) should be able to help here. Activate it, then use Tab and Ret to navigate from cell to cell, letting orgtbl create and balance cells as you go. (Balancing happens when you navigate to a new cell, e.g. with Tab.)

You'll have to start the table yourself, e.g. with something like

| Key | Mnemonic | Description | Function |
|-

but from there orgtbl can take over. You can also use things like org-table-insert-column and org-table-move-row-down to make other kinds of tabular changes.

I'm not entirely sure how nicely this will play with evil-mode or what bindings it will use come out of the box, but it's worth a try.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • Thanks for your answer. Actually, I'm looking for a way to generate the table _content_ not just the table structure, which probably requires some elisp code, or a very nifty use of keyboard macros. That said, `orgtbl` is great and I used it to create the example table above :-) – Claudio Apr 24 '19 at 13:17
  • @Claudio, oh. What's the source data for the content? Are you going to provide a list of bindings somehow? Or a list of elisp functions? – ChrisGPT was on strike Apr 24 '19 at 14:16
  • Just iterating through the possible single keystrokes (letters, numbers, punctuation, and possibly space and some control characters), seeing what function they are bound to, and getting the description of the function. I can do that manually, but it would be handy to generate a table like this, especially since the bindings also depend on the mode and state we're in. – Claudio Apr 24 '19 at 15:52
  • @Claudio, so you're trying to create something like `describe-mode` (bound to `C-h m` by default)? – ChrisGPT was on strike Apr 24 '19 at 16:50