From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Alexander Adolf Newsgroups: gmane.emacs.devel Subject: Re: [Proposal] New EUDC backend for macOS address book Date: Thu, 07 May 2020 18:03:58 +0200 Message-ID: <298df6a619aa45393b0ae9250123faef@condition-alpha.com> References: <8da7df5281e91d8a351f97c0837d79b7@condition-alpha.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="79127"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Jean-Christophe Helary , emacs-devel@gnu.org To: Thomas Fitzsimmons Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu May 07 18:13:23 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jWj9H-000KUv-DH for ged-emacs-devel@m.gmane-mx.org; Thu, 07 May 2020 18:13:23 +0200 Original-Received: from localhost ([::1]:56014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jWj9G-0002N5-FJ for ged-emacs-devel@m.gmane-mx.org; Thu, 07 May 2020 12:13:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37172) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWj0J-0006SY-VJ for emacs-devel@gnu.org; Thu, 07 May 2020 12:04:07 -0400 Original-Received: from smtprelay01.ispgateway.de ([80.67.18.13]:22353) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWj0I-0006xT-30 for emacs-devel@gnu.org; Thu, 07 May 2020 12:04:07 -0400 Original-Received: from [46.244.192.102] (helo=localhost) by smtprelay01.ispgateway.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) (envelope-from ) id 1jWj0B-0004Ij-91; Thu, 07 May 2020 18:03:59 +0200 In-Reply-To: X-Df-Sender: YWxleGFuZGVyLmFkb2xmQGNvbmRpdGlvbi1hbHBoYS5jb20= Received-SPF: pass client-ip=80.67.18.13; envelope-from=alexander.adolf@condition-alpha.com; helo=smtprelay01.ispgateway.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/07 12:04:01 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:249189 Archived-At: --=-=-= Content-Type: text/plain Hello Thomas, Thomas Fitzsimmons writes: > [...] > Yes, looks good. I noticed one more formatting thing. font-lock is > showing "result))))" in red; you can type C-h . to check what the > warning is, which in this case is "Hidden behind deeper element; move to > another line?". Can you put that on its own line to eliminate the > warning? Done; result attached. > [...] > This looks good to go in now. Thanks to yourself, Jean-Christophe, and Chad for your interest, and your support in giving it "the final polish". I'm glad you found it useful enough to include it in the next release! > Can you send a draft of the manual change, and then once that's > reviewed, I'll have you put it all into one git-format-patch > attachment (including the commit log/change log entry) and I can push > that to master? > [...] Whatever is good practice here, and what suits you best. Also happy to submit a pull request for emacs/doc/misc/eudc.texi on a git forge of your preference, if that makes it easier for you/everyone. Please advise. Many thanks and cheers, --alexander --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=eudcb-macos-contacts.el Content-Transfer-Encoding: quoted-printable ;;; eudcb-macos-contacts.el --- EUDC - macOS Contacts backend ;; Copyright (C) 2020 condition-alpha.com ;; 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 3 of the License, 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, see . ;;; Commentary: ;; This library provides an interface to the macOS Contacts app as ;; an EUDC data source. It uses AppleScript to interface with the ;; Contacts app on localhost, so no 3rd party tools are needed. ;;; Usage: ;; (require 'eudcb-macos-contacts) ;; (eudc-macos-contacts-set-server "localhost") ;;; Code: (require 'eudc) (require 'executable) ;;{{{ Internal cooking (defvar eudc-macos-contacts-conversion-alist nil) ;; hook ourselves into the EUDC framework (eudc-protocol-set 'eudc-query-function 'eudc-macos-contacts-query-internal 'macos-contacts) (eudc-protocol-set 'eudc-list-attributes-function nil 'macos-contacts) (eudc-protocol-set 'eudc-macos-contacts-conversion-alist nil 'macos-contacts) (eudc-protocol-set 'eudc-protocol-has-default-query-attributes nil 'macos-contacts) (defun eudc-macos-contacts-search-helper (str) "Helper function to query the Contacts app via AppleScript. Searches for all persons with a case-insensitive substring match of STR in any of their name fields (first, middle, or last)." (if (executable-find "osascript") (call-process "osascript" nil t nil "-e" (format " set results to {} tell application \"Address Book\" set pList to every person whose (name contains \"%s\") repeat with pers in pList repeat with emailAddr in emails of pers set results to results & {name of pers & \":\" & value =C2=AC of emailAddr & \"\n\"} end repeat end repeat get results as text end tell" str)) (message (concat "[eudc] Error in macOS Contacts backend: " "`osascript' executable not found. " "Is this is a macOS 10.0 or later system?")))) (defun eudc-macos-contacts-query-internal (query &optional return-attrs) "Query macOS Contacts with QUERY. QUERY is a list of cons cells (ATTR . VALUE) where ATTRs should be valid macOS Contacts attribute names. RETURN-ATTRS is a list of attributes to return, defaulting to `eudc-default-return-attributes'." (let ((macos-contacts-buffer (get-buffer-create " *macOS Contacts*")) result) (with-current-buffer macos-contacts-buffer (erase-buffer) (dolist (term query) (eudc-macos-contacts-search-helper (cdr term))) (delete-duplicate-lines (point-min) (point-max)) (goto-char (point-min)) (while (not (eobp)) (if (not (equal (line-beginning-position) (line-end-position))) (let* ((args (split-string (buffer-substring (point) (line-end-position)) ":")) (name (nth 0 args)) (email (nth 1 args))) (setq result (cons `((name . ,name) (email . ,email)) result)))) (forward-line)) result))) ;;}}} ;;{{{ High-level interfaces (interactive functions) (defun eudc-macos-contacts-set-server (dummy) "Set the EUDC server to macOS Contacts app. The server in DUMMY is not actually used, since this backend always and implicitly connetcs to an instance of the Contacts app running on the local host." (interactive) (eudc-set-server dummy 'macos-contacts) (message "[eudc] macOS Contacts app server selected")) ;;}}} (eudc-register-protocol 'macos-contacts) (provide 'eudcb-macos-contacts) ;;; eudcb-macos-contacts.el ends here --=-=-=--