I just checked the behaviour for an example text.
When marking the region and pressing tab, they were indented automatically according to the indentation rules, i.e.
Can you verify whether this happens for you?
If you want to force a specific behaviour of
Tab, I came up with this solution:
(defcustom dumb-indent-string " "
"What string should be used for indenting?"
:safe #'booleanp) ;; <- Considered safe as a buffer local variable.
(defun dumb-indent-line ()
(setq deactivate-mark nil)))
(defun dumb-indent-region (start end)
(interactive (list (region-beginning) (region-end)))
(while (< (point) end)
(setq deactivate-mark nil))) ;; Works only when calling function directly.
(defun dumb-indent-activate ()
"A hook function for activating dumb indenting. Can also be used as
(setq-local indent-line-function #'dumb-indent-line)
(setq-local indent-region-function #'dumb-indent-region))
(add-hook 'latex-mode-hook #'dumb-indent-activate) ;; preinstalled latex-mode
(add-hook 'LaTeX-mode-hook #'dumb-indent-activate) ;; AucTeX LaTeX-mode
There is a little flaw though. Pressing tab will remove highlighting, because
indent-region explicitly calls
(deactivate-mark) without querying the
deactivate-mark variable. I could have written a function, that is bound to
TAB instead of
indent-for-tab-command, but I hope for someone having a better idea.