Skip to content

shankar2k/company-org-table

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Company Org Table

Summary

This package provides autocompletion functionality in Org tables using company. The completion candidates are, by default, the contents of other cells in the same table column, similar to spreadsheet programs like Excel, Libreoffice and Google Sheets. The completion candidates can be configured to be dynamically generated based on the table name and column header.

Installation

This package can be cloned from GitHub via the following command:

git clone https://github.com/shankar2k/company-org-table.git

To start using it, place it somewhere in your Emacs load-path and add it as a company backend with following commands:

(require 'company-org-table)
(add-to-list 'company-backends 'company-org-table)

in your .emacs.d/init.el file.

If you use use-package, you can configure this as follows:

(setq company-org-table-load-path "<path to company-org-table dir>")
(use-package company-org-table
  :load-path company-org-table-load-path
  :ensure nil
  :config
  (add-to-list 'company-backends 'company-org-table))

Usage

This package defines the following commands:

company-org-table: company-mode backend for Org tables that mimics the auto-complete behavior of spreadsheet programs like Microsoft Excel, LibreOffice, and Google Sheets.

By default, the completion candidates are contents of table cells in the current column excluding the current cell. The following custom variables can be changed to enable additional functionality:

company-org-table-section
which section of table column to use for completion candidates
company-org-table-alist
map between table name/header information and candidate list generators

company-org-table-section can be set to exclude, above, or below. With exclude all columns cells except the cell at point are used as completion candidates. With above and below, all column cells above or below point, respectively, are used as completion candidates

company-org-table-alist is an alist that maps table name and header information to candidate list generators.

Each key is a two-element, where the first element is a regexp matching an Org table name (i.e., what follows “#+TBLNAME:”), and the second element is a regexp matching a column header.

Each value is a function with no arguments that returns a list of completion candidate strings.

Example

Suppose that you have the configuration below to help you keep track of language pack purchases from your userbase:

(setq user-list
      '("Alice" "Bob" "Carol" "Dave" "Eve" "Frank" "Grace" "Heidi" "Ivan"
        "Judy" "Ken" "Lisa" "Mike" "Nancy" "Olivia" "Pat" "Quentin" "Rupert"
        "Sybil" "Ted" "Ursula" "Victor" "Wendy" "Xavier" "Yusuf" "Zoe"))

(add-to-list 'company-org-table-alist
             (cons (list "user-purchases" "User") (lambda () user-list)))

(add-to-list 'company-org-table-alist
             (cons (list "user-purchases" "Language")
                   (lambda () (mapcar #'car language-info-alist))))

The following example illustrates the autocompletion provided by this package.

example.gif

Credits

This package would not have been possible without the following guides for writing company backends: Company Github repository and the Sixty North blog.

About

Completion backend for Org table cells

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published