代码之家  ›  专栏  ›  技术社区  ›  jameshfisher

Emacs选项卡的全局配置

  •  6
  • jameshfisher  · 技术社区  · 14 年前

    我正试图从Vim切换到Emacs,但我正在努力将它配置成我所希望的那样。我要求:

    • 标签(即真实的 \t 字符)在屏幕上由
    • 按TAB键 在光标处插入选项卡 整行缩进 . 目前,我在任何地方按TAB键,Emacs销毁行开头的所有空白;这是迄今为止最令人愤怒的事情。

    ~/.emacs

    (setq standard-indent 2)
    (setq-default indent-tabs-mode nil)
    

    但是我已经尝试了无数的网络配置,没有一个像他们说的那样(API是否不断变化?我在用 GNU Emacs 23.1.1 ,显然是。)

    3 回复  |  直到 14 年前
        1
  •  7
  •   Damyan    14 年前

    所以这取决于你工作的模式,这会限制你得到的答案。在大多数情况下,我建议您不要反对它—对我来说,缩进行为是emacs最好的特性之一。但是,您确实需要花时间为自己定制它。

    • c制表符始终缩进
    • c-句法缩进

    我建议您通过自定义界面设置这些。如果使用“M-x customize group RET C”,则可以看到C模式的各种设置。

    也许emacs对于您的文件处于错误的模式。你可以试试“M-x基本模式”,看看你是否喜欢那里的行为。

        2
  •  4
  •   offby1    14 年前
    ;; * Inserted "tabs" to be expanded into two spaces. Emacs stubbornly
    ;;   sticks to eight, no matter what I do.
    
    ;; * Tabs (i.e. real \t characters) to be represented on screen by two
    ;;   spaces.
    
    (setq-default tab-width 2)
    
    
    ;; * Pressing TAB should insert a tab at the cursor rather than indent
    ;;   the entire line. Currently, I press TAB anywhere and Emacs
    ;;   destroys all whitespace at the start of the line; this is the
    ;;   most infuriating thing so far.
    
    (setq-default indent-tabs-mode t)
    
    (mapcar (lambda (hooksym)
              (add-hook hooksym
                        (lambda ()
                          (kill-local-variable 'indent-tabs-mode)
                          (kill-local-variable 'tab-width)
                          (local-set-key (kbd "TAB") 'self-insert-command))))
    
            '(
              c-mode-common-hook
    
              ;; add other hook functions here, one for each mode you use :-(
              ))
    
    ;; How to know the name of the hook function?  Well ... visit a file
    ;; in that mode, and then type C-h v major-mode RET.  You'll see the
    ;; mode's name in the *Help* buffer (probably on the second line).
    
    ;; Then type (e.g.) C-h f python-mode; you'll see blather about the
    ;; mode, and (hopefully) somewhere in there you'll see (again e.g.)
    ;; "This mode runs the hook `python-mode-hook', as the final step
    ;; during initialization."
    
        3
  •  1
  •   Trey Jackson    14 年前

    (defun insert-tab ()
      "self-insert-command doesn't seem to work for tab"
      (interactive)
      (insert "\t"))
    (setq indent-line-function 'insert-tab)  ;# for many modes
    (define-key c-mode-base-map [tab] 'insert-tab) ;# for c/c++/java/etc.
    (setq-default tab-width 2)