Skip to content

Commit

Permalink
Document the pgmacs-table-list-buttons and pgmacs-row-list-buttons va…
Browse files Browse the repository at this point in the history
…riables
  • Loading branch information
emarsden committed Jan 2, 2025
1 parent e9ce711 commit 8cb4354
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
35 changes: 33 additions & 2 deletions doc/src/row-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,22 @@ The following keys are bound when the point is located in the row-list table:
| <kbd>S</kbd> | Sort the table by the current column. |
| <kbd>{</kbd> | Make the current column narrower. |
| <kbd>}</kbd> | Make the current column wider. |
| <kbd>=</kbd> | Adjust all column widths to the narrowest size possible. |
| <kbd>T</kbd> | Jump to the main PGmacs table-list buffer. |
| <kbd>q</kbd> | Bury the current buffer. |


The hook functions on `pgmacs-row-list-hook` are run when a row-list buffer is opened. They are run
just before control is returned to the user, in a buffer with all data inserted.
Any functions on `pgmacs-row-list-hook` are run when a row-list buffer is opened. They are run just
before control is returned to the user, in a buffer with all data inserted. For example, if you
would like all column widths to be adjusted to the narrowest size possible given the data displayed
in the table (obtaining the same result as if you pressed <kbd>=</kbd> each time you open a row-list
buffer), you can include the following in your Emacs initialization file:

```lisp
(eval-after-load 'pgmacs
(add-hook 'pgmacs-row-list-hook #'pgmacs--shrink-columns))
```



## Run a shell command or an external application on cell value
Expand Down Expand Up @@ -147,3 +157,24 @@ operation, combined with the WHERE filtering described above.
src="https://github.com/emarsden/emarsden.github.io/raw/refs/heads/main/assets/pgmacs-where-filter-multidelete.mp4">
</video>




## Custom buttons in a row-list buffer

The list of buttons displayed above the rows of a table (“count rows”, “export to CSV” and so on)
is user-customizable via the variable `pgmacs-row-list-buttons`. To add a new button to this list,
add code such as the following to your Emacs initialization file:

```lisp
(require 'pgmacs)
(add-to-list 'pgmacs-row-list-buttons
(pgmacs-shortcut-button
:label "The displayed label"
:action #'my/function-of-zero-arguments
:help-echo "Help text echoed to minibuffer"))
```

If you prefer the button to be added to the end of the list, add a last argument of `t` to the
`add-to-list` invocation.
21 changes: 21 additions & 0 deletions doc/src/table-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,24 @@ concerning the PostgreSQL backend that you are connected to, including the list
extensions.

![Screenshot backend information](img/backend-information-buffer.png)



## Custom buttons in the table-list buffer

The list of buttons displayed above the list of tables (“Display tables", “More backend information” and so on)
is user-customizable via the variable `pgmacs-table-list-buttons`. To add a new button to this list,
add code such as the following to your Emacs initialization file:

```lisp
(require 'pgmacs)
(add-to-list 'pgmacs-table-list-buttons
(pgmacs-shortcut-button
:label "The displayed label"
:action #'my/function-of-zero-arguments
:help-echo "Help text echoed to minibuffer"))
```

If you prefer the button to be added to the end of the list, add a last argument of `t` to the
`add-to-list` invocation.
4 changes: 2 additions & 2 deletions pgmacs.el
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ e.g. 'UTC' or 'Europe/Berlin'. Nil for local OS timezone."
(pgmacs--display-table pgmacs--table))
:help-echo "Add an SQL comment to the table")))


(defun pgmacs--widget-setup ()
"Set up the appearance of widgets used in PGmacs.
Uses customizations implemented in Emacs' customize support."
Expand Down Expand Up @@ -2444,7 +2443,8 @@ Runs functions on `pgmacs-row-list-hook'."
(insert " ")
(when (> (current-column) (min (window-width) 90))
(insert "\n")))
(insert "\n\n")
(unless (bolp)
(insert "\n"))
;; Make it visually clear to the user that a WHERE filter is active
(when where-filter
(insert (propertize "WHERE filter" 'face 'bold))
Expand Down

0 comments on commit 8cb4354

Please sign in to comment.