Yet Another Emacs Post

There’s been a lot of random emacs customizations I’ve added to my init file, so it’s time to document them all here. There are also a few additions to customizations I’ve talked about in previous blogs; when this occurs, I’ll link back to those.

The first category is just emacs options, that effect every buffer. I save often enough to find auto-saving, which can clutter my directories, annoying, so I disable it. While I personally don’t mind tabs, pretty much every place I work requires the use for spaces for indentation, so I just set indent-tabs-mode to nil so that they are happy. x-enable-clipboard determines whether you want emacs to be able to interact with the system clipboard under X, which of course you do. I like having the time displayed in the mode line, so I enable that. Blink-cursor-mode is responsible for determining whether the cursor blinks, as in many applications, or is just constant highlighting. I prefer the constant highlight, so I turn the mode off. The visible bell, which most people prefer, alerts you to errors by blinking the top and bottom lines instead of giving an annoying beep. I enabled one of the commands that I end up using, so that Emacs doesn’t complain when I do use it, and then gave query-replace-regexp a convenience alias since I use it a fair amount.

(setq auto-save-default nil)
(setq-default indent-tabs-mode nil)
(setq x-select-enable-clipboard t)
(display-time)
(blink-cursor-mode nil)
(setq visible-bell t)
(put 'erase-buffer 'disabled nil)
(defalias 'qrr 'query-replace-regexp)

There are a few modes that I’ve added back in but blogged about before restarting my .emacs file: pabbrev and cua. The links for those posts are here and here respectively. Pabbrev is a mode for predictive expansion, which is incredibly useful. Cua is a mode that does several things, the two main ones being adding windows-friendly keybindings when the region is visible and adding much better rectangle support. I only really like the rectangle support, as I’ve mentioned before.

(require 'pabbrev)
(global-pabbrev-mode t)
(setq pabbrev-read-only-error nil)
 
(setq cua-enable-cua-keys nil) ;
(cua-mode t)

The next category is for customizations for other modes that I’ve talked about but ended up changing. comint-process-echoes makes M-x shell behave more like a real terminal in some cases, stripping extraneous output. This isn’t necessary on my home computer, but it is on my work one so I missed it in my initial post here. I added a few more customizations for ido, which I wrote about here: one that moves the location of one of it’s files to centralize it in .emacs.d, and one that removes the prompt asking if you want to create a new buffer when you switch to one that doesn’t exist.

I also add a few additional keybindings to make my life easier:

(global-set-key (kbd "C-w") 'backward-kill-word)
(global-set-key (kbd "C-x C-k") 'kill-region)
(define-key visual-line-mode-map (kbd "C-a") 'beginning-of-visual-line)
(global-set-key (kbd"C-x \\") 'align-regexp)

The following function I had in my old setup, and it was much better than M-x rgrep in a lot of cases I wanted so I ended up pulling it back. It prompts you for an expression, defaulting to the symbol that your cursor is on, and greps for that in the current directory and all subdirectories. Very useful.

(defun my-grep ()
  "grep the whole directory for something defaults to term at cursor position"
  (interactive)
  (setq default (thing-at-point 'symbol))
  (setq needle (or (read-string (concat "grep for <" default "> ")) default))
  (setq needle (if (equal needle "") default needle))
  (grep (concat "egrep -s -i -n -r " needle " *")))
(global-set-key (kbd "C-x g") 'my-grep)

The last few things in this batch are just things that I have emacs do on startup. I almost always want to be able to look at my init file, so I load it up here. I also start a server, so I can connect to it with emacsclient and save on startup times when doing things from the command-line that need an editor.

(find-file "~/.emacs.d/init.el")
(server-start)

Tags:

2 Responses to “Yet Another Emacs Post”

  1. [...] there are a few cool customizations I didn’t know about posted on Musings of a Software Engineering Student. There are lots of [...]

  2. [...] December 5, 2010 mzuliani Leave a comment Go to comments I really like pabbrev. Refer to this blog for a thorough [...]

Leave a Reply