Refactor duplicated open org-contacts file and create buffer

This commit is contained in:
stardiviner 2022-12-21 12:27:53 +08:00
parent bd5093e46b
commit b7d176dcfb

View file

@ -1301,31 +1301,29 @@ Each element has the form (NAME . (FILE . POSITION))."
(org-contacts-files))))
;;;###autoload
(defun org-contacts-link-open (path)
(defun org-contacts-link-open (query)
"Open contacts: link type with jumping or searching."
(let ((query path))
(let* ((f (car (org-contacts-files)))
(fname (file-name-nondirectory f))
(buf (progn
(unless (buffer-live-p (get-buffer fname)) (find-file f))
(get-buffer fname))))
(cond
;; /query/ format searching
((string-match "/.*/" query)
(let* ((f (car (org-contacts-files)))
(buf (get-buffer (file-name-nondirectory f))))
(unless (buffer-live-p buf) (find-file f))
(with-current-buffer buf
(string-match "/\\(.*\\)/" query)
(occur (match-string 1 query)))))
(occur (match-string 1 query))))
;; jump to exact contact headline directly
(t
(let* ((f (car (org-contacts-files)))
(_ (find-file f))
(buf (get-buffer (file-name-nondirectory f))))
(with-current-buffer buf
(goto-char (marker-position (org-find-exact-headline-in-buffer query))))
(display-buffer buf '(display-buffer-below-selected)))
(let ((position (org-find-exact-headline-in-buffer query)))
(goto-char (marker-position position))))
(display-buffer buf '(display-buffer-below-selected))
;; (let* ((f (car (org-contacts-files)))
;; (_ (find-file f))
;; ;; FIXME:
;; (contact-entry (map-filter
;; FIXME:
;; (let* ((contact-entry (map-filter
;; (lambda (contact-plist)
;; (if (string-equal (plist-get contact-plist :name) query)
;; contact-plist))