mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-15 10:30:25 -08:00
Also remove some redundant `:group` arguments. * lisp/net/eudc-export.el: Use lexical-binding. (eudc-create-bbdb-record): Use `cl-progv` and `apply` to avoid `eval`. * lisp/net/eudc-hotlist.el: Use lexical-binding. * lisp/net/eudc.el (eudc-print-attribute-value): Use `funcall` to avoid `eval`. * lisp/net/eudcb-bbdb.el: Use lexical-binding. (eudc-bbdb-filter-non-matching-record): Use `funcall` to avoid `eval`. Move `bbdb-val` binding to avoid `setq`. Use `seq-some` instead of `eval+or`. (eudc-bbdb-format-record-as-result): Use `dolist` and `pcase`. Use `funcall` to avoid `eval`. (eudc-bbdb-query-internal): Simplify a bit. * lisp/net/eudcb-ldap.el: Use lexical-binding. (eudc-ldap-get-host-parameter): Use `defalias` to avoid `eval-and-compile`. * lisp/net/telnet.el: Use lexical-binding. * lisp/net/quickurl.el: Use lexical-binding. * lisp/net/newst-ticker.el: Use lexical-binding. * lisp/net/newst-reader.el: Use lexical-binding. * lisp/net/goto-addr.el: Use lexical-binding. * lisp/net/gnutls.el: Use lexical-binding. * lisp/net/eudcb-macos-contacts.el: Use lexical-binding. * lisp/net/eudcb-mab.el: Use lexical-binding. * lisp/net/net-utils.el: Use lexical-binding. (finger): Remove unused var `found`. * lisp/net/network-stream.el (open-protocol-stream): Remove redundant `defalias`. * lisp/net/newst-plainview.el: Use lexical-binding. (newsticker-hide-entry, newsticker-show-entry): Remove unused var `is-invisible`. (w3m-fill-column, w3-maximum-line-length): Declare vars. * lisp/net/tramp.el (tramp-compute-multi-hops): * lisp/net/tramp-compat.el (tramp-compat-temporary-file-directory): * lisp/net/tramp-cmds.el (tramp-default-rename-file): * lisp/net/webjump.el (webjump): Don't forget lexical-binding for `eval`.
123 lines
4 KiB
EmacsLisp
123 lines
4 KiB
EmacsLisp
;;; eudcb-macos-contacts.el --- EUDC - macOS Contacts backend -*- lexical-binding: t; -*-
|
|
|
|
;; Copyright (C) 2020-2021 Free Software Foundation, Inc.
|
|
|
|
;; Author: Alexander Adolf
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;; GNU Emacs 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.
|
|
|
|
;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
;;; 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 ¬
|
|
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 connects 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
|