;;; phobos.el --- view Phobos documentation from within Emacs -*- lexical-binding:t -*- ;; Copyright (C) 2024 Jeremy Baxter ;; Author: Jeremy Baxter ;; Created: July 2024 ;; Keywords: d ;; This file is not part of GNU Emacs. ;; phobos.el 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. ;; ;; phobos.el 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 phobos.el. If not, see . ;;; Code: (defvar phobos-browser "xdg-open" "Web browser to use when opening documentation with `phobos'.") (defvar phobos-root "https://dlang.org/library" "Root URL to use when viewing documentation with `phobos'.") (defvar phobos-dpldocs-domain "dpldocs.info" "Root domain to use when viewing documentation on dub packages with `dub-doc'.") (defvar phobos-registry-root "https://code.dlang.org" "Root URL of the D package registry used with `describe-dub-package'.") (defun phobos (symbol) "View the documentation on SYMBOL from the Phobos documentation. SYMBOL can be a module (e.g. std.sumtype), a submodule (e.g. std.algorithm.searching), a function or type (e.g. std.stdio.File) 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 ." (interactive "MModule or symbol: ") (shell-command (format "%s %s/%s.html" phobos-browser phobos-root (string-replace "." "/" symbol)))) (defun dub-doc (package &optional symbol) "View the documentation on SYMBOL from the dub package PACKAGE. PACKAGE is the name of a package listed on the code.dlang.org registry. For more information on SYMBOL, see the documentation for `phobos'. If SYMBOL is not provided, the contents of PACKAGE is displayed instead. Support for dub package documentation is provided by Adam Ruppe's site hosted at ." (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))) (defalias 'view-dub-documentation 'dub-doc) (defun describe-dub-package (package) "View the home page for dub package PACKAGE. 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))) (provide 'phobos)