学习再学习,多少大秘密

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
  1. (require 'po-mode)
  2.  
  3. ;;(setq auto-mode-alist (cons '("\\.po$"  . po-mode) auto-mode-alist))
  4. (setq auto-mode-alist
  5.       (cons '("\\.po\\'\\|\\.po\\." . po-mode) auto-mode-alist))
  6.  
  7. (defun po-eval-requoted (form prefix obsolete)
  8.   "Eval FORM, which inserts a string, and return the string fully requoted.
  9.    If PREFIX, precede the result with its contents.  If OBSOLETE, comment all
  10.    generated lines in the returned string.  Evaluating FORM should insert the
  11.    wanted string in the buffer which is current at the time of evaluation.
  12.    If FORM is itself a string, then this string is used for insertion."
  13.   (po-with-temp-buffer
  14.    (if (stringp form)
  15.        (insert form)
  16.      (push-mark)
  17.      (eval form))
  18.    (goto-char (point-min))
  19.    (let ((multi-line (re-search-forward "[^\n]\n+[^\n]" nil t)))
  20.      (goto-char (point-min))
  21.      (while (re-search-forward "[\"\a\b\f\n\r\t\\]" nil t)
  22.        (cond ((eq (preceding-char) ?\") (replace-match "\\\"" t t))
  23.      ((eq (preceding-char) ?\a) (replace-match "\\a" t t))
  24.      ((eq (preceding-char) ?\b) (replace-match "\\b" t t))
  25.      ((eq (preceding-char) ?\f) (replace-match "\\f" t t))
  26.              ((eq (preceding-char) ?\n) ;(replace-match "\n" t t))
  27.       (replace-match (if (or (not multi-line) (eobp))
  28. "\\n"
  29.        "\"\n\"") ;修改一
  30.      t t))
  31.      ((eq (preceding-char) ?\r) (replace-match "\\r" t t))
  32.      ((eq (preceding-char) ?\t) (replace-match "\\t" t t))
  33.      ((eq (preceding-char) ?\\) (replace-match "\\\\" t t))))
  34.      (goto-char (point-min))
  35.      (if prefix (insert prefix " "))
  36.      (insert (if multi-line "\"\"\n\"" "\""))
  37.      (goto-char (point-min))
  38.      (while (re-search-forward "\\\\n\"\n" nil t)
  39.        (replace-match "n\"\n" t t)) ;以上三行是新增加的二次处理
  40.      (goto-char (point-max))
  41.      (insert "\"")
  42.      (if prefix (insert "\n"))
  43.      (if obsolete
  44. (progn
  45.    (goto-char (point-min))
  46.    (while (not (eobp))
  47.      (or (eq (following-char) ?\n) (insert "#~ "))
  48.      (search-forward "\n"))))
  49.     
  50.      (buffer-string))))
  51.  
  52. (add-hook 'po-subedit-mode-hook 'auto-fill-mode)

目前还有一个问题,就是二次编辑一些条目时,之前的一些符号控制设置,比如
\n 或换行这样的,会丢失,查了一下,好像时那个 po-extract-part-unquoted
函数的问题,暂时还没有看,下面有空了就研究下这个,改进一下吧。

One Response to “小修改了一下 po-mode 的配置”

  1. 1
    Store Rock Says:

    Store Rock…

    Store Rock…

Leave a Reply



Spam Protection by WP-SpamFree

© 2010 学习再学习,多少大秘密 | Entries (RSS) and Comments (RSS)

Your Index Web Directorywordpress logo