- 论坛徽章:
- 0
|
C代码格式问题
呵呵真是搞不懂,为什么我的这个C程序会是这样的格式?我编好后用C+M+\,代码就没变,还是这个样子,请问如何才能设置成正常的样子?就是11,17,31到40行,明显就是没有缩进好嘛,可是我连手工调整都不行,呵呵水平太有限了这是我的.emacs,请大家看看是设置有问题吗?- ;插件路径
- (add-to-list 'load-path "/cygdrive/e/HOME/smouse/emacscool")
- (add-to-list 'load-path "/cygdrive/e/HOME/smouse/emacscool/ecb-2.32")
- (add-to-list 'load-path "/cygdrive/e/HOME/smouse/emacscool/cedet-1.0pre4/common")
- (add-to-list 'load-path "/cygdrive/e/HOME/smouse/emacscool/emms-3.0")
- ;;放歌听嘿嘿
- (defun emms ()
- (interactive)
- (require 'emms-init))
- (global-set-key [f9] 'emms)
- (setq gdb-many-windows t)
- (load-library "multi-gud.el")
- (load-library "multi-gdb-ui.el")
- ;自定义按键
- (global-set-key [f4] 'shell);F1进入Shell
- (global-set-key [f5] 'gdb);F5调试程序
- (global-set-key [f1] 'compile);F1编译文件
- (setq compile-command "make ")
- (global-set-key [f8] 'other-window);F8窗口间跳转
- (global-set-key [C-return] 'kill-this-buffer);C-return关闭当前buffer
- (global-set-key [f10] 'split-window-vertically);F10分割窗口
- (global-set-key [f11] 'delete-other-windows);F11 关闭其它窗口
- (global-set-key (kbd "C-,") 'backward-page);文件首
- (global-set-key (kbd "C-.") 'forward-page);文件尾
- ;普通设置
- (setq inhibit-startup-message t);关闭起动时闪屏
- (setq visible-bell t);关闭出错时的提示声
- (setq make-backup-files nil);不产生备份文件
- (setq default-major-mode 'text-mode);一打开就起用 text 模式
- (add-hook 'text-mode-hook 'turn-on-auto-fill);打开text后是自动换行自动换行
- (global-font-lock-mode t);语法高亮
- (auto-image-file-mode t);打开图片显示功能
- (fset 'yes-or-no-p 'y-or-n-p);以 y/n代表 yes/no
- (column-number-mode t);显示列号
- (show-paren-mode t);显示括号匹配
- (display-time-mode 1);显示时间,格式如下
- (setq display-time-24hr-format t)
- (setq display-time-day-and-date t)
- (tool-bar-mode nil);去掉那个大大的工具栏
- (scroll-bar-mode nil);去掉滚动条
- ;(mouse-avoidance-mode 'animate);光标靠近鼠标指针时,让鼠标指针自动让开
- (setq mouse-yank-at-point t);支持中键粘贴
- (transient-mark-mode t);允许临时设置标记
- (setq x-select-enable-clipboard t);支持emacs和外部程序的粘贴
- (setq frame-title-format '("" buffer-file-name "@emacs" ));在标题栏显示buffer名称
- (setq default-fill-column 80);默认显示 80列就换行
- ;鼠标滚轮,默认的滚动太快,这里改为3行
- (defun up-slightly () (interactive) (scroll-up 3))
- (defun down-slightly () (interactive) (scroll-down 3))
- (global-set-key [mouse-4] 'down-slightly)
- (global-set-key [mouse-5] 'up-slightly)
- ;shell,gdb退出后,自动关闭该buffer
- (add-hook 'shell-mode-hook 'mode-hook-func)
- (add-hook 'gdb-mode-hook 'mode-hook-func)
- (defun mode-hook-func ()
- (set-process-sentinel (get-buffer-process (current-buffer))
- #'kill-buffer-on-exit))
- (defun kill-buffer-on-exit (process state)
- (message "%s" state)
- (if (or
- (string-match "exited abnormally with code.*" state)
- (string-match "finished" state))
- (kill-buffer (current-buffer))))
- ;加入color-theme插件
- (require 'color-theme)
- (color-theme-blue-mood)
- (setq initial-frame-alist '((top . 30) (left . 0) (width . 139) (height . 44)))
- (add-hook 'window-setup-hook 'maximize-frame t)
- (setq make-backup-files nil)
- ;; 设定不产生备份文件
- (setq auto-save-mode nil)
- ;;自动保存模式文件
- ;;;C的风格
- ;我的C设置:
- ;C语言编辑
- (add-hook 'c-mode-hook 'linux-c-mode)
- (add-hook 'c++-mode-hook 'linux-cpp-mode)
- ;; 设置imenu的排序方式为按名称排序
- (setq imenu-sort-function 'imenu--sort-by-name)
- (defun linux-c-mode()
- ;; 将回车代替C-j的功能,换行的同时对齐
- (define-key c-mode-map [return] 'newline-and-indent)
- (interactive)
- ;; 设置C程序的对齐风格
- (c-set-style "K&R")
- ;; 自动模式,在此种模式下当你键入{时,会自动根据你设置的对齐风格对齐
- ; (c-toggle-auto-state)
- ;; 此模式下,当按Backspace时会删除最多的空格
- (c-toggle-hungry-state)
- ;; TAB键的宽度设置为4
- (setq c-basic-offset 4)
- ;; 在菜单中加入当前Buffer的函数索引
- (imenu-add-menubar-index)
- ;; 在状态条上显示当前光标在哪个函数体内部
- (which-function-mode)
- )
- (defun linux-cpp-mode()
- (define-key c++-mode-map [return] 'newline-and-indent)
- (define-key c++-mode-map [(control c) (c)] 'compile)
- (interactive)
- (c-set-style "K&R")
- ;(c-toggle-auto-state)
- (c-toggle-hungry-state)
- ;(setq c-basic-offset 8)
- (imenu-add-menubar-index)
- (which-function-mode)
- )
- ;;字体
- ;; create a fontsets
- (create-fontset-from-fontset-spec
- "-adobe-courier-medium-r-*-*-14-*-*-*-*-*-fontset-adobe,
- latin-iso8859-1:-adobe-courier-medium-r-*-*-14-*-*-*-*-*-*-1,
- latin-iso8859-2:-adobe-courier-medium-r-*-*-14-*-*-*-*-*-*-2,
- cyrillic-iso8859-5:-adobe-courier-medium-r-*-*-14-*-*-*-*-*-*-5,
- chinese-gb2312:*-song-medium-r-normal-*-14-*")
- (create-fontset-from-fontset-spec
- "-adobe-courier-medium-o-*-*-14-*-*-*-*-*-fontset-adobe,
- latin-iso8859-1:-adobe-courier-medium-o-*-*-14-*-*-*-*-*-*-1,
- latin-iso8859-2:-adobe-courier-medium-o-*-*-14-*-*-*-*-*-*-2,
- cyrillic-iso8859-5:-adobe-courier-medium-o-*-*-14-*-*-*-*-*-*-5,
- chinese-gb2312:*-song-medium-r-normal-*-14-*")
- (create-fontset-from-fontset-spec
- "-adobe-courier-bold-o-*-*-14-*-*-*-*-*-fontset-adobe,
- latin-iso8859-1:-adobe-courier-bold-o-*-*-14-*-*-*-*-*-*-1,
- latin-iso8859-2:-adobe-courier-bold-o-*-*-14-*-*-*-*-*-*-2,
- cyrillic-iso8859-5:-adobe-courier-bold-o-*-*-14-*-*-*-*-*-*-5,
- chinese-gb2312:*-song-medium-r-normal-*-14-*")
- (create-fontset-from-fontset-spec
- "-adobe-courier-bold-r-*-*-14-*-*-*-*-*-fontset-adobe,
- latin-iso8859-1:-adobe-courier-bold-r-*-*-14-*-*-*-*-*-*-1,
- latin-iso8859-2:-adobe-courier-bold-r-*-*-14-*-*-*-*-*-*-2,
- cyrillic-iso8859-5:-adobe-courier-bold-r-*-*-14-*-*-*-*-*-*-5,
- chinese-gb2312:*-song-medium-r-normal-*-14-*")
- (set-default-font "fontset-adobe")
- (setq default-frame-alist (append '((font . "fontset-adobe")
- (width . 78) (height . 45))))
- ;;行号
- ;; 加载显示行号模块
- (require 'display-line-number)
- ;; 如果想所有打开的文件都显示行的话就打开下面的注释
- (global-display-line-number-mode 1)
- ;; 设置显示格式
- (setq display-line-number-format "%4d|")
- ;; 仅对某种 mode 启动显示行号的模式
- (add-hook 'c-mode-hook 'display-line-number-mode)
- ;;ctrl-o换行哈哈我太高兴了
- (define-key global-map (kbd "C-o") 'vi-open-next-line)
- (defun vi-open-next-line (arg)
- "Move to the next line (like vi) and then opens a line."
- (interactive "p")
- (end-of-line)
- (open-line arg)
- (next-line 1)
- (indent-according-to-mode))
- ;; tabbar
- (require 'tabbar)
- (tabbar-mode t)
- (global-set-key (kbd "M--") 'tabbar-backward-group)
- (global-set-key (kbd "M-=") 'tabbar-forward-group)
- (global-set-key (kbd "M-1") 'tabbar-backward)
- (global-set-key (kbd "M-2") 'tabbar-forward)
- ;;现在,我们就可以按alt加上1或者2什么的来在不同的tab间切换了。当然了,你也可以用鼠标。
- ;;原来的 tabbar 强行对你的 buffer 进行分组,但是如果你想在你编辑的buffer间切换而不论它们是什么组,那么似乎没有一个好办法。但是 tabbar 本来提供了一个机制,让你可以自己确定 tab 属于哪组,只要修改 tabbar-buffer-groups-function 就行了。
- ;这样,我可以把每个 buffer 同时加入它所在的 major mode 的组和一个叫做 "default" 的组,这样我在 default 组里就可以方便的浏览到所有的 buffer 了。而切换到其它组就可以分组浏览。你还可以自行把某些 buffer 分到一组,比如我可以把 scheme-mode 的 buffer 和 inferer-scheme-mode 的 buffer 分到同一个组。
- (setq tabbar-buffer-groups-function 'tabbar-buffer-ignore-groups)
- (defun tabbar-buffer-ignore-groups (buffer)
- "Return the list of group names BUFFER belongs to.
- Return only one group for each buffer."
- (with-current-buffer (get-buffer buffer)
- (cond
- ((or (get-buffer-process (current-buffer))
- (memq major-mode
- '(comint-mode compilation-mode)))
- '("Process")
- )
- ((member (buffer-name)
- '("*scratch*" "*Messages*"))
- '("Common")
- )
- ((eq major-mode 'dired-mode)
- '("Dired")
- )
- ((memq major-mode
- '(help-mode apropos-mode Info-mode Man-mode))
- '("Help")
- )
- ((memq major-mode
- '(rmail-mode
- rmail-edit-mode vm-summary-mode vm-mode mail-mode
- mh-letter-mode mh-show-mode mh-folder-mode
- gnus-summary-mode message-mode gnus-group-mode
- gnus-article-mode score-mode gnus-browse-killed-mode))
- '("Mail")
- )
- (t
- (list
- "default" ;; no-grouping
- (if (and (stringp mode-name) (string-match "[^ ]" mode-name))
- mode-name
- (symbol-name major-mode)))
- )
-
- )))
- ;; set fly-on-spell
- (autoload 'flyspell-mode "flyspell" "On-the-fly spelling checker." t)
- (autoload 'flyspell-delay-command "flyspell" "Delay on command." t)
- (autoload 'tex-mode-flyspell-verify "flyspell" "" t)
- ;(global-flyspell-mode)
- ;;使用c-j来代替goto-line,指定移动到某行
- (define-key global-map (kbd "C-j") 'goto-line)
复制代码 |
-
a.GIF
(62.5 KB, 下载次数: 49)
|