#2
yaobao2013-01-15 11:59
|
;作者:zklhp
;Email:zklhp@
;QQ:493165744
;2013.1.14
;转载请保持完整
;*****************************************************************************************************************
写得比较水啦
程序代码:
(defun make-a-long-sentence ()
"make a long sentence and also work on region"
(interactive)
(if (region-active-p)
(progn ; there is a text selection
(let (str pt)
(while (< (point) (region-end))
(progn
(delete-indentation 1) ;一个现成函数 但要处理连字符
(backward-char)
(setq str (buffer-substring (setq pt (point)) (1+ pt)))
(if (string-equal str "-")
(delete-char 2)
(forward-char)
)
)
)
)
)
)
(progn
(let (str pt)
(delete-indentation 1) ;一个现成函数 但要处理连字符
(backward-char)
(setq str (buffer-substring (setq pt (point)) (1+ pt)))
(if (string-equal str "-")
(delete-char 2)
(forward-char)
)
)
)
)
;; C-;
(global-set-key [67108923] (quote make-a-long-sentence))
这个实现了从
this
is
a hard-war-
ped
到
this is a hard-warped
的一键转换 而且加了处理选区(region)的功能
程序代码:
(defun dwim-make-a-long-sentence ()
"make a long sentence and also work on region"
(interactive)
(if (region-active-p)
(progn ; there is a text selection
(save-restriction
(narrow-to-region (region-beginning) (region-end))
(goto-char (point-min))
(while (search-forward "\n" nil t) (replace-match "" nil t))
)
)
(progn
(end-of-line)
(delete-char 1)
)
)
)
;; C-'
(global-set-key [67108903] (quote dwim-make-a-long-sentence))
;; C-M-;
(global-set-key [201326651] (quote dwim-make-a-long-sentence))
这个实现的是不加空格和删除连字符的版本 主要用于中文 例子
这句话
被
人为
分开了
好讨厌呀
到
这句话被人为分开了好讨厌呀
进步之处也是能处理选区
效率大大提高了诶 Emacs的无限可定制性真好
但有一个 要是能自动判断哪些是截断的就好了 不过我感觉实现有困难。。
显摆一下 顺便发今年的第一个有点技术的帖子。。
[ 本帖最后由 zklhp 于 2013-1-15 13:00 编辑 ]