-
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewrite syntax-table definition of markdown-mode
- Loading branch information
Showing
4 changed files
with
99 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Hello | ||
|
||
```lisp | ||
(defpackage :foo | ||
(:use :cl)) | ||
(in-package :foo) | ||
(defun hello () | ||
(write-line "Hello World")) | ||
``` | ||
|
||
```c | ||
#include <stdio.h> | ||
|
||
int main(void) { | ||
printf("Hello World\n"); | ||
} | ||
``` | ||
## Test | ||
this is test | ||
- foo | ||
- bar | ||
- baz | ||
* hoge | ||
* piyo | ||
+ hoge | ||
+ piyo | ||
1. one | ||
2. two | ||
3. three |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
(defsystem "lem-markdown-mode" | ||
:depends-on ("lem") | ||
:serial t | ||
:components ((:file "markdown-mode"))) | ||
:components ((:file "syntax-parser") | ||
(:file "markdown-mode"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
(defpackage :lem-markdown-mode/syntax-parser | ||
(:use :cl :lem) | ||
(:export :make-syntax-parser | ||
:scan-buffer)) | ||
(in-package :lem-markdown-mode/syntax-parser) | ||
|
||
(defclass syntax-parser () ()) | ||
|
||
(defun make-syntax-parser () | ||
(make-instance 'syntax-parser)) | ||
|
||
(defmethod lem/buffer/internal::%syntax-scan-region ((parser syntax-parser) start end) | ||
(scan-region start end)) | ||
|
||
(defun put-line-attribute (point attribute) | ||
(with-point ((start point) | ||
(end point)) | ||
(line-start start) | ||
(line-end end) | ||
(put-text-property start end :attribute attribute))) | ||
|
||
(defun scan-code-block (point end) | ||
(log:info point end) | ||
(let* ((groups (nth-value 1 (looking-at point "^```(.*)"))) | ||
(language-name (and groups (elt groups 0))) | ||
(syntax-table (get-syntax-table-by-mode-name language-name))) | ||
(line-offset point 1) | ||
(with-point ((start point)) | ||
(loop :while (point< point end) | ||
:until (looking-at point "^```") | ||
:while (line-offset point 1)) | ||
(if syntax-table | ||
(let ((lem/buffer/internal::*recursive-syntax-scan* nil)) | ||
(syntax-scan-region start point :syntax-table syntax-table)) | ||
(put-text-property start point :attribute 'syntax-string-attribute))))) | ||
|
||
(defun scan-region (start end) | ||
(with-point ((point start)) | ||
(loop :while (point< point end) | ||
:do (cond ((looking-at point "^#") | ||
(put-line-attribute point 'syntax-constant-attribute)) | ||
((looking-at point "^>") | ||
(put-line-attribute point 'syntax-string-attribute)) | ||
((looking-at point "^\\s*[-*+]") | ||
(back-to-indentation point) | ||
(with-point ((start point) | ||
(end point)) | ||
(character-offset end 1) | ||
(put-text-property start end :attribute 'syntax-keyword-attribute))) | ||
((looking-at point "^\\s*(?:\\d)+\\.\\s") | ||
(back-to-indentation point) | ||
(with-point ((start point) | ||
(end point)) | ||
(skip-chars-forward end #'digit-char-p) | ||
(character-offset end 1) | ||
(put-text-property start end :attribute 'syntax-keyword-attribute))) | ||
((looking-at point "^```") | ||
(scan-code-block point end))) | ||
:while (line-offset point 1)))) |