gpt4 book ai didi

Emacs 缩进难度

转载 作者:行者123 更新时间:2023-12-04 05:44:09 25 4
gpt4 key购买 nike

我真的很想切换到 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)

最佳答案

您的默认设置可能会被 cc-mode 覆盖的风格特征。

尝试像这样初始化默认样式:
(setq c-default-style '((java-mode . "java") (awk-mode . "awk") (other . "user")))
您应该能够将前一行粘贴到您的 .emacs 文件中,或者自定义 c-default-style多变的。默认有 (other "gnu")作为列表的最后一个元素,这意味着所有非 Java 和非 awk 文件都获得 gnu样式而不是您设置的样式 setq .特价user style 从您手动设置的样式变量中初始化。

另一种选择是选择一种内置样式而不是自己定义它,或者使用 c-add-style 创建自己的样式。功能。为此,请更改 "user"在上面的命令中添加样式的名称(作为字符串)。试试 stroustruppython内置样式以您想要的方式格式化 if 语句。

关于Emacs 缩进难度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2461962/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com