diff options
-rw-r--r-- | piem-elfeed.el | 3 | ||||
-rw-r--r-- | piem-eww.el | 7 | ||||
-rw-r--r-- | piem.el | 14 |
3 files changed, 16 insertions, 8 deletions
diff --git a/piem-elfeed.el b/piem-elfeed.el index e1ee2f8..5a6472b 100644 --- a/piem-elfeed.el +++ b/piem-elfeed.el @@ -39,8 +39,7 @@ "Return inbox name from an `elfeed-show-mode' buffer." (when (derived-mode-p 'elfeed-show-mode) (when-let ((link (elfeed-entry-link elfeed-show-entry))) - (and (string-match piem-link-re link) - (match-string 1 link))))) + (piem-inbox-by-url-match link)))) (defun piem-elfeed-get-mid () "Return the message ID of an `elfeed-show-mode' buffer." diff --git a/piem-eww.el b/piem-eww.el index e8c77f5..5fb629b 100644 --- a/piem-eww.el +++ b/piem-eww.el @@ -38,12 +38,7 @@ "Return inbox name from an EWW buffer." (when (derived-mode-p 'eww-mode) (when-let ((link (plist-get eww-data :url))) - ;; NEEDSWORK: This relies on the inbox name in the URL matching - ;; the inbox name in `piem-inboxes', which might not be the - ;; case. If there's a :url in `piem-inboxes', that could be - ;; matched instead. - (and (string-match piem-link-re link) - (match-string 1 link))))) + (piem-inbox-by-url-match link)))) (defun piem-eww-get-mid () "Return the message ID of an EWW buffer." @@ -252,6 +252,9 @@ Functions should accept one argument, the message ID given to ;;;; Extractors +(defun piem--ensure-trailing-slash (s) + (if (string-match-p ".+/\\'" s) s (concat s "/"))) + (defvar piem-link-re (rx "/" (group (one-or-more (not (any "/" "\n")))) "/" (group (one-or-more (not (any "/" "\n")))) @@ -301,6 +304,17 @@ intended to be used by libraries implementing a function for (repo (plist-get (cdr (assoc p piem-inboxes)) :coderepo))) (expand-file-name repo))) +(defun piem-inbox-by-url-match (url) + "Return inbox based on matching URL against `:url'." + (setq url (piem--ensure-trailing-slash url)) + (catch 'hit + (dolist (inbox piem-inboxes) + (when-let ((info (cdr inbox)) + (p-url (plist-get info :url))) + (setq p-url (piem--ensure-trailing-slash p-url)) + (when (string-match-p (regexp-quote p-url) url) + (throw 'hit (car inbox))))))) + (defun piem-inbox-url () "Return the URL of current buffer's inbox." (when-let ((p (piem-inbox))) |