phobos.el: reduce repetition with phobos--visit

This commit is contained in:
Jeremy Baxter 2024-07-17 18:36:53 +12:00
parent 491559212b
commit 05f482e7dc

View file

@ -32,6 +32,11 @@
(defvar phobos-registry-root "https://code.dlang.org"
"Root URL of the D package registry used with `describe-dub-package'.")
(defun phobos--visit (&rest format-args)
(let ((url (apply #'format format-args)))
(shell-command (concat phobos-browser " " url))
(message url)))
(defun phobos (symbol)
"View the documentation on SYMBOL from the Phobos documentation.
@ -42,9 +47,7 @@ or any other symbol part of a standard module, such as object.Exception.
Phobos is the standard library for the D programming language. For more
information on Phobos and the D programming language, see <https://dlang.org>."
(interactive "MModule or symbol: ")
(shell-command (format "%s %s/%s.html"
phobos-browser phobos-root
(string-replace "." "/" symbol))))
(phobos--visit "%s/%s.html" phobos-root (string-replace "." "/" symbol)))
(defun dub-doc (package &optional symbol)
"View the documentation on SYMBOL from the dub package PACKAGE.
@ -57,8 +60,8 @@ Support for dub package documentation is provided by Adam Ruppe's
site hosted at <https://dpldocs.info>."
(interactive "MPackage name: \nMModule or symbol: ")
(or symbol (setq symbol "index")) ; index.html
(shell-command (format "%s https://%s.%s/%s.html"
phobos-browser package phobos-dpldocs-domain symbol)))
(phobos--visit "https://%s.%s/%s.html"
package phobos-dpldocs-domain symbol))
(defalias 'view-dub-documentation 'dub-doc)
@ -68,7 +71,7 @@ site hosted at <https://dpldocs.info>."
PACKAGE is the name of a package listed on the code.dlang.org registry.
Also see `dub-doc' for retrieving documentation for a specific symbol."
(interactive "MPackage name: ")
(shell-command (format "%s %s/packages/%s"
phobos-browser phobos-registry-root package)))
(phobos--visit "%s/packages/%s"
phobos-registry-root package))
(provide 'phobos)