hack on match-paren

I used to use a short code "match-paren" (http://grok2.tripod.com/) when I program, especially in Lisp where parentheses are everywhere. I like this piece of code, for its simplicity and usefulness: if you bind this code to something like M-[, and when you press M-[ on a "(", the cursor goes to the matching ")" automatically. This also works when mark is activated, so you can highlight the region between two matching "(" and ")" very easily. The original code is as follows:

(defun match-paren (arg)
"Go to the matching paren if on a paren."
(interactive "p")
(cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
((looking-at "\\s\)") (forward-char 1) (backward-list 1))))

Then sometimes I found that the code does not always work intuitively, especially when I want to highlight a region with the matching "(" and ")", so I did the following hack:
(1) when you keep hitting the key-binding, e.g., M-[, the cursor jump back and forth between its original locations, not like the original code
(2) when the mark is active, the cursor jump to the matching parenthesis and move forward one step after reaching ")" or backward one step after reaching "(", so the highlighted region contains everything between (and including) the matching "(" and ")". I found this especially useful when you want to cut a list out when programming in Lisp.

Here is my hack.

(defun da-match-paren (arg)
"Go to the matching paren if on a paren."
(interactive "p")
(cond ((and mark-active (looking-at "\\s\(")) (forward-list 1))
((and mark-active (looking-back "\\s\)")) (backward-list 1))
((looking-at "\\s\(") (forward-list 1) (backward-char 1))
((looking-at "\\s\)") (forward-char 1) (backward-list 1))
))
(global-set-key (kbd "M-[") ‘da-match-paren)

another way to track literature

I found using NIH or NSF grant number, such as NIH RO1-EB002123, is another good way to track a series of papers from a particular research group. Actually, the corresponding authors usually pay attention to which grants a paper should mention at the Acknowledgment part, so the papers having the same grant number are often automatically and carefully classified according to the big project they are related to. I think this is worth mentioning in my web note.

open a windows explorer at the path of the current buffer

I use emacs in Windows. As I edit some text based files in Emacs, sometimes I need to open a window at the path of the current buffer to visit other files. It would be nice if I can just press a key in Emacs, and have this window open. Here is my simple solution for this task in Emacs with Windows OS.

(defun open-buffer-path ()
“Run explorer on the directory of the current buffer.”
(interactive)
(shell-command (concat “explorer ” (replace-regexp-in-string “/” “\\\\” (file-name-directory (buffer-file-name)) t t))))

I bound this function to a key-binding:
(global-set-key [M-f9] ‘open-buffer-path)

Notes: the key points in the line
(shell-command (concat “explorer ” (replace-regexp-in-string “/” “\\\\” (file-name-directory (buffer-file-name)) t t)))
(1) shell-command call a command specified by a string from shell
(2) replace-regexp-in-string “/” “\\\\” replace the Unix-style path (using /) to Windows-style paht (using \), the optional arguments “t t” let replace-regexp-in-string replace literally.