私も emacs が好きですが、タブを管理しようとする試みには我慢できません。だから私は私の中で以下を使用します.emacs
:
(global-set-key "\r" 'newline-and-indent)
(global-set-key "\C-m" 'newline-and-indent)
(global-set-key "\C-j" 'newline)
(defalias 'backward-delete-char-untabify 'backward-delete-char)
(defun indent-according-to-mode () (interactive)
(save-excursion
(goto-char (- (line-beginning-position) 1))
(search-backward-regexp "^[ ]*")
)
(if (eq (point) (line-beginning-position))
(insert (match-string 0))
(save-excursion
(goto-char (line-beginning-position))
(insert (match-string 0))
)
)
)
(defun newline-and-indent () (interactive) (newline) (indent-according-to-mode))
(defun lisp-indent-line () (interactive) (insert " "))
; Is there a way to fix this without a hook?
(defun my-c-hook ()
(setq c-electric-flag nil)
(defun c-indent-command (n) (interactive "*") (insert " ")))
(add-hook 'c-mode-common-hook 'my-c-hook)
(defun my-perl-hook ()
(defun perl-electric-terminator () (interactive "*") (self-insert-command 1))
(defun perl-indent-command () (interactive "*") (insert " ")))
(add-hook 'perl-mode-hook 'my-perl-hook)
(defun indent-for-tab-command () (interactive "*") (insert " "))
結果の動作: タブ キーは純粋に挿入されるタブ文字であり、Enter キーを押すと、現在の行から新しい行に先頭の空白 (スペースまたはタブ) が正確にコピーされ、これらのモードでの特別なインデント動作はすべて無効になります。他の言語を使用する場合は、上記を拡張/適応させてフックを追加する必要がある場合があります。
注: 上記で、引用符内の空白のほとんどは、実際にはリテラル タブです。SO を通過せず、正しくコピー/貼り付けできない場合は、自分で手動で修正する必要がある場合があります。