Git Product home page Git Product logo

org-table-sticky-header's Introduction

org-table-sticky-header-mode

https://melpa.org/packages/org-table-sticky-header-badge.svg

A minor mode to show the sticky header for org-mode tables.

Overview

Similar to semantic-stickyfunc-mode, this package uses the header line to show the table header when it is out of sight.

Usage

Recommend: install from melpa.

To install manually:

(add-to-list 'load-path "/path/to/org-table-sticky-header.el")

M-x org-table-sticky-header-mode to enable the minor mode in an org-mode buffer.

To automatically enable the minor mode in all org-mode buffers, use

(add-hook 'org-mode-hook 'org-table-sticky-header-mode)

Demo

./screenshots/demo.gif

org-table-sticky-header's People

Contributors

alphapapa avatar cute-jumper avatar stardiviner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

org-table-sticky-header's Issues

Added support for moving, inserting and deleting columns

Hello,
I added following functionality to change the sticky line if moving, inserting or deleting columns.
Please feel free to use the following code snippet.
With kind regards,
Stefan

modified   lisp/org-table-sticky-header.el
@@ -79,6 +79,7 @@
 ;;; Code:
 
 (require 'org)
+(require 'org-table)
 
 (defvar org-table-sticky-header--last-win-start -1)
 (defvar org-table-sticky-header--old-header-line-format nil)
@@ -171,6 +172,14 @@ org-table-sticky-header--scroll-function
     (save-match-data
       (org-table-sticky-header--fetch-header))))
 
+(defun org-table-sticky-header--insert-delete-column ()
+  (save-match-data
+    (org-table-sticky-header--fetch-header)))
+
+(defun org-table-sticky-header--table-move-column (&optional left)
+  (save-match-data
+    (org-table-sticky-header--fetch-header)))
+
 ;;;###autoload
 (define-minor-mode org-table-sticky-header-mode
   "Sticky header for org-mode tables."
@@ -181,10 +190,16 @@ org-table-sticky-header-mode
             (setq org-table-sticky-header--old-header-line-format header-line-format)
             (add-hook 'window-scroll-functions
                       'org-table-sticky-header--scroll-function 'append 'local)
+            (advice-add 'org-table-delete-column :after #'org-table-sticky-header--insert-delete-column)
+            (advice-add 'org-table-insert-column :after #'org-table-sticky-header--insert-delete-column)
+            (advice-add 'org-table-move-column :after #'org-table-sticky-header--table-move-column)
             (setq org-table-sticky-header--last-win-start (window-start))
             (org-table-sticky-header--fetch-header))
         (setq org-table-sticky-header-mode nil)
         (error "Not in `org-mode'"))
+    (advice-remove 'org-table-delete-column #'org-table-sticky-header--insert-delete-column)
+    (advice-remove 'org-table-insert-column #'org-table-sticky-header--insert-delete-column)
+    (advice-remove 'org-table-move-column #'org-table-sticky-header--table-move-column)
     (remove-hook 'window-scroll-functions 'org-table-sticky-header--scroll-function 'local)
     (setq header-line-format org-table-sticky-header--old-header-line-format)))
 

Save match data is necessary

Hello,
I'm using your package since since several weeks, it's nice. Today I came about a problem
when using query-replace to change the content of an org-table; it throw a exception.
After digging it down I saw, that the problem occurs if the screen scrolls vertically. The match
data where lost. So it is necessary to save the match data, here is my proposal of change:

@@ -168,7 +168,8 @@ org-table-sticky-header--fetch-header
 (defun org-table-sticky-header--scroll-function (win start-pos)
   (unless (= org-table-sticky-header--last-win-start start-pos)
     (setq org-table-sticky-header--last-win-start start-pos)
-    (org-table-sticky-header--fetch-header)))
+    (save-match-data
+      (org-table-sticky-header--fetch-header))))
 
 ;;;###autoload
 (define-minor-mode org-table-sticky-header-mode

With kind regards,
Stefan

Indentation of table not same as header

Great package. I deal with long tables a lot. This is a bit of a nit, but I always use org-indent-mode, so my tables are typically indented depending on where they are in the outline. Looks like the sticky header is always flush against the left side, so it is out of alignment with the table body. Would be nice to have it follow the body indent if possible.

Allow column alignment before headerline

Great package!!!

One thing missing: In my tables I have column width line mostly before headerline as:

| <6> | |
| Col-1 | Col-2 |
|-
| Data | |

In this case the headerline is not correctly recognized. Org-mode also allows a
table to begin with a line additionally.

With kind regards,
Stefan

Difference to "org-table-electric-header-mode"

Hi,

This functionality is now part of the default setup using M-x org-table-electric-header-mode which then got renamed to M-x org-table-header-line-mode.

Source: https://mastodon.etalab.gouv.fr/@bzg/103578639383778830

You should add a prominent statement in the README and explain the differences between them both so that users are able to decide which way to go.

Bastien wrote that org-table-header-line-mode has less code and does not use any advice. So I would interpret this as an argument to switch to org-table-header-line-mode and stop using your code. Is this true?

header does not scroll right

If I have a very wide table - columns are A, B, C, D ...... Z.

Without scrolling right, I can see only up to columns A .. G. After scrolling down, such that the overlay header line is activated using org-table-sticky-header, if I scroll right to see columns H, I, ...., the header line does not scroll right.

Incompatibility with line-numbers-mode (Emacs 26)

Using Emacs 26 with line-numbers-mode the header alignment is lost.

I guess this did not happen with linum-mode because it used the display margin while line-numbers-mode uses something entirely different.

image

Narrowed head line

Narrowed columns are respected. However, if the head-line is narrowed the layout is wrong.

 * Table
 
 | Byte | Bit | Bit-Offset | Type  | Description |
 |      |     |  <4>       |       |             |
 |------+-----+------------+-------+-------------|
 |    0 |   0 |          0 | DWORD |             |
 |    6 |   0 |         48 | DWORD |             |
 |   10 |   0 |         80 | BYTE  |             |
 |   11 |   0 |         88 | BOOL  |             |
 |   11 |   1 |         89 | BOOL  |             |
 |   11 |   2 |         90 | BOOL  |             |
 |   11 |   3 |         91 | BOOL  |             |
 |   14 |   0 |         96 | DWORD |             |
 |   16 |   0 |        128 | BYTE  |             |
 |   17 |   0 |        136 | BOOL  |             |
 |   17 |   1 |        137 | BOOL  |             |
 |   17 |   2 |        138 | BOOL  |             |
 |   17 |   3 |        139 | BOOL  |             |

Add support for Org 9.0

Thanks for sharing this. This will be very handy when dealing with long tables. Does it support org 9.0?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.