I’ve ended up migrating a few of my old functions back to my new setup, as well as creating a few newer ones. These are the ones I’ve added recently - maybe they’ll be useful to you, as well.
I’ve been doing a few book reviews recently, and instead of having to manually add in links I just wrote a function to generate a link based on the ASIN I give it. If you end up using something like this, you’ll probably want to change it so that it links to your Amazon Associate’s account, although I won’t complain if you don’t.
(defun insert-amzn-product (asin) "Inserts a link(image + text to an Amazon product using the ASIN" (interactive "MAsin:") (insert (concat "<iframe src=\"http://rcm.amazon.com/e/cm?t=randmusiofaso-20" "&o=1&p=8&l=as1&asins=" (replace-regexp-in-string "\\n" "" asin) "&fc1=000000&IS2=1<1=_blank&m=amazon&lc1=0000FF&" "bc1=000000&bg1=FFFFFF&f=ifr\" style=\"width:120px;height:240px;\"" "scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\"" "frameborder=\"0\"></iframe>")))
I like to be able to know how many words are in a buffer, so I found the following function somewhere online. It just runs ‘wc -w’ as a shell command on the contents of the current buffer, which outputs the number of words.
(defun wc nil "Count words in buffer" (interactive) (shell-command-on-region (point-min) (point-max) "wc -w"))
I sometimes use different editors on the same files, and end up having broken indentation a lot of the time this happen. I wrote iwb (for indent-whole-buffer) to fix indentation problems.
(defun iwb () "Indents the entire buffer" (interactive) (indent-region (point-min) (point-max) nil))
This function I picked up from Steve Yegge’s blog. It prompts for a directory and then moves the buffer you are editing and the associated file to that directory
(defun move-buffer-file (dir) "Moves both current buffer and file it's visiting to DIR." (interactive "DNew directory: ") (let* ((name (buffer-name)) (filename (buffer-file-name)) (dir (if (string-match dir "\\(?:/\\|\\\\)$") (substring dir 0 -1) dir)) (newname (concat dir "/" name))) (if (not filename) (message "Buffer '%s' is not visiting a file!" name) (progn (copy-file filename newname 1) (delete-file filename) (set-visited-file-name newname) (set-buffer-modified-p nil) t))))