You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
143 lines
6.2 KiB
143 lines
6.2 KiB
;;; tiddlermode.el -*- lexical-binding: t; -*- |
|
;;; TIDDLER-MODE |
|
;; A mode for viewing Tiddlywiki Tiddlers (.tid files) with some |
|
;; nice colors that make them easier to read in emacs |
|
;; So far this is just colors and formatting |
|
;; requires: olivetti (makes the tiddlers look nicer, adds a margin) |
|
;; TODO fix some of the bugs (some colors aren't applied) |
|
;; TODO perhaps hide some of the markup |
|
;; TODO replace [img[imagename]] links with the actual images |
|
;; TODO create some follow-link functionality (click <enter> on [[stuff]] will load the file stuff.tid) |
|
;; |
|
;; Chris Beckstrom September 28, 2021 |
|
;; |
|
;; lots of code borrowed from |
|
;; https://emacs-fu.blogspot.com/2010/04/creating-custom-modes-easy-way-with.html |
|
;; http://makble.com/how-to-define-emacs-custom-faces-for-text-highlighting |
|
;; https://raw.githubusercontent.com/mwfogleman/tid-mode/master/tid-mode.el |
|
|
|
(require 'generic-x) ;; we need this ... ? |
|
|
|
(defvar tiddler-title 'tiddler-title "Face name to use for tiddler-title.") |
|
(defface tiddler-title '((((class color) (min-colors 88) (background light)) |
|
:foreground "#0080ff" |
|
;:background "#E9FFD4" |
|
;; TODO get the title to be bigger |
|
;; TODO also: why isn't this formatting being applied? |
|
:height 200 |
|
) |
|
(t :inverse-video t)) |
|
"Basic face for tiddler-titleing." |
|
:group 'basic-faces) |
|
|
|
|
|
(defvar strong-bold 'strong-bold "Face name to use for strong.") |
|
(defface strong-bold |
|
'((((class color) (min-colors 88) (background light)) :foreground "black" :weight bold ) |
|
(((class color) (min-colors 88) (background dark)) :foreground "#ffff00" :weight bold ) |
|
(t :inverse-video t)) |
|
"Basic face for strong." |
|
:group 'basic-faces) |
|
|
|
|
|
(defvar wikilink 'wikilink "Face name to use for wikilinks.") |
|
(defface wikilink |
|
'((((class color) (min-colors 88) (background light)) :foreground "#660066" :weight bold ) |
|
(((class color) (min-colors 88) (background dark)) :foreground "#ff9900" :weight bold ) |
|
(t :inverse-video t)) |
|
"Basic face for wikilinks." |
|
:group 'basic-faces) |
|
|
|
(defvar tiddler-comment 'tiddler-comment "Face name to use for tiddler-comments.") |
|
(defface tiddler-comment |
|
'((((class color) (min-colors 88) (background light)) :foreground "#808080" ) |
|
(((class color) (min-colors 88) (background dark)) :foreground "#808080" ) |
|
(t :inverse-video t)) |
|
"Basic face for tiddler-comments." |
|
:group 'basic-faces) |
|
|
|
(defvar tiddler-quoteblock 'tiddler-quoteblock "Face name to use for tiddler-quoteblocks.") |
|
(defface tiddler-quoteblock |
|
'((((class color) (min-colors 88) (background light)) :foreground "#808080" ) |
|
(((class color) (min-colors 88) (background dark)) :foreground "#ffff00" ) |
|
(t :inverse-video t)) |
|
"Basic face for tiddler-quoteblocks." |
|
:group 'basic-faces) |
|
|
|
(defvar tiddler-code 'tiddler-code "Face name to use for tiddler-code.") |
|
(defface tiddler-code |
|
'((((class color) (min-colors 88) (background light)) |
|
:foreground "red" |
|
:background "green") |
|
(t :inverse-video t)) |
|
"Basic face for tiddler-code." |
|
:group 'basic-faces) |
|
|
|
|
|
(defvar tiddler-highlight 'tiddler-highlight "Face name to use for tiddler-highlight.") |
|
(defface tiddler-highlight '((((class color) (min-colors 88) (background light)) |
|
:foreground "#009900" |
|
;:background "#E9FFD4" |
|
) |
|
(t :inverse-video t)) |
|
"Basic face for tiddler-highlighting." |
|
:group 'basic-faces) |
|
|
|
|
|
(defun test-font-lock-extend-region () |
|
"Extend the search region to include an entire block of text." |
|
;; Avoid compiler warnings about these global variables from font-lock.el. |
|
;; See the documentation for variable `font-lock-extend-region-functions'. |
|
(eval-when-compile (defvar font-lock-beg) (defvar font-lock-end)) |
|
(save-excursion |
|
(goto-char font-lock-beg) |
|
(let ((found (or (re-search-backward "\n\n" nil t) (point-min)))) |
|
(goto-char font-lock-end) |
|
(when (re-search-forward "\n\n" nil t) |
|
(beginning-of-line) |
|
(setq font-lock-end (point))) |
|
(setq font-lock-beg found)))) |
|
|
|
(define-derived-mode tiddler-mode fundamental-mode "tiddler-mode" |
|
;; TODO |
|
;; is it possible to replace <<< , ```, etc like what happens in markdown-mode? |
|
(setq tiddlermode-highlights '( |
|
;("code:hide\\(.\\|\n\\)*?code:end" . (0 font-lock-comment-face t)) |
|
("''.*?''" . (0 strong-bold t)) |
|
("\\[\\[.*?\\]\\]" . (0 wikilink t)) |
|
("http.*?\s" . (0 wikilink t)) |
|
;("https:.*?\n" . (0 wikilink t)) |
|
;("^\\[.*?\\]\\]?" . (0 sub-title t)) |
|
("`.*?`" . (0 tiddler-code t)) |
|
;; code blocks, including new lines |
|
;; https://stackoverflow.com/questions/320590/regexps-in-elisp-to-include-newlines |
|
( "\\(\`\\{3\\}\\(.*\n?\\)*?\`\\{3\\}\\)" . (0 tiddler-code t)) |
|
( "\\(<\\{3\\}\\(.*\n?\\)*?<\\{3\\}\\)" . (0 tiddler-quoteblock t)) |
|
;("\*.*?" . (0 code t)) |
|
("!.*?\n" . (0 tiddler-highlight t)) |
|
;; frontmatter |
|
("^created:.*$" . (0 tiddler-comment t)) |
|
("^modified:.*$" . (0 tiddler-comment t)) |
|
("^rating:.*$" . (0 tiddler-comment t)) |
|
("^tags:.*$" . (0 tiddler-comment t)) |
|
("^leaf_collected:.*$" . (0 tiddler-comment t)) |
|
("^latinname:.*$" . (0 tiddler-comment t)) |
|
("^source:.*$" . (0 tiddler-comment t)) |
|
("^source:.*$" . (0 tiddler-comment t)) |
|
("^title:.*$" . (0 tiddler-title t)) |
|
("^type:.*$" . (0 tiddler-comment t)) |
|
) |
|
) |
|
(setq font-lock-defaults '(tiddlermode-highlights)) |
|
(message "deriving mode tiddlermode") |
|
(olivetti-mode) ;; when my tiddler mode is activated, also activate olivetti mode |
|
(variable-pitch-mode t) ;; nice text |
|
;(add-hook 'tiddler-mode-hook ) |
|
|
|
(set (make-local-variable 'font-lock-multiline) t) |
|
(add-hook 'font-lock-extend-region-functions |
|
'test-font-lock-extend-region) |
|
) |
|
|
|
(add-to-list 'auto-mode-alist '("\\.tid\\'" . tiddler-mode)) |
|
(provide 'tiddler-mode)
|
|
|