diff options
author | Bastien <bzg@gnu.org> | 2020-01-29 15:17:32 +0100 |
---|---|---|
committer | Bastien <bzg@gnu.org> | 2020-01-29 15:17:32 +0100 |
commit | b476ffd266744748dc5e86552459ab5c7909e23c (patch) | |
tree | f79766009f7a0c9be53f4b4c39e8c143b08c3337 | |
parent | 0f86a14af3a42772289dcebfca3aefdf808e2c89 (diff) | |
download | org-mode-b476ffd266744748dc5e86552459ab5c7909e23c.tar.gz |
Implement the `org-table-electric-header-mode' minor mode
* lisp/org-table.el (org-table-electric-header-p): New option.
(org-table-temp-header-line, org-table-electric-header-mode): New
variables.
(org-table-set-header-line-format)
(org-table-electric-header-mode): New minor mode to display the
table's current first row as the header line when this first row
is not visible anymore.
* doc/org-manual.org (Miscellaneous): Document
`org-table-electric-header-mode'.
-rw-r--r-- | doc/org-manual.org | 9 | ||||
-rw-r--r-- | etc/ORG-NEWS | 7 | ||||
-rw-r--r-- | lisp/org-table.el | 42 |
3 files changed, 58 insertions, 0 deletions
diff --git a/doc/org-manual.org b/doc/org-manual.org index 6708aea..b7eb234 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -1638,6 +1638,15 @@ you, configure the option ~org-table-auto-blank-field~. the same as the format used by Orgtbl radio tables, see [[*Translator functions]], for a detailed description. +- {{{kbd(M-x org-table-electric-header-mode)}}} :: + + #+findex: org-table-electric-header-mode + #+vindex: org-table-electric-header-p + Turn on the display of the first data row of the table at point in + the window header line when this first row is not visible anymore in + the buffer. You can activate this minor mode by default by setting + the option ~org-table-electric-header-p~ to ~t~. + ** Column Width and Alignment :PROPERTIES: :DESCRIPTION: Overrule the automatic settings. diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 62e1030..ced65db 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -13,6 +13,13 @@ Please send Org bug reports to mailto:emacs-orgmode@gnu.org. * Version 9.4 (not yet released) ** New features +*** New minor mode ~org-table-electric-header-mode~ + +Turn on the display of the first data row of the table at point in the +window header line when this first row is not visible anymore in the +buffer. You can activate this minor mode by default by setting the +option ~org-table-electric-header-p~ to ~t~. + *** Property drawers before first headline, outline level 0 Property drawers will now work before first headline and Org mode is diff --git a/lisp/org-table.el b/lisp/org-table.el index cc49650..67e7140 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -164,6 +164,12 @@ table, obtained by prompting the user." :tag "Org Table Settings" :group 'org-table) +(defcustom org-table-electric-header-p nil + "Activate `org-table-electric-header-mode' by default?" + :type 'boolean + :package-version "9.4" + :group 'org-table) + (defcustom org-table-default-size "5x2" "The default size for newly created tables, Columns x Rows." :group 'org-table-settings @@ -442,6 +448,42 @@ prevents it from hanging Emacs." :package-version '(Org . "8.3")) +;;; Org table electric header minor mode +(defvar org-table-temp-header-line nil) +(defun org-table-set-header-line-format () + "Set the header of table at point as the `header-line-format'. +Assume `org-table-temp-header-line' already stores the previously +existing value of `header-line-format' we might want to restore." + (if (org-at-table-p) + (run-with-timer + 0 nil + (lambda () + (let* ((beg (org-table-begin)) + (tbeg (if (save-excursion (goto-char beg) (org-at-table-hline-p)) + (save-excursion (goto-char beg) (move-beginning-of-line 2) (point)) + beg))) + (if (< tbeg (save-excursion (move-to-window-line 0) (point))) + (setq header-line-format + (concat (propertize " " 'display '(space :width left-fringe)) + (buffer-substring + tbeg (+ tbeg (- (point-at-eol) (point-at-bol)))))) + (setq header-line-format org-table-temp-header-line))))) + (setq header-line-format org-table-temp-header-line))) + +(defvar org-table-electric-header-mode nil) +(define-minor-mode org-table-electric-header-mode + "Display the first row of the table at point in the header line." + :init-value org-table-electric-header-p + :global nil + :variable org-table-electric-header-mode + :group 'org-table + (if org-table-electric-header-mode + (progn (setq org-table-temp-header-line header-line-format) + (add-hook 'post-command-hook 'org-table-set-header-line-format)) + (remove-hook 'post-command-hook 'org-table-set-header-line-format) + (setq header-line-format org-table-temp-header-line))) + + ;;; Regexps Constants (defconst org-table-any-line-regexp "^[ \t]*\\(|\\|\\+-[-+]\\)" |