关于 emacs 缩进问题

Vim、Emacs配置和使用
回复
头像
chinazhangjie
帖子: 4
注册时间: 2011-01-14 11:24

关于 emacs 缩进问题

#1

帖子 chinazhangjie » 2011-08-12 14:51

大家好,我的emacs在.cpp文件下缩进比较正常,但是在.h文件下缩进如下:

代码: 全选

template <class T, class Alloc = alloc>
class list {
 protected:
 typedef __list_node<T> list_node;
 // 专属之空间配置器,每次配置一个节点大小
 typedef simple_alloc<list_node, Alloc> list_node_allocator;
 
 protected:
 // 配置一个节点并返回
 link_type get_node() { return list_node_allocator::allocate(); }
 // 释放一个节点
 void put_node(link_type p) { list_node_allocator::deallocate(p); }

 // 产生(配置并构造)一个节点,带有元素值
 link_type create_node(const T& x) {
	 link_type p = get_node();
	 construct(&p->data, x);   // 全局函数
	 return p;
 }
 // 销毁(析构并释放)一个节点
 void destroy_node(link_type p) {
	 destroy(&p->data);
	 put_node(p);
 }

 public:
 list() { empty_initialize(); }  // 产生一个空链表

 protected:
 void empty_initialize() {
	 node = get_node();   // 配置一个节点空间,令node不指向它
	 node->next = node;
	 node->prev = node;
 }

 public:
 void push_back(const T& x) { insert(end(), x); }
}
我觉得很不舒服,
(1)public 前面只有一个字符
(2)public:回车之后会自动与public对齐,并且不能手动修改。
我想要的效果是public前面没有字符(或者四个字符),而回车之后空四个字符。请问我应该怎么修改我的配置文件。
我的配置文件内容如下:
;; author: chinazhangjie
;; e-mail: [email protected]

;; 指针颜色设置为白色
(set-cursor-color "white")
;; 鼠标颜色设置为白色
(set-mouse-color "white")


;; 从color-theme中获取
;; 网上下载color-theme.el,放到加载路径(/usr/share/emacs/site-lisp )下
;; M-x color-theme-select,鼠标左键选中,回车查看效果
;; d查看信息,将出现如下信息:
;; color-theme-matrix is an interactive Lisp function in `color-theme.el'.
;; (color-theme-matrix)
;; Color theme by [email protected], created 2003-10-16.
;; 选择(color-theme-blue-mood)即可
(require 'color-theme)
(setq color-theme-is-global t)
(color-theme-xemacs)

;; 使用tabbar.el
(require 'tabbar)
(tabbar-mode)
(global-set-key (kbd "") 'tabbar-backward-group)
(global-set-key (kbd "") 'tabbar-forward-group)
(global-set-key (kbd "") 'tabbar-backward)
(global-set-key (kbd "") 'tabbar-forward)


;; 一打开就起用 text 模式。
(setq default-major-mode 'text-mode)

;; 语法高亮
(global-font-lock-mode t)

;; 以 y/n代表 yes/no
(fset 'yes-or-no-p 'y-or-n-p)

;; 显示括号匹配
(show-paren-mode t)
(setq show-paren-style 'parentheses)

;; 显示时间,格式如下
(display-time-mode 1)
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)

(transient-mark-mode t)

;; 支持emacs和外部程序的粘贴
(setq x-select-enable-clipboard t)

;; 在标题栏提示你目前在什么位置
(setq frame-title-format "zhj@%b")

;; 默认显示 80列就换行
(setq default-fill-column 80)

;; 去掉工具栏
(tool-bar-mode nil)

;;去掉菜单栏
;;(menu-bar-mode nil)

;; 去掉滚动栏
(scroll-bar-mode nil)

;; 设置字体
;; 方法为: emacs->options->Set Default Font->"M-x describe-font"查看当前使用的字体名称、字体大小
(set-default-font " -bitstream-Courier 10 Pitch-normal-normal-normal-*-17-*-*-*-m-0-iso10646-1")

;; 显示列号
(setq column-number-mode t)
(setq line-number-mode t)

;; 设置缩进
(setq c-basic-offset 4)
(setq indent-tabs-mode nil)
(setq default-tab-width 4)
(setq tab-width 4)
(setq tab-stop-list ())
(loop for x downfrom 40 to 1 do
(setq tab-stop-list (cons (* x 4) tab-stop-list)))


;; 回车缩进
(global-set-key "\C-m" 'newline-and-indent)
(global-set-key (kbd "C-<return>") 'newline)

;; 实现全屏效果,快捷键为f6
(global-set-key [f6] 'my-fullscreen)
(defun my-fullscreen ()
(interactive)
(x-send-client-message
nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_FULLSCREEN" 0))
)

;; 最大化
(defun my-maximized ()
(interactive)
(x-send-client-message
nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_MAXIMIZED_HORZ" 0))
(x-send-client-message
nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_MAXIMIZED_VERT" 0))
)
;; 启动emacs时窗口最大化
(my-maximized)

;; 启动窗口大小
(setq default-frame-alist
'((height . 35) (width . 125) (menu-bar-lines . 20) (tool-bar-lines . 0)))
头像
chinazhangjie
帖子: 4
注册时间: 2011-01-14 11:24

Re: 关于 emacs 缩进问题

#2

帖子 chinazhangjie » 2011-08-13 17:39

问题已解决,在配置文件中添加:

代码: 全选

(add-to-list 'auto-mode-alist (cons "\\.h$" #'c++-mode))
回复