;;; phobos.el --- view Phobos documentation from within Emacs -*- lexical-binding:t -*- ;; Copyright (C) 2024 Jeremy Baxter ;; Author: Jeremy Baxter ;; Maintainer: 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 . ;;; Commentary: ;; phobos.el provides several functions for viewing Phobos documentation ;; and documentation for other D libraries. These functions open the ;; documentation in a web browser, calling the process `phobos-browser'. ;; These functions are provided: ;; * `phobos': view Phobos documentation ;; * `dub-doc': view documentation for a symbol in a dub package ;; * `describe-dub-package': view the home page for a dub package ;; An alias `view-dub-documentation' also exists for `dub-doc'. ;;; Code: (defgroup phobos nil "View D documentation from within Emacs." :prefix "phobos-" :group 'languages) (defcustom phobos-browser "xdg-open" "Web browser to use when opening documentation with `phobos'." :group 'phobos :type 'string) (defcustom phobos-root "https://dlang.org/library" "Root URL to use when viewing documentation with `phobos'." :group 'phobos :type 'string) (defcustom phobos-dpldocs-domain "dpldocs.info" "Root domain to use when viewing documentation on dub packages with `dub-doc'." :group 'phobos :type 'string) (defcustom phobos-registry-root "https://code.dlang.org" "Root URL of the D package registry used with `describe-dub-package'." :group 'phobos :type 'string) (defun phobos--visit (&rest format-args) (let ((url (apply #'format format-args))) (shell-command (concat phobos-browser " " url)) (message url))) ;;;###autoload (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: ") (phobos--visit "%s/%s.html" phobos-root (string-replace "." "/" symbol))) ;;;###autoload (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 (phobos--visit "https://%s.%s/%s.html" package phobos-dpldocs-domain symbol)) ;;;###autoload (defalias 'view-dub-documentation 'dub-doc) ;;;###autoload (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: ") (phobos--visit "%s/packages/%s" phobos-registry-root package)) (provide 'phobos) ;;; phobos.el ends here