{"id":1112,"date":"2015-06-13T00:21:31","date_gmt":"2015-06-13T07:21:31","guid":{"rendered":"http:\/\/www.elbeno.com\/blog\/?p=1112"},"modified":"2015-06-13T09:27:34","modified_gmt":"2015-06-13T16:27:34","slug":"emacs-bankruptcy","status":"publish","type":"post","link":"https:\/\/www.elbeno.com\/blog\/?p=1112","title":{"rendered":".emacs bankruptcy"},"content":{"rendered":"<p>So, this past week I decided to redo my .emacs file. Previously, I was using the (somewhat common?) literate programming approach with org-mode, but I decided to ditch that, go back to a flat file and embrace John Wiegley&#8217;s excellent <a href=\"https:\/\/github.com\/jwiegley\/use-package\">use-package<\/a>.<\/p>\n<p>My .emacs is at <a href=\"https:\/\/github.com\/elbeno\/dotemacs\">https:\/\/github.com\/elbeno\/dotemacs<\/a> if you want to follow along or just peruse it at your leisure. I&#8217;m not going to cover every detail, but there is some useful stuff so I&#8217;ll call it out. This post is going to be a bit of a link-dump&#8230;<\/p>\n<p><strong>Preliminaries<\/strong><\/p>\n<p>First, since I keep everything in a git repo, I usually structure it so that I just symlink ~\/.emacs to the .emacs file in the repo. Everything &#8220;fixed&#8221; stays in the repo, and ephemeral stuff like caches gets automatically put in ~\/.emacs.d. So the top of the file looks like this:<\/p>\n<pre lang=\"lisp\">\r\n;; this file's true directory\r\n(setq dotfile-dir (file-name-directory\r\n                   (file-chase-links\r\n                    (or load-file-name\r\n                        (buffer-file-name)))))\r\n\r\n;; my stuff is in .emacs.d\r\n(add-to-list 'load-path (concat dotfile-dir \".emacs.d\/\"))\r\n;; 3rd party stuff is in site-lisp\r\n(add-to-list 'load-path (concat dotfile-dir \".emacs.d\/site-lisp\/\"))\r\n;; packages\r\n(setq package-user-dir (concat dotfile-dir \".emacs.d\/packages\/\"))\r\n;; extra binaries (if needed) are in site-bin\r\n(add-to-list 'exec-path (concat dotfile-dir \".emacs.d\/site-bin\/\"))\r\n<\/pre>\n<p><strong>The package system<\/strong><\/p>\n<p>Next, the package system gets set up, and use-package is loaded. Previously using org-mode, startup time was appreciable, and now, using use-package it&#8217;s in the sub-second range: most packages are deferred until needed.<\/p>\n<pre lang=\"lisp\">\r\n(setq package-archives '((\"org\" . \"http:\/\/orgmode.org\/elpa\/\")\r\n                         (\"gnu\" . \"http:\/\/elpa.gnu.org\/packages\/\")\r\n                         (\"elpa\" . \"http:\/\/tromey.com\/elpa\/\")\r\n                         (\"marmalade\" . \"http:\/\/marmalade-repo.org\/packages\/\")\r\n                         (\"melpa\" . \"http:\/\/melpa.org\/packages\/\")))\r\n\r\n(package-initialize)\r\n(setq package-enable-at-startup nil)\r\n\r\n(unless package-archive-contents\r\n  (message \"Refreshing package archives...\")\r\n  (package-refresh-contents))\r\n\r\n(unless (package-installed-p 'use-package)\r\n  (message \"`use-package' not found.  Installing...\")\r\n  (package-install 'use-package))\r\n\r\n(require 'use-package)\r\n(setq use-package-minimum-reported-time 0\r\n      use-package-verbose t\r\n      use-package-always-ensure t)\r\n<\/pre>\n<p>Then I have a bunch of stuff that sets fonts (10-pt Inconsolata is my font of choice), and turns off everything people usually turn off &#8211; toolbar, menu, scrollbar, startup screen message, etc. I have a few functions to wrangle frames, and a bunch of top-level key bindings I&#8217;m used to. Then it gets to the important stuff: what helps me code.<\/p>\n<p><strong>Generally useful packages<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/Fuco1\/smartparens\">smartparens<\/a> &#8211; for doing stuff with anything surrounded with stuff, whether that stuff is parens, square brackets, angle brackets, quotes, or something else user-defined. Takes a little getting used to, and really shines in lisp, of course, but the notion of hybrid s-expressions is really useful also.<\/li>\n<li><a href=\"https:\/\/github.com\/Fanael\/rainbow-delimiters\">rainbow-delimiters<\/a> &#8211; subtly colours each pair of brackets\/parens\/whatever differently.<\/li>\n<li><a href=\"https:\/\/github.com\/emacsmirror\/rainbow-mode\">rainbow-mode<\/a> &#8211; colourizes colour names and codes in the buffer. I had a Greenspunned version of this before, I threw it out when I found the package. Nice.<\/li>\n<li><a href=\"https:\/\/github.com\/joodland\/bm\">bm<\/a> &#8211; just a really nice simple bookmarking solution. I had it before, I&#8217;m keeping it now.<\/li>\n<li><a href=\"https:\/\/github.com\/nonsequitur\/smex\">smex<\/a>, <a href=\"http:\/\/emacswiki.org\/emacs\/InteractivelyDoThings\">flx-ido, ido-ubiquitous, ido-vertical-mode<\/a> &#8211; this time around I added the vertical mode, which I&#8217;m finding pretty nice, especially with <code>(setq ido-vertical-define-keys 'C-n-C-p-up-and-down)<\/code><\/li>\n<li><a href=\"http:\/\/www.emacswiki.org\/emacs\/UndoTree\">undo-tree<\/a> &#8211; the best package for navigating Emacs&#8217; undo system.<\/li>\n<\/ul>\n<p>Honorable mentions: <a href=\"http:\/\/www.emacswiki.org\/emacs\/AceJump\">ace-jump-mode<\/a>, <a href=\"https:\/\/github.com\/fourier\/ztree\">ztree<\/a>, <a href=\"https:\/\/github.com\/magnars\/multiple-cursors.el\">multiple-cursors<\/a>, <a href=\"https:\/\/github.com\/m00natic\/vlfi\">vlf<\/a>, <a href=\"https:\/\/github.com\/jschaf\/esup\">esup<\/a>.<\/p>\n<p><strong>Git interactions<\/strong><\/p>\n<p>Of course, there&#8217;s <a href=\"http:\/\/magit.vc\/\">magit<\/a>. That goes without saying. But there are also the mode packages: gitconfig-mode, gitignore-mode, git-commit-mode and git-rebase-mode. They just ease the everyday.<\/p>\n<p>I already knew about <a href=\"https:\/\/github.com\/nonsequitur\/git-gutter-fringe-plus\">git-gutter-fringe+<\/a> and <a href=\"https:\/\/github.com\/voins\/mo-git-blame\">mo-git-blame<\/a>. But mo-git-blame is a little heavyweight&#8230; and I discovered <a href=\"https:\/\/github.com\/syohex\/emacs-git-messenger\">git-messenger<\/a>, much lighter weight. Cool. I also found <a href=\"https:\/\/github.com\/pidu\/git-timemachine\">git-timemachine<\/a> which allows stepping back\/forward through history. Awesome!<\/p>\n<p><strong>C++ stuff<\/strong><\/p>\n<p>I program in several languages semi-regularly and Emacs supports them all, but mostly I use C++, and C++ is a tricky beast to wrangle. So I really wanted to improve things. There&#8217;s the behemoth that is <a href=\"http:\/\/cedet.sourceforge.net\/\">CEDET<\/a>, and it can do a load of things, but I&#8217;ve found it slow to do most of them.<\/p>\n<p>When it comes down to it, the following are really the features I want\/need:<\/p>\n<ul>\n<li>Quick switch between header and implementation file: for this, I use <a href=\"http:\/\/batsov.com\/projectile\/\">Projectile<\/a>&#8216;s <code>projectile-find-other-file<\/code>.<\/li>\n<li>Open file in project &#8211; Projectile covers that too with <code>projectile-find-file<\/code>.<\/li>\n<li>Open header at point &#8211; Projectile does that with <code>projectile-find-file-dwim<\/code>.<\/li>\n<li>Grep files in project &#8211; you guessed it, <code>projectile-grep<\/code>.<\/li>\n<li>Autocomplete &#8211; this is the big one. This is the one that&#8217;s really slow on a big codebase. And there are no good solutions on Windows, really. CEDET (semantic) isn&#8217;t a good solution either &#8211; it&#8217;s too slow. But a mix of <a href=\"http:\/\/company-mode.github.io\/\">company<\/a> and (on Linux) <a href=\"https:\/\/github.com\/Sarcasm\/irony-mode\">irony-mode<\/a> works really well, using libclang. For Windows, I just use the company-dabbrev-code backend because I&#8217;m in a Microsoft ecosystem.<\/li>\n<li>For header completion, <a href=\"https:\/\/github.com\/randomphrase\/company-c-headers\">company-c-headers<\/a> does the job.<\/li>\n<li><a href=\"https:\/\/github.com\/flycheck\/flycheck\">Flycheck<\/a> and <a href=\"https:\/\/github.com\/Sarcasm\/flycheck-irony\">flycheck-irony<\/a> give me in-buffer errors\/warnings on Linux. That&#8217;s nice.<\/li>\n<li>For go-to-definition, I use plain old <code>etags-select<\/code> and <code>etags-table<\/code>, but with a <a href=\"https:\/\/github.com\/gfixler\/githist\">nice addition<\/a> to keep tags automatically up-to-date with git interactions.<\/li>\n<li>One more thing: automatic header insertion with my own hacked-up variant of <a href=\"https:\/\/github.com\/syohex\/emacs-cpp-auto-include\">cpp-auto-include<\/a>. I updated it to separate and alphabetize the STL headers and deal with all the new C++11\/14 stuff. So with a keypress, Emacs can automatically pull in the headers I need.<\/li>\n<\/ul>\n<p>There&#8217;s more &#8211; Haskell stuff I haven&#8217;t entirely finished tweaking yet, Python and JavaScript flycheck linting seems to be working well, and of course there&#8217;s org-mode which I use for making presentations. Still on my to-do list: setting up a decent debugging experience with Emacs. Maybe that&#8217;s another post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, this past week I decided to redo my .emacs file. Previously, I was using the (somewhat common?) literate programming approach with org-mode, but I decided to ditch that, go back to a flat file and embrace John Wiegley&#8217;s excellent use-package. My .emacs is at https:\/\/github.com\/elbeno\/dotemacs if you want to&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-1112","post","type-post","status-publish","format-standard","hentry","category-emacs"],"_links":{"self":[{"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1112"}],"version-history":[{"count":4,"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1112\/revisions"}],"predecessor-version":[{"id":1116,"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1112\/revisions\/1116"}],"wp:attachment":[{"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}