什么是你的.emacs?

最近我换了几次电脑,并在某个地方丢失了我的.emacs。 我试图再次build立它,但是当我在这个时候,我想我会select其他人使用的其他好的configuration。

那么,如果你使用Emacs, 你的 .emacs中有什么?

我现在是非常贫瘠的,只包含:

  1. 全局字体locking模式! (global-font-lock-mode 1)
  2. 我个人对缩进,制表符和空格的偏好。
  3. 使用cperl模式而不是perl模式。
  4. 编译的捷径。

你觉得有用吗?

使用最终的dotfiles网站 。 在这里添加你的'.emacs'。 阅读其他人的“.emacs”。

我最喜欢的片段。 在Emacs眼睛糖果的终极:

 ;; real lisp hackers use the lambda character ;; courtesy of stefan monnier on cll (defun sm-lambda-mode-hook () (font-lock-add-keywords nil `(("\\<lambda\\>" (0 (progn (compose-region (match-beginning 0) (match-end 0) ,(make-char 'greek-iso8859-7 107)) nil)))))) (add-hook 'emacs-lisp-mode-hook 'sm-lambda-mode-hook) (add-hook 'lisp-interactive-mode-hook 'sm-lamba-mode-hook) (add-hook 'scheme-mode-hook 'sm-lambda-mode-hook) 

所以编辑lisp / scheme时你会看到以下内容:

 (global-set-key "^Cr" '(λ () (interactive) (revert-buffer tt nil))) 

我有这个改变yesno提示yn提示:

 (fset 'yes-or-no-p 'y-or-np) 

我有这些来启动Emacs,而没有从这个问题中得到那么多的“夸奖”。

 (setq inhibit-startup-echo-area-message t) (setq inhibit-startup-message t) 

Steve Yegge的function是将你正在编辑的文件和相应的缓冲区重命名:

 (defun rename-file-and-buffer (new-name) "Renames both current buffer and file it's visiting to NEW-NAME." (interactive "sNew name: ") (let ((name (buffer-name)) (filename (buffer-file-name))) (if (not filename) (message "Buffer '%s' is not visiting a file!" name) (if (get-buffer new-name) (message "A buffer named '%s' already exists!" new-name) (progn (rename-file name new-name 1) (rename-buffer new-name) (set-visited-file-name new-name) (set-buffer-modified-p nil)))))) 

有一件事情可以certificate是非常有用的:在它变得太大之前,尝试把它分成多个文件来完成各种任务:我的.emacs只是设置我的加载path并加载一堆文件 – 我已经得到了所有的模式 – mode-configs.el特定设置, mode-configs.el等中的键绑定

我的.emacs只有127行,这里是最有用的小片段:

 ;; keep backup files neatly out of the way in .~/ (setq backup-directory-alist '(("." . ".~"))) 

这使我find的*〜文件变成了一个特殊的目录,在这种情况下〜

 ;; uniquify changes conflicting buffer names from file<2> etc (require 'uniquify) (setq uniquify-buffer-name-style 'reverse) (setq uniquify-separator "/") (setq uniquify-after-kill-buffer-p t) ; rename after killing uniquified (setq uniquify-ignore-buffers-re "^\\*") ; don't muck with special buffers 

这设置了独特的function,可以将多个文件具有相同名称的那些丑陋的文件<2>等缓冲区名称更改为使用文件的整个path尽可能多的整齐无瑕的名称。

这就是它…其余的是非常标准的东西,我敢肯定每个人都知道。

这不是整个工具包和kaboodle,但它是我收集的一些更有用的片段:

 (defadvice show-paren-function (after show-matching-paren-offscreen activate) "If the matching paren is offscreen, show the matching line in the echo area. Has no effect if the character before point is not of the syntax class ')'." (interactive) (let ((matching-text nil)) ;; Only call `blink-matching-open' if the character before point ;; is a close parentheses type character. Otherwise, there's not ;; really any point, and `blink-matching-open' would just echo ;; "Mismatched parentheses", which gets really annoying. (if (char-equal (char-syntax (char-before (point))) ?\)) (setq matching-text (blink-matching-open))) (if (not (null matching-text)) (message matching-text)))) ;;;;;;;;;;;;;;; ;; UTF-8 ;;;;;;;;;;;;;;;;;;;; ;; set up unicode (prefer-coding-system 'utf-8) (set-default-coding-systems 'utf-8) (set-terminal-coding-system 'utf-8) (set-keyboard-coding-system 'utf-8) ;; This from a japanese individual. I hope it works. (setq default-buffer-file-coding-system 'utf-8) ;; From Emacs wiki (setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING)) ;; Wwindows clipboard is UTF-16LE (set-clipboard-coding-system 'utf-16le-dos) (defun jonnay-timestamp () "Spit out the current time" (interactive) (insert (format-time-string "%Y-%m-%d"))) (defun jonnay-sign () "spit out my name, email and the current time" (interactive) (insert "-- Jonathan Arkell (jonathana@criticalmass.com)") (jonnay-timestamp)) ;; Cygwin requires some seriosu setting up to work the way i likes it (message "Setting up Cygwin...") (let* ((cygwin-root "c:") (cygwin-bin (concat cygwin-root "/bin")) (gambit-bin "/usr/local/Gambit-C/4.0b22/bin/") (snow-bin "/usr/local/snow/current/bin") (mysql-bin "/wamp/bin/mysql/mysql5.0.51a/bin/")) (setenv "PATH" (concat cygwin-bin ";" ; snow-bin ";" gambit-bin ";" mysql-bin ";" ".;") (getenv "PATH")) (setq exec-path (cons cygwin-bin exec-path))) (setq shell-file-name "bash") (setq explicit-shell-file-name "bash") (require 'cygwin-mount) (cygwin-mount-activate) (message "Setting up Cygwin...Done") ; Completion isn't perfect, but close (defun my-shell-setup () "For Cygwin bash under Emacs 20+" (setq comint-scroll-show-maximum-output 'this) (setq comint-completion-addsuffix t) (setq comint-eol-on-send t) (setq w32-quote-process-args ?\") (make-variable-buffer-local 'comint-completion-addsuffix)) (setq shell-mode-hook 'my-shell-setup) (add-hook 'emacs-startup-hook 'cygwin-shell) ; Change how home key works (global-set-key [home] 'beginning-or-indentation) (substitute-key-definition 'beginning-of-line 'beginning-or-indentation global-map) (defun yank-and-down () "Yank the text and go down a line." (interactive) (yank) (exchange-point-and-mark) (next-line)) (defun kill-syntax (&optional arg) "Kill ARG sets of syntax characters after point." (interactive "p") (let ((arg (or arg 1)) (inc (if (and arg (< arg 0)) 1 -1)) (opoint (point))) (while (not (= arg 0)) (if (> arg 0) (skip-syntax-forward (string (char-syntax (char-after)))) (skip-syntax-backward (string (char-syntax (char-before))))) (setq arg (+ arg inc))) (kill-region opoint (point)))) (defun kill-syntax-backward (&optional arg) "Kill ARG sets of syntax characters preceding point." (interactive "p") (kill-syntax (- 0 (or arg 1)))) (global-set-key [(control shift y)] 'yank-and-down) (global-set-key [(shift backspace)] 'kill-syntax-backward) (global-set-key [(shift delete)] 'kill-syntax) (defun insert-file-name (arg filename) "Insert name of file FILENAME into buffer after point. Set mark after the inserted text. Prefixed with \\[universal-argument], expand the file name to its fully canocalized path. See `expand-file-name'." ;; Based on insert-file in Emacs -- ashawley 2008-09-26 (interactive "*P\nfInsert file name: ") (if arg (insert (expand-file-name filename)) (insert filename))) (defun kill-ring-save-filename () "Copy the current filename to the kill ring" (interactive) (kill-new (buffer-file-name))) (defun insert-file-name () "Insert the name of the current file." (interactive) (insert (buffer-file-name))) (defun insert-directory-name () "Insert the name of the current directory" (interactive) (insert (file-name-directory (buffer-file-name)))) (defun jonnay-toggle-debug () "Toggle debugging by toggling icicles, and debug on error" (interactive) (toggle-debug-on-error) (icicle-mode)) (defvar programming-modes '(emacs-lisp-mode scheme-mode lisp-mode c-mode c++-mode objc-mode latex-mode plain-tex-mode java-mode php-mode css-mode js2-mode nxml-mode nxhtml-mode) "List of modes related to programming") ; Text-mate style indenting (defadvice yank (after indent-region activate) (if (member major-mode programming-modes) (indent-region (region-beginning) (region-end) nil))) 

我有很多已经提到的其他人,但是在我看来这是绝对必要的:

 (transient-mark-mode 1) ; makes the region visible (line-number-mode 1) ; makes the line number show up (column-number-mode 1) ; makes the column number show up 

你可以看这里: http : //www.dotemacs.de/

而且我的.emacs也很长,所以它会使答案不太可读。 无论如何,如果你愿意,我可以把它寄给你。

另外我会build议你阅读这个: http : //steve.yegge.googlepages.com/my-dot-emacs-file

以下是我所依赖的一些关键映射:

 (global-set-key [(control \,)] 'goto-line) (global-set-key [(control \.)] 'call-last-kbd-macro) (global-set-key [(control tab)] 'indent-region) (global-set-key [(control j)] 'join-line) (global-set-key [f1] 'man) (global-set-key [f2] 'igrep-find) (global-set-key [f3] 'isearch-forward) (global-set-key [f4] 'next-error) (global-set-key [f5] 'gdb) (global-set-key [f6] 'compile) (global-set-key [f7] 'recompile) (global-set-key [f8] 'shell) (global-set-key [f9] 'find-next-matching-tag) (global-set-key [f11] 'list-buffers) (global-set-key [f12] 'shell) 

其他一些其他的东西,主要用于C ++开发:

 ;; Use C++ mode for .h files (instead of plain-old C mode) (setq auto-mode-alist (cons '("\\.h$" . c++-mode) auto-mode-alist)) ;; Use python-mode for SCons files (setq auto-mode-alist (cons '("SConstruct" . python-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("SConscript" . python-mode) auto-mode-alist)) ;; Parse CppUnit failure reports in compilation-mode (require 'compile) (setq compilation-error-regexp-alist (cons '("\\(!!!FAILURES!!!\nTest Results:\nRun:[^\n]*\n\n\n\\)?\\([0-9]+\\)) test: \\([^(]+\\)(F) line: \\([0-9]+\\) \\([^ \n]+\\)" 5 4) compilation-error-regexp-alist)) ;; Enable cmake-mode from http://www.cmake.org/Wiki/CMake_Emacs_mode_patch_for_comment_formatting (require 'cmake-mode) (setq auto-mode-alist (append '(("CMakeLists\\.txt\\'" . cmake-mode) ("\\.cmake\\'" . cmake-mode)) auto-mode-alist)) ;; "Mx reload-buffer" will revert-buffer without requiring confirmation (defun reload-buffer () "revert-buffer without confirmation" (interactive) (revert-buffer tt)) 

刷新您在Emacs中编辑的网页

 (defun moz-connect() (interactive) (make-comint "moz-buffer" (cons "127.0.0.1" "4242")) (global-set-key "\Cx\Cg" '(lambda () (interactive) (save-buffer) (comint-send-string "*moz-buffer*" "this.BrowserReload()\n")))) 

http://hyperstruct.net/projects/mozlab结合使用;

你可以在我的网站上find我的configuration(包括HTML和tar格式的档案)。 它包含了很多不同模式的设置

这块对我来说是最重要的:

 (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) 

不过,我从来没有清楚过这些之间的区别。 货物崇拜,我猜…

我试图保持我的.emacs组织。 configuration将一直在进行中,但我开始对整体结构感到满意。

所有的东西都在~/.elisp ,一个在版本控制下的目录(如果感兴趣,我使用git)。 ~/.emacs简单地指向~/.elisp/dotemacs ,它本身只是加载~/.elisp/cfg/init 。 该文件依次通过require导入各种configuration文件。 这意味着configuration文件需要像模式那样工作:它们导入他们依赖的东西,并且在文件末尾provide它们自己,例如(provide 'my-ibuffer-cfg) 。 我在我的configuration中使用my-作为前缀标识符。

我组织模式/主题/任务的configuration,而不是他们的技术含义,例如,我没有一个单独的configuration文件,其中所有的键绑定或面被定义。

我的init.el定义了下面的钩子来确保Emacs在保存时重新编译configuration文件(编译后的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 :组织模式文件,其中我跟踪仍然需要完成的东西(+愿望清单项目)。

~/.elisp/dotemacs~/.emacs符号链接目标,加载~/.elisp/cfg/init

~/.elisp/cfg :我自己的configuration文件。

~/.elisp/modes :只包含一个文件的模式。

~/.elisp/packages :与lisp,文档和可能的资源文件复杂的模式。

我使用GNU Emacs,该版本没有真正的软件包支持。 因此,我手动组织它们,通常是这样的: ~/.elisp/packages/foobar-0.1.3是包的根目录。 子目录lisp保存所有的lisp文件, info就是文件所在的位置。 ~/.elisp/packages/foobar是一个符号链接,指向当前使用的软件包版本,以便在更新内容时不需要更改configuration文件。 对于某些软件包,我保留一个~/.elisp/packages/foobar.installation文件,其中包含有关安装过程的注释。 出于性能原因,我编译新安装的软件包中的所有elisp文件,如果不是默认情况下。

这里有几个我自己的东西:

以ISO 8601格式插入date:

 (defun insertdate () (interactive) (insert (format-time-string "%Y-%m-%d"))) (global-set-key [(f5)] 'insertdate) 

对于C ++程序员来说,创build一个类框架(类的名字将和没有扩展名的文件名相同):

 (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 ")) 

自动创build右括号:

 (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) 

我使用paredit轻松(e)lisp处理和ido模式minibuffer完成。

这个问题很难回答,因为每个人都使用Emacs来达到非常不同的目的。

此外,更好的做法可能是吻你的dotemacs。 由于Easy Customization Interface在Emacs的模式中得到了广泛的支持,所以你应该把所有的定制存储在你的custom-file (这可能是你的dotemacs中的一个独立的地方),并且对于dotemacs来说 ,只需要加载path设置,需要,钩子和键绑定。 一旦你开始使用Emacs入门套件 ,一整套有用的设置也可能从你的dotemacs中删除。

请参阅EmacsWiki的DotEmacs类别。 它提供了很多指向这个问题的页面的链接。

 (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) 

我设置了一些方便的网页快捷方式和search使用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))) 

一行修改加载path一行加载我的init库一行加载我的emacs init文件

当然,“emacs初始化文件”是相当多的,每个特定的东西,加载一个确定性的顺序。

emacs-starter-kit作为基础,然后添加了vimpulse.elwhitespace.elyasnippetnewsticker.elnewsticker.el

在我的〜/ .emacs.d / $ USERNAME.el(dbr.el)文件中:

 (add-to-list 'load-path (concat dotfiles-dir "/vendor/")) ;; Snippets (add-to-list 'load-path "~/.emacs.d/vendor/yasnippet/") (require 'yasnippet) (yas/initialize) (yas/load-directory "~/.emacs.d/vendor/yasnippet/snippets") ;; TextMate module (require 'textmate) (textmate-mode 'on) ;; Whitespace module (require 'whitespace) (add-hook 'ruby-mode-hook 'whitespace-mode) (add-hook 'python-mode-hook 'whitespace-mode) ;; Misc (flyspell-mode 'on) (setq viper-mode t) (require 'viper) (require 'vimpulse) ;; IM (eval-after-load 'rcirc '(require 'rcirc-color)) (setq rcirc-default-nick "_dbr") (setq rcirc-default-user-name "_dbr") (setq rcirc-default-user-full-name "_dbr") (require 'jabber) ;;; Google Talk account (custom-set-variables '(jabber-connection-type (quote ssl)) '(jabber-network-server "talk.google.com") '(jabber-port 5223) '(jabber-server "mysite.tld") '(jabber-username "myusername")) ;; Theme (color-theme-zenburn) ;; Key bindings (global-set-key (kbd "Mz") 'undo) (global-set-key (kbd "Ms") 'save-buffer) (global-set-key (kbd "MSz") 'redo) 

总是保存我的configuration在svn http://my-trac.assembla.com/ez-conf/browser/emacs.d

看完这个之后,我觉得只需要一个简单的网站就可以了.emacs最好的修改。 随意张贴并在这里投票:

http://dotemacs.slinkset.com/

我是新来的emacs,在我的.emacs文件中

  • 缩进configuration
  • 颜色的主题
  • PHP模式,咖啡模式和js2模式
  • ido模式

FWIW,我的.emacs在这里:

http://svn.red-bean.com/repos/kfogel/trunk/.emacs

很多东西: https : //github.com/tavisrudd/emacs.d

el-get使pipe理它和依赖关系变得更容易: https : //github.com/tavisrudd/emacs.d/blob/master/dss-init-el-get.el

对于Scala编码器

 ;; Load the ensime lisp code... http://github.com/aemoncannon/ensime (add-to-list 'load-path "ENSIME_ROOT/elisp/") (require 'ensime) ;; This step causes the ensime-mode to be started whenever ;; scala-mode is started for a buffer. You may have to customize this step ;; if you're not using the standard scala mode. (add-hook 'scala-mode-hook 'ensime-scala-mode-hook) ;; MINI HOWTO: ;; Open .scala file. Mx ensime (once per project) 

我的emacsconfiguration已经成长了很多年,我在那里有很多有用的东西,但如果我有两个function,它可能会是那些。

定义Cx UP和Cx 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) ) )