From a4b7de02b0389feff60570afb9d97f0123bbbc0f Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 20 Jul 2023 21:27:39 +1000 Subject: grok from wiki mode --- emacs/.emacs.d/init/ycp-markup.el | 4 +++- emacs/.emacs.d/lisp/my/link-gopher.el | 2 +- emacs/.emacs.d/lisp/my/my-wikipedia.el | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) (limited to 'emacs') diff --git a/emacs/.emacs.d/init/ycp-markup.el b/emacs/.emacs.d/init/ycp-markup.el index fb31663..9dc888b 100644 --- a/emacs/.emacs.d/init/ycp-markup.el +++ b/emacs/.emacs.d/init/ycp-markup.el @@ -70,7 +70,9 @@ ;; mediawiki (my-package mediawiki) -(my-package wiki) +(my-package wiki + (my-keybind wiki-mode-map + "C-'" #'my-wiki-grok-wikipedia)) (my-package ledger-mode (:install t) diff --git a/emacs/.emacs.d/lisp/my/link-gopher.el b/emacs/.emacs.d/lisp/my/link-gopher.el index cf8b47a..11bb75d 100644 --- a/emacs/.emacs.d/lisp/my/link-gopher.el +++ b/emacs/.emacs.d/lisp/my/link-gopher.el @@ -106,7 +106,7 @@ removing frags (defun http-s-media-links-in-buffer () (http-s-links-in-buffer - "\\.\\(jpg\\|png\\|gif\\|webp\\|mp4\\|flv\\|mkv\\|mov\\|webm\\|ogv\\|avi\\|rmvb\\|mp3\\|ogg\\|opus\\|pdf\\|docx\\|epub\\)$")) + "\\.\\(jpeg\\|jpg\\|png\\|gif\\|webp\\|mp4\\|flv\\|mkv\\|mov\\|webm\\|ogv\\|avi\\|rmvb\\|mp3\\|ogg\\|opus\\|pdf\\|docx\\|epub\\)$")) (provide 'link-gopher) ;;; link-gopher.el ends here diff --git a/emacs/.emacs.d/lisp/my/my-wikipedia.el b/emacs/.emacs.d/lisp/my/my-wikipedia.el index f2a4365..af954bf 100644 --- a/emacs/.emacs.d/lisp/my/my-wikipedia.el +++ b/emacs/.emacs.d/lisp/my/my-wikipedia.el @@ -31,6 +31,7 @@ (require 'my-markup) (require 'my-net) (require 'my-mediawiki) +(require 'wiki) ;; TODO: much of these can be generalised to any mediawiki site (defvar my-wikipedia-lang "en") @@ -46,6 +47,15 @@ (libxml-parse-html-region (point-min) (point-max)))) (append (my-grok-wikipedia-html html url) results)))) +(defun my-wiki-grok-wikipedia () + "groks current wiki-mode buffer if the site is wikipedia." + (interactive) + (unless (and (derived-mode-p 'wiki-mode) + (string-prefix-p "wikipedia" (format "%s" wiki-site))) + (error "Not in wiki mode or wikipedia.")) + (my-org-grok + (wiki-current-html-url))) + (defun my-grok-wikipedia-get-imdb-rating () (when (re-search-forward "\\(https://\\(www\\.\\)?imdb.com/title/tt[0-9]+/\\)" nil t) @@ -53,9 +63,9 @@ (with-current-buffer (url-retrieve-synchronously (concat url "ratings")) (goto-char (point-min)) - (when + (when (re-search-forward - "\\([0-9,]+\\)\\s-*IMDb.*?\\([0-9\\.]+\\) / 10" nil t) + "\\([0-9,]+\\)\\s-*IMDb.*?\\([0-9\\.]+\\) / 10" nil t) (list (cons "IMDB-link" url) (cons "IMDB-rating" (match-string 2)) (cons "IMDB-rated-by" (match-string 1)))))))) -- cgit v1.2.3