Generating a markdown table with key bindings in Spacemacs - emacs

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.)

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.

Related

Weird ghost records in PostgreSQL - what are they?

I have a very weird issue on our postgresql DB. I have a table called "statement" which has some strange records in it.
Using the command line console psql, I query select * from customer.statement where type in ('QUOTE'); and get 12 rows back. 7 rows look normal, 5 are missing all data except a single column which is a nullable column but seems to hold real values entered by the user. psql tells me that 7 rows were returned even though there are 12. Most of the other columns are not nullable. The weird records look like this:
select * from customer.statement where type = 'QUOTE';
id | issuer_id | recipient_id | recipient_name | recipient_reference | source_statement_id | catalogue_id | reference | issue_date | due_date | description | total | currency | type | tax_level | rounding_mode | status | recall_requested | time_created | time_updated | time_paid
------------------+------------------+------------------+----------------+---------------------+---------------------+--------------+-----------+------------+------------+------------------------------------------------------------------+-----------+----------+-------+-----------+---------------+-----------+------------------+----------------------------+----------------------------+-----------
... 7 valid records removed ...
| | | | | | | | | | Build bulkheads and sheet with plasterboard. +| | | | | | | | | |
| | | | | | | | | | Patch all patches. +| | | | | | | | | |
| | | | | | | | | | Set and sand all joints ready for painting. +| | | | | | | | | |
| | | | | | | | | | Use wall angle on bulkhead in main bedroom. +| | | | | | | | | |
| | | | | | | | | | Build nib and sheet and set in entrance | | | | | | | | | |
(7 rows)
If I run the same query using pgAdmin, I don't see those weird records.
Anyone know what these are?
The plus sign before the separator (+|) indicates a newline character in the displayed string value in psql. So no additional rows, just the same row continued with line breaks. The final line of output in your quote confirms as much: (7 rows).
In pgAdmin you don't see the extra lines as long as you don't increase the height of the field (or copy / paste the content somewhere), but there are multiple lines as well.
Try in psql and in pgAdmin:
test=# SELECT E'This\nis\na\ntest.' AS multi_line, 'foo' AS single_line;
multi_line | single_line
--------------+-------------
This +| foo
is +|
a +|
test. |
(1 row)
The manual about psql:
linestyle
Sets the border line drawing style to one of ascii, old-ascii, or unicode. [...] The default setting is ascii. [...]
ascii style uses plain ASCII characters. Newlines in data are shown using a + symbol in the right-hand margin. [...]

In emacs org mode, is there a formula I can use to count the number of cells?

I'm new to emacs (spacemacs, actually) and org-mode. I'd like to have a final line in my table that shows how many rows there are in the table. Is there a formula function for that?
This formula should work: vlen(#I..#II).
Example:
| Title |
|-------|
| one |
| two |
| three |
| four |
|-------|
| 4 |
#+Tblfm: #6$1=vlen(#I..#II)
the example above is specified as "#6" which requires you to know hte sum in advance. The following seems to work:
| Title |
|-------|
| one |
| two |
| three |
| four |
|-------|
| 4 |
#+Tblfm: #II$1=vlen(#I..#II)

Numbering the rows in reverse order in an Emacs Org Mode table

I'd like to do something like this:
How to achieve a row index column in Emacs Org Mode using a Calc column rule
but I'd like the rows to be numbered in reverse order. I suspect this should be very easy, and should have something to do with #>, but e.g. $1=#>-## doesn't work.
You can try this example
| row | data |
|-----+------|
| 8 | |
| 7 | |
|-----+------|
| 6 | |
| 5 | |
| 4 | |
| 3 | 5123 |
| 2 | |
| 1 | 4234 |
#+TBLFM: $1='(- (length org-table-dlines) ##)

How to configure emacs to open a wide compilation window?

Usually I edit source code in emacs with two (emacs-)windows side-by-side -- The second
windows opened via 'C-x 3. Like this:
+------------+-------------+
| | |
| src1 | src2 |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
+------------+-------------+
| mini-buffer |
+------------+-------------+
When I now start compile, eg with F9, the new *compilation* buffer replaces one of my src-buffers.
Instead I would like the *compilation* buffer to open on-top of the mini-buffer, if it is not visible already (if it is, use it, of course).
+------------+-------------+
| | |
| src1 | src2 |
| | |
| | |
| | |
| | |
+------------+-------------+
| |
| *compilation* |
| |
+------------+-------------+
| mini-buffer |
+------------+-------------+
The *compilation*-buffer should have a height of about 30% of the while window or 6-10 lines.
How to accomplish that?
One way to achieve this would be to use popwin.el. I've never used it but it seems pretty customizable and the default config includes *compilation* already.

Using named fields to determine ranges with vsum in Emacs org-table-mode, impossible?

I have been trying to simplify a semi-complex table that I have by adding named fields, without a problem, until I get to the vsum operator. I had the formula set to $M=vsum($3..#-4) which works, however I am continuously having to add and remove items from those fields, which changes the column numbering. This results in me having to change the field specifications of the vsum range after every update/change. I thus tried naming the top field and bottom fields with the thought of supplying the named variables to vsum, giving me a table similar to the following:
| / | <> | <> |
|---+--------+---------|
| | Title1 | Title 2 |
|---+--------+---------|
| _ | | START |
| | name | 1000 |
| | name | 3456 |
| | name | 123 |
| ^ | | END |
|---+--------+---------|
| _ | | MT |
| # | Total | #ERROR |
| # | | |
|---+--------+---------|
#+TBLFM: $MT=vsum($START..$END)
This is the debug formula output from the above table:
Substitution history of formula
Orig: vsum($START..$END)
$xyz-> vsum((1000)..(123))
#r$c-> vsum((1000)..(123))
$1-> vsum((1000)..(123))
-----------^
Error: Expected `)'
I have tried embrasing the named field variables in parenthesis, and several other ways but have thus far not been able to get this to work. I am hoping I am just missing something and being blind, but perhaps this is not possible to do?
I have also tried the sum-up function with no success as well. Thank you in advance for your assistance.
The following solution works by using #II and #III to refer to all entries between the second and third hline.
| / | <> | <> |
|---+--------+---------|
| | Title1 | Title 2 |
|---+--------+---------|
| | name | 1000 |
| | name | 3456 |
| | name | 123 |
|---+--------+---------|
| _ | | MT |
| # | Total | 4579 |
| # | | |
|---+--------+---------|
#+TBLFM: $MT=vsum(#II..#III)
Documentation: http://orgmode.org/manual/References.html#References