我最近换了几次计算机,在某个地方我丢失了我的.emacs.我正在尝试再次构建它,但是当我在它时,我想我会选择其他人使用的其他好的配置.
那么,如果你使用Emacs,你的 .emacs中有什么?
我现在非常贫瘠,仅包含:
全局字体锁模式! (global-font-lock-mode 1)
关于缩进,制表符和空格的个人偏好.
使用cperl-mode而不是perl-mode.
编译的快捷方式.
你认为什么有用?
使用最终的dotfiles网站.在这里添加'.emacs'.阅读其他人的'.emacs'.
我最喜欢的片段.最终的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 `(("\\" (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)))
我有这个改变yes
或no
提示y
或n
提示:
(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))))))
有一点可以证明是非常有用的:在它变得太大之前,尝试将它分成多个文件以执行各种任务:我的.emacs只是设置我的加载路径和加载一堆文件 - 我已经得到了我所有的模式 - 特定设置mode-configs.el
,键绑定keys.el
等等
我的.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>等缓冲区名称更改为当多个文件具有相同名称时,使用尽可能多的文件整个路径来更清晰明确的名称.
这是关于它...其余的是非常标准的东西,我相信每个人都知道.
这不是整个套件和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也很长,所以它会让答案不太可读.无论如何,如果你愿意我可以发给你.
我还建议你阅读这篇文章: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)) ;; "M-x reload-buffer" will revert-buffer without requiring confirmation (defun reload-buffer () "revert-buffer without confirmation" (interactive) (revert-buffer t t))
刷新您在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结合使用
您可以在我的网站上找到我的配置(包括html和tar'ed存档).它包含许多不同模式的设置