fix org table colored cells

This commit is contained in:
2026-01-25 21:11:30 +01:00
parent a22d7a3954
commit f99f844e25

View File

@@ -392,10 +392,10 @@ then return the table element otherwise return nil.
`org-at-table-p' is nil if cursor on #+TBLFM"
(let ((element (org-element-at-point))) ;; get org element
(while (and element (not (eq (car element) 'table))) ;; check if it is table
(setq element (plist-get (cadr element) :parent))) ;; if not check if parent element is table
(setq element (org-element-parent element))) ;; if not check if parent element is table
(cond
((equal (car element) 'table) ;; only if table found
(cadr element))))) ;; return element
element)))) ;; return element
(defun my-org-table-range-to-list (desc &optional val)
"
@@ -456,7 +456,8 @@ SEQ is a list of cell name and color name pairs."
;;(fg (if (>= (apply #'my-color-contrast color-rgb) 4.5) "gray10" 'default))
(beg (progn (org-table-goto-field cell) (backward-char) (point))) ;; beginning of the cell
;;(end (progn (org-table-end-of-field 1) (forward-char) (point))) ;; for left aligned cells end is end of content not of cell
(end (1- (plist-get (cadr (org-element-context)) :end)))
;;(end (1- (plist-get (cadr (org-element-context)) :end)))
(end (1- (org-element-end (org-element-context))))
)
(ov beg end 'face (list :background bg
:foreground fg))
@@ -485,11 +486,12 @@ Example usage to add a (normal, global) hook:
Example usage to add a local hook:
(add-hook 'org-ctrl-c-ctrl-c-hook 'my-org-table-cell-color-var nil t)"
(let* ((table (my-org-table-get)) ;; get table element
(table-name (plist-get table :name))) ;; get table name (string)
(table-name (plist-get (cadr table) :name))) ;; get table name (string)
(cond
(table-name ;; only if table found
(let ((begcont (plist-get table :contents-begin)) ;; :begin at the beginning of #+NAME:, #+ATTR_...
(endcont (plist-get table :contents-end)) ;; :end at the end of #+TBLFM: ...
(table-name ;; only if table found
(goto-char (org-element-begin table))
(let ((begcont (org-table-begin table)) ;; :begin at the beginning of #+NAME:, #+ATTR_...
(endcont (org-table-end table)) ;; :end at the end of #+TBLFM: ...
(tmp-list (plist-get my-org-table-cell-color-list (intern table-name)))) ;; get value of key (string to symbol)
(my-org-table-cell-color begcont endcont tmp-list))))))
@@ -507,12 +509,13 @@ Example usage
#+ATTR_COLOR: @2$3 blue @2$1 yellow @2$2 green
#+ATTR_COLOR: @3$1..@4$3 #cc0000 @5$3 red
"
(let* ((table (my-org-table-get)) ;; get table element
(table-attr (plist-get table :attr_color))) ;; nil if attr not set, table can be nil
(let* ((table (my-org-table-get)) ;; get table element
(table-attr (plist-get (cadr table) :attr_color))) ;; nil if attr not set, table can be nil
(cond
(table-attr ;; only if table attr found
(let ((begcont (plist-get table :contents-begin)) ;; :begin at the beginning of #+NAME:, #+ATTR_...
(endcont (plist-get table :contents-end)) ;; :end at the end of #+TBLFM: ...
(table-attr ;; only if table attr found
(goto-char (org-element-begin table))
(let ((begcont (org-table-begin table)) ;; :begin at the beginning of #+NAME:, #+ATTR_...
(endcont (org-table-end table)) ;; :end at the end of #+TBLFM: ...
(color-list
(my-org-table-list-of-range-to-list
(my-org-attr-to-list table-attr))))