Friday, November 16, 2007

[Emacs Tips] 插入相邻一行的字符

类似于 VIM 插入状态下的 C-y 和 C-e,也就是插入光标所在上一行或者下一行的字符。
例如: VIM 插入状态下的 C-y 和 C-e,也就是插入光标所在上一行或者下一行的字符。

写程序的时候还是挺有用的
;;;###autoload
(defun my-insert-char-next-line (arg)
"insert char below the cursor"
(interactive "p")
(let ((col (current-column))
char)
(setq char
(save-excursion
(forward-line arg)
(move-to-column col)
(if (= (current-column) col)
(char-after))))
(if char
(insert-char char 1)
(message (concat "Can't get charactor in "
(if (< arg 0)
"previous"
"next")
(progn (setq arg (abs arg))
(if (= arg 1) ""
(concat " " (number-to-string arg))))
" line.")))))

;;;###autoload
(defun my-insert-char-prev-line (arg)
"insert char above the cursor"
(interactive "p")
(my-insert-char-next-line (- arg)))
用的键绑定是 C-x (C-x )
(global-set-key (kbd "C-)") 'my-insert-char-next-line)
(global-set-key (kbd "C-(") 'my-insert-char-prev-line)

2 comments:

Programming Life said...

请问带有语法高亮的代码是如何贴到blog里的,使用了什么工具?

jasonal said...

I used this one:
http://jasonal00.googlepages.com/code-publish.el