你的.emacs里有什么?

时间:2008-09-30 17:27:09

标签: emacs text-editor elisp dot-emacs

我最近几次切换了计算机,并且在某处我丢失了我的.emacs。我正在尝试再次构建它,但是当我接受它时,我想我会选择其他人使用的其他良好配置。

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

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

  1. 全球字体锁定模式! (global-font-lock-mode 1)
  2. 关于缩进,标签和空格的个人偏好。
  3. 使用cperl-mode而不是perl-mode。
  4. 编译的快捷方式。
  5. 您认为有用的是什么?

29 个答案:

答案 0 :(得分:45)

使用ultimate dotfiles site。在这里添加'.emacs'。阅读其他人的'.emacs'。

答案 1 :(得分:27)

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

;; real lisp hackers use the lambda character
;; courtesy of stefan monnier on c.l.l
(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 t t nil)))

答案 2 :(得分:21)

我要将yesno提示更改为yn提示:

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

我有这些来启动Emacs而没有从this question得到的那些“大肆宣传”。

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

并且Steve Yegge's可以重命名您正在编辑的文件及其相应的缓冲区:

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

答案 3 :(得分:18)

有一件事可以证明是非常有用的:在它变得太大之前,尝试将它分成多个文件以执行各种任务:我的.emacs只设置我的加载路径和加载一堆文件 - 我已经全部mode-configs.el中的模式特定设置,keys.el中的键绑定等等

答案 4 :(得分:15)

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

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

这使得我发现杂乱的目录的*〜文件进入一个特殊的目录,在这种情况下.~

;; 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

这设置了uniquify,它改变那些丑陋的文件&lt; 2&gt;等多个文件具有相同名称的缓冲区名称,使用尽可能多的整个文件路径,以及更加简洁明确的名称。

就是这样......剩下的就是相当标准的东西,我相信每个人都知道。

答案 5 :(得分:9)

这不是整个套件和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)))

答案 6 :(得分:9)

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

(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

答案 7 :(得分:8)

您可以在此处查看:http://www.dotemacs.de/

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

另外,我建议你阅读:http://steve.yegge.googlepages.com/my-dot-emacs-file

答案 8 :(得分:5)

从Emacs中刷新您正在编辑的网页

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

http://hyperstruct.net/projects/mozlab

结合使用

答案 9 :(得分:5)

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

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

;; "M-x reload-buffer" will revert-buffer without requiring confirmation
(defun reload-buffer ()
  "revert-buffer without confirmation"
  (interactive)
  (revert-buffer t t))

答案 10 :(得分:5)

您可以在my site上找到我的配置(包括html&amp; in tar'ed存档)。它包含许多不同模式的设置

答案 11 :(得分:4)

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

(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)
但是,我从来都不清楚它们之间的区别。货物崇拜,我猜......

答案 12 :(得分:4)

我尽量保持我的.emacs有条不紊。配置将始终是一项正在进行的工作,但我开始对整体结构感到满意。

所有内容都在~/.elisp下,一个受版本控制的目录(我使用git,如果感兴趣的话)。 ~/.emacs只是指向~/.elisp/dotemacs,它本身只会加载~/.elisp/cfg/init。该文件依次通过require导入各种配置文件。这意味着配置文件需要表现得像模式:它们导入它们所依赖的内容,并且它们provide本身位于文件的末尾,例如: (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,文档和可能的资源文件的复杂模式。

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

答案 13 :(得分:4)

这是我自己的一些东西:

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

答案 14 :(得分:3)

我使用paredit轻松(e)lisp处理和ido模式迷你缓冲区完成。

答案 15 :(得分:3)

很难回答这个问题,因为每个人都将Emacs用于非常不同的目的。

此外,更好的做法可能是亲吻您的dotemacs。由于Easy Customization Interface在Emacs的模式中得到广泛支持,因此您应该将所有自定义内容存储在custom-file(可能是您的dotemacs中的单独位置),以及dotemacs中。在它中只加载路径设置,包需要,挂钩和键绑定。一旦开始使用Emacs Starter Kit,您的dotemacs也可能会删除一大堆有用的设置。

答案 16 :(得分:3)

请参阅EmacsWiki的DotEmacs类别。它提供了很多链接到解决这个问题的网页。

答案 17 :(得分:1)

我使用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)))

答案 18 :(得分: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)

答案 19 :(得分:0)

我的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)
    )
  )

答案 20 :(得分:0)

答案 21 :(得分:0)

FWIW,我的.emacs在这里:

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

答案 22 :(得分:0)

我是emacs的新手,在我的.emacs文件中有

  • 缩进配置
  • 颜色主题
  • php模式,咖啡模式和js2模式
  • ido mode

答案 23 :(得分:0)

答案 24 :(得分:0)

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. M-x ensime (once per project)

答案 25 :(得分:0)

阅读完本文后,我认为最好有一个简单的网站,以便进行最佳的.emacs修改。欢迎在此发布并投票:

http://dotemacs.slinkset.com/

答案 26 :(得分:0)

始终在svn http://my-trac.assembla.com/ez-conf/browser/emacs.d

中保存我的配置

答案 27 :(得分:0)

emacs-starter-kit作为基础,然后我添加了.. vimpulse.elwhitespace.elyasnippettextmate.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 "M-z") 'undo)
(global-set-key (kbd "M-s") 'save-buffer)
(global-set-key (kbd "M-S-z") 'redo)

答案 28 :(得分:0)

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

当然,“emacs init文件”非常多,每个特定的东西都有一个确定的顺序加载。