aboutsummaryrefslogtreecommitdiff
path: root/emacs/.emacs.d/lisp/my
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2023-07-01 23:55:05 +1000
committerYuchen Pei <id@ypei.org>2023-07-01 23:55:05 +1000
commit2af840342c242fe1f40f033936d3eaa9e7a9aab5 (patch)
tree0903e56ebe9c602197b9b0c1aa61884b76fb011b /emacs/.emacs.d/lisp/my
parent28ef1d4fafaf3beda0379924b6413f262f0bafe4 (diff)
Adding more faces to wiki mode, as well as rendering the links
like in org mode
Diffstat (limited to 'emacs/.emacs.d/lisp/my')
-rw-r--r--emacs/.emacs.d/lisp/my/wiki-faces.el31
-rw-r--r--emacs/.emacs.d/lisp/my/wiki.el74
2 files changed, 97 insertions, 8 deletions
diff --git a/emacs/.emacs.d/lisp/my/wiki-faces.el b/emacs/.emacs.d/lisp/my/wiki-faces.el
index 2c35722..00a346a 100644
--- a/emacs/.emacs.d/lisp/my/wiki-faces.el
+++ b/emacs/.emacs.d/lisp/my/wiki-faces.el
@@ -73,5 +73,36 @@
(defvar wiki-level-6 'wiki-level-6
"Face used for level 6 headlines.")
+(defface wiki-hr-face '((t :inherit font-lock-builtin-face))
+ "Wiki hrule face")
+
+(defvar wiki-hr-face 'wiki-hr-face
+ "Wiki hrule face")
+
+(defface wiki-bold-italic '((t :inherit bold-italic))
+ "Wiki bold-italic face")
+
+(defvar wiki-bold-italic 'wiki-bold-italic
+ "Wiki bold-italic face")
+
+(defface wiki-bold '((t :inherit bold))
+ "Wiki bold face")
+
+(defvar wiki-bold 'wiki-bold
+ "Wiki bold face")
+
+(defface wiki-italic '((t :inherit italic))
+ "Wiki italic face")
+
+(defvar wiki-italic 'wiki-italic "Wiki italic face")
+
+(defface wiki-pre-face '((t :inherit org-code)) "Wiki pre face")
+
+(defvar wiki-pre-face 'wiki-pre-face "Wiki pre face")
+
+(defface wiki-link '((t :inherit org-link)) "Wiki link face")
+
+(defvar wiki-link 'wiki-link "Wiki link face")
+
(provide 'wiki-faces)
;;; wiki-faces.el ends here
diff --git a/emacs/.emacs.d/lisp/my/wiki.el b/emacs/.emacs.d/lisp/my/wiki.el
index 2aace73..468244c 100644
--- a/emacs/.emacs.d/lisp/my/wiki.el
+++ b/emacs/.emacs.d/lisp/my/wiki.el
@@ -27,23 +27,81 @@
;;; Code:
(require 'wiki-faces)
+(defvar wiki-link-re
+ (rx (seq "[["
+ ;; Target
+ (group
+ (one-or-more
+ (not (any "[|]"))))
+ ;; Label (optional)
+ (opt (seq "|" (group (+? anything))))
+ "]]"))
+ ;; "\\(\\[\\[\\)\\([^][|]+\\)\\(|\\)\\([^][|]+\\)\\(\\]\\]\\)"
+ )
+
(defvar wiki-font-lock-keywords
(list
- (cons "^======.*======$" 'wiki-level-6)
- (cons "^=====.*=====$" 'wiki-level-5)
- (cons "^====.*====$" 'wiki-level-4)
- (cons "^===.*===$" 'wiki-level-3)
- (cons "^==.*==$" 'wiki-level-2)
- (cons "^=.*=$" 'wiki-level-1)
+ (cons "^======.*======\\ *$" 'wiki-level-6)
+ (cons "^=====.*=====\\ *$" 'wiki-level-5)
+ (cons "^====.*====\\ *$" 'wiki-level-4)
+ (cons "^===.*===\\ *$" 'wiki-level-3)
+ (cons "^==.*==\\ *$" 'wiki-level-2)
+ (cons "^=.*=\\ *$" 'wiki-level-1)
+ (cons "^----+\\ *$" 'wiki-hr-face)
+ (cons "'''''[^ \t\n].*[^ \t\n]'''''" 'wiki-bold-italic)
+ (cons "'''[^ \t\n'].*[^ \t\n']'''" 'wiki-bold)
+ (cons "''[^ \t\n'].*[^ \t\n']''" 'wiki-italic)
+ (cons "^ .*$" 'wiki-pre-face)
+ ;; FIXME: not working, need to do something like `org-activate-links'
+ (cons "\\(\\[\\[\\)\\([^][|]+\\)\\(|\\)\\([^][|]+\\)\\(\\]\\]\\)"
+ '((1 invisible)
+ (2 invisible)
+ (3 invisible)
+ (4 wiki-link)
+ (5 invisible)))
))
+(defvar wiki-font-lock-keywords nil)
+
+(defvar wiki-outline-regexp "=+.*=+\ *$")
+
+(defun wiki-outline-level ()
+ (when (looking-at "\\(=+\\).*\\(=+\\)\ *$")
+ (min (length (match-string 1))
+ (length (match-string 2))
+ 6)))
+
+;; `org-activate-links'
+(defun wiki-activate-links ()
+ (save-excursion
+ (goto-char (point-min))
+ (while (re-search-forward wiki-link-re nil t)
+ (let ((matched (match-data))
+ (target (match-string 1))
+ (maybe-label (match-string 2)))
+ (put-text-property
+ (nth 0 matched)
+ (nth (if maybe-label 4 2) matched)
+ 'invisible t)
+ (put-text-property
+ (nth (if maybe-label 5 3) matched)
+ (nth 1 matched)
+ 'invisible t)
+ (put-text-property
+ (nth (if maybe-label 4 2) matched)
+ (nth (if maybe-label 5 3) matched)
+ 'font-lock-face 'wiki-link)))))
-(define-derived-mode wiki-mode text-mode "Wiki"
+(define-derived-mode wiki-mode outline-mode "Wiki"
"A wikitext mode."
(setq-local comment-start "<!--")
(setq-local comment-end "-->")
- (setq-local font-lock-defaults '(wiki-font-lock-keywords t nil nil nil)))
+ ;; FIXME: this should not be necessary in outline mode
+ (setq-local font-lock-defaults '(wiki-font-lock-keywords t nil nil nil))
+ (setq-local outline-regexp wiki-outline-regexp)
+ (setq-local outline-level 'wiki-outline-level)
+ (wiki-activate-links))
(provide 'wiki)
;;; wiki.el ends here