aboutsummaryrefslogtreecommitdiff
path: root/wiki-markup.el
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2023-07-23 17:01:24 +1000
committerYuchen Pei <id@ypei.org>2023-07-23 17:01:24 +1000
commitcd62bb147b15d052d52c5dc0f6277902efa7a61e (patch)
treedd7cad9e672c1b4605802e25ea5348cc8f9b6748 /wiki-markup.el
parentfcf126f8aab283078111f8dac0b589e51f30f0ce (diff)
Fixing copyright and flymake complaints.
Diffstat (limited to 'wiki-markup.el')
-rw-r--r--wiki-markup.el45
1 files changed, 39 insertions, 6 deletions
diff --git a/wiki-markup.el b/wiki-markup.el
index f0f26cb..645c71e 100644
--- a/wiki-markup.el
+++ b/wiki-markup.el
@@ -1,6 +1,6 @@
;;; wiki-markup.el -- A wikitext mode -*- lexical-binding: t -*-
-;; Copyright (C) 2023 Free Software Foundation.
+;; Copyright (C) 2023 Free Software Foundation, Inc.
;; Author: Yuchen Pei <id@ypei.org>
;; Package-Requires: ((emacs "28.2"))
@@ -26,6 +26,7 @@
;;; Code:
(require 'wiki-faces)
+(require 'wiki-utils)
(defvar wiki-url-re "https?://[^ |}]+")
@@ -78,7 +79,9 @@
(defvar-local wiki-title nil
"The title of the current wiki buffer.")
(defun wiki-follow-wikilink-action (data)
- "Button action to follow a wikilink"
+ "Button action to follow a wikilink.
+
+The button data is passed as DATA."
(funcall (wiki-site-fetcher wiki-site) (alist-get 'target data)))
(defun wiki-guess-site ()
@@ -101,12 +104,16 @@ This can be overriden with .dir-locals.el."
(setq-local wiki-title (file-name-base (buffer-file-name)))))
(defun wiki-outline-level ()
+ "Determines the outline header level in `outline-mode'."
(when (looking-at "\\(=+\\).*[^=]\\(=+\\)\\ *$")
(min (length (match-string 1))
(length (match-string 2))
6)))
(defun wiki-do-refs (limit)
+ "Process ref tags.
+
+LIMIT is the limit of the search, used for `font-lock-keywords'."
(let ((ref-counter 0))
(while (re-search-forward "<ref\\([^>]*\\)>" limit t)
(let ((start (match-beginning 0))
@@ -130,13 +137,16 @@ This can be overriden with .dir-locals.el."
(goto-char end))
(t (goto-char next-start)))))))
+;; TODO: complete this function.
(defun wiki-set-template-face (limit)
- "Set template faces."
+ "Set template faces.
+
+LIMIT is the limit of the search, used for `font-lock-keywords'."
(while (search-forward "{{" limit t)
(save-excursion
(let* ((name-start (point))
;; (visible-start name-start)
- (start (progn (backward-char 2) (point)))
+ ;; (start (progn (backward-char 2) (point)))
(end (progn (forward-sexp) (point)))
(visible-end (- end 2))
(name-end (progn
@@ -154,8 +164,12 @@ This can be overriden with .dir-locals.el."
)
))
+;; TODO: complete this function.
;; We assume the arg name cannot contain (nested) templates
(defun wiki-do-one-template-arg (limit)
+ "Process one template arg.
+
+LIMIT is the limit of the search, used for `font-lock-keywords'."
(let ((found (re-search-forward "|\\ *\\([^|= \t\n]+\\ *[=|]\\)"
limit 'move))
(name-start (match-beginning 1))
@@ -184,6 +198,9 @@ This can be overriden with .dir-locals.el."
;; Like `org-do-emphasis-faces'
(defun wiki-do-emphasis-faces (limit)
+ "Fix emphasis faces of mediawiki markup.
+
+LIMIT is the limit of the search, used for `font-lock-keywords'."
(while (re-search-forward "\\(''+\\)[^ \t\n].*?[^ \t\n']\\(''+\\)" limit t)
(let ((start (match-beginning 0))
(end (match-end 0)))
@@ -194,7 +211,12 @@ This can be overriden with .dir-locals.el."
))))
;; Like `org-activate-links'
+;; TODO: support more types, e.g. interwiki and anchor links.
(defun wiki-activate-links (link-re type limit)
+ "Activate links in wiki markup match LINK-RE(gexp) of link TYPE.
+
+LIMIT is the limit of the search, used for `font-lock-keywords'.
+Currently supported types are `internal' and `external'."
(save-excursion
(goto-char (point-min))
(while (re-search-forward link-re limit t)
@@ -227,15 +249,25 @@ This can be overriden with .dir-locals.el."
))))
(defun wiki-browse-url-action (data)
+ "Call `browse-url' on the button DATA."
(browse-url (alist-get 'target data)))
(defun wiki-activate-internal-links (limit)
+ "Activate internal links in mediawiki markup.
+
+LIMIT is the limit of the search, used for `font-lock-keywords'."
(wiki-activate-links wiki-internal-link-re 'internal limit))
(defun wiki-activate-external-links (limit)
+ "Activate external links in mediawiki markup.
+
+LIMIT is the limit of the search, used for `font-lock-keywords'."
(wiki-activate-links wiki-external-link-re 'external limit))
(defun wiki-activate-raw-links (limit)
+ "Activate raw url links in mediawiki markup.
+
+LIMIT is the limit of the search, used for `font-lock-keywords'."
(wiki-activate-links (format "\\(%s\\)" wiki-url-re) 'external limit))
(define-derived-mode wiki-mode outline-mode "Wiki"
@@ -261,11 +293,12 @@ This can be overriden with .dir-locals.el."
imenu-space-replacement nil)
)
-(defun set-wiki-site (wiki-site)
+(defun set-wiki-site (site)
+ "Set `wiki-site' to SITE."
(interactive (list
(completing-read "Set wiki site: "
(mapcar 'car wiki-sites))))
- (setq-local wiki-site (intern wiki-site)))
+ (setq-local wiki-site (intern site)))
(add-hook 'wiki-mode-hook 'wiki-guess-site)
(add-hook 'wiki-mode-hook 'wiki-guess-title)