summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanos Apollo <public@thanosapollo.org>2026-04-29 01:56:47 +0300
committerThanos Apollo <public@thanosapollo.org>2026-04-29 01:56:47 +0300
commit68f4429ef05ab939ed27dc4108bbe49e58d57384 (patch)
treee5103d539bb91b1b55f23d48313af9de3d1b2d12
parentfbe87309f09476e931a3713b7f520ce727226eec (diff)
buffer, utils: Add forgejo-markdown-mode defcustom
-rw-r--r--lisp/forgejo-buffer.el10
-rw-r--r--lisp/forgejo-utils.el16
-rw-r--r--lisp/forgejo.el13
3 files changed, 30 insertions, 9 deletions
diff --git a/lisp/forgejo-buffer.el b/lisp/forgejo-buffer.el
index 80252b5..de21c20 100644
--- a/lisp/forgejo-buffer.el
+++ b/lisp/forgejo-buffer.el
@@ -199,8 +199,10 @@ Matches 7-40 character hex strings at word boundaries."
'keymap forgejo-buffer--action-map))))))
(defun forgejo-buffer--url-at-point ()
- "Return the URL at point via `markdown-link-url'."
- (markdown-link-url))
+ "Return the URL at point.
+Tries `markdown-link-url' if available, otherwise `thing-at-point'."
+ (or (and (fboundp 'markdown-link-url) (markdown-link-url))
+ (thing-at-point 'url)))
;;; Body rendering
@@ -209,7 +211,7 @@ Matches 7-40 character hex strings at word boundaries."
Uses a null byte that won't appear in markdown text.")
(defun forgejo-buffer--fontify-bodies (bodies)
- "Fontify all BODIES in a single `gfm-view-mode' temp buffer.
+ "Fontify all BODIES in a single temp buffer using `forgejo-markdown-mode'.
Returns a list of fontified strings in the same order.
Much faster than fontifying each body in a separate buffer."
(if (null bodies)
@@ -217,7 +219,7 @@ Much faster than fontifying each body in a separate buffer."
(let ((sep forgejo-buffer--body-separator))
(with-temp-buffer
(insert "\n" (mapconcat #'identity bodies sep))
- (gfm-view-mode)
+ (funcall forgejo-markdown-mode)
(font-lock-ensure)
(split-string (buffer-substring (+ (point-min) 1) (point-max))
sep)))))
diff --git a/lisp/forgejo-utils.el b/lisp/forgejo-utils.el
index 22e3f3a..ca08b61 100644
--- a/lisp/forgejo-utils.el
+++ b/lisp/forgejo-utils.el
@@ -29,6 +29,7 @@
(require 'markdown-mode)
(declare-function forgejo-token "forgejo.el" (host-url))
+(defvar forgejo-markdown-mode)
;;; URL builders
@@ -188,10 +189,19 @@ free-text prefixes. Returns the query string."
"Keymap for `forgejo-compose-mode'.
Unbinds C-c C-c so `string-edit-minor-mode' handles it.")
-(define-derived-mode forgejo-compose-mode gfm-mode "Forgejo Compose"
+(defvar forgejo-compose-mode-hook nil
+ "Hook run after `forgejo-compose-mode' setup.")
+
+(defun forgejo-compose-mode ()
"Major mode for composing Forgejo comments.
-Inherits `gfm-mode' for markdown highlighting."
- :group 'forgejo)
+Activates `forgejo-markdown-mode' for highlighting, then applies
+Forgejo-specific keybindings."
+ (funcall forgejo-markdown-mode)
+ (setq major-mode 'forgejo-compose-mode
+ mode-name "Forgejo Compose")
+ (use-local-map (make-composed-keymap forgejo-compose-mode-map
+ (current-local-map)))
+ (run-hooks 'forgejo-compose-mode-hook))
(defun forgejo-utils-read-body (prompt &optional initial)
"Read multi-line text with markdown highlighting and # completion.
diff --git a/lisp/forgejo.el b/lisp/forgejo.el
index 6c94d2a..28a0caf 100644
--- a/lisp/forgejo.el
+++ b/lisp/forgejo.el
@@ -61,10 +61,19 @@
Each function receives the current buffer as its sole argument."
:type '(repeat function))
+(defcustom forgejo-markdown-mode 'gfm-mode
+ "Major mode used for markdown highlighting.
+Applied in compose buffers and for fontifying comment bodies.
+Typical choices are `gfm-mode' (from `markdown-mode' package)
+and `markdown-ts-mode' (built-in, requires tree-sitter grammars)."
+ :type '(choice (function-item gfm-mode)
+ (function-item markdown-ts-mode)
+ (function :tag "Other"))
+ :group 'forgejo)
+
(defcustom forgejo-compose-hook nil
"Hook run in composition buffers after setup.
-Compose buffers already use `gfm-mode', so this is for extras
-like `flyspell-mode' or `visual-line-mode'."
+This is for extras like `flyspell-mode' or `visual-line-mode'."
:type 'hook)