emacs默认情况下,在scratch下,tab没反应,我自己设置了tab转换为空格 但是还是不行,试了下spacemacs的,可以直接tab为空格
我的配置
;; 设置tab为4个空格
(setq-default indent-tabs-mode nil)
(setq-default c-basic-offset 4)
(setq default-tab-width 4)
;; 在很多时候,tab按了不管用,使用ctrl+tab来模拟
(global-set-key [C-tab] '(lambda () (interactive) (insert-char 9 1)))
;; 鼠标滚轮,默认的滚动太快,这里改为3行
(defun up-slightly () (interactive) (scroll-up 3))
(defun down-slightly () (interactive) (scroll-down 3))
(global-set-key [mouse-4] 'down-slightly)
(global-set-key [mouse-5] 'up-slightly)
;; 重新绑定C-z到撤销
(global-set-key (kbd "C-z") 'undo)
用子龙山人大神的lisp代码,提示错误
;; my fix for tab indent
(defun zilongshanren/indent-region(numSpaces)
(progn
; default to start and end of current line
(setq regionStart (line-beginning-position))
(setq regionEnd (line-end-position))
; if there's a selection, use that instead of the current line
(when (use-region-p)
(setq regionStart (region-beginning))
(setq regionEnd (region-end))
)
(save-excursion ; restore the position afterwards
(goto-char regionStart) ; go to the start of region
(setq start (line-beginning-position)) ; save the start of the line
(goto-char regionEnd) ; go to the end of region
(setq end (line-end-position)) ; save the end of the line
(indent-rigidly start end numSpaces) ; indent between start and end
(setq deactivate-mark nil) ; restore the selected region
)
)
)
(defun zilongshanren/tab-region ()
(interactive "p")
(if (use-region-p)
(zilongshanren/indent-region 4) ; region was selected, call indent-region
(insert " ") ; else insert four spaces as expected
))
(defun zilongshanren/untab-region ()
(interactive "p")
(zilongshanren/indent-region -4))
(defun zilongshanren/hack-tab-key ()
(interactive)
(local-set-key (kbd "<tab>") 'zilongshanren/tab-region)
(local-set-key (kbd "<S-tab>") 'zilongshanren/untab-region)
)
(add-hook 'prog-mode-hook 'zilongshanren/hack-tab-key)
我加了行
(add-hook 'text-mode-hook 'zilongshanren/hack-tab-key)