;;; systemd.el --- Major mode for editing systemd units -*- lexical-binding: t -*- ;; Copyright (C) 2014-2016 Mark Oteiza ;; Author: Mark Oteiza ;; Version: 1.3.1 ;; Package-Requires: ((emacs "24.4")) ;; Keywords: tools, unix ;; This file 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 file 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 file. If not, see . ;;; Commentary: ;; Major mode for editing systemd units. ;; Similar to `conf-mode' but with added highlighting; e.g. for ;; specifiers and booleans. Employs strict regex for whitespace. ;; Features a facility for browsing documentation: use C-c C-o to open ;; links to documentation in a unit (cf. systemctl help). ;; Supports completion of directives and sections in either units or ;; network configuration. Both a completer for ;; `completion-at-point-functions' and a company backend are provided. ;; The latter can be enabled by adding `company-mode' to ;; `systemd-mode-hook'. ;;; Code: (require 'conf-mode) (require 'thingatpt) (require 'url-parse) (declare-function company-begin-backend "company") (declare-function company-grab-symbol "company") (defgroup systemd () "Major mode for editing systemd units." :link '(url-link "http://www.freedesktop.org/wiki/Software/systemd/") :group 'tools) (defcustom systemd-browse-url-function 'browse-url "Browser to use for HTTP(S) documentation." :type `(radio (function-item browse-url) ,@(when (fboundp 'eww) '((function-item eww))) ,@(when (fboundp 'w3m-browse-url) '((function-item w3m-browse-url))) (function :tag "Other function")) :group 'systemd) (defcustom systemd-comment-start "#" "String to insert to start a new comment." :type '(choice (string :tag "Comment sign" "#") (string :tag "Semicolon" ";")) :group 'systemd) (defcustom systemd-man-function 'man "Pager to use for system manual pages." :type '(radio (function-item man) (function-item woman) (function :tag "Other function")) :group 'systemd) (defcustom systemd-use-company-p nil "Whether to use `company-mode' for completion, if available." :type 'boolean :group 'systemd) (defconst systemd-unit-sections '("Unit" "Install" "Service") "Configuration sections for systemd 225.") (defconst systemd-unit-directives ;; TODO: keep a script of sorts for generating this list. systemd ;; source has a python script in tools/ for parsing the ;; documentation xml for the unit directives. ;; ;; forcer on freenode threw together a curl monstrosity for achieving ;; the same: ;; curl -s http://www.freedesktop.org/software/systemd/man/systemd.directives.html | tr -d '\n' | sed 's/>/>\n/g' | sed -ne '/Unit directives/,/Options on the kernel/p' | sed -ne 's/.*
" table) (modify-syntax-entry ?\% "\\" table) table) "Syntax table used in `systemd-mode' buffers.") (defvar systemd-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "C-c C-d") 'systemd-doc-directives) (define-key map (kbd "C-c C-o") 'systemd-doc-open) map) "Keymap used in `systemd-mode' buffers.") (easy-menu-define systemd-mode-menu systemd-mode-map "Menu used in `systemd-mode' buffers." '("Systemd" ["Open Unit File help" systemd-doc-open :help "Documentation referenced in current buffer"] ["Open systemd.directives(7)" systemd-doc-directives :help "Index of configuration directives"])) ;;;###autoload (add-to-list 'auto-mode-alist `(,systemd-autoload-regexp . systemd-mode)) ;;;###autoload (add-to-list 'auto-mode-alist `(,systemd-tempfn-autoload-regexp . systemd-mode)) ;;;###autoload (add-to-list 'auto-mode-alist `(,systemd-dropin-autoload-regexp . systemd-mode)) ;;;###autoload (define-derived-mode systemd-mode conf-mode "Systemd" "Major mode for editing systemd unit files. See http://www.freedesktop.org/wiki/Software/systemd/ for more information about systemd. In addition to any hooks its parent mode might have run, this mode runs the hook `systemd-mode-hook' at mode initialization. Key bindings: \\{systemd-mode-map}" (set-keymap-parent systemd-mode-map nil) (conf-mode-initialize systemd-comment-start) (if (and systemd-use-company-p (fboundp 'company-mode)) (company-mode 1)) (add-hook 'company-backends #'systemd-company-backend) (add-hook 'completion-at-point-functions #'systemd-complete-at-point) (setq-local font-lock-defaults '(systemd-font-lock-keywords))) (provide 'systemd) ;;; systemd.el ends here