2008-09-30 81 views
53

我最近換了幾次電腦,並在某個地方丟失了我的.emacs。我正在努力重新構建它,但是當我在做它時,我想我會選擇其他人使用的其他良好配置。你的.emacs中有什麼?

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

礦,現在是相當貧瘠,只含有:

  1. 全球字型鎖模式! (global-font-lock-mode 1)
  2. 我個人對縮進,製表符和空格的偏好。
  3. 使用cperl模式而不是perl模式。
  4. 編譯的快捷方式。

您認爲什麼有用?

+8

任何一個有4行.emacs文件是可疑的。 – Cheeso 2009-02-26 10:32:49

+0

@A。雷克斯:關於不失去你*的.emacs *文件......有幾個選項:最近有些人成立DVCS爲他們配置文件,這樣一個「推」和tadaaaa:免費在線備份。但我覺得有點牽強,喜歡簡單的方法:我只是我的(文本)配置文件附加到我的Gmail帳戶的郵件(我啓用POP對於Gmail,讓我得到我的電子郵件脫機備份以及) 。有趣的是我做了我*的.emacs的另一個「Gmail的備份」 *昨天:) – SyntaxT3rr0r 2011-09-09 14:23:33

回答

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) 
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)) 
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 ([email protected])") 
    (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))) 
+0

非常感謝cygwin的東西 – binOr 2008-10-27 10:18:33

+0

感謝您幫助我恢復「秀 - 括號功能,這在我以前從我的同事和我的複製監督20年前! – 2010-01-04 08:41:56

3

我使用paredit以方便(e)lisp處理和ido模式minibuffer完成。

21

我有這樣的改變yesno提示yn提示:

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

我有這方面無需如此多的「大張旗鼓」這是我從this question得到啓動Emacs。

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

所以你看即在編輯時口齒不清以下/方案:

(global-set-key "^Cr" '(λ() (interactive) (revert-buffer t t nil))) 
+4

(眼睛回滾頭,Cheeso倒了,緊張性) – Cheeso 2009-05-20 22:05:21

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

18

有一兩件事可以證明非常有用:它變得太大之前,請嘗試將其分割成不同的任務,多個文件:我的.emacs只是將我的負載路徑和負載一堆文件 - 我有我的所有特定模式的設置在mode-configs.el,鍵綁定在keys.el等等一個

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

我儘管如此,這些差異從來沒有清楚過。天上掉餡餅,我猜...

5

你可以在my site找到我的配置(在HTML &在tar'ed檔案中)。它含有大量的設置不同模式

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

一行修改負載路徑 一號線加載我的初始化庫 一號線加載我的emacs初始化文件

當然, 「emacs初始化文件」是相當多的,每一個特定的東西,加載一個確定性的順序。

3

很難回答這個問題,因爲每個人都使用Emacs的非常不同的目的。

更進一步,一個更好的做法可能會親吻你的dotemacs。由於Easy Customization Interface廣泛當中Emacs的模式支持,你應該儲存所有的自定義您的custom-file(這可能是在您dotemacs一個單獨的地方),併爲dotemacs,放在它只是負載路徑設置,包裝要求,掛鉤,和鍵綁定。一旦你開始使用Emacs Starter Kit,一整套有用的設置也可能從你的dotemacs中刪除。

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,它將那些醜陋的文件更改爲緩衝區名稱等。當多個文件具有相同的名稱時,您將獲得的緩衝區名稱變成一個更整齊明確的名稱,儘可能多地使用文件的整個路徑。

就是這樣...其餘的都是非常標準的東西,我敢肯定每個人都知道。

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

我儘量保持組織了我的.emacs。配置將一直在進行中,但我開始對整體結構感到滿意。

所有的東西都在~/.elisp之下,這是一個受版本控制的目錄(我使用git,如果感興趣的話)。 ~/.emacs只需指向~/.elisp/dotemacs,它本身只是加載~/.elisp/cfg/init。該文件依次通過require導入各種配置文件。這意味着配置文件需要像模式一樣工作:它們將它們依賴的東西以及它們本身provide本身導入到文件末尾,例如, (provide 'my-ibuffer-cfg)。我在我的配置中使用my-加上所有標識符的前綴。

我組織關於模式/主題/任務的配置,而不是其技術含義,例如,我不要有一個單獨的配置文件,其中所有鍵綁定或面被定義。

我​​定義了下面的掛鉤,以確保重新編譯的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:用口齒不清,文檔先進的模式和可能的資源文件。

我使用GNU Emacs的,該版本不具備封裝的真正支持。因此,我手動整理它們,通常是這樣的: ~/.elisp/packages/foobar-0.1.3是軟件包的根目錄。子目錄lisp包含所有lisp文件,info是文檔所在的位置。 ~/.elisp/packages/foobar是一個符號鏈接,指向當前使用的軟件包版本,以便在更新某些內容時不需要更改我的配置文件。對於某些軟件包,我保留一個~/.elisp/packages/foobar.installation文件,其中包含有關安裝過程的註釋。出於性能原因,我編譯新安裝的軟件包中的所有elisp文件,如果默認情況下不是這樣。

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

我是新來的Emacs,在我的.emacs文件有

  • 壓痕配置
  • 顏色主題
  • PHP模式,咖啡模式和js2模式
  • IDO模式
3

請參閱EmacsWiki的DotEmacs類別。它提供了很多指向這個問題的頁面的鏈接。

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