53

我最近换了几次电脑,在某个地方我丢失了我的 .emacs。我正在尝试重新构建它,但是当我这样做时,我想我会选择其他人使用的其他好的配置。

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

我的现在很贫瘠,只包含:

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

你觉得什么有用?

4

29 回答 29

45

使用终极 dotfiles 站点。在此处添加您的“.emacs”。阅读其他人的“.emacs”。

于 2008-10-18T13:26:25.637 回答
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)))
于 2008-10-01T14:58:29.483 回答
21

我有这个要更改yesno提示yn提示:

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

我有这些来启动 Emacs,而没有从这个问题中得到这么多“大张旗鼓” 。

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

以及Steve Yegge重命名您正在编辑的文件及其相应缓冲区的功能:

(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))))))
于 2008-10-01T10:23:22.437 回答
18

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

于 2008-10-05T22:01:33.043 回答
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 ,它将您在多个文件具有相同名称时获得的那些丑陋的文件 <2> 等缓冲区名称更改为使用尽可能多的文件整个路径的更简洁明确的名称。

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

于 2009-05-10T13:13:44.703 回答
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)))
于 2008-09-30T20:38:55.803 回答
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
于 2008-10-18T04:44:18.140 回答
8

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

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

另外,我建议您阅读以下内容:http ://steve.yegge.googlepages.com/my-dot-emacs-file

于 2008-09-30T17:31:15.113 回答
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))
于 2008-09-30T17:37:39.063 回答
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结合使用

于 2008-10-01T17:00:08.753 回答
5

您可以在我的网站上找到我的配置(在 html 和 tar'ed 存档中)。它包含许多不同模式的设置

于 2008-11-04T08:47:14.637 回答
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)

不过,我一直不清楚它们之间的区别。货物崇拜,我猜...

于 2008-10-18T04:50:56.253 回答
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:组织模式文件,我在其中跟踪仍然需要完成的事情(+愿望清单项目)。

~/.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 文件,默认情况下不是这种情况。

于 2010-02-16T22:48:24.780 回答
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)
于 2010-04-15T06:06:37.493 回答
3

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

于 2008-09-30T20:48:07.233 回答
3

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

此外,更好的做法可能是亲吻你的 dotmacs。由于Emacs 模式广泛支持Easy Customization Interface,因此您应该将所有自定义存储在您的custom-file(可能是 dotmacs 中的一个单独位置)中,对于dotmacs,仅将加载路径设置、包要求、挂钩放入其中, 和键绑定。一旦你开始使用Emacs Starter Kit,一大堆有用的设置也可能会从你的 dotmacs 中删除。

于 2009-04-15T06:15:55.413 回答
3

请参阅 EmacsWiki 的DotEmacs类别。它提供了许多指向解决此问题的页面的链接。

于 2011-10-28T21:24:23.030 回答
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)
于 2008-09-30T17:29:33.713 回答
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)))
于 2009-02-14T21:41:54.543 回答
0

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

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

于 2009-02-26T10:47:36.020 回答
0

emacs-starter-kit作为基础,然后我添加了 .. vimpulse.elwhitespace.elyasnippet和.textmate.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)
于 2009-05-10T14:00:34.640 回答
0

始终将我的配置保存在 svn http://my-trac.assembla.com/ez-conf/browser/emacs.d

于 2009-05-10T14:11:50.790 回答
0

读完这篇文章后,我认为最好有一个简单的站点来进行最好的 .emacs 修改。随时在这里发布和投票:

http://dotemacs.slinkset.com/

于 2009-12-10T18:00:01.713 回答
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)
于 2010-10-22T20:59:53.607 回答
0

https://b7j0c.org/stuff/dotemacs.html

于 2011-01-17T16:44:53.063 回答
0

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

  • 缩进配置
  • 颜色主题
  • php模式、咖啡模式和js2模式
  • 偶像模式
于 2011-07-19T06:04:33.690 回答
0

FWIW,我的 .emacs 在这里:

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

于 2011-08-21T00:12:46.853 回答
0

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

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

于 2011-10-19T00:49:02.117 回答
0

这些年来,我的 emacs 配置已经变得相当大,那里有很多对我有用的东西,但如果我有两个功能,那可能就是那些功能了。

定义 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)
    )
  )
于 2012-04-29T16:45:39.593 回答