TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: What's in your .emacs file?

121 pointsby procrastinatusover 15 years ago
I recently accidentally lost my .emacs file which I'd tweaked and put together over the last 5 years. I though this would be a good chance to ask you, what's in your .emacs file?

32 comments

yummyfajitasover 15 years ago
I have an emacs.d, which is a superior alternative to a .emacs.<p>The basic init.el file loads my various language modes, and some other minor modes (e.g., tempbuf-mode). It also loads a bunch of files from the "emacs.d/my_lisp" directory which contains various overrides and new functionality attached to existing modes (e.g., icicles customization, assorted one-off functions I want to add to modes). Lastly, it loads a bunch more files from my emacs.d/lisp directory which implement custom functionality.<p>For example, the current emacs M-x eshell doesn't behave the way I like. I often want multiple shells, so I've build a "ring of shells" functionality: f6 cycles through the ring of shells, C-f6 creates new shell window in the ring. I did something similar with window configurations.<p>Also, the emacs.d stores all modes which I use regularly. So when I migrate to a new computer, all I need to do is<p><pre><code> darcs get me@oldbox:emacs.d </code></pre> and tweak a few settings.
mark_hover 15 years ago
<a href="http://github.com/markhepburn/dotemacs" rel="nofollow">http://github.com/markhepburn/dotemacs</a><p>Lots of cruft (roughly 10 years worth), although I did recently start to refactor.<p>Most notable: it's fairly portable and relocatable, thanks to a snippet I cooked up (probably not original, but I haven't seen it else-where): <a href="http://everythingtastesbetterwithchilli.com/initialisation-file-portability-tweaks" rel="nofollow">http://everythingtastesbetterwithchilli.com/initialisation-f...</a> (check it out anywhere and just symlink init.el to ~/.emacs, it figures out all paths from there. It'll also load platform-specific code, if you need that).<p>I try and make it lazier by combining autoload and eval-after-load, which helps with startup time.<p>On an organisational point (still work to be done here!), init.el mostly just loads a bunch of other files, which are roughly grouped by task or mode. Github has been a huge boon, combined with submodules to track a lot of third-party extensions.<p>I don't change many key bindings (most notable is the Yegge-suggested C-w for backward-kill-word), but I do have a /lot/ of extensions installed. I'm a fairly heavy user, although almost exclusively as an editor (+ lisp or python interaction, etc) -- I don't use it as a mail client, browser, or anything along those lines. The furthest away I get is the occasional twitter or IRC usage.<p>While I'm rambling: I'd like to make all my key-binding specifications consistent. Currently I have a mix of string specifications, vectors, kbd macros, etc. Does anyone know what the canonical approach is these days? Extra reference: <a href="http://www.nongnu.org/emacs-tiny-tools/keybindings/" rel="nofollow">http://www.nongnu.org/emacs-tiny-tools/keybindings/</a> and <a href="http://www.emacswiki.org/emacs/KeyBindingNotation" rel="nofollow">http://www.emacswiki.org/emacs/KeyBindingNotation</a>
mahmudover 15 years ago
I wrote a long article and at the last paragraph, I decided to edit a sentence, I selected the "region" and pressed C-w to remove it :-(<p>For uninitiated, C-w is "yank text", i.e. cut it, and Firefox it is "close current tab without warning".
评论 #857066 未加载
评论 #856514 未加载
评论 #856486 未加载
jmhodgesover 15 years ago
I am completely surprised no one has linked to technomancy's emacs-start-kit: <a href="https://github.com/technomancy/emacs-starter-kit" rel="nofollow">https://github.com/technomancy/emacs-starter-kit</a><p>Clone that as your emacs.d, add a .el file named the same as your logged in user, and add your specific preferences there. (I like to have it include stuff in a jmhodges directory in emacs.d, of course.)<p>On that note, my own fork of it with very minor personal changes: <a href="https://github.com/jmhodges/emacs-starter-kit" rel="nofollow">https://github.com/jmhodges/emacs-starter-kit</a>
评论 #866038 未加载
scottwover 15 years ago
You'll want to check out dotfiles.com also, btw. I considered putting this in a separate link, but thought that since you asked, it wouldn't be <i>too</i> terrible to post here. There are a few things I include in every .emacs file I have across multiple shell accounts, and this is more or less the entirety of it:<p><pre><code> ;; how emacs behaves generally (setq scroll-step 1) (setq next-line-add-newlines nil) (setq search-highlight t) (setq-default indent-tabs-mode nil) ;; some niceties on the status bar (display-time) (setq column-number-mode t) (setq line-number-mode t) ;; other shortcuts (global-set-key "\C-^" 'enlarge-window) (global-set-key "\C-c\C-w" 'compare-windows) ;; fix broken backspace (global-set-key "\b" 'backward-delete-char) (global-set-key "\C-xt" 'term) ;; UTF-8 goodness (set-terminal-coding-system 'utf-8) (set-keyboard-coding-system 'utf-8) (prefer-coding-system 'utf-8) ;; I'm into Perl, but prefer cperl-mode over the default (defun modify-alist (alist-symbol key value &#38;optional search-cdr) (let ((alist (symbol-value alist-symbol))) (while alist (if (eq (if search-cdr (cdr (car alist)) (car (car alist))) key) (setcdr (car alist) value) (setq alist (cdr alist)))))) (modify-alist 'interpreter-mode-alist 'perl-mode 'cperl-mode t) (modify-alist 'auto-mode-alist 'perl-mode 'cperl-mode t) ;; the one true indentation level (setq cperl-indent-level 4)</code></pre>
评论 #857689 未加载
al3xover 15 years ago
I only periodically experiment with Emacs as my day-to-day editor, but my configuration isn't too shabby: <a href="http://github.com/al3x/emacs" rel="nofollow">http://github.com/al3x/emacs</a>
评论 #856238 未加载
lackerover 15 years ago
Most important:<p><pre><code> ;; Don't mix tabs and spaces (setq-default indent-tabs-mode nil) ;; Use "newline-and-indent" when you hit the Enter key so ;; you don't need to keep using TAB to align each line. (global-set-key "\C-m" 'newline-and-indent) ;; Get rid of the &#60;2&#62; with duplicate file names (require 'uniquify) (setq uniquify-buffer-name-style 'post-forward-angle-brackets) </code></pre> And then a whole bunch of autoload statements for different programming languages.
评论 #856639 未加载
评论 #856637 未加载
评论 #856805 未加载
radu_floricicaover 15 years ago
Pretty new to emacs, so my first move was to make it more familiar and avoid breaking my fingers:<p>;; Switch buffer<p>(global-set-key [f5] 'buffer-menu)<p>;; Save and load<p>(global-set-key [f2] 'save-buffer)<p>(global-set-key [f3] 'find-file)<p>;; Compile file<p>(global-set-key [f9] 'slime-compile-and-load-file)<p>;; Goto line<p>(global-set-key "\M-l" 'goto-line)<p>;; Go to other window<p>(global-set-key (kbd "&#60;C-tab&#62;") 'other-window)<p>;; And probably the most useful one, numpad Enter for eval line:<p>(global-set-key (kbd "&#60;kp-enter&#62;") 'slime-eval-last-expression)
justinhjover 15 years ago
Some key ones<p>(setq transient-mark-mode t) ; visually show region<p>(setq line-number-mode t) ; show line numbers<p>(setq global-font-lock-mode 1) ; everything should use font<p>(windmove-default-keybindings) ; shift-arrow key moves to window in that direction<p>I set up `webjump' to search online API documentation<p><a href="http://justinsboringpage.blogspot.com/2009/05/emacs-searching-programming-apis-with.html" rel="nofollow">http://justinsboringpage.blogspot.com/2009/05/emacs-searchin...</a><p>I like to send gmail<p><a href="http://justinsboringpage.blogspot.com/2009/02/sending-mail-with-emacs-in-windows.html" rel="nofollow">http://justinsboringpage.blogspot.com/2009/02/sending-mail-w...</a><p>I think this is the most important one<p>(setq visible-bell t) ; annoying beeps off
评论 #856803 未加载
justinweissover 15 years ago
I work mostly inside git repositories, so this has been really valuable for scoping commands to the current repository:<p><pre><code> (defun my-git-root () (if buffer-file-name (let* ((current-directory (file-name-directory buffer-file-name)) (git-directory (concat current-directory ".git"))) (while (and current-directory (not (file-exists-p git-directory))) (setq current-directory (file-name-directory (substring current-directory 0 -1))) (setq git-directory (concat current-directory ".git"))) current-directory))) </code></pre> I also hated editing system files until I added this function, which I almost definitely cribbed from somewhere:<p><pre><code> (defun sudo-find-file (file-name) (interactive "FFind file (sudo): ") (find-file (concat "/sudo::" file-name))) </code></pre> I got sick of having to context-switch to the browser when I needed to do a quick search, which is where these come in:<p><pre><code> (defun go-to-doc (base-url) (let ((default (symbol-name (symbol-at-point)))) (browse-url (concat base-url (read-string "Search term: " nil nil default))))) (defun rails-doc () (interactive) (go-to-doc "http://apidock.com/rails/search?query=")) (defun ruby-doc () (interactive) (go-to-doc "http://apidock.com/ruby/search?query=")) </code></pre> I really, really hope package.el is built-in soon:<p><pre><code> (when (load (expand-file-name "~/.emacs.d/elpa/package.el")) (package-initialize)) </code></pre> and by far the most important line in the whole file:<p><pre><code> (server-start)</code></pre>
dirtyauraover 15 years ago
My emacs setup consists of several files, a structure that I shamelessly copied from one and only Stevey Yegge, a true emacs fanatic.<p>Now, I used to work for Google and most people there let you see their own home directories and I used that as an opportunity to learn from Stevey's setup.<p>There are a lot of customization going on and I should do a separate blog post about the setup. Here are I just cherry-picked some recent configuration favorites of mine:<p><pre><code> ;; ;; Superb way to move between Emacs windows ;; Shift+arrow keys (windmove-default-keybindings) ;; Resize emacs according to the display resoluton (defun set-frame-size-according-to-resolution () (interactive) (if window-system (progn (if (&#62; (x-display-pixel-width) 1900) (add-to-list 'default-frame-alist (cons 'width 260)) (add-to-list 'default-frame-alist (cons 'width 80))) (add-to-list 'default-frame-alist (cons 'height (/ (- (x-display-pixel-height) 50) (frame-char-height)))) (add-to-list 'default-frame-alist (cons 'top 10)) (add-to-list 'default-frame-alist (cons 'left 5)))))</code></pre>
j_bakerover 15 years ago
I use anything: <a href="http://www.emacswiki.org/emacs/Anything" rel="nofollow">http://www.emacswiki.org/emacs/Anything</a><p>And then I have this in my .emacs:<p><pre><code> (require 'anything-config) (global-set-key "\C-c\C-a" 'anything) (global-set-key "\C-c\C-e" 'anything-for-files) </code></pre> I try to get in the habit of using C-cC-e instead of C-xC-f or C-x b. Anything is just too useful as a file/buffer finder.
评论 #857074 未加载
aiiieover 15 years ago
<a href="http:&#x2F;&#x2F;bitbucket.org&#x2F;[redacted]&#x2F;dotfiles&#x2F;src&#x2F;tip&#x2F;.emacs" rel="nofollow">http:&#x2F;&#x2F;bitbucket.org&#x2F;[redacted]&#x2F;dotfiles&#x2F;src&#x2F;tip&#x2F;.emacs</a><p><a href="http:&#x2F;&#x2F;bitbucket.org&#x2F;[redacted]&#x2F;dotfiles&#x2F;src&#x2F;tip&#x2F;.emacs.d&#x2F;plugins&#x2F;" rel="nofollow">http:&#x2F;&#x2F;bitbucket.org&#x2F;[redacted]&#x2F;dotfiles&#x2F;src&#x2F;tip&#x2F;.emacs.d&#x2F;pl...</a><p>Probably my favorite bit of the config is that it uses flymake to run Pyflakes on my Python code as I&#x27;m writing it. I also have a little plugin that shows the error in the minibuffer area when the point is over the offending line.<p>It also disables backup&#x2F;autosave file littering by using a locked down directory in &#x2F;tmp.<p>As far as bindings go, I wrote delete-backward-indent for python-mode which deletes a level of indentation instead of just one space. There&#x27;s also newline-maybe-indent that doesn&#x27;t indent if the previous line has no indentation.<p>Everything else is pretty straightforward customization, I think. flyspell-prog-mode is another thing worth mentioning: it highlights spelling errors, but only in strings and comments.
mikedouglasover 15 years ago
Here is a one-liner that's quite useful:<p><pre><code> (add-hook 'c-mode-common-hook (lambda () (font-lock-add-keywords nil '(("\\&#60;\\(FIXME\\|TODO\\|BUG\\):" 1 font-lock-warning-face t)))))</code></pre>
diiqover 15 years ago
Apart from the usual utilities, I've got an emacs-lisp version of write-or-die; it deletes words if you stop typing for more than a few seconds. It's an excellent motivator for first drafts.
diN0botover 15 years ago
i put third party .el files in .emacs.d and then set the load path in the first line of my .emacs file<p><pre><code> (setq load-path (append load-path (list "/Users/diN0bot/.emacs.d"))) </code></pre> some useful .el's auto-save-list/ highlight-current-line.el auto_save_list/ psvn.el backup-file-list/ pycomplete.el cpp-font-lock.el python-mode.el django-mode.el vc-.el doctest-mode.el zenburn.el<p>rebindings are useful, such ctrl-q for M-x goto-line: (global-set-key "\C-q" 'goto-line)<p>I cribbed the following from someone else, but i find it most awesome:<p>; ===== Put auto-save, backup files in one place ===<p>;; Put autosave files (ie #foo#) in one place, <i>not</i> ;; scattered all over the file system! (defvar autosave-dir (concat "/Users/diN0bot/.emacs.d/auto-save-list/"))<p>(make-directory autosave-dir t)<p>(defun auto-save-file-name-p (filename) (string-match "^#.*#$" (file-name-nondirectory filename)))<p>(defun make-auto-save-file-name () (concat autosave-dir (if buffer-file-name (concat "#" (file-name-nondirectory buffer-file-name) "#") (expand-file-name (concat "#%" (buffer-name) "#")))))<p>;; Put backup files (ie foo~) in one place too. (The backup-directory-alist ;; list contains regexp=&#62;directory mappings; filenames matching a regexp are ;; backed up in the corresponding directory. Emacs will mkdir it if necessary.) (defvar backup-dir (concat "/Users/diN0bot/.emacs.d/backup-file-list/")) (setq backup-directory-alist (list (cons "." backup-dir)))
kirubakaranover 15 years ago
<a href="http://github.com/ki/my-dot-emacs/raw/master/dot-emacs.txt" rel="nofollow">http://github.com/ki/my-dot-emacs/raw/master/dot-emacs.txt</a>
coffeemugover 15 years ago
<a href="http://sources.defmacro.org/emacs-conf/" rel="nofollow">http://sources.defmacro.org/emacs-conf/</a>
Ben65over 15 years ago
It's hard to live without:<p>(fset 'yes-or-no-p 'y-or-n-p)
评论 #856790 未加载
评论 #856792 未加载
elqover 15 years ago
<a href="http://github.com/elq/dot-emacs/" rel="nofollow">http://github.com/elq/dot-emacs/</a>
grandalfover 15 years ago
I use Phil Hagelberg's starter kit and have made a few minor customizations -- works great and minimal learning curve.<p><a href="http://github.com/technomancy/emacs-starter-kit" rel="nofollow">http://github.com/technomancy/emacs-starter-kit</a>
bmacover 15 years ago
my emacs.d still needs a few tweaks but I'm convinced it always will.<p>most useful parts: replacing fundamental mode with text-mode as the default mode when a new buffer is open.<p>(setq default-major-mode 'text-mode)<p>turn auto fill (automatic line wraping) and flyspell (spellchecking) on by default<p>(add-hook 'text-mode-hook 'turn-on-auto-fill)<p>(add-hook 'text-mode-hook 'turn-on-flyspell)<p>also I find yasnippet <a href="http://code.google.com/p/yasnippet/" rel="nofollow">http://code.google.com/p/yasnippet/</a> wonderful for coding html mockups and django templates.<p>my github repo if anyone cares to take a peek: <a href="http://github.com/bmac/emacs" rel="nofollow">http://github.com/bmac/emacs</a>
评论 #856245 未加载
johngundermanover 15 years ago
<a href="http://github.com/johngunderman/emacs/blob/master/emacs-john.el" rel="nofollow">http://github.com/johngunderman/emacs/blob/master/emacs-john...</a><p>Mine's pretty minimal at the moment, but it does the job.
jwsover 15 years ago
178 lines of crap accumulated over about 20 years. I think I only use an indent variable setting, one key binding, and a handful of language autoloads.<p><i>delete-delete-delete save-buffer</i> Much better.
评论 #856155 未加载
评论 #856174 未加载
apgwozover 15 years ago
Mine has:<p>(require 'activator) (activator-start)<p>Which then looks at all of the stuff here: <a href="http://github.com/apgwoz/emacs-config" rel="nofollow">http://github.com/apgwoz/emacs-config</a>
bkudriaover 15 years ago
My (somewhat extensive) Emacs config can be found here: <a href="http://github.com/bkudria/dotfile" rel="nofollow">http://github.com/bkudria/dotfile</a>
larrywrightover 15 years ago
Much of this is cribbed from other places (credited where possible):<p><a href="http://github.com/larrywright/emacs" rel="nofollow">http://github.com/larrywright/emacs</a>
jonsheaover 15 years ago
<a href="http://github.com/jonshea/config-files/blob/master/.emacs" rel="nofollow">http://github.com/jonshea/config-files/blob/master/.emacs</a>
vaporstunover 15 years ago
(setq comint-input-ring-size 2048)<p>The default undo history is only 32. I like to be able to go further back.
leifover 15 years ago
mine's in <a href="http://github.com/adlaiff6/df.git" rel="nofollow">http://github.com/adlaiff6/df.git</a> but I don't really expect you to read it
评论 #857912 未加载
twismover 15 years ago
ido.el to find files<p><pre><code> (require 'ido) (ido-mode t)</code></pre>
gibsonf1over 15 years ago
;; Easymacs sets some common Windows key bindings like ctrl-c to copy, ctrl-s to save, etc. (load "c:/Otech/programs/easymacs/easymacs.el")<p>(defun init-streamfocus () (interactive)<p>;; Slime is for starting or connecting to SBCL ;; To start: C-x slime RET (add-to-list 'load-path "c:/Otech/sf/lib/slime")<p>;;(setq inferior-lisp-program "C:/Otech/programs/sbcl-1.0.9/sbcl")<p><pre><code> ;(setq inferior-lisp-program "C:/Program Files/LispWorks/lispworks-4450")</code></pre> (add-hook 'lisp-mode-hook (lambda () (slime-mode t))) (add-hook 'inferior-lisp-mode-hook (lambda () (inferior-slime-mode t))) ;; (defun lw-start () ;; (interactive) ;; (shell-command (concat "C:/Program Files/LispWorks/lispworks-4450.exe -multiprocessing " ;; "-init c:/Otech/swank.lisp&#38;")))<p>;;;For SBCL on Windows ;(setq inferior-lisp-program "sbcl") ;(add-to-list 'load-path "C:/Program Files/Steel Bank Common Lisp/1.0.22/sbcl.exe")<p>;;For Allegro on Windows (setq inferior-lisp-program "allegro") (add-to-list 'load-path "C:/Program Files/acl81/allegro.exe")<p>(require 'slime) (slime-setup '(slime-fancy slime-banner))<p>;;allegro (global-set-key "\C-cs" 'slime-selector) (setq slime-complete-symbol<i>-fancy t) (setq slime-complete-symbol-function 'slime-fuzzy-complete-symbol)<p>(setq slime-multiprocessing t) ;; choose one of the below based on Express or non-Express usage ;(setq </i>slime-lisp* "alisp.exe") (setq <i>slime-lisp</i> "allegro.exe")<p><pre><code> ;;(setq *slime-lisp* "allegro-express.exe") (setq *slime-port* 4005) (global-set-key [(f5)] '(lambda () (interactive) (shell-command (format "%s +B +cm -L c:/.slime.lisp -- -p %s --ef %s &#38;" *slime-lisp* *slime-port* slime-net-coding-system)) (delete-other-windows) (while (not (ignore-errors (slime-connect "localhost" *slime-port*))) (sleep-for 0.2)))) (let* ((cygwin-root "c:/cygwin") (cygwin-bin (concat cygwin-root "/bin"))) ;(setenv "HOME" (concat cygwin-root "/home/frederick")) (setenv "PATH" (concat cygwin-bin ";" (getenv "PATH"))) (setq exec-path (cons cygwin-bin exec-path))) (setq shell-file-name "bash") (setq explicit-shell-file-name "bash") (push ".fasl" completion-ignored-extensions) (push ".git" completion-ignored-extensions) ;;--------------------------------------</code></pre> ;;;; For remote slime ;; see <a href="http://a1k0n.net/blah/archives/2005/11/04/T18_00_44/index.html" rel="nofollow">http://a1k0n.net/blah/archives/2005/11/04/T18_00_44/index.ht...</a> (require 'tramp) (defvar <i>cayenne-path</i> "/sshx:streamfocus@cayenne:") (defvar <i>current-tramp-path</i> nil)<p><pre><code> (defun slime-connect-to-host (path port) (setq *current-tramp-path* path) (setq slime-translate-from-lisp-filename-function (lambda (f) (if *current-tramp-path* (concat *current-tramp-path* f) f))) (setq slime-translate-to-lisp-filename-function (lambda (f) (if *current-tramp-path* (substring f (length *current-tramp-path*)) f))) (slime-connect "localhost" port)) (defun cayenne-slime () (interactive) (slime-connect-to-host *cayenne-path* 4006)) (defun cayenne-find-file () (interactive) (find-file (concat *cayenne-path* "/home/streamfocus/sf/"))) </code></pre> ;;;; TRAMP remote editing. See notes for NTEmacs on <a href="http://www.emacswiki.org/cgi-bin/wiki/TrampMode" rel="nofollow">http://www.emacswiki.org/cgi-bin/wiki/TrampMode</a> (setq tramp-default-method "sshx") ;;;; SLIME settings to edit remote files on rembrandt ;(push (list "^cayenne$" ; (lambda (emacs-filename) ; (subseq emacs-filename (length "/cayenne:"))) ; (lambda (lisp-filename) ; (concat "/cayenne:" lisp-filename))) ; slime-filename-translations)<p><pre><code> ;; http://www.emacswiki.org/cgi-bin/wiki/NTEmacsWithCygwin (let* ((cygwin-root "c:/cygwin") (cygwin-bin (concat cygwin-root "/bin"))) ;(setenv "HOME" (concat cygwin-root "/home/fred")) (setenv "PATH" (concat cygwin-bin ";" (getenv "PATH"))) (setq exec-path (cons cygwin-bin exec-path))) (setq shell-file-name "bash") (setq explicit-shell-file-name "bash") ) </code></pre> (defun init-clojure () "Inits slime for streamfocus" (interactive) ;; clojure-mode (add-to-list 'load-path "C:/Otech/programs/clojure/clojure-mode") (require 'clojure-mode)<p><pre><code> ;; swank-clojure (add-to-list 'load-path "C:/Otech/programs/clojure/swank-clojure") (require 'swank-clojure-autoload) ;(swank-clojure-config (setq swank-clojure-jar-path "C:/Otech/programs/clojure/clojure/clojure.jar") (setq swank-clojure-extra-classpaths (list "C:/Otech/programs/clojure/clojure-contrib/clojure-contrib.jar")) ;) ;; slime (eval-after-load "slime" '(progn (slime-setup '(slime-repl)))) (add-to-list 'load-path "C:/Otech/programs/clojure/slime") (require 'slime) (slime-setup) ;;;type alt-x and slime to start repl )</code></pre>