Browse Source

Handle header line scaling for `org-table-electric-header-mode'

* lisp/org-table.el (org-table-temp-header-remapping): New variable.
(org-table-set-header-line-format): Scale the header line properly.
(org-table-electric-header-mode): Don't run outside `org-mode'.
Bastien 1 year ago
parent
commit
57721a1cb0
1 changed files with 18 additions and 13 deletions
  1. 18 13
      lisp/org-table.el

+ 18 - 13
lisp/org-table.el

@@ -450,24 +450,26 @@ prevents it from hanging Emacs."
 
 ;;; Org table electric header minor mode
 (defvar org-table-temp-header-line nil)
+(defvar org-table-temp-header-remapping 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."
+  (ignore-errors (require 'face-remap))
+  (face-remap-remove-relative org-table-temp-header-remapping)
+  (setq org-table-temp-header-remapping
+	(face-remap-add-relative 'header-line '(:inherit default)))
   (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)))))
+      (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)
@@ -477,10 +479,13 @@ existing value of `header-line-format' we might want to restore."
   :global nil
   :variable org-table-electric-header-mode
   :group 'org-table
+  (unless (eq major-mode 'org-mode)
+    (user-error "Cannot turn org table electric mode outside org-mode buffers"))
   (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)
+    (face-remap-remove-relative org-table-temp-header-remapping)
     (setq header-line-format org-table-temp-header-line)))