posts/a foray into emacsbloghttp://blog.spang.cc/posts/a_foray_into_emacs/blogikiwiki2010-02-18T18:16:51Zautoindent on carriage returnhttp://blog.spang.cc/posts/a_foray_into_emacs/comment_1/zwol [livejournal.com]2010-02-15T06:57:44Z2010-02-15T06:57:44Z
<p>I have a huge pile of these in .emacs:</p>
<pre><code>(defun crindents ()
"Set CR to do newline-and-indent"
(interactive)
(local-set-key "\r" 'newline-and-indent))
(add-hook 'perl-mode-hook 'crindents)
(add-hook 'python-mode-hook 'crindents)
(add-hook 'emacs-lisp-mode-hook 'crindents)
;; repeat for every programming language I regularly use
</code></pre>
<p>Since you're used to vi(m), you may also want</p>
<pre><code>(global-set-key [(control ?s)] 'isearch-forward-regexp)
(global-set-key [(control ?r)] 'isearch-backward-regexp)
</code></pre>
<p>which makes the interactive search prompt take a regular expression instead of a literal string, by default. (I don't remember why I used the extra-verbose key expressions, "\C-s" and "\C-s" would be equivalent.)</p>
comment 2http://blog.spang.cc/posts/a_foray_into_emacs/comment_2/traubert [myopenid.com]2010-02-15T06:59:13Z2010-02-15T06:59:13Z
Re auto-indentation: there's newline-and-indent, which by default is bound to C-j, but many people bind it to RET in specific programming modes or even globally.
comment 3http://blog.spang.cc/posts/a_foray_into_emacs/comment_3/traubert [myopenid.com]2010-02-15T07:00:03Z2010-02-15T07:00:03Z
Beaten to the punch <img src="http://blog.spang.cc/posts/a_foray_into_emacs/../../smileys/sad.png" alt=":(" />
Window movement / split / bookmarkshttp://blog.spang.cc/posts/a_foray_into_emacs/comment_4/orebokech.com2010-02-15T07:29:00Z2010-02-15T07:28:59Z
<p>To move between windows more easily you can use windmove-mode (then shift-<arrow key> will move in the corresponding direction in your windows).</p>
<p>I don't think there's a built-in way to automatically balance windows when you split them, however it is trivial to change the behavior of the corresponding function using advice:</p>
<pre><code>(defadvice split-window-horizontally (after auto-balance activate)
(balance-windows))
</code></pre>
<p>About bookmarks: they're meant to be more of a long-term thing. If you just want to remember places in a buffer and move between them you should use the mark ring, C-SPC C-SPC to mark a spot, C-u C-SPC to move back (C-x C-SPC to allow jumps to other buffers).</p>
Control & M-Tabhttp://blog.spang.cc/posts/a_foray_into_emacs/comment_5/rswarbrick.blogspot.com2010-02-15T09:11:58Z2010-02-15T09:11:58Z
<p>About the control thing, have you considered remapping your keyboard slightly further? I've been very happy with Ctrl, Meta, Super, [Hyper] moving outwards symmetrically from the spacebar. This has you hitting Ctrl with your thumb.</p>
<p>And, about the M-Tab thing: Firstly, I'd recommend rebinding (I'm using F3 for some reason). Secondly, I'd point out that Escape counts as Meta - hit escape then Tab. Finally, have you tried hippie-expand? It seems to work pretty well for me (although my lisp experience is mostly common lisp, where symbol completion is C-c TAB).</p>
<p>Rupert</p>
Easy window navigationhttp://blog.spang.cc/posts/a_foray_into_emacs/comment_6/jao2010-02-15T09:28:23Z2010-02-15T09:28:23Z
<p>I use the following code to easily access windows:</p>
<pre><code> ;;;; window navigation
(defun jao-first-window ()
(interactive)
(select-window (frame-first-window)))
(defun jao-nth-window (n)
(if (zerop n) 'jao-first-window
`(λ ()
(interactive)
(jao-first-window)
(other-window ,n))))
;;; keybindings: C-c 1, C-c 2 ...
(mapc (lambda (n)
(global-set-key (format "\C-c%s" (1+ n))
(jao-nth-window n)))
'(0 1 2 3 4 5 6 7 8))
</code></pre>
<p>With that, C-c 1 goes to the first window, and so on, up to 9.</p>
About the Control Tab problem...http://blog.spang.cc/posts/a_foray_into_emacs/comment_7/chmouel [myopenid.com]2010-02-15T15:41:22Z2010-02-15T15:41:22Z
<p>This mode :</p>
<p>http://nschum.de/src/emacs/window-numbering-mode/</p>
<p>is exactly made for you...</p>
default keybindingshttp://blog.spang.cc/posts/a_foray_into_emacs/comment_8/vvill [myopenid.com]2010-02-15T18:01:13Z2010-02-15T18:01:13Z
<p>Thanks for the wonderfully enlightening post.
I have been using vi for most of my editing tasks, which are never very complicated. And I'm also delving into how to get by with only ed, also hoping ed will help me understand C a bit better.
About keybindings, I have way to many different Window Managers and related minimalist programs, all installed with their default set(s) of function keys, to be able to even start thinking about making my own keybindings for convenience. I do also dabble with getting Gnome a KDE to work fairly well without always installing everything they offer. But they offer another set of behaviors to the mix, at least from what I've seen so far....
After a fresh install of emacs, while using dwm as windowmanager and a fairly basic 105 us keyboard, (I want to try colemak soon too) I find that CTRL is fairly consistent across the board with emacs, but meta is all over the place. with some bindings working as ALT and some working as Escape and still others working as CTRL ALT while some I can't find at all yet..Plus since you mentioned your only using the X version (to reduce confusion) I noticed there are some functions that work easier with the mouse than with the keyboard. And that can also make the transition a bit more frustrating, at least for me it does...
And dwm (the window manager) has an extensive set of predefined keybindings, that I always have to watch and see if keystrokes are intercepted by dwm, as I don't know them all, or even most of them yet.
I wanted to share one thing that I found while on a previous emacs journey back in sarge, The emacs psychotherapist. I have not scheduled many appointments with it to check my sanity, but I hope someday it will include a lintian type interface for just that purpose... But don't let it's tag line "Our doctor will help you feel better" lull you into a false sense of security, as it rarely helped to make me feel better, but was interesting none the less....</p>
<p>Unrelated, the minimalist web browser Conkeror also uses emacs type keybindings. Now if there were only a emacs Window Manager, but that might make switching to easy, if that is possible.....</p>
comment 9http://blog.spang.cc/posts/a_foray_into_emacs/comment_9/free-dissociation.com2010-02-15T20:55:17Z2010-02-15T20:55:17Z
viper-mode. It's annoyingly not-like-vim in a number of ways, but it's got the basic vi nature and the modality, and then you can use the Emacs keybindings for eg. interacting with your VCS around that. Emacs -- just another IDE. (Though a fairly nice one, really.)
comment 10http://blog.spang.cc/posts/a_foray_into_emacs/comment_10/davidglasser [livejournal.com]2010-02-15T23:25:16Z2010-02-15T23:25:16Z
<p>heh, I think you're in about the stage of life I was when I kicked the vim habit.</p>
<p>some notes:</p>
<p>first, my absolute number one suggest: USE IDO. TURN IT ON IMMEDIATELY, AND DON'T LOOK BACK. Basically, ido lets you open files and switch buffers by typing any (not necessarily contiguous) subsequence of its name, not just a prefix. It's really great.</p>
<p>re: C-x o: I use window-number.el with the prefix set to C-c, so that "C-c 4" takes me to the 4th window. Also, I bound C-x C-o to other-window as well because I always type that by accident <img src="http://blog.spang.cc/posts/a_foray_into_emacs/../../smileys/smile.png" alt=":)" /></p>
<p>I love shell-dwim for shells; I just hit it and it takes me to one of my shell buffers, and hitting it more times cycles through them; C-u before shell-dwim opens a new shell in the current directory.</p>
<p>I do interact with VCS from my editor but not using the "VC" (per-file autodetected thing)... I tend to use things like magit.el (or git.el), psvn.el, etc, which give a buffer for a given working copy that I can use to run VCS commands. If nothing else, magit lets me mostly ignore the concept of the git index.</p>
<p>I essentially only use dabbrev (M-/). One nice thing about it is that since I typically have a single emacs session open for weeks and rarely kill buffers, almost all the symbols I care about tend to be in some open buffer, so dabbrev works great.</p>
comment 11http://blog.spang.cc/posts/a_foray_into_emacs/comment_11/go-team-ari [livejournal.com]2010-02-16T22:35:27Z2010-02-16T22:35:27Z
FWIW, there's an obscure feature of the scheme syntax highlighting.. "let is_mzscheme=1" will enable "mzscheme-specific" syntax highlighting features, which include #| |#.
moving between windowshttp://blog.spang.cc/posts/a_foray_into_emacs/comment_12/hexmode [openweblog.com]2010-02-18T18:16:51Z2010-02-18T18:16:51Z
<p>Put (windmove-default-keybindings) in your .emacs file and you can move between windows with shift-arrow keys. See the documentation on that function (C-h f windmove-default-keybindings RET) if you want to use a modifier besides shift.</p>
<p>C-x v v -- yes people actually use their VCS from the editor. Also C-x v d DIR RET to see the changed files in a VCS repository and do different operations on them.</p>
<p>Don't quit emacs just because you're done editing that one file. It is meant to be started and then just worked in. Leave it open and load a file when you need to edit another one.</p>