LoginSignup
4
6

More than 5 years have passed since last update.

現在行もしくは選択範囲の逆インデント (アウトデント、デデント)

Posted at

一部のメジャーモードでは思ったようにインデントを整えてくれないことがありますね。
indentの逆、outdent,dedentというものが標準関数に見つからなかったので以下を試してみます。
割り当てキーバインドはShift+TABにします。

(defun my-outdent-dwim ()
  (interactive)
  (let* ((x-times (or current-prefix-arg 1))
         (offset (- (* c-basic-offset x-times))))
    (if mark-active
        (indent-rigidly
         (save-excursion (goto-char (region-beginning)) (point-at-bol))
         (save-excursion (goto-char (region-end)) (point-at-eol))
         offset)
      (indent-rigidly (point-at-bol) (point-at-eol) offset))))

(global-set-key (kbd "<S-tab>") 'my-outdent-dwim)
  • 範囲選択があり: 範囲全体のインデントを1つ戻す
  • 範囲選択がなし: 現在行のインデントを1つ戻す

C-u NUM S-TABのように数字の引数を与えることでNUM分インデントを下げます。

  • C-u 3 S-TAB: インデントを3レベル分戻す

補足

indent-rigidlyC-x TABに標準で割り当てられています。
面倒ですがC-u -4 C-x TABとすることで同じような効果が得られます。

4
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
6