2015-10-30 13:23:24 +00:00
|
|
|
;;; core-spacemacs.el --- Spacemacs Core File
|
|
|
|
;;
|
2016-01-12 02:40:54 +00:00
|
|
|
;; Copyright (c) 2012-2016 Sylvain Benner & Contributors
|
2015-10-30 13:23:24 +00:00
|
|
|
;;
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
|
|
|
(require 'org)
|
|
|
|
(require 'ox-publish)
|
|
|
|
(require 's)
|
|
|
|
(require 'dash)
|
2016-03-14 16:00:21 +00:00
|
|
|
(require 'f)
|
2016-03-14 18:44:37 +00:00
|
|
|
(require 'toc-org)
|
|
|
|
(require 'org-id)
|
2015-10-30 13:23:24 +00:00
|
|
|
|
|
|
|
(defvar spacemacs--category-names
|
|
|
|
'(("config-files" . "Configuration files")
|
|
|
|
("email" . "E-mail")
|
2016-03-24 01:39:43 +00:00
|
|
|
("intl" . "International support")
|
|
|
|
("lang" . "Programming and markup languages")
|
|
|
|
("os" . "Operating systems")
|
|
|
|
("spacemacs" . "Spacemacs distribution layers"))
|
2015-10-30 13:23:24 +00:00
|
|
|
"Special names for categories. Used to generate the layers list.")
|
|
|
|
|
|
|
|
(defun spacemacs//generate-layers-from-path (path level)
|
|
|
|
"Add all layers found in PATH to the current buffer, at org level LEVEL."
|
|
|
|
(let* ((all-subs (directory-files path t nil nil))
|
|
|
|
(layers (-filter (lambda (p)
|
|
|
|
(eq 'layer (configuration-layer//directory-type p)))
|
|
|
|
all-subs))
|
|
|
|
(categories (-filter (lambda (p)
|
|
|
|
(eq 'category (configuration-layer//directory-type p)))
|
|
|
|
all-subs)))
|
|
|
|
(message "%S" layers)
|
|
|
|
(dolist (l layers)
|
|
|
|
(let ((layer-name (file-name-nondirectory l))
|
|
|
|
(target-path (concat (file-relative-name
|
2016-06-23 04:19:12 +00:00
|
|
|
l (concat spacemacs-start-directory "layers"))
|
2015-10-30 13:23:24 +00:00
|
|
|
"/README.org")))
|
|
|
|
(insert (format "- [[file:%s][%s]]\n" target-path layer-name))))
|
|
|
|
(dolist (c categories)
|
|
|
|
(let* ((category-name (substring (file-name-nondirectory c) 1))
|
|
|
|
(pretty-name (or (cdr (assoc category-name spacemacs--category-names))
|
|
|
|
(s-capitalize (replace-regexp-in-string
|
|
|
|
"-" " " category-name)))))
|
|
|
|
(message "%S" category-name)
|
|
|
|
(unless (string= "distribution" category-name)
|
|
|
|
(insert (format "\n%s %s\n" level pretty-name))
|
2015-11-02 21:30:44 +00:00
|
|
|
(spacemacs//generate-layers-from-path c (concat level "*"))
|
2015-10-30 13:23:24 +00:00
|
|
|
)))))
|
|
|
|
|
|
|
|
(defun spacemacs//generate-layers-file ()
|
|
|
|
"Generate the layers list file."
|
|
|
|
(interactive)
|
|
|
|
(with-temp-buffer
|
|
|
|
(org-mode)
|
2015-11-08 18:04:44 +00:00
|
|
|
(insert "#+TITLE: Configuration layers\n")
|
|
|
|
(insert "#+HTML_HEAD_EXTRA: <link rel=\"stylesheet\" type=\"text/css\" href=\"../css/readtheorg.css\" />\n\n")
|
2015-10-30 13:23:24 +00:00
|
|
|
(insert "* Table of Contents\n")
|
|
|
|
(org-set-tags-to '("TOC_4_org" "noexport"))
|
2016-03-28 22:21:01 +00:00
|
|
|
;; there is no layer at the root level for now
|
|
|
|
;; uncomment this line if any new layer is added at the root level
|
|
|
|
;; (insert "* General layers\n")
|
2015-10-30 13:23:24 +00:00
|
|
|
(spacemacs//generate-layers-from-path configuration-layer-directory "*")
|
2016-06-23 04:19:12 +00:00
|
|
|
(write-file (concat spacemacs-start-directory "layers/LAYERS.org"))))
|
2015-10-30 13:23:24 +00:00
|
|
|
|
2015-11-22 19:43:18 +00:00
|
|
|
(defun spacemacs//format-toc (&rest r)
|
|
|
|
(if (not (null (car r)))
|
|
|
|
(let* ((toc (car r))
|
|
|
|
(heading-pos (s-index-of "Contents</h" toc)))
|
|
|
|
(if (not (null heading-pos))
|
|
|
|
(let* ((end-of-heading-pos (+ (length "Contents") heading-pos))
|
|
|
|
(beginning-of-heading (substring toc 0 end-of-heading-pos))
|
|
|
|
(rest-of-toc (substring toc end-of-heading-pos)))
|
|
|
|
(format "%s<a href=\"#\">Close</a>%s" beginning-of-heading rest-of-toc))
|
|
|
|
toc))
|
|
|
|
(car r)))
|
|
|
|
|
|
|
|
(defun spacemacs//format-content (&rest r)
|
|
|
|
(let* ((content (car r))
|
|
|
|
(div-string "<div id=\"content\">")
|
|
|
|
(toc-string "<div id=\"toggle-sidebar\"><a href=\"#table-of-contents\"><h2>Table of Contents</h2></a></div>")
|
|
|
|
(has-toc (s-index-of "Table of Contents" content))
|
|
|
|
(beginning-of-content-div-pos (+ (length div-string) (s-index-of div-string content)))
|
|
|
|
(beginning-of-content (substring content 0 beginning-of-content-div-pos))
|
|
|
|
(rest-of-content (substring content beginning-of-content-div-pos)))
|
|
|
|
(if (not (null has-toc))
|
|
|
|
(format "%s\n%s%s" beginning-of-content toc-string rest-of-content)
|
|
|
|
content)))
|
|
|
|
|
2016-03-14 18:44:37 +00:00
|
|
|
(defun spacemacs//toc-org-unhrefify-toc ()
|
|
|
|
"Make TOC classical org-mode TOC."
|
|
|
|
(let ((toc-org-hrefify-default "org"))
|
|
|
|
(toc-org-insert-toc)))
|
|
|
|
|
|
|
|
(defun spacemacs//org-heading-annotate-custom-id ()
|
|
|
|
"Annotate headings with the indexes that GitHub uses for linking.
|
|
|
|
`org-html-publish-to-html' will use them instead of the default #orgheadline{N}.
|
|
|
|
This way the GitHub links and the http://spacemacs.org/ links will be compatible."
|
|
|
|
(progn (goto-char (point-min))
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (re-search-forward "^[\\*]+\s\\(.*\\).*$" nil t)
|
|
|
|
(let ((heading (match-string 1)))
|
|
|
|
(progn (move-end-of-line nil)
|
|
|
|
(open-line 1)
|
|
|
|
(next-line 1)
|
|
|
|
(insert (format (concat " :PROPERTIES:\n"
|
|
|
|
" :CUSTOM_ID: %s\n"
|
|
|
|
" :END:\n")
|
|
|
|
(substring (toc-org-hrefify-gh
|
|
|
|
(replace-regexp-in-string
|
|
|
|
toc-org-tags-regexp
|
|
|
|
""
|
|
|
|
heading))
|
|
|
|
;; Remove # prefix added by `toc-org-hrefify-gh'.
|
|
|
|
1))))))))
|
|
|
|
|
|
|
|
(defun spacemacs//reroot-links ()
|
|
|
|
"Find the links that start with https://github.com/syl20bnr/spacemacs/blob/
|
|
|
|
and end with .org{#an-optional-heading-link} (i.e the links between the local org files).
|
|
|
|
Change their root to http://spacemacs.org/ so the links will point at files located on the site.
|
|
|
|
For the file to file links to work properly the exported org files should be processed with
|
|
|
|
the `spacemacs//org-heading-annotate-custom-id' function."
|
|
|
|
(let ((git-url-root-regexp
|
|
|
|
(concat "\\[\\[[\\s]*\\(https\\:\\/\\/github\\.com\\/syl20bnr"
|
|
|
|
"\\/spacemacs\\/blob\\/[^/]+\\/\\)[^]]+\\(\\.org\\).*$"))
|
|
|
|
(site-url "http://spacemacs.org/")
|
|
|
|
(site-doc-postf ".html"))
|
|
|
|
(progn (goto-char (point-min))
|
|
|
|
(while (re-search-forward git-url-root-regexp nil t)
|
|
|
|
(progn (replace-match site-url nil t nil 1)
|
|
|
|
(replace-match site-doc-postf nil t nil 2))))))
|
|
|
|
|
2016-03-14 16:00:21 +00:00
|
|
|
(defun spacemacs//add-org-meta-readtheorg-css (filename)
|
|
|
|
(let* ((head-css-extra-readtheorg-head (concat
|
|
|
|
"#+HTML_HEAD_EXTRA:"
|
|
|
|
"<link rel=\"stylesheet\" "
|
|
|
|
"type=\"text/css\" "
|
|
|
|
"href=\""))
|
|
|
|
(head-css-extra-readtheorg-tail "css/readtheorg.css\" />\n"))
|
|
|
|
(progn (goto-char (point-min))
|
|
|
|
(delete-matching-lines "\\+HTML_HEAD_EXTRA\\:.*\\/css\\/readtheorg\\.css")
|
|
|
|
(goto-char (point-min))
|
|
|
|
(if (search-forward "#+TITLE:" nil t nil)
|
|
|
|
(beginning-of-line 2)
|
2016-03-14 18:44:37 +00:00
|
|
|
(error (format "Can't find #+TITLE: in %s"
|
|
|
|
(buffer-file-name))))
|
2016-03-14 16:00:21 +00:00
|
|
|
(insert (concat head-css-extra-readtheorg-head
|
2016-06-23 04:25:04 +00:00
|
|
|
(f-relative spacemacs-start-directory
|
2016-03-14 16:00:21 +00:00
|
|
|
(file-name-directory filename))
|
|
|
|
head-css-extra-readtheorg-tail)))))
|
|
|
|
|
|
|
|
(defun spacemacs//pub-doc-html-advice (origfunc &rest args)
|
2016-03-14 18:44:37 +00:00
|
|
|
"Wrapper for `org-html-publish-to-html' use it to insert
|
|
|
|
preprocessors for the exported .org files."
|
2016-03-14 16:00:21 +00:00
|
|
|
(save-current-buffer
|
|
|
|
(save-excursion
|
|
|
|
(let* ((filename (car (nthcdr 1 args)))
|
|
|
|
(visitingp (find-buffer-visiting filename)))
|
|
|
|
;; Temporary "unvisit" the visited org files.
|
|
|
|
(when visitingp (with-current-buffer visitingp (setq buffer-file-name nil)))
|
|
|
|
(with-temp-buffer
|
|
|
|
(save-match-data
|
|
|
|
(insert-file-contents filename t)
|
2016-03-14 18:44:37 +00:00
|
|
|
;; ===========Add preprocessors here===============
|
2016-03-14 16:00:21 +00:00
|
|
|
(spacemacs//add-org-meta-readtheorg-css filename)
|
2016-03-14 18:44:37 +00:00
|
|
|
(spacemacs//toc-org-unhrefify-toc)
|
|
|
|
(spacemacs//reroot-links)
|
|
|
|
(spacemacs//org-heading-annotate-custom-id)
|
2016-03-14 16:00:21 +00:00
|
|
|
(apply origfunc args)
|
|
|
|
(not-modified)))
|
|
|
|
;; Restore `buffer-file-name' for the buffers that previously visited the org files.
|
|
|
|
(when visitingp (with-current-buffer visitingp (setq buffer-file-name filename)))))))
|
|
|
|
|
2015-10-30 13:23:24 +00:00
|
|
|
(defun spacemacs/publish-doc ()
|
2016-03-14 14:34:27 +00:00
|
|
|
"Publish the documentation to doc/export/."
|
2015-10-30 13:23:24 +00:00
|
|
|
(interactive)
|
2015-11-22 19:43:18 +00:00
|
|
|
(advice-add 'org-html-toc :filter-return #'spacemacs//format-toc)
|
|
|
|
(advice-add 'org-html-template :filter-return #'spacemacs//format-content)
|
2016-03-14 16:00:21 +00:00
|
|
|
(advice-add 'org-html-publish-to-html :around #'spacemacs//pub-doc-html-advice)
|
2015-10-30 13:23:24 +00:00
|
|
|
(let* ((header
|
|
|
|
"<link rel=\"stylesheet\" type=\"text/css\"
|
2015-11-08 18:04:44 +00:00
|
|
|
href=\"http://www.pirilampo.org/styles/readtheorg/css/htmlize.css\"/>
|
2015-10-30 13:23:24 +00:00
|
|
|
<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js\"></script>
|
|
|
|
<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js\"></script>
|
|
|
|
<script type=\"text/javascript\"
|
2016-03-12 18:42:08 +00:00
|
|
|
src=\"http://www.pirilampo.org/styles/readtheorg/js/readtheorg.js\"></script>
|
|
|
|
<script>
|
|
|
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
|
|
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new
|
|
|
|
Date();a=s.createElement(o),
|
|
|
|
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
|
|
|
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
|
|
|
|
|
|
|
ga('create', 'UA-28326243-2', 'auto'); ga('send', 'pageview');
|
|
|
|
</script>")
|
2016-06-23 04:19:12 +00:00
|
|
|
(publish-target (concat spacemacs-start-directory "export/"))
|
2015-11-08 18:04:44 +00:00
|
|
|
(org-html-htmlize-output-type 'css)
|
2015-10-30 13:23:24 +00:00
|
|
|
(org-publish-project-alist
|
|
|
|
`(("spacemacs"
|
|
|
|
:components ("spacemacs-doc"
|
|
|
|
"spacemacs-doc-static"
|
|
|
|
"layers-doc"
|
|
|
|
"layers-doc-static"))
|
|
|
|
("spacemacs-doc"
|
|
|
|
:base-directory ,spacemacs-docs-directory
|
|
|
|
:base-extension "org"
|
|
|
|
:publishing-directory ,(concat publish-target "doc/")
|
|
|
|
:publishing-function org-html-publish-to-html
|
|
|
|
:headline-levels 4
|
|
|
|
:html-head ,header)
|
|
|
|
("layers-doc"
|
2016-06-23 04:19:12 +00:00
|
|
|
:base-directory ,(concat spacemacs-start-directory "layers/")
|
2015-10-30 13:23:24 +00:00
|
|
|
:base-extension "org"
|
|
|
|
:recursive t
|
|
|
|
:publishing-directory ,(concat publish-target "layers/")
|
|
|
|
:publishing-function org-html-publish-to-html
|
2015-11-02 21:30:44 +00:00
|
|
|
:preparation-function spacemacs//generate-layers-file
|
2016-01-18 03:06:04 +00:00
|
|
|
:exclude "local"
|
2015-10-30 13:23:24 +00:00
|
|
|
:html-head ,header)
|
|
|
|
("spacemacs-doc-static"
|
|
|
|
:base-directory ,spacemacs-docs-directory
|
|
|
|
:base-extension "png"
|
|
|
|
:recursive t
|
|
|
|
:publishing-directory ,(concat publish-target "doc/")
|
|
|
|
:publishing-function org-publish-attachment)
|
|
|
|
("layers-doc-static"
|
2016-06-23 04:19:12 +00:00
|
|
|
:base-directory ,(concat spacemacs-start-directory "layers/")
|
2015-12-02 14:23:39 +00:00
|
|
|
:base-extension "jpg\\|png\\|gif"
|
2015-10-30 13:23:24 +00:00
|
|
|
:recursive t
|
|
|
|
:publishing-directory ,(concat publish-target "layers/")
|
|
|
|
:publishing-function org-publish-attachment))))
|
2015-11-22 19:43:18 +00:00
|
|
|
(org-publish-project "spacemacs"))
|
|
|
|
(advice-remove 'org-html-toc #'spacemacs//format-toc)
|
2016-03-14 16:00:21 +00:00
|
|
|
(advice-remove 'org-html-template #'spacemacs//format-content)
|
|
|
|
(advice-remove 'org-html-publish-to-html #'spacemacs//pub-doc-html-advice))
|
2015-10-30 13:23:24 +00:00
|
|
|
|
|
|
|
(provide 'core-documentation)
|