diff --git a/layers/+lang/restructuredtext/README.org b/layers/+lang/restructuredtext/README.org index 43fb70b94..57ee51e9f 100644 --- a/layers/+lang/restructuredtext/README.org +++ b/layers/+lang/restructuredtext/README.org @@ -6,56 +6,20 @@ - [[#description][Description]] - [[#features][Features]] - [[#install][Install]] - - [[#configuration][Configuration]] - - [[#sphinx-target][Sphinx target]] - - [[#web-browser][Web browser]] - - [[#key-bindings][Key bindings]] * Description The layer adds ReStructuredText (ReST) support to Spacemacs and adds some functions to =rst-mode=. +Note: to add =Sphinx= specific support use the layer =sphinx=. + ** Features - =rst= files are supported via Emacs built-in =rst.el=. - Lists are inserted by new functions. - Directives can be inserted easily. -- Sphinx support. * Install To use this configuration layer, add it to your =~/.spacemacs=. You will need to add =restructuredtext= to the existing =dotspacemacs-configuration-layers= list in this file. -* Configuration -** Sphinx target -To use the layer's Sphinx feature, the following variables should be set. - -A parent directory is needed for all Sphinx projects' builds. - -#+begin_src emacs-lisp - (setq rst-sphinx-target-parent "/your/path/of/build/") -#+end_src - -Set a directory in the parent directory for each Sphinx project. - -#+begin_src emacs-lisp - (setq rst-sphinx-target-projects - '(("project1" . (latex "folder/in/target/parent" t)) - ("project2" . (html "folder/in/target/parent" nil)) - )) -#+end_src - -** Web browser -Set the browser for viewing the HTML page of current rst file. This one -is optional. If not set, the default browser will be used. - -#+begin_src emacs-lisp - (setq rst-slides-program "chromium") -#+end_src - -* Key bindings - -| Key Binding | Description | -|-------------+-----------------------------------------| -| ~ m c~ | compile projects | -| ~ m f~ | open compiled HTML page of current page | diff --git a/layers/+lang/restructuredtext/packages.el b/layers/+lang/restructuredtext/packages.el index e0b80d698..49754d2ad 100644 --- a/layers/+lang/restructuredtext/packages.el +++ b/layers/+lang/restructuredtext/packages.el @@ -1,6 +1,6 @@ ;;; packages.el --- rest layer packages file for Spacemacs. ;; -;; Copyright (c) 2012-2016 Sylvain Benner & Contributors +;; Copyright (c) 2012-2017 Sylvain Benner & Contributors ;; ;; Author: ;; URL: https://github.com/syl20bnr/spacemacs @@ -9,15 +9,28 @@ ;; ;;; License: GPLv3 -(setq restructuredtext-packages - '((rst :location built-in) - (rst-directives :location local) - (rst-lists :location local) - (rst-sphinx :location local) - flyspell - smartparens - yasnippet - )) +(defconst restructuredtext-packages + '( + auto-complete + (auto-complete-rst :toggle (configuration-layer/package-usedp 'auto-complete)) + (rst :location built-in) + (rst-directives :location local) + (rst-lists :location local) + flyspell + smartparens + yasnippet + )) + +(defun restructuredtext/post-init-auto-complete () + (add-hook 'rst-mode-hook 'auto-complete-mode)) + +(defun restructuredtext/init-auto-complete-rst () + (use-package auto-complete-rst + :commands (auto-complete-rst-add-sources + auto-complete-rst-init) + :init (spacemacs/add-to-hook 'rst-mode-hook '(auto-complete-rst-init + auto-complete-rst-add-sources)))) + (defun restructuredtext/init-rst-directives () (use-package rst-directives)) @@ -31,12 +44,7 @@ (defun restructuredtext/init-rst () (use-package rst :defer t - :config - (progn - (add-hook 'rst-adjust-hook 'rst-toc-update) - (spacemacs/set-leader-keys-for-major-mode 'rst-mode - "c" 'rst-sphinx-compile - "f" 'rst-sphinx-target-open)))) + :config (add-hook 'rst-adjust-hook 'rst-toc-update))) (defun restructuredtext/post-init-flyspell () (spell-checking/add-flyspell-hook 'rst-mode-hook)) @@ -45,6 +53,9 @@ (defun restructuredtext/post-init-yasnippet () (add-hook 'rst-mode-hook 'spacemacs/load-yasnippet))) +(defun restructuredtext/post-init-yasnippet () + (add-hook 'rst-mode-hook 'spacemacs/load-yasnippet)) + (defun restructuredtext/post-init-smartparens () (add-hook 'rst-mode-hook 'smartparens-mode)) diff --git a/layers/+tools/sphinx/README.org b/layers/+tools/sphinx/README.org new file mode 100644 index 000000000..90d8e7962 --- /dev/null +++ b/layers/+tools/sphinx/README.org @@ -0,0 +1,54 @@ +#+TITLE: Sphinx layer + +[[file:img/sphinx.png]] + +* Table of Contents :TOC_4_gh:noexport: + - [[#description][Description]] + - [[#install][Install]] + - [[#configuration][Configuration]] + - [[#sphinx-target][Sphinx target]] + - [[#web-browser][Web browser]] + - [[#key-bindings][Key bindings]] + +* Description +The layer adds =Sphinx= support to Spacemacs. It will automatically also install +the =restructuredtext= layer. + +* Install +To use this configuration layer, add it to your =~/.spacemacs=. You will need to +add =sphinx= to the existing =dotspacemacs-configuration-layers= list +in this file. + +* Configuration +** Sphinx target +To use the layer's Sphinx feature, the following variables should be set. + +A parent directory is needed for all Sphinx projects' builds. + +#+begin_src emacs-lisp + (setq rst-sphinx-target-parent "/your/path/of/build/") +#+end_src + +Set a directory in the parent directory for each Sphinx project. + +#+begin_src emacs-lisp + (setq rst-sphinx-target-projects + '(("project1" . (latex "folder/in/target/parent" t)) + ("project2" . (html "folder/in/target/parent" nil)) + )) +#+end_src + +** Web browser +Set the browser for viewing the HTML page of current rst file. This one +is optional. If not set, the default browser will be used. + +#+begin_src emacs-lisp + (setq rst-slides-program "chromium") +#+end_src + +* Key bindings + +| Key Binding | Description | +|-------------+-----------------------------------------| +| ~ m c~ | compile projects | +| ~ m f~ | open compiled HTML page of current page | diff --git a/layers/+tools/sphinx/img/restructuredtext.png b/layers/+tools/sphinx/img/restructuredtext.png new file mode 100644 index 000000000..b95c77d3c Binary files /dev/null and b/layers/+tools/sphinx/img/restructuredtext.png differ diff --git a/layers/+tools/sphinx/layers.el b/layers/+tools/sphinx/layers.el new file mode 100644 index 000000000..880af1af7 --- /dev/null +++ b/layers/+tools/sphinx/layers.el @@ -0,0 +1,12 @@ +;;; layers.el --- Sphinx layer layers File for Spacemacs +;; +;; Copyright (c) 2012-2017 Sylvain Benner & Contributors +;; +;; Author: Sylvain Benner +;; URL: https://github.com/syl20bnr/spacemacs +;; +;; This file is not part of GNU Emacs. +;; +;;; License: GPLv3 + +(configuration-layer/declare-layer 'restructuredtext) diff --git a/layers/+tools/sphinx/local/rst-sphinx/rst-sphinx.el b/layers/+tools/sphinx/local/rst-sphinx/rst-sphinx.el new file mode 100644 index 000000000..df4facb3f --- /dev/null +++ b/layers/+tools/sphinx/local/rst-sphinx/rst-sphinx.el @@ -0,0 +1,148 @@ +;;; rst-sphinx.el --- Build Sphinx projects. + +;; Copyright (C) 2012 Wei-Wei Guo. + +;; Author: Wei-Wei Guo +;; Version: 0.1 +;; +;; This file is published under the GNU Gerneral Public License, +;; see . +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;;; Commentary: + +;; This file enable building Sphinx project in Emacs. + +;;; Code: + +(defgroup rst-sphinx nil + "Settings for support of conversion of reStructuredText +document with \\[rst-sphinx]." + :group 'rst + :version "24.5") + +(defvar rst-sphinx-command "sphinx-build -b" + "Sphinx compile command.") + +(defvar rst-sphinx-builder + '((html . "html") + (latex . "xelatex")) + "Table describing the builder used to compile.") + +(defvar rst-sphinx-source nil + "The Sphinx project source directory.") + +(defvar rst-sphinx-target nil + "The Sphinx project target directory.") + +(defvar rst-sphinx-project nil + "The Sphinx project name.") + +(defvar rst-sphinx-source-file nil + "Current Sphinx project source file.") + +(defvar rst-sphinx-source-buffer nil + "Current Sphinx project source file buffer.") + +(defcustom rst-sphinx-target-parent nil + "The Sphinx project target parent directory." + :group 'rst-builders + :type 'directory) + +(defcustom rst-sphinx-target-projects nil + "The Sphinx project target project directories." + :group 'rst-builders) + +(defun rst-sphinx-find-conf () + "Look for the configuration file in the parents of the current path." + ;; (interactive) + (let* ((file-name "conf.py") + (buffer-file (buffer-file-name)) + (dir (file-name-directory buffer-file))) + ;; Move up in the dir hierarchy till we find a change log file. + (while (or (not (file-exists-p (concat dir file-name)))) + ;; Move up to the parent dir and try again. + (setq buffer-file (directory-file-name + (file-name-directory buffer-file))) + (setq dir (file-name-directory buffer-file))) + (setq dir (directory-file-name + (file-name-directory buffer-file))) + (setq rst-sphinx-source dir) + (setq rst-sphinx-project (file-name-nondirectory dir)) + ;; not depend on local variables, put here just for convience. + (setq rst-sphinx-target + (expand-file-name + (nth 2 (assoc rst-sphinx-project + rst-sphinx-target-projects)) + rst-sphinx-target-parent)) + (setq rst-sphinx-source-buffer (current-buffer) + rst-sphinx-source-file (buffer-file-name)) + )) + + +(require 'compile) + +(defun rst-sphinx-compile () + "Compile Sphinx project." + (interactive) + (if (not (string= (file-name-extension (buffer-file-name)) "rst")) + (print "Not a ReStructerdText file.") + (progn + (rst-sphinx-find-conf) + (let ((builder (nth 1 (assoc rst-sphinx-project + rst-sphinx-target-projects)))) + (compile (mapconcat 'identity + (list rst-sphinx-command + (cdr (assoc builder rst-sphinx-builder)) + rst-sphinx-source + rst-sphinx-target) + " ")) + )))) + +(defun rst-sphinx-target-open () + "Open builded Sphinx project file." + (interactive) + (if (not (string= (file-name-extension (buffer-file-name)) "rst")) + (print "Not a ReStructerdText file.") + (progn + (rst-sphinx-find-conf) + (let ((builder (nth 1 (assoc rst-sphinx-project + rst-sphinx-target-projects))) + (buffer-file (nth 1 (split-string + (file-name-sans-extension rst-sphinx-source-file) + rst-sphinx-source)))) + (if (eq builder 'html) + (start-process-shell-command + "Sphinx HTML project viewing" nil + (mapconcat 'identity + (list rst-slides-program + (concat rst-sphinx-target buffer-file ".html")) + " "))) + (if (eq builder 'latex) + (let (type) + (setq type (completing-read "Which file? (TeX, PDF): " '("tex" "pdf"))) + (if (string= "tex" type) + (progn + (setq rst-sphinx-tex-file + (car (directory-files rst-sphinx-target nil ".tex"))) + (find-file (expand-file-name rst-sphinx-tex-file rst-sphinx-target)))) + (if (string= "pdf" type) + (if (directory-files rst-sphinx-target nil ".pdf") + (start-process-shell-command + "Sphinx PDF project viewing" nil + (mapconcat 'identity + (list rst-pdf-program + (expand-file-name + (car (directory-files + rst-sphinx-target nil ".pdf")) + rst-sphinx-target)) + " ")) + (print "Cannot find PDF file."))))))))) + +(defun rst-sphinx-switch-buffer () + "Switch to Sphinx project file buffer." + (interactive) + (switch-to-buffer rst-sphinx-source-buffer)) + + +(provide 'rst-sphinx) diff --git a/layers/+tools/sphinx/packages.el b/layers/+tools/sphinx/packages.el new file mode 100644 index 000000000..d72229fd8 --- /dev/null +++ b/layers/+tools/sphinx/packages.el @@ -0,0 +1,26 @@ +;;; packages.el --- Sphinx layer packages file for Spacemacs. +;; +;; Copyright (c) 2012-2017 Sylvain Benner & Contributors +;; +;; Author: +;; URL: https://github.com/syl20bnr/spacemacs +;; +;; This file is not part of GNU Emacs. +;; +;;; License: GPLv3 + +(defconst sphinx-packages + '( + rst + (rst-sphinx :location local) + )) + +(defun sphinx/init-rst-sphinx () + (use-package rst-sphinx)) + +(defun sphinx/post-init-rst () + (spacemacs|use-package-add-hook rst + :post-config (spacemacs/set-leader-keys-for-major-mode 'rst-mode + "c" 'rst-sphinx-compile + "f" 'rst-sphinx-target-open))) +