branch: externals/polymode
commit 79af5f3c0f58e8b37bdd5ef1ba40cfa5d68d1f14
Author: Vitalie Spinu <[email protected]>
Commit: Vitalie Spinu <[email protected]>
Aesthetic
---
polymode-compat.el | 13 ----
polymode-core.el | 21 +++++
tests/compat-tests.el | 210 +++++++++++++++++++++++++-------------------------
3 files changed, 126 insertions(+), 118 deletions(-)
diff --git a/polymode-compat.el b/polymode-compat.el
index aa919b71c0..bd4fd74946 100644
--- a/polymode-compat.el
+++ b/polymode-compat.el
@@ -69,22 +69,9 @@ Elements of ALIST that are not conses are ignored."
(assoc-delete-all key alist #'eq)))
-;;; emacs 30
-(unless (fboundp 'major-mode-remap)
- (defvar major-mode-remap-alist nil)
- (defvar major-mode-remap-defaults nil)
- (defalias 'major-mode-remap
- (lambda (mode)
- "Return the function to use to enable MODE."
- (or (cdr (or (assq mode major-mode-remap-alist)
- (assq mode major-mode-remap-defaults)))
- mode))))
-
;;; Various Wrappers for Around Advice
-(defvar *span* nil)
-
;; advice doesn't provide named symbols. So we need to define specialized
;; wrappers for some key functions (unfinished)
(defmacro pm-define-wrapp-protected (fun)
diff --git a/polymode-core.el b/polymode-core.el
index 17a7848075..e48267f612 100644
--- a/polymode-core.el
+++ b/polymode-core.el
@@ -37,8 +37,11 @@
(require 'cl-lib)
(require 'derived))
+
;;; ESSENTIAL DECLARATIONS
+
+;; fixme: rename into pm-active-span or something similar
(defvar *span* nil)
(defvar-local pm/polymode nil)
(put 'pm/polymode 'permanent-local t)
@@ -82,6 +85,23 @@
(with-no-warnings
(eieio-object-name-string obj)))
+
+
+;; CORE EMACS COMPATS
+
+;;; emacs 30
+(unless (fboundp 'major-mode-remap)
+ (defvar major-mode-remap-alist nil)
+ (defvar major-mode-remap-defaults nil)
+ (defalias 'major-mode-remap
+ (lambda (mode)
+ "Return the function to use to enable MODE."
+ (or (cdr (or (assq mode major-mode-remap-alist)
+ (assq mode major-mode-remap-defaults)))
+ mode))))
+
+
+
;; SHIELDS
(defvar pm-allow-after-change-hook t)
@@ -237,6 +257,7 @@ The hook is run in chunkmode's body buffer from
`pm-initialze'
objects provides same functionality for narrower scope. See also
`polymode-init-host-hook'.")
+
;;; Mode Macros
diff --git a/tests/compat-tests.el b/tests/compat-tests.el
index 398642f226..9b80f34d16 100644
--- a/tests/compat-tests.el
+++ b/tests/compat-tests.el
@@ -22,114 +22,114 @@
(skip-unless (fboundp 'poly-markdown-mode))
(let ((markdown-enable-math t))
(pm-test-run-on-file poly-test-markdown-mode "test.md"
- ;; python
- (goto-char 44)
- (pm-switch-to-buffer)
- (should (equal (pm--lsp-buffer-content 108 108) ""))
- (should (equal (pm--lsp-buffer-content 29 29) ""))
- (should (equal (pm--lsp-buffer-content 128 128) ""))
- (should (equal (pm--lsp-buffer-content 150 150) ""))
- (should (equal (pm--lsp-buffer-content 151 151) ""))
- (should (equal (pm--lsp-buffer-content 152 152) ""))
-
- (should (equal (pm--lsp-buffer-content 142 143) " "))
- (should (equal (pm--lsp-buffer-content 142 145) "
"))
-
- (should (equal (pm--lsp-buffer-content 44 50)
"fruits"))
- (should (equal (pm--lsp-buffer-content 21 50)
- (concat (make-string 3 ?\n) "#
foo\nfruits")))
-
- (should (equal (pm--lsp-buffer-content 148 155)
- "+ x"))
- (should (equal (pm--lsp-buffer-content 131 155)
- (concat (make-string 12 ? ) " 3 +
x")))
- (should (equal (pm--lsp-buffer-content 103 155)
- (concat "print(x)\n\n\n\n"
- (make-string 28 ? )
- "3 + x")))
- (should (equal (pm--lsp-buffer-content 121 141)
- (make-string 20 ? )))
- (should (equal (pm--lsp-buffer-content 121 131)
- (make-string 10 ? )))
-
- ;; latex
- (goto-char 130)
- (pm-switch-to-buffer)
- (should (equal (pm--lsp-buffer-content 108 108) ""))
- (should (equal (pm--lsp-buffer-content 29 29) ""))
- (should (equal (pm--lsp-buffer-content 128 128) ""))
- (should (equal (pm--lsp-buffer-content 150 150) ""))
- (should (equal (pm--lsp-buffer-content 151 151) ""))
- (should (equal (pm--lsp-buffer-content 152 152) ""))
-
-
- ;; markdown
- (goto-char 21)
- (pm-switch-to-buffer)
- (should (equal (pm--lsp-buffer-content 108 108) ""))
- (should (equal (pm--lsp-buffer-content 29 29) ""))
- (should (equal (pm--lsp-buffer-content 128 128) ""))
- (should (equal (pm--lsp-buffer-content 150 150) ""))
- (should (equal (pm--lsp-buffer-content 151 151) ""))
- (should (equal (pm--lsp-buffer-content 152 152) ""))
-
- (should (equal (pm--lsp-buffer-content 142 143) " "))
- (should (equal (pm--lsp-buffer-content 142 145) "
"))
- (should (equal (pm--lsp-buffer-content 151 152) " "))
-
- (should (equal (pm--lsp-buffer-content 117 121)
"\nfoo"))
- (should (equal (pm--lsp-buffer-content 118 121)
"foo"))
- (should (equal (pm--lsp-buffer-content 122 123) "$"))
- (should (equal (pm--lsp-buffer-content 135 145) " $
bar "))
-
- (should (equal (pm--lsp-buffer-content 21 50)
- "some text\n\n```py\n\n"))
- (should (equal (point) 21))
-
- (let ((base (concat "\n\n```\n\nfoo $"
- (make-string 13 ? )
- "$ bar "
- (make-string 8 ? )
- " baz")))
- (should (equal (pm--lsp-buffer-content 100 156)
- base))
- (should (equal (pm--lsp-buffer-content 100 160)
- (concat base "\n```")))
- (should (equal (pm--lsp-buffer-content 100 163)
- (concat base "\n```js\n")))
- (should (equal (pm--lsp-buffer-content 100 200)
- (concat base "\n```js\n\n\n"))))
-
- (let ((base " baz\n```js\n\n\n"))
- (should (equal (pm--lsp-buffer-content 145 203)
- base))
- (should (equal (pm--lsp-buffer-content 136 203)
- (concat "$ bar " base)))
- (should (equal (pm--lsp-buffer-content 128 203)
- (concat " $ bar " base))))
- (should (equal (point) 21))
-
- )))
+ ;; python
+ (goto-char 44)
+ (pm-switch-to-buffer)
+ (should (equal (pm--lsp-buffer-content 108 108) ""))
+ (should (equal (pm--lsp-buffer-content 29 29) ""))
+ (should (equal (pm--lsp-buffer-content 128 128) ""))
+ (should (equal (pm--lsp-buffer-content 150 150) ""))
+ (should (equal (pm--lsp-buffer-content 151 151) ""))
+ (should (equal (pm--lsp-buffer-content 152 152) ""))
+
+ (should (equal (pm--lsp-buffer-content 142 143) " "))
+ (should (equal (pm--lsp-buffer-content 142 145) " "))
+
+ (should (equal (pm--lsp-buffer-content 44 50) "fruits"))
+ (should (equal (pm--lsp-buffer-content 21 50)
+ (concat (make-string 3 ?\n) "# foo\nfruits")))
+
+ (should (equal (pm--lsp-buffer-content 148 155)
+ "+ x"))
+ (should (equal (pm--lsp-buffer-content 131 155)
+ (concat (make-string 12 ? ) " 3 + x")))
+ (should (equal (pm--lsp-buffer-content 103 155)
+ (concat "print(x)\n\n\n\n"
+ (make-string 28 ? )
+ "3 + x")))
+ (should (equal (pm--lsp-buffer-content 121 141)
+ (make-string 20 ? )))
+ (should (equal (pm--lsp-buffer-content 121 131)
+ (make-string 10 ? )))
+
+ ;; latex
+ (goto-char 130)
+ (pm-switch-to-buffer)
+ (should (equal (pm--lsp-buffer-content 108 108) ""))
+ (should (equal (pm--lsp-buffer-content 29 29) ""))
+ (should (equal (pm--lsp-buffer-content 128 128) ""))
+ (should (equal (pm--lsp-buffer-content 150 150) ""))
+ (should (equal (pm--lsp-buffer-content 151 151) ""))
+ (should (equal (pm--lsp-buffer-content 152 152) ""))
+
+
+ ;; markdown
+ (goto-char 21)
+ (pm-switch-to-buffer)
+ (should (equal (pm--lsp-buffer-content 108 108) ""))
+ (should (equal (pm--lsp-buffer-content 29 29) ""))
+ (should (equal (pm--lsp-buffer-content 128 128) ""))
+ (should (equal (pm--lsp-buffer-content 150 150) ""))
+ (should (equal (pm--lsp-buffer-content 151 151) ""))
+ (should (equal (pm--lsp-buffer-content 152 152) ""))
+
+ (should (equal (pm--lsp-buffer-content 142 143) " "))
+ (should (equal (pm--lsp-buffer-content 142 145) " "))
+ (should (equal (pm--lsp-buffer-content 151 152) " "))
+
+ (should (equal (pm--lsp-buffer-content 117 121) "\nfoo"))
+ (should (equal (pm--lsp-buffer-content 118 121) "foo"))
+ (should (equal (pm--lsp-buffer-content 122 123) "$"))
+ (should (equal (pm--lsp-buffer-content 135 145) " $ bar "))
+
+ (should (equal (pm--lsp-buffer-content 21 50)
+ "some text\n\n```py\n\n"))
+ (should (equal (point) 21))
+
+ (let ((base (concat "\n\n```\n\nfoo $"
+ (make-string 13 ? )
+ "$ bar "
+ (make-string 8 ? )
+ " baz")))
+ (should (equal (pm--lsp-buffer-content 100 156)
+ base))
+ (should (equal (pm--lsp-buffer-content 100 160)
+ (concat base "\n```")))
+ (should (equal (pm--lsp-buffer-content 100 163)
+ (concat base "\n```js\n")))
+ (should (equal (pm--lsp-buffer-content 100 200)
+ (concat base "\n```js\n\n\n"))))
+
+ (let ((base " baz\n```js\n\n\n"))
+ (should (equal (pm--lsp-buffer-content 145 203)
+ base))
+ (should (equal (pm--lsp-buffer-content 136 203)
+ (concat "$ bar " base)))
+ (should (equal (pm--lsp-buffer-content 128 203)
+ (concat " $ bar " base))))
+ (should (equal (point) 21))
+
+ )))
(ert-deftest compat/indent/double-poly-mode-init-preserves-original-functions
()
(skip-unless (fboundp 'poly-markdown-mode))
(pm-test-run-on-file poly-test-markdown-mode "test.md"
- (goto-char (point-min))
- (pm-switch-to-buffer)
- (should (eq major-mode 'markdown-mode))
- (poly-test-markdown-mode t)
- (should (equal pm--indent-line-function-original
'markdown-indent-line))
- (should (equal pm--indent-region-function-original
'markdown--indent-region))
- (should (equal pm--fill-forward-paragraph-original
'markdown-fill-forward-paragraph))
- (should (equal pm--syntax-propertize-function-original
'markdown-syntax-propertize))
-
- (re-search-forward "http.createServer")
- (forward-line 1)
- (pm-switch-to-buffer)
- (poly-test-markdown-mode t)
- (should (eq major-mode 'js-mode))
- (should (equal pm--indent-line-function-original
'js-indent-line))
- (should (equal pm--indent-region-function-original
'pm--indent-region-line-by-line))
- (should (equal pm--fill-forward-paragraph-original
'forward-paragraph))))
+ (goto-char (point-min))
+ (pm-switch-to-buffer)
+ (should (eq major-mode 'markdown-mode))
+ (poly-test-markdown-mode t)
+ (should (equal pm--indent-line-function-original 'markdown-indent-line))
+ (should (equal pm--indent-region-function-original
'markdown--indent-region))
+ (should (equal pm--fill-forward-paragraph-original
'markdown-fill-forward-paragraph))
+ (should (equal pm--syntax-propertize-function-original
'markdown-syntax-propertize))
+
+ (re-search-forward "http.createServer")
+ (forward-line 1)
+ (pm-switch-to-buffer)
+ (poly-test-markdown-mode t)
+ (should (eq major-mode 'js-mode))
+ (should (equal pm--indent-line-function-original 'js-indent-line))
+ (should (equal pm--indent-region-function-original
'pm--indent-region-line-by-line))
+ (should (equal pm--fill-forward-paragraph-original 'forward-paragraph))))