From: stardiviner <numbchild@gmail.com> To: Jean Louis <bugs@gnu.support> Cc: julien@danjou.info, Org-mode <emacs-orgmode@gnu.org> Subject: [UPDATED PATCH] Re: add new link type "contact:" for org-contacts.el Date: Tue, 10 Nov 2020 09:15:54 +0800 Message-ID: <CAL1eYuL6Lk=HCwzu4D23Kme9O5UmfG7DdAc-tp5ka6nJ2iBEWA@mail.gmail.com> (raw) In-Reply-To: <X6jeQC7JxnXTvdjy@protected.rcdrun.com> [-- Attachment #1.1: Type: text/plain, Size: 1088 bytes --] You're right. Thanks for suggestion. I attached new patch now. [stardiviner] <Hack this world!> GPG key ID: 47C32433 IRC(freeenode): stardiviner Twitter: @numbchild Key fingerprint = 9BAA 92BC CDDD B9EF 3B36 CB99 B8C4 B8E5 47C3 2433 Blog: http://stardiviner.github.io/ On Mon, Nov 9, 2020 at 7:05 PM Jean Louis <bugs@gnu.support> wrote: > * stardiviner <numbchild@gmail.com> [2020-11-09 03:25]: > > After waited some days, still no reponse, so I popup this email. > > Can some Org maintainer review my patch? Thanks. > > It does not changed org-contacts.el core logic. Just added a new link > type. > > Should be easy to review. > > If I may say, many people manage their contacts and it can be by > various ways, I am managing my contacts and by default use "contact:" > > I find it useful for people to leave "contact:" link free and not bind > it to org-contact package. > > Instead it is more pointful to make "org-contact:" link that > specificaly points to contacts for org-contact package. > > Just "org-contact:" instead of "contact:" > > [-- Attachment #1.2: Type: text/html, Size: 2040 bytes --] [-- Attachment #2: 0001-org-contacts.el-Add-new-link-type-contact.patch --] [-- Type: text/x-patch, Size: 4181 bytes --] From 7446c0dda49554db0af18401984d20b9b460d408 Mon Sep 17 00:00:00 2001 From: stardiviner <numbchild@gmail.com> Date: Fri, 30 Oct 2020 15:11:53 +0800 Subject: [PATCH] org-contacts.el: Add new link type "contact:" * contrib/lisp/org-contacts.el (org-contacts-link-store): Store a link of org-contacts in Org file. * contrib/lisp/org-contacts.el (org-contacts-link-open): Open contact: link in Org file. * contrib/lisp/org-contacts.el (org-contacts-link-complete): Insert a contact: link with completion of contacts. * contrib/lisp/org-contacts.el (org-contacts-link-face): Set different face for contact: link. --- contrib/lisp/org-contacts.el | 75 ++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/contrib/lisp/org-contacts.el b/contrib/lisp/org-contacts.el index 4b3693a0e..d8d498425 100644 --- a/contrib/lisp/org-contacts.el +++ b/contrib/lisp/org-contacts.el @@ -1146,6 +1146,81 @@ (defun org-contacts-split-property (string &optional separators omit-nulls) (setq proplist (cons bufferstring proplist)))) (cdr (reverse proplist)))) +;;; Add an Org link type `org-contact:' for easy jump to or searching org-contacts headline. +;;; link spec: [[org-contact:query][desc]] +(org-link-set-parameters "org-contact" + :follow 'org-contacts-link-open + :complete 'org-contacts-link-complete + :store 'org-contacts-link-store + :face 'org-contacts-link-face) + +(defun org-contacts-link-store () + "Store the contact in `org-contacts-files' with a link." + (when (eq major-mode 'org-mode) + ;; (member (buffer-file-name) (mapcar 'expand-file-name org-contacts-files)) + (let ((headline-str (substring-no-properties (org-get-heading t t t t)))) + (org-store-link-props + :type "org-contact" + :link headline-str + :description headline-str)))) + +(defun org-contacts--all-contacts () + "Return an alist (name . (file . position)) of all contacts in `org-contacts-files'." + (car (mapcar + (lambda (file) + (unless (buffer-live-p (get-buffer (file-name-nondirectory file))) + (find-file file)) + (with-current-buffer (get-buffer (file-name-nondirectory file)) + (org-map-entries + (lambda () + (let ((name (substring-no-properties (org-get-heading t t t t))) + (file (buffer-file-name)) + (position (point))) + `(:name ,name :file ,file :position ,position)))))) + org-contacts-files))) + +(defun org-contacts-link-open (path) + "Open contacts: link type with jumping or searching." + (let ((query path)) + (cond + ((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))))) + (t + (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 + (goto-char (marker-position (org-find-exact-headline-in-buffer query))))) + ;; FIXME + ;; (let* ((contact-entry (plist-get (org-contacts--all-contacts) query)) + ;; (contact-name (plist-get contact-entry :name)) + ;; (file (plist-get contact-entry :file)) + ;; (position (plist-get contact-entry :position)) + ;; (buf (get-buffer (file-name-nondirectory file)))) + ;; (unless (buffer-live-p buf) (find-file file)) + ;; (with-current-buffer buf (goto-char position))) + )))) + +(defun org-contacts-link-complete (&optional arg) + "Create a org-contacts link using completion." + (let ((name (completing-read "org-contact Name: " + (mapcar + (lambda (plist) (plist-get plist :name)) + (org-contacts--all-contacts))))) + (concat "org-contact:" name))) + +(defun org-contacts-link-face (path) + "Different face color for different org-contacts link query." + (cond + ((string-match "/.*/" path) + '(:background "sky blue" :overline t :slant 'italic)) + (t '(:background "green yellow" :underline t)))) + (provide 'org-contacts) ;;; org-contacts.el ends here -- 2.29.2
next prev parent reply other threads:[~2020-11-10 1:17 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-10-30 7:35 [PATCH] " stardiviner 2020-10-30 7:44 ` stardiviner 2020-11-09 0:24 ` stardiviner 2020-11-09 6:14 ` Jean Louis 2020-11-10 1:15 ` stardiviner [this message] 2020-11-11 8:37 ` [UPDATED PATCH] " Bastien 2020-11-11 12:04 ` stardiviner 2020-11-11 13:57 ` More on design of org-contacts.el - " Jean Louis 2020-11-16 9:26 ` stardiviner 2020-11-17 6:34 ` Jean Louis 2020-12-15 8:46 ` stardiviner 2020-12-14 6:06 ` Bastien 2020-12-15 8:53 ` [final patch] " stardiviner 2020-12-15 9:56 ` Bastien 2020-12-15 14:13 ` stardiviner 2020-12-15 14:27 ` Bastien 2020-11-11 8:33 ` [PATCH] " Bastien
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: https://orgmode.org * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to='CAL1eYuL6Lk=HCwzu4D23Kme9O5UmfG7DdAc-tp5ka6nJ2iBEWA@mail.gmail.com' \ --to=numbchild@gmail.com \ --cc=bugs@gnu.support \ --cc=emacs-orgmode@gnu.org \ --cc=julien@danjou.info \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Org-mode mailing list This inbox may be cloned and mirrored by anyone: git clone --mirror https://orgmode.org/list/0 list/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 list list/ https://orgmode.org/list \ emacs-orgmode@gnu.org public-inbox-index list Example config snippet for mirrors. Newsgroups are available over NNTP: nntp://news.yhetil.org/yhetil.emacs.orgmode nntp://news.gmane.io/gmane.emacs.orgmode AGPL code for this site: git clone https://public-inbox.org/public-inbox.git