fix org table colored cells
This commit is contained in:
@@ -392,10 +392,10 @@ then return the table element otherwise return nil.
|
|||||||
`org-at-table-p' is nil if cursor on #+TBLFM"
|
`org-at-table-p' is nil if cursor on #+TBLFM"
|
||||||
(let ((element (org-element-at-point))) ;; get org element
|
(let ((element (org-element-at-point))) ;; get org element
|
||||||
(while (and element (not (eq (car element) 'table))) ;; check if it is table
|
(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
|
(cond
|
||||||
((equal (car element) 'table) ;; only if table found
|
((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)
|
(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))
|
;;(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
|
(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 (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
|
(ov beg end 'face (list :background bg
|
||||||
:foreground fg))
|
:foreground fg))
|
||||||
@@ -485,11 +486,12 @@ Example usage to add a (normal, global) hook:
|
|||||||
Example usage to add a local hook:
|
Example usage to add a local hook:
|
||||||
(add-hook 'org-ctrl-c-ctrl-c-hook 'my-org-table-cell-color-var nil t)"
|
(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
|
(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
|
(cond
|
||||||
(table-name ;; only if table found
|
(table-name ;; only if table found
|
||||||
(let ((begcont (plist-get table :contents-begin)) ;; :begin at the beginning of #+NAME:, #+ATTR_...
|
(goto-char (org-element-begin table))
|
||||||
(endcont (plist-get table :contents-end)) ;; :end at the end of #+TBLFM: ...
|
(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)
|
(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))))))
|
(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: @2$3 blue @2$1 yellow @2$2 green
|
||||||
#+ATTR_COLOR: @3$1..@4$3 #cc0000 @5$3 red
|
#+ATTR_COLOR: @3$1..@4$3 #cc0000 @5$3 red
|
||||||
"
|
"
|
||||||
(let* ((table (my-org-table-get)) ;; get table element
|
(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
|
(table-attr (plist-get (cadr table) :attr_color))) ;; nil if attr not set, table can be nil
|
||||||
(cond
|
(cond
|
||||||
(table-attr ;; only if table attr found
|
(table-attr ;; only if table attr found
|
||||||
(let ((begcont (plist-get table :contents-begin)) ;; :begin at the beginning of #+NAME:, #+ATTR_...
|
(goto-char (org-element-begin table))
|
||||||
(endcont (plist-get table :contents-end)) ;; :end at the end of #+TBLFM: ...
|
(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
|
(color-list
|
||||||
(my-org-table-list-of-range-to-list
|
(my-org-table-list-of-range-to-list
|
||||||
(my-org-attr-to-list table-attr))))
|
(my-org-attr-to-list table-attr))))
|
||||||
|
|||||||
Reference in New Issue
Block a user