텍스트 모드에서 Emacs에서 4 개의 들여 쓰기 설정
TAB주요 모드에서 버퍼를 누를 때 Emacs가 8 개의 스페이스 탭에서 4 개의 스페이스 탭으로 전환하는 데 실패했습니다 text-mode
. 내 다음을 추가했습니다 .emacs
.
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
;;; And I have tried
(setq indent-tabs-mode nil)
(setq tab-width 4)
.emacs
파일 (또는 버퍼의 로컬 변수)을 어떻게 변경하더라도 TAB버튼은 항상 동일한 작업을 수행합니다.
- 위의 텍스트가 없으면 8 칸 들여 쓰기
- 이전 줄에 텍스트가 있으면 두 번째 단어의 시작 부분에 들여 쓰기
내가 Emacs를 좋아하는 한 이것은 성가시다. 이전 줄에 텍스트가 없을 때 Emacs가 4 칸 이상 들여 쓰기 할 수있는 방법이 있습니까?
(customize-variable (quote tab-stop-list))
또는 .emacs 파일의 custom-set-variables 에 tab-stop-list 항목을 추가 하십시오 .
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(tab-stop-list (quote (4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120))))
짧은 답변:
요점은 이멕스가 들여 쓰기 할 때 원하는 것을 삽입하도록 지시하는 것입니다. 이는 들여 쓰기 라인 기능을 변경하여 수행됩니다. 탭을 삽입하도록 변경 한 다음 4 개의 공백을 삽입하도록 변경하는 것보다 탭을 4 개의 공백으로 변경하는 것이 더 쉽습니다. 다음 구성은 문제를 해결합니다.
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
(setq indent-line-function 'insert-tab)
설명:
주요 모드로 제어되는 들여 쓰기 에서 @ emacs manual :
각 주요 모드의 중요한 기능은 편집중인 언어에 맞게 들여 쓰기되도록 키를 사용자 정의하는 것입니다.
[...]
indent-line-function 변수는 현재 줄을 들여 쓰기 위해 (그리고 indent-region을 호출 할 때와 같은 다양한 명령) 사용할 함수입니다. 들여 쓰기 모드로 명령은 더 이상이 함수를 호출하지 않습니다.
[...]
많은 모드에서 기본값은 들여 쓰기 기준입니다.
들여 쓰기 기준 @ emacs 매뉴얼에서 :
들여 쓰기 기준 이전 공백이 아닌 줄의 다음 들여 쓰기 지점 아래로 공백.
[...]
이전의 비 공백 라인이 열 포인트 시작점을 넘어서서 들여 쓰기 포인트가 없다면, 대신 'tab-to-tab-stop'이 수행됩니다.
indent-line-function의 값을 insert-tab 함수로 변경하고 탭 삽입을 4 개의 공백으로 구성하십시오.
업데이트 : Emacs 24.4 이후 :
tab-stop-list
이제 암시 적으로 무한대로 확장됩니다. 기본값이로 변경되어nil
탭이 모든tab-width
열을 중지합니다 .
즉 tab-stop-list
, 설정을 유지할 수 있으므로 더 이상 아래에 표시된 방식 으로 설정할 필요가 없습니다 nil
.
원래 답변은 다음과 같습니다.
함수가 사용되기를 기다리고있을 (setq tab-stop-list 4 8 12 ................)
때 와 같은 것을 보는 것은 항상 고통 스럽습니다 number-sequence
.
(setq tab-stop-list (number-sequence 4 200 4))
또는
(defun my-generate-tab-stops (&optional width max)
"Return a sequence suitable for `tab-stop-list'."
(let* ((max-column (or max 200))
(tab-width (or width tab-width))
(count (/ max-column tab-width)))
(number-sequence tab-width (* tab-width count) tab-width)))
(setq tab-width 4)
(setq tab-stop-list (my-generate-tab-stops))
You may find it easier to set up your tabs as follows:
M-x customize-group
At the Customize group:
prompt enter indent
.
You'll see a screen where you can set all you indenting options and set them for the current session or save them for all future sessions.
If you do it this way you'll want to set up a customisations file.
(setq tab-width 4)
(setq tab-stop-list '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80))
(setq indent-tabs-mode nil)
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
(setq indent-line-function 'insert-tab)
(setq c-default-style "linux")
(setq c-basic-offset 4)
(c-set-offset 'comment-intro 0)
this works for C++ code and the comment inside too
(defun my-custom-settings-fn ()
(setq indent-tabs-mode t)
(setq tab-stop-list (number-sequence 2 200 2))
(setq tab-width 2)
(setq indent-line-function 'insert-tab))
(add-hook 'text-mode-hook 'my-custom-settings-fn)
This problem isn't caused by missing tab stops; it's that emacs has a (new?) tab method called indent-relative that seems designed to line up tabular data. The TAB key is mapped to the method indent-for-tab-command, which calls whatever method the variable indent-line-function is set to, which is indent-relative method for text mode. I havn't figured out a good way to override the indent-line-function variable (text mode hook isn't working, so maybe it is getting reset after the mode-hooks run?) but one simple way to get rid of this behavior is to just chuck the intent-for-tab-command method by setting TAB to the simpler tab-to-tab-stop method:
(define-key text-mode-map (kbd "TAB") 'tab-to-tab-stop)
Try this:
(add-hook 'text-mode-hook
(function
(lambda ()
(setq tab-width 4)
(define-key text-mode-map "\C-i" 'self-insert-command)
)))
That will make TAB always insert a literal TAB character with tab stops every 4 characters (but only in Text mode). If that's not what you're asking for, please describe the behavior you'd like to see.
You can add these lines of code to your .emacs file. It adds a hook for text mode to use insert-tab instead of indent-relative.
(custom-set-variables
'(indent-line-function 'insert-tab)
'(indent-tabs-mode t)
'(tab-width 4))
(add-hook 'text-mode-hook
(lambda() (setq indent-line-function 'insert-tab)))
I hope it helps.
Just changing the style with c-set-style was enough for me.
Add this to your .emacs file:
This will set the width that a tab is displayed to 2 characters (change the number 2 to whatever you want)
(setq default-tab-width 2)
To make sure that emacs is actually using tabs instead of spaces:
(global-set-key (kbd "TAB") 'self-insert-command)
As an aside, the default for emacs when backspacing over a tab is to convert it to spaces and then delete a space. This can be annoying. If you want it to just delete the tab, you can do this:
(setq c-backspace-function 'backward-delete-char)
Enjoy!
Customizations can shadow (setq tab width 4)
so either use setq-default
or let Customize know what you're doing. I also had issues similar to the OP and fixed it with this alone, did not need to adjust tab-stop-list
or any insert
functions:
(custom-set-variables
'(tab-width 4 't)
)
Found it useful to add this immediately after (a tip from emacsWiki):
(defvaralias 'c-basic-offset 'tab-width)
(defvaralias 'cperl-indent-level 'tab-width)
The best answers did not work for until I wrote this in the .emacs file:
(global-set-key (kbd "TAB") 'self-insert-command)
This is the only solution that keeps a tab from ever getting inserted for me, without a sequence or conversion of tabs to spaces. Both of those seemed adequate, but wasteful:
(setq-default
indent-tabs-mode nil
tab-width 4
tab-stop-list (quote (4 8))
)
Note that quote
needs two numbers to work (but not more!).
Also, in most major modes (Python
for instance), indentation is automatic in Emacs. If you need to indent outside of the auto indent, use:
M-i
Have you tried
(setq tab-width 4)
(setq-default tab-width 4)
(setq-default indent-tabs-mode nil)
By the way, for C-mode, I add (setq-default c-basic-offset 4)
to .emacs. See http://www.emacswiki.org/emacs/IndentingC for details.
From my init file, different because I wanted spaces instead of tabs:
(add-hook 'sql-mode-hook (lambda () (progn (setq-default tab-width 4) (setq indent-tabs-mode nil) (setq indent-line-function 'tab-to-tab-stop) (modify-syntax-entry ?_ "w") ; now '_' is not considered a word-delimiter (modify-syntax-entry ?- "w") ; now '-' is not considered a word-delimiter )))
참고URL : https://stackoverflow.com/questions/69934/set-4-space-indent-in-emacs-in-text-mode
'development' 카테고리의 다른 글
Android에서 자체 URI 체계를 구현하는 방법 (0) | 2020.06.06 |
---|---|
데이터 (유형 인터페이스 {})를 유형 문자열로 변환 할 수 없음 : 유형 어설 션 필요 (0) | 2020.06.06 |
관찰자, 발행 / 구독 및 데이터 바인딩의 차이점 (0) | 2020.06.06 |
주어진 접미사로 끝나지 않는 문자열에 대한 정규식 (0) | 2020.06.06 |
브라우저의 스크롤바 크기를 어떻게 알 수 있습니까? (0) | 2020.06.06 |