.emacs中有什么?

时间:2020-03-06 14:56:09  来源:igfitidea点击:

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

因此,如果我们使用Emacs,则.emacs中包含什么?

我的矿山目前非常贫瘠,仅包含:

  • 全局字体锁定模式! (全局字体锁定模式1)
  • 我在缩进,制表符和空格方面的个人偏好。
  • 使用cperl-mode而不是perl-mode。
  • 编译的快捷方式。

我们认为有什么用?

解决方案

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

我们可以在这里查看: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))

这不是全部工具包和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)))

我使用paredit进行简单的(e)lisp处理和ido-mode minibuffer完成。

我有这个将y或者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终极眼霜:

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

要刷新我们正在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结合使用

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

我已经提到了很多其他内容,但是我认为这些绝对是必要的:

(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

此块对我来说最重要:

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

不过,我从未清楚两者之间的区别。货物崇拜,我想...

使用最终的dotfiles网站。在此处添加" .emacs"。阅读其他人的" .emacs"。

我们可以在我的网站上找到我的配置(包括html和tar存档)。它包含许多用于不同模式的设置

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

一行修改加载路径
一行加载我的初始化库
一行来加载我的emacs初始化文件

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

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

此外,更好的做法可能是亲吻dotemacs。由于Emacs模式中广泛支持Easy Customization Interface,因此我们应将所有自定义存储在" custom-file"(可能在dotemacs中的单独位置)中,对于dotemacs,仅将其加载路径设置中即可。 ,包要求,钩子和键绑定。一旦开始使用Emacs入门套件,也可能会从dotemacs中删除一整套有用的设置。

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

这设置了唯一性,当多个文件具有相同的名称时,将使用这些文件的整个路径来更改它们,从而更改丑陋的file <2>等缓冲区名称。

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

以emacs-starter-kit为基础,然后添加了.vimpulse.el,whitespace.el,yasnippet,textmate.el和newsticker.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)

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

读完这篇文章后,我觉得最好有一个简单的网站,以进行最佳的.emacs修改。随时在此处发布帖子并对其进行投票:

http://dotemacs.slinkset.com/

我试图使我的.emacs井井有条。配置将一直在进行中,但是我开始对整体结构感到满意。

所有的东西都在〜/ .elisp下,这是一个受版本控制的目录(如果感兴趣的话,我使用git)。 ~~ .emacs只是指向〜/ .elisp / dotemacs,它本身只是加载~~ ..elisp / cfg / init。该文件又通过require导入各种配置文件。这意味着配置文件的行为必须类似于模式:它们会导入它们所依赖的内容,并在文件末尾``提供''自己的内容,例如(提供'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文件,默认情况下不是这种情况。

这是我自己的一些东西:

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

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