Extra Cookie

Yet Another Programmer's Blog

Talk About Emacs

Using Emacs is like an adventure.

I found two very powerful extensions recently in Github. Yes, I’ve shared some powerful features/extensions last year by this post, but those two are not only powerful, but also handy, compared with align-regex, occur, anything, etc.

mark-multiple.el

I’ve used Eclipse, which has a good support for refactoring, but I want complain: Dialogs suck!

So, when I need to rename one variable or a function which occurs many times in a file, what am I supposed to do?

replace-string? It could, but it’s not good enough, since I am lazy, I don’t want to type the whole name, I use replace-regexp.

I mean, before I saw the magic of mark-multiple.el.

With it, I only need to mark the whole name, by two key stroke, C-space M-f, then use C-. to match all occurrences afterwards, and edit, all occurrences are being changed at the same time.

Download it from here, and my configuration:

1
2
3
4
5
6
7
(add-to-list 'load-path "~/Dropbox/Emacs/emacs.d/mark-multiple")
(require 'inline-string-rectangle)
(global-set-key (kbd "C-x r t") 'inline-string-rectangle)
(require 'mark-more-like-this)
;; I don't like C-> and C-< , not easy to type
(global-set-key (kbd "C-,") 'mark-previous-like-this)
(global-set-key (kbd "C-.") 'mark-next-like-this)

expand-region.el

Imagine how frequently you copy or move some words a day?

I do it like always. Copy one word is easy, C-space M-f, one line is also easy, C-a M-k, but check code samples below, how can I mark point-min when my cursor is after “m”, C-f C-f M-b M-b?

Seems too many key strokes.

Do we mark things like these: in from point, to-char (po from (goto-char (point-min))?

I never do that. If cursor is after “m” of point-min, what I might want to mark are min, point-min, (“point-min”), goto-char (point-min), (goto-char (point-min)), those are meaningful.

They are semantic units.

What expand-region does is to mark the semantic units one by one, inside out by each expand.

Move cursor character by character is boring, and hurts finger, so, no more cursor move, just expand.

Download it from here.

1
2
3
4
5
6
7
8
9
10
;; Convert a buffer from dos ^M end of lines to unix end of lines
(defun dos2unix ()
  (interactive)
    (goto-char (point-min))
      (while (search-forward "\r" nil t) (replace-match "")))
;; vice versa
(defun unix2dos ()
  (interactive)
    (goto-char (point-min))
      (while (search-forward "\n" nil t) (replace-match "\r\n")))

You can watch the demos of those two extensions in Emacs Rocks: mark-multiple and expand-region

Some more things, maybe not very powerful, but interesting.

key-chord.el

Tired of control and meta keys? Try KeyChord, by this extension, we can bind commands to two keys pressed simultaneous or a single key quickly pressed twice. For example, hj might never appears in one word, so I bind ido-find-file to hj, whenever I want to open another file, type h and j at the same time, quick and easy.

highlight-indentation.el

I began to write python code, when a function is long, I feel it’s hard to track which scope I am in by indentation, if block of indentation is highlighted by some color, it might be better. HighLightIndentation makes my life easier.

fill-column-indicator.el

I think it’s cool to have a grey dotted line in editor on column 80. I don’t want to argue whether it’s reasonable to restrict one line to less than 80 characters, I just believe if “keep it simple, stupid!”, 80 characters is really enough, and I love to split windows horizontally.

Comments