Emacs Shift-Tab左移块 [英] Emacs Shift-Tab to left shift the block

查看:200
本文介绍了Emacs Shift-Tab左移块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取emacs移位选项卡以将所选文本向左移动4个空格?

How can I get emacs to shift-tab to move the selected text to the left by 4 spaces?

推荐答案

从当前行的前面移除4个空格(只要存在空格)。

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 "")))))

如果您的变量 tab-width 恰好是4(这就是你想要撤消),那么可以将看起来^)与更常见的东西像(concat^(mak e-string tab-width?\))

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 ?\ )).

此外,代码会将行前面的标签转换为空格使用 untabify

Also, the code will convert the tabs at the front of the line to spaces using untabify.

这篇关于Emacs Shift-Tab左移块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆