最近我换了几次电脑,在这个过程中我丢失了我的.emacs文件。现在我正在尝试重新构建它,但是在此期间,我想学习其他人使用的好的配置。
所以,如果你使用Emacs,你的.emacs文件里有什么呢?
我的.emacs文件现在非常简单,只包含:
- 全局字体锁定模式!
(global-font-lock-mode 1)
- 我的个人偏好关于缩进,制表符和空格。
- 使用cperl-mode代替perl-mode。
- 编译的快捷方式。
你认为哪些设置是有用的呢?
最近我换了几次电脑,在这个过程中我丢失了我的.emacs文件。现在我正在尝试重新构建它,但是在此期间,我想学习其他人使用的好的配置。
所以,如果你使用Emacs,你的.emacs文件里有什么呢?
我的.emacs文件现在非常简单,只包含:
(global-font-lock-mode 1)
你认为哪些设置是有用的呢?
(defun moz-connect()
(interactive)
(make-comint "moz-buffer" (cons "127.0.0.1" "4242"))
(global-set-key "\C-x\C-g" '(lambda ()
(interactive)
(save-buffer)
(comint-send-string "*moz-buffer*" "this.BrowserReload()\n"))))
我试图保持我的.emacs文件有组织性。配置始终是一个不断改进的过程,但我开始对整体结构感到满意。
所有的东西都在~/.elisp下,这是一个受版本控制的目录(如果您感兴趣,我使用git)。~/.emacs只是指向~/.elisp/dotemacs,它本身只加载~/.elisp/cfg/init。该文件通过require导入各种配置文件。这意味着配置文件需要像模式一样运行:它们导入所依赖的内容,并在文件末尾提供自己,例如(provide 'my-ibuffer-cfg)。我为在配置中定义的所有标识符添加前缀my-。
我根据模式/主题/任务的关系来组织配置,而不是根据它们的技术含义,例如,我没有单独的配置文件定义所有按键绑定或面部特征。
我的init.el定义了以下钩子,以确保Emacs在保存时重新编译配置文件(编译的Elisp加载速度更快,但我不想手动执行此步骤):
;; byte compile config file if changed
(add-hook 'after-save-hook
'(lambda ()
(when (string-match
(concat (expand-file-name "~/.elisp/cfg/") ".*\.el$")
buffer-file-name)
(byte-compile-file buffer-file-name))))
~/.elisp
的目录结构:
~/.elisp/todo.org
:Org-mode文件,用于跟踪仍需完成的事项(包括愿望清单项目)。
~/.elisp/dotemacs
:指向~/.emacs
的符号链接目标,加载~/.elisp/cfg/init
。
~/.elisp/cfg
:我的自定义配置文件。
~/.elisp/modes
:仅由单个文件组成的模式。
~/.elisp/packages
:具有Lisp、文档和可能的资源文件的复杂模式。~/.elisp/packages/foobar-0.1.3
是该软件包的根目录。子目录lisp
保存所有Lisp文件,而info
则用于文档。~/.elisp/packages/foobar
是一个符号链接,指向当前使用的软件包版本,这样当我更新某些内容时就不需要更改配置文件了。对于某些软件包,我会保留~/.elisp/packages/foobar.installation
文件,其中记录了安装过程的笔记。出于性能原因,我会编译所有新安装软件包中的elisp文件,如果默认情况下不是这样的话。以下是我自己的一些内容:
在ISO 8601格式中插入日期:
(defun insertdate ()
(interactive)
(insert (format-time-string "%Y-%m-%d")))
(global-set-key [(f5)] 'insertdate)
对于C++程序员,创建一个类的框架(类名将与文件名(不带扩展名)相同):
(defun createclass ()
(interactive)
(setq classname (file-name-sans-extension (file-name-nondirectory buffer-file-name)))
(insert
"/**
* " classname".h
*
* Author: Your Mom
* Modified: " (format-time-string "%Y-%m-%d") "
* Licence: GNU GPL
*/
#ifndef "(upcase classname)"
#define "(upcase classname)"
class " classname "
{
public:
"classname"();
~"classname"();
private:
};
#endif
"))
自动创建闭合括号:
(setq skeleton-pair t)
(setq skeleton-pair-on-word t)
(global-set-key (kbd "[") 'skeleton-pair-insert-maybe)
(global-set-key (kbd "(") 'skeleton-pair-insert-maybe)
(global-set-key (kbd "{") 'skeleton-pair-insert-maybe)
(global-set-key (kbd "<") 'skeleton-pair-insert-maybe)
这个块对我来说非常重要:
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
我从来没有很清楚这两者之间的区别,可能是一种货物崇拜...
我使用paredit来方便地处理(e)lisp,并使用ido-mode补全minibuffer。
回答这个问题很难,因为每个人使用Emacs的目的都不同。
此外,更好的做法可能是简化你的dotemacs。由于Easy Customization Interface在Emacs的模式中得到了广泛支持,您应该将所有自定义存储在custom-file
中(它可以是dotemacs中的一个单独位置),并且对于dotemacs, 只放置加载路径设置、包需求、钩子和按键绑定。一旦开始使用Emacs Starter Kit,一整个有用的设置集合也可以从您的dotemacs中删除。
我使用webjump设置了一些方便的快捷方式到网页和搜索。
(require 'webjump)
(global-set-key [f2] 'webjump)
(setq webjump-sites
(append '(
("Reddit Search" .
[simple-query "www.reddit.com" "http://www.reddit.com/search?q=" ""])
("Google Image Search" .
[simple-query "images.google.com" "images.google.com/images?hl=en&q=" ""])
("Flickr Search" .
[simple-query "www.flickr.com" "flickr.com/search/?q=" ""])
("Astar algorithm" .
"http://www.heyes-jones.com/astar")
)
webjump-sample-sites))
这里有关于此如何工作的博客文章
http://justinsboringpage.blogspot.com/2009/02/search-reddit-flickr-and-google-from.html
我也推荐这些:
(setq visible-bell t) ; no beeping
(setq transient-mark-mode t) ; visually show region
(setq line-number-mode t) ; show line numbers
(setq global-font-lock-mode 1) ; everything should use fonts
(setq font-lock-maximum-decoration t)
我还去掉了一些多余的GUI元素
(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)))
(put 'erase-buffer 'disabled nil)
(put 'downcase-region 'disabled nil)
(set-variable 'visible-bell t)
(set-variable 'tool-bar-mode nil)
(set-variable 'menu-bar-mode nil)
(setq load-path (cons (expand-file-name "/usr/share/doc/git-core/contrib/emacs") load-path))
(require 'vc-git)
(when (featurep 'vc-git) (add-to-list 'vc-handled-backends 'git))
(require 'git)
(autoload 'git-blame-mode "git-blame"
"Minor mode for incremental blame for Git." t)
我的emacs配置多年来已经变得相当庞大,我在那里有很多对我有用的东西,但如果我只能选择两个函数,那可能就是这两个。
定义C-x UP和C-x DOWN以移动当前行或向下移动,同时保持光标在正确的位置:
;Down/UP the current line
(global-set-key '[(control x) (up)] 'my-up-line)
(global-set-key '[(control x) (down)] 'my-down-line)
(defun my-down-line()
(interactive)
(let ((col (current-column)))
(forward-line 1)
(transpose-lines 1)
(forward-line -1)
(forward-char col)
)
)
(defun my-up-line()
(interactive)
(let ((col (current-column)))
(transpose-lines 1)
(forward-line -2)
(forward-char col)
)
)