>From 35c018604c93d7f7f4a52393c7e55dab185c0f90 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Mon, 11 Jul 2022 05:14:57 -0700 Subject: [PATCH 09/10] [POC] Demo improved ol-irc integration * lisp/erc/erc.el (erc--org-init, erc--handle-url-org-visit, erc--handle-url-org-visit-irc, erc--handle-url-org-visit-ircs): Add various functions to demo org link integration. --- lisp/erc/erc.el | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index fd91441828..7137a7b401 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -7602,6 +7602,58 @@ erc--handle-ircs-url ;; Amazingly, this does TRT for /&chan, /#chan, /##chan, /#&chan (url-irc url))) +;; ERASE ME +;; +;; Org's ol-irc.el is pretty elaborate. But a lot of things have to +;; go perfectly for joining and prompting to work as intended. + +(defun erc--handle-url-org-visit (ircsp link) + ;; The dispatcher that calls `org-irc-visit' strips the scheme and + ;; colon, leaving only "//irc.gnu.org/#chan", which becomes + ;; (("irc.gnu.org") "#chan") when parsed by `org-irc-parse-link'. + (pcase-let* + ((`((,server ,port) ,channel ,nick) link) + (oj (and nick + (lambda () + (cl-assert nick) + ;; Channel may not be populated yet + (unless (erc-get-server-user nick) + (erc-error "%s not found in %s" nick (erc-default-target))) + (goto-char erc-input-marker) + (insert (concat nick ": "))))) + (fn (or (if ircsp + erc--url-ircs-connect-function + erc--url-irc-connect-function) + (apply-partially #'erc--url-default-connect-function + (and ircsp t))))) + (erc-handle-irc-url server port channel nil nil fn oj))) + +(declare-function org-irc-parse-link "ol-irc" (link)) +(declare-function org-link-get-parameter "ol" (type key)) +(declare-function org-link-set-parameters "ol" (type &rest parameters)) + +(defun erc--handle-url-org-follow-irc (link _) + (erc--handle-url-org-visit nil (org-irc-parse-link link))) + +(defun erc--handle-url-org-follow-ircs (link _) + (erc--handle-url-org-visit t (org-irc-parse-link link))) + +;; Eventually, we should petition for `org-irc-visit-erc' to call our +;; stuff to do the heavy lifting, assuming a new enough Emacs is +;; present. The following is only for demo purposes. + +(defun erc--org-init () + ;; TODO also add irc6 and irc6s (possibly nonstandard) + (require 'ol-irc) + (org-link-set-parameters + "irc" + :follow #'erc--handle-url-org-follow-irc) + (org-link-set-parameters + "ircs" + :follow #'erc--handle-url-org-follow-ircs + :store (org-link-get-parameter "irc" :store) + :export (org-link-get-parameter "irc" :export))) + (provide 'erc) -- 2.36.1