15 Dec
小修改了一下 po-mode 的配置
之前
小修改了一下 po-mode, 使用了 . 来识别是否需要真正的使用 \n 来断行,
但是今天被郁闷了,翻译 kile.po 时遇到了几个 abc.def 的文件名,照样翻译了
之后,点被替换成 \n 了。于是发现用其他符号代替回车不是一个好办法,最好的
还是使用 \n,不过一个问题是,emacs 替换时会将 \n 替换成 \\n,这是基于 \
的转义,平时在一行的中间也是可以的,但是在一行的行尾的话就会有问题。
继续查看了一下,突然想到进行二次替换,也就是将行尾的 \\n 重新替换成 \n,
测试写了一下,基本正常,比 . 的办法是稍微漂亮一些了。
同时一个问题是在编辑的时候,下面的窗口,也就是编辑窗口,默认是没有打开
auto-fill-mode 的,这样,编辑的时候断行就不怎么方便,看了下源码,找到了
一个 hook, 添加了下,好了。
下面是我的 po-mode 配置文件
下载: 23-pomode.el
- (require 'po-mode)
- ;;(setq auto-mode-alist (cons '("\\.po$" . po-mode) auto-mode-alist))
- (setq auto-mode-alist
- (cons '("\\.po\\'\\|\\.po\\." . po-mode) auto-mode-alist))
- (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) ?\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-min))
- (while (re-search-forward "\\\\n\"\n" nil t)
- (replace-match "n\"\n" t t)) ;以上三行是新增加的二次处理
- (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))))
- (add-hook 'po-subedit-mode-hook 'auto-fill-mode)
目前还有一个问题,就是二次编辑一些条目时,之前的一些符号控制设置,比如
\n 或换行这样的,会丢失,查了一下,好像时那个 po-extract-part-unquoted
函数的问题,暂时还没有看,下面有空了就研究下这个,改进一下吧。


Store Rock…
Store Rock…
07月 16th, 2009 at 5:59 am