我真的想切換到emacs,但學習設置環境真是痛苦。大家都說這是值得的,所以我只是繼續。Emacs縮進難度
我希望我的C代碼來實現這種方式:
if(asdf)
{
asdr = 1;
}
根據當前的標準(我知道,不要讓我開始),可以是:
if(asdf) {
asdr = 1;
}
我似乎無法改變從2的縮進大小,它總是看起來像GNU標準:
if(asdf)
{
asdr = 1;
}
,我不喜歡。 以下是我已經把我的.emacs:
; Warn in C for while();, if(x=0), ...
(global-cwarn-mode 1)
; no electric mode in c
(c-toggle-electric-state -1)
; indent the current line only if the cursor is at the beginning of the line
(setq-default c-tab-always-indent nil)
(setq-default c-indent-level 4)
(setq-default tab-width 4)
(setq-default indent-tabs-mode nil)
(setq-default c-basic-offset 4)
(setq-default c-basic-indent 4)
; These commands I read about on the web, but they don't work?
;(highlight-tabs)
;(highlight-trailing_whitespace)
這並沒有幫助,我仍然是GNU縮進。 有人嗎?
---編輯添加的我整個的.emacs(實際上〜/ .emacs.d/init.el)
; directory to put various el files into
(add-to-list 'load-path "C:/Program/emacs-22.3/includes")
; loads ruby mode when a .rb file is opened.
(autoload 'ruby-mode "ruby-mode" "Major mode for editing ruby scripts." t)
(setq auto-mode-alist (cons '(".rb$" . ruby-mode) auto-mode-alist))
(setq auto-mode-alist (cons '(".rhtml$" . html-mode) auto-mode-alist))
(add-hook 'ruby-mode-hook
(lambda()
(add-hook 'local-write-file-hooks
'(lambda()
(save-excursion
(untabify (point-min) (point-max))
(delete-trailing-whitespace)
)))
(set (make-local-variable 'indent-tabs-mode) 'nil)
(set (make-local-variable 'tab-width) 2)
(imenu-add-to-menubar "IMENU")
(define-key ruby-mode-map "\C-m" 'newline-and-indent) ;Not sure if this line is 100% right but it works!
(require 'ruby-electric)
(ruby-electric-mode t)
))
; Install mode-compile to give friendlier compiling support!
(autoload 'mode-compile "mode-compile"
"Command to compile current buffer file based on the major mode" t)
(global-set-key "\C-cc" 'mode-compile)
(autoload 'mode-compile-kill "mode-compile"
"Command to kill a compilation launched by `mode-compile'" t)
(global-set-key "\C-ck" 'mode-compile-kill)
(show-paren-mode 1)
; Color theme
(require 'color-theme)
(color-theme-pok-wog)
;;Emacs.pane.menubar.* does not seem to work?
;Emacs.pane.menubar.background: darkGrey
;Emacs.pane.menubar.foreground: black
; Default font 9 pt
(set-face-attribute 'default nil :height 80)
(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.
)
(custom-set-faces
;; custom-set-faces 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.
'(font-lock-comment-face ((t (:foreground "limegreen" :slant oblique))))
'(font-lock-preprocessor-face ((t (:inherit font-lock-builtin-face :foreground "orange" :weight bold)))))
(global-set-key [C-tab] 'other-window)
(global-set-key [C-S-tab] (lambda() (interactive) (other-window -1)))
(defun linux-c-mode()
"C mode with adjusted defaults for use with the Linux
kernel."
(interactive)
(c-mode)
(setq c-indent-level 8)
(setq c-brace-imaginary-offset 0)
(setq c-brace-offset -8)
(setq c-argdecl-indent 8)
(setq c-label-offset -8)
(setq c-continued-statement-offset 8)
(setq indent-tabs-mode nil)
(setq tab-width 8))
; Warn in C for while();, if(x=0), ...
(global-cwarn-mode 1)
; no electric mode in c
(c-toggle-electric-state -1)
; indent the current line only if the cursor is at the beginning of the line
(setq-default c-tab-always-indent nil)
(setq-default c-indent-level 4)
(setq-default tab-width 4)
(setq indent-tabs-mode nil)
(setq-default c-basic-offset 4)
(setq-default c-basic-indent 4)
; These commands I read about on the web, but they don't work?
;(highlight-tabs)
;(highlight-trailing_whitespace)
(setq indent-tabs-mode nil)
(setq c-default-style "user")
;; Remove lull: scroll bar, tool bar, menu bar.
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
;; restore window size as it was at previous use
(defun restore-saved-window-size()
(unless (load "~/.emacs.d/whsettings" t nil t)
(setq saved-window-size '(80 30)))
(nconc default-frame-alist `((width . ,(car saved-window-size))
(height . ,(cadr saved-window-size)))))
(restore-saved-window-size)
(defun save-window-size-if-changed (&optional unused)
(let ((original-window-size `(,(frame-width) ,(frame-height))))
(unless (equal original-window-size saved-window-size)
(with-temp-buffer
(setq saved-window-size original-window-size)
(insert (concat "(setq saved-window-size '"
(prin1-to-string saved-window-size) ")"))
(write-file "~/.emacs.d/whsettings")))))
(add-hook 'window-size-change-functions 'save-window-size-if-changed)
;; Ack as a replacment for grep
(global-set-key "\M-s" 'ack)
(require 'ack)
我試圖插入你寫的線路和負載文件,但我還是看到了GNU標準。 我也試過用「stroustrup」和「python」,沒有什麼區別。 – Gauthier 2010-03-17 12:28:21
您是否有正在加載的自定義文件並覆蓋您的設置? 另外,我不確定使用setq-default與用戶風格的變量 - 你可以嘗試普通的setq? (這並不能解釋爲什麼stroustrup/python無法正常工作) – Doug 2010-03-17 12:41:03
我不這麼認爲。我在原始文章中添加了我的整個.emacs,我認爲這可能會有所幫助。 用「用戶」我幾乎得到我想要的。標籤不能被空格替換,我不明白爲什麼。 – Gauthier 2010-03-17 13:14:18