forked from polymode/poly-org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoly-org.el
96 lines (87 loc) · 3.52 KB
/
poly-org.el
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
86
87
88
89
90
91
92
93
94
95
96
;;; poly-org.el --- Polymode for org-mode -*- lexical-binding: t -*-
;;
;; Author: Vitalie Spinu
;; Maintainer: Vitalie Spinu
;; Copyright (C) 2013-2020 Vitalie Spinu
;; Version: 0.2.2
;; Package-Requires: ((emacs "25") (polymode "0.2.2"))
;; URL: https://github.com/polymode/poly-org
;; 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:
;;
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:
(require 'polymode)
(require 'org)
(require 'org-src)
(define-obsolete-variable-alias 'pm-host/org 'poly-org-hostmode "v0.2")
(define-obsolete-variable-alias 'pm-inner/org 'poly-org-innermode "v0.2")
(defun poly-org-mode-matcher ()
(let ((case-fold-search t))
(when (re-search-forward "#\\+begin_\\(src\\|example\\|export\\) +\\([^ \t\n]+\\)" (point-at-eol) t)
(let ((lang (match-string-no-properties 2)))
(or (cdr (assoc lang org-src-lang-modes))
lang)))))
(defvar ess-local-process-name)
(defun poly-org-convey-src-block-params-to-inner-modes (_ this-buf)
"Move src block parameters to innermode specific locals.
Used in :switch-buffer-functions slot."
(cond
((derived-mode-p 'ess-mode)
(with-current-buffer (pm-base-buffer)
(let* ((params (nth 2 (org-babel-get-src-block-info t)))
(session (cdr (assq :session params))))
(when (and session (org-babel-comint-buffer-livep session))
(let ((proc (buffer-local-value 'ess-local-process-name
(get-buffer session))))
(with-current-buffer this-buf
(setq-local ess-local-process-name proc)))))))))
(define-hostmode poly-org-hostmode
:mode 'org-mode
:protect-syntax nil
:protect-font-lock nil)
(define-auto-innermode poly-org-innermode
:fallback-mode 'host
:head-mode 'host
:tail-mode 'host
:head-matcher "^[ \t]*#\\+begin_\\(src\\|example\\|export\\) .*\n"
:tail-matcher "^[ \t]*#\\+end_\\(src\\|example\\|export\\)"
:mode-matcher #'poly-org-mode-matcher
:head-adjust-face nil
:switch-buffer-functions '(poly-org-convey-src-block-params-to-inner-modes)
:body-indent-offset 'org-edit-src-content-indentation
:indent-offset 'org-edit-src-content-indentation)
;;;###autoload (autoload 'poly-org-mode "poly-org")
(define-polymode poly-org-mode
:hostmode 'poly-org-hostmode
:innermodes '(poly-org-innermode)
(setq-local org-src-fontify-natively nil)
(make-local-variable 'polymode-move-these-minor-modes-from-old-buffer)
(push 'org-indent-mode polymode-move-these-minor-modes-from-old-buffer))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.org\\'" . poly-org-mode))
(provide 'poly-org)
;;; poly-org.el ends here