I just checked the behaviour for an example text.
{
Hello
world
!
When marking the region and pressing tab, they were indented automatically according to the indentation rules, i.e.
{
Hello
world
!
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?"
:group 'dumb-indent
:type 'string
:safe #'booleanp) ;; <- Considered safe as a buffer local variable.
(defun dumb-indent-line ()
(interactive)
(save-excursion
(goto-char (line-beginning-position))
(search-forward-regexp "[[:blank:]]*")
(insert dumb-indent-string)
(setq deactivate-mark nil)))
(defun dumb-indent-region (start end)
(interactive (list (region-beginning) (region-end)))
(save-excursion
(goto-char start)
(while (< (point) end)
(dumb-indent-line)
(forward-line))
(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
`M-x dumb-indent-activate'."
(interactive)
(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.
C-q
prefix to it. i.e.C-q TAB
inserts aTAB
and runs nothing else.