I could not get emacs to shift-tab to move the selected text to the left side by -4 space
any clue will be appreciated.
PS. I am learner and sorry for too many questions on emacs.
I could not get emacs to shift-tab to move the selected text to the left side by -4 space
any clue will be appreciated.
PS. I am learner and sorry for too many questions on emacs.
This removes 4 spaces from the front of the current line (provided the spaces exist).
(global-set-key (kbd "<S-tab>") 'un-indent-by-removing-4-spaces)
(defun un-indent-by-removing-4-spaces ()
"remove 4 spaces from beginning of of line"
(interactive)
(save-excursion
(save-match-data
(beginning-of-line)
;; get rid of tabs at beginning of line
(when (looking-at "^\\s-+")
(untabify (match-beginning 0) (match-end 0)))
(when (looking-at "^ ")
(replace-match "")))))
If your variable tab-width
happens to be 4 (and that's what you want to "undo"), then you can replace the (looking-at "^ ")
with something more general like (concat "^" (make-string tab-width ?\ ))
.
Also, the code will convert the tabs at the front of the line to spaces using untabify.
To do that, I use the command indent-rigidly
, bound to C-x TAB
. Give it the argument -4 to move the selected region to the left by four spaces: C-u -4 C-x TAB
.
http://www.gnu.org/s/emacs/manual/html_node/elisp/Region-Indent.html