103 lines
3.4 KiB
EmacsLisp
103 lines
3.4 KiB
EmacsLisp
|
;;; archwiki.el --- Browse the Arch Wiki from Emacs -*- lexical-binding: t -*-
|
|||
|
|
|||
|
;; Author: Lucien Cartier-Tilet <lucien@phundrak.com>
|
|||
|
;; Maintainer: Lucien Cartier-Tilet <lucien@phundrak.com>
|
|||
|
;; Version: 0.1.0
|
|||
|
;; Package-Requires: ((emacs "25") (f "0.20") (s "1"))
|
|||
|
;; Homepage: https://labs.phundrak.com/phundrak/archwiki.el
|
|||
|
;; Keywords: keywords
|
|||
|
|
|||
|
|
|||
|
;; This file is not part of GNU Emacs
|
|||
|
|
|||
|
;; This program is free software: you can redistribute it and/or modify
|
|||
|
;; it under the terms of the GNU General Public License as published by
|
|||
|
;; the Free Software Foundation, either version 3 of the License, or
|
|||
|
;; (at your option) any later version.
|
|||
|
|
|||
|
;; This program is distributed in the hope that it will be useful,
|
|||
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|||
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|||
|
;; GNU General Public License for more details.
|
|||
|
|
|||
|
;; You should have received a copy of the GNU General Public License
|
|||
|
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
|
|
|||
|
;;; Commentary:
|
|||
|
|
|||
|
;; This package relies on the fact the Arch Wiki docs are available to
|
|||
|
;; Emacs, either locally or through TRAMP. If available through TRAMP,
|
|||
|
;; opening pages should work through eww, although it can be slow
|
|||
|
;; depending on the quality of your network, but I don’t expect it to
|
|||
|
;; work with external programs such as qutebrowser, Nyxt, or Firefox.
|
|||
|
|
|||
|
;; If you don’t open the ArchWiki pages through eww, either make sure
|
|||
|
;; `xdg-open' is available in your path or that you customized
|
|||
|
;; `archwiki-external-browser'.
|
|||
|
|
|||
|
;;; Code:
|
|||
|
|
|||
|
(require 'f)
|
|||
|
(require 's)
|
|||
|
|
|||
|
(defgroup archwiki nil
|
|||
|
"browse the Arch Wiki from Emacs."
|
|||
|
:prefix "archwiki-"
|
|||
|
:link '(url-link :tag "Gitea" "https://labs.phundrak.com/phundrak/archwiki.el"))
|
|||
|
|
|||
|
(defcustom archwiki-local-path "/usr/share/doc/arch-wiki/html/en/"
|
|||
|
"Path to local copy of the Arch Wiki."
|
|||
|
:group 'archwiki
|
|||
|
:version "0.1.0"
|
|||
|
:type 'path)
|
|||
|
|
|||
|
(defcustom archwiki-use-eww t
|
|||
|
"Whether to use eww or an external program."
|
|||
|
:group 'archwiki
|
|||
|
:version "0.1.0"
|
|||
|
:type 'boolean
|
|||
|
:safe #'booleanp)
|
|||
|
|
|||
|
(defcustom archwiki-external-browser ""
|
|||
|
"Which external web browser to use.
|
|||
|
If its value is an empty string, use `xdg-open'."
|
|||
|
:group 'archwiki
|
|||
|
:version "0.1.0"
|
|||
|
:type 'string)
|
|||
|
|
|||
|
(defun archwiki--list-web-pages ()
|
|||
|
"List web pages of the Arch Wiki."
|
|||
|
(mapcar
|
|||
|
(lambda (file) (replace-regexp-in-string "_" " " (f-no-ext (f-filename file))))
|
|||
|
(f-files archwiki-local-path
|
|||
|
(lambda (path)
|
|||
|
(s-ends-with-p "html" path t))
|
|||
|
nil)))
|
|||
|
|
|||
|
;;;###autoload
|
|||
|
(defun archwiki (page)
|
|||
|
"Find and open an Arch Wiki PAGE in Emacs.
|
|||
|
|
|||
|
PAGE is the name of the Arch Wiki page we want to open, without
|
|||
|
any underscore or extension."
|
|||
|
(interactive
|
|||
|
`(,(completing-read "Page to open: "
|
|||
|
(archwiki--list-web-pages))))
|
|||
|
(let ((path (concat "file://"
|
|||
|
archwiki-local-path
|
|||
|
(replace-regexp-in-string " " "_" page)
|
|||
|
".html")))
|
|||
|
(if archwiki-use-eww
|
|||
|
(eww-browse-url path)
|
|||
|
(with-temp-buffer
|
|||
|
(call-process (if (or (string= "" archwiki-external-browser)
|
|||
|
(null (executable-find archwiki-external-browser)))
|
|||
|
"xdg-open"
|
|||
|
archwiki-external-browser)
|
|||
|
nil t nil
|
|||
|
path)))))
|
|||
|
|
|||
|
(provide 'archwiki)
|
|||
|
|
|||
|
;;; archwiki.el ends here
|