自己写一个将当前行一些的非上档字符转成上档字符,
因为多次按 shift 输入一些字符,是很烦的,所以我不想这样。
比如 我写3[attr];'value'
(写这个全部都是单个按键直接上屏,不再怎么需要去按 shift)
M-x
调用函数就可以,就会转成 #{attr}:"value"
用 M-x
肯定比按 shift 爽嘛
(defun shift-to()
"在当前行一些的非上档字符转成上档字符"
(interactive)
(let ((pos (line-beginning-position)))
(end-of-line)
(set-mark pos))
(let (
(p1 (region-beginning))
(p2 (region-end)))
(save-restriction
(narrow-to-region p1 p2)
(goto-char (point-min))
(while (search-forward "[" nil t)
(replace-match "{" nil t)
)
(goto-char (point-min))
(while (search-forward "]" nil t)
(replace-match "}" nil t)
)
(goto-char (point-min))
(while (search-forward "1" nil t)
(replace-match "!" nil t)
)
(goto-char (point-min))
(while (search-forward "2" nil t)
(replace-match "@" nil t)
)
(goto-char (point-min))
(while (search-forward "3" nil t)
(replace-match "#" nil t)
)
(goto-char (point-min))
(while (search-forward "4" nil t)
(replace-match "$" nil t)
)
(goto-char (point-min))
(while (search-forward "5" nil t)
(replace-match "%" nil t)
)
(goto-char (point-min))
(while (search-forward "6" nil t)
(replace-match "^" nil t)
)
(goto-char (point-min))
(while (search-forward "7" nil t)
(replace-match "&" nil t)
)
(goto-char (point-min))
(while (search-forward "8" nil t)
(replace-match "*" nil t)
)
(goto-char (point-min))
(while (search-forward "9" nil t)
(replace-match "()" nil t)
)
(goto-char (point-min))
(while (search-forward "=" nil t)
(replace-match "+" nil t)
)
(goto-char (point-min))
(while (search-forward ";" nil t)
(replace-match ":" nil t)
)
(goto-char (point-min))
(while (search-forward "'" nil t)
(replace-match "\"" nil t)
)
(goto-char (point-min))
)
)
)
代码有些地方没有复用,还请见谅
我想知道 怎么保证替换字符串后光标仍在原来位置与状态
因为这个函数写后光标位置与状态会改变