emacs po-mode 断行的问题
emacs 的 po-mode 非常好用,而且几乎不用任何配置,快捷键很多而且很简单。
比如 n 跳到下一条,t 跳到下一条翻译的,u 跳到下一条没有翻译的,f 跳到下
一条标记 fuzzy 的, backspace 增加 fuzzy 标记, TAB 去除,等等…
不过也有个比较郁闷的地方,就是多行的文本,在 emacs 中配合 autofill-mode
自动换行之后,会在每一行后面多出一个回车符“\n”,这个是不需要的,并且以后
修改的时候比较麻烦。因为在 po-mode 中是不能直接随心所欲的编辑文本正文的。
所以只有文本模式下面编辑。再处理一次简直是不可原谅的。所以就自己想修改一
下,查了一下,该死的竟然没有文档,于是就只有修改源码了。。。
找了一下,改了一个小小的部分。在 po-mode.el 的 1722 行的一个函数定义之中
- (defun po-eval-requoted (form prefix obsolete)
- "Eval FORM, which inserts a string, and return the string fully requoted.
- If PREFIX, precede the result with its contents. If OBSOLETE, comment all
- generated lines in the returned string. Evaluating FORM should insert the
- wanted string in the buffer which is current at the time of evaluation.
- If FORM is itself a string, then this string is used for insertion."
- (po-with-temp-buffer
- (if (stringp form)
- (insert form)
- (push-mark)
- (eval form))
- (goto-char (point-min))
- (let ((multi-line (re-search-forward "[^\n]\n+[^\n]" nil t)))
- (goto-char (point-min))
- (while (re-search-forward "[.\"\a\b\f\n\r\t\\]" nil t) ;第一
- (cond ((eq (preceding-char) ?\") (replace-match "\\\"" t t))
- ((eq (preceding-char) ?\a) (replace-match "\\a" t t))
- ((eq (preceding-char) ?\b) (replace-match "\\b" t t))
- ((eq (preceding-char) ?\f) (replace-match "\\f" t t))
- ((eq (preceding-char) ?.) (replace-match "\\n" t t)) ;第二
- ((eq (preceding-char) ?\n) ;(replace-match "\n" t t))
- (replace-match (if (or (not multi-line) (eobp))
- "\\n"
- "\"\n\"") ;第三
- t t))
- ((eq (preceding-char) ?\r) (replace-match "\\r" t t))
- ((eq (preceding-char) ?\t) (replace-match "\\t" t t))
- ((eq (preceding-char) ?\\) (replace-match "\\\\" t t))))
- (goto-char (point-min))
- (if prefix (insert prefix " "))
- (insert (if multi-line "\"\"\n\"" "\""))
- (goto-char (point-max))
- (insert "\"")
- (if prefix (insert "\n"))
- (if obsolete
- (progn
- (goto-char (point-min))
- (while (not (eobp))
- (or (eq (following-char) ?\n) (insert "#~ "))
- (search-forward "\n"))))
- (buffer-string))))
修改的就是上面标记了 第一,第二,第三 的三行,下面是相关的说明。
先说第三,原先这里是 “\\n\”\n\”") 实质是在每一行结尾加上 \n”然后回车,再
在下面一行加上”, 当然我简单的将 \\n 给去掉了
再说第二,经过下面的修改之后,每一行的最后的 \n 都被去掉了,不过最后一行
如果是 \n 就还在,这个是我们期望的,但是也有多行的文本,本来有 \n 的,这
时也被去掉了,很是郁闷,但是在正常状况之下,emacs 无法区分哪里的回车应该
加上,哪里不应该加上。于是我就想到使用不同的标识符,想了半天,最后相中了
这个 . 因此就多了这么一个规则,将 . 替换为 \n。自然,在第一处的中括号中
就多出了一个 . 。于是遇到应该有 \n 符号的,就在行尾加上一个 . 。再断行,
否则就直接断行,最后一行不用理会。 Emacs 会自动处理好的。
虽然比较 ugly,不过初步目的是达到了,简单测试了一下,还好,能够正常工作。哈哈~
附:我是直接在 scratch 中 eval 这段代码测试的,这样这个函数覆盖了原来的
定义,我想应该直接可以写在配置文件中的,只要保证这段代码在 po-mode 之后
加载就能够正常工作了。具体的明天有空再补充了。


vi下貌似也有po.vim。不過我還是用poedit。
11月 26th, 2007 at 11:48 下午暈,trackback也trackback錯地方了,zhan把它刪掉吧。
11月 26th, 2007 at 11:49 下午trackback 是什么玩意?
11月 27th, 2007 at 11:08 下午[...] 之前 小修改了一下 po-mode, 使用了 . 来识别是否需要真正的使用 n 来断行, 但是今天被郁闷了,翻译 kile.po 时遇到了几个 abc.def 的文件名,照样翻译了 之后,点被替换成 n 了。于是发现用其他符号代替回车不是一个好办法,最好的 还是使用 n,不过一个问题是,emacs 替换时会将 n 替换成 \n,这是基于 的转义,平时在一行的中间也是可以的,但是在一行的行尾的话就会有问题。 [...]
12月 15th, 2007 at 11:08 下午