[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ebdb 1ae4bbf 206/350: Provide internationalized ebdb-st
From: |
Eric Abrahamsen |
Subject: |
[elpa] externals/ebdb 1ae4bbf 206/350: Provide internationalized ebdb-string and ebdb-parse for phones |
Date: |
Mon, 14 Aug 2017 11:46:37 -0400 (EDT) |
branch: externals/ebdb
commit 1ae4bbfc21085b91e0935b28d7312e1fdb26ff52
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>
Provide internationalized ebdb-string and ebdb-parse for phones
Fixes #29
* ebdb-i18n.el (ebdb-string, ebdb-parse): Provide internationalized
hooks keyed on the integer country code.
* ebdb-chn.el (ebdb-string-i18n, ebdb-parse-i18n): Implement for
Chinese phone numbers.
---
ebdb-chn.el | 34 ++++++++++++++++++++++++++++++++++
ebdb-i18n.el | 18 ++++++++++++++++++
2 files changed, 52 insertions(+)
diff --git a/ebdb-chn.el b/ebdb-chn.el
index 4a6192d..dce7dfe 100644
--- a/ebdb-chn.el
+++ b/ebdb-chn.el
@@ -29,6 +29,40 @@
(require 'chinese-pyim-dictools)
+(cl-defmethod ebdb-string-i18n ((phone ebdb-field-phone)
+ (_cc (eql 86)))
+ (with-slots (area-code number extension) phone
+ (concat
+ "+86 "
+ (if area-code
+ (format "%d-%s" area-code number)
+ number)
+ (if extension
+ (format "X%d" extension)
+ ""))))
+
+(cl-defmethod ebdb-parse-i18n ((class (subclass ebdb-field-phone))
+ (str string)
+ (cc (eql 86))
+ &optional slots)
+ ;; First remove everything but the numbers.
+ (let ((num-str (string-trim
+ (replace-regexp-in-string "[^0-9Xx]+" "" str)))
+ a-code number extension)
+ ;; In China, basically everything that starts with a 1 is a cell
+ ;; number, unless it starts with a 10, in which case it's the
+ ;; Beijing area code. Sometimes the area codes are written with a
+ ;; leading zero, but they shouldn't be saved that way.
+ (when (string-match "\\`0?\\(10\\|[2-9][0-9]\\{1,2\\}\\)?\\([0-9]+\\)"
num-str)
+ (setq a-code (match-string 1 num-str)
+ slots (plist-put slots :number (match-string 2 num-str)))
+ (when a-code
+ (setq slots (plist-put slots :area-code (string-to-number a-code)))))
+ (when (string-match "X\\([0-9]+\\)\\'" num-str)
+ (setq slots (plist-put slots :extension
+ (string-to-number (match-string 1 num-str)))))
+ (apply #'make-instance 'ebdb-field-phone slots)))
+
;; This isn't all of them, but it seems like a reasonable subset. See
;; https://en.wikipedia.org/wiki/Chinese_compound_surname for a fuller
;; list.
diff --git a/ebdb-i18n.el b/ebdb-i18n.el
index 2230e27..3224489 100644
--- a/ebdb-i18n.el
+++ b/ebdb-i18n.el
@@ -149,6 +149,24 @@ for their symbol representations.")
slots)))
(cl-call-next-method class slots obj)))
+(cl-defmethod ebdb-string :extra "i18n" ((phone ebdb-field-phone))
+ "Internationally-aware version of `ebdb-string' for phones."
+ (let ((cc (slot-value phone 'country-code)))
+ (or (and cc
+ (condition-case nil
+ (ebdb-string-i18n phone cc)
+ (cl-no-applicable-method nil)))
+ (cl-call-next-method))))
+
+(cl-defmethod ebdb-parse :extra "i18n" ((class (subclass ebdb-field-phone))
+ (str string)
+ &optional slots)
+ (let ((cc (plist-get slots :country-code)))
+ (or (and cc
+ (condition-case nil
+ (ebdb-parse-i18n class str cc slots)
+ (cl-no-applicable-method nil)))
+ (cl-call-next-method))))
;; We don't need to override the `ebdb-read' method for names. It
;; only matters what script the name is in if the user has set
- [elpa] externals/ebdb e4c0442 162/350: Fix up actions and EBDB buffer menus, (continued)
- [elpa] externals/ebdb e4c0442 162/350: Fix up actions and EBDB buffer menus, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 09e421f 156/350: Rework anniversary/diary integration, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb a8e44ee 175/350: Update company-ebdb for new search behavior, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb ece91cb 176/350: Remove spurious ebdb-record-search implementation, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 86a3aa9 180/350: Change signature of ebdb-undisplay-records, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 05cf7ec 184/350: New ebdb-message-buffer-name subst, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb ae377c1 199/350: Use ebdb-field-search in notes-type record searches, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 54bb078 200/350: Remove final references to ebdb-print, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 072bb74 205/350: ebdb-parse-i18n must also accept a slots argument, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 79ed878 201/350: Handle formatting to a fake *EBDB* buffer, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 1ae4bbf 206/350: Provide internationalized ebdb-string and ebdb-parse for phones,
Eric Abrahamsen <=
- [elpa] externals/ebdb 0cb406e 210/350: Expand ebdb-test-save-vars to save ebdb-db-list as well, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 722e2c3 211/350: Mild hack to make pop up windows work well, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 374919e 196/350: Fixes to proper name formatting, part III, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 0ccfc0a 215/350: Write generics for ebdb-db-add/remove-record, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 498a580 214/350: Allow user transformation of search strings, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 760fd91 204/350: More informative warning when deleting record fields, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 762f027 219/350: Add Makefile, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 325426e 207/350: Add ebdb-complete.el (#32), Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb ea13778 221/350: Autoload calendar-absolute-from-gregorian, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb af13080 218/350: Support sending text messages via Signal, Eric Abrahamsen, 2017/08/14