[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/systemd 37541b2 003/131: add facility for browsing documen
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/systemd 37541b2 003/131: add facility for browsing documentation |
Date: |
Sun, 29 Aug 2021 11:35:04 -0400 (EDT) |
branch: elpa/systemd
commit 37541b27ce04000eb4a596083ce0e1bae32e7914
Author: Mark Oteiza <mvoteiza@udel.edu>
Commit: Mark Oteiza <mvoteiza@udel.edu>
add facility for browsing documentation
---
systemd-mode.el | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 60 insertions(+), 1 deletion(-)
diff --git a/systemd-mode.el b/systemd-mode.el
index 38a82ca..90ef1c8 100644
--- a/systemd-mode.el
+++ b/systemd-mode.el
@@ -22,10 +22,18 @@
;;; Code:
+(require 'thingatpt)
+(require 'url-parse)
+
(defgroup systemd ()
"Major mode for editing systemd units."
:group 'tools)
+(defcustom systemd-browse-url-function 'eww
+ "Browser to use for HTTP(S) documentation."
+ :group 'systemd
+ :type '(choice function))
+
(defcustom systemd-comment-start "#"
"String to insert to start a new comment."
:group 'systemd
@@ -53,6 +61,48 @@
"Default expressions to highlight in `systemd-mode'. See systemd.unit(5)
for details on unit file syntax.")
+(defun systemd-get-value (start)
+ "Joins lines in the key value starting at buffer position START,
+possibly broken by a backslash, and returns a string containing
+the value."
+ (save-excursion
+ (let ((break "\\\\\n")
+ end)
+ (while (progn (goto-char (- (line-end-position) 1))
+ (looking-at break))
+ (forward-line))
+ (setq end (line-end-position))
+ (replace-regexp-in-string break " " (buffer-substring start end)))))
+
+(defun systemd-doc-find ()
+ "Find the value of the unit's “Documentation” keys and return
+as a list of strings, otherwise nil."
+ (let ((key "^Documentation=")
+ string)
+ (save-excursion
+ (goto-char (point-min))
+ (while (re-search-forward key nil t)
+ (setq string (concat string " " (systemd-get-value (point))))))
+ (when string
+ (split-string string))))
+
+(defun systemd-doc-open (url)
+ "Open URL. Interactively completes the documentation in the
+current unit file, defaulting to the link under point, if any."
+ (interactive
+ (let* ((uri (thing-at-point-url-at-point))
+ (prompt (concat "URL"
+ (when uri (format " (default %s)" uri))
+ ": ")))
+ (list (completing-read prompt (systemd-doc-find) nil nil nil nil uri))))
+ (let ((link (url-generic-parse-url url)))
+ (pcase (url-type link)
+ ("file" (find-file (url-filename link)))
+ ("man" (url-man link))
+ ("info" (url-info link))
+ ((or "http" "https") (apply systemd-browse-url-function `(,url)))
+ (_ (user-error "Invalid link")))))
+
(defvar systemd-mode-syntax-table
(let ((table (make-syntax-table)))
(modify-syntax-entry ?\" ". " table)
@@ -61,6 +111,12 @@ for details on unit file syntax.")
table)
"Syntax table used in `systemd-mode' buffers.")
+(defvar systemd-mode-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map (kbd "C-c C-o") 'systemd-doc-open)
+ map)
+ "Keymap used in `systemd-mode' buffers.")
+
;;;###autoload (add-to-list 'auto-mode-alist '("\\.automount\\'" .
systemd-mode))
;;;###autoload (add-to-list 'auto-mode-alist '("\\.busname\\'" . systemd-mode))
;;;###autoload (add-to-list 'auto-mode-alist '("\\.mount\\'" . systemd-mode))
@@ -77,7 +133,10 @@ for details on unit file syntax.")
"Major mode for editing systemd unit files. See
http://www.freedesktop.org/wiki/Software/systemd/ for more
information about systemd. The hook `systemd-mode-hook' is run
-at mode initialization."
+at mode initialization.
+
+Key bindings:
+\\{systemd-mode-map}"
(set-syntax-table systemd-mode-syntax-table)
(setq-local comment-start systemd-comment-start)
(setq-local font-lock-defaults '(systemd-font-lock-keywords))
- [nongnu] elpa/systemd 612c3de 027/131: double bump, (continued)
- [nongnu] elpa/systemd 612c3de 027/131: double bump, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 347c157 031/131: lexical binding, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd e7a2efb 021/131: mention `package-install-file` in README, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd ed00e3f 029/131: require 24.4 (with-eval-after-load), ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd ef24360 037/131: spaces unneeded in syntax table modifications, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 0c871fc 042/131: Use four different candidate lists:, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 602d9d3 050/131: reword some commentary, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 6fd29c5 070/131: font lock keywords: comments and sections, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd ff523bc 071/131: woops, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 2e6309d 002/131: add systemd-mode.el, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 37541b2 003/131: add facility for browsing documentation,
ELPA Syncer <=
- [nongnu] elpa/systemd 930e82e 100/131: font lock additional exec prefix, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 9cfd315 102/131: simplify, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 1e7567a 117/131: prepare v1.6, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 077aedd 125/131: systemd 244 directives, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 53b44ad 001/131: initial commit, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 7bdb35a 032/131: mention package archive in README, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 3cb77a5 013/131: add a link, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd a46e81b 017/131: autoload for slice units, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd b03e616 079/131: bump, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd a1633c2 083/131: systemd 231 directives, ELPA Syncer, 2021/08/29