-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpoly-rst.el
More file actions
85 lines (75 loc) · 2.93 KB
/
poly-rst.el
File metadata and controls
85 lines (75 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
;;; poly-rst.el --- poly-rst-mode polymode -*- lexical-binding: t -*-
;;
;; Author: Gustaf Waldemarson, Vitalie Spinu
;; Copyright (C) 2018 Gustaf Waldemarson, Vitalie Spinu
;; Version: 0.2.2
;; Package-Requires: ((emacs "25") (polymode "0.2.2"))
;; URL: https://github.com/polymode/poly-rst
;; Keywords: languages, multi-modes
;;
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; This file is *NOT* part of GNU Emacs.
;;
;; This program 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, or
;; (at your option) any later version.
;;
;; This program 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 program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;;
;; Polymode for working with files using ReStructured Text (ReST or rst) markup
;; syntax. This allows the user to work in regions marked with code using the
;; appropriate Emacs major mode.
;;
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:
(require 'polymode)
(require 'rst)
(define-obsolete-variable-alias 'pm-host/rst 'poly-rst-hostmode "v0.2")
(define-obsolete-variable-alias 'pm-inner/rst 'poly-rst-innermode "v0.2")
(defvar poly-rst-code-tags '("code" "code-block" "sourcecode" "highlight")
"List of rst code block tags.")
(defvar poly-rst-head-start-regexp (format "\.\. +%s::[^:]" (regexp-opt poly-rst-code-tags))
"Regexp to match start of the header.")
(defun poly-rst-head-matcher (ahead)
"ReST heads end with an empty line.
Find the ReST header that are AHEAD or -AHEAD number of headers
away from the current location."
(when (re-search-forward poly-rst-head-start-regexp nil t ahead)
(cons (match-beginning 0)
(if (re-search-forward "^[ \t]*\n" nil t)
(match-end 0)
(point-max)))))
(define-hostmode poly-rst-hostmode nil
"ReSTructured text hostmode."
:mode 'rst-mode)
(define-auto-innermode poly-rst-innermode nil
"ReSTructured text innermode."
:head-matcher #'poly-rst-head-matcher
:tail-matcher #'pm-same-indent-tail-matcher
:mode 'host
:head-mode 'host
:indent-offset 4
:mode-matcher (cons "\.\. .*:: +\\(.+\\)" 1))
;;;###autoload (autoload #'poly-rst-mode "poly-rst")
(define-polymode poly-rst-mode
:hostmode 'poly-rst-hostmode
:innermodes '(poly-rst-innermode))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.re?st\\'" . poly-rst-mode))
(provide 'poly-rst)
;;; poly-rst.el ends here