|
;;; fudeo2hagaki-design.el --- Convert AddressBook from Fudeo to Hagaki Design |
|
;; -*- Mode: Emacs-Lisp -*- |
|
|
|
;; Copyright (C) 2014 Masayuki Ataka <[email protected]> |
|
|
|
;; Author: Masayuki Ataka <[email protected]> |
|
;; Keywords: tools, convenience |
|
|
|
;; This file is not part of GNU Emacs. |
|
|
|
;; This program is free software; you can redistribute it and/or modify |
|
;; it under the terms of the GNU General Public License as published by |
|
;; the Free Software Foundation; either version 2, or (at your option) |
|
;; any later version. |
|
|
|
;; This program is distributed in the hope that it will be useful, |
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
;; GNU General Public License for more details. |
|
|
|
;; You should have received a copy of the GNU General Public License |
|
;; along with this program; if not, you can either send email to this |
|
;; program's maintainer or write to: The Free Software Foundation, |
|
;; Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA. |
|
|
|
;;; Code: |
|
|
|
(defconst fudeo2hagaki-design-prefecture-names-list |
|
'("北海道" "青森県" "岩手県" "宮城県" "秋田県" "山形県" "福島県" "茨城県" "栃木県" "群馬県" "埼玉県" "千葉県" "東京都" "神奈川県" "新潟県" "富山県" "石川県" "福井県" "山梨県" "長野県" "岐阜県" "静岡県" "愛知県" "三重県" "滋賀県" "京都府" "大阪府" "兵庫県" "奈良県" "和歌山県" "鳥取県" "島根県" "岡山県" "広島県" "山口県" "徳島県" "香川県" "愛媛県" "高知県" "福岡県" "佐賀県" "長崎県" "熊本県" "大分県" "宮崎県" "鹿児島県" "沖縄県") |
|
"List of Japanese prefecture names") |
|
|
|
(defconst fudeo2hagaki-design-zenkaku-space " " |
|
"Zenkaku Space") |
|
|
|
|
|
(defun fudeo2hagaki-design-convert-addressbook (beg end) |
|
"Convert CSV AddressBook from Fudeo to Hagaki Design in region |
|
Fudeo should export in following format: |
|
1: Name |
|
2: Kana |
|
3: Zip Number |
|
4: Address 1 |
|
5: Address 2 |
|
6: Address 3 |
|
7: Company |
|
8: Department |
|
9: Title |
|
10: Joint Signature 1 |
|
11: Joint Signature 2 |
|
12: Joint Signature 3" |
|
(interactive "r") |
|
(save-excursion |
|
(save-restriction |
|
(narrow-to-region beg end) |
|
(japanese-zenkaku-region beg end t) |
|
(fudeo2hagaki-design-convert-name) |
|
(fudeo2hagaki-design-convert-furigana) |
|
(fudeo2hagaki-design-split-prefecture)))) |
|
|
|
(defun fudeo2hagaki-design-convert-name () |
|
(save-excursion |
|
(goto-char (point-min)) |
|
(while (not (= (progn (end-of-line) (point)) (point-max))) |
|
(forward-line 0) |
|
(let ((beg (point)) |
|
(bound (search-forward "," nil t))) |
|
(goto-char beg) |
|
(fudeo2hagaki-design-convert-space-zenkaku-to-hankaku bound) |
|
(fudeo2hagaki-design-replace-space-with-comma bound)) |
|
(forward-line 1)))) |
|
|
|
(defun fudeo2hagaki-design-convert-furigana () |
|
(save-excursion |
|
(goto-char (point-min)) |
|
(while (not (= (progn (end-of-line) (point)) (point-max))) |
|
(forward-line 0) |
|
(search-forward "," nil t 2) |
|
(let ((beg (point)) |
|
(bound (search-forward "," nil t))) |
|
(goto-char beg) |
|
(fudeo2hagaki-design-convert-space-zenkaku-to-hankaku bound) |
|
(fudeo2hagaki-design-replace-space-with-comma bound)) |
|
(forward-line 1)))) |
|
|
|
(defsubst fudeo2hagaki-design-convert-space-zenkaku-to-hankaku (bound) |
|
(save-excursion |
|
(when (search-forward fudeo2hagaki-design-zenkaku-space bound t) |
|
(replace-match " ")))) |
|
|
|
(defsubst fudeo2hagaki-design-replace-space-with-comma (bound) |
|
(when (re-search-forward " +" bound t) |
|
(replace-match "\",\""))) |
|
|
|
(defun fudeo2hagaki-design-split-prefecture () |
|
(save-excursion |
|
(let ((prefecture-regexp (regexp-opt fudeo2hagaki-design-prefecture-names-list))) |
|
(goto-char (point-min)) |
|
(while (not (= (progn (end-of-line) (point)) (point-max))) |
|
(forward-line 0) |
|
(search-forward "," nil t 5) |
|
(let ((beg (point)) |
|
(bound (search-forward "," nil t))) |
|
(goto-char beg) |
|
(re-search-forward prefecture-regexp bound t) |
|
(insert "\",\"")) |
|
(forward-line 1))))) |
|
|
|
|
|
(provide 'fudeo2hagaki-design.el) |
|
;;; fudeo2hagaki-design.el ends here |
|
|