web-dev-qa-db-ja.com

あなたの.emacsには何が入っていますか?

最近、コンピューターを数回切り替えましたが、途中で.emacsを紛失しました。もう一度作り直そうとしていますが、その間、他の人が使っている他の良い構成を選んでみようと思いました。

したがって、Emacsを使用する場合、何が含まれていますか きみの .emacs?

鉱山は現在かなり不毛で、以下のみが含まれています。

  1. グローバルフォントロックモード! (global-font-lock-mode 1)
  2. インデント、タブ、スペースに関する私の個人的な好み。
  3. Perlモードの代わりにcperlモードを使用してください。
  4. コンパイルのショートカット。

何が役に立つと思いますか?

53
A. Rex

究極のドットファイルサイト を使用します。ここに「.emacs」を追加します。他の人の「.emacs」を読んでください。

45
bortzmeyer

私のお気に入りのスニペット。究極の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 /スキームを編集すると次のようになります。

(global-set-key "^Cr" '(λ () (interactive) (revert-buffer t t nil)))
27
Jason Dufair

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'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))))))
21
Dave Webb

非常に役立つことが証明できることの1つ:大きくなりすぎる前に、さまざまなタスクのために複数のファイルに分割してみてください:私の.emacsはロードパスを設定し、たくさんのファイルをロードします-私はすべてのモードを持っています- mode-configs.elの特定の設定、keys.elのキーバインドなど

18
jamesnvc

私の.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が設定され、複数のファイルが同じ名前の場合に取得する醜いfile <2>などのバッファ名が、ファイルのパス全体を必要なだけ使用して、よりわかりやすい名前に変更されます。

それはそれについてです...残りは誰もが知っていると確信しているかなり標準的なものです。

15
Borbus

私はすでに言及されている他の多くを持っていますが、これらは私の意見では絶対に必要です:

(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
9
Adam Crume

これはキットと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)))
9
Jonathan Arkell

あなたはここを見ることができます: http://www.dotemacs.de/

そして、私の.emacsもここに置くのはかなり長いので、答えが読みにくくなります。とにかく、あなたが望むなら、私はあなたにそれを送ることができます。

また、これを読むことをお勧めします: http://steve.yegge.googlepages.com/my-dot-emacs-file

8
avp

これが私が依存するようになったいくつかの重要なマッピングです:

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

私の構成(htmlとtar'edアーカイブの両方)は 私のサイト にあります。さまざまなモードの設定がたくさん含まれています

5
Alex Ott

Emacs内から編集しているWebページを更新するには

(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 と組み合わせて使用

5
Sard

このブロックは私にとって最も重要です:

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

しかし、私はそれらの違いについてははっきりしていません。カーゴカルト、私は推測する...

4
Chris Dolan

.emacsを整理しておくようにしています。構成は常に進行中の作業ですが、全体的な構造に満足し始めています。

すべてのものは、バージョン管理下にあるディレクトリである~/.elispの下にあります(興味がある場合は、gitを使用します)。 ~/.emacsは単に~/.elisp/dotemacsを指し、それ自体が~/.elisp/cfg/initをロードするだけです。そのファイルは、requireを介してさまざまな構成ファイルをインポートします。つまり、構成ファイルはモードのように動作する必要があります。つまり、構成ファイルは依存するものをインポートし、ファイルの最後にprovideします。 (provide 'my-ibuffer-cfg)。構成で定義されているすべての識別子の前にmy-を付けます。

技術的な意味ではなく、モード/サブジェクト/タスクに関して構成を整理します。 I しない別の設定ファイルがあり、そこにすべてキーバインディングまたは面が定義されています。

私の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ファイルをコンパイルします。デフォルト。

4
paprika

これが私自身のもののいくつかです:

ISO8601形式で日付を挿入します。

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

EmacsWikiの DotEmacs カテゴリを参照してください。この質問に対処するページへのリンクがたくさんあります。

3
Drew

私は簡単な(e)LISP処理とidoモードミニバッファー補完のためにpareditを使用しています。

3
user23932

誰もが非常に異なる目的でEmacsを使用しているため、この質問に答えるのは難しいです。

さらに、より良い方法はKISSあなたのdotemacsです。 Easy Customization Interface はEmacsのモード間で広くサポートされているので、すべてのカスタマイズをあなたのcustom-file(dotemacs内の別の場所である可能性があります)、および dotemacs の場合は、ロードパス設定、パッケージrequires、フック、およびキーバインディングのみを入力します。 Emacs Starter Kit を使い始めると、便利な設定がすべてdotemacsから削除される可能性があります。

3
Török Gábor

Webページへの便利なショートカットと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)))
1
justinhj
(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)
1
David Nehme

FWIW、私の.emacsはここにあります:

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

0
Karl Fogel

私のemacs構成は何年にもわたってかなり大きくなり、そこにはたくさんの便利なものがありますが、2つの機能があれば、おそらくそれらの機能だったでしょう。

C-xUPとC-xDOWNを定義して、現在の行を移動するか、カーソルを正しい位置に置いたまま下に移動します。

;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)
    )
  )
0
0
Brad Clawsie

emacs-starter-kit ベースとして、追加しました.. vimpulse.elwhitespace.elyasnippettextmate.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)
0
dbr

常に設定をsvnに保存してください http://my-trac.assembla.com/ez-conf/browser/emacs.d

0
ezotrank

私はemacsを初めて使用しますが、.emacsファイルには次のようなものがあります。

  • インデント構成
  • カラーテーマ
  • phpモード、コーヒーモード、js2モード
  • イド語モード
0
czizzy

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
oluies

ロードパスを修正するための1行initライブラリをロードするための1行emacsinitファイルをロードするための1行

もちろん、「emacs initファイル」は非常に多く、特定のものごとに1つずつ、決定論的な順序でロードされます。

0
Vatine

これを読んだ後、私は最高の.emacs修正のためだけに単純なサイトを持っているのが良いだろうと思いました。ここに投稿して投票してください。

http://dotemacs.slinkset.com/

0
RobKohr

たくさんのもの: https://github.com/tavisrudd/emacs.d

el-get により、それと依存関係の管理がはるかに簡単になりました: https://github.com/tavisrudd/emacs.d/blob/master/dss-init-el-get。 el

0
Tavis Rudd