# Automatically turn on hl-line-mode inside org-mode tables

Based on this answer my question is whether there is a (simple) way to automatically turn on hl-line-mode whenever the cursor is within an org-mode table in an org-mode file.

I tried to find a hook for entering or leaving an org-mode table but I was not successful.

• I've suggested one approach in my answer below. I also added an answer to the other question about getting odd/even row highlighting for org tables use stripe-table-mode, which may be all you need. – glucas Dec 22 '16 at 14:37

Org mode does provide the org-at-table-p function that can be used to determine if the cursor is inside an org table.

You would need to check this every time the cursor moves, which could be done using the post-command-hook.

(defun highlight-current-table-line ()
(interactive)
(if (org-at-table-p)
(hl-line-mode 1)
(hl-line-mode -1)))

(defun setup-table-highlighting ()

This adds a hook that runs after every command when you are in an org (or orgtbl) buffer, and toggles hl-line-mode accordingly.