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

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

问题描述

如何让 Emacs 使用 ShiftTab 将所选文本向左移动 4 个空格?

How can I get Emacs to ShiftTab 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 "^" (make-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 ? )).

此外,代码将使用 取消标签化.

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

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