Emacs缩进困难

2023-12-25

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

EmacsWiki 有一篇不错的文章缩进C http://www.emacswiki.org/emacs/IndentingC.

事实上,EmacsWiki 上有关于所有内容的精彩文章。我不想在 Emacs 出现之前就学会它。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Emacs缩进困难 的相关文章

随机推荐

  • iPhone + Drupal + JSON RPC 服务器问题

    我不知道如何使用 Obj C 发布 JSON RPC 请求 谁能帮我 到目前为止我有 responseData NSMutableData data retain NSMutableURLRequest request NSMutableU
  • 使用 getNodeSet 解析 XML - 识别缺失的标签

    我正在解析 XML 文件getNodeSet 假设我有一个来自书店的 XML 文件 其中列出了 4 本书 但其中一本书缺少 作者 标签 如果我使用以下方法解析 XML 中的标签 authors data nodes 2 lt getNode
  • android edittext的最小值和最大值

    我正在开发一个android应用程序 实际上我需要为编辑文本条目设置最小值和最大值我的最小值是18 最大值是65 我做了这个的确切代码 package com test import android text InputFilter imp
  • CSS 按钮在 Google Chrome 中不起作用?

    我正在为一家电影公司的网站制作一个主页 它有一个带有悬停效果的 CSS 按钮 一旦准备好就会打开一个灯箱 目前我只是将其设置为 href 作为一个占位符 直到我准备好实现灯箱 还有一个向下箭头的小图像 链接设置为尚未出现在页面上的锚点 这两
  • ios7 UIWebView Youtube 视频

    我有一个 UIWebView 子类 用来播放 youtube 和本地视频 在iOS6下完美运行 在升级到 iOS7 的过程中 我遇到了一个问题 我真的不知道从哪里开始 虽然子类似乎仍然可以在 iOS7 模拟器上播放 youtube 和本地视
  • 在通用方法中将值转换为 T

    我有一个破旧的属性映射的界面 interface IPropertyMap bool Exists string key int GetInt string key string GetString string key etc 我想创建一
  • 有没有办法检测 Facebook Javascript SDK 是否加载成功?

    我使用 Facebook 作为我网站的会员系统 它使用代码生成登录控件 允许用户通过 Facebook 帐户登录 如果他们已经是会员 则基本上只需单击一下 如果不是会员 则只需单击 2 次 用于授予权限 但我遇到了问题 反馈表明登录按钮并不
  • 在 Eclipse IDE 中恢复已删除的文件

    两天前 我在 Eclipse IDE 中删除了五个 Java 文件 现在我需要它们 我试图从当地历史中恢复它们 我只恢复了其中两个 当我右键单击其他文件 然后单击从本地历史记录恢复时 收到错误消息No additional members
  • 处理大文件的最佳 Python Zip 模块是什么?

    编辑 特别是压缩和提取速度 有什么建议么 Thanks 所以我制作了一个随机的大压缩文件 ls l zip rw r r 1 aleax 5000 115749854 Nov 18 19 16 large zip unzip l large
  • ASP.NET MVC 帐户控制器使用指南?

    我正在查看 MVC 帐户控制器 它似乎来自 ASP NET Webforms 有没有关于如何使用它的好的背景信息 您可以将其映射到用户数据库表还是最好进行自己的用户管理 如何在 MVC 中使用它来限制登录用户可以查看的页面 您必须自己完成所
  • 没有可用的缓冲区空间(已达到最大连接?)表单 Postgres EDB 驱动程序

    我们在通过 java 应用程序连接到数据库时遇到异常 堆栈跟踪如下 com edb util PSQLException The connection attempt failed at com edb core v3 Connection
  • 如何使用 Windows 任务计划程序安全地存储每天运行的脚本的密码?

    我编写了一个PowerShell脚本来执行一些操作 操作完成后 我希望脚本使用以下命令发送邮件Send MailMessage cmdlet 为此 我使用了谷歌的应用程序密码功能 但我对将应用程序密码以纯文本形式存储在脚本本身中没有信心 我
  • 了解 Firebase 云功能中 Firebase 存储中存储的视频的持续时间的最简单方法是什么?

    我有一个基于触发器的云函数 应该可以找到上传到 Firebase Storage 的视频的持续时间 我尝试使用以下 npm 模块 get video duration https www npmjs com package get vide
  • 这是解析 XML 的低效方法吗?

    我可能担心错误的优化 但我有一个挥之不去的想法 它一遍又一遍地解析 xml 树 也许我在某个地方读过它 不记得了 无论如何 这就是我正在做的事情 using System using System Collections Generic u
  • 在奏鸣曲管理中隐藏下载按钮

    我想从某些自定义实体中隐藏 Sonata Admin 上的 下载 按钮 如何隐藏 删除它 如果我覆盖base list html twig并从 table footer 中删除下载按钮 它会消失所有实体列表 有什么办法可以将其隐藏在 Adm
  • GitHub 操作的输出为空

    我正在创建我的第一个 GitHub 操作 但我不明白为什么输出为空 动作 yml name Run Endtest functional tests description Register a deployment event with
  • 如何在 cirros OS 中安装软件包

    如何在 cirros 镜像中安装软件包 我在 devstack 安装附带的 cirros 映像中找不到任何可用的安装程序 正如 Harikrishnan 评论的那样 cirros 不包含包管理器 Cirros 主要用于验证云是否正常工作 虚
  • C++ 算法在数组中查找“最大差异”

    我正在询问您对这个问题的想法 I have one array A with N elements of type double or alternatively integer I would like to find an algori
  • 下载绘图而无需在 R闪亮中重新绘图

    我正在尝试下载已经绘制的ggplot图像而无需再次重新绘制 我找到的所有解决方案 例如保存在闪亮的应用程序中制作的绘图 https stackoverflow com questions 14810409 save plots made i
  • Emacs缩进困难

    我真的很想切换到 emacs 但是学习设置环境真的很痛苦 大家都说值得 所以我就继续 我希望我的 C 代码能够以这种方式实现 if asdf asdr 1 根据当前的标准 我知道 别让我开始 可能是 if asdf asdr 1 我似乎无法