Some more additions to my .emacs file (actually, my init.el file now. I decided it was easier to be able to add my entire .emacs.d directory to source control, and keep all of my customizations in it). Most of these were from my old config files - It turns out there’s a reason I had most of that stuff. I’ll just keep re-adding stuff from them if I need it, it turns out I had a fairly comprehensible structure that allows me to easily find specific customizations I had.
(require 'ansi-color) (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on) (setq comint-prompt-read-only t) (shell)
A few more customizations to my shell configuration. The first line adds colours, as well as fixing the issues I mentioned last time. I had this in my old .emacs file, but did not realize it was what fixed shell-mode to be readable - part of the reason I started over I suppose, to better understand all of my customizations. The last line just starts a shell buffer - since I primarily use the shell from emacs, I always open one anyway. This just saves me from doing it manually.
(setq default-major-mode 'text-mode) (add-hook 'text-mode-hook 'flyspell-mode) (add-hook 'text-mode-hook 'visual-line-mode) (defadvice ispell-command-loop (before ispell-reverse-miss-list activate) "reverse the first argument to ispell-command-loop" (ad-set-arg 0 (reverse (ad-get-arg 0))))
I added a few things to make writing this blog and other text documents easier on myself. There are pretty much no downsides to setting the default major mode to text instead of fundamental. While in text mode, I also want spellchecking and line wrapping based on my frame size. The advice is something I picked up from the internet somewhere(actually, after investigating, from here), which reverses the order in which ispell makes suggestions. This tends to offer me better suggestions than just the normal order, for whatever reason.
(require 'uniquify) (setq uniquify-buffer-name-style 'reverse) (setq uniquify-separator "/") (setq uniquify-after-kill-buffer-p t) (setq uniquify-ignore-buffers-re "^\\*")
Uniquify is an built-in emacs package that renames buffers when you open two files with the same name. In the default case, they will merely be numbered, so for example you would have a .emacs buffer and an .emacs<2> buffer. Uniquify will append part of the file path to the file, so instead you’d have .emacs/nflath and .emacs/emacs buffers. uniquify-buffer-name-style and uniquify-separator control how the buffer names are created; describe-variable uniquify-buffer-name-style in order to see all the possible options. uniquify-after-kill-buffer-p controls whether or not buffers are renamed when other buffers were killed: When set to t, when one of the about duplicate .emacs buffers is closed, the other will rename itself to .emacs. The last line specifies not to perform this for special buffers, such as *scratch*
(defun insert-strong-tags () "Inserts <strong></strong> around the word at point" (interactive) (save-excursion (re-search-backward "\\s ") (forward-char 1) (insert "<strong>") (forward-char 1) (re-search-forward "\\s \\|$") (if (not (eq (point) (point-max))) (backward-char 1)) (insert "</strong>"))) (global-set-key (kbd "C-c i s") 'insert-strong-tags)
I actually wrote this function while writing this blog post. This is one of the great things about emacs: You can immediately solve inefficiencies once you notice them. This function will insert strong tags around the word you are currently on, leaving the point at the same location. This is great when you forget to add an opening tag to the beginning of the word, or are noticing an error you made afterwords and just need to add the tags.
(global-set-key (kbd "C-a") 'back-to-indentation)
I used to have C-a bound to switch between going to the beginning of the line and back to the indentation, but I realized I pretty much never wanted to go to the actual beginning of a line. I rebound C-a to what usually M-m because it’s much easier to type.
(global-set-key (kbd "C-c j") 'join-line)
A useful function that doesn’t have a default keybinding, so I provided one
(add-hook 'before-save-hook 'delete-trailing-whitespace) (set-face-attribute 'default nil :height 80) (column-number-mode)
The first of these customizations will delete trailing whitespace from files every time I save. I really, really hate it when I press C-e and am not at what I want to edit, and I haven’t ever encountered a situation where I need to keep trailing whitespace, so I just automate the process of removing it. The second line just sets the size of the font; you should customize this to your liking, depending on your monitor’s resolution. On some versions and monitors, I’ve had to have this be at 90; others I could set the size to 60 without any problems. column-number-mode puts the current column number on the mode line, which I like to know.
I have made a few more customizations, but they’re big enough to warrant separate posts.