From 8a074f2a41ea7bec4f8396955ccec172d7f8a08b Mon Sep 17 00:00:00 2001 From: stardiviner Date: Thu, 18 Nov 2021 16:53:06 +0800 Subject: [PATCH] company-mode doc-buffer return customized buffer which support customization --- org-contacts.el | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/org-contacts.el b/org-contacts.el index 44eb016..d9d9e2b 100644 --- a/org-contacts.el +++ b/org-contacts.el @@ -639,20 +639,29 @@ description." (org-contacts--all-contacts))) (name (plist-get contact :name)) (file (plist-get contact :file)) - (position (plist-get contact :position))) - (company-doc-buffer - ;; get org-contact headline and property drawer. - (with-current-buffer (find-file-noselect file) - (goto-char position) - (when (derived-mode-p 'org-mode) - ;; `org-edit-src-code' is not a real narrowing command. - ;; Remove this first conditional if you don't want it. - (cond ((ignore-errors (org-edit-src-code)) - (delete-other-windows)) - ((org-at-block-p) - (org-narrow-to-block)) - (t (org-narrow-to-subtree))) - (buffer-substring (point-min) (point-max))))))) + (position (plist-get contact :position)) + (doc-buffer (get-buffer-create " *org-contact*")) + (org-contact-buffer (get-buffer (find-file-noselect file))) + ;; get org-contact headline and property drawer. + (contents (with-current-buffer org-contact-buffer + (goto-char position) + (when (derived-mode-p 'org-mode) + ;; `org-edit-src-code' is not a real narrowing command. + ;; Remove this first conditional if you don't want it. + (cond ((ignore-errors (org-edit-src-code)) + (delete-other-windows)) + ((org-at-block-p) + (org-narrow-to-block)) + (t (org-narrow-to-subtree))) + (buffer-substring (point-min) (point-max)))))) + (with-current-buffer doc-buffer + (read-only-mode 1) + (let ((inhibit-read-only t)) + (erase-buffer) + (insert contents) + (org-mode) + (org-show-all))) + doc-buffer)) (defun org-contacts-org-complete--location-function (candidate) "Return org-contacts location of contact candidate."